Пример #1
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());
 }
Пример #2
0
  public static void assertRunArrayEquals(int[][] expected, Bidi bidi) {
    assertEquals("different length", expected.length, bidi.getRunCount());

    FORRUN:
    for (int i = 0; i < bidi.getRunCount(); i++) {
      int[] butWas = new int[] {bidi.getRunStart(i), bidi.getRunLimit(i), bidi.getRunLevel(i)};

      for (int j = 0; j < expected.length; j++) {
        if (expected[j][0] == butWas[0]
            && expected[j][1] == butWas[1]
            && expected[j][2] == butWas[2]) {
          continue FORRUN;
        }
      }
      fail(
          "expected ["
              + i
              + "] "
              + " start: "
              + butWas[0]
              + " limit: "
              + butWas[1]
              + " level: "
              + butWas[2]);
    }
  }
 private static void addRuns(List<BidiRun> runs, char[] text, int start, int end) {
   if (start >= end) return;
   Bidi bidi = new Bidi(text, start, null, 0, end - start, Bidi.DIRECTION_LEFT_TO_RIGHT);
   int runCount = bidi.getRunCount();
   for (int i = 0; i < runCount; i++) {
     addOrMergeRun(
         runs,
         new BidiRun(
             (byte) bidi.getRunLevel(i),
             start + bidi.getRunStart(i),
             start + bidi.getRunLimit(i)));
   }
 }
Пример #4
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);
  }
Пример #5
0
  private TextLine makeTextLineOnRange(int startPos, int limitPos) {

    int[] charsLtoV = null;
    byte[] charLevels = null;

    if (fBidi != null) {
      Bidi lineBidi = fBidi.createLineBidi(startPos, limitPos);
      charLevels = BidiUtils.getLevels(lineBidi);
      int[] charsVtoL = BidiUtils.createVisualToLogicalMap(charLevels);
      charsLtoV = BidiUtils.createInverseMap(charsVtoL);
    }

    TextLineComponent[] components = makeComponentsOnRange(startPos, limitPos);

    return new TextLine(
        fFrc,
        components,
        fBaselineOffsets,
        fChars,
        startPos,
        limitPos,
        charsLtoV,
        charLevels,
        fIsDirectionLTR);
  }
Пример #6
0
  /**
   * Updates the <code>TextMeasurer</code> after a single character has been deleted from the
   * paragraph currently represented by this <code>TextMeasurer</code>. After this call, this <code>
   * TextMeasurer</code> is equivalent to a new <code>TextMeasurer</code> created from the text;
   * however, it will usually be more efficient to update an existing <code>TextMeasurer</code> than
   * to create a new one from scratch.
   *
   * @param newParagraph the text of the paragraph after performing the deletion. Cannot be null.
   * @param deletePos the position in the text where the character was removed. Must not be less
   *     than the start of <code>newParagraph</code>, and must not be greater than the end of <code>
   *     newParagraph</code>.
   * @throws IndexOutOfBoundsException if <code>deletePos</code> is less than the start of <code>
   *     newParagraph</code> or greater than the end of <code>newParagraph</code>
   * @throws NullPointerException if <code>newParagraph</code> is <code>null</code>
   */
  public void deleteChar(AttributedCharacterIterator newParagraph, int deletePos) {

    fStart = newParagraph.getBeginIndex();
    int end = newParagraph.getEndIndex();
    if (end - fStart != fChars.length - 1) {
      initAll(newParagraph);
    }

    char[] newChars = new char[end - fStart];
    int changedIndex = deletePos - fStart;

    System.arraycopy(fChars, 0, newChars, 0, deletePos - fStart);
    System.arraycopy(fChars, changedIndex + 1, newChars, changedIndex, end - deletePos);
    fChars = newChars;

    if (fBidi != null) {
      fBidi = new Bidi(newParagraph);
      if (fBidi.isLeftToRight()) {
        fBidi = null;
      }
    }

    fParagraph = StyledParagraph.deleteChar(newParagraph, fChars, deletePos, fParagraph);
    invalidateComponents();
  }
