Search in sources :

Example 21 with Bidi

use of java.text.Bidi in project jdk8u_jdk by JetBrains.

the class Bug8005277 method main.

public static void main(String[] args) {
    boolean err = false;
    String string = "אבג";
    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.");
    }
}
Also used : Bidi(java.text.Bidi)

Example 22 with Bidi

use of java.text.Bidi in project jdk8u_jdk by JetBrains.

the class BidiConformance method testConstructor2.

private void testConstructor2() {
    Bidi bidi;
    try {
        bidi = new Bidi(null, Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT);
        errorHandling("Bidi((String)null, DIRECTION_DEFAULT_LEFT_TO_RIGHT)" + " should throw an IAE.");
    } catch (IllegalArgumentException e) {
    } catch (NullPointerException e) {
        errorHandling("Bidi((String)null, DIRECTION_DEFAULT_LEFT_TO_RIGHT) " + "should not throw an NPE but an IAE.");
    }
    try {
        bidi = new Bidi("abc", -3);
    } catch (Exception e) {
        errorHandling("Bidi(\"abc\", -3) should not throw an exception: " + e);
    }
    try {
        bidi = new Bidi("abc", 2);
    } catch (Exception e) {
        errorHandling("Bidi(\"abc\", 2) should not throw an exception: " + e);
    }
}
Also used : Bidi(java.text.Bidi)

Example 23 with Bidi

use of java.text.Bidi in project jdk8u_jdk by JetBrains.

the class BidiConformance method testMethods4Constructor1.

