Bug 11965 fixed: Export to SVG converted texts in shapes 00/9400/2
Calixte DENIZET [Wed, 10 Oct 2012 13:24:19 +0000 (15:24 +0200)]
Requires http://codereview.forge.scilab.org/#/c/615/

Change-Id: I1d897a7a71fe2c6dcbd5f45623951547397cb4f4

scilab/CHANGES_5.4.X
scilab/modules/graphic_export/src/java/org/scilab/modules/graphic_export/Export.java
scilab/modules/graphic_export/tests/nonreg_tests/bug_11965.dia.ref [new file with mode: 0644]
scilab/modules/graphic_export/tests/nonreg_tests/bug_11965.tst [new file with mode: 0644]

index 88efd8d..cfa007b 100644 (file)
@@ -197,6 +197,8 @@ Bug fixes
 
 * Bug #12179 fixed - Fix an incompatibility with MPI version of HDF5.
 
+* Bug #11965 fixed - Export to SVG converted texts in shapes.
+
 
                     Changes between version 5.3.3 and 5.4.0
                     =======================================
index 7ba2362..48b0b4b 100644 (file)
@@ -24,6 +24,7 @@ import java.io.IOException;
 import java.io.OutputStream;
 import java.io.OutputStreamWriter;
 import java.io.Writer;
