Java Code Examples for java.text.CharacterIterator#current()

The following examples show how to use java.text.CharacterIterator#current() . 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: PatternParser.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
private void parseVariable(final CharacterIterator iterator) {
  // Consume the starting '{' character
  iterator.next();

  final String varName = readFragment(iterator, VARIABLE_NAME_TERMINATORS, ESCAPE_CHARS, VARNAME_DISALLOWED_CHARS);

  // The iterator is currently pointing to the end character.
  if (iterator.current() == ':') {
    // Skip the ':' character
    iterator.next();
    final String regexp = readFragment(iterator, END_OF_VARIABLE_DECLARATION, ESCAPE_CHARS, NONE);
    tokens.add(new VariableToken(varName, regexp));
  }
  else {
    tokens.add(new VariableToken(varName, DEFAULT_VARIABLE_REGEXP));
  }

  // The iterator should now be pointing to the varname end delimiter.
  checkArgument(iterator.current() == '}', "Variable does not end with '}' at position %s", iterator.getIndex());
  // Consume it.
  iterator.next();
}
 
Example 2
Source File: CharacterIteration.java    From fitnotifications with Apache License 2.0 6 votes vote down vote up
public static int current32(CharacterIterator ci) {
    char  lead   = ci.current();
    int   retVal = lead;
    if (retVal < UTF16.LEAD_SURROGATE_MIN_VALUE) {
        return retVal;   
    }
    if (UTF16.isLeadSurrogate(lead)) {
        int  trail = (int)ci.next();
        ci.previous();
        if (UTF16.isTrailSurrogate((char)trail)) {
            retVal = ((lead  - UTF16.LEAD_SURROGATE_MIN_VALUE) << 10) +
                     (trail - UTF16.TRAIL_SURROGATE_MIN_VALUE) +
                     UTF16.SUPPLEMENTARY_MIN_VALUE;
        }
     } else {
        if (lead == CharacterIterator.DONE) {
            if (ci.getIndex() >= ci.getEndIndex())   {
                retVal = DONE32;   
            }
        }
     }
    return retVal;
}
 
Example 3
Source File: CompactDecimalFormatTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
private static String iterToString(CharacterIterator iter) {
    StringBuilder builder = new StringBuilder();
    for (char c = iter.current(); c != CharacterIterator.DONE; c = iter.next()) {
        builder.append(c);
    }
    return builder.toString();
}
 
