Java Code Examples for java.text.Bidi#getRunStart()

The following examples show how to use java.text.Bidi#getRunStart() . 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: BidiSurrogateTest.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
void testBidi(String string, int rtlstart, int rtllength) {
    Bidi bidi = new Bidi(string, Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT);
    for (int i = 0; i < bidi.getRunCount(); ++i) {
        if ((bidi.getRunLevel(i) & 1) != 0) {
            if (bidi.getRunStart(i) != rtlstart ||
                bidi.getRunLimit(i) != rtlstart + rtllength) {
                throw new RuntimeException("first rtl run didn't match " + rtlstart + ", " + rtllength);
            }
            break;
        }
    }
}
 
Example 2
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 3
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 4
Source File: BidiSurrogateTest.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
void testBidi(String string, int rtlstart, int rtllength) {
    Bidi bidi = new Bidi(string, Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT);
    for (int i = 0; i < bidi.getRunCount(); ++i) {
        if ((bidi.getRunLevel(i) & 1) != 0) {
            if (bidi.getRunStart(i) != rtlstart ||
                bidi.getRunLimit(i) != rtlstart + rtllength) {
                throw new RuntimeException("first rtl run didn't match " + rtlstart + ", " + rtllength);
            }
            break;
        }
    }
}
 
Example 5
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 6
Source File: BidiSurrogateTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
void testBidi(String string, int rtlstart, int rtllength) {
    Bidi bidi = new Bidi(string, Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT);
    for (int i = 0; i < bidi.getRunCount(); ++i) {
        if ((bidi.getRunLevel(i) & 1) != 0) {
            if (bidi.getRunStart(i) != rtlstart ||
                bidi.getRunLimit(i) != rtlstart + rtllength) {
                throw new RuntimeException("first rtl run didn't match " + rtlstart + ", " + rtllength);
            }
            break;
        }
    }
}
 
Example 7
Source File: BidiSurrogateTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
void testBidi(String string, int rtlstart, int rtllength) {
    Bidi bidi = new Bidi(string, Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT);
    for (int i = 0; i < bidi.getRunCount(); ++i) {
        if ((bidi.getRunLevel(i) & 1) != 0) {
            if (bidi.getRunStart(i) != rtlstart ||
                bidi.getRunLimit(i) != rtlstart + rtllength) {
                throw new RuntimeException("first rtl run didn't match " + rtlstart + ", " + rtllength);
            }
            break;
        }
    }
}
 
Example 8
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 9
Source File: BidiSurrogateTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
void testBidi(String string, int rtlstart, int rtllength) {
    Bidi bidi = new Bidi(string, Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT);
    for (int i = 0; i < bidi.getRunCount(); ++i) {
        if ((bidi.getRunLevel(i) & 1) != 0) {
            if (bidi.getRunStart(i) != rtlstart ||
                bidi.getRunLimit(i) != rtlstart + rtllength) {
                throw new RuntimeException("first rtl run didn't match " + rtlstart + ", " + rtllength);
            }
            break;
        }
    }
}
 
Example 10
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 11
Source File: BidiSurrogateTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
void testBidi(String string, int rtlstart, int rtllength) {
    Bidi bidi = new Bidi(string, Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT);
    for (int i = 0; i < bidi.getRunCount(); ++i) {
        if ((bidi.getRunLevel(i) & 1) != 0) {
            if (bidi.getRunStart(i) != rtlstart ||
                bidi.getRunLimit(i) != rtlstart + rtllength) {
                throw new RuntimeException("first rtl run didn't match " + rtlstart + ", " + rtllength);
            }
            break;
        }
    }
}
 