+import java.text.AttributedCharacterIterator;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.WeakHashMap;
@@ -198,11 +199,11 @@ public class Export {
             Canvas canvas = G2DCanvasFactory.createCanvas(g2d, width, height);
             DrawerVisitor oldVisitor = DrawerVisitor.getVisitor(uid);
             DrawerVisitor visitor = new DrawerVisitor(null, canvas, figure) {
-                    @Override
-                    public void updateObject(String id, int property) {
-                        // Don't update during the export
-                    }
-                };
+                @Override
+                public void updateObject(String id, int property) {
+                    // Don't update during the export
+                }
+            };
 
             try {
                 canvas.setMainDrawer(visitor);
@@ -297,16 +298,16 @@ public class Export {
                 DrawerVisitor oldVisitor = DrawerVisitor.getVisitor(uid);
                 joglCanvas = (JoGLCanvas) JoGLCanvasFactory.createCanvas(dims[0], dims[1]);
                 DrawerVisitor visitor = new DrawerVisitor(null, joglCanvas, figure) {
-                        @Override
-                        public void updateObject(String id, int property) {
-                            // Don't update during the export
-                        }
+                    @Override
+                    public void updateObject(String id, int property) {
+                        // Don't update during the export
+                    }
 
-                        @Override
-                        public void deleteObject(String id) {
-                            // Don't delete during the export
-                        }
-                    };
+                    @Override
+                    public void deleteObject(String id) {
+                        // Don't delete during the export
+                    }
+                };
                 joglCanvas.setMainDrawer(visitor);
                 joglCanvas.redraw();
                 GraphicController.getController().unregister(visitor);
@@ -343,11 +344,11 @@ public class Export {
         G2DCanvas canvas = G2DCanvasFactory.createCanvas(g2d, width, height);
         canvas.disableDraw();
         DrawerVisitor visitor = new DrawerVisitor(null, canvas, figure) {
-                @Override
-                public void deleteObject(String id) {
-                    // Don't delete during the export
-                }
-            };
+            @Override
+            public void deleteObject(String id) {
+                // Don't delete during the export
+            }
+        };
         visitor.setDrawingTools(canvas.getDrawingTools());
         canvas.setMainDrawer(visitor);
         visitorsToExp.put(visitor, exporter);
@@ -360,33 +361,33 @@ public class Export {
      */
     private static Exporter getExporter(TYPE type) {
         switch (type) {
-        case PNG :
-            return new PNGExporter();
-        case GIF :
-            return new GIFExporter();
-        case JPEG :
-            return new JPEGExporter();
-        case BMP :
-            return new BMPExporter();
-        case PPM :
-            return new PPMExporter();
-        case SVG :
-            if (!svgLoaded) {
-                ScilabCommonsUtils.loadOnUse(CLASSPATH_SVG_EXPORT_NAME);
-                svgLoaded = true;
-            }
-            return new SVGExporter();
-        case PDF :
-            loadPDF();
-            return new PDFExporter();
-        case PS :
-            loadPDF();
-            return new PSExporter();
-        case EPS :
-            loadPDF();
-            return new EPSExporter();
-        default :
-            break;
+            case PNG :
+                return new PNGExporter();
+            case GIF :
+                return new GIFExporter();
+            case JPEG :
+                return new JPEGExporter();
+            case BMP :
+                return new BMPExporter();
+            case PPM :
+                return new PPMExporter();
+            case SVG :
+                if (!svgLoaded) {
+                    ScilabCommonsUtils.loadOnUse(CLASSPATH_SVG_EXPORT_NAME);
+                    svgLoaded = true;
+                }
+                return new SVGExporter();
+            case PDF :
+                loadPDF();
+                return new PDFExporter();
+            case PS :
+                loadPDF();
+                return new PSExporter();
+            case EPS :
+                loadPDF();
+                return new EPSExporter();
+            default :
+                break;
         }
 
         return null;
@@ -551,12 +552,23 @@ public class Export {
             this.params = params;
             DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation();
             Document document = domImpl.createDocument("http://www.w3.org/2000/svg", "svg", null);
-            SVGGeneratorContext ctx = SVGGeneratorContext.createDefault(document);
+            final SVGGeneratorContext ctx = SVGGeneratorContext.createDefault(document);
             ctx.setComment("Generated by Scilab with Batik SVG Generator");
             // TODO: better handle of LaTeX fonts (should remove the 'true' below and include the font in the SVG)
             // same thing for PDF & co...
             ctx.setEmbeddedFontsOn(true);
-            g2d = new SVGGraphics2D(ctx, true);
+            g2d = new SVGGraphics2D(ctx, false) {
+
+                public void drawString(String s, float x, float y) {
+                    textAsShapes = getFont().getFontName().startsWith("jlm");
+                    super.drawString(s, x, y);
+                }
+
+                public void drawString(AttributedCharacterIterator ati, float x, float y) {
+                    textAsShapes = getFont().getFontName().startsWith("jlm");
+                    super.drawString(ati, x, y);
+                }
+            };
             if (params.orientation == ExportParams.LANDSCAPE) {
                 g2d.setSVGCanvasSize(new Dimension(height, width));
                 AffineTransform transf = AffineTransform.getRotateInstance(Math.PI / 2);
@@ -674,16 +686,16 @@ public class Export {
                     out = new BufferedOutputStream(new FileOutputStream(file));
                 }
                 g2d = new PSDocumentGraphics2D(true, out, width, height) {
-                        @Override
-                        protected void writePageHeader() throws IOException {
-                            super.writePageHeader();
-                            if (params.orientation == ExportParams.LANDSCAPE) {
-                                gen.writeDSCComment(DSCConstants.PAGE_ORIENTATION, "Landscape");
-                            } else {
-                                gen.writeDSCComment(DSCConstants.PAGE_ORIENTATION, "Portrait");
-                            }
+                    @Override
+                    protected void writePageHeader() throws IOException {
+                        super.writePageHeader();
+                        if (params.orientation == ExportParams.LANDSCAPE) {
+                            gen.writeDSCComment(DSCConstants.PAGE_ORIENTATION, "Landscape");
+                        } else {
+                            gen.writeDSCComment(DSCConstants.PAGE_ORIENTATION, "Portrait");
                         }
-                    };
+                    }
+                };
                 g2d.setGraphicContext(new GraphicContext());
             } catch (IOException e) { }
 
@@ -732,16 +744,16 @@ public class Export {
                     out = new BufferedOutputStream(new FileOutputStream(file));
                 }
                 g2d = new EPSDocumentGraphics2D(true) {
-                        @Override
-                        protected void writePageHeader() throws IOException {
-                            super.writePageHeader();
-                            if (params.orientation == ExportParams.LANDSCAPE) {
-                                gen.writeDSCComment(DSCConstants.PAGE_ORIENTATION, "Landscape");
-                            } else {
-                                gen.writeDSCComment(DSCConstants.PAGE_ORIENTATION, "Portrait");
-                            }
+                    @Override
+                    protected void writePageHeader() throws IOException {
+                        super.writePageHeader();
+                        if (params.orientation == ExportParams.LANDSCAPE) {
+                            gen.writeDSCComment(DSCConstants.PAGE_ORIENTATION, "Landscape");
+                        } else {
+                            gen.writeDSCComment(DSCConstants.PAGE_ORIENTATION, "Portrait");
                         }
-                    };
+                    }
+                };
                 g2d.setupDocument(out, width, height);
                 g2d.setGraphicContext(new GraphicContext());
             } catch (IOException e) { }
diff --git a/scilab/modules/graphic_export/tests/nonreg_tests/bug_11965.dia.ref b/scilab/modules/graphic_export/tests/nonreg_tests/bug_11965.dia.ref
new file mode 100644 (file)
index 0000000..a9f3636
--- /dev/null
@@ -0,0 +1,26 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2012 - Scilab Enterprises - Calixte DENIZET
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+//
+// <-- Non-regression test for bug 11965 -->
+//
+// <-- Bugzilla URL -->
+// http://bugzilla.scilab.org/11965
+//
+// <-- Short Description -->
+// Export to SVG converted texts in shapes.
+driver("SVG")
+ ans  =
+ Rec   
+xinit(TMPDIR+"/plop.svg")
+xtitle('this appears as bezier','x','y')
+xend();
+doc=xmlRead(TMPDIR+"/plop.svg");
+xp=xmlXPath(doc, "//*[local-name()=''text'']");
+strs=xmlAsText(xp);
+xmlDelete(doc);
+assert_checktrue(or(strs=="this appears as bezier"));
diff --git a/scilab/modules/graphic_export/tests/nonreg_tests/bug_11965.tst b/scilab/modules/graphic_export/tests/nonreg_tests/bug_11965.tst
new file mode 100644 (file)
index 0000000..f8af1e7
--- /dev/null
@@ -0,0 +1,27 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2012 - Scilab Enterprises - Calixte DENIZET
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+//
+// <-- Non-regression test for bug 11965 -->
+//
+// <-- Bugzilla URL -->
+// http://bugzilla.scilab.org/11965
+//
+// <-- Short Description -->
+// Export to SVG converted texts in shapes.
+
+
+driver("SVG")
+xinit(TMPDIR+"/plop.svg")
+xtitle('this appears as bezier','x','y')
+xend();
+
+doc=xmlRead(TMPDIR+"/plop.svg");
+xp=xmlXPath(doc, "//*[local-name()=''text'']");
+strs=xmlAsText(xp);
+xmlDelete(doc);
+
+assert_checktrue(or(strs=="this appears as bezier"));