java.awt.geom.GeneralPath Java Examples

The following examples show how to use java.awt.geom.GeneralPath. 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: UIUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static void drawWave(Graphics2D g, Rectangle rectangle) {
  GraphicsConfig config = GraphicsUtil.setupAAPainting(g);
  Stroke oldStroke = g.getStroke();
  try {
    g.setStroke(new BasicStroke(0.7F));
    double cycle = 4;
    final double wavedAt = rectangle.y + (double)rectangle.height / 2 - .5;
    GeneralPath wavePath = new GeneralPath();
    wavePath.moveTo(rectangle.x, wavedAt - Math.cos(rectangle.x * 2 * Math.PI / cycle));
    for (int x = rectangle.x + 1; x <= rectangle.x + rectangle.width; x++) {
      wavePath.lineTo(x, wavedAt - Math.cos(x * 2 * Math.PI / cycle));
    }
    g.draw(wavePath);
  }
  finally {
    config.restore();
    g.setStroke(oldStroke);
  }
}
 
Example #2
Source File: ButtonShape.java    From pumpernickel with MIT License 6 votes vote down vote up
private static GeneralPath findShapeToFitRectangle(Shape originalShape,
		int w, int h) {
	GeneralPath newShape = new GeneralPath();
	Rectangle2D rect = new Rectangle2D.Float();
	ShapeBounds.getBounds(originalShape, rect);
	if (originalShape.contains(rect.getX() + rect.getWidth() / 2,
			rect.getY() + rect.getHeight() / 2) == false)
		throw new IllegalArgumentException(
				"This custom shape is not allowed.  The center of this shape must be inside the shape.");
	double scale = Math.min((w) / rect.getWidth(), (h) / rect.getHeight());
	AffineTransform transform = new AffineTransform();
	while (true) {
		newShape.reset();
		newShape.append(originalShape, true);
		transform.setToScale(scale, scale);
		newShape.transform(transform);
		ShapeBounds.getBounds(newShape, rect);

		if (newShape.contains(rect.getX() + rect.getWidth() / 2 - w / 2,
				rect.getY() + rect.getHeight() / 2 - h / 2, w, h)) {
			return newShape;
		}

		scale += .01;
	}
}
 
Example #3
Source File: StdDraw.java    From algs4 with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Draws a polygon with the vertices 
 * (<em>x</em><sub>0</sub>, <em>y</em><sub>0</sub>),
 * (<em>x</em><sub>1</sub>, <em>y</em><sub>1</sub>), ...,
 * (<em>x</em><sub><em>n</em>–1</sub>, <em>y</em><sub><em>n</em>–1</sub>).
 *
 * @param  x an array of all the <em>x</em>-coordinates of the polygon
 * @param  y an array of all the <em>y</em>-coordinates of the polygon
 * @throws IllegalArgumentException unless {@code x[]} and {@code y[]}
 *         are of the same length
 * @throws IllegalArgumentException if any coordinate is either NaN or infinite
 * @throws IllegalArgumentException if either {@code x[]} or {@code y[]} is {@code null}
 */
public static void polygon(double[] x, double[] y) {
    validateNotNull(x, "x-coordinate array");
    validateNotNull(y, "y-coordinate array");
    for (int i = 0; i < x.length; i++) validate(x[i], "x[" + i + "]");
    for (int i = 0; i < y.length; i++) validate(y[i], "y[" + i + "]");

    int n1 = x.length;
    int n2 = y.length;
    if (n1 != n2) throw new IllegalArgumentException("arrays must be of the same length");
    int n = n1;
    if (n == 0) return;

    GeneralPath path = new GeneralPath();
    path.moveTo((float) scaleX(x[0]), (float) scaleY(y[0]));
    for (int i = 0; i < n; i++)
        path.lineTo((float) scaleX(x[i]), (float) scaleY(y[i]));
    path.closePath();
    offscreen.draw(path);
    draw();
}
 
