You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by ss...@apache.org on 2015/07/31 17:04:32 UTC

svn commit: r1693613 - in /xmlgraphics/fop/trunk: src/java/org/apache/fop/render/ps/PSPainter.java test/java/org/apache/fop/render/ps/PSPainterTestCase.java

Author: ssteiner
Date: Fri Jul 31 15:04:31 2015
New Revision: 1693613

URL: http://svn.apache.org/r1693613
Log:
FOP-2508: TTF bullet missing when OTF used

Modified:
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSPainter.java
    xmlgraphics/fop/trunk/test/java/org/apache/fop/render/ps/PSPainterTestCase.java

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSPainter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSPainter.java?rev=1693613&r1=1693612&r2=1693613&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSPainter.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSPainter.java Fri Jul 31 15:04:31 2015
@@ -377,12 +377,8 @@ public class PSPainter extends AbstractI
             Font font = getFontInfo().getFontInstance(triplet, sizeMillipoints);
 
             PSFontResource res = getDocumentHandler().getPSResourceForFontKey(fontKey);
-            if (tf instanceof MultiByteFont && ((MultiByteFont)tf).isOTFFile()) {
-                generator.writeln("/" + res.getName() + ".0 "
-                        + generator.formatDouble(sizeMillipoints / 1000f) + " F");
-            } else {
-                useFont(fontKey, sizeMillipoints);
-            }
+            boolean otf = tf instanceof MultiByteFont && ((MultiByteFont)tf).isOTFFile();
+            useFont(fontKey, sizeMillipoints, otf);
 
             if (dp != null && dp[0] != null) {
                 x += dp[0][0];
@@ -406,9 +402,9 @@ public class PSPainter extends AbstractI
                                     letterSpacing, wordSpacing, dp, font, tf, false);
                         }
                         if (encoding == 0) {
-                            useFont(fontKey, sizeMillipoints);
+                            useFont(fontKey, sizeMillipoints, false);
                         } else {
-                            useFont(fontKey + "_" + Integer.toString(encoding), sizeMillipoints);
+                            useFont(fontKey + "_" + Integer.toString(encoding), sizeMillipoints, false);
                         }
                         currentEncoding = encoding;
                         start = i;
@@ -438,7 +434,7 @@ public class PSPainter extends AbstractI
                         }
                     }
                 } else {
-                    useFont(fontKey, sizeMillipoints);
+                    useFont(fontKey, sizeMillipoints, false);
                 }
             }
             writeText(text, start, textLen - start, letterSpacing, wordSpacing, dp, font, tf,
@@ -580,10 +576,16 @@ public class PSPainter extends AbstractI
         return lineStart;
     }
 
-    private void useFont(String key, int size) throws IOException {
+    private void useFont(String key, int size, boolean otf) throws IOException {
         PSFontResource res = getDocumentHandler().getPSResourceForFontKey(key);
         PSGenerator generator = getGenerator();
-        generator.useFont("/" + res.getName(), size / 1000f);
+        if (otf) {
+            String name = "/" + res.getName() + ".0";
+            generator.getCurrentState().useFont(name, size);
+            generator.writeln(name + ' ' + generator.formatDouble(size / 1000f) + " F");
+        } else {
+            generator.useFont("/" + res.getName(), size / 1000f);
+        }
         res.notifyResourceUsageOnPage(generator.getResourceTracker());
     }
 }

Modified: xmlgraphics/fop/trunk/test/java/org/apache/fop/render/ps/PSPainterTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/test/java/org/apache/fop/render/ps/PSPainterTestCase.java?rev=1693613&r1=1693612&r2=1693613&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/test/java/org/apache/fop/render/ps/PSPainterTestCase.java (original)
+++ xmlgraphics/fop/trunk/test/java/org/apache/fop/render/ps/PSPainterTestCase.java Fri Jul 31 15:04:31 2015
@@ -18,11 +18,16 @@ package org.apache.fop.render.ps;
 
 import java.awt.Color;
 import java.awt.Rectangle;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
 import java.io.IOException;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
 