Example 12
Source File: BidiConformance.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
private void testEachMethod(Bidi bidi,
                            String text,
                            String expectedLevels,
                            boolean expectedBaseIsLTR,
                            boolean expectedIsLTR,
                            boolean expectedIsRTL
                           ) {
    /* Test baseIsLeftToRight() */
    boolean actualBoolean = bidi.baseIsLeftToRight();
    checkResult("baseIsLeftToRight()", expectedBaseIsLTR, actualBoolean);

    /* Test getBaseLevel() */
    int expectedInt = (expectedBaseIsLTR) ? 0 : 1;
    int actualInt = bidi.getBaseLevel();
    checkResult("getBaseLevel()", expectedInt, actualInt);

    /* Test getLength() */
    expectedInt = text.length();
    actualInt = bidi.getLength();
    checkResult("getLength()", expectedInt, actualInt);

    /* Test getLevelAt() */
    sb.setLength(0);
    for (int i = 0; i < text.length(); i++) {
        sb.append(bidi.getLevelAt(i));
    }
    checkResult("getLevelAt()", expectedLevels, sb.toString());

    /* Test getRunCount() */
    expectedInt = getRunCount(expectedLevels);
    actualInt = bidi.getRunCount();
    checkResult("getRunCount()", expectedInt, actualInt);

    /* Test getRunLevel(), getRunLimit() and getRunStart() */
    if (expectedInt == actualInt) {
        int runCount = expectedInt;
        int[] expectedRunLevels = getRunLevels_int(runCount, expectedLevels);
        int[] expectedRunLimits = getRunLimits(runCount, expectedLevels);
        int[] expectedRunStarts = getRunStarts(runCount, expectedLevels);
        int[] actualRunLevels = new int[runCount];
        int[] actualRunLimits = new int[runCount];
        int[] actualRunStarts = new int[runCount];

        for (int k = 0; k < runCount; k++) {
            actualRunLevels[k] = bidi.getRunLevel(k);
            actualRunLimits[k] = bidi.getRunLimit(k);
            actualRunStarts[k] = bidi.getRunStart(k);
        }

        checkResult("getRunLevel()", expectedRunLevels, actualRunLevels);
        checkResult("getRunStart()", expectedRunStarts, actualRunStarts);
        checkResult("getRunLimit()", expectedRunLimits, actualRunLimits);
    }

    /* Test isLeftToRight() */
    boolean expectedBoolean = expectedIsLTR;
    actualBoolean = bidi.isLeftToRight();
    checkResult("isLeftToRight()", expectedBoolean, actualBoolean);

    /* Test isMixed() */
    expectedBoolean = !(expectedIsLTR || expectedIsRTL);
    actualBoolean = bidi.isMixed();
    checkResult("isMixed()", expectedBoolean, actualBoolean);

    /* Test isRightToLeft() */
    expectedBoolean = expectedIsRTL;
    actualBoolean = bidi.isRightToLeft();
    checkResult("isRightToLeft()", expectedBoolean, actualBoolean);
}
 
Example 13
Source File: BidiConformance.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
private void testEachMethod(Bidi bidi,
                            String text,
                            String expectedLevels,
                            boolean expectedBaseIsLTR,
                            boolean expectedIsLTR,
                            boolean expectedIsRTL
                           ) {
    /* Test baseIsLeftToRight() */
    boolean actualBoolean = bidi.baseIsLeftToRight();
    checkResult("baseIsLeftToRight()", expectedBaseIsLTR, actualBoolean);

    /* Test getBaseLevel() */
    int expectedInt = (expectedBaseIsLTR) ? 0 : 1;
    int actualInt = bidi.getBaseLevel();
    checkResult("getBaseLevel()", expectedInt, actualInt);

    /* Test getLength() */
    expectedInt = text.length();
    actualInt = bidi.getLength();
    checkResult("getLength()", expectedInt, actualInt);

    /* Test getLevelAt() */
    sb.setLength(0);
    for (int i = 0; i < text.length(); i++) {
        sb.append(bidi.getLevelAt(i));
    }
    checkResult("getLevelAt()", expectedLevels, sb.toString());

    /* Test getRunCount() */
    expectedInt = getRunCount(expectedLevels);
    actualInt = bidi.getRunCount();
    checkResult("getRunCount()", expectedInt, actualInt);

    /* Test getRunLevel(), getRunLimit() and getRunStart() */
    if (expectedInt == actualInt) {
        int runCount = expectedInt;
        int[] expectedRunLevels = getRunLevels_int(runCount, expectedLevels);
        int[] expectedRunLimits = getRunLimits(runCount, expectedLevels);
        int[] expectedRunStarts = getRunStarts(runCount, expectedLevels);
        int[] actualRunLevels = new int[runCount];
        int[] actualRunLimits = new int[runCount];
        int[] actualRunStarts = new int[runCount];

        for (int k = 0; k < runCount; k++) {
            actualRunLevels[k] = bidi.getRunLevel(k);
            actualRunLimits[k] = bidi.getRunLimit(k);
            actualRunStarts[k] = bidi.getRunStart(k);
        }

        checkResult("getRunLevel()", expectedRunLevels, actualRunLevels);
        checkResult("getRunStart()", expectedRunStarts, actualRunStarts);
        checkResult("getRunLimit()", expectedRunLimits, actualRunLimits);
    }

    /* Test isLeftToRight() */
    boolean expectedBoolean = expectedIsLTR;
    actualBoolean = bidi.isLeftToRight();
    checkResult("isLeftToRight()", expectedBoolean, actualBoolean);

    /* Test isMixed() */
    expectedBoolean = !(expectedIsLTR || expectedIsRTL);
    actualBoolean = bidi.isMixed();
    checkResult("isMixed()", expectedBoolean, actualBoolean);

    /* Test isRightToLeft() */
    expectedBoolean = expectedIsRTL;
    actualBoolean = bidi.isRightToLeft();
    checkResult("isRightToLeft()", expectedBoolean, actualBoolean);
}
 