Example #4
Source File: LayoutPathImpl.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
public Shape mapShape(Shape s) {
    if (LOGMAP) LOG.format("mapshape on path: %s\n", LayoutPathImpl.SegmentPath.this);
    PathIterator pi = s.getPathIterator(null, 1); // cheap way to handle curves.

    if (LOGMAP) LOG.format("start\n");
    init();

    final double[] coords = new double[2];
    while (!pi.isDone()) {
        switch (pi.currentSegment(coords)) {
        case SEG_CLOSE: close(); break;
        case SEG_MOVETO: moveTo(coords[0], coords[1]); break;
        case SEG_LINETO: lineTo(coords[0], coords[1]); break;
        default: break;
        }

        pi.next();
    }
    if (LOGMAP) LOG.format("finish\n\n");

    GeneralPath gp = new GeneralPath();
    for (Segment seg: segments) {
        gp.append(seg.gp, false);
    }
    return gp;
}
 
Example #5
Source File: TextLayout.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
private GeneralPath rightShape(Rectangle2D bounds) {
    double[] path1;
    if (isVerticalLine) {
        path1 = new double[] {
            bounds.getX(),
            bounds.getY() + bounds.getHeight(),
            bounds.getX() + bounds.getWidth(),
            bounds.getY() + bounds.getHeight()
        };
    } else {
        path1 = new double[] {
            bounds.getX() + bounds.getWidth(),
            bounds.getY() + bounds.getHeight(),
            bounds.getX() + bounds.getWidth(),
            bounds.getY()
        };
    }

    double[] path0 = getCaretPath(characterCount, bounds, true);

    return boundingShape(path0, path1);
}
 
Example #6
Source File: PDTextAppearanceHandler.java    From sambox with Apache License 2.0 6 votes vote down vote up
private void drawCheck(PDAnnotationText annotation,
        final PDAppearanceContentStream contentStream) throws IOException
{
    PDRectangle bbox = adjustRectAndBBox(annotation, 20, 19);

    float min = Math.min(bbox.getWidth(), bbox.getHeight());

    contentStream.setMiterLimit(4);
    contentStream.setLineJoinStyle(1);
    contentStream.setLineCapStyle(0);
    contentStream.setLineWidth(0.59f); // value from Adobe

    contentStream.transform(Matrix.getScaleInstance(0.001f * min / 0.8f, 0.001f * min / 0.8f));
    contentStream.transform(Matrix.getTranslateInstance(0, 50));

    // we get the shape of a Zapf Dingbats check (0x2714) and use that one.
    // Adobe uses a different font (which one?), or created the shape from scratch.
    GeneralPath path = PDType1Font.ZAPF_DINGBATS.getPath("a20");
    addPath(contentStream, path);
    contentStream.fillAndStroke();
}
 
Example #7
Source File: PDTextAppearanceHandler.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
private void drawRightPointer(PDAnnotationText annotation, final PDAppearanceContentStream contentStream)
        throws IOException
{
    PDRectangle bbox = adjustRectAndBBox(annotation, 20, 17);

    float min = Math.min(bbox.getWidth(), bbox.getHeight());

    contentStream.setMiterLimit(4);
    contentStream.setLineJoinStyle(1);
    contentStream.setLineCapStyle(0);
    contentStream.setLineWidth(0.59f); // value from Adobe

    contentStream.transform(Matrix.getScaleInstance(0.001f * min / 0.8f, 0.001f * min / 0.8f));
    contentStream.transform(Matrix.getTranslateInstance(0, 50));

    // we get the shape of a Zapf Dingbats right pointer (0x27A4) and use that one.
    // Adobe uses a different font (which one?), or created the shape from scratch.
    GeneralPath path = PDType1Font.ZAPF_DINGBATS.getPath("a174");
    addPath(contentStream, path);
    contentStream.fillAndStroke();
}
 
Example #8
Source File: AbstractRadial.java    From mars-sim with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns the image of the MinMeasuredValue and MaxMeasuredValue dependend
 * @param WIDTH
 * @param COLOR
 * @param ROTATION_OFFSET
 * @return the image of the min or max measured value
 */
