Java Code Examples for java.text.Bidi#DIRECTION_LEFT_TO_RIGHT

The following examples show how to use java.text.Bidi#DIRECTION_LEFT_TO_RIGHT . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EditorView.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void reinitSettings() {
  assertIsDispatchThread();
  synchronized (myLock) {
    myPlainSpaceWidth = -1;
    myTabSize = -1;
    setFontRenderContext(null);
  }
  switch (EditorSettingsExternalizable.getInstance().getBidiTextDirection()) {
    case LTR:
      myBidiFlags = Bidi.DIRECTION_LEFT_TO_RIGHT;
      break;
    case RTL:
      myBidiFlags = Bidi.DIRECTION_RIGHT_TO_LEFT;
      break;
    default:
      myBidiFlags = Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT;
  }
  myLogicalPositionCache.reset(false);
  myTextLayoutCache.resetToDocumentSize(false);
  invalidateFoldRegionLayouts();
  myCharWidthCache.clear();
  setPrefix(myPrefixText, myPrefixAttributes); // recreate prefix layout
  mySizeManager.reset();
}
 
Example 2
Source File: Bug8005277.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    boolean err = false;
    String string = "\u05D0\u05D1\u05D2";
    Bidi bidi = new Bidi(string, Bidi.DIRECTION_LEFT_TO_RIGHT);

    int result = bidi.getRunCount();
    if (result != 1) {
        System.err.println("Incorrect run count: " + result);
        err = true;
    }

    result = bidi.getRunStart(0);
    if (result != 0) {
        System.err.println("Incorrect run start: " + result);
        err = true;
    }

    result = bidi.getRunLimit(0);
    if (result != 3) {
        System.err.println("Incorrect run limit: " + result);
        err = true;
    }

    result = bidi.getRunLevel(0);
    if (result != 1) {
        System.err.println("Incorrect run level: " + result);
        err = true;
    }

    if (err) {
        throw new RuntimeException("Failed.");
    }
}
 
Example 3
Source File: Bug8005277.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    boolean err = false;
    String string = "\u05D0\u05D1\u05D2";
    Bidi bidi = new Bidi(string, Bidi.DIRECTION_LEFT_TO_RIGHT);

    int result = bidi.getRunCount();
    if (result != 1) {
        System.err.println("Incorrect run count: " + result);
        err = true;
    }

    result = bidi.getRunStart(0);
    if (result != 0) {
        System.err.println("Incorrect run start: " + result);
        err = true;
    }

    result = bidi.getRunLimit(0);
    if (result != 3) {
        System.err.println("Incorrect run limit: " + result);
        err = true;
    }

    result = bidi.getRunLevel(0);
    if (result != 1) {
        System.err.println("Incorrect run level: " + result);
        err = true;
    }

    if (err) {
        throw new RuntimeException("Failed.");
    }
}
 
Example 4
Source File: Bug8005277.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    boolean err = false;
    String string = "\u05D0\u05D1\u05D2";
    Bidi bidi = new Bidi(string, Bidi.DIRECTION_LEFT_TO_RIGHT);

    int result = bidi.getRunCount();
    if (result != 1) {
        System.err.println("Incorrect run count: " + result);
        err = true;
    }

    result = bidi.getRunStart(0);
    if (result != 0) {
        System.err.println("Incorrect run start: " + result);
        err = true;
    }

    result = bidi.getRunLimit(0);
    if (result != 3) {
        System.err.println("Incorrect run limit: " + result);
        err = true;
    }

    result = bidi.getRunLevel(0);
    if (result != 1) {
        System.err.println("Incorrect run level: " + result);
        err = true;
    }

    if (err) {
        throw new RuntimeException("Failed.");
    }
}
 