Example 14
Source File: BidiConformance.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private void testEachMethod(Bidi bidi,
                            String text,
                            String expectedLevels,
                            boolean expectedBaseIsLTR,
                            boolean expectedIsLTR,
                            boolean expectedIsRTL
                           ) {
    /* Test baseIsLeftToRight() */
    boolean actualBoolean = bidi.baseIsLeftToRight();
    checkResult("baseIsLeftToRight()", expectedBaseIsLTR, actualBoolean);

    /* Test getBaseLevel() */
    int expectedInt = (expectedBaseIsLTR) ? 0 : 1;
    int actualInt = bidi.getBaseLevel();
    checkResult("getBaseLevel()", expectedInt, actualInt);

    /* Test getLength() */
    expectedInt = text.length();
    actualInt = bidi.getLength();
    checkResult("getLength()", expectedInt, actualInt);

    /* Test getLevelAt() */
    sb.setLength(0);
    for (int i = 0; i < text.length(); i++) {
        sb.append(bidi.getLevelAt(i));
    }
    checkResult("getLevelAt()", expectedLevels, sb.toString());

    /* Test getRunCount() */
    expectedInt = getRunCount(expectedLevels);
    actualInt = bidi.getRunCount();
    checkResult("getRunCount()", expectedInt, actualInt);

    /* Test getRunLevel(), getRunLimit() and getRunStart() */
    if (expectedInt == actualInt) {
        int runCount = expectedInt;
        int[] expectedRunLevels = getRunLevels_int(runCount, expectedLevels);
        int[] expectedRunLimits = getRunLimits(runCount, expectedLevels);
        int[] expectedRunStarts = getRunStarts(runCount, expectedLevels);
        int[] actualRunLevels = new int[runCount];
        int[] actualRunLimits = new int[runCount];
        int[] actualRunStarts = new int[runCount];

        for (int k = 0; k < runCount; k++) {
            actualRunLevels[k] = bidi.getRunLevel(k);
            actualRunLimits[k] = bidi.getRunLimit(k);
            actualRunStarts[k] = bidi.getRunStart(k);
        }

        checkResult("getRunLevel()", expectedRunLevels, actualRunLevels);
        checkResult("getRunStart()", expectedRunStarts, actualRunStarts);
        checkResult("getRunLimit()", expectedRunLimits, actualRunLimits);
    }

    /* Test isLeftToRight() */
    boolean expectedBoolean = expectedIsLTR;
    actualBoolean = bidi.isLeftToRight();
    checkResult("isLeftToRight()", expectedBoolean, actualBoolean);

    /* Test isMixed() */
    expectedBoolean = !(expectedIsLTR || expectedIsRTL);
    actualBoolean = bidi.isMixed();
    checkResult("isMixed()", expectedBoolean, actualBoolean);

    /* Test isRightToLeft() */
    expectedBoolean = expectedIsRTL;
    actualBoolean = bidi.isRightToLeft();
    checkResult("isRightToLeft()", expectedBoolean, actualBoolean);
}
 
