/** * @param mark * @param size * @param uom * @param context * @param x * @param y * @param rotation */ public static void renderMark( Mark mark, int size, UOM uom, RendererContext context, double x, double y, double rotation ) { if ( size == 0 ) { LOG.debug( "Not rendering a symbol because the size is zero." ); return; } if ( mark.fill == null && mark.stroke == null ) { LOG.debug( "Not rendering a symbol because no fill/stroke is available/configured." ); return; } Shape shape = getShapeFromMark( mark, size - 1, rotation, true, x, y ); if ( mark.fill != null ) { context.fillRenderer.applyFill( mark.fill, uom ); context.graphics.fill( shape ); } if ( mark.stroke != null ) { context.strokeRenderer.applyStroke( mark.stroke, uom, shape, 0, null ); } }
void applyFill( Fill fill, UOM uom ) { if ( fill == null ) { graphics.setPaint( new Color( 0, 0, 0, 0 ) ); return; } if ( fill.graphic == null ) { graphics.setPaint( fill.color ); } else { applyGraphicFill( fill.graphic, uom ); } }
void applyGraphicFill( Graphic graphic, UOM uom ) { BufferedImage img; if ( graphic.image == null ) { int size = round( uomCalculator.considerUOM( graphic.size, uom ) ); img = new BufferedImage( size, size, TYPE_INT_ARGB ); Graphics2D g = img.createGraphics(); Java2DRenderer renderer = new Java2DRenderer( g ); renderMark( graphic.mark, graphic.size < 0 ? 6 : size, uom, renderer.rendererContext, 0, 0, graphic.rotation ); g.dispose(); } else { img = graphic.image; } graphics.setPaint( new TexturePaint( img, getGraphicBounds( graphic, 0, 0, uom ) ) ); }
RendererContext( double pixelSize, double res, Graphics2D graphics, Java2DRenderer renderer, Envelope bbox, int width, AffineTransform worldToScreen ) { this.graphics = graphics; if ( bbox != null ) { geomHelper = new GeometryHelper( bbox, width, worldToScreen ); clipper = new GeometryClipper( bbox, width ); } uomCalculator = new UomCalculator( pixelSize, res ); fillRenderer = new Java2DFillRenderer( uomCalculator, graphics ); strokeRenderer = new Java2DStrokeRenderer( graphics, uomCalculator, fillRenderer ); svgRenderer = new SvgRenderer(); polygonRenderer = new PolygonRenderer( geomHelper, fillRenderer, strokeRenderer, graphics, renderer ); curveRenderer = new CurveRenderer( renderer ); pointRenderer = new PointRenderer( renderer.worldToScreen, this ); }
void render( TextStyling styling, Font font, String text, Curve c ) { java.awt.Stroke stroke = new TextStroke( text, font, styling.linePlacement ); if ( isZero( ( (TextStroke) stroke ).getLineHeight() ) ) { return; } stroke = applyOffset( styling, stroke ); Double line = renderer.rendererContext.geomHelper.fromCurve( c, false ); if ( styling.halo != null ) { Stroke haloStroke = new HaloStroke( text, font, styling.linePlacement, styling.halo, styling.uom, renderer.rendererContext.uomCalculator ); haloStroke = applyOffset( styling, haloStroke ); renderer.rendererContext.fillRenderer.applyFill( styling.halo.fill, styling.uom ); renderer.graphics.setStroke( haloStroke ); renderer.graphics.draw( line ); } renderer.rendererContext.fillRenderer.applyFill( styling.fill, styling.uom ); renderer.graphics.setStroke( stroke ); renderer.graphics.draw( line ); }
void applyStroke( Stroke stroke, UOM uom, Shape object, double perpendicularOffset, PerpendicularOffsetType type ) { if ( stroke == null || isZero( stroke.width ) ) { graphics.setPaint( new Color( 0, 0, 0, 0 ) ); return; } if ( stroke.fill == null ) { graphics.setPaint( stroke.color ); } else { fillRenderer.applyGraphicFill( stroke.fill, uom ); } if ( stroke.stroke != null ) { if ( applyGraphicStroke( stroke, uom, object, perpendicularOffset, type ) ) { return; } } else { applyNormalStroke( stroke, uom, object, perpendicularOffset, type ); } graphics.draw( object ); }
void render( PointStyling styling, double x, double y ) { Point2D.Double p = (Point2D.Double) worldToScreen.transform( new Point2D.Double( x, y ), null ); x = p.x; y = p.y; Graphic g = styling.graphic; Rectangle2D.Double rect = rendererContext.fillRenderer.getGraphicBounds( g, x, y, styling.uom ); if ( g.image == null && g.imageURL == null ) { renderMark( g.mark, g.size < 0 ? 6 : round( rendererContext.uomCalculator.considerUOM( g.size, styling.uom ) ), styling.uom, rendererContext, rect.getMinX(), rect.getMinY(), g.rotation ); return; } BufferedImage img = g.image; // try if it's an svg if ( img == null && g.imageURL != null ) { img = rendererContext.svgRenderer.prepareSvg( rect, g ); } if ( img != null ) { // TODO: fix rotation if anchor point is not 0.5,0.5 - see org.deegree.rendering.r2d.Java2DRendererTest.testPointStyling() AffineTransform t = rendererContext.graphics.getTransform(); if ( !isZero( g.rotation ) ) { int rotationPointX = round( rect.x + rect.getWidth() * g.anchorPointX ); int rotationPointY = round( rect.y + rect.getHeight() * g.anchorPointY ); rendererContext.graphics.rotate( toRadians( g.rotation ), rotationPointX, rotationPointY ); } rendererContext.graphics.drawImage( img, round( rect.x ), round( rect.y ), round( rect.width ), round( rect.height ), null ); rendererContext.graphics.setTransform( t ); } }
void render( PolygonStyling styling, Surface surface ) { for ( SurfacePatch patch : surface.getPatches() ) { if ( patch instanceof PolygonPatch ) { LinkedList<Double> lines = new LinkedList<Double>(); PolygonPatch polygonPatch = (PolygonPatch) patch; // just appending the holes appears to work, the Java2D rendering mechanism can determine that they lie // inside and thus no substraction etc. is needed. This speeds up things SIGNIFICANTLY GeneralPath polygon = new GeneralPath( WIND_EVEN_ODD ); for ( Curve curve : polygonPatch.getBoundaryRings() ) { Double d = geomHelper.fromCurve( curve, true ); lines.add( d ); polygon.append( d, false ); } fillRenderer.applyFill( styling.fill, styling.uom ); graphics.fill( polygon ); for ( Double d : lines ) { strokeRenderer.applyStroke( styling.stroke, styling.uom, d, styling.perpendicularOffset, styling.perpendicularOffsetType ); } } else { throw new IllegalArgumentException( "Cannot render non-planar surfaces." ); } } }
@Override public void render( Label pLabel ) { renderer.graphics.setFont( pLabel.getFont() ); AffineTransform transform = renderer.graphics.getTransform(); renderer.graphics.rotate( toRadians( pLabel.getStyling().rotation ), pLabel.getOrigin().x, pLabel.getOrigin().y ); if ( pLabel.getStyling().halo != null ) { context.fillRenderer.applyFill( pLabel.getStyling().halo.fill, pLabel.getStyling().uom ); BasicStroke stroke = new BasicStroke( round( 2 * context.uomCalculator.considerUOM( pLabel.getStyling().halo.radius, pLabel.getStyling().uom ) ), CAP_BUTT, JOIN_ROUND ); renderer.graphics.setStroke( stroke ); renderer.graphics.draw( pLabel.getLayout().getOutline( getTranslateInstance( pLabel.getDrawPosition().x, pLabel.getDrawPosition().y ) ) ); } //LOG.debug("LabelRender w:" + pLabel.getLayout().getBounds().getWidth() + " h: "+pLabel.getLayout().getBounds().getHeight()+" x: "+pLabel.getDrawPosition().x + " y: "+pLabel.getDrawPosition().y); renderer.graphics.setStroke( new BasicStroke() ); context.fillRenderer.applyFill( pLabel.getStyling().fill, pLabel.getStyling().uom ); pLabel.getLayout().draw( renderer.graphics, (float) pLabel.getDrawPosition().x, (float) pLabel.getDrawPosition().y ); renderer.graphics.setTransform( transform ); }
transed = s.createStrokedShape( transed ); if ( stroke.stroke.mark.fill != null ) { fillRenderer.applyFill( stroke.stroke.mark.fill, uom ); graphics.fill( transed );