]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
FOP-2508: TTF bullet missing when OTF used
authorSimon Steiner <ssteiner@apache.org>
Fri, 31 Jul 2015 15:04:31 +0000 (15:04 +0000)
committerSimon Steiner <ssteiner@apache.org>
Fri, 31 Jul 2015 15:04:31 +0000 (15:04 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1693613 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/fop/render/ps/PSPainter.java
test/java/org/apache/fop/render/ps/PSPainterTestCase.java

index 18e0d6fec62a8ca849e52a713413363e207165ba..d00fdd263faa22f4b1402f1262ad287d28982ef7 100644 (file)
@@ -377,12 +377,8 @@ public class PSPainter extends AbstractIFPainter<PSDocumentHandler> {
             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 AbstractIFPainter<PSDocumentHandler> {
                                     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 AbstractIFPainter<PSDocumentHandler> {
                         }
                     }
                 } 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 AbstractIFPainter<PSDocumentHandler> {
         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());
     }
 }
index b678fdb4b202f6e2da6c96366c7cce9a5988aed4..3efbb47d47cc40f99766745b0e631eae2ee28dce 100644 (file)
@@ -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);
+    }
 }