sun.font.LayoutPathImpl Java Examples

The following examples show how to use sun.font.LayoutPathImpl. 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: TextLayout.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a <code>Shape</code> representing the outline of this
 * <code>TextLayout</code>.
 * @param tx an optional {@link AffineTransform} to apply to the
 *     outline of this <code>TextLayout</code>.
 * @return a <code>Shape</code> that is the outline of this
 *     <code>TextLayout</code>.  This is in standard coordinates.
 */
public Shape getOutline(AffineTransform tx) {
    ensureCache();
    Shape result = textLine.getOutline(tx);
    LayoutPathImpl lp = textLine.getLayoutPath();
    if (lp != null) {
        result = lp.mapShape(result);
    }
    return result;
}
 
Example #2
Source File: TextLayout.java    From Java8CN with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a <code>Shape</code> representing the outline of this
 * <code>TextLayout</code>.
 * @param tx an optional {@link AffineTransform} to apply to the
 *     outline of this <code>TextLayout</code>.
 * @return a <code>Shape</code> that is the outline of this
 *     <code>TextLayout</code>.  This is in standard coordinates.
 */
public Shape getOutline(AffineTransform tx) {
    ensureCache();
    Shape result = textLine.getOutline(tx);
    LayoutPathImpl lp = textLine.getLayoutPath();
    if (lp != null) {
        result = lp.mapShape(result);
    }
    return result;
}
 
Example #3
Source File: TextLayout.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a <code>Shape</code> representing the outline of this
 * <code>TextLayout</code>.
 * @param tx an optional {@link AffineTransform} to apply to the
 *     outline of this <code>TextLayout</code>.
 * @return a <code>Shape</code> that is the outline of this
 *     <code>TextLayout</code>.  This is in standard coordinates.
 */
public Shape getOutline(AffineTransform tx) {
    ensureCache();
    Shape result = textLine.getOutline(tx);
    LayoutPathImpl lp = textLine.getLayoutPath();
    if (lp != null) {
        result = lp.mapShape(result);
    }
    return result;
}
 
Example #4
Source File: TextLayout.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a <code>Shape</code> representing the outline of this
 * <code>TextLayout</code>.
 * @param tx an optional {@link AffineTransform} to apply to the
 *     outline of this <code>TextLayout</code>.
 * @return a <code>Shape</code> that is the outline of this
 *     <code>TextLayout</code>.  This is in standard coordinates.
 */
public Shape getOutline(AffineTransform tx) {
    ensureCache();
    Shape result = textLine.getOutline(tx);
    LayoutPathImpl lp = textLine.getLayoutPath();
    if (lp != null) {
        result = lp.mapShape(result);
    }
    return result;
}
 
Example #5
Source File: TextLayout.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a <code>Shape</code> representing the outline of this
 * <code>TextLayout</code>.
 * @param tx an optional {@link AffineTransform} to apply to the
 *     outline of this <code>TextLayout</code>.
 * @return a <code>Shape</code> that is the outline of this
 *     <code>TextLayout</code>.  This is in standard coordinates.
 */
public Shape getOutline(AffineTransform tx) {
    ensureCache();
    Shape result = textLine.getOutline(tx);
    LayoutPathImpl lp = textLine.getLayoutPath();
    if (lp != null) {
        result = lp.mapShape(result);
    }
    return result;
}
 
Example #6
Source File: TextLayout.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a {@code Shape} representing the outline of this
 * {@code TextLayout}.
 * @param tx an optional {@link AffineTransform} to apply to the
 *     outline of this {@code TextLayout}.
 * @return a {@code Shape} that is the outline of this
 *     {@code TextLayout}.  This is in standard coordinates.
 */
public Shape getOutline(AffineTransform tx) {
    ensureCache();
    Shape result = textLine.getOutline(tx);
    LayoutPathImpl lp = textLine.getLayoutPath();
    if (lp != null) {
        result = lp.mapShape(result);
    }
    return result;
}
 
Example #7
Source File: TextLayout.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a {@code Shape} representing the outline of this
 * {@code TextLayout}.
 * @param tx an optional {@link AffineTransform} to apply to the
 *     outline of this {@code TextLayout}.
 * @return a {@code Shape} that is the outline of this
 *     {@code TextLayout}.  This is in standard coordinates.
 */
public Shape getOutline(AffineTransform tx) {
    ensureCache();
    Shape result = textLine.getOutline(tx);
    LayoutPathImpl lp = textLine.getLayoutPath();
    if (lp != null) {
        result = lp.mapShape(result);
    }
    return result;
}
 