Example 15
Source File: BidiConformance.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
private void testEachMethod(Bidi bidi,
                            String text,
                            String expectedLevels,
                            boolean expectedBaseIsLTR,
                            boolean expectedIsLTR,
                            boolean expectedIsRTL
                           ) {
    /* Test baseIsLeftToRight() */
    boolean actualBoolean = bidi.baseIsLeftToRight();
    checkResult("baseIsLeftToRight()", expectedBaseIsLTR, actualBoolean);

    /* Test getBaseLevel() */
    int expectedInt = (expectedBaseIsLTR) ? 0 : 1;
    int actualInt = bidi.getBaseLevel();
    checkResult("getBaseLevel()", expectedInt, actualInt);

    /* Test getLength() */
    expectedInt = text.length();
    actualInt = bidi.getLength();
    checkResult("getLength()", expectedInt, actualInt);

    /* Test getLevelAt() */
    sb.setLength(0);
    for (int i = 0; i < text.length(); i++) {
        sb.append(bidi.getLevelAt(i));
    }
    checkResult("getLevelAt()", expectedLevels, sb.toString());

    /* Test getRunCount() */
    expectedInt = getRunCount(expectedLevels);
    actualInt = bidi.getRunCount();
    checkResult("getRunCount()", expectedInt, actualInt);

    /* Test getRunLevel(), getRunLimit() and getRunStart() */
    if (expectedInt == actualInt) {
        int runCount = expectedInt;
        int[] expectedRunLevels = getRunLevels_int(runCount, expectedLevels);
        int[] expectedRunLimits = getRunLimits(runCount, expectedLevels);
        int[] expectedRunStarts = getRunStarts(runCount, expectedLevels);
        int[] actualRunLevels = new int[runCount];
        int[] actualRunLimits = new int[runCount];
        int[] actualRunStarts = new int[runCount];

        for (int k = 0; k < runCount; k++) {
            actualRunLevels[k] = bidi.getRunLevel(k);
            actualRunLimits[k] = bidi.getRunLimit(k);
            actualRunStarts[k] = bidi.getRunStart(k);
        }

        checkResult("getRunLevel()", expectedRunLevels, actualRunLevels);
        checkResult("getRunStart()", expectedRunStarts, actualRunStarts);
        checkResult("getRunLimit()", expectedRunLimits, actualRunLimits);
    }

    /* Test isLeftToRight() */
    boolean expectedBoolean = expectedIsLTR;
    actualBoolean = bidi.isLeftToRight();
    checkResult("isLeftToRight()", expectedBoolean, actualBoolean);

    /* Test isMixed() */
    expectedBoolean = !(expectedIsLTR || expectedIsRTL);
    actualBoolean = bidi.isMixed();
    checkResult("isMixed()", expectedBoolean, actualBoolean);

    /* Test isRightToLeft() */
    expectedBoolean = expectedIsRTL;
    actualBoolean = bidi.isRightToLeft();
    checkResult("isRightToLeft()", expectedBoolean, actualBoolean);
}
 
