當前位置: 首頁>>代碼示例>>Java>>正文


Java Bidi.requiresBidi方法代碼示例

本文整理匯總了Java中java.text.Bidi.requiresBidi方法的典型用法代碼示例。如果您正苦於以下問題:Java Bidi.requiresBidi方法的具體用法?Java Bidi.requiresBidi怎麽用?Java Bidi.requiresBidi使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.text.Bidi的用法示例。


在下文中一共展示了Bidi.requiresBidi方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: bidiUpdateProperty

import java.text.Bidi; //導入方法依賴的package包/類
private boolean bidiUpdateProperty(final int offset, final Segment text) {
    final boolean hasBidiInfo = hasBidiInfo();

    if (!hasBidiInfo && TextUtils.isLTR(getDefaultDirection(offset))
        && !Bidi.requiresBidi(text.array, text.offset,
                              text.offset + text.count)) {

        return false;
    }

    final Bidi bidi = new Bidi(text.array, text.offset, null, 0, text.count,
                               getDefaultDirection(offset));

    if (hasBidiInfo && !bidi.isMixed()
        && isLeftToRight(offset) == bidi.isLeftToRight()) {

        return false;
    }

    if (!hasBidiInfo) {
        putProperty(StringConstants.BIDI_PROPERTY, Boolean.TRUE);
    }
    return true;
}
 
開發者ID:shannah,項目名稱:cn1,代碼行數:25,代碼來源:AbstractDocument.java

示例2: layoutBidi

import java.text.Bidi; //導入方法依賴的package包/類
private int layoutBidi(String str) {
	final char[] text = str.toCharArray();

	/* Avoid performing full bidirectional analysis if text has no "strong" right-to-left characters */
	if (!Bidi.requiresBidi(text, 0, text.length))
		return layoutFont(text, 0, text.length, Font.LAYOUT_LEFT_TO_RIGHT);

	final Bidi bidi = new Bidi(text, 0, null, 0, text.length, Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT);

	/* If text is entirely right-to-left, then just lay it out */
	if (bidi.isRightToLeft())
		return layoutFont(text, 0, text.length, Font.LAYOUT_RIGHT_TO_LEFT);

	/* Otherwise text has a mixture of LTR and RLT, and it requires full bidirectional analysis */
	final int runCount = bidi.getRunCount();
	final byte[] levels = new byte[runCount];
	final Integer[] ranges = new Integer[runCount];

	for (int i = 0; i < runCount; i++) {
		levels[i] = (byte) bidi.getRunLevel(i);
		ranges[i] = i;
	}
	Bidi.reorderVisually(levels, 0, ranges, 0, runCount);

	int width = 0;

	for (int i = 0; i < runCount; i++) {
		final int index = ranges[i];
		width += layoutFont(text, bidi.getRunStart(index), bidi.getRunLimit(index), (bidi.getRunLevel(index) & 1));
	}
	return width;
}
 
開發者ID:ImpactDevelopment,項目名稱:ClientAPI,代碼行數:33,代碼來源:FontCache.java

示例3: init

