]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Added cleaner rendering hint to decide text rendering mode: text/paths 92/992/2
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Tue, 19 Sep 2017 06:50:05 +0000 (09:50 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Tue, 19 Sep 2017 08:05:41 +0000 (11:05 +0300)
refs #7491

Change-Id: I0c22413f149b25fcfc16cde2c2f7279a9e0eaa55

bundles/org.simantics.diagram/src/org/simantics/diagram/elements/TextNode.java
bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/G2DPDFRenderingHints.java
bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/nodes/FlagNode.java

index 4554decee2c01a41b032be9dab5c77ecec2af2f7..9d39bbfdedccc4287b9eca1049d133c07c910da5 100644 (file)
@@ -51,6 +51,7 @@ import org.simantics.scenegraph.LoaderNode;
 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;
@@ -710,7 +711,8 @@ public class TextNode extends G2DNode implements IDynamicSelectionPainterNode, L
 
         // 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;
@@ -730,7 +732,7 @@ public class TextNode extends G2DNode implements IDynamicSelectionPainterNode, L
 
                 // Base text
                 g.setColor(color);
-                renderText(g, xOffset, isRenderingPdf);
+                renderText(g, xOffset, renderAsText);
 
                 Shape clip = g.getClip();
 
@@ -744,7 +746,7 @@ public class TextNode extends G2DNode implements IDynamicSelectionPainterNode, L
                         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);
@@ -760,7 +762,7 @@ public class TextNode extends G2DNode implements IDynamicSelectionPainterNode, L
 
                 if (renderText) {
                     g.setColor(color);
-                    renderText(g, 0, isRenderingPdf);
+                    renderText(g, 0, renderAsText);
                 }
 
             }
@@ -823,11 +825,11 @@ public class TextNode extends G2DNode implements IDynamicSelectionPainterNode, L
           }
         }
     }
-    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);
index ffdcc32ab31a09e8316b180b592e076ab7b31f38..0b9a57474057a41247b69c82e7fbf9e9846ab628 100644 (file)
@@ -62,6 +62,29 @@ public final class G2DPDFRenderingHints {
             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
index 598e130091391303febf5b14cbe039e4bda3ef2e..756804f7dc4e900c3d8ee2e66bb57ed3caf477f2 100644 (file)
@@ -28,8 +28,11 @@ import java.util.Arrays;
 
 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;
@@ -310,7 +313,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(G2DPDFRenderingHints.KEY_TEXT_RENDERING_MODE) == TextRenderingMode.AS_TEXT;
 
             for (int i = 0; i < flagText.length; ++i) {
                 //String line = flagText[i];
@@ -343,7 +347,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);