Пример #7
0
  private String func_78283_c(String p_78283_1_) {
    if (p_78283_1_ != null && Bidi.requiresBidi(p_78283_1_.toCharArray(), 0, p_78283_1_.length())) {
      Bidi var2 = new Bidi(p_78283_1_, -2);
      byte[] var3 = new byte[var2.getRunCount()];
      String[] var4 = new String[var3.length];

      int var7;
      for (int var5 = 0; var5 < var3.length; ++var5) {
        int var6 = var2.getRunStart(var5);
        var7 = var2.getRunLimit(var5);
        int var8 = var2.getRunLevel(var5);
        String var9 = p_78283_1_.substring(var6, var7);
        var3[var5] = (byte) var8;
        var4[var5] = var9;
      }

      String[] var11 = (String[]) var4.clone();
      Bidi.reorderVisually(var3, 0, var4, 0, var3.length);
      StringBuilder var12 = new StringBuilder();
      var7 = 0;

      while (var7 < var4.length) {
        byte var13 = var3[var7];
        int var14 = 0;

        while (true) {
          if (var14 < var11.length) {
            if (!var11[var14].equals(var4[var7])) {
              ++var14;
              continue;
            }

            var13 = var3[var14];
          }

          if ((var13 & 1) == 0) {
            var12.append(var4[var7]);
          } else {
            for (var14 = var4[var7].length() - 1; var14 >= 0; --var14) {
              char var10 = var4[var7].charAt(var14);
              if (var10 == 40) {
                var10 = 41;
              } else if (var10 == 41) {
                var10 = 40;
              }

              var12.append(var10);
            }
          }

          ++var7;
          break;
        }
      }

      return var12.toString();
    } else {
      return p_78283_1_;
    }
  }
 private static void reorderRunsVisually(BidiRun[] bidiRunsInLogicalOrder) {
   if (bidiRunsInLogicalOrder.length > 1) {
     byte[] levels = new byte[bidiRunsInLogicalOrder.length];
     for (int i = 0; i < bidiRunsInLogicalOrder.length; i++) {
       levels[i] = bidiRunsInLogicalOrder[i].level;
     }
     Bidi.reorderVisually(levels, 0, bidiRunsInLogicalOrder, 0, levels.length);
   }
 }
Пример #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
 // 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());
 }
Пример #11
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());
 }
Пример #12
0
  public void testGetRuns() {
    // Regression test for Harmony-1028

    String LTR = "\u0061\u0062";
    String RTL = "\u05DC\u05DD";
    String newLine = "\n";
    String defText = LTR + newLine + RTL + LTR + RTL;

    int[][] expectedRuns = {
      {0, 3},
      {3, 5},
      {5, 7},
      {7, 9},
    };

    Bidi bi = new Bidi(defText, 0);
    final int count = bi.getRunCount();
    for (int i = 0; i < count; i++) {
      assertEquals(expectedRuns[i][0], bi.getRunStart(i));
      assertEquals(expectedRuns[i][1], bi.getRunLimit(i));
    }
  }