Example 16
Source File: BidiConformance.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
private void testEachMethod(Bidi bidi,
                            String text,
                            String expectedLevels,
                            boolean expectedBaseIsLTR,
                            boolean expectedIsLTR,
                            boolean expectedIsRTL
                           ) {
    /* Test baseIsLeftToRight() */
    boolean actualBoolean = bidi.baseIsLeftToRight();
    checkResult("baseIsLeftToRight()", expectedBaseIsLTR, actualBoolean);

    /* Test getBaseLevel() */
    int expectedInt = (expectedBaseIsLTR) ? 0 : 1;
    int actualInt = bidi.getBaseLevel();
    checkResult("getBaseLevel()", expectedInt, actualInt);

    /* Test getLength() */
    expectedInt = text.length();
    actualInt = bidi.getLength();
    checkResult("getLength()", expectedInt, actualInt);

    /* Test getLevelAt() */
    sb.setLength(0);
    for (int i = 0; i < text.length(); i++) {
        sb.append(bidi.getLevelAt(i));
    }
    checkResult("getLevelAt()", expectedLevels, sb.toString());

    /* Test getRunCount() */
    expectedInt = getRunCount(expectedLevels);
    actualInt = bidi.getRunCount();
    checkResult("getRunCount()", expectedInt, actualInt);

    /* Test getRunLevel(), getRunLimit() and getRunStart() */
    if (expectedInt == actualInt) {
        int runCount = expectedInt;
        int[] expectedRunLevels = getRunLevels_int(runCount, expectedLevels);
        int[] expectedRunLimits = getRunLimits(runCount, expectedLevels);
        int[] expectedRunStarts = getRunStarts(runCount, expectedLevels);
        int[] actualRunLevels = new int[runCount];
        int[] actualRunLimits = new int[runCount];
        int[] actualRunStarts = new int[runCount];

        for (int k = 0; k < runCount; k++) {
            actualRunLevels[k] = bidi.getRunLevel(k);
            actualRunLimits[k] = bidi.getRunLimit(k);
            actualRunStarts[k] = bidi.getRunStart(k);
        }

        checkResult("getRunLevel()", expectedRunLevels, actualRunLevels);
        checkResult("getRunStart()", expectedRunStarts, actualRunStarts);
        checkResult("getRunLimit()", expectedRunLimits, actualRunLimits);
    }

    /* Test isLeftToRight() */
    boolean expectedBoolean = expectedIsLTR;
    actualBoolean = bidi.isLeftToRight();
    checkResult("isLeftToRight()", expectedBoolean, actualBoolean);

    /* Test isMixed() */
    expectedBoolean = !(expectedIsLTR || expectedIsRTL);
    actualBoolean = bidi.isMixed();
    checkResult("isMixed()", expectedBoolean, actualBoolean);

    /* Test isRightToLeft() */
    expectedBoolean = expectedIsRTL;
    actualBoolean = bidi.isRightToLeft();
    checkResult("isRightToLeft()", expectedBoolean, actualBoolean);
}
 
Example 17
Source File: BidiConformance.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
private void testEachMethod(Bidi bidi,
                            String text,
                            String expectedLevels,
                            boolean expectedBaseIsLTR,
                            boolean expectedIsLTR,
                            boolean expectedIsRTL
                           ) {
    /* Test baseIsLeftToRight() */
    boolean actualBoolean = bidi.baseIsLeftToRight();
    checkResult("baseIsLeftToRight()", expectedBaseIsLTR, actualBoolean);

    /* Test getBaseLevel() */
    int expectedInt = (expectedBaseIsLTR) ? 0 : 1;
    int actualInt = bidi.getBaseLevel();
    checkResult("getBaseLevel()", expectedInt, actualInt);

    /* Test getLength() */
    expectedInt = text.length();
    actualInt = bidi.getLength();
    checkResult("getLength()", expectedInt, actualInt);

    /* Test getLevelAt() */
    sb.setLength(0);
    for (int i = 0; i < text.length(); i++) {
        sb.append(bidi.getLevelAt(i));
    }
    checkResult("getLevelAt()", expectedLevels, sb.toString());

    /* Test getRunCount() */
    expectedInt = getRunCount(expectedLevels);
    actualInt = bidi.getRunCount();
    checkResult("getRunCount()", expectedInt, actualInt);

    /* Test getRunLevel(), getRunLimit() and getRunStart() */
    if (expectedInt == actualInt) {
        int runCount = expectedInt;
        int[] expectedRunLevels = getRunLevels_int(runCount, expectedLevels);
        int[] expectedRunLimits = getRunLimits(runCount, expectedLevels);
        int[] expectedRunStarts = getRunStarts(runCount, expectedLevels);
        int[] actualRunLevels = new int[runCount];
        int[] actualRunLimits = new int[runCount];
        int[] actualRunStarts = new int[runCount];

        for (int k = 0; k < runCount; k++) {
            actualRunLevels[k] = bidi.getRunLevel(k);
            actualRunLimits[k] = bidi.getRunLimit(k);
            actualRunStarts[k] = bidi.getRunStart(k);
        }

        checkResult("getRunLevel()", expectedRunLevels, actualRunLevels);
        checkResult("getRunStart()", expectedRunStarts, actualRunStarts);
        checkResult("getRunLimit()", expectedRunLimits, actualRunLimits);
    }

    /* Test isLeftToRight() */
    boolean expectedBoolean = expectedIsLTR;
    actualBoolean = bidi.isLeftToRight();
    checkResult("isLeftToRight()", expectedBoolean, actualBoolean);

    /* Test isMixed() */
    expectedBoolean = !(expectedIsLTR || expectedIsRTL);
    actualBoolean = bidi.isMixed();
    checkResult("isMixed()", expectedBoolean, actualBoolean);

    /* Test isRightToLeft() */
    expectedBoolean = expectedIsRTL;
    actualBoolean = bidi.isRightToLeft();
    checkResult("isRightToLeft()", expectedBoolean, actualBoolean);
}
 
