X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.scenegraph%2Fsrc%2Forg%2Fsimantics%2Fscenegraph%2Fg2d%2Fnodes%2FFlagNode.java;h=b2e973949517d7e66ff06391c7e1b20e27bd90fc;hb=a9513be166b1fd5c369b013fedfdd39f07685a2c;hp=4468996fb81d57e995bcc0c34162feb94e672cd8;hpb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/nodes/FlagNode.java b/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/nodes/FlagNode.java index 4468996fb..b2e973949 100644 --- a/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/nodes/FlagNode.java +++ b/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/nodes/FlagNode.java @@ -28,6 +28,8 @@ import java.util.Arrays; import org.simantics.scenegraph.g2d.G2DNode; import org.simantics.scenegraph.g2d.G2DPDFRenderingHints; +import org.simantics.scenegraph.g2d.G2DRenderingHints; +import org.simantics.scenegraph.g2d.G2DRenderingHints.TextRenderingMode; import org.simantics.scenegraph.utils.GeometryUtils; public class FlagNode extends G2DNode { @@ -49,7 +51,7 @@ public class FlagNode extends G2DNode { static transient final BasicStroke STROKE = new BasicStroke(0.25f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER); - final transient Font FONT = Font.decode("Arial 12"); + public final static Font DEFAULT_FONT = Font.decode("Arial 12"); protected boolean visible; @@ -66,6 +68,7 @@ public class FlagNode extends G2DNode { protected Rectangle2D textArea; protected byte hAlign; protected byte vAlign; + protected Font font = DEFAULT_FONT; private transient final Point2D origin = new Point2D.Double(); private transient final Point2D xa = new Point2D.Double(); @@ -85,8 +88,8 @@ public class FlagNode extends G2DNode { return visible; } - @SyncField({"visible", "flagShape", "flagText", "stroke", "border", "fill", "textColor", "width", "height", "direction", "beakAngle", "textSize", "hAlign", "vAlign"}) - public void init(Shape flagShape, String[] flagText, Stroke stroke, Color border, Color fill, Color textColor, float width, float height, double direction, float beakAngle, Rectangle2D textArea, int hAlign, int vAlign) { + @SyncField({"visible", "flagShape", "flagText", "stroke", "border", "fill", "textColor", "width", "height", "direction", "beakAngle", "textSize", "hAlign", "vAlign", "font"}) + public void init(Shape flagShape, String[] flagText, Stroke stroke, Color border, Color fill, Color textColor, float width, float height, double direction, float beakAngle, Rectangle2D textArea, int hAlign, int vAlign, Font font) { this.visible = true; this.flagShape = flagShape; this.flagText = flagText; @@ -101,6 +104,7 @@ public class FlagNode extends G2DNode { this.textArea = textArea; this.hAlign = (byte) hAlign; this.vAlign = (byte) vAlign; + this.font = font; resetCaches(); } @@ -165,8 +169,7 @@ public class FlagNode extends G2DNode { } // Paint flag text - Font f = FONT; - g.setFont(f); + g.setFont(font); g.setColor(textColor); AffineTransform orig = g.getTransform(); @@ -240,7 +243,7 @@ public class FlagNode extends G2DNode { System.out.println("transform: " + g.getTransform()); } - FontMetrics fm = g.getFontMetrics(f); + FontMetrics fm = g.getFontMetrics(font); double fontHeight = fm.getHeight(); if (textLayout == null || (float) scale != lastViewScale) @@ -254,7 +257,7 @@ public class FlagNode extends G2DNode { textHeight = 0; for (int i = 0; i < flagText.length; ++i) { String txt = flagText[i].isEmpty() ? " " : flagText[i]; - textLayout[i] = new TextLayout(txt, f, frc); + textLayout[i] = new TextLayout(txt, font, frc); rects[i] = textLayout[i].getBounds(); // If the bb height is not overridden with the font height @@ -309,7 +312,8 @@ public class FlagNode extends G2DNode { lineDist *= gScaleRecip; double y = startY; double textAreaWidth = textArea.getWidth() * gScaleRecip; - boolean isRenderingPdf = g.getRenderingHint(G2DPDFRenderingHints.KEY_PDF_WRITER) != null; + boolean renderAsText = g.getRenderingHint(G2DPDFRenderingHints.KEY_PDF_WRITER) != null + || g.getRenderingHint(G2DRenderingHints.KEY_TEXT_RENDERING_MODE) == TextRenderingMode.AS_TEXT; for (int i = 0; i < flagText.length; ++i) { //String line = flagText[i]; @@ -342,7 +346,7 @@ public class FlagNode extends G2DNode { System.out.println(" DRAW: '" + flagText[i] + "' with " + g.getTransform()); // #6459: render as text in PDF and paths on screen - if (isRenderingPdf) + if (renderAsText) g.drawString(flagText[i], (float) x, (float) y); else textLayout[i].draw(g, (float) x, (float) y);