protected BufferedImage create_MEASURED_VALUE_Image(final int WIDTH, final Color COLOR, final double ROTATION_OFFSET) {
    if (WIDTH <= 36) // 36 is needed otherwise the image size could be smaller than 1
    {
        return UTIL.createImage(1, 1, Transparency.TRANSLUCENT);
    }

    final int IMAGE_HEIGHT = (int) (WIDTH * 0.0280373832);
    final int IMAGE_WIDTH = IMAGE_HEIGHT;

    final BufferedImage IMAGE = UTIL.createImage(IMAGE_WIDTH, IMAGE_HEIGHT, Transparency.TRANSLUCENT);
    final Graphics2D G2 = IMAGE.createGraphics();
    G2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    G2.rotate(ROTATION_OFFSET, IMAGE_WIDTH / 2.0, IMAGE_HEIGHT / 2.0);

    final GeneralPath INDICATOR = new GeneralPath();
    INDICATOR.setWindingRule(Path2D.WIND_EVEN_ODD);
    INDICATOR.moveTo(IMAGE_WIDTH * 0.5, IMAGE_HEIGHT);
    INDICATOR.lineTo(0.0, 0.0);
    INDICATOR.lineTo(IMAGE_WIDTH, 0.0);
    INDICATOR.closePath();

    G2.setColor(COLOR);
    G2.fill(INDICATOR);

    G2.dispose();

    return IMAGE;
}
 
Example #9
Source File: SamplingXYLineRenderer.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Initialises the renderer.
 * <P>
 * This method will be called before the first item is rendered, giving the
 * renderer an opportunity to initialise any state information it wants to
 * maintain.  The renderer can do nothing if it chooses.
 *
 * @param g2  the graphics device.
 * @param dataArea  the area inside the axes.
 * @param plot  the plot.
 * @param data  the data.
 * @param info  an optional info collection object to return data back to
 *              the caller.
 *
 * @return The renderer state.
 */
@Override
public XYItemRendererState initialise(Graphics2D g2,
        Rectangle2D dataArea, XYPlot plot, XYDataset data,
        PlotRenderingInfo info) {

    double dpi = 72;
//        Integer dpiVal = (Integer) g2.getRenderingHint(HintKey.DPI);
//        if (dpiVal != null) {
//            dpi = dpiVal.intValue();
//        }
    State state = new State(info);
    state.seriesPath = new GeneralPath();
    state.intervalPath = new GeneralPath();
    state.dX = 72.0 / dpi;
    return state;
}
 
Example #10
Source File: StandardGlyphVector.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
Rectangle2D getGlyphOutlineBounds(int glyphID, float x, float y) {
    Rectangle2D result = null;
    if (sgv.invdtx == null) {
        result = new Rectangle2D.Float();
        result.setRect(strike.getGlyphOutlineBounds(glyphID)); // don't mutate cached rect
    } else {
        GeneralPath gp = strike.getGlyphOutline(glyphID, 0, 0);
        gp.transform(sgv.invdtx);
        result = gp.getBounds2D();
    }
    /* Since x is the logical advance of the glyph to this point.
     * Because of the way that Rectangle.union is specified, this
     * means that subsequent unioning of a rect including that
     * will be affected, even if the glyph is empty. So skip such
     * cases. This alone isn't a complete solution since x==0
     * may also not be what is wanted. The code that does the
     * unioning also needs to be aware to ignore empty glyphs.
     */
    if (!result.isEmpty()) {
        result.setRect(result.getMinX() + x + dx,
                       result.getMinY() + y + dy,
                       result.getWidth(), result.getHeight());
    }
    return result;
}
 
Example #11
Source File: ArcDialFrame.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns the shape for the window for this dial.  Some dial layers will
 * request that their drawing be clipped within this window.
 *
 * @param frame  the reference frame (<code>null</code> not permitted).
 *
 * @return The shape of the dial's window.
 */
@Override
public Shape getWindow(Rectangle2D frame) {

    Rectangle2D innerFrame = DialPlot.rectangleByRadius(frame,
            this.innerRadius, this.innerRadius);
    Rectangle2D outerFrame = DialPlot.rectangleByRadius(frame,
            this.outerRadius, this.outerRadius);
    Arc2D inner = new Arc2D.Double(innerFrame, this.startAngle,
            this.extent, Arc2D.OPEN);
    Arc2D outer = new Arc2D.Double(outerFrame, this.startAngle
            + this.extent, -this.extent, Arc2D.OPEN);
    GeneralPath p = new GeneralPath();
    Point2D point1 = inner.getStartPoint();
    p.moveTo((float) point1.getX(), (float) point1.getY());
    p.append(inner, true);
    p.append(outer, true);
    p.closePath();
    return p;

}
 
