Пример #1
0
  public void testSimpleHebrewParagraph() {
    bd = new Bidi("\u05D0", Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT);
    assertFalse(bd.baseIsLeftToRight());
    assertEquals(1, bd.getBaseLevel());
    assertEquals(1, bd.getLength());
    assertEquals(1, bd.getLevelAt(0));
    assertEquals(1, bd.getLevelAt(1000));
    assertEquals(1, bd.getRunCount());
    assertRunArrayEquals(
        new int[][] {
          {0, 1, 1},
        },
        bd);
    assertFalse(bd.isLeftToRight());
    assertFalse(bd.isMixed());
    assertTrue(bd.isRightToLeft());

    bd = new Bidi("\u05D0", Bidi.DIRECTION_DEFAULT_RIGHT_TO_LEFT);
    assertFalse(bd.baseIsLeftToRight());
    assertEquals(1, bd.getBaseLevel());
    assertEquals(1, bd.getLength());
    assertEquals(1, bd.getLevelAt(0));
    assertEquals(1, bd.getLevelAt(1000));
    assertEquals(1, bd.getRunCount());
    assertRunArrayEquals(
        new int[][] {
          {0, 1, 1},
        },
        bd);
    assertFalse(bd.isLeftToRight());
    assertFalse(bd.isMixed());
    assertTrue(bd.isRightToLeft());

    bd = new Bidi("\u05D0", Bidi.DIRECTION_RIGHT_TO_LEFT);
    assertFalse(bd.baseIsLeftToRight());
    assertEquals(1, bd.getBaseLevel());
    assertEquals(1, bd.getLength());
    assertEquals(1, bd.getLevelAt(0));
    assertEquals(1, bd.getLevelAt(1000));
    assertEquals(1, bd.getRunCount());
    assertRunArrayEquals(
        new int[][] {
          {0, 1, 1},
        },
        bd);
    assertFalse(bd.isLeftToRight());
    assertFalse(bd.isMixed());
    assertTrue(bd.isRightToLeft());
  }
Пример #2
0
  /** Generate components for the paragraph. fChars, fBidi should have been initialized already. */
  private void generateComponents(int startingAt, int endingAt) {

    if (collectStats) {
      formattedChars += (endingAt - startingAt);
    }
    int layoutFlags = 0; // no extra info yet, bidi determines run and line direction
    TextLabelFactory factory = new TextLabelFactory(fFrc, fChars, fBidi, layoutFlags);

    int[] charsLtoV = null;

    if (fBidi != null) {
      fLevels = BidiUtils.getLevels(fBidi);
      int[] charsVtoL = BidiUtils.createVisualToLogicalMap(fLevels);
      charsLtoV = BidiUtils.createInverseMap(charsVtoL);
      fIsDirectionLTR = fBidi.baseIsLeftToRight();
    } else {
      fLevels = null;
      fIsDirectionLTR = true;
    }

    try {
      fComponents =
          TextLine.getComponents(
              fParagraph, fChars, startingAt, endingAt, charsLtoV, fLevels, factory);
    } catch (IllegalArgumentException e) {
      System.out.println("startingAt=" + startingAt + "; endingAt=" + endingAt);
      System.out.println("fComponentLimit=" + fComponentLimit);
      throw e;
    }

    fComponentStart = startingAt;
    fComponentLimit = endingAt;
    // debugFormatCount += (endingAt-startingAt);
  }