Example #8
Source File: TextLayout.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a <code>Shape</code> representing the outline of this
 * <code>TextLayout</code>.
 * @param tx an optional {@link AffineTransform} to apply to the
 *     outline of this <code>TextLayout</code>.
 * @return a <code>Shape</code> that is the outline of this
 *     <code>TextLayout</code>.  This is in standard coordinates.
 */
public Shape getOutline(AffineTransform tx) {
    ensureCache();
    Shape result = textLine.getOutline(tx);
    LayoutPathImpl lp = textLine.getLayoutPath();
    if (lp != null) {
        result = lp.mapShape(result);
    }
    return result;
}
 
Example #9
Source File: TextLayout.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a <code>Shape</code> representing the outline of this
 * <code>TextLayout</code>.
 * @param tx an optional {@link AffineTransform} to apply to the
 *     outline of this <code>TextLayout</code>.
 * @return a <code>Shape</code> that is the outline of this
 *     <code>TextLayout</code>.  This is in standard coordinates.
 */
public Shape getOutline(AffineTransform tx) {
    ensureCache();
    Shape result = textLine.getOutline(tx);
    LayoutPathImpl lp = textLine.getLayoutPath();
    if (lp != null) {
        result = lp.mapShape(result);
    }
    return result;
}
 
Example #10
Source File: TextLayout.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a <code>Shape</code> representing the outline of this
 * <code>TextLayout</code>.
 * @param tx an optional {@link AffineTransform} to apply to the
 *     outline of this <code>TextLayout</code>.
 * @return a <code>Shape</code> that is the outline of this
 *     <code>TextLayout</code>.  This is in standard coordinates.
 */
public Shape getOutline(AffineTransform tx) {
    ensureCache();
    Shape result = textLine.getOutline(tx);
    LayoutPathImpl lp = textLine.getLayoutPath();
    if (lp != null) {
        result = lp.mapShape(result);
    }
    return result;
}
 
Example #11
Source File: TextLayout.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a <code>Shape</code> representing the outline of this
 * <code>TextLayout</code>.
 * @param tx an optional {@link AffineTransform} to apply to the
 *     outline of this <code>TextLayout</code>.
 * @return a <code>Shape</code> that is the outline of this
 *     <code>TextLayout</code>.  This is in standard coordinates.
 */
public Shape getOutline(AffineTransform tx) {
    ensureCache();
    Shape result = textLine.getOutline(tx);
    LayoutPathImpl lp = textLine.getLayoutPath();
    if (lp != null) {
        result = lp.mapShape(result);
    }
    return result;
}
 
Example #12
Source File: TextLayout.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * Returns a <code>Shape</code> representing the outline of this
 * <code>TextLayout</code>.
 * @param tx an optional {@link AffineTransform} to apply to the
 *     outline of this <code>TextLayout</code>.
 * @return a <code>Shape</code> that is the outline of this
 *     <code>TextLayout</code>.  This is in standard coordinates.
 */
public Shape getOutline(AffineTransform tx) {
    ensureCache();
    Shape result = textLine.getOutline(tx);
    LayoutPathImpl lp = textLine.getLayoutPath();
    if (lp != null) {
        result = lp.mapShape(result);
    }
    return result;
}
 
Example #13
Source File: TextLayout.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a <code>Shape</code> representing the outline of this
 * <code>TextLayout</code>.
 * @param tx an optional {@link AffineTransform} to apply to the
 *     outline of this <code>TextLayout</code>.
 * @return a <code>Shape</code> that is the outline of this
 *     <code>TextLayout</code>.  This is in standard coordinates.
 */
public Shape getOutline(AffineTransform tx) {
    ensureCache();
    Shape result = textLine.getOutline(tx);
    LayoutPathImpl lp = textLine.getLayoutPath();
    if (lp != null) {
        result = lp.mapShape(result);
    }
    return result;
}
 
Example #14
Source File: TextLayout.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a <code>Shape</code> representing the outline of this
 * <code>TextLayout</code>.
 * @param tx an optional {@link AffineTransform} to apply to the
 *     outline of this <code>TextLayout</code>.
 * @return a <code>Shape</code> that is the outline of this
 *     <code>TextLayout</code>.  This is in standard coordinates.
 */
public Shape getOutline(AffineTransform tx) {
    ensureCache();
    Shape result = textLine.getOutline(tx);
    LayoutPathImpl lp = textLine.getLayoutPath();
    if (lp != null) {
        result = lp.mapShape(result);
    }
    return result;
}
 
