import org.simantics.scenegraph.g2d.G2DNode;
import org.simantics.scenegraph.g2d.G2DPDFRenderingHints;
+import org.simantics.scenegraph.g2d.G2DPDFRenderingHints.TextRenderingMode;
import org.simantics.scenegraph.utils.GeometryUtils;
+import com.lowagie.text.pdf.PdfWriter;
+
public class FlagNode extends G2DNode {
private static final long serialVersionUID = -1716729504104107151L;
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;
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();
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;
this.textArea = textArea;
this.hAlign = (byte) hAlign;
this.vAlign = (byte) vAlign;
+ this.font = font;
resetCaches();
}
}
// Paint flag text
- Font f = FONT;
- g.setFont(f);
+ g.setFont(font);
g.setColor(textColor);
AffineTransform orig = g.getTransform();
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)
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
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(G2DPDFRenderingHints.KEY_TEXT_RENDERING_MODE) == TextRenderingMode.AS_TEXT;
for (int i = 0; i < flagText.length; ++i) {
//String line = flagText[i];
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);