Пример #3
0
 public void testCreateLineBidi() {
   bd =
       new Bidi(
           "a\u05D0a\u05D0a\u05D0\"\u05D0a".toCharArray(),
           0,
           new byte[] {0, 0, 0, -3, -3, 2, 2, 0, 3},
           0,
           9,
           Bidi.DIRECTION_RIGHT_TO_LEFT);
   Bidi line = bd.createLineBidi(2, 7);
   assertFalse(line.baseIsLeftToRight());
   assertEquals(1, line.getBaseLevel());
   assertEquals(5, line.getLength());
   assertEquals(2, line.getLevelAt(0));
   assertEquals(3, line.getLevelAt(1));
   assertEquals(3, line.getLevelAt(2));
   assertEquals(3, line.getLevelAt(3));
   assertEquals(2, line.getLevelAt(4));
   assertEquals(1, line.getLevelAt(1000));
   assertEquals(3, line.getRunCount());
   assertRunArrayEquals(
       new int[][] {
         {0, 1, 2}, {1, 4, 3}, {4, 5, 2},
       },
       line);
   assertFalse(line.isLeftToRight());
   assertTrue(line.isMixed());
   assertFalse(line.isRightToLeft());
 }
Пример #4
0
 public void testComplicatedOverrideBidi() {
   bd =
       new Bidi(
           "a\u05D0a\"a\u05D0\"\u05D0a".toCharArray(),
           0,
           new byte[] {0, 0, 0, -3, -3, 2, 2, 0, 3},
           0,
           9,
           Bidi.DIRECTION_RIGHT_TO_LEFT);
   assertFalse(bd.baseIsLeftToRight());
   assertEquals(1, bd.getBaseLevel());
   assertEquals(9, bd.getLength());
   assertEquals(2, bd.getLevelAt(0));
   assertEquals(1, bd.getLevelAt(1));
   assertEquals(2, bd.getLevelAt(2));
   assertEquals(3, bd.getLevelAt(3));
   assertEquals(3, bd.getLevelAt(4));
   assertEquals(3, bd.getLevelAt(5));
   assertEquals(2, bd.getLevelAt(6));
   assertEquals(1, bd.getLevelAt(7));
   assertEquals(4, bd.getLevelAt(8));
   assertEquals(1, bd.getLevelAt(1000));
   assertEquals(7, bd.getRunCount());
   assertRunArrayEquals(
       new int[][] {
         {0, 1, 2}, {1, 2, 1}, {2, 3, 2}, {3, 6, 3}, {6, 7, 2}, {7, 8, 1}, {8, 9, 4},
       },
       bd);
   assertFalse(bd.isLeftToRight());
   assertTrue(bd.isMixed());
   assertFalse(bd.isRightToLeft());
 }
Пример #5
0
 public void testComplicatedBidi() {
   bd = new Bidi("a\u05D0a\"a\u05D0\"\u05D0a", Bidi.DIRECTION_RIGHT_TO_LEFT);
   assertFalse(bd.baseIsLeftToRight());
   assertEquals(1, bd.getBaseLevel());
   assertEquals(9, bd.getLength());
   assertEquals(2, bd.getLevelAt(0));
   assertEquals(1, bd.getLevelAt(1));
   assertEquals(2, bd.getLevelAt(2));
   assertEquals(2, bd.getLevelAt(3));
   assertEquals(2, bd.getLevelAt(4));
   assertEquals(1, bd.getLevelAt(5));
   assertEquals(1, bd.getLevelAt(6));
   assertEquals(1, bd.getLevelAt(7));
   assertEquals(2, bd.getLevelAt(8));
   assertEquals(1, bd.getLevelAt(1000));
   assertEquals(5, bd.getRunCount());
   assertRunArrayEquals(
       new int[][] {
         {0, 1, 2}, {1, 2, 1}, {2, 5, 2}, {5, 8, 1}, {8, 9, 2},
       },
       bd);
   assertFalse(bd.isLeftToRight());
   assertTrue(bd.isMixed());
   assertFalse(bd.isRightToLeft());
 }