Example 5
Source File: Bug8005277.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    boolean err = false;
    String string = "\u05D0\u05D1\u05D2";
    Bidi bidi = new Bidi(string, Bidi.DIRECTION_LEFT_TO_RIGHT);

    int result = bidi.getRunCount();
    if (result != 1) {
        System.err.println("Incorrect run count: " + result);
        err = true;
    }

    result = bidi.getRunStart(0);
    if (result != 0) {
        System.err.println("Incorrect run start: " + result);
        err = true;
    }

    result = bidi.getRunLimit(0);
    if (result != 3) {
        System.err.println("Incorrect run limit: " + result);
        err = true;
    }

    result = bidi.getRunLevel(0);
    if (result != 1) {
        System.err.println("Incorrect run level: " + result);
        err = true;
    }

    if (err) {
        throw new RuntimeException("Failed.");
    }
}
 
Example 6
Source File: Bug8005277.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    boolean err = false;
    String string = "\u05D0\u05D1\u05D2";
    Bidi bidi = new Bidi(string, Bidi.DIRECTION_LEFT_TO_RIGHT);

    int result = bidi.getRunCount();
    if (result != 1) {
        System.err.println("Incorrect run count: " + result);
        err = true;
    }

    result = bidi.getRunStart(0);
    if (result != 0) {
        System.err.println("Incorrect run start: " + result);
        err = true;
    }

    result = bidi.getRunLimit(0);
    if (result != 3) {
        System.err.println("Incorrect run limit: " + result);
        err = true;
    }

    result = bidi.getRunLevel(0);
    if (result != 1) {
        System.err.println("Incorrect run level: " + result);
        err = true;
    }

    if (err) {
        throw new RuntimeException("Failed.");
    }
}
 
Example 7
Source File: Bug8005277.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    boolean err = false;
    String string = "\u05D0\u05D1\u05D2";
    Bidi bidi = new Bidi(string, Bidi.DIRECTION_LEFT_TO_RIGHT);

    int result = bidi.getRunCount();
    if (result != 1) {
        System.err.println("Incorrect run count: " + result);
        err = true;
    }

    result = bidi.getRunStart(0);
    if (result != 0) {
        System.err.println("Incorrect run start: " + result);
        err = true;
    }

    result = bidi.getRunLimit(0);
    if (result != 3) {
        System.err.println("Incorrect run limit: " + result);
        err = true;
    }

    result = bidi.getRunLevel(0);
    if (result != 1) {
        System.err.println("Incorrect run level: " + result);
        err = true;
    }

    if (err) {
        throw new RuntimeException("Failed.");
    }
}
 
Example 8
Source File: Bug8005277.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    boolean err = false;
    String string = "\u05D0\u05D1\u05D2";
    Bidi bidi = new Bidi(string, Bidi.DIRECTION_LEFT_TO_RIGHT);

    int result = bidi.getRunCount();
    if (result != 1) {
        System.err.println("Incorrect run count: " + result);
        err = true;
    }

    result = bidi.getRunStart(0);
    if (result != 0) {
        System.err.println("Incorrect run start: " + result);
        err = true;
    }

    result = bidi.getRunLimit(0);
    if (result != 3) {
        System.err.println("Incorrect run limit: " + result);
        err = true;
    }

    result = bidi.getRunLevel(0);
    if (result != 1) {
        System.err.println("Incorrect run level: " + result);
        err = true;
    }

    if (err) {
        throw new RuntimeException("Failed.");
    }
}
 
Example 9
Source File: Bug8005277.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    boolean err = false;
    String string = "\u05D0\u05D1\u05D2";
    Bidi bidi = new Bidi(string, Bidi.DIRECTION_LEFT_TO_RIGHT);

    int result = bidi.getRunCount();
    if (result != 1) {
        System.err.println("Incorrect run count: " + result);
        err = true;
    }

    result = bidi.getRunStart(0);
    if (result != 0) {
        System.err.println("Incorrect run start: " + result);
        err = true;
    }

    result = bidi.getRunLimit(0);
    if (result != 3) {
        System.err.println("Incorrect run limit: " + result);
        err = true;
    }

    result = bidi.getRunLevel(0);
    if (result != 1) {
        System.err.println("Incorrect run level: " + result);
        err = true;
    }

    if (err) {
        throw new RuntimeException("Failed.");
    }
}
 