private void testMethods4Constructor1() {
    System.out.println("*** Test methods for constructor 1");
    String paragraph;
    Bidi bidi;
    NumericShaper ns = NumericShaper.getShaper(NumericShaper.ARABIC);
    for (int textNo = 0; textNo < data4Constructor1.length; textNo++) {
        paragraph = data4Constructor1[textNo][0];
        int start = paragraph.indexOf('<') + 1;
        int limit = paragraph.indexOf('>');
        int testNo;
        System.out.println("*** Test textNo=" + textNo + ": Bidi(AttributedCharacterIterator\"" + toReadableString(paragraph) + "\") " + "  start=" + start + ", limit=" + limit);
        // Test 0
        testNo = 0;
        System.out.println(" Test#" + testNo + ": RUN_DIRECTION_LTR");
        AttributedString astr = new AttributedString(paragraph);
        astr.addAttribute(TextAttribute.RUN_DIRECTION, TextAttribute.RUN_DIRECTION_LTR);
        bidi = new Bidi(astr.getIterator());
        callTestEachMethod4Constructor1(textNo, testNo, bidi);
        // Test 1
        ++testNo;
        System.out.println(" Test#" + testNo + ": RUN_DIRECTION_LTR, BIDI_EMBEDDING(1)");
        astr = new AttributedString(paragraph);
        astr.addAttribute(TextAttribute.RUN_DIRECTION, TextAttribute.RUN_DIRECTION_LTR);
        astr.addAttribute(TextAttribute.BIDI_EMBEDDING, new Integer(1), start, limit);
        bidi = new Bidi(astr.getIterator());
        callTestEachMethod4Constructor1(textNo, testNo, bidi);
        // Test 2
        ++testNo;
        System.out.println(" Test#" + testNo + ": RUN_DIERCTION_LTR, BIDI_EMBEDDING(2)");
        astr = new AttributedString(paragraph);
        astr.addAttribute(TextAttribute.RUN_DIRECTION, TextAttribute.RUN_DIRECTION_LTR);
        astr.addAttribute(TextAttribute.BIDI_EMBEDDING, new Integer(2), start, limit);
        bidi = new Bidi(astr.getIterator());
        callTestEachMethod4Constructor1(textNo, testNo, bidi);
        // Test 3
        ++testNo;
        System.out.println(" Test#" + testNo + ": RUN_DIRECTIOIN_LTR, BIDI_EMBEDDING(-3)");
        astr = new AttributedString(paragraph);
        astr.addAttribute(TextAttribute.RUN_DIRECTION, TextAttribute.RUN_DIRECTION_LTR);
        astr.addAttribute(TextAttribute.BIDI_EMBEDDING, new Integer(-3), start, limit);
        bidi = new Bidi(astr.getIterator());
        callTestEachMethod4Constructor1(textNo, testNo, bidi);
        // Test 4
        ++testNo;
        System.out.println(" Test#" + testNo + ": RUN_DIRECTION_LTR, BIDI_EMBEDDING(-4)");
        astr = new AttributedString(paragraph);
        astr.addAttribute(TextAttribute.RUN_DIRECTION, TextAttribute.RUN_DIRECTION_LTR);
        astr.addAttribute(TextAttribute.BIDI_EMBEDDING, new Integer(-4), start, limit);
        bidi = new Bidi(astr.getIterator());
        callTestEachMethod4Constructor1(textNo, testNo, bidi);
        // Test 5
        ++testNo;
        System.out.println(" Test#" + testNo + ": RUN_DIRECTION_RTL");
        astr = new AttributedString(paragraph);
        astr.addAttribute(TextAttribute.RUN_DIRECTION, TextAttribute.RUN_DIRECTION_RTL);
        bidi = new Bidi(astr.getIterator());
        callTestEachMethod4Constructor1(textNo, testNo, bidi);
        // Test 6
        ++testNo;
        System.out.println(" Test#" + testNo + ": RUN_DIRECTION_RTL, BIDI_EMBEDDING(1)");
        astr = new AttributedString(paragraph);
        astr.addAttribute(TextAttribute.RUN_DIRECTION, TextAttribute.RUN_DIRECTION_RTL);
        astr.addAttribute(TextAttribute.BIDI_EMBEDDING, new Integer(1), start, limit);
        try {
            bidi = new Bidi(astr.getIterator());
            callTestEachMethod4Constructor1(textNo, testNo, bidi);
        } catch (IllegalArgumentException e) {
            errorHandling("  Unexpected exception: " + e);
        }
        // Test 7
        ++testNo;
        System.out.println(" Test#" + testNo + ": RUN_DIRECTION_RTL, BIDI_EMBEDDING(2)");
        astr = new AttributedString(paragraph);
        astr.addAttribute(TextAttribute.RUN_DIRECTION, TextAttribute.RUN_DIRECTION_RTL);
        astr.addAttribute(TextAttribute.BIDI_EMBEDDING, new Integer(2), start, limit);
        try {
            bidi = new Bidi(astr.getIterator());
            callTestEachMethod4Constructor1(textNo, testNo, bidi);
        } catch (IllegalArgumentException e) {
            errorHandling("  Unexpected exception: " + e);
        }
        // Test 8
        ++testNo;
        System.out.println(" Test#" + testNo + ": RUN_DIRECTION_RTL, BIDI_EMBEDDING(-3)");
        astr = new AttributedString(paragraph);
        astr.addAttribute(TextAttribute.RUN_DIRECTION, TextAttribute.RUN_DIRECTION_RTL);
        astr.addAttribute(TextAttribute.BIDI_EMBEDDING, new Integer(-3), start, limit);
        try {
            bidi = new Bidi(astr.getIterator());
            callTestEachMethod4Constructor1(textNo, testNo, bidi);
        } catch (IllegalArgumentException e) {
            errorHandling("  Unexpected exception: " + e);
        }
        // Test 9
        ++testNo;
        System.out.println(" Test#" + testNo + ": RUN_DIRECTION_RTL, BIDI_EMBEDDING(-4)");
        astr = new AttributedString(paragraph);
        astr.addAttribute(TextAttribute.RUN_DIRECTION, TextAttribute.RUN_DIRECTION_RTL);
        astr.addAttribute(TextAttribute.BIDI_EMBEDDING, new Integer(-4), start, limit);
        try {
            bidi = new Bidi(astr.getIterator());
            callTestEachMethod4Constructor1(textNo, testNo, bidi);
        } catch (IllegalArgumentException e) {
            errorHandling("  Unexpected exception: " + e);
        }
        // Test 10
        ++testNo;
        System.out.println(" Test#" + testNo + ": TextAttribute not specified");
        astr = new AttributedString(paragraph);
        bidi = new Bidi(astr.getIterator());
        callTestEachMethod4Constructor1(textNo, testNo, bidi);
        // Test 11
        ++testNo;
        System.out.println(" Test#" + testNo + ": RUN_DIRECTION_LTR, NUMERIC_SHAPING(ARABIC)");
        astr = new AttributedString(paragraph);
        astr.addAttribute(TextAttribute.RUN_DIRECTION, TextAttribute.RUN_DIRECTION_LTR);
        astr.addAttribute(TextAttribute.NUMERIC_SHAPING, ns);
        bidi = new Bidi(astr.getIterator());
        callTestEachMethod4Constructor1(textNo, testNo, bidi);
        // Test 12
        ++testNo;
        System.out.println(" Test#" + testNo + ": RUN_DIRECTION_RTL, NUMERIC_SHAPING(ARABIC)");
        astr = new AttributedString(paragraph);
        astr.addAttribute(TextAttribute.RUN_DIRECTION, TextAttribute.RUN_DIRECTION_RTL);
        astr.addAttribute(TextAttribute.NUMERIC_SHAPING, ns);
        bidi = new Bidi(astr.getIterator());
        callTestEachMethod4Constructor1(textNo, testNo, bidi);
    }
}
Also used : Bidi(java.text.Bidi) NumericShaper(java.awt.font.NumericShaper) AttributedString(java.text.AttributedString) AttributedString(java.text.AttributedString)

