summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Steiner <ssteiner@apache.org>2015-07-31 15:04:31 +0000
committerSimon Steiner <ssteiner@apache.org>2015-07-31 15:04:31 +0000
commit946356166c77565a1044b015ac85508aa931940c (patch)
treebc16dc1278f22e92d1047492cd5d00675938d103
parent77467fb13329ffebf62f9fbda48b6e832c977bfe (diff)
downloadxmlgraphics-fop-946356166c77565a1044b015ac85508aa931940c.tar.gz
xmlgraphics-fop-946356166c77565a1044b015ac85508aa931940c.zip
FOP-2508: TTF bullet missing when OTF used
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1693613 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--src/java/org/apache/fop/render/ps/PSPainter.java24
-rw-r--r--test/java/org/apache/fop/render/ps/PSPainterTestCase.java74
2 files changed, 87 insertions, 11 deletions
diff --git a/src/java/org/apache/fop/render/ps/PSPainter.java b/src/java/org/apache/fop/render/ps/PSPainter.java
index 18e0d6fec..d00fdd263 100644
--- a/src/java/org/apache/fop/render/ps/PSPainter.java
+++ b/src/java/org/apache/fop/render/ps/PSPainter.java
@@ -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());
}
}
diff --git a/test/java/org/apache/fop/render/ps/PSPainterTestCase.java b/test/java/org/apache/fop/render/ps/PSPainterTestCase.java
index b678fdb4b..3efbb47d4 100644
--- a/test/java/org/apache/fop/render/ps/PSPainterTestCase.java
+++ b/test/java/org/apache/fop/render/ps/PSPainterTestCase.java
@@ -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);
+ }
}