+import javax.xml.transform.stream.StreamResult;
+
+import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 import org.mockito.verification.VerificationMode;
@@ -38,15 +43,19 @@ import static org.mockito.Mockito.verify
 import static org.mockito.Mockito.when;
 
 import org.apache.xmlgraphics.ps.PSGenerator;
+import org.apache.xmlgraphics.ps.dsc.ResourceTracker;
 
 import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.apps.FopFactory;
 import org.apache.fop.fo.Constants;
+import org.apache.fop.fonts.EmbeddingMode;
 import org.apache.fop.fonts.Font;
 import org.apache.fop.fonts.FontInfo;
 import org.apache.fop.fonts.FontTriplet;
 import org.apache.fop.fonts.MultiByteFont;
 import org.apache.fop.fonts.Typeface;
 import org.apache.fop.render.intermediate.IFContext;
+import org.apache.fop.render.intermediate.IFException;
 import org.apache.fop.render.intermediate.IFState;
 import org.apache.fop.traits.BorderProps;
 
@@ -161,4 +170,69 @@ public class PSPainterTestCase {
             fail("something broke...");
         }
     }
+
+    @Test
+    public void testOTF() throws IFException, IOException {
+        FOUserAgent ua = FopFactory.newInstance(new File(".").toURI()).newFOUserAgent();
+        final IFState state = IFState.create();
+        PSDocumentHandler dh = new PSDocumentHandler(new IFContext(ua)) {
+            protected PSFontResource getPSResourceForFontKey(String key) {
+                return new PSFontResource() {
+                    String getName() {
+                        return state.getFontFamily();
+                    }
+                    void notifyResourceUsageOnPage(ResourceTracker resourceTracker) {
+                    }
+                };
+            }
+        };
+        FontInfo fi = new FontInfo();
+        addFont(fi, "OTFFont", true);
+        addFont(fi, "TTFFont", false);
+
+        dh.setFontInfo(fi);
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        dh.setResult(new StreamResult(bos));
+        dh.startDocument();
+        state.setFontSize(10);
+        state.setTextColor(Color.BLACK);
+        state.setFontStyle("");
+        PSPainter p = new PSPainter(dh, state) {
+            protected String getFontKey(FontTriplet triplet) throws IFException {
+                return state.getFontFamily();
+            }
+        };
+
+        state.setFontFamily("TTFFont");
+        p.drawText(0, 0, 0, 0, null, "test1");
+
+        state.setFontFamily("OTFFont");
+        p.drawText(0, 0, 0, 0, null, "test2");
+        p.drawText(0, 0, 0, 0, null, "test3");
+
+        state.setFontFamily("TTFFont");
+        p.drawText(0, 0, 0, 0, null, "test4");
+
+        Assert.assertTrue(bos.toString(), bos.toString().endsWith("BT\n"
+                + "/TTFFont 0.01 F\n"
+                + "1 0 0 -1 0 0 Tm\n"
+                + "<00000000000000000000> t\n"
+                + "/OTFFont.0 0.01 F\n"
+                + "1 0 0 -1 0 0 Tm\n"
+                + "<FFFFFFFFFF> t\n"
+                + "/OTFFont.0 0.01 F\n"
+                + "1 0 0 -1 0 0 Tm\n"
+                + "<FFFFFFFFFF> t\n"
+                + "/TTFFont 0.01 F\n"
+                + "1 0 0 -1 0 0 Tm\n"
+                + "<00000000000000000000> t\n"));
+    }
+
+    private void addFont(FontInfo fi, String name, boolean otf) {
+        fi.addFontProperties(name, name, "", 0);
+        MultiByteFont mbf = new MultiByteFont(null, EmbeddingMode.AUTO);
+        mbf.setWidthArray(new int[100]);
+        mbf.setIsOTFFile(otf);
+        fi.addMetrics(name, mbf);
+    }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org