Example 24 with Bidi

use of java.text.Bidi in project jdk8u_jdk by JetBrains.

the class BidiConformance method testConstructor1.

private void testConstructor1() {
    Bidi bidi;
    try {
        bidi = new Bidi(null);
        errorHandling("Bidi((AttributedCharacterIterator)null) " + "should throw an IAE.");
    } catch (IllegalArgumentException e) {
    } catch (NullPointerException e) {
        errorHandling("Bidi((AttributedCharacterIterator)null) " + "should not throw an NPE but an IAE.");
    }
    String paragraph = data4Constructor1[1][0];
    int start = paragraph.indexOf('<') + 1;
    int limit = paragraph.indexOf('>');
    AttributedString astr = new AttributedString(paragraph);
    astr.addAttribute(TextAttribute.RUN_DIRECTION, TextAttribute.RUN_DIRECTION_RTL);
    astr.addAttribute(TextAttribute.BIDI_EMBEDDING, new Integer(-61), start, limit);
    try {
        bidi = new Bidi(astr.getIterator());
        for (int i = start; i < limit; i++) {
            if (bidi.getLevelAt(i) != 61) {
                errorHandling("Bidi(AttributedCharacterIterator).getLevelAt(" + i + ") should not be " + bidi.getLevelAt(i) + " but 60 when BIDI_EMBEDDING is -61.");
            }
        }
    } catch (Exception e) {
        errorHandling("  Unexpected exception: " + e);
    }
    astr = new AttributedString(paragraph);
    astr.addAttribute(TextAttribute.RUN_DIRECTION, TextAttribute.RUN_DIRECTION_RTL);
    astr.addAttribute(TextAttribute.BIDI_EMBEDDING, new Integer(-62), start, limit);
    try {
        bidi = new Bidi(astr.getIterator());
        for (int i = start; i < limit; i++) {
            if (bidi.getLevelAt(i) != 1) {
                errorHandling("Bidi(AttributedCharacterIterator).getLevelAt() " + "should be 1 when BIDI_EMBEDDING is -62.");
            }
        }
    } catch (Exception e) {
        errorHandling("  Unexpected exception: " + e);
    }
    astr = new AttributedString(paragraph);
    astr.addAttribute(TextAttribute.RUN_DIRECTION, TextAttribute.RUN_DIRECTION_RTL);
    astr.addAttribute(TextAttribute.BIDI_EMBEDDING, new Integer(60), start, limit);
    try {
        bidi = new Bidi(astr.getIterator());
        for (int i = start; i < limit; i++) {
            if (bidi.getLevelAt(i) != 61) {
                errorHandling("Bidi(AttributedCharacterIterator).getLevelAt() " + "should be 61 when BIDI_EMBEDDING is 60.");
            }
        }
    } catch (Exception e) {
        errorHandling("  Unexpected exception: " + e);
    }
    astr = new AttributedString(paragraph);
    astr.addAttribute(TextAttribute.RUN_DIRECTION, TextAttribute.RUN_DIRECTION_RTL);
    astr.addAttribute(TextAttribute.BIDI_EMBEDDING, new Integer(61), start, limit);
    try {
        bidi = new Bidi(astr.getIterator());
        for (int i = start; i < limit; i++) {
            if (bidi.getLevelAt(i) != 61) {
                errorHandling("Bidi(AttributedCharacterIterator).getLevelAt(" + i + ") should not be " + bidi.getLevelAt(i) + " but 61 when BIDI_EMBEDDING is 61.");
            }
        }
    } catch (Exception e) {
        errorHandling("  Unexpected exception: " + e);
    }
    astr = new AttributedString(paragraph);
    astr.addAttribute(TextAttribute.RUN_DIRECTION, TextAttribute.RUN_DIRECTION_RTL);
    astr.addAttribute(TextAttribute.BIDI_EMBEDDING, new Integer(62), start, limit);
    try {
        bidi = new Bidi(astr.getIterator());
        for (int i = start; i < limit; i++) {
            if (bidi.getLevelAt(i) != 1) {
                errorHandling("Bidi(AttributedCharacterIterator).getLevelAt()" + " should not be " + bidi.getLevelAt(i) + " but 1 when BIDI_EMBEDDING is 62.");
            }
        }
    } catch (Exception e) {
        errorHandling("  Unexpected exception: " + e);
    }
}
Also used : Bidi(java.text.Bidi) AttributedString(java.text.AttributedString) AttributedString(java.text.AttributedString)