Example 18
Source File: BidiConformance.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
private void testEachMethod(Bidi bidi,
                            String text,
                            String expectedLevels,
                            boolean expectedBaseIsLTR,
                            boolean expectedIsLTR,
                            boolean expectedIsRTL
                           ) {
    /* Test baseIsLeftToRight() */
    boolean actualBoolean = bidi.baseIsLeftToRight();
    checkResult("baseIsLeftToRight()", expectedBaseIsLTR, actualBoolean);

    /* Test getBaseLevel() */
    int expectedInt = (expectedBaseIsLTR) ? 0 : 1;
    int actualInt = bidi.getBaseLevel();
    checkResult("getBaseLevel()", expectedInt, actualInt);

    /* Test getLength() */
    expectedInt = text.length();
    actualInt = bidi.getLength();
    checkResult("getLength()", expectedInt, actualInt);

    /* Test getLevelAt() */
    sb.setLength(0);
    for (int i = 0; i < text.length(); i++) {
        sb.append(bidi.getLevelAt(i));
    }
    checkResult("getLevelAt()", expectedLevels, sb.toString());

    /* Test getRunCount() */
    expectedInt = getRunCount(expectedLevels);
    actualInt = bidi.getRunCount();
    checkResult("getRunCount()", expectedInt, actualInt);

    /* Test getRunLevel(), getRunLimit() and getRunStart() */
    if (expectedInt == actualInt) {
        int runCount = expectedInt;
        int[] expectedRunLevels = getRunLevels_int(runCount, expectedLevels);
        int[] expectedRunLimits = getRunLimits(runCount, expectedLevels);
        int[] expectedRunStarts = getRunStarts(runCount, expectedLevels);
        int[] actualRunLevels = new int[runCount];
        int[] actualRunLimits = new int[runCount];
        int[] actualRunStarts = new int[runCount];

        for (int k = 0; k < runCount; k++) {
            actualRunLevels[k] = bidi.getRunLevel(k);
            actualRunLimits[k] = bidi.getRunLimit(k);
            actualRunStarts[k] = bidi.getRunStart(k);
        }

        checkResult("getRunLevel()", expectedRunLevels, actualRunLevels);
        checkResult("getRunStart()", expectedRunStarts, actualRunStarts);
        checkResult("getRunLimit()", expectedRunLimits, actualRunLimits);
    }

    /* Test isLeftToRight() */
    boolean expectedBoolean = expectedIsLTR;
    actualBoolean = bidi.isLeftToRight();
    checkResult("isLeftToRight()", expectedBoolean, actualBoolean);

    /* Test isMixed() */
    expectedBoolean = !(expectedIsLTR || expectedIsRTL);
    actualBoolean = bidi.isMixed();
    checkResult("isMixed()", expectedBoolean, actualBoolean);

    /* Test isRightToLeft() */
    expectedBoolean = expectedIsRTL;
    actualBoolean = bidi.isRightToLeft();
    checkResult("isRightToLeft()", expectedBoolean, actualBoolean);
}
 