Пример #13
0
  /**
   * Updates the <code>TextMeasurer</code> after a single character has been inserted into the
   * paragraph currently represented by this <code>TextMeasurer</code>. After this call, this <code>
   * TextMeasurer</code> is equivalent to a new <code>TextMeasurer</code> created from the text;
   * however, it will usually be more efficient to update an existing <code>TextMeasurer</code> than
   * to create a new one from scratch.
   *
   * @param newParagraph the text of the paragraph after performing the insertion. Cannot be null.
   * @param insertPos the position in the text where the character was inserted. Must not be less
   *     than the start of <code>newParagraph</code>, and must be less than the end of <code>
   *     newParagraph</code>.
   * @throws IndexOutOfBoundsException if <code>insertPos</code> is less than the start of <code>
   *     newParagraph</code> or greater than or equal to the end of <code>newParagraph</code>
   * @throws NullPointerException if <code>newParagraph</code> is <code>null</code>
   */
  public void insertChar(AttributedCharacterIterator newParagraph, int insertPos) {

    if (collectStats) {
      printStats();
    }
    if (wantStats) {
      collectStats = true;
    }

    fStart = newParagraph.getBeginIndex();
    int end = newParagraph.getEndIndex();
    if (end - fStart != fChars.length + 1) {
      initAll(newParagraph);
    }

    char[] newChars = new char[end - fStart];
    int newCharIndex = insertPos - fStart;
    System.arraycopy(fChars, 0, newChars, 0, newCharIndex);

    char newChar = newParagraph.setIndex(insertPos);
    newChars[newCharIndex] = newChar;
    System.arraycopy(fChars, newCharIndex, newChars, newCharIndex + 1, end - insertPos - 1);
    fChars = newChars;

    if (fBidi != null
        || Bidi.requiresBidi(newChars, newCharIndex, newCharIndex + 1)
        || newParagraph.getAttribute(TextAttribute.BIDI_EMBEDDING) != null) {

      fBidi = new Bidi(newParagraph);
      if (fBidi.isLeftToRight()) {
        fBidi = null;
      }
    }

    fParagraph = StyledParagraph.insertChar(newParagraph, fChars, insertPos, fParagraph);
    invalidateComponents();
  }
Пример #14
0
  public void testReorderVisually() {
    String[] init = new String[] {"a", "b", "c", "d"};
    String[] s = new String[4];

    System.arraycopy(init, 0, s, 0, s.length);
    Bidi.reorderVisually(new byte[] {2, 1, 3, 0}, 0, s, 0, 4);
    assertEquals("[c, b, a, d]", Arrays.asList(s).toString());

    System.arraycopy(init, 0, s, 0, s.length);
    Bidi.reorderVisually(new byte[] {1, 3}, 0, s, 1, 2);
    assertEquals("[a, c, b, d]", Arrays.asList(s).toString());

    System.arraycopy(init, 0, s, 0, s.length);
    Bidi.reorderVisually(new byte[] {2, 1, 3, 0}, 1, s, 1, 2);
    assertEquals("[a, c, b, d]", Arrays.asList(s).toString());

    System.arraycopy(init, 0, s, 0, s.length);
    Bidi.reorderVisually(new byte[] {2, 1, 2, 1}, 1, s, 0, 3);
    assertEquals("[c, b, a, d]", Arrays.asList(s).toString());

    System.arraycopy(init, 0, s, 0, s.length);
    Bidi.reorderVisually(new byte[] {2, 1, 0, 1}, 1, s, 0, 3);
    assertEquals("[a, b, c, d]", Arrays.asList(s).toString());
  }
Пример #15
0
  public void testOne(TestHarness harness, String input, String levels, String expected) {
    Object[] inputA = new Object[input.length()];
    byte[] levelsA = new byte[levels.length()];

    for (int i = 0; i < input.length(); ++i) {
      inputA[i] = input.substring(i, i + 1);
      levelsA[i] = (byte) (levels.charAt(i) - '0');
    }

    Bidi.reorderVisually(levelsA, 0, inputA, 0, inputA.length);

    StringBuffer result = new StringBuffer();
    for (int i = 0; i < inputA.length; ++i) result.append(inputA[i]);

    harness.check(result.toString(), expected);
  }
Пример #16
0
  public void testCreateLineBidiInvalid() {
    // regression for HARMONY-1050
    Bidi bidi = new Bidi("str", 1);
    try {
      bidi.createLineBidi(-1, 1);
      fail("Expected IAE");
    } catch (IllegalArgumentException e) {
      // Expected
    }

    try {
      bidi.createLineBidi(1, -1);
      fail("Expected IAE");
    } catch (IllegalArgumentException e) {
      // Expected
    }

    try {
      bidi.createLineBidi(-1, -1);
      fail("Expected IAE");
    } catch (IllegalArgumentException e) {
      // Expected
    }

    try {
      bidi.createLineBidi(2, 1);
      fail("Expected IAE");
    } catch (IllegalArgumentException e) {
      // Expected
    }

    try {
      bidi.createLineBidi(2, 2);
    } catch (IllegalArgumentException e) {
      // Expected
    }

    try {
      bidi.createLineBidi(2, 4);
      fail("Expected IAE");
    } catch (IllegalArgumentException e) {
      // Expected
    }
  }