Example #12
Source File: AccuracyTest.java    From pumpernickel with MIT License 6 votes vote down vote up
private GeneralPath getShape(int index) {
	Random r = new Random(index * 100000);
	GeneralPath path = new GeneralPath(
			r.nextBoolean() ? Path2D.WIND_EVEN_ODD : Path2D.WIND_NON_ZERO);
	path.moveTo(r.nextFloat() * 100, r.nextFloat() * 100);
	for (int a = 0; a < 3; a++) {
		int k;
		if (type.getSelectedIndex() == 0) {
			k = r.nextInt(3);
		} else {
			k = type.getSelectedIndex() - 1;
		}

		if (k == 0) {
			path.lineTo(r.nextFloat() * 100, r.nextFloat() * 100);
		} else if (k == 1) {
			path.quadTo(r.nextFloat() * 100, r.nextFloat() * 100,
					r.nextFloat() * 100, r.nextFloat() * 100);
		} else {
			path.curveTo(r.nextFloat() * 100, r.nextFloat() * 100,
					r.nextFloat() * 100, r.nextFloat() * 100,
					r.nextFloat() * 100, r.nextFloat() * 100);
		}
	}
	return path;
}
 
Example #13
Source File: PointShapeFactory.java    From jts with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Creates a shape representing a point.
 * 
 * @param point
 *          the location of the point
 * @return a shape
 */
public Shape createPoint(Point2D point) {
  GeneralPath path = new GeneralPath();
  path.moveTo((float) (point.getX()), (float) (point.getY() - size * 1/8));
  path.lineTo((float) (point.getX() + size * 2/8), (float) (point.getY() - size/2));
  path.lineTo((float) (point.getX() + size/2), (float) (point.getY() - size/2));
  path.lineTo((float) (point.getX() + size * 1/8), (float) (point.getY()));
  path.lineTo((float) (point.getX() + size/2), (float) (point.getY() + size/2));
  path.lineTo((float) (point.getX() + size * 2/8), (float) (point.getY() + size/2));
  path.lineTo((float) (point.getX()), (float) (point.getY() + size * 1/8));
  path.lineTo((float) (point.getX() - size * 2/8), (float) (point.getY() + size/2));
  path.lineTo((float) (point.getX() - size/2), (float) (point.getY() + size/2));
  path.lineTo((float) (point.getX() - size * 1/8), (float) (point.getY()));
  path.lineTo((float) (point.getX() - size/2), (float) (point.getY() - size/2));
  path.lineTo((float) (point.getX() - size * 2/8), (float) (point.getY() - size/2));
  path.closePath();
  return path;
}
 
Example #14
Source File: clsUtilityCPOF.java    From mil-sym-java with Apache License 2.0 6 votes vote down vote up
private static ShapeInfo BuildDummyShapeSpec() {
    ShapeInfo shape = new ShapeInfo(null);
    try {
        AffineTransform tx = new AffineTransform();
        tx.setToIdentity();
        GeneralPath gp = new GeneralPath();
        shape.setLineColor(Color.WHITE);
        shape.setFillColor(null);
        shape.setStroke(new BasicStroke());
        shape.setTexturePaint(null);
        gp.moveTo(-1000, -1000);
        gp.lineTo(-1001, -1001);
        shape.setShape(gp);
        shape.setAffineTransform(tx);
    } catch (Exception exc) {
        ErrorLogger.LogException(_className, "BuidDummyShapeSpec",
                new RendererException("Failed inside BuildDummyShapeSpec", exc));
    }
    return shape;
}
 
Example #15
Source File: AbstractSearchHighlight.java    From pumpernickel with MIT License 6 votes vote down vote up
/**
 * Repositions this component.
 */