Example 19
Source File: BidiUtils.java    From sambox with Apache 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 text The word that shall be processed
 * @return new word with the correct direction of the containing characters
 */
public static String visualToLogical(String text)
{
    if (!CharUtils.isBlank(text))
    {
        Bidi bidi = new Bidi(text, Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT);
        if (!bidi.isLeftToRight())
        {
            // 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 = text.charAt(end);
                        if (Character.isMirrored(text.codePointAt(end))
                                && MIRRORING_CHAR_MAP.containsKey(character))
                        {
                            result.append(MIRRORING_CHAR_MAP.get(character));
                        }
                        else
                        {
                            result.append(character);
                        }
                    }
                }
                else
                {
                    result.append(text, start, end);
                }
            }

            return result.toString();
        }
    }
    return text;
}
 
Example 20
Source File: BidiConformance.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
private void testEachMethod(Bidi bidi,
                            String text,
                            String expectedLevels,
                            boolean expectedBaseIsLTR,
                            boolean expectedIsLTR,
                            boolean expectedIsRTL
                           ) {
    /* Test baseIsLeftToRight() */
    boolean actualBoolean = bidi.baseIsLeftToRight();
    checkResult("baseIsLeftToRight()", expectedBaseIsLTR, actualBoolean);

    /* Test getBaseLevel() */
    int expectedInt = (expectedBaseIsLTR) ? 0 : 1;
    int actualInt = bidi.getBaseLevel();
    checkResult("getBaseLevel()", expectedInt, actualInt);

    /* Test getLength() */
    expectedInt = text.length();
    actualInt = bidi.getLength();
    checkResult("getLength()", expectedInt, actualInt);

    /* Test getLevelAt() */
    sb.setLength(0);
    for (int i = 0; i < text.length(); i++) {
        sb.append(bidi.getLevelAt(i));
    }
    checkResult("getLevelAt()", expectedLevels, sb.toString());

    /* Test getRunCount() */
    expectedInt = getRunCount(expectedLevels);
    actualInt = bidi.getRunCount();
    checkResult("getRunCount()", expectedInt, actualInt);

    /* Test getRunLevel(), getRunLimit() and getRunStart() */
    if (expectedInt == actualInt) {
        int runCount = expectedInt;
        int[] expectedRunLevels = getRunLevels_int(runCount, expectedLevels);
        int[] expectedRunLimits = getRunLimits(runCount, expectedLevels);
        int[] expectedRunStarts = getRunStarts(runCount, expectedLevels);
        int[] actualRunLevels = new int[runCount];
        int[] actualRunLimits = new int[runCount];
        int[] actualRunStarts = new int[runCount];

        for (int k = 0; k < runCount; k++) {
            actualRunLevels[k] = bidi.getRunLevel(k);
            actualRunLimits[k] = bidi.getRunLimit(k);
            actualRunStarts[k] = bidi.getRunStart(k);
        }

        checkResult("getRunLevel()", expectedRunLevels, actualRunLevels);
        checkResult("getRunStart()", expectedRunStarts, actualRunStarts);
        checkResult("getRunLimit()", expectedRunLimits, actualRunLimits);
    }

    /* Test isLeftToRight() */
    boolean expectedBoolean = expectedIsLTR;
    actualBoolean = bidi.isLeftToRight();
    checkResult("isLeftToRight()", expectedBoolean, actualBoolean);

    /* Test isMixed() */
    expectedBoolean = !(expectedIsLTR || expectedIsRTL);
    actualBoolean = bidi.isMixed();
    checkResult("isMixed()", expectedBoolean, actualBoolean);

    /* Test isRightToLeft() */
    expectedBoolean = expectedIsRTL;
    actualBoolean = bidi.isRightToLeft();
    checkResult("isRightToLeft()", expectedBoolean, actualBoolean);
}