Example #15
Source File: TextLayout.java    From jdk-1.7-annotated with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a <code>Shape</code> representing the outline of this
 * <code>TextLayout</code>.
 * @param tx an optional {@link AffineTransform} to apply to the
 *     outline of this <code>TextLayout</code>.
 * @return a <code>Shape</code> that is the outline of this
 *     <code>TextLayout</code>.  This is in standard coordinates.
 */
public Shape getOutline(AffineTransform tx) {
    ensureCache();
    Shape result = textLine.getOutline(tx);
    LayoutPathImpl lp = textLine.getLayoutPath();
    if (lp != null) {
        result = lp.mapShape(result);
    }
    return result;
}
 
Example #16
Source File: TextLayout.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a <code>Shape</code> representing the outline of this
 * <code>TextLayout</code>.
 * @param tx an optional {@link AffineTransform} to apply to the
 *     outline of this <code>TextLayout</code>.
 * @return a <code>Shape</code> that is the outline of this
 *     <code>TextLayout</code>.  This is in standard coordinates.
 */
public Shape getOutline(AffineTransform tx) {
    ensureCache();
    Shape result = textLine.getOutline(tx);
    LayoutPathImpl lp = textLine.getLayoutPath();
    if (lp != null) {
        result = lp.mapShape(result);
    }
    return result;
}
 
Example #17
Source File: TextLayout.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a <code>Shape</code> representing the outline of this
 * <code>TextLayout</code>.
 * @param tx an optional {@link AffineTransform} to apply to the
 *     outline of this <code>TextLayout</code>.
 * @return a <code>Shape</code> that is the outline of this
 *     <code>TextLayout</code>.  This is in standard coordinates.
 */
public Shape getOutline(AffineTransform tx) {
    ensureCache();
    Shape result = textLine.getOutline(tx);
    LayoutPathImpl lp = textLine.getLayoutPath();
    if (lp != null) {
        result = lp.mapShape(result);
    }
    return result;
}
 
Example #18
Source File: TextLayout.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a <code>Shape</code> representing the outline of this
 * <code>TextLayout</code>.
 * @param tx an optional {@link AffineTransform} to apply to the
 *     outline of this <code>TextLayout</code>.
 * @return a <code>Shape</code> that is the outline of this
 *     <code>TextLayout</code>.  This is in standard coordinates.
 */
public Shape getOutline(AffineTransform tx) {
    ensureCache();
    Shape result = textLine.getOutline(tx);
    LayoutPathImpl lp = textLine.getLayoutPath();
    if (lp != null) {
        result = lp.mapShape(result);
    }
    return result;
}
 
Example #19
Source File: TextLine.java    From jdk-1.7-annotated with Apache License 2.0 4 votes vote down vote up
LayoutPathImpl getLayoutPath() {
    return lp;
}
 
Example #20
Source File: TextLayout.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns two paths corresponding to the strong and weak caret.
 * @param offset an offset in this <code>TextLayout</code>
 * @param bounds the bounds to which to extend the carets.  The
 * bounds is in baseline-relative coordinates.
 * @param policy the specified <code>CaretPolicy</code>
 * @return an array of two paths.  Element zero is the strong
 * caret.  If there are two carets, element one is the weak caret,
 * otherwise it is <code>null</code>. The returned shapes
 * are in standard coordinates.
 */
public Shape[] getCaretShapes(int offset, Rectangle2D bounds, CaretPolicy policy) {

    ensureCache();

    if (offset < 0 || offset > characterCount) {
        throw new IllegalArgumentException("Offset out of bounds in TextLayout.getCaretShapes()");
    }

    if (bounds == null) {
        throw new IllegalArgumentException("Null Rectangle2D passed to TextLayout.getCaretShapes()");
    }

    if (policy == null) {
        throw new IllegalArgumentException("Null CaretPolicy passed to TextLayout.getCaretShapes()");
    }

    Shape[] result = new Shape[2];

    TextHitInfo hit = TextHitInfo.afterOffset(offset);

    int hitCaret = hitToCaret(hit);

    LayoutPathImpl lp = textLine.getLayoutPath();
    Shape hitShape = pathToShape(getCaretPath(hit, bounds), false, lp);
    TextHitInfo otherHit = hit.getOtherHit();
    int otherCaret = hitToCaret(otherHit);

    if (hitCaret == otherCaret) {
        result[0] = hitShape;
    }
    else { // more than one caret
        Shape otherShape = pathToShape(getCaretPath(otherHit, bounds), false, lp);

        TextHitInfo strongHit = policy.getStrongCaret(hit, otherHit, this);
        boolean hitIsStrong = strongHit.equals(hit);

        if (hitIsStrong) {// then other is weak
            result[0] = hitShape;
            result[1] = otherShape;
        }
        else {
            result[0] = otherShape;
            result[1] = hitShape;
        }
    }

    return result;
}
 
