Label(TextLayout pLayout, TextStyling pStyling, Font pFont, String pText, Point2D.Double pOrigin, RendererContext context){ mLayout = pLayout; mStyling = pStyling; mFont = pFont; mText = pText; mOrigin = pOrigin; double ox = mOrigin.x + context.uomCalculator.considerUOM( mStyling.displacementX, mStyling.uom ); double oy = mOrigin.y - context.uomCalculator.considerUOM( mStyling.displacementY, mStyling.uom ); double px = ox - ( mStyling.anchorPointX * mLayout.getBounds().getWidth() ); double py = oy + ( mStyling.anchorPointY * mLayout.getBounds().getHeight() ); mDrawPosition = new Point2D.Double(px,py); }
Rectangle2D.Double getGraphicBounds( Graphic graphic, double x, double y, UOM uom ) { double width, height; if ( graphic.image != null ) { double max = Math.max( graphic.image.getWidth(), graphic.image.getHeight() ); double fac = graphic.size / max; width = fac * graphic.image.getWidth(); height = fac * graphic.image.getHeight(); } else { width = graphic.size; height = graphic.size; } width = uomCalculator.considerUOM( width, uom ); height = uomCalculator.considerUOM( height, uom ); if ( width < 0 ) { if ( graphic.image == null ) { width = 6; height = 6; } else { width = graphic.image.getWidth(); height = graphic.image.getHeight(); } } double x0 = x - width * graphic.anchorPointX + uomCalculator.considerUOM( graphic.displacementX, uom ); double y0 = y - height * graphic.anchorPointY + uomCalculator.considerUOM( graphic.displacementY, uom ); return new Rectangle2D.Double( x0, y0, width, height ); }
private void applyNormalStroke( Stroke stroke, UOM uom, Shape object, double perpendicularOffset, PerpendicularOffsetType type ) { int linecap = getLinecap( stroke ); float miterLimit = 10; int linejoin = getLinejoin( stroke ); float dashoffset = (float) uomCalculator.considerUOM( stroke.dashoffset, uom ); float[] dasharray = stroke.dasharray == null ? null : new float[stroke.dasharray.length]; if ( dasharray != null ) { for ( int i = 0; i < stroke.dasharray.length; ++i ) { dasharray[i] = (float) uomCalculator.considerUOM( stroke.dasharray[i], uom ); } } BasicStroke bs = new BasicStroke( (float) uomCalculator.considerUOM( stroke.width, uom ), linecap, linejoin, miterLimit, dasharray, dashoffset ); double poff = uomCalculator.considerUOM( perpendicularOffset, uom ); if ( !isZero( poff ) ) { graphics.setStroke( new OffsetStroke( poff, bs, type ) ); } else { graphics.setStroke( bs ); } }
@Override protected void appendShape( GeneralPath result, Shape transformedShape ) { BasicStroke stroke = new BasicStroke( round( 2 * uomCalculator.considerUOM( halo.radius, uom ) ), CAP_BUTT, JOIN_ROUND ); Shape haloShape = stroke.createStrokedShape( transformedShape ); result.append( haloShape, false ); }
protected Font convertFont( TextStyling styling ) { AffineTransform shear = null; int style = styling.font.bold ? BOLD : PLAIN; switch ( styling.font.fontStyle ) { case ITALIC: style += ITALIC; break; case NORMAL: style += PLAIN; // yes, it's zero, but the code looks nicer this way break; case OBLIQUE: // Shear the font horizontally to achieve obliqueness shear = new AffineTransform(); shear.shear( -0.2, 0 ); break; } // use the first matching name, or Dialog, if none was found int size = round( renderer.rendererContext.uomCalculator.considerUOM( styling.font.fontSize, styling.uom ) ); Font font = new Font( "", style, size ); for ( String name : styling.font.fontFamily ) { font = new Font( name, style, size ); if ( !font.getFamily().equalsIgnoreCase( "dialog" ) ) { break; } } if ( styling.font.fontStyle == Style.OBLIQUE && shear != null ) font = font.deriveFont( shear ); return font; }
/** * Creates a PointLabelPositionOptions - Object containing the original label, * * @param label * The label to autoposition * * @param uomCalculator * The {@link UomCalculator} from the RenderContext, used to calculate the correct displacement */ public PointLabelPositionOptions( Label label, UomCalculator uomCalculator ){ this.label = label; TextStyling styling = label.getStyling(); displacementX = uomCalculator.considerUOM( styling.displacementX, styling.uom ); displacementY = uomCalculator.considerUOM( styling.displacementY, styling.uom ); select(0); calcTotalBoundingBox(); totalPolygon = getPolygon(totalMinX, totalMinY, totalMaxX, totalMaxY); }
null ); double x = pt.x + renderer.rendererContext.uomCalculator.considerUOM( styling.displacementX, styling.uom ); double y = pt.y - renderer.rendererContext.uomCalculator.considerUOM( styling.displacementY, styling.uom ); renderer.graphics.setFont( font ); AffineTransform transform = renderer.graphics.getTransform(); round( 2 * renderer.rendererContext.uomCalculator.considerUOM( styling.halo.radius, styling.uom ) ), CAP_BUTT, JOIN_ROUND );
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 ) ) ); }
if ( stroke.stroke.image == null && stroke.stroke.imageURL != null ) { Shape shape = getShapeFromSvg( stroke.stroke.imageURL, uomCalculator.considerUOM( stroke.stroke.size, uom ), stroke.stroke.rotation ); graphics.setStroke( new ShapeStroke( shape, uomCalculator.considerUOM( stroke.strokeGap + stroke.stroke.size, uom ), stroke.positionPercentage, stroke.strokeInitialGap ) ); } else if ( stroke.stroke.mark != null ) { double poff = uomCalculator.considerUOM( perpendicularOffset, uom ); Shape transed = object; if ( !isZero( poff ) ) { Shape shape = getShapeFromMark( stroke.stroke.mark, sz <= 0 ? 6 : uomCalculator.considerUOM( sz, uom ), stroke.stroke.rotation ); if ( sz <= 0 ) { sz = 6; ShapeStroke s = new ShapeStroke( shape, uomCalculator.considerUOM( stroke.strokeGap + sz, uom ), stroke.positionPercentage, stroke.strokeInitialGap ); transed = s.createStrokedShape( transed );
@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 ); }
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 ); } }