import java.text.Bidi; //導入方法依賴的package包/類
public void init(TestEnvironment env, Result results) {
    super.init(env, results);

    int flags = Font.LAYOUT_LEFT_TO_RIGHT;
    if (Bidi.requiresBidi(chars, 0, chars.length)) { // assume rtl
        flags = Font.LAYOUT_RIGHT_TO_LEFT;
    }
    gv = font.layoutGlyphVector(frc, chars, 0, chars.length, flags);

    // gv options
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:12,代碼來源:TextMeasureTests.java

示例4: init

import java.text.Bidi; //導入方法依賴的package包/類
public void init(TestEnvironment env, Result results) {
    super.init(env, results);

    chars1 = new char[chars.length + 2];
    System.arraycopy(chars, 0, chars1, 1, chars.length);
    ci = new ArrayCI(chars1, 1, chars.length);
    gv = font.createGlyphVector(frc, text);
    glyphs = gv.getGlyphCodes(0, gv.getNumGlyphs(), null);
    flags = Bidi.requiresBidi(chars, 0, chars.length)
        ? Font.LAYOUT_LEFT_TO_RIGHT
        : Font.LAYOUT_RIGHT_TO_LEFT;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:13,代碼來源:TextConstructionTests.java

示例5: isLeftToRight

import java.text.Bidi; //導入方法依賴的package包/類
protected boolean isLeftToRight(char[] chars)
{
	boolean leftToRight = true;
	if (Bidi.requiresBidi(chars, 0, chars.length))
	{
		// determining the text direction
		// using default LTR as there's no way to have other default in the text
		Bidi bidi = new Bidi(chars, 0, null, 0, chars.length, Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT);
		leftToRight = bidi.baseIsLeftToRight();
	}
	return leftToRight;
}
 
開發者ID:TIBCOSoftware,項目名稱:jasperreports,代碼行數:13,代碼來源:SimpleTextLineWrapper.java

示例6: insertStringImpl

import java.text.Bidi; //導入方法依賴的package包/類
void insertStringImpl(int offset, String text, AttributeSet attributes)
  throws BadLocationException
{
  // Just return when no text to insert was given.
  if (text == null || text.length() == 0)
    return;
  DefaultDocumentEvent event =
    new DefaultDocumentEvent(offset, text.length(),
                             DocumentEvent.EventType.INSERT);

  UndoableEdit undo = content.insertString(offset, text);
  if (undo != null)
    event.addEdit(undo);

  // Check if we need bidi layout.
  if (getProperty(I18N).equals(Boolean.FALSE))
    {
      Object dir = getProperty(TextAttribute.RUN_DIRECTION);
      if (TextAttribute.RUN_DIRECTION_RTL.equals(dir))
        putProperty(I18N, Boolean.TRUE);
      else
        {
          char[] chars = text.toCharArray();
          if (Bidi.requiresBidi(chars, 0, chars.length))
            putProperty(I18N, Boolean.TRUE);
        }
    }

  insertUpdate(event, attributes);

  fireInsertUpdate(event);

  if (undo != null)
    fireUndoableEditUpdate(new UndoableEditEvent(this, undo));
}
 
開發者ID:vilie,項目名稱:javify,代碼行數:36,代碼來源:AbstractDocument.java

示例7: insertStringImpl

import java.text.Bidi; //導入方法依賴的package包/類
void insertStringImpl(int offset, String text, AttributeSet attributes)
  throws BadLocationException
{
  // Just return when no text to insert was given.
  if (text == null || text.length() == 0)
    return;
  DefaultDocumentEvent event =
    new DefaultDocumentEvent(offset, text.length(),
	       DocumentEvent.EventType.INSERT);

  UndoableEdit undo = content.insertString(offset, text);
  if (undo != null)
    event.addEdit(undo);

  // Check if we need bidi layout.
  if (getProperty(I18N).equals(Boolean.FALSE))
    {
      Object dir = getProperty(TextAttribute.RUN_DIRECTION);
      if (TextAttribute.RUN_DIRECTION_RTL.equals(dir))
        putProperty(I18N, Boolean.TRUE);
      else
        {
          char[] chars = text.toCharArray();
          if (Bidi.requiresBidi(chars, 0, chars.length))
            putProperty(I18N, Boolean.TRUE);
        }
    }

  insertUpdate(event, attributes);

  fireInsertUpdate(event);

  if (undo != null)
    fireUndoableEditUpdate(new UndoableEditEvent(this, undo));
}
 
開發者ID:nmldiegues,項目名稱:jvm-stm,代碼行數:36,代碼來源:AbstractDocument.java

示例8: getWidth

import java.text.Bidi; //導入方法依賴的package包/類
/**
     * Compute a most appropriate width of the given text layout.
     */
    public static float getWidth(TextLayout textLayout, String textLayoutText, Font font) {
        // For italic fonts the textLayout.getAdvance() includes some extra horizontal space.
        // On the other hand index2X() for TL.getCharacterCount() is width along baseline
        // so when TL ends with e.g. 'd' char the end of 'd' char is cut off.
        float width;
        int tlLen = textLayoutText.length();
        if (!font.isItalic() ||
            tlLen == 0 ||
            Character.isWhitespace(textLayoutText.charAt(tlLen - 1)) ||
            Bidi.requiresBidi(textLayoutText.toCharArray(), 0, textLayoutText.length()))
        {
            width = textLayout.getAdvance();
            if (LOG.isLoggable(Level.FINE)) {
                LOG.fine("TLUtils.getWidth(\"" + CharSequenceUtilities.debugText(textLayoutText) + // NOI18N
                        "\"): Using TL.getAdvance()=" + width + // NOI18N
//                        textLayoutDump(textLayout) + 
                        '\n');
            }
        } else {
            // Compute pixel bounds (with frc being null - means use textLayout's frc; and with default bounds)
            Rectangle pixelBounds = textLayout.getPixelBounds(null, 0, 0);
            width = (float) pixelBounds.getMaxX();
            // On Mac OS X with retina displays the TL.getPixelBounds() give incorrect results. Luckily
            // TL.getAdvance() gives a correct result in that case.
            // Therefore use a minimum of both values (on all platforms).
            float tlAdvance = textLayout.getAdvance();
            if (LOG.isLoggable(Level.FINE)) {
                LOG.fine("TLUtils.getWidth(\"" + CharSequenceUtilities.debugText(textLayoutText) + // NOI18N
                        "\"): Using minimum of TL.getPixelBounds().getMaxX()=" + width + // NOI18N
                        " or TL.getAdvance()=" + tlAdvance +
                        textLayoutDump(textLayout) +
                        '\n');
            }
            width = Math.min(width, tlAdvance);
        }
        
        // For RTL text the hit-info of the first char is above the hit-info of ending char.
        // However textLayout.isLeftToRight() returns true in case of mixture of LTR and RTL text
        // in a single textLayout.
        
        // Ceil the width to avoid rendering artifacts.
        width = (float) Math.ceil(width);
        return width;
    }
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:48,代碼來源:TextLayoutUtils.java

示例9: renderLink

import java.text.Bidi; //導入方法依賴的package包/類
protected void renderLink(
  FacesContext     context,
  RenderingContext rc,
  UIComponent      child,
  int              renderedCount,
  boolean          isLastChild
  ) throws IOException
{
  if (isLastChild)
    ((CoreRenderingContext) rc).setLinkDisabled(true);

  boolean isBidi = false;
  String text = toString(child.getAttributes().get(CoreCommandLink.TEXT_KEY.getName()));
  if ((text != null) && (text.length() > 0))
  {
    char[] firstChar = new char[1];
    firstChar[0] = text.charAt(0);
    isBidi = Bidi.requiresBidi(firstChar, 0, 1);
  }

  Map<String, String> originalResourceKeyMap = rc.getSkinResourceKeyMap();
  try
  {
    rc.setSkinResourceKeyMap(_RESOURCE_KEY_MAP);
    if (!isBidi)
    {
      ResponseWriter writer = context.getResponseWriter();
      writer.startElement(XhtmlConstants.SPAN_ELEMENT, null);
      writer.writeAttribute(XhtmlConstants.DIR_ATTRIBUTE_VALUE, "ltr",null);
      encodeChild(context, child);
      writer.endElement(XhtmlConstants.SPAN_ELEMENT);
    }
    else
      encodeChild(context, child);

    if (isLastChild)
      ((CoreRenderingContext) rc).setLinkDisabled(false);
  }
  finally
  {
    rc.setSkinResourceKeyMap(originalResourceKeyMap);
  }
}
 
開發者ID:apache,項目名稱:myfaces-trinidad,代碼行數:44,代碼來源:BreadCrumbsRenderer.java

示例10: testRequiresBidi

import java.text.Bidi; //導入方法依賴的package包/類
void testRequiresBidi(String string, boolean requiresBidi) {
    char[] text = string.toCharArray();
    if (Bidi.requiresBidi(text, 0, text.length) != requiresBidi) {
        throw new RuntimeException("testRequiresBidi failed with '" + string + "', " + requiresBidi);
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:7,代碼來源:BidiSurrogateTest.java

示例11: bidiReorder

import java.text.Bidi; //導入方法依賴的package包/類
/**
 * Apply Unicode Bidirectional Algorithm to string and return a new possibly
 * reordered string for visual rendering.
 */
private String bidiReorder(String par1Str)
{
    if (par1Str != null && Bidi.requiresBidi(par1Str.toCharArray(), 0, par1Str.length()))
    {
        Bidi bidi = new Bidi(par1Str, -2);
        byte[] abyte = new byte[bidi.getRunCount()];
        String[] astring = new String[abyte.length];
        int i;

        for (int j = 0; j < abyte.length; ++j)
        {
            int k = bidi.getRunStart(j);
            i = bidi.getRunLimit(j);
            int l = bidi.getRunLevel(j);
            String s1 = par1Str.substring(k, i);
            abyte[j] = (byte) l;
            astring[j] = s1;
        }

        String[] astring1 = astring.clone();
        Bidi.reorderVisually(abyte, 0, astring, 0, abyte.length);
        StringBuilder stringbuilder = new StringBuilder();
        i = 0;

        while (i < astring.length)
        {
            byte b0 = abyte[i];
            int i1 = 0;

            while (true)
            {
                if (i1 < astring1.length)
                {
                    if (!astring1[i1].equals(astring[i]))
                    {
                        ++i1;
                        continue;
                    }

                    b0 = abyte[i1];
                }

                if ((b0 & 1) == 0)
                {
                    stringbuilder.append(astring[i]);
                }
                else
                {
                    for (i1 = astring[i].length() - 1; i1 >= 0; --i1)
                    {
                        char c0 = astring[i].charAt(i1);

                        if (c0 == 40)
                        {
                            c0 = 41;
                        }
                        else if (c0 == 41)
                        {
                            c0 = 40;
                        }

                        stringbuilder.append(c0);
                    }
                }

                ++i;
                break;
            }
        }

        return stringbuilder.toString();
    }
    else
    {
        return par1Str;
    }
}
 
開發者ID:4Space,項目名稱:4Space-5,代碼行數:82,代碼來源:SmallFontRenderer.java

示例12: layoutBidiString

import java.text.Bidi; //導入方法依賴的package包/類
/**
     * Split a string into contiguous LTR or RTL sections by applying the Unicode Bidirectional Algorithm. Calls layoutString()
     * for each contiguous run to perform further analysis.
     *
     * @param glyphList will hold all new Glyph objects allocated by layoutFont()
     * @param text      the string to lay out
     * @param start     the offset into text at which to start the layout
     * @param limit     the (offset + length) at which to stop performing the layout
     * @return the total advance (horizontal distance) of this string
     */
    private int layoutBidiString(List<Glyph> glyphList, char text[], int start, int limit, ColorCode colors[])
    {
        int advance = 0;

        /* Avoid performing full bidirectional analysis if text has no "strong" right-to-left characters */
        if (Bidi.requiresBidi(text, start, limit))
        {
            /* Note that while requiresBidi() uses start/limit the Bidi constructor uses start/length */
            Bidi bidi = new Bidi(text, start, null, 0, limit - start, Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT);

            /* If text is entirely right-to-left, then insert an EntryText node for the entire string */
            if (bidi.isRightToLeft())
            {
                return layoutStyle(glyphList, text, start, limit, Font.LAYOUT_RIGHT_TO_LEFT, advance, colors);
            }

            /* Otherwise text has a mixture of LTR and RLT, and it requires full bidirectional analysis */
            else
            {
                int runCount = bidi.getRunCount();
                byte levels[] = new byte[runCount];
                Integer ranges[] = new Integer[runCount];

                /* Reorder contiguous runs of text into their display order from left to right */
                for (int index = 0; index < runCount; index++)
                {
                    levels[index] = (byte) bidi.getRunLevel(index);
                    ranges[index] = new Integer(index);
                }
                Bidi.reorderVisually(levels, 0, ranges, 0, runCount);

                /*
* Every GlyphVector must be created on a contiguous run of left-to-right or right-to-left text. Keep track of
* the horizontal advance between each run of text, so that the glyphs in each run can be assigned a position relative
* to the start of the entire string and not just relative to that run.
*/
                for (int visualIndex = 0; visualIndex < runCount; visualIndex++)
                {
                    int logicalIndex = ranges[visualIndex];

                    /* An odd numbered level indicates right-to-left ordering */
                    int layoutFlag = (bidi.getRunLevel(logicalIndex) & 1) == 1 ? Font.LAYOUT_RIGHT_TO_LEFT : Font.LAYOUT_LEFT_TO_RIGHT;
                    advance = layoutStyle(glyphList, text, start + bidi.getRunStart(logicalIndex), start + bidi.getRunLimit(logicalIndex),
                                          layoutFlag, advance, colors);
                }
            }

            return advance;
        }

        /* If text is entirely left-to-right, then insert an EntryText node for the entire string */
        else
        {
            return layoutStyle(glyphList, text, start, limit, Font.LAYOUT_LEFT_TO_RIGHT, advance, colors);
        }
    }
 
開發者ID:cubex2,項目名稱:BetterFonts,代碼行數:67,代碼來源:StringCache.java

示例13: bidiReorder

import java.text.Bidi; //導入方法依賴的package包/類
/**
 * Apply Unicode Bidirectional Algorithm to string and return a new possibly
 * reordered string for visual rendering.
 */
private String bidiReorder(String par1Str)
{
    if (par1Str != null && Bidi.requiresBidi(par1Str.toCharArray(), 0, par1Str.length())) {
        Bidi bidi = new Bidi(par1Str, -2);
        byte[] abyte = new byte[bidi.getRunCount()];
        String[] astring = new String[abyte.length];
        int i;

        for (int j = 0; j < abyte.length; ++j) {
            int k = bidi.getRunStart(j);
            i = bidi.getRunLimit(j);
            int l = bidi.getRunLevel(j);
            String s1 = par1Str.substring(k, i);
            abyte[j] = (byte) l;
            astring[j] = s1;
        }

        String[] astring1 = astring.clone();
        Bidi.reorderVisually(abyte, 0, astring, 0, abyte.length);
        StringBuilder stringbuilder = new StringBuilder();
        i = 0;

        while (i < astring.length) {
            byte b0 = abyte[i];
            int i1 = 0;

            while (true) {
                if (i1 < astring1.length) {
                    if (!astring1[i1].equals(astring[i])) {
                        ++i1;
                        continue;
                    }

                    b0 = abyte[i1];
                }

                if ((b0 & 1) == 0) {
                    stringbuilder.append(astring[i]);
                }
                else {
                    for (i1 = astring[i].length() - 1; i1 >= 0; --i1) {
                        char c0 = astring[i].charAt(i1);

                        if (c0 == 40) {
                            c0 = 41;
                        }
                        else if (c0 == 41) {
                            c0 = 40;
                        }

                        stringbuilder.append(c0);
                    }
                }

                ++i;
                break;
            }
        }

        return stringbuilder.toString();
    }
    else {
        return par1Str;
    }
}
 
開發者ID:BubbleTrouble14,項目名稱:ARKCraft,代碼行數:70,代碼來源:SmallFontRenderer.java

示例14: isBidiLayoutRequired

import java.text.Bidi; //導入方法依賴的package包/類
static boolean isBidiLayoutRequired(@NotNull CharSequence text) {
  char[] chars = CharArrayUtil.fromSequence(text);
  return Bidi.requiresBidi(chars, 0, chars.length);
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:5,代碼來源:LineLayout.java

示例15: bidiReorder

import java.text.Bidi; //導入方法依賴的package包/類
/**
 * Apply Unicode Bidirectional Algorithm to string and return a new possibly reordered string for visual rendering.
 */
private String bidiReorder(String par1Str)
{
    if (par1Str != null && Bidi.requiresBidi(par1Str.toCharArray(), 0, par1Str.length()))
    {
        Bidi bidi = new Bidi(par1Str, -2);
        byte[] abyte = new byte[bidi.getRunCount()];
        String[] astring = new String[abyte.length];
        int i;

        for (int j = 0; j < abyte.length; ++j)
        {
            int k = bidi.getRunStart(j);
            i = bidi.getRunLimit(j);
            int l = bidi.getRunLevel(j);
            String s1 = par1Str.substring(k, i);
            abyte[j] = (byte) l;
            astring[j] = s1;
        }

        String[] astring1 = astring.clone();
        Bidi.reorderVisually(abyte, 0, astring, 0, abyte.length);
        StringBuilder stringbuilder = new StringBuilder();
        i = 0;

        while (i < astring.length)
        {
            byte b0 = abyte[i];
            int i1 = 0;

            while (true)
            {
                if (i1 < astring1.length)
                {
                    if (!astring1[i1].equals(astring[i]))
                    {
                        ++i1;
                        continue;
                    }

                    b0 = abyte[i1];
                }

                if ((b0 & 1) == 0)
                {
                    stringbuilder.append(astring[i]);
                }
                else
                {
                    for (i1 = astring[i].length() - 1; i1 >= 0; --i1)
                    {
                        char c0 = astring[i].charAt(i1);

                        if (c0 == 40)
                        {
                            c0 = 41;
                        }
                        else if (c0 == 41)
                        {
                            c0 = 40;
                        }

                        stringbuilder.append(c0);
                    }
                }

                ++i;
                break;
            }
        }

        return stringbuilder.toString();
    }
    else
    {
        return par1Str;
    }
}
 
開發者ID:Archiving,項目名稱:ARKCraft-Code,代碼行數:81,代碼來源:SmallFontRenderer.java


注:本文中的java.text.Bidi.requiresBidi方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。