Example #21
Source File: TextLine.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
LayoutPathImpl getLayoutPath() {
    return lp;
}
 
Example #22
Source File: TextLayout.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
/**
 * Returns two paths corresponding to the strong and weak caret.
 * @param offset an offset in this <code>TextLayout</code>
 * @param bounds the bounds to which to extend the carets.  The
 * bounds is in baseline-relative coordinates.
 * @param policy the specified <code>CaretPolicy</code>
 * @return an array of two paths.  Element zero is the strong
 * caret.  If there are two carets, element one is the weak caret,
 * otherwise it is <code>null</code>. The returned shapes
 * are in standard coordinates.
 */
public Shape[] getCaretShapes(int offset, Rectangle2D bounds, CaretPolicy policy) {

    ensureCache();

    if (offset < 0 || offset > characterCount) {
        throw new IllegalArgumentException("Offset out of bounds in TextLayout.getCaretShapes()");
    }

    if (bounds == null) {
        throw new IllegalArgumentException("Null Rectangle2D passed to TextLayout.getCaretShapes()");
    }

    if (policy == null) {
        throw new IllegalArgumentException("Null CaretPolicy passed to TextLayout.getCaretShapes()");
    }

    Shape[] result = new Shape[2];

    TextHitInfo hit = TextHitInfo.afterOffset(offset);

    int hitCaret = hitToCaret(hit);

    LayoutPathImpl lp = textLine.getLayoutPath();
    Shape hitShape = pathToShape(getCaretPath(hit, bounds), false, lp);
    TextHitInfo otherHit = hit.getOtherHit();
    int otherCaret = hitToCaret(otherHit);

    if (hitCaret == otherCaret) {
        result[0] = hitShape;
    }
    else { // more than one caret
        Shape otherShape = pathToShape(getCaretPath(otherHit, bounds), false, lp);

        TextHitInfo strongHit = policy.getStrongCaret(hit, otherHit, this);
        boolean hitIsStrong = strongHit.equals(hit);

        if (hitIsStrong) {// then other is weak
            result[0] = hitShape;
            result[1] = otherShape;
        }
        else {
            result[0] = otherShape;
            result[1] = hitShape;
        }
    }

    return result;
}
 
Example #23
Source File: TextLine.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
LayoutPathImpl getLayoutPath() {
    return lp;
}
 
Example #24
Source File: TextLayout.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns two paths corresponding to the strong and weak caret.
 * @param offset an offset in this <code>TextLayout</code>
 * @param bounds the bounds to which to extend the carets.  The
 * bounds is in baseline-relative coordinates.
 * @param policy the specified <code>CaretPolicy</code>
 * @return an array of two paths.  Element zero is the strong
 * caret.  If there are two carets, element one is the weak caret,
 * otherwise it is <code>null</code>. The returned shapes
 * are in standard coordinates.
 */
public Shape[] getCaretShapes(int offset, Rectangle2D bounds, CaretPolicy policy) {

    ensureCache();

    if (offset < 0 || offset > characterCount) {
        throw new IllegalArgumentException("Offset out of bounds in TextLayout.getCaretShapes()");
    }

    if (bounds == null) {
        throw new IllegalArgumentException("Null Rectangle2D passed to TextLayout.getCaretShapes()");
    }

    if (policy == null) {
        throw new IllegalArgumentException("Null CaretPolicy passed to TextLayout.getCaretShapes()");
    }

    Shape[] result = new Shape[2];

    TextHitInfo hit = TextHitInfo.afterOffset(offset);

    int hitCaret = hitToCaret(hit);

    LayoutPathImpl lp = textLine.getLayoutPath();
    Shape hitShape = pathToShape(getCaretPath(hit, bounds), false, lp);
    TextHitInfo otherHit = hit.getOtherHit();
    int otherCaret = hitToCaret(otherHit);

    if (hitCaret == otherCaret) {
        result[0] = hitShape;
    }
    else { // more than one caret
        Shape otherShape = pathToShape(getCaretPath(otherHit, bounds), false, lp);

        TextHitInfo strongHit = policy.getStrongCaret(hit, otherHit, this);
        boolean hitIsStrong = strongHit.equals(hit);

        if (hitIsStrong) {// then other is weak
            result[0] = hitShape;
            result[1] = otherShape;
        }
        else {
            result[0] = otherShape;
            result[1] = hitShape;
        }
    }

    return result;
}
 
