Search in sources :

Example 26 with GeneralPath

use of java.awt.geom.GeneralPath in project JMRI by JMRI.

the class Region method initPath.

void initPath(Point3d[] points) {
    if (points.length < 3) {
        log.error("Region needs at least three points to have non-zero area");
    }
    path = new GeneralPath();
    path.moveTo((float) points[0].x, (float) points[0].y);
    for (int i = 1; i < points.length; i++) {
        path.lineTo((float) points[i].x, (float) points[i].y);
    }
    path.lineTo((float) points[0].x, (float) points[0].y);
}
Also used : GeneralPath(java.awt.geom.GeneralPath)

Example 27 with GeneralPath

use of java.awt.geom.GeneralPath in project jdk8u_jdk by JetBrains.

the class CompositeStrike method getGlyphOutline.

GeneralPath getGlyphOutline(int glyphCode, float x, float y) {
    PhysicalStrike strike = getStrikeForGlyph(glyphCode);
    GeneralPath path = strike.getGlyphOutline(glyphCode & SLOTMASK, x, y);
    if (path == null) {
        return new GeneralPath();
    } else {
        return path;
    }
}
Also used : GeneralPath(java.awt.geom.GeneralPath)

Example 28 with GeneralPath

use of java.awt.geom.GeneralPath in project jdk8u_jdk by JetBrains.

the class StandardGlyphVector method getGlyphsOutline.

/**
     * Used by getOutline, getGlyphsOutline
     */
private Shape getGlyphsOutline(int start, int count, float x, float y) {
    setFRCTX();
    initPositions();
    GeneralPath result = new GeneralPath(GeneralPath.WIND_NON_ZERO);
    for (int i = start, e = start + count, n = start * 2; i < e; ++i, n += 2) {
        float px = x + positions[n];
        float py = y + positions[n + 1];
        getGlyphStrike(i).appendGlyphOutline(glyphs[i], result, px, py);
    }
    return result;
}
Also used : GeneralPath(java.awt.geom.GeneralPath) Point(java.awt.Point)

Example 29 with GeneralPath

use of java.awt.geom.GeneralPath in project jdk8u_jdk by JetBrains.

the class TextLayout method getVisualHighlightShape.

/**
     * Returns a path enclosing the visual selection in the specified range,
     * extended to <code>bounds</code>.
     * <p>
     * If the selection includes the leftmost (topmost) position, the selection
     * is extended to the left (top) of <code>bounds</code>.  If the
     * selection includes the rightmost (bottommost) position, the selection
     * is extended to the right (bottom) of the bounds.  The height
     * (width on vertical lines) of the selection is always extended to
     * <code>bounds</code>.
     * <p>
     * Although the selection is always contiguous, the logically selected
     * text can be discontiguous on lines with mixed-direction text.  The
     * logical ranges of text selected can be retrieved using
     * <code>getLogicalRangesForVisualSelection</code>.  For example,
     * consider the text 'ABCdef' where capital letters indicate
     * right-to-left text, rendered on a right-to-left line, with a visual
     * selection from 0L (the leading edge of 'A') to 3T (the trailing edge
     * of 'd').  The text appears as follows, with bold underlined areas
     * representing the selection:
     * <br><pre>
     *    d<u><b>efCBA  </b></u>
     * </pre>
     * The logical selection ranges are 0-3, 4-6 (ABC, ef) because the
     * visually contiguous text is logically discontiguous.  Also note that
     * since the rightmost position on the layout (to the right of 'A') is
     * selected, the selection is extended to the right of the bounds.
     * @param firstEndpoint one end of the visual selection
     * @param secondEndpoint the other end of the visual selection
     * @param bounds the bounding rectangle to which to extend the selection.
     *     This is in baseline-relative coordinates.
     * @return a <code>Shape</code> enclosing the selection.  This is in
     *     standard coordinates.
     * @see #getLogicalRangesForVisualSelection(TextHitInfo, TextHitInfo)
     * @see #getLogicalHighlightShape(int, int, Rectangle2D)
     */