protected void nudge() {
	Point topLeft = SwingUtilities.convertPoint(highlightInfo.jc, 0, 0,
			layeredPane);

	GeneralPath path = new GeneralPath();
	path.moveTo(0, 0);
	path.lineTo(image.getWidth(), 0);
	path.lineTo(image.getWidth(), image.getHeight());
	path.lineTo(0, image.getHeight());
	path.closePath();

	AffineTransform transform = AffineTransform
			.getTranslateInstance(-imageCenter.x, -imageCenter.y);
	AffineTransform hTransform = (AffineTransform) getClientProperty(
			"transform");
	if (hTransform != null) {
		transform.concatenate(hTransform);
	}
	path.transform(transform);
	Rectangle bounds = path.getBounds();
	setBounds(center.x + topLeft.x - bounds.width / 2,
			center.y + topLeft.y - bounds.height / 2, bounds.width,
			bounds.height);
}
 
Example #16
Source File: Draw.java    From MeteoInfo with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Fill polygon
 *
 * @param points The points array
 * @param g Graphics2D
 * @param aPGB Polygon break
 */
public static void fillPolygon(PointD[] points, Graphics2D g, PolygonBreak aPGB) {
    GeneralPath path = new GeneralPath(GeneralPath.WIND_EVEN_ODD, points.length);
    for (int i = 0; i < points.length; i++) {
        if (i == 0) {
            path.moveTo(points[i].X, points[i].Y);
        } else {
            path.lineTo(points[i].X, points[i].Y);
        }
    }
    path.closePath();

    if (aPGB != null) {
        if (aPGB.isUsingHatchStyle()) {
            int size = aPGB.getStyleSize();
            BufferedImage bi = getHatchImage(aPGB.getStyle(), size, aPGB.getColor(), aPGB.getBackColor());
            Rectangle2D rect = new Rectangle2D.Double(0, 0, size, size);
            g.setPaint(new TexturePaint(bi, rect));
            g.fill(path);
        } else {
            g.fill(path);
        }
    } else {
        g.fill(path);
    }
}
 
Example #17
Source File: StandardGlyphVector.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
void appendGlyphOutline(int glyphID, GeneralPath result, float x, float y) {
    // !!! fontStrike needs a method for this.  For that matter, GeneralPath does.
    GeneralPath gp = null;
    if (sgv.invdtx == null) {
        gp = strike.getGlyphOutline(glyphID, x + dx, y + dy);
    } else {
        gp = strike.getGlyphOutline(glyphID, 0, 0);
        gp.transform(sgv.invdtx);
        gp.transform(AffineTransform.getTranslateInstance(x + dx, y + dy));
    }
    PathIterator iterator = gp.getPathIterator(null);
    result.append(iterator, false);
}
 
Example #18
Source File: BoundaryOverlay.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
private GeneralPath convertToPixelPath(final GeoPos[] geoBoundary) {
    final GeneralPath gp = new GeneralPath();
    for (int i = 0; i < geoBoundary.length; i++) {
        final GeoPos geoPos = geoBoundary[i];
        final AffineTransform m2vTransform = layerCanvas.getViewport().getModelToViewTransform();
        final Point2D viewPos = m2vTransform.transform(new PixelPos.Double(geoPos.lon, geoPos.lat), null);
        if (i == 0) {
            gp.moveTo(viewPos.getX(), viewPos.getY());
        } else {
            gp.lineTo(viewPos.getX(), viewPos.getY());
        }
    }
    gp.closePath();
    return gp;
}
 
Example #19
Source File: ClipPath.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Generates the clip path.
 *
 * @param dataArea  the dataArea that the plot is being draw in.
 * @param horizontalAxis  the horizontal axis.
 * @param verticalAxis  the vertical axis.
 *
 * @return The GeneralPath defining the outline
 */
public GeneralPath generateClipPath(Rectangle2D dataArea,
                                    ValueAxis horizontalAxis,
                                    ValueAxis verticalAxis) {

    GeneralPath generalPath = new GeneralPath();
    double transX = horizontalAxis.valueToJava2D(
        this.xValue[0], dataArea, RectangleEdge.BOTTOM
    );
    double transY = verticalAxis.valueToJava2D(
        this.yValue[0], dataArea, RectangleEdge.LEFT
    );
    generalPath.moveTo((float) transX, (float) transY);
    for (int k = 0; k < this.yValue.length; k++) {
        transX = horizontalAxis.valueToJava2D(
            this.xValue[k], dataArea, RectangleEdge.BOTTOM
        );
        transY = verticalAxis.valueToJava2D(
            this.yValue[k], dataArea, RectangleEdge.LEFT
        );
        generalPath.lineTo((float) transX, (float) transY);
    }
    generalPath.closePath();

    return generalPath;

}
 