Example 25 with Bidi

use of java.text.Bidi in project jdk8u_jdk by JetBrains.

the class BidiConformance method testMethod_getLevelAt.

/*
     * Confirm that getLevelAt() doesn't throw an exception for invalid offset
     * unlike ICU4J.
     */
private void testMethod_getLevelAt() {
    System.out.println("*** Test getLevelAt()");
    Bidi bidi = new Bidi(data4Constructor1[1][0], FLAGS[0]);
    int len = data4Constructor1[1][0].length();
    try {
        int level = bidi.getLevelAt(-1);
        if (level != bidi.getBaseLevel()) {
            errorHandling("getLevelAt(-1) returned a wrong level." + " Expected=" + bidi.getBaseLevel() + ", got=" + level);
        }
    } catch (Exception e) {
        errorHandling("getLevelAt(-1) should not throw an exception.");
    }
    try {
        int level = bidi.getLevelAt(len + 1);
        if (level != bidi.getBaseLevel()) {
            errorHandling("getLevelAt(textLength+1)" + " returned a wrong level." + " Expected=" + bidi.getBaseLevel() + ", got=" + level);
        }
    } catch (Exception e) {
        errorHandling("getLevelAt(-1) should not throw an exception.");
    }
}
Also used : Bidi(java.text.Bidi)

Aggregations

Bidi (java.text.Bidi)30 AttributedString (java.text.AttributedString)11 TextLineComponent (sun.font.TextLineComponent)3 TextLabelFactory (sun.font.TextLabelFactory)2 Font (java.awt.Font)1 NumericShaper (java.awt.font.NumericShaper)1 Hashtable (java.util.Hashtable)1 AttributeValues (sun.font.AttributeValues)1 Decoration (sun.font.Decoration)1