Browse Source

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
pull/6/head
Simon Steiner 6 years ago
parent
commit
dd327ebf12

+ 1
- 1
fop-core/src/main/java/org/apache/fop/pdf/PDFFactory.java View File

@@ -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();

+ 54
- 0
fop-core/src/test/java/org/apache/fop/pdf/PDFFactoryTestCase.java View File

@@ -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;

/**
@@ -81,6 +88,53 @@ public class PDFFactoryTestCase {
assertEquals("/EAAAAB+Arial", pdfArial.getBaseFont().toString());
}

@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 =

Loading…
Cancel
Save