public Shape getVisualHighlightShape(TextHitInfo firstEndpoint, TextHitInfo secondEndpoint, Rectangle2D bounds) {
    ensureCache();
    checkTextHit(firstEndpoint);
    checkTextHit(secondEndpoint);
    if (bounds == null) {
        throw new IllegalArgumentException("Null Rectangle2D passed to TextLayout.getVisualHighlightShape()");
    }
    GeneralPath result = new GeneralPath(GeneralPath.WIND_EVEN_ODD);
    int firstCaret = hitToCaret(firstEndpoint);
    int secondCaret = hitToCaret(secondEndpoint);
    result.append(caretBoundingShape(firstCaret, secondCaret, bounds), false);
    if (firstCaret == 0 || secondCaret == 0) {
        GeneralPath ls = leftShape(bounds);
        if (!ls.getBounds().isEmpty())
            result.append(ls, false);
    }
    if (firstCaret == characterCount || secondCaret == characterCount) {
        GeneralPath rs = rightShape(bounds);
        if (!rs.getBounds().isEmpty()) {
            result.append(rs, false);
        }
    }
    LayoutPathImpl lp = textLine.getLayoutPath();
    if (lp != null) {
        // dlf cast safe?
        result = (GeneralPath) lp.mapShape(result);
    }
    return result;
}
Also used : GeneralPath(java.awt.geom.GeneralPath) LayoutPathImpl(sun.font.LayoutPathImpl)

Example 30 with GeneralPath

use of java.awt.geom.GeneralPath in project jdk8u_jdk by JetBrains.

the class TextLayout method boundingShape.

// A utility to return a path enclosing the given path
// Path0 must be left or top of path1
// {jbr} no assumptions about size of path0, path1 anymore.
private GeneralPath boundingShape(double[] path0, double[] path1) {
    // Really, we want the path to be a convex hull around all of the
    // points in path0 and path1.  But we can get by with less than
    // that.  We do need to prevent the two segments which
    // join path0 to path1 from crossing each other.  So, if we
    // traverse path0 from top to bottom, we'll traverse path1 from
    // bottom to top (and vice versa).
    GeneralPath result = pathToShape(path0, false, null);
    boolean sameDirection;
    if (isVerticalLine) {
        sameDirection = (path0[1] > path0[path0.length - 1]) == (path1[1] > path1[path1.length - 1]);
    } else {
        sameDirection = (path0[0] > path0[path0.length - 2]) == (path1[0] > path1[path1.length - 2]);
    }
    int start;
    int limit;
    int increment;
    if (sameDirection) {
        start = path1.length - 2;
        limit = -2;
        increment = -2;
    } else {
        start = 0;
        limit = path1.length;
        increment = 2;
    }
    for (int i = start; i != limit; i += increment) {
        result.lineTo((float) path1[i], (float) path1[i + 1]);
    }
    result.closePath();
    return result;
}
Also used : GeneralPath(java.awt.geom.GeneralPath)

Aggregations

GeneralPath (java.awt.geom.GeneralPath)96 Point (java.awt.Point)14 AffineTransform (java.awt.geom.AffineTransform)14 PathIterator (java.awt.geom.PathIterator)14 Graphics2D (java.awt.Graphics2D)8 Rectangle2D (java.awt.geom.Rectangle2D)8 Color (java.awt.Color)7 Paint (java.awt.Paint)7 BasicStroke (java.awt.BasicStroke)6 Point2D (java.awt.geom.Point2D)6 Stroke (java.awt.Stroke)5 Area (java.awt.geom.Area)4 Shape (java.awt.Shape)3 CubicCurve2D (java.awt.geom.CubicCurve2D)3 LayoutPathImpl (sun.font.LayoutPathImpl)3 GradientPaint (java.awt.GradientPaint)2 Rectangle (java.awt.Rectangle)2 Line2D (java.awt.geom.Line2D)2 RoundRectangle2D (java.awt.geom.RoundRectangle2D)2 JBColor (com.intellij.ui.JBColor)1