Example 10
Source File: Bug8005277.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    boolean err = false;
    String string = "\u05D0\u05D1\u05D2";
    Bidi bidi = new Bidi(string, Bidi.DIRECTION_LEFT_TO_RIGHT);

    int result = bidi.getRunCount();
    if (result != 1) {
        System.err.println("Incorrect run count: " + result);
        err = true;
    }

    result = bidi.getRunStart(0);
    if (result != 0) {
        System.err.println("Incorrect run start: " + result);
        err = true;
    }

    result = bidi.getRunLimit(0);
    if (result != 3) {
        System.err.println("Incorrect run limit: " + result);
        err = true;
    }

    result = bidi.getRunLevel(0);
    if (result != 1) {
        System.err.println("Incorrect run level: " + result);
        err = true;
    }

    if (err) {
        throw new RuntimeException("Failed.");
    }
}
 
Example 11
Source File: Bug8005277.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    boolean err = false;
    String string = "\u05D0\u05D1\u05D2";
    Bidi bidi = new Bidi(string, Bidi.DIRECTION_LEFT_TO_RIGHT);

    int result = bidi.getRunCount();
    if (result != 1) {
        System.err.println("Incorrect run count: " + result);
        err = true;
    }

    result = bidi.getRunStart(0);
    if (result != 0) {
        System.err.println("Incorrect run start: " + result);
        err = true;
    }

    result = bidi.getRunLimit(0);
    if (result != 3) {
        System.err.println("Incorrect run limit: " + result);
        err = true;
    }

    result = bidi.getRunLevel(0);
    if (result != 1) {
        System.err.println("Incorrect run level: " + result);
        err = true;
    }

    if (err) {
        throw new RuntimeException("Failed.");
    }
}
 
Example 12
Source File: Bug8005277.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    boolean err = false;
    String string = "\u05D0\u05D1\u05D2";
    Bidi bidi = new Bidi(string, Bidi.DIRECTION_LEFT_TO_RIGHT);

    int result = bidi.getRunCount();
    if (result != 1) {
        System.err.println("Incorrect run count: " + result);
        err = true;
    }

    result = bidi.getRunStart(0);
    if (result != 0) {
        System.err.println("Incorrect run start: " + result);
        err = true;
    }

    result = bidi.getRunLimit(0);
    if (result != 3) {
        System.err.println("Incorrect run limit: " + result);
        err = true;
    }

    result = bidi.getRunLevel(0);
    if (result != 1) {
        System.err.println("Incorrect run level: " + result);
        err = true;
    }

    if (err) {
        throw new RuntimeException("Failed.");
    }
}
 
Example 13
Source File: Bug8005277.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    boolean err = false;
    String string = "\u05D0\u05D1\u05D2";
    Bidi bidi = new Bidi(string, Bidi.DIRECTION_LEFT_TO_RIGHT);

    int result = bidi.getRunCount();
    if (result != 1) {
        System.err.println("Incorrect run count: " + result);
        err = true;
    }

    result = bidi.getRunStart(0);
    if (result != 0) {
        System.err.println("Incorrect run start: " + result);
        err = true;
    }

    result = bidi.getRunLimit(0);
    if (result != 3) {
        System.err.println("Incorrect run limit: " + result);
        err = true;
    }

    result = bidi.getRunLevel(0);
    if (result != 1) {
        System.err.println("Incorrect run level: " + result);
        err = true;
    }

    if (err) {
        throw new RuntimeException("Failed.");
    }
}
 
Example 14
Source File: Bug8005277.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    boolean err = false;
    String string = "\u05D0\u05D1\u05D2";
    Bidi bidi = new Bidi(string, Bidi.DIRECTION_LEFT_TO_RIGHT);

    int result = bidi.getRunCount();
    if (result != 1) {
        System.err.println("Incorrect run count: " + result);
        err = true;
    }

    result = bidi.getRunStart(0);
    if (result != 0) {
        System.err.println("Incorrect run start: " + result);
        err = true;
    }

    result = bidi.getRunLimit(0);
    if (result != 3) {
        System.err.println("Incorrect run limit: " + result);
        err = true;
    }

    result = bidi.getRunLevel(0);
    if (result != 1) {
        System.err.println("Incorrect run level: " + result);
        err = true;
    }

    if (err) {
        throw new RuntimeException("Failed.");
    }
}
 