Пример #17
0
  public void testBadReorderVisually() {
    String[] s = new String[] {"a", "b", "c", "d"};

    try {
      Bidi.reorderVisually(new byte[] {2, 1, 3, 0}, 0, s, 0, 5);
      fail("should throw IAE");
    } catch (IllegalArgumentException e) {
      // expected
    }

    try {
      Bidi.reorderVisually(new byte[] {2, 1, 3, 0}, 0, s, -1, 1);
      fail("should throw IAE");
    } catch (IllegalArgumentException e) {
      // expected
    }

    try {
      Bidi.reorderVisually(new byte[] {2, 1, 3, 0}, -1, s, 0, 1);
      fail("should throw IAE");
    } catch (IllegalArgumentException e) {
      // expected
    }

    try {
      Bidi.reorderVisually(null, 0, s, 0, 1);
      fail("should throw NPE");
    } catch (NullPointerException e) {
      // expected
    }

    try {
      Bidi.reorderVisually(new byte[] {2, 1, 3, 0}, 0, null, 0, 1);
      fail("should throw NPE");
    } catch (NullPointerException e) {
      // expected
    }

    try {
      Bidi.reorderVisually(new byte[] {2, 1, 3, 0}, 1, s, 0, -1);
      fail("should throw IAE");
    } catch (IllegalArgumentException e) {
      // expected
    }
  }
Пример #18
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());
  }
Пример #19
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());
 }
Пример #20
0
  /** Initialize state, including fChars array, direction, and fBidi. */
  private void initAll(AttributedCharacterIterator text) {

    fStart = text.getBeginIndex();

    // extract chars
    fChars = new char[text.getEndIndex() - fStart];

    int n = 0;
    for (char c = text.first(); c != CharacterIterator.DONE; c = text.next()) {
      fChars[n++] = c;
    }

    text.first();

    fBidi = new Bidi(text);
    if (fBidi.isLeftToRight()) {
      fBidi = null;
    }

    text.first();
    Map<? extends Attribute, ?> paragraphAttrs = text.getAttributes();
    NumericShaper shaper = AttributeValues.getNumericShaping(paragraphAttrs);
    if (shaper != null) {
      shaper.shape(fChars, 0, fChars.length);
    }

    fParagraph = new StyledParagraph(text, fChars);

    // set paragraph attributes
    {
      // If there's an embedded graphic at the start of the
      // paragraph, look for the first non-graphic character
      // and use it and its font to initialize the paragraph.
      // If not, use the first graphic to initialize.
      fJustifyRatio = AttributeValues.getJustification(paragraphAttrs);

      boolean haveFont = TextLine.advanceToFirstFont(text);

      if (haveFont) {
        Font defaultFont = TextLine.getFontAtCurrentPos(text);
        int charsStart = text.getIndex() - text.getBeginIndex();
        LineMetrics lm = defaultFont.getLineMetrics(fChars, charsStart, charsStart + 1, fFrc);
        fBaseline = (byte) lm.getBaselineIndex();
        fBaselineOffsets = lm.getBaselineOffsets();
      } else {
        // hmmm what to do here?  Just try to supply reasonable
        // values I guess.

        GraphicAttribute graphic =
            (GraphicAttribute) paragraphAttrs.get(TextAttribute.CHAR_REPLACEMENT);
        fBaseline = TextLayout.getBaselineFromGraphic(graphic);
        Hashtable<Attribute, ?> fmap = new Hashtable<>(5, (float) 0.9);
        Font dummyFont = new Font(fmap);
        LineMetrics lm = dummyFont.getLineMetrics(" ", 0, 1, fFrc);
        fBaselineOffsets = lm.getBaselineOffsets();
      }
      fBaselineOffsets = TextLine.getNormalizedOffsets(fBaselineOffsets, fBaseline);
    }

    invalidateComponents();
  }