Example #25
Source File: TextLayout.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns two paths corresponding to the strong and weak caret.
 * @param offset an offset in this <code>TextLayout</code>
 * @param bounds the bounds to which to extend the carets.  The
 * bounds is in baseline-relative coordinates.
 * @param policy the specified <code>CaretPolicy</code>
 * @return an array of two paths.  Element zero is the strong
 * caret.  If there are two carets, element one is the weak caret,
 * otherwise it is <code>null</code>. The returned shapes
 * are in standard coordinates.
 */
public Shape[] getCaretShapes(int offset, Rectangle2D bounds, CaretPolicy policy) {

    ensureCache();

    if (offset < 0 || offset > characterCount) {
        throw new IllegalArgumentException("Offset out of bounds in TextLayout.getCaretShapes()");
    }

    if (bounds == null) {
        throw new IllegalArgumentException("Null Rectangle2D passed to TextLayout.getCaretShapes()");
    }

    if (policy == null) {
        throw new IllegalArgumentException("Null CaretPolicy passed to TextLayout.getCaretShapes()");
    }

    Shape[] result = new Shape[2];

    TextHitInfo hit = TextHitInfo.afterOffset(offset);

    int hitCaret = hitToCaret(hit);

    LayoutPathImpl lp = textLine.getLayoutPath();
    Shape hitShape = pathToShape(getCaretPath(hit, bounds), false, lp);
    TextHitInfo otherHit = hit.getOtherHit();
    int otherCaret = hitToCaret(otherHit);

    if (hitCaret == otherCaret) {
        result[0] = hitShape;
    }
    else { // more than one caret
        Shape otherShape = pathToShape(getCaretPath(otherHit, bounds), false, lp);

        TextHitInfo strongHit = policy.getStrongCaret(hit, otherHit, this);
        boolean hitIsStrong = strongHit.equals(hit);

        if (hitIsStrong) {// then other is weak
            result[0] = hitShape;
            result[1] = otherShape;
        }
        else {
            result[0] = otherShape;
            result[1] = hitShape;
        }
    }

    return result;
}
 
Example #26
Source File: TextLine.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
LayoutPathImpl getLayoutPath() {
    return lp;
}
 
Example #27
Source File: TextLayout.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns two paths corresponding to the strong and weak caret.
 * @param offset an offset in this <code>TextLayout</code>
 * @param bounds the bounds to which to extend the carets.  The
 * bounds is in baseline-relative coordinates.
 * @param policy the specified <code>CaretPolicy</code>
 * @return an array of two paths.  Element zero is the strong
 * caret.  If there are two carets, element one is the weak caret,
 * otherwise it is <code>null</code>. The returned shapes
 * are in standard coordinates.
 */
public Shape[] getCaretShapes(int offset, Rectangle2D bounds, CaretPolicy policy) {

    ensureCache();

    if (offset < 0 || offset > characterCount) {
        throw new IllegalArgumentException("Offset out of bounds in TextLayout.getCaretShapes()");
    }

    if (bounds == null) {
        throw new IllegalArgumentException("Null Rectangle2D passed to TextLayout.getCaretShapes()");
    }

    if (policy == null) {
        throw new IllegalArgumentException("Null CaretPolicy passed to TextLayout.getCaretShapes()");
    }

    Shape[] result = new Shape[2];

    TextHitInfo hit = TextHitInfo.afterOffset(offset);

    int hitCaret = hitToCaret(hit);

    LayoutPathImpl lp = textLine.getLayoutPath();
    Shape hitShape = pathToShape(getCaretPath(hit, bounds), false, lp);
    TextHitInfo otherHit = hit.getOtherHit();
    int otherCaret = hitToCaret(otherHit);

    if (hitCaret == otherCaret) {
        result[0] = hitShape;
    }
    else { // more than one caret
        Shape otherShape = pathToShape(getCaretPath(otherHit, bounds), false, lp);

        TextHitInfo strongHit = policy.getStrongCaret(hit, otherHit, this);
        boolean hitIsStrong = strongHit.equals(hit);

        if (hitIsStrong) {// then other is weak
            result[0] = hitShape;
            result[1] = otherShape;
        }
        else {
            result[0] = otherShape;
            result[1] = hitShape;
        }
    }

    return result;
}
 