Example #20
Source File: mxGraphicsCanvas2D.java    From blog-codes with Apache License 2.0 5 votes vote down vote up
/**
 * 
 */
public void ellipse(double x, double y, double w, double h)
{
	currentPath = new GeneralPath();
	currentPath.append(new Ellipse2D.Double((state.dx + x) * state.scale,
			(state.dy + y) * state.scale, w * state.scale, h * state.scale),
			false);
}
 
Example #21
Source File: TextLine.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public Shape getOutline(AffineTransform tx) {

        GeneralPath dstShape = new GeneralPath(GeneralPath.WIND_NON_ZERO);

        for (int i=0, n = 0; i < fComponents.length; i++, n += 2) {
            TextLineComponent tlc = fComponents[getComponentLogicalIndex(i)];

            dstShape.append(tlc.getOutline(locs[n], locs[n+1]), false);
        }

        if (tx != null) {
            dstShape.transform(tx);
        }
        return dstShape;
    }
 
Example #22
Source File: PixelToShapeConverter.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private Shape makePoly(int xPoints[], int yPoints[],
                       int nPoints, boolean close) {
    GeneralPath gp = new GeneralPath(GeneralPath.WIND_EVEN_ODD);
    if (nPoints > 0) {
        gp.moveTo(xPoints[0], yPoints[0]);
        for (int i = 1; i < nPoints; i++) {
            gp.lineTo(xPoints[i], yPoints[i]);
        }
        if (close) {
            gp.closePath();
        }
    }
    return gp;
}
 
Example #23
Source File: TransformTest.java    From pumpernickel with MIT License 5 votes vote down vote up
protected GeneralPath getShape(int randomSeed) {
	random.setSeed(randomSeed);
	GeneralPath path = new GeneralPath();
	path.moveTo(100 * random.nextFloat(), 100 * random.nextFloat());
	for (int a = 0; a < 3; a++) {
		int k;
		if (type.getSelectedIndex() == 0) {
			k = random.nextInt(3);
		} else if (type.getSelectedIndex() == 1) {
			k = 0;
		} else if (type.getSelectedIndex() == 2) {
			k = 1;
		} else {
			k = 2;
		}

		if (k == 0) {
			path.lineTo(100 * random.nextFloat(), 100 * random.nextFloat());
		} else if (k == 1) {
			path.quadTo(100 * random.nextFloat(), 100 * random.nextFloat(),
					100 * random.nextFloat(), 100 * random.nextFloat());
		} else {
			path.curveTo(100 * random.nextFloat(),
					100 * random.nextFloat(), 100 * random.nextFloat(),
					100 * random.nextFloat(), 100 * random.nextFloat(),
					100 * random.nextFloat());
		}
	}
	return path;
}
 
Example #24
Source File: PdfToTextInfoConverter.java    From testarea-pdfbox2 with Apache License 2.0 5 votes vote down vote up
private Integer getCharacterBackgroundColor(TextPosition text) {
    Integer fillColorRgb = null;
    try {           
        for (Map.Entry<GeneralPath, PDColor> filledPath : filledPaths.entrySet()) {
            Vector center = getTextPositionCenterPoint(text);
            if (filledPath.getKey().contains(lowerLeftX + center.getX(), lowerLeftY + center.getY())) {
                fillColorRgb = filledPath.getValue().toRGB();                   
            }
        }
    } catch (IOException e) {
        logger.error("Could not convert color to RGB", e);
    }
    return fillColorRgb;
}
 
Example #25
Source File: TextLine.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
public Shape getOutline(AffineTransform tx) {

        GeneralPath dstShape = new GeneralPath(GeneralPath.WIND_NON_ZERO);

        for (int i=0, n = 0; i < fComponents.length; i++, n += 2) {
            TextLineComponent tlc = fComponents[getComponentLogicalIndex(i)];

            dstShape.append(tlc.getOutline(locs[n], locs[n+1]), false);
        }

        if (tx != null) {
            dstShape.transform(tx);
        }
        return dstShape;
    }
 