Example 15
Source File: PDFTextStripper.java    From gcs with Mozilla Public License 2.0 4 votes vote down vote up
/**
 * Handles the LTR and RTL direction of the given words. The whole implementation stands and falls with the given
 * word. If the word is a full line, the results will be the best. If the word contains of single words or
 * characters, the order of the characters in a word or words in a line may wrong, due to RTL and LTR marks and
 * characters!
 * 
 * Based on http://www.nesterovsky-bros.com/weblog/2013/07/28/VisualToLogicalConversionInJava.aspx
 * 
 * @param word The word that shall be processed
 * @return new word with the correct direction of the containing characters
 */
private String handleDirection(String word)
{
    Bidi bidi = new Bidi(word, Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT);

    // if there is pure LTR text no need to process further
    if (!bidi.isMixed() && bidi.getBaseLevel() == Bidi.DIRECTION_LEFT_TO_RIGHT)
    {
        return word;
    }
    
    // collect individual bidi information
    int runCount = bidi.getRunCount();
    byte[] levels = new byte[runCount];
    Integer[] runs = new Integer[runCount];
  
    for (int i = 0; i < runCount; i++)
    {
       levels[i] = (byte)bidi.getRunLevel(i);
       runs[i] = i;
    }

    // reorder individual parts based on their levels
    Bidi.reorderVisually(levels, 0, runs, 0, runCount);
    
    // collect the parts based on the direction within the run
    StringBuilder result = new StringBuilder();

    for (int i = 0; i < runCount; i++)
    {
       int index = runs[i];
       int start = bidi.getRunStart(index);
       int end = bidi.getRunLimit(index);

        int level = levels[index];

        if ((level & 1) != 0)
        {
            while (--end >= start)
            {
                char character = word.charAt(end);
                if (Character.isMirrored(word.codePointAt(end)))
                {
                    if (MIRRORING_CHAR_MAP.containsKey(character))
                    {
                        result.append(MIRRORING_CHAR_MAP.get(character));
                    }
                    else
                    {
                        result.append(character);
                    }
                }
                else
                {
                    result.append(character);
                }
            }
        }
        else
        {
            result.append(word, start, end);
        }
    }
    
    return result.toString();
}
 
Example 16
Source File: UIUtil.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Get Bidi level of Expression String.
 * 
 * @param message
 * @return
 */
public static int[] getExpressionBidiLevel( String message )
{
	java.text.Bidi bidi = new Bidi( message,
	// Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT );
			Bidi.DIRECTION_LEFT_TO_RIGHT ); // bidi_hcg
	int[] level = new int[message.length( )];
	boolean bidiStart = false;
	Stack<Character> bracket = new Stack<Character>( );
	for ( int i = 0; i < message.length( ); i++ )
	{
		char c = message.charAt( i );
		if ( isNeutral( c ) )
		{
			// Neutral char enclosed with ' or " should bidi with surround
			// bidichar.
			// otherwise should not bidi.
			if ( c == '\'' || c == '\"' )
			{
				if ( bracket.empty( ) )
				{
					bracket.add( Character.valueOf( c ) );
				}
				else
				{
					if ( bracket.peek( ).charValue( ) == c )
					{
						bracket.pop( );
						bidiStart = false;
					}
					else
					{
						bracket.add( Character.valueOf( c ) );
					}
				}
			}
			level[i] = bidiStart && !bracket.empty( ) ? 1 : 0;
		}
		else
		{
			level[i] = bidi.getLevelAt( i );
			if ( level[i] % 2 != 0 )
			{
				bidiStart = true;
			}
		}
	}
	return level;
}