Example 4
Source File: PatternParser.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Reads from the character iterator until either a stop character is reached or the iterator is {@link
 * CharacterIterator#DONE done}. The stop character is not consumed. Escape characters indicate that the
 * following character should not be considered as a stop character.
 *
 * @throws IllegalArgumentException if the fragment isn't at least one character
 */
static String readFragment(final CharacterIterator iterator,
                           final List<Character> stopChars,
                           final List<Character> escapeChars,
                           final List<Character> disallowed)
{
  StringBuilder b = new StringBuilder();
  boolean escaping = false;
  while (true) {
    final char ch = iterator.current();

    if (ch == CharacterIterator.DONE) {
      checkArgument(!escaping,
          format("Unexpected end after escape character '%s' at position %s.", ch, iterator.getIndex()));

      checkArgument(b.length() >= 1, format("Zero-length fragment at position %s.", iterator.getIndex()));

      return b.toString();
    }

    if (escaping) {
      checkAllowed(iterator, disallowed);
      b.append(ch);
      escaping = false;
    }
    else if (escapeChars.contains(ch)) {
      escaping = true;
    }
    else if (stopChars.contains(ch)) {
      return b.toString();
    }
    else {
      checkAllowed(iterator, disallowed);
      b.append(ch);
    }

    iterator.next();
  }
}
 
Example 5
Source File: PatternParser.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
private void parseTemplate(final CharacterIterator iterator) {
  while (true) {
    final char ch = iterator.current();
    switch (ch) {
      case CharacterIterator.DONE:
        return;
      case '{':
        parseVariable(iterator);
        break;
      default:
        parseLiteral(iterator);
    }
  }
}
 
Example 6
Source File: Font.java    From openjdk-jdk8u with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns the logical bounds of the characters indexed in the
 * specified {@link CharacterIterator} in the
 * specified <code>FontRenderContext</code>.  The logical bounds
 * contains the origin, ascent, advance, and height, which includes
 * the leading.  The logical bounds does not always enclose all the
 * text.  For example, in some languages and in some fonts, accent
 * marks can be positioned above the ascent or below the descent.
 * To obtain a visual bounding box, which encloses all the text,
 * use the {@link TextLayout#getBounds() getBounds} method of
 * <code>TextLayout</code>.
 * <p>Note: The returned bounds is in baseline-relative coordinates
 * (see {@link java.awt.Font class notes}).
 * @param ci the specified <code>CharacterIterator</code>
 * @param beginIndex the initial offset in <code>ci</code>
 * @param limit the end offset in <code>ci</code>
 * @param frc the specified <code>FontRenderContext</code>
 * @return a <code>Rectangle2D</code> that is the bounding box of the
 * characters indexed in the specified <code>CharacterIterator</code>
 * in the specified <code>FontRenderContext</code>.
 * @see FontRenderContext
 * @see Font#createGlyphVector
 * @since 1.2
 * @throws IndexOutOfBoundsException if <code>beginIndex</code> is
 *         less than the start index of <code>ci</code>, or
 *         <code>limit</code> is greater than the end index of
 *         <code>ci</code>, or <code>beginIndex</code> is greater
 *         than <code>limit</code>
 */
public Rectangle2D getStringBounds(CharacterIterator ci,
                                int beginIndex, int limit,
                                   FontRenderContext frc) {
    int start = ci.getBeginIndex();
    int end = ci.getEndIndex();

    if (beginIndex < start) {
        throw new IndexOutOfBoundsException("beginIndex: " + beginIndex);
    }
    if (limit > end) {
        throw new IndexOutOfBoundsException("limit: " + limit);
    }
    if (beginIndex > limit) {
        throw new IndexOutOfBoundsException("range length: " +
                                            (limit - beginIndex));
    }

    char[]  arr = new char[limit - beginIndex];

    ci.setIndex(beginIndex);
    for(int idx = 0; idx < arr.length; idx++) {
        arr[idx] = ci.current();
        ci.next();
    }

    return getStringBounds(arr,0,arr.length,frc);
}
 
Example 7
Source File: Font.java    From jdk8u-jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns the logical bounds of the characters indexed in the
 * specified {@link CharacterIterator} in the
 * specified <code>FontRenderContext</code>.  The logical bounds
 * contains the origin, ascent, advance, and height, which includes
 * the leading.  The logical bounds does not always enclose all the
 * text.  For example, in some languages and in some fonts, accent
 * marks can be positioned above the ascent or below the descent.
 * To obtain a visual bounding box, which encloses all the text,
 * use the {@link TextLayout#getBounds() getBounds} method of
 * <code>TextLayout</code>.
 * <p>Note: The returned bounds is in baseline-relative coordinates
 * (see {@link java.awt.Font class notes}).
 * @param ci the specified <code>CharacterIterator</code>
 * @param beginIndex the initial offset in <code>ci</code>
 * @param limit the end offset in <code>ci</code>
 * @param frc the specified <code>FontRenderContext</code>
 * @return a <code>Rectangle2D</code> that is the bounding box of the
 * characters indexed in the specified <code>CharacterIterator</code>
 * in the specified <code>FontRenderContext</code>.
 * @see FontRenderContext
 * @see Font#createGlyphVector
 * @since 1.2
 * @throws IndexOutOfBoundsException if <code>beginIndex</code> is
 *         less than the start index of <code>ci</code>, or
 *         <code>limit</code> is greater than the end index of
 *         <code>ci</code>, or <code>beginIndex</code> is greater
 *         than <code>limit</code>
 */
public Rectangle2D getStringBounds(CharacterIterator ci,
                                int beginIndex, int limit,
                                   FontRenderContext frc) {
    int start = ci.getBeginIndex();
    int end = ci.getEndIndex();

    if (beginIndex < start) {
        throw new IndexOutOfBoundsException("beginIndex: " + beginIndex);
    }
    if (limit > end) {
        throw new IndexOutOfBoundsException("limit: " + limit);
    }
    if (beginIndex > limit) {
        throw new IndexOutOfBoundsException("range length: " +
                                            (limit - beginIndex));
    }

    char[]  arr = new char[limit - beginIndex];

    ci.setIndex(beginIndex);
    for(int idx = 0; idx < arr.length; idx++) {
        arr[idx] = ci.current();
        ci.next();
    }

    return getStringBounds(arr,0,arr.length,frc);
}
 
Example 8
Source File: Font.java    From JDKSourceCode1.8 with MIT License 3 votes vote down vote up
/**
 * Returns the logical bounds of the characters indexed in the
 * specified {@link CharacterIterator} in the
 * specified <code>FontRenderContext</code>.  The logical bounds
 * contains the origin, ascent, advance, and height, which includes
 * the leading.  The logical bounds does not always enclose all the
 * text.  For example, in some languages and in some fonts, accent
 * marks can be positioned above the ascent or below the descent.
 * To obtain a visual bounding box, which encloses all the text,
 * use the {@link TextLayout#getBounds() getBounds} method of
 * <code>TextLayout</code>.
 * <p>Note: The returned bounds is in baseline-relative coordinates
 * (see {@link java.awt.Font class notes}).
 * @param ci the specified <code>CharacterIterator</code>
 * @param beginIndex the initial offset in <code>ci</code>
 * @param limit the end offset in <code>ci</code>
 * @param frc the specified <code>FontRenderContext</code>
 * @return a <code>Rectangle2D</code> that is the bounding box of the
 * characters indexed in the specified <code>CharacterIterator</code>
 * in the specified <code>FontRenderContext</code>.
 * @see FontRenderContext
 * @see Font#createGlyphVector
 * @since 1.2
 * @throws IndexOutOfBoundsException if <code>beginIndex</code> is
 *         less than the start index of <code>ci</code>, or
 *         <code>limit</code> is greater than the end index of
 *         <code>ci</code>, or <code>beginIndex</code> is greater
 *         than <code>limit</code>
 */
public Rectangle2D getStringBounds(CharacterIterator ci,
                                int beginIndex, int limit,
                                   FontRenderContext frc) {
    int start = ci.getBeginIndex();
    int end = ci.getEndIndex();

    if (beginIndex < start) {
        throw new IndexOutOfBoundsException("beginIndex: " + beginIndex);
    }
    if (limit > end) {
        throw new IndexOutOfBoundsException("limit: " + limit);
    }
    if (beginIndex > limit) {
        throw new IndexOutOfBoundsException("range length: " +
                                            (limit - beginIndex));
    }

    char[]  arr = new char[limit - beginIndex];

    ci.setIndex(beginIndex);
    for(int idx = 0; idx < arr.length; idx++) {
        arr[idx] = ci.current();
        ci.next();
    }

    return getStringBounds(arr,0,arr.length,frc);
}
 
Example 9
Source File: Font.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns the logical bounds of the characters indexed in the
 * specified {@link CharacterIterator} in the
 * specified <code>FontRenderContext</code>.  The logical bounds
 * contains the origin, ascent, advance, and height, which includes
 * the leading.  The logical bounds does not always enclose all the
 * text.  For example, in some languages and in some fonts, accent
 * marks can be positioned above the ascent or below the descent.
 * To obtain a visual bounding box, which encloses all the text,
 * use the {@link TextLayout#getBounds() getBounds} method of
 * <code>TextLayout</code>.
 * <p>Note: The returned bounds is in baseline-relative coordinates
 * (see {@link java.awt.Font class notes}).
 * @param ci the specified <code>CharacterIterator</code>
 * @param beginIndex the initial offset in <code>ci</code>
 * @param limit the end offset in <code>ci</code>
 * @param frc the specified <code>FontRenderContext</code>
 * @return a <code>Rectangle2D</code> that is the bounding box of the
 * characters indexed in the specified <code>CharacterIterator</code>
 * in the specified <code>FontRenderContext</code>.
 * @see FontRenderContext
 * @see Font#createGlyphVector
 * @since 1.2
 * @throws IndexOutOfBoundsException if <code>beginIndex</code> is
 *         less than the start index of <code>ci</code>, or
 *         <code>limit</code> is greater than the end index of
 *         <code>ci</code>, or <code>beginIndex</code> is greater
 *         than <code>limit</code>
 */
public Rectangle2D getStringBounds(CharacterIterator ci,
                                int beginIndex, int limit,
                                   FontRenderContext frc) {
    int start = ci.getBeginIndex();
    int end = ci.getEndIndex();

    if (beginIndex < start) {
        throw new IndexOutOfBoundsException("beginIndex: " + beginIndex);
    }
    if (limit > end) {
        throw new IndexOutOfBoundsException("limit: " + limit);
    }
    if (beginIndex > limit) {
        throw new IndexOutOfBoundsException("range length: " +
                                            (limit - beginIndex));
    }

    char[]  arr = new char[limit - beginIndex];

    ci.setIndex(beginIndex);
    for(int idx = 0; idx < arr.length; idx++) {
        arr[idx] = ci.current();
        ci.next();
    }

    return getStringBounds(arr,0,arr.length,frc);
}
 
Example 10
Source File: Font.java    From Bytecoder with Apache License 2.0 3 votes vote down vote up
/**
 * Returns the logical bounds of the characters indexed in the
 * specified {@link CharacterIterator} in the
 * specified {@code FontRenderContext}.  The logical bounds
 * contains the origin, ascent, advance, and height, which includes
 * the leading.  The logical bounds does not always enclose all the
 * text.  For example, in some languages and in some fonts, accent
 * marks can be positioned above the ascent or below the descent.
 * To obtain a visual bounding box, which encloses all the text,
 * use the {@link TextLayout#getBounds() getBounds} method of
 * {@code TextLayout}.
 * <p>Note: The returned bounds is in baseline-relative coordinates
 * (see {@link java.awt.Font class notes}).
 * @param ci the specified {@code CharacterIterator}
 * @param beginIndex the initial offset in {@code ci}
 * @param limit the end offset in {@code ci}
 * @param frc the specified {@code FontRenderContext}
 * @return a {@code Rectangle2D} that is the bounding box of the
 * characters indexed in the specified {@code CharacterIterator}
 * in the specified {@code FontRenderContext}.
 * @see FontRenderContext
 * @see Font#createGlyphVector
 * @since 1.2
 * @throws IndexOutOfBoundsException if {@code beginIndex} is
 *         less than the start index of {@code ci}, or
 *         {@code limit} is greater than the end index of
 *         {@code ci}, or {@code beginIndex} is greater
 *         than {@code limit}
 */
public Rectangle2D getStringBounds(CharacterIterator ci,
                                int beginIndex, int limit,
                                   FontRenderContext frc) {
    int start = ci.getBeginIndex();
    int end = ci.getEndIndex();

    if (beginIndex < start) {
        throw new IndexOutOfBoundsException("beginIndex: " + beginIndex);
    }
    if (limit > end) {
        throw new IndexOutOfBoundsException("limit: " + limit);
    }
    if (beginIndex > limit) {
        throw new IndexOutOfBoundsException("range length: " +
                                            (limit - beginIndex));
    }

    char[]  arr = new char[limit - beginIndex];

    ci.setIndex(beginIndex);
    for(int idx = 0; idx < arr.length; idx++) {
        arr[idx] = ci.current();
        ci.next();
    }

    return getStringBounds(arr,0,arr.length,frc);
}
 
Example 11
Source File: Font.java    From jdk8u-dev-jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns the logical bounds of the characters indexed in the
 * specified {@link CharacterIterator} in the
 * specified <code>FontRenderContext</code>.  The logical bounds
 * contains the origin, ascent, advance, and height, which includes
 * the leading.  The logical bounds does not always enclose all the
 * text.  For example, in some languages and in some fonts, accent
 * marks can be positioned above the ascent or below the descent.
 * To obtain a visual bounding box, which encloses all the text,
 * use the {@link TextLayout#getBounds() getBounds} method of
 * <code>TextLayout</code>.
 * <p>Note: The returned bounds is in baseline-relative coordinates
 * (see {@link java.awt.Font class notes}).
 * @param ci the specified <code>CharacterIterator</code>
 * @param beginIndex the initial offset in <code>ci</code>
 * @param limit the end offset in <code>ci</code>
 * @param frc the specified <code>FontRenderContext</code>
 * @return a <code>Rectangle2D</code> that is the bounding box of the
 * characters indexed in the specified <code>CharacterIterator</code>
 * in the specified <code>FontRenderContext</code>.
 * @see FontRenderContext
 * @see Font#createGlyphVector
 * @since 1.2
 * @throws IndexOutOfBoundsException if <code>beginIndex</code> is
 *         less than the start index of <code>ci</code>, or
 *         <code>limit</code> is greater than the end index of
 *         <code>ci</code>, or <code>beginIndex</code> is greater
 *         than <code>limit</code>
 */
public Rectangle2D getStringBounds(CharacterIterator ci,
                                int beginIndex, int limit,
                                   FontRenderContext frc) {
    int start = ci.getBeginIndex();
    int end = ci.getEndIndex();

    if (beginIndex < start) {
        throw new IndexOutOfBoundsException("beginIndex: " + beginIndex);
    }
    if (limit > end) {
        throw new IndexOutOfBoundsException("limit: " + limit);
    }
    if (beginIndex > limit) {
        throw new IndexOutOfBoundsException("range length: " +
                                            (limit - beginIndex));
    }

    char[]  arr = new char[limit - beginIndex];

    ci.setIndex(beginIndex);
    for(int idx = 0; idx < arr.length; idx++) {
        arr[idx] = ci.current();
        ci.next();
    }

    return getStringBounds(arr,0,arr.length,frc);
}
 
Example 12
Source File: Font.java    From jdk8u-jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns the logical bounds of the characters indexed in the
 * specified {@link CharacterIterator} in the
 * specified <code>FontRenderContext</code>.  The logical bounds
 * contains the origin, ascent, advance, and height, which includes
 * the leading.  The logical bounds does not always enclose all the
 * text.  For example, in some languages and in some fonts, accent
 * marks can be positioned above the ascent or below the descent.
 * To obtain a visual bounding box, which encloses all the text,
 * use the {@link TextLayout#getBounds() getBounds} method of
 * <code>TextLayout</code>.
 * <p>Note: The returned bounds is in baseline-relative coordinates
 * (see {@link java.awt.Font class notes}).
 * @param ci the specified <code>CharacterIterator</code>
 * @param beginIndex the initial offset in <code>ci</code>
 * @param limit the end offset in <code>ci</code>
 * @param frc the specified <code>FontRenderContext</code>
 * @return a <code>Rectangle2D</code> that is the bounding box of the
 * characters indexed in the specified <code>CharacterIterator</code>
 * in the specified <code>FontRenderContext</code>.
 * @see FontRenderContext
 * @see Font#createGlyphVector
 * @since 1.2
 * @throws IndexOutOfBoundsException if <code>beginIndex</code> is
 *         less than the start index of <code>ci</code>, or
 *         <code>limit</code> is greater than the end index of
 *         <code>ci</code>, or <code>beginIndex</code> is greater
 *         than <code>limit</code>
 */
public Rectangle2D getStringBounds(CharacterIterator ci,
                                int beginIndex, int limit,
                                   FontRenderContext frc) {
    int start = ci.getBeginIndex();
    int end = ci.getEndIndex();

    if (beginIndex < start) {
        throw new IndexOutOfBoundsException("beginIndex: " + beginIndex);
    }
    if (limit > end) {
        throw new IndexOutOfBoundsException("limit: " + limit);
    }
    if (beginIndex > limit) {
        throw new IndexOutOfBoundsException("range length: " +
                                            (limit - beginIndex));
    }

    char[]  arr = new char[limit - beginIndex];

    ci.setIndex(beginIndex);
    for(int idx = 0; idx < arr.length; idx++) {
        arr[idx] = ci.current();
        ci.next();
    }

    return getStringBounds(arr,0,arr.length,frc);
}
 
Example 13
Source File: Font.java    From Java8CN with Apache License 2.0 3 votes vote down vote up
/**
 * Returns the logical bounds of the characters indexed in the
 * specified {@link CharacterIterator} in the
 * specified <code>FontRenderContext</code>.  The logical bounds
 * contains the origin, ascent, advance, and height, which includes
 * the leading.  The logical bounds does not always enclose all the
 * text.  For example, in some languages and in some fonts, accent
 * marks can be positioned above the ascent or below the descent.
 * To obtain a visual bounding box, which encloses all the text,
 * use the {@link TextLayout#getBounds() getBounds} method of
 * <code>TextLayout</code>.
 * <p>Note: The returned bounds is in baseline-relative coordinates
 * (see {@link java.awt.Font class notes}).
 * @param ci the specified <code>CharacterIterator</code>
 * @param beginIndex the initial offset in <code>ci</code>
 * @param limit the end offset in <code>ci</code>
 * @param frc the specified <code>FontRenderContext</code>
 * @return a <code>Rectangle2D</code> that is the bounding box of the
 * characters indexed in the specified <code>CharacterIterator</code>
 * in the specified <code>FontRenderContext</code>.
 * @see FontRenderContext
 * @see Font#createGlyphVector
 * @since 1.2
 * @throws IndexOutOfBoundsException if <code>beginIndex</code> is
 *         less than the start index of <code>ci</code>, or
 *         <code>limit</code> is greater than the end index of
 *         <code>ci</code>, or <code>beginIndex</code> is greater
 *         than <code>limit</code>
 */
public Rectangle2D getStringBounds(CharacterIterator ci,
                                int beginIndex, int limit,
                                   FontRenderContext frc) {
    int start = ci.getBeginIndex();
    int end = ci.getEndIndex();

    if (beginIndex < start) {
        throw new IndexOutOfBoundsException("beginIndex: " + beginIndex);
    }
    if (limit > end) {
        throw new IndexOutOfBoundsException("limit: " + limit);
    }
    if (beginIndex > limit) {
        throw new IndexOutOfBoundsException("range length: " +
                                            (limit - beginIndex));
    }

    char[]  arr = new char[limit - beginIndex];

    ci.setIndex(beginIndex);
    for(int idx = 0; idx < arr.length; idx++) {
        arr[idx] = ci.current();
        ci.next();
    }

    return getStringBounds(arr,0,arr.length,frc);
}
 
Example 14
Source File: Font.java    From hottub with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns the logical bounds of the characters indexed in the
 * specified {@link CharacterIterator} in the
 * specified <code>FontRenderContext</code>.  The logical bounds
 * contains the origin, ascent, advance, and height, which includes
 * the leading.  The logical bounds does not always enclose all the
 * text.  For example, in some languages and in some fonts, accent
 * marks can be positioned above the ascent or below the descent.
 * To obtain a visual bounding box, which encloses all the text,
 * use the {@link TextLayout#getBounds() getBounds} method of
 * <code>TextLayout</code>.
 * <p>Note: The returned bounds is in baseline-relative coordinates
 * (see {@link java.awt.Font class notes}).
 * @param ci the specified <code>CharacterIterator</code>
 * @param beginIndex the initial offset in <code>ci</code>
 * @param limit the end offset in <code>ci</code>
 * @param frc the specified <code>FontRenderContext</code>
 * @return a <code>Rectangle2D</code> that is the bounding box of the
 * characters indexed in the specified <code>CharacterIterator</code>
 * in the specified <code>FontRenderContext</code>.
 * @see FontRenderContext
 * @see Font#createGlyphVector
 * @since 1.2
 * @throws IndexOutOfBoundsException if <code>beginIndex</code> is
 *         less than the start index of <code>ci</code>, or
 *         <code>limit</code> is greater than the end index of
 *         <code>ci</code>, or <code>beginIndex</code> is greater
 *         than <code>limit</code>
 */
public Rectangle2D getStringBounds(CharacterIterator ci,
                                int beginIndex, int limit,
                                   FontRenderContext frc) {
    int start = ci.getBeginIndex();
    int end = ci.getEndIndex();

    if (beginIndex < start) {
        throw new IndexOutOfBoundsException("beginIndex: " + beginIndex);
    }
    if (limit > end) {
        throw new IndexOutOfBoundsException("limit: " + limit);
    }
    if (beginIndex > limit) {
        throw new IndexOutOfBoundsException("range length: " +
                                            (limit - beginIndex));
    }

    char[]  arr = new char[limit - beginIndex];

    ci.setIndex(beginIndex);
    for(int idx = 0; idx < arr.length; idx++) {
        arr[idx] = ci.current();
        ci.next();
    }

    return getStringBounds(arr,0,arr.length,frc);
}
 
Example 15
Source File: Font.java    From openjdk-8-source with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns the logical bounds of the characters indexed in the
 * specified {@link CharacterIterator} in the
 * specified <code>FontRenderContext</code>.  The logical bounds
 * contains the origin, ascent, advance, and height, which includes
 * the leading.  The logical bounds does not always enclose all the
 * text.  For example, in some languages and in some fonts, accent
 * marks can be positioned above the ascent or below the descent.
 * To obtain a visual bounding box, which encloses all the text,
 * use the {@link TextLayout#getBounds() getBounds} method of
 * <code>TextLayout</code>.
 * <p>Note: The returned bounds is in baseline-relative coordinates
 * (see {@link java.awt.Font class notes}).
 * @param ci the specified <code>CharacterIterator</code>
 * @param beginIndex the initial offset in <code>ci</code>
 * @param limit the end offset in <code>ci</code>
 * @param frc the specified <code>FontRenderContext</code>
 * @return a <code>Rectangle2D</code> that is the bounding box of the
 * characters indexed in the specified <code>CharacterIterator</code>
 * in the specified <code>FontRenderContext</code>.
 * @see FontRenderContext
 * @see Font#createGlyphVector
 * @since 1.2
 * @throws IndexOutOfBoundsException if <code>beginIndex</code> is
 *         less than the start index of <code>ci</code>, or
 *         <code>limit</code> is greater than the end index of
 *         <code>ci</code>, or <code>beginIndex</code> is greater
 *         than <code>limit</code>
 */
public Rectangle2D getStringBounds(CharacterIterator ci,
                                int beginIndex, int limit,
                                   FontRenderContext frc) {
    int start = ci.getBeginIndex();
    int end = ci.getEndIndex();

    if (beginIndex < start) {
        throw new IndexOutOfBoundsException("beginIndex: " + beginIndex);
    }
    if (limit > end) {
        throw new IndexOutOfBoundsException("limit: " + limit);
    }
    if (beginIndex > limit) {
        throw new IndexOutOfBoundsException("range length: " +
                                            (limit - beginIndex));
    }

    char[]  arr = new char[limit - beginIndex];

    ci.setIndex(beginIndex);
    for(int idx = 0; idx < arr.length; idx++) {
        arr[idx] = ci.current();
        ci.next();
    }

    return getStringBounds(arr,0,arr.length,frc);
}
 
Example 16
Source File: Font.java    From openjdk-8 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns the logical bounds of the characters indexed in the
 * specified {@link CharacterIterator} in the
 * specified <code>FontRenderContext</code>.  The logical bounds
 * contains the origin, ascent, advance, and height, which includes
 * the leading.  The logical bounds does not always enclose all the
 * text.  For example, in some languages and in some fonts, accent
 * marks can be positioned above the ascent or below the descent.
 * To obtain a visual bounding box, which encloses all the text,
 * use the {@link TextLayout#getBounds() getBounds} method of
 * <code>TextLayout</code>.
 * <p>Note: The returned bounds is in baseline-relative coordinates
 * (see {@link java.awt.Font class notes}).
 * @param ci the specified <code>CharacterIterator</code>
 * @param beginIndex the initial offset in <code>ci</code>
 * @param limit the end offset in <code>ci</code>
 * @param frc the specified <code>FontRenderContext</code>
 * @return a <code>Rectangle2D</code> that is the bounding box of the
 * characters indexed in the specified <code>CharacterIterator</code>
 * in the specified <code>FontRenderContext</code>.
 * @see FontRenderContext
 * @see Font#createGlyphVector
 * @since 1.2
 * @throws IndexOutOfBoundsException if <code>beginIndex</code> is
 *         less than the start index of <code>ci</code>, or
 *         <code>limit</code> is greater than the end index of
 *         <code>ci</code>, or <code>beginIndex</code> is greater
 *         than <code>limit</code>
 */
public Rectangle2D getStringBounds(CharacterIterator ci,
                                int beginIndex, int limit,
                                   FontRenderContext frc) {
    int start = ci.getBeginIndex();
    int end = ci.getEndIndex();

    if (beginIndex < start) {
        throw new IndexOutOfBoundsException("beginIndex: " + beginIndex);
    }
    if (limit > end) {
        throw new IndexOutOfBoundsException("limit: " + limit);
    }
    if (beginIndex > limit) {
        throw new IndexOutOfBoundsException("range length: " +
                                            (limit - beginIndex));
    }

    char[]  arr = new char[limit - beginIndex];

    ci.setIndex(beginIndex);
    for(int idx = 0; idx < arr.length; idx++) {
        arr[idx] = ci.current();
        ci.next();
    }

    return getStringBounds(arr,0,arr.length,frc);
}
 
Example 17
Source File: Font.java    From jdk8u_jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns the logical bounds of the characters indexed in the
 * specified {@link CharacterIterator} in the
 * specified <code>FontRenderContext</code>.  The logical bounds
 * contains the origin, ascent, advance, and height, which includes
 * the leading.  The logical bounds does not always enclose all the
 * text.  For example, in some languages and in some fonts, accent
 * marks can be positioned above the ascent or below the descent.
 * To obtain a visual bounding box, which encloses all the text,
 * use the {@link TextLayout#getBounds() getBounds} method of
 * <code>TextLayout</code>.
 * <p>Note: The returned bounds is in baseline-relative coordinates
 * (see {@link java.awt.Font class notes}).
 * @param ci the specified <code>CharacterIterator</code>
 * @param beginIndex the initial offset in <code>ci</code>
 * @param limit the end offset in <code>ci</code>
 * @param frc the specified <code>FontRenderContext</code>
 * @return a <code>Rectangle2D</code> that is the bounding box of the
 * characters indexed in the specified <code>CharacterIterator</code>
 * in the specified <code>FontRenderContext</code>.
 * @see FontRenderContext
 * @see Font#createGlyphVector
 * @since 1.2
 * @throws IndexOutOfBoundsException if <code>beginIndex</code> is
 *         less than the start index of <code>ci</code>, or
 *         <code>limit</code> is greater than the end index of
 *         <code>ci</code>, or <code>beginIndex</code> is greater
 *         than <code>limit</code>
 */
public Rectangle2D getStringBounds(CharacterIterator ci,
                                int beginIndex, int limit,
                                   FontRenderContext frc) {
    int start = ci.getBeginIndex();
    int end = ci.getEndIndex();

    if (beginIndex < start) {
        throw new IndexOutOfBoundsException("beginIndex: " + beginIndex);
    }
    if (limit > end) {
        throw new IndexOutOfBoundsException("limit: " + limit);
    }
    if (beginIndex > limit) {
        throw new IndexOutOfBoundsException("range length: " +
                                            (limit - beginIndex));
    }

    char[]  arr = new char[limit - beginIndex];

    ci.setIndex(beginIndex);
    for(int idx = 0; idx < arr.length; idx++) {
        arr[idx] = ci.current();
        ci.next();
    }

    return getStringBounds(arr,0,arr.length,frc);
}
 
Example 18
Source File: Font.java    From jdk8u60 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns the logical bounds of the characters indexed in the
 * specified {@link CharacterIterator} in the
 * specified <code>FontRenderContext</code>.  The logical bounds
 * contains the origin, ascent, advance, and height, which includes
 * the leading.  The logical bounds does not always enclose all the
 * text.  For example, in some languages and in some fonts, accent
 * marks can be positioned above the ascent or below the descent.
 * To obtain a visual bounding box, which encloses all the text,
 * use the {@link TextLayout#getBounds() getBounds} method of
 * <code>TextLayout</code>.
 * <p>Note: The returned bounds is in baseline-relative coordinates
 * (see {@link java.awt.Font class notes}).
 * @param ci the specified <code>CharacterIterator</code>
 * @param beginIndex the initial offset in <code>ci</code>
 * @param limit the end offset in <code>ci</code>
 * @param frc the specified <code>FontRenderContext</code>
 * @return a <code>Rectangle2D</code> that is the bounding box of the
 * characters indexed in the specified <code>CharacterIterator</code>
 * in the specified <code>FontRenderContext</code>.
 * @see FontRenderContext
 * @see Font#createGlyphVector
 * @since 1.2
 * @throws IndexOutOfBoundsException if <code>beginIndex</code> is
 *         less than the start index of <code>ci</code>, or
 *         <code>limit</code> is greater than the end index of
 *         <code>ci</code>, or <code>beginIndex</code> is greater
 *         than <code>limit</code>
 */
public Rectangle2D getStringBounds(CharacterIterator ci,
                                int beginIndex, int limit,
                                   FontRenderContext frc) {
    int start = ci.getBeginIndex();
    int end = ci.getEndIndex();

    if (beginIndex < start) {
        throw new IndexOutOfBoundsException("beginIndex: " + beginIndex);
    }
    if (limit > end) {
        throw new IndexOutOfBoundsException("limit: " + limit);
    }
    if (beginIndex > limit) {
        throw new IndexOutOfBoundsException("range length: " +
                                            (limit - beginIndex));
    }

    char[]  arr = new char[limit - beginIndex];

    ci.setIndex(beginIndex);
    for(int idx = 0; idx < arr.length; idx++) {
        arr[idx] = ci.current();
        ci.next();
    }

    return getStringBounds(arr,0,arr.length,frc);
}
 
Example 19
Source File: Font.java    From TencentKona-8 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns the logical bounds of the characters indexed in the
 * specified {@link CharacterIterator} in the
 * specified <code>FontRenderContext</code>.  The logical bounds
 * contains the origin, ascent, advance, and height, which includes
 * the leading.  The logical bounds does not always enclose all the
 * text.  For example, in some languages and in some fonts, accent
 * marks can be positioned above the ascent or below the descent.
 * To obtain a visual bounding box, which encloses all the text,
 * use the {@link TextLayout#getBounds() getBounds} method of
 * <code>TextLayout</code>.
 * <p>Note: The returned bounds is in baseline-relative coordinates
 * (see {@link java.awt.Font class notes}).
 * @param ci the specified <code>CharacterIterator</code>
 * @param beginIndex the initial offset in <code>ci</code>
 * @param limit the end offset in <code>ci</code>
 * @param frc the specified <code>FontRenderContext</code>
 * @return a <code>Rectangle2D</code> that is the bounding box of the
 * characters indexed in the specified <code>CharacterIterator</code>
 * in the specified <code>FontRenderContext</code>.
 * @see FontRenderContext
 * @see Font#createGlyphVector
 * @since 1.2
 * @throws IndexOutOfBoundsException if <code>beginIndex</code> is
 *         less than the start index of <code>ci</code>, or
 *         <code>limit</code> is greater than the end index of
 *         <code>ci</code>, or <code>beginIndex</code> is greater
 *         than <code>limit</code>
 */
public Rectangle2D getStringBounds(CharacterIterator ci,
                                int beginIndex, int limit,
                                   FontRenderContext frc) {
    int start = ci.getBeginIndex();
    int end = ci.getEndIndex();

    if (beginIndex < start) {
        throw new IndexOutOfBoundsException("beginIndex: " + beginIndex);
    }
    if (limit > end) {
        throw new IndexOutOfBoundsException("limit: " + limit);
    }
    if (beginIndex > limit) {
        throw new IndexOutOfBoundsException("range length: " +
                                            (limit - beginIndex));
    }

    char[]  arr = new char[limit - beginIndex];

    ci.setIndex(beginIndex);
    for(int idx = 0; idx < arr.length; idx++) {
        arr[idx] = ci.current();
        ci.next();
    }

    return getStringBounds(arr,0,arr.length,frc);
}
 
Example 20
Source File: Font.java    From jdk-1.7-annotated with Apache License 2.0 3 votes vote down vote up
/**
 * Returns the logical bounds of the characters indexed in the
 * specified {@link CharacterIterator} in the
 * specified <code>FontRenderContext</code>.  The logical bounds
 * contains the origin, ascent, advance, and height, which includes
 * the leading.  The logical bounds does not always enclose all the
 * text.  For example, in some languages and in some fonts, accent
 * marks can be positioned above the ascent or below the descent.
 * To obtain a visual bounding box, which encloses all the text,
 * use the {@link TextLayout#getBounds() getBounds} method of
 * <code>TextLayout</code>.
 * <p>Note: The returned bounds is in baseline-relative coordinates
 * (see {@link java.awt.Font class notes}).
 * @param ci the specified <code>CharacterIterator</code>
 * @param beginIndex the initial offset in <code>ci</code>
 * @param limit the end offset in <code>ci</code>
 * @param frc the specified <code>FontRenderContext</code>
 * @return a <code>Rectangle2D</code> that is the bounding box of the
 * characters indexed in the specified <code>CharacterIterator</code>
 * in the specified <code>FontRenderContext</code>.
 * @see FontRenderContext
 * @see Font#createGlyphVector
 * @since 1.2
 * @throws IndexOutOfBoundsException if <code>beginIndex</code> is
 *         less than the start index of <code>ci</code>, or
 *         <code>limit</code> is greater than the end index of
 *         <code>ci</code>, or <code>beginIndex</code> is greater
 *         than <code>limit</code>
 */
public Rectangle2D getStringBounds(CharacterIterator ci,
                                int beginIndex, int limit,
                                   FontRenderContext frc) {
    int start = ci.getBeginIndex();
    int end = ci.getEndIndex();

    if (beginIndex < start) {
        throw new IndexOutOfBoundsException("beginIndex: " + beginIndex);
    }
    if (limit > end) {
        throw new IndexOutOfBoundsException("limit: " + limit);
    }
    if (beginIndex > limit) {
        throw new IndexOutOfBoundsException("range length: " +
                                            (limit - beginIndex));
    }

    char[]  arr = new char[limit - beginIndex];

    ci.setIndex(beginIndex);
    for(int idx = 0; idx < arr.length; idx++) {
        arr[idx] = ci.current();
        ci.next();
    }

    return getStringBounds(arr,0,arr.length,frc);
}