public static IRenderingElement embedText ( Font font , String text , Color color , double scale ) { final String [ ] lines = text . split ( "\n" ) ; ElementGroup group = new ElementGroup ( ) ; double yOffset = 0 ; double lineHeight = 1.4d ; for ( String line : lines ) { TextOutline outline = new TextOutline ( line , font ) . resize ( scale , - scale ) ; Point2D center = outline . getCenter ( ) ; outline = outline . translate ( - center . getX ( ) , - ( center . getY ( ) + yOffset ) ) ; yOffset += lineHeight * outline . getBounds ( ) . getHeight ( ) ; group . add ( GeneralPath . shapeOf ( outline . getOutline ( ) , color ) ) ; Rectangle2D logicalBounds = outline . getLogicalBounds ( ) ; group . add ( new Bounds ( logicalBounds . getMinX ( ) , logicalBounds . getMinY ( ) , logicalBounds . getMaxX ( ) , logicalBounds . getMaxY ( ) ) ) ; } return group ; }
Make an embedded text label for display in a CDK renderer . If a piece of text contains newlines they are centred aligned below each other with a line height of 1 . 4 .