import org.simantics.scenegraph.ScenegraphUtils;
import org.simantics.scenegraph.g2d.G2DNode;
import org.simantics.scenegraph.g2d.G2DPDFRenderingHints;
+import org.simantics.scenegraph.g2d.G2DPDFRenderingHints.TextRenderingMode;
import org.simantics.scenegraph.g2d.events.Event;
import org.simantics.scenegraph.g2d.events.EventTypes;
import org.simantics.scenegraph.g2d.events.KeyEvent.KeyPressedEvent;
// PDF
PdfWriter writer = (PdfWriter) g.getRenderingHint(G2DPDFRenderingHints.KEY_PDF_WRITER);
- boolean isRenderingPdf = writer != null;
+ TextRenderingMode renderingMode = (TextRenderingMode) g.getRenderingHint(G2DPDFRenderingHints.KEY_TEXT_RENDERING_MODE);
+ boolean renderAsText = writer != null || renderingMode == TextRenderingMode.AS_TEXT;
/// PDF
Color backgroundColor = hasState(STATE_VALID) ? this.backgroundColor : Color.red;
// Base text
g.setColor(color);
- renderText(g, xOffset, isRenderingPdf);
+ renderText(g, xOffset, renderAsText);
Shape clip = g.getClip();
g.fill(selShape);
g.setColor(Color.WHITE);
// #6459: render as text in PDF and paths on screen
- if (isRenderingPdf)
+ if (renderAsText)
g.drawString(line.getText(), 0, 0);
else
line.layout.draw(g, 0, 0);
if (renderText) {
g.setColor(color);
- renderText(g, 0, isRenderingPdf);
+ renderText(g, 0, renderAsText);
}
}
}
}
}
- private void renderText(Graphics2D g, float xOffset, boolean isRenderingPdf) {
+ private void renderText(Graphics2D g, float xOffset, boolean renderAsText) {
//g.draw(tightBoundsCache); // DEBUG
for (Line line : lines) {
// #6459: render as text in PDF and paths on screen
- if (isRenderingPdf)
+ if (renderAsText)
g.drawString(line.getText(), line.alignedPosX + xOffset, line.alignedPosY);
else
line.layout.draw(g, line.alignedPosX + xOffset, line.alignedPosY);
return val instanceof FontMapper;
}
};
-
+
+ /**
+ * If this hint is not specified, the default interpretation should be
+ * {@value #AS_PATHS}.
+ *
+ * @since 1.31.0
+ */
+ public static enum TextRenderingMode {
+ AS_PATHS,
+ AS_TEXT
+ }
+
+ /**
+ * A rendering hint for telling text rendering Simantics G2D scene graph node
+ * implementations how to render the text: as text or paths.
+ *
+ * @since 1.31.0
+ */
+ public static final Key KEY_TEXT_RENDERING_MODE = new Key(2004) {
+ @Override
+ public boolean isCompatibleValue(Object val) {
+ return val instanceof TextRenderingMode;
+ }
+ };
}
\ No newline at end of file
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;
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);