Пример #6
0
 public void testRelativeEmbeddings() {
   bd =
       new Bidi(
           new char[] {'s', 's', 's'},
           0,
           new byte[] {(byte) 1, (byte) 2, (byte) 3},
           0,
           3,
           Bidi.DIRECTION_RIGHT_TO_LEFT);
   assertFalse(bd.baseIsLeftToRight());
   assertEquals(1, bd.getBaseLevel());
   assertEquals(3, bd.getLength());
   assertEquals(2, bd.getLevelAt(0));
   assertEquals(2, bd.getLevelAt(1));
   assertEquals(4, bd.getLevelAt(2));
   assertEquals(1, bd.getLevelAt(1000));
   assertEquals(2, bd.getRunCount());
   assertRunArrayEquals(
       new int[][] {
         {0, 2, 2}, {2, 3, 4},
       },
       bd);
   assertFalse(bd.isLeftToRight());
   assertTrue(bd.isMixed());
   assertFalse(bd.isRightToLeft());
 }
Пример #7
0
 public void testIncompatibleLineAlgorithm() {
   // ICU treat a new line as in the same run, however RI does not
   bd =
       new Bidi(
           "aaaaa".toCharArray(),
           0,
           new byte[] {-2, -1, -3, -3, -2},
           0,
           5,
           Bidi.DIRECTION_RIGHT_TO_LEFT);
   Bidi line = bd.createLineBidi(1, 4);
   assertFalse(line.baseIsLeftToRight());
   assertEquals(1, line.getBaseLevel());
   assertEquals(3, line.getLength());
   assertEquals(1, line.getLevelAt(0));
   assertEquals(1, line.getLevelAt(1));
   assertEquals(1, line.getLevelAt(2));
   assertEquals(1, line.getLevelAt(1000));
   assertEquals(1, line.getRunCount());
   assertRunArrayEquals(
       new int[][] {
         {0, 3, 1},
       },
       line);
   assertFalse(line.isLeftToRight());
   assertFalse(line.isMixed());
   assertTrue(line.isRightToLeft());
 }
Пример #8
0
 // this is essentially the same bug as Bug_1
 public void testRIBug_2() {
   bd = new Bidi("\u05D0", Bidi.DIRECTION_LEFT_TO_RIGHT);
   assertTrue(bd.baseIsLeftToRight());
   assertEquals(0, bd.getBaseLevel());
   assertEquals(1, bd.getLength());
   assertEquals(1, bd.getLevelAt(0));
   assertEquals(0, bd.getLevelAt(1000));
   assertEquals(1, bd.getRunCount());
   assertRunArrayEquals(
       new int[][] {
         {0, 1, 1},
       },
       bd);
   assertFalse(bd.isLeftToRight());
   assertTrue(bd.isMixed());
   assertFalse(bd.isRightToLeft());
 }
Пример #9
0
 public void testBadFlags() {
   bd = new Bidi("", 173);
   assertTrue(bd.baseIsLeftToRight());
   assertEquals(0, bd.getBaseLevel());
   assertEquals(0, bd.getLength());
   assertEquals(0, bd.getLevelAt(0));
   assertEquals(0, bd.getLevelAt(1000));
   assertEquals(1, bd.getRunCount());
   assertRunArrayEquals(
       new int[][] {
         {0, 0, 0},
       },
       bd);
   assertTrue(bd.isLeftToRight());
   assertFalse(bd.isMixed());
   assertFalse(bd.isRightToLeft());
 }
Пример #10
0
 /*
  * spec reads: public static final int DIRECTION_RIGHT_TO_LEFT Constant
  * indicating base direction is right-to-left. according to that, the method
  * baseIsLeftToRight() here should return false. however, RI doesn't act so.
  */
 public void testRIBug_1() {
   bd = new Bidi("t", Bidi.DIRECTION_RIGHT_TO_LEFT);
   assertFalse(bd.baseIsLeftToRight());
   // the base level it the essential cause
   assertEquals(1, bd.getBaseLevel());
   assertEquals(1, bd.getLength());
   assertEquals(2, bd.getLevelAt(0));
   assertEquals(1, bd.getLevelAt(1000));
   assertEquals(1, bd.getRunCount());
   assertRunArrayEquals(
       new int[][] {
         {0, 1, 2},
       },
       bd);
   assertFalse(bd.isLeftToRight());
   assertTrue(bd.isMixed());
   assertFalse(bd.isRightToLeft());
 }
