if (graphicFill instanceof MarkStyle2D) { final MarkStyle2D ms2d = (MarkStyle2D) graphicFill; final Shape markShape = ms2d.getShape(); double size = ms2d.getSize(); Rectangle2D boundsFill = markShape.getBounds2D(); double aspect = lineStyle.setStroke(ms2d.getStroke()); lineStyle.setContour(ms2d.getContour()); lineStyle.setContourComposite(ms2d.getContourComposite()); lineStyle.setGraphicStroke(ms2d.getGraphicStroke()); filler.fillRectangle(shape.getBounds2D(), this, clippedGraphics, lineStyle); return;
while (!(citer.isDone())) { if (citer.currentSegment(coords) != PathIterator.SEG_MOVETO) { transformedShape = ms2d.getTransformedShape(coords[0], coords[1]); if (transformedShape != null) { if (ms2d.getFill() != null) { graphics.setPaint(ms2d.getFill()); graphics.setComposite(ms2d.getFillComposite()); graphics.fill(transformedShape); if (ms2d.getContour() != null) { graphics.setPaint(ms2d.getContour()); graphics.setStroke(ms2d.getStroke()); graphics.setComposite(ms2d.getContourComposite()); graphics.draw(transformedShape);
MarkStyle2D createMarkStyle(Mark mark, Object feature, Symbolizer symbolizer, double size) { Shape shape = getShape(mark, feature); if (shape == null) { throw new IllegalArgumentException( "The specified mark " + mark.getWellKnownName() + " was not found!"); } Composite composite = getComposite(symbolizer.getOptions()); MarkStyle2D ms2d = new MarkStyle2D(); ms2d.setShape(shape); ms2d.setFill(getPaint(mark.getFill(), feature, symbolizer)); ms2d.setFillComposite( composite != null ? composite : getComposite(mark.getFill(), feature)); ms2d.setStroke(getStroke(mark.getStroke(), feature)); ms2d.setContour(getStrokePaint(mark.getStroke(), feature)); ms2d.setContourComposite( composite != null ? composite : getStrokeComposite(mark.getStroke(), feature)); // in case of Mark we don't have a natural size, so we default // to 16 if (size <= 0) { size = DEFAULT_MARK_SIZE; } ms2d.setSize(size); return ms2d; }
ms2d.getTransformedShape( (float) x, (float) y, (float) rotation, (float) graphicRotation); if (transformedShape != null) { if (ms2d.getFill() != null) { graphics.setPaint(ms2d.getFill()); graphics.fill(transformedShape); if (ms2d.getContour() != null) { graphics.setPaint(ms2d.getContour()); graphics.setStroke(ms2d.getStroke()); graphics.draw(transformedShape);
public void testAlternativeMarkSizeCalculation() { MarkStyle2D ms = new MarkStyle2D(); ms.setSize(1); GeneralPath gp = new GeneralPath(); gp.moveTo(500, 0); gp.lineTo(-500, 0); gp.moveTo(200, -275); gp.lineTo(200, 275); ms.setShape(gp); Shape shape = ms.getTransformedShape(0, 0); Rectangle2D rect = shape.getBounds2D(); assertEquals(1.0, rect.getHeight(), 0.0001); assertEquals(1000.0 / 550.0, rect.getWidth(), 0.0001); MarkStyle2D.setMaxMarkSizeEnabled(true); shape = ms.getTransformedShape(0, 0); rect = shape.getBounds2D(); assertEquals(550.0 / 1000.0, rect.getHeight(), 0.0001); assertEquals(1.0, rect.getWidth(), 0.0001); }
MarkStyle2D mark = (MarkStyle2D) graphic; Shape original = mark.getShape(); Rectangle2D bounds = original.getBounds2D(); MarkStyle2D resized = (MarkStyle2D) mark.clone(); if (mode == GraphicResize.PROPORTIONAL) { if (width > height) { resized.setSize(Math.round(bounds.getHeight() * width / bounds.getWidth())); } else { resized.setSize(height); AffineTransform.getScaleInstance( width / bounds.getWidth(), height / bounds.getHeight())); resized.setShape(tss); resized.setSize(height);
if (graphicFill instanceof MarkStyle2D) Rectangle2D boundsFill = ((MarkStyle2D)graphicFill).getShape().getBounds2D(); double size = ((MarkStyle2D)graphicFill).getSize(); double aspect = (boundsFill.getHeight() > 0 && boundsFill.getWidth() > 0) ? boundsFill.getWidth()/boundsFill.getHeight() : 1.0; stippleSize = new Rectangle2D.Double(0, 0, size*aspect, size);
/** * Returns a shape that can be used to draw the mark at the x, y coordinates with appropriated * rotation and size (according to the current style) * * @param x the x coordinate where the mark will be drawn * @param y the y coordinate where the mark will be drawn * @return a shape that can be used to draw the mark */ public Shape getTransformedShape(float x, float y) { return getTransformedShape(x, y, 0, rotation); }
@Override protected Expression rescaleGraphicSize(Graphic gr) { Expression size = gr.getSize(); if (size == null || size == Expression.NIL) { PointSymbolizer symbolizer = sf.createPointSymbolizer(gr, null); Style2D style = ssf.createStyle(null, symbolizer, INFINITE_RANGE); if (style instanceof IconStyle2D) { IconStyle2D is = (IconStyle2D) style; size = ff.literal(is.getIcon().getIconHeight()); } else if (style instanceof GraphicStyle2D) { GraphicStyle2D gs = (GraphicStyle2D) style; size = ff.literal(gs.getImage().getHeight()); } else if (style instanceof MarkStyle2D) { MarkStyle2D ms = (MarkStyle2D) style; size = ff.literal(ms.getSize()); } } return rescale(size); } }
public void testCreateDynamicMark() throws Exception { PointSymbolizer symb = sf.createPointSymbolizer(); Mark myMark = sf.createMark(); final String ttfUrl = "ttf://Serif#${symb}"; myMark.setWellKnownName(ff.literal(ttfUrl)); symb.getGraphic().addMark(myMark); MarkStyle2D ms = (MarkStyle2D) sld.createStyle(feature, symb, range); assertNotNull(ms.getShape()); // make sure the style has been recognized as dynamic SymbolizerKey key = new SymbolizerKey(symb, range); assertTrue(sld.dynamicSymbolizers.containsKey(key)); Shape expected = new TTFMarkFactory().getShape(null, ff.literal("ttf://Serif#0xF054"), feature); // no general path equality implemented, we have to check manually PathIterator piExpected = expected.getPathIterator(new AffineTransform()); PathIterator pi = ms.getShape().getPathIterator(new AffineTransform()); double[] coordsExpected = new double[6]; double[] coords = new double[6]; assertEquals(piExpected.getWindingRule(), pi.getWindingRule()); while (!piExpected.isDone()) { assertFalse(pi.isDone()); piExpected.currentSegment(coordsExpected); pi.currentSegment(coords); assertEquals(coordsExpected[0], coords[0], 0.00001); assertEquals(coordsExpected[1], coords[1], 0.00001); piExpected.next(); pi.next(); } assertTrue(pi.isDone()); }
double graphicRotation = 0; // rotation in radians if (graphicStroke instanceof MarkStyle2D) { imageSize = ((MarkStyle2D) graphicStroke).getSize(); graphicRotation = ((MarkStyle2D) graphicStroke).getRotation(); } else if (graphicStroke instanceof IconStyle2D) { imageSize = ((IconStyle2D) graphicStroke).getIcon().getIconWidth();
Shape transformedShape = ms2d.getTransformedShape((float) x, (float) y, (float) rotation); if (transformedShape != null) { if (ms2d.getFill() != null) { graphics.setPaint(ms2d.getFill()); graphics.fill(transformedShape); if (ms2d.getContour() != null) { graphics.setPaint(ms2d.getContour()); graphics.setStroke(ms2d.getStroke()); graphics.draw(transformedShape);
MarkStyle2D mark = (MarkStyle2D) graphic; Shape original = mark.getShape(); Rectangle2D bounds = original.getBounds2D(); MarkStyle2D resized = (MarkStyle2D) mark.clone(); if(mode == GraphicResize.PROPORTIONAL) { if(width > height) { resized.setSize((int) Math.round(bounds.getHeight() * width / bounds.getWidth())); } else { resized.setSize((int) height); tss.shape = original; tss.setTransform(AffineTransform.getScaleInstance(width / bounds.getWidth(), height / bounds.getHeight())); resized.setShape(tss); resized.setSize((int) height);
if (graphicFill instanceof MarkStyle2D) Rectangle2D boundsFill = ((MarkStyle2D)graphicFill).getShape().getBounds2D(); double size = ((MarkStyle2D)graphicFill).getSize(); double aspect = (boundsFill.getHeight() > 0 && boundsFill.getWidth() > 0) ? boundsFill.getWidth()/boundsFill.getHeight() : 1.0; stippleSize = new Rectangle2D.Double(0, 0, size*aspect, size);
public Rectangle getGraphicDimensions() { if (graphic instanceof MarkStyle2D) { return ((MarkStyle2D) graphic).getTransformedShape(0f, 0f).getBounds(); } else if (graphic instanceof GraphicStyle2D) { BufferedImage i = ((GraphicStyle2D) graphic).getImage(); return new Rectangle(i.getWidth(), i.getHeight()); } else if (graphic instanceof IconStyle2D) { final Icon icon = ((IconStyle2D) graphic).getIcon(); return new Rectangle(icon.getIconWidth(), icon.getIconWidth()); } else { throw new RuntimeException( "Can't render graphic which is not a MarkStyle2D or a GraphicStyle2D"); } }
public static double getStyle2DSize(Style2D style) { if (style instanceof GraphicStyle2D) { final BufferedImage image = ((GraphicStyle2D) style).getImage(); return maxSize(image.getWidth(), image.getHeight()); } else if (style instanceof IconStyle2D) { final Icon icon = ((IconStyle2D) style).getIcon(); return maxSize(icon.getIconWidth(), icon.getIconHeight()); } else if (style instanceof LineStyle2D) { LineStyle2D ls = ((LineStyle2D) style); double gsSize = getStyle2DSize(ls.getGraphicStroke()); double strokeSize = 0; if (ls.getStroke() instanceof BasicStroke) { strokeSize = ((BasicStroke) ls.getStroke()).getLineWidth(); } double offset = ls.getPerpendicularOffset(); double lineSize = maxSize(maxSize(gsSize, strokeSize), offset); // a MarkStyle2D is also a LineStyle2D, but we have to account for the symbol size if (style instanceof MarkStyle2D) { MarkStyle2D mark = (MarkStyle2D) style; return mark.getSize() + lineSize; } else { return lineSize; } } else { return 0; } }
public Rectangle getGraphicDimensions() { if (graphic instanceof MarkStyle2D) return ((MarkStyle2D)graphic).getShape().getBounds(); else if (graphic instanceof GraphicStyle2D) { BufferedImage i = ((GraphicStyle2D)graphic).getImage(); return new Rectangle(i.getWidth(),i.getHeight()); } else { throw new RuntimeException("Can't render graphic which is not a MarkStyle2D or a GraphicStyle2D"); } }
citer.currentSegment(coords); Shape transformedShape = ms2d.getTransformedShape(coords[0], coords[1]); if (ms2d.getFill() != null) { graphics.setPaint(ms2d.getFill()); graphics.setComposite(ms2d.getFillComposite()); graphics.fill(transformedShape); if (ms2d.getContour() != null) { graphics.setPaint(ms2d.getContour()); graphics.setStroke(ms2d.getStroke()); graphics.setComposite(ms2d.getContourComposite()); graphics.draw(transformedShape);
.evaluate(feature).toString()); ms2d = new MarkStyle2D(); ms2d.setShape(shape); ms2d.setFill(getPaint(mark.getFill(), feature)); ms2d.setFillComposite(getComposite(mark.getFill(), feature)); ms2d.setStroke(getStroke(mark.getStroke(), feature)); ms2d.setContour(getStrokePaint(mark.getStroke(), feature)); ms2d.setContourComposite(getStrokeComposite(mark.getStroke(), feature)); ms2d.setSize(size); ms2d.setRotation(rotation); retval = ms2d;
Shape transformedShape = ms2d.getTransformedShape((float) x, (float) y, (float) rotation); if (transformedShape != null) { if (ms2d.getFill() != null) { graphics.setPaint(ms2d.getFill()); graphics.fill(transformedShape); if (ms2d.getContour() != null) { graphics.setPaint(ms2d.getContour()); graphics.setStroke(ms2d.getStroke()); graphics.draw(transformedShape);