use of org.geotoolkit.display.shape.TransformedShape in project geotoolkit by Geomatys.
the class CachedMark method getImage.
public BufferedImage getImage(final Object candidate, final Float size, final RenderingHints hints) {
evaluate();
final Expression wkn = styleElement.getWellKnownName();
final ExternalMark external = styleElement.getExternalMark();
int j2dSize = 16;
float margin = 0;
int maxWidth = 0;
int center = 0;
Shape candidateShape = getShape(candidate, hints);
if (wkn != null || external != null) {
j2dSize = (size != null) ? size.intValue() : 16;
if (j2dSize < 0)
j2dSize = 0;
if (j2dSize > 1000)
j2dSize = 1000;
margin = cachedStroke.getMargin(candidate, 1);
maxWidth = (int) (margin * 2 + 0.5f) + j2dSize;
center = maxWidth / 2;
}
if (maxWidth < 1)
maxWidth = 1;
if (candidateShape != null) {
BufferedImage buffer = new BufferedImage(maxWidth, maxWidth, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2 = (Graphics2D) buffer.getGraphics();
if (hints != null)
g2.setRenderingHints(hints);
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2.translate(center, center);
TransformedShape trs = new TransformedShape();
trs.setOriginalShape(candidateShape);
trs.scale(j2dSize, j2dSize);
// trs.createTransformedShape(marker);
Shape shp = trs;
// test if we need to paint the fill
if (cachedFill.isVisible(candidate)) {
g2.setPaint(cachedFill.getJ2DPaint(candidate, 0, 0, 1, hints));
g2.setComposite(cachedFill.getJ2DComposite(candidate));
g2.fill(shp);
}
// test if we need to paint the stroke
if (cachedStroke.isVisible(candidate)) {
g2.setStroke(cachedStroke.getJ2DStroke(candidate, 1));
g2.setPaint(cachedStroke.getJ2DPaint(candidate, 0, 0, 1, hints));
g2.setComposite(cachedStroke.getJ2DComposite(candidate));
g2.draw(shp);
}
g2.dispose();
return buffer;
} else if (external != null) {
return createImage(external, j2dSize, hints);
}
return null;
}
use of org.geotoolkit.display.shape.TransformedShape in project geotoolkit by Geomatys.
the class PolygonSymbolizerRendererService method glyph.
/**
* {@inheritDoc }
*/
@Override
public void glyph(final Graphics2D g, final Rectangle2D rectangle, final CachedPolygonSymbolizer symbol, final MapLayer layer) {
final AffineTransform affine = new AffineTransform(rectangle.getWidth(), 0, 0, rectangle.getHeight(), rectangle.getX(), rectangle.getY());
g.setClip(rectangle);
final TransformedShape shape = new TransformedShape();
shape.setOriginalShape(GO2Utilities.GLYPH_POLYGON);
shape.setTransform(affine);
final Fill fill = symbol.getSource().getFill();
final Stroke stroke = symbol.getSource().getStroke();
if (fill != null) {
GO2Utilities.renderFill(shape, symbol.getSource().getFill(), g);
}
if (stroke != null) {
GO2Utilities.renderStroke(shape, symbol.getSource().getStroke(), symbol.getSource().getUnitOfMeasure(), g);
}
}
Aggregations