Пример #11
0
  public void testHebrewOverrideEmbeddings() {
    bd =
        new Bidi(
            new char[] {'\u05D0', '\u05D0', '\u05D0'},
            0,
            new byte[] {(byte) -1, (byte) -2, (byte) -3},
            0,
            3,
            Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT);
    assertFalse(bd.baseIsLeftToRight());
    assertEquals(1, bd.getBaseLevel());
    assertEquals(3, bd.getLength());
    assertEquals(1, bd.getLevelAt(0));
    assertEquals(2, bd.getLevelAt(1));
    assertEquals(3, bd.getLevelAt(2));
    assertEquals(1, bd.getLevelAt(1000));
    assertEquals(3, bd.getRunCount());
    assertRunArrayEquals(
        new int[][] {
          {0, 1, 1}, {1, 2, 2}, {2, 3, 3},
        },
        bd);
    assertFalse(bd.isLeftToRight());
    assertTrue(bd.isMixed());
    assertFalse(bd.isRightToLeft());

    bd =
        new Bidi(
            new char[] {'\u05D0', '\u05D0', '\u05D0'},
            0,
            new byte[] {(byte) -1, (byte) -2, (byte) -3},
            0,
            3,
            Bidi.DIRECTION_DEFAULT_RIGHT_TO_LEFT);
    assertFalse(bd.baseIsLeftToRight());
    assertEquals(1, bd.getBaseLevel());
    assertEquals(3, bd.getLength());
    assertEquals(1, bd.getLevelAt(0));
    assertEquals(2, bd.getLevelAt(1));
    assertEquals(3, bd.getLevelAt(2));
    assertEquals(1, bd.getLevelAt(1000));
    assertEquals(3, bd.getRunCount());
    assertRunArrayEquals(
        new int[][] {
          {0, 1, 1}, {1, 2, 2}, {2, 3, 3},
        },
        bd);
    assertFalse(bd.isLeftToRight());
    assertTrue(bd.isMixed());
    assertFalse(bd.isRightToLeft());

    bd =
        new Bidi(
            new char[] {'\u05D0', '\u05D0', '\u05D0'},
            0,
            new byte[] {(byte) -1, (byte) -2, (byte) -3},
            0,
            3,
            Bidi.DIRECTION_LEFT_TO_RIGHT);
    assertTrue(bd.baseIsLeftToRight());
    assertEquals(0, bd.getBaseLevel());
    assertEquals(3, bd.getLength());
    assertEquals(1, bd.getLevelAt(0));
    assertEquals(2, bd.getLevelAt(1));
    assertEquals(3, bd.getLevelAt(2));
    assertEquals(0, bd.getLevelAt(1000));
    assertEquals(3, bd.getRunCount());
    assertRunArrayEquals(
        new int[][] {
          {0, 1, 1}, {1, 2, 2}, {2, 3, 3},
        },
        bd);
    assertFalse(bd.isLeftToRight());
    assertTrue(bd.isMixed());
    assertFalse(bd.isRightToLeft());

    bd =
        new Bidi(
            new char[] {'\u05D0', '\u05D0', '\u05D0'},
            0,
            new byte[] {(byte) -1, (byte) -2, (byte) -3},
            0,
            3,
            Bidi.DIRECTION_RIGHT_TO_LEFT);
    assertFalse(bd.baseIsLeftToRight());
    assertEquals(1, bd.getBaseLevel());
    assertEquals(3, bd.getLength());
    assertEquals(1, bd.getLevelAt(0));
    assertEquals(2, bd.getLevelAt(1));
    assertEquals(3, bd.getLevelAt(2));
    assertEquals(1, bd.getLevelAt(1000));
    assertEquals(3, bd.getRunCount());
    assertRunArrayEquals(
        new int[][] {
          {0, 1, 1}, {1, 2, 2}, {2, 3, 3},
        },
        bd);
    assertFalse(bd.isLeftToRight());
    assertTrue(bd.isMixed());
    assertFalse(bd.isRightToLeft());
  }