summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Steiner <ssteiner@apache.org>2018-02-08 12:26:33 +0000
committerSimon Steiner <ssteiner@apache.org>2018-02-08 12:26:33 +0000
commit1942336d7e574eaf285b36ab88f746d6a8d1b25c (patch)
tree76aa0409939efb75410846db2e8e4f2b59951875
parenteccb79bbb782429e651e8e3576f595eeaeb86413 (diff)
downloadxmlgraphics-fop-1942336d7e574eaf285b36ab88f746d6a8d1b25c.tar.gz
xmlgraphics-fop-1942336d7e574eaf285b36ab88f746d6a8d1b25c.zip
FOP-2770: Merge fonts not handling Truetype MacRomanEncoding
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1823552 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--fop-core/src/main/java/org/apache/fop/pdf/PDFFactory.java2
-rw-r--r--fop-core/src/test/java/org/apache/fop/pdf/PDFFactoryTestCase.java54
2 files changed, 55 insertions, 1 deletions
diff --git a/fop-core/src/main/java/org/apache/fop/pdf/PDFFactory.java b/fop-core/src/main/java/org/apache/fop/pdf/PDFFactory.java
index 856e7d765..81fd0c38a 100644
--- a/fop-core/src/main/java/org/apache/fop/pdf/PDFFactory.java
+++ b/fop-core/src/main/java/org/apache/fop/pdf/PDFFactory.java
@@ -1061,7 +1061,7 @@ public class PDFFactory {
//believed.
} else if (mapping.getName().equals("FOPPDFEncoding")) {
if (fonttype == FontType.TRUETYPE) {
- font.setEncoding("WinAnsiEncoding");
+ font.setEncoding(encoding);
} else {
String[] charNameMap = mapping.getCharNameMap();
char[] intmap = mapping.getUnicodeCharMap();
diff --git a/fop-core/src/test/java/org/apache/fop/pdf/PDFFactoryTestCase.java b/fop-core/src/test/java/org/apache/fop/pdf/PDFFactoryTestCase.java
index 220464e6e..61cec5d4a 100644
--- a/fop-core/src/test/java/org/apache/fop/pdf/PDFFactoryTestCase.java
+++ b/fop-core/src/test/java/org/apache/fop/pdf/PDFFactoryTestCase.java
@@ -19,9 +19,12 @@
package org.apache.fop.pdf;
+import java.awt.Rectangle;
import java.io.ByteArrayOutputStream;
import java.io.File;
+import java.io.FileInputStream;
import java.io.IOException;
+import java.io.InputStream;
import java.net.URI;
import org.junit.Test;
@@ -34,10 +37,14 @@ import org.apache.fop.apps.io.InternalResourceResolver;
import org.apache.fop.apps.io.ResourceResolverFactory;
import org.apache.fop.fonts.CIDSet;
import org.apache.fop.fonts.CIDSubset;
+import org.apache.fop.fonts.CodePointMapping;
import org.apache.fop.fonts.CustomFont;
import org.apache.fop.fonts.EmbeddingMode;
+import org.apache.fop.fonts.FontType;
import org.apache.fop.fonts.FontUris;
import org.apache.fop.fonts.MultiByteFont;
+import org.apache.fop.fonts.NamedCharacter;
+import org.apache.fop.fonts.SingleByteFont;
import org.apache.fop.fonts.truetype.OFFontLoader;
/**
@@ -82,6 +89,53 @@ public class PDFFactoryTestCase {
}
@Test
+ public void testMakeFont() throws IOException {
+ PDFDocument doc = new PDFDocument("");
+ PDFFactory pdfFactory = new PDFFactory(doc);
+ SingleByteFont sb = new TestSingleByteFont(null);
+ sb.setFontName("test");
+ sb.setWidth(0, 0);
+ sb.setFlags(0);
+ sb.setEmbedResourceName("");
+ sb.mapChar('a');
+ sb.addUnencodedCharacter(new NamedCharacter("xyz", String.valueOf((char) 0x2202)), 0, new Rectangle());
+ sb.mapChar((char) 0x2202);
+ sb.setEncoding(new CodePointMapping("FOPPDFEncoding", new int[0]));
+ PDFFont font = pdfFactory.makeFont("a", "a", "WinAnsiEncoding", sb, sb);
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ font.output(bos);
+ assertTrue(bos.toString().contains("/BaseFont /EAAAAA+a"));
+ assertEquals(sb.getAdditionalEncodingCount(), 1);
+ }
+
+ @Test
+ public void testMakeTrueTypeFont() throws IOException {
+ PDFDocument doc = new PDFDocument("");
+ PDFFactory pdfFactory = new PDFFactory(doc);
+ SingleByteFont sb = new TestSingleByteFont(null);
+ sb.setFontType(FontType.TRUETYPE);
+ sb.setFontName("test");
+ sb.setWidth(0, 0);
+ sb.setFlags(0);
+ sb.setEncoding(new CodePointMapping("FOPPDFEncoding", new int[0]));
+ String enc = "MacRomanEncoding";
+ PDFFont font = pdfFactory.makeFont("a", "a", enc, sb, sb);
+ font.output(new ByteArrayOutputStream());
+ assertEquals(((PDFName)font.entries.get("Encoding")).getName(), enc);
+ }
+
+ class TestSingleByteFont extends SingleByteFont {
+ public TestSingleByteFont(InternalResourceResolver resourceResolver) {
+ super(resourceResolver, EmbeddingMode.SUBSET);
+ }
+
+ public InputStream getInputStream() throws IOException {
+ File f = new File("test/resources/fonts/type1/a010013l.pfb");
+ return new FileInputStream(f);
+ }
+ }
+
+ @Test
public void testMakeOTFFont() throws IOException {
InternalResourceResolver rr =
ResourceResolverFactory.createDefaultInternalResourceResolver(new File(".").toURI());