Example #28
Source File: TextLine.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
LayoutPathImpl getLayoutPath() {
    return lp;
}
 
Example #29
Source File: TextLayout.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns two paths corresponding to the strong and weak caret.
 * @param offset an offset in this <code>TextLayout</code>
 * @param bounds the bounds to which to extend the carets.  The
 * bounds is in baseline-relative coordinates.
 * @param policy the specified <code>CaretPolicy</code>
 * @return an array of two paths.  Element zero is the strong
 * caret.  If there are two carets, element one is the weak caret,
 * otherwise it is <code>null</code>. The returned shapes
 * are in standard coordinates.
 */
public Shape[] getCaretShapes(int offset, Rectangle2D bounds, CaretPolicy policy) {

    ensureCache();

    if (offset < 0 || offset > characterCount) {
        throw new IllegalArgumentException("Offset out of bounds in TextLayout.getCaretShapes()");
    }

    if (bounds == null) {
        throw new IllegalArgumentException("Null Rectangle2D passed to TextLayout.getCaretShapes()");
    }

    if (policy == null) {
        throw new IllegalArgumentException("Null CaretPolicy passed to TextLayout.getCaretShapes()");
    }

    Shape[] result = new Shape[2];

    TextHitInfo hit = TextHitInfo.afterOffset(offset);

    int hitCaret = hitToCaret(hit);

    LayoutPathImpl lp = textLine.getLayoutPath();
    Shape hitShape = pathToShape(getCaretPath(hit, bounds), false, lp);
    TextHitInfo otherHit = hit.getOtherHit();
    int otherCaret = hitToCaret(otherHit);

    if (hitCaret == otherCaret) {
        result[0] = hitShape;
    }
    else { // more than one caret
        Shape otherShape = pathToShape(getCaretPath(otherHit, bounds), false, lp);

        TextHitInfo strongHit = policy.getStrongCaret(hit, otherHit, this);
        boolean hitIsStrong = strongHit.equals(hit);

        if (hitIsStrong) {// then other is weak
            result[0] = hitShape;
            result[1] = otherShape;
        }
        else {
            result[0] = otherShape;
            result[1] = hitShape;
        }
    }

    return result;
}
 
Example #30
Source File: TextLayout.java    From jdk-1.7-annotated with Apache License 2.0 4 votes vote down vote up
/**
 * Returns two paths corresponding to the strong and weak caret.
 * @param offset an offset in this <code>TextLayout</code>
 * @param bounds the bounds to which to extend the carets.  The
 * bounds is in baseline-relative coordinates.
 * @param policy the specified <code>CaretPolicy</code>
 * @return an array of two paths.  Element zero is the strong
 * caret.  If there are two carets, element one is the weak caret,
 * otherwise it is <code>null</code>. The returned shapes
 * are in standard coordinates.
 */
public Shape[] getCaretShapes(int offset, Rectangle2D bounds, CaretPolicy policy) {

    ensureCache();

    if (offset < 0 || offset > characterCount) {
        throw new IllegalArgumentException("Offset out of bounds in TextLayout.getCaretShapes()");
    }

    if (bounds == null) {
        throw new IllegalArgumentException("Null Rectangle2D passed to TextLayout.getCaretShapes()");
    }

    if (policy == null) {
        throw new IllegalArgumentException("Null CaretPolicy passed to TextLayout.getCaretShapes()");
    }

    Shape[] result = new Shape[2];

    TextHitInfo hit = TextHitInfo.afterOffset(offset);

    int hitCaret = hitToCaret(hit);

    LayoutPathImpl lp = textLine.getLayoutPath();
    Shape hitShape = pathToShape(getCaretPath(hit, bounds), false, lp);
    TextHitInfo otherHit = hit.getOtherHit();
    int otherCaret = hitToCaret(otherHit);

    if (hitCaret == otherCaret) {
        result[0] = hitShape;
    }
    else { // more than one caret
        Shape otherShape = pathToShape(getCaretPath(otherHit, bounds), false, lp);

        TextHitInfo strongHit = policy.getStrongCaret(hit, otherHit, this);
        boolean hitIsStrong = strongHit.equals(hit);

        if (hitIsStrong) {// then other is weak
            result[0] = hitShape;
            result[1] = otherShape;
        }
        else {
            result[0] = otherShape;
            result[1] = hitShape;
        }
    }

    return result;
}