Example #26
Source File: FreetypeFontScaler.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
synchronized GeneralPath getGlyphVectorOutline(
                 long pScalerContext, int[] glyphs, int numGlyphs,
                 float x, float y) throws FontScalerException {
    if (nativeScaler != 0L) {
        return getGlyphVectorOutlineNative(font.get(),
                                           pScalerContext,
                                           nativeScaler,
                                           glyphs,
                                           numGlyphs,
                                           x, y);
    }
    return FontScaler
        .getNullScaler().getGlyphVectorOutline(0L, glyphs, numGlyphs, x, y);
}
 
Example #27
Source File: WorldMapPane.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
public void zoomToProduct(Product product) {
    if (product == null || product.getSceneGeoCoding() == null) {
        return;
    }
    final GeneralPath[] generalPaths = getGeoBoundaryPaths(product);
    Rectangle2D modelArea = new Rectangle2D.Double();
    final Viewport viewport = getLayerCanvas().getViewport();
    for (GeneralPath generalPath : generalPaths) {
        final Rectangle2D rectangle2D = generalPath.getBounds2D();
        if (modelArea.isEmpty()) {
            if (!viewport.isModelYAxisDown()) {
                modelArea.setFrame(rectangle2D.getX(), rectangle2D.getMaxY(),
                                   rectangle2D.getWidth(), rectangle2D.getHeight());
            }
            modelArea = rectangle2D;
        } else {
            modelArea.add(rectangle2D);
        }
    }
    Rectangle2D modelBounds = modelArea.getBounds2D();
    modelBounds.setFrame(modelBounds.getX() - 2, modelBounds.getY() - 2,
                         modelBounds.getWidth() + 4, modelBounds.getHeight() + 4);

    modelBounds = cropToMaxModelBounds(modelBounds);

    viewport.zoom(modelBounds);
    fireScrolled();
}
 
Example #28
Source File: Flag.java    From freecol with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a triangle of the given shape and size. This is a large
 * top left triangle if the given shape is BEND, and a small left
 * triangle if the given shape is CHEVRON or TRIANGLE.
 *
 * @param unionShape The shape of the union.
 * @param small Whether the shape is limited by decorations.
 * @return The triangle shape.
 */
private GeneralPath getTriangle(UnionShape unionShape, boolean small) {
    GeneralPath path = new GeneralPath();
    double x = 0;
    double y = 0;
    if (small) {
        x = BEND_X;
        y = BEND_Y;
    }
    switch(unionShape) {
    case BEND:
        path.moveTo(0, HEIGHT - y);
        path.lineTo(0, 0);
        path.lineTo(WIDTH - x, 0);
        break;
    case CHEVRON:
        path.moveTo(0, y);
        path.lineTo(CHEVRON_X - x, HEIGHT / 2);
        path.lineTo(0, HEIGHT - y);
        break;
    case TRIANGLE:
        if (unionPosition == UnionPosition.LEFT
            || unionPosition == UnionPosition.RIGHT) {
            path.moveTo(0, y);
            path.lineTo(WIDTH / 2 - x, HEIGHT / 2);
            path.lineTo(0, HEIGHT - y);
        } else {
            path.moveTo(0, x);
            path.lineTo(HEIGHT / 2 - y, WIDTH / 2);
            path.lineTo(0, WIDTH - x);
        }
        break;
    default:
        break;
    }
    return path;
}
 
Example #29
Source File: FileFont.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
GeneralPath getGlyphOutline(long pScalerContext, int glyphCode, float x, float y) {
    try {
        return getScaler().getGlyphOutline(pScalerContext, glyphCode, x, y);
    } catch (FontScalerException fe) {
        scaler = FontScaler.getNullScaler();
        return getGlyphOutline(pScalerContext, glyphCode, x, y);
    }
}
 
Example #30
Source File: TextLine.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public Shape getOutline(AffineTransform tx) {

        GeneralPath dstShape = new GeneralPath(GeneralPath.WIND_NON_ZERO);

        for (int i=0, n = 0; i < fComponents.length; i++, n += 2) {
            TextLineComponent tlc = fComponents[getComponentLogicalIndex(i)];

            dstShape.append(tlc.getOutline(locs[n], locs[n+1]), false);
        }

        if (tx != null) {
            dstShape.transform(tx);
        }
        return dstShape;
    }