Пример #21
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());
 }
Пример #22
0
  public void testRequiresBidi() {
    try {
      Bidi.requiresBidi(null, 0, 0);
      fail("should throw NullPointerException");
    } catch (NullPointerException e) {
      // expected
    }

    try {
      assertFalse(Bidi.requiresBidi(null, 0, 1));
      fail("should throw NPE");
    } catch (NullPointerException e) {
      // expected
    }
    try {
      assertFalse(Bidi.requiresBidi("".toCharArray(), 0, 1));
      fail("should throw IllegalArgumentException");
    } catch (IllegalArgumentException e) {
      // expected
    }
    try {
      assertFalse(Bidi.requiresBidi("aaa".toCharArray(), -1, 1));
      fail("should throw IllegalArgumentException");
    } catch (IllegalArgumentException e) {
      // expected
    }
    try {
      assertFalse(Bidi.requiresBidi("aaa".toCharArray(), 1, -1));
      fail("should throw IllegalArgumentException");
    } catch (IllegalArgumentException e) {
      // expected
    }
    try {
      assertFalse(Bidi.requiresBidi("\u05D0".toCharArray(), 1, -1));
      fail("should throw IllegalArgumentException");
    } catch (IllegalArgumentException e) {
      // expected
    }
    try {
      assertFalse(Bidi.requiresBidi("aaa".toCharArray(), 1, 0));
      fail("should throw IllegalArgumentException");
    } catch (IllegalArgumentException e) {
      // expected
    }
    try {
      assertFalse(Bidi.requiresBidi("aaa".toCharArray(), 7, 7));
      fail("should throw IllegalArgumentException");
    } catch (IllegalArgumentException e) {
      // expected
    }
    try {
      assertFalse(Bidi.requiresBidi("aaa".toCharArray(), 1, Integer.MAX_VALUE));
      fail("should throw IllegalArgumentException");
    } catch (IllegalArgumentException e) {
      // expected
    }
    try {
      assertFalse(Bidi.requiresBidi("aaa".toCharArray(), Integer.MAX_VALUE, 1));
      fail("should throw IllegalArgumentException");
    } catch (IllegalArgumentException e) {
      // expected
    }

    assertFalse(Bidi.requiresBidi("".toCharArray(), 0, 0));
    assertFalse(Bidi.requiresBidi("aaa".toCharArray(), 1, 1));
    assertFalse(Bidi.requiresBidi("aaa".toCharArray(), 0, 2));
    assertFalse(Bidi.requiresBidi("\u05D0".toCharArray(), 1, 1));
    assertTrue(Bidi.requiresBidi("\u05D0".toCharArray(), 0, 1));
    assertFalse(Bidi.requiresBidi("aa\u05D0a".toCharArray(), 0, 2));
    assertTrue(Bidi.requiresBidi("aa\u05D0a".toCharArray(), 1, 3));
  }
Пример #23
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());
 }
Пример #24
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());
 }
Пример #25
0
  public void testSimpleBidiParagraph_2() {
    bd = new Bidi("a\u05D0", Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT);
    assertTrue(bd.baseIsLeftToRight());
    assertEquals(0, bd.getBaseLevel());
    assertEquals(2, bd.getLength());
    assertEquals(0, bd.getLevelAt(0));
    assertEquals(1, bd.getLevelAt(1));
    assertEquals(0, bd.getLevelAt(1000));
    assertEquals(2, bd.getRunCount());
    assertRunArrayEquals(
        new int[][] {
          {0, 1, 0}, {1, 2, 1},
        },
        bd);
    assertFalse(bd.isLeftToRight());
    assertTrue(bd.isMixed());
    assertFalse(bd.isRightToLeft());

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

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

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