aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache/fop
diff options
context:
space:
mode:
authorRobert Meyer <rmeyer@apache.org>2014-02-10 16:21:03 +0000
committerRobert Meyer <rmeyer@apache.org>2014-02-10 16:21:03 +0000
commit785ace252f252ff211330e93635631931d68b890 (patch)
tree9a7924d1e35d867a0606f24f348285b3cd1b83ba /src/java/org/apache/fop
parent9dc9aff9a9cef7e5696b42eb8d396944d1c40881 (diff)
downloadxmlgraphics-fop-785ace252f252ff211330e93635631931d68b890.tar.gz
xmlgraphics-fop-785ace252f252ff211330e93635631931d68b890.zip
FOP-2252: OpenType CFF - Remove need for patch to fontbox
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1566674 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/fop')
-rw-r--r--src/java/org/apache/fop/fonts/truetype/OTFFile.java76
-rw-r--r--src/java/org/apache/fop/fonts/truetype/OTFSubSetFile.java31
2 files changed, 100 insertions, 7 deletions
diff --git a/src/java/org/apache/fop/fonts/truetype/OTFFile.java b/src/java/org/apache/fop/fonts/truetype/OTFFile.java
index 3976b5994..ab9654beb 100644
--- a/src/java/org/apache/fop/fonts/truetype/OTFFile.java
+++ b/src/java/org/apache/fop/fonts/truetype/OTFFile.java
@@ -20,11 +20,17 @@
package org.apache.fop.fonts.truetype;
import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
import org.apache.fontbox.cff.CFFDataInput;
import org.apache.fontbox.cff.CFFFont;
-import org.apache.fontbox.cff.CFFFont.Mapping;
import org.apache.fontbox.cff.CFFParser;
+import org.apache.fontbox.cff.charset.CFFCharset;
public class OTFFile extends OpenFont {
@@ -45,17 +51,77 @@ public class OTFFile extends OpenFont {
@Override
protected void updateBBoxAndOffset() throws IOException {
+ List<Mapping> gidMappings = getGIDMappings(fileFont);
+ Map<Integer, String> sidNames = constructNameMap(gidMappings);
UnicodeMapping[] mappings = unicodeMappings.toArray(new UnicodeMapping[0]);
for (int i = 0; i < mappings.length; i++) {
int glyphIdx = mappings[i].getGlyphIndex();
- Mapping m = fileFont.getGIDMappings().get(glyphIdx);
- int[] bbox = fileFont.getBoundingBox(m.getSID());
- String name = fileFont.getNameOfCharFromCode(m.getSID());
- mtxTab[glyphIdx].setBoundingBox(bbox);
+ Mapping m = gidMappings.get(glyphIdx);
+ String name = sidNames.get(m.getSID());
mtxTab[glyphIdx].setName(name);
}
}
+ private List<Mapping> getGIDMappings(CFFFont font) {
+ List<Mapping> gidMappings = new ArrayList<Mapping>();
+ Mapping notdef = new Mapping();
+ gidMappings.add(notdef);
+ for (CFFCharset.Entry entry : font.getCharset().getEntries()) {
+ String name = entry.getName();
+ byte[] bytes = font.getCharStringsDict().get(name);
+ if (bytes == null) {
+ continue;
+ }
+ Mapping mapping = new Mapping();
+ mapping.setSID(entry.getSID());
+ mapping.setName(name);
+ mapping.setBytes(bytes);
+ gidMappings.add(mapping);
+ }
+ return gidMappings;
+ }
+
+ private Map<Integer, String> constructNameMap(Collection<Mapping> mappings) {
+ Map<Integer, String> sidNames = new HashMap<Integer, String>();
+ Iterator<Mapping> it = mappings.iterator();
+ while (it.hasNext()) {
+ Mapping mapping = it.next();
+ sidNames.put(mapping.getSID(), mapping.getName());
+ }
+ return sidNames;
+ }
+
+ private static class Mapping {
+ private int sid;
+ private String name;
+ private byte[] bytes;
+
+ public void setSID(int sid) {
+ this.sid = sid;
+ }
+
+ public int getSID() {
+ return sid;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setBytes(byte[] bytes) {
+ this.bytes = bytes;
+ }
+
+ public byte[] getBytes() {
+ return bytes;
+ }
+ }
+
+
@Override
protected void initializeFont(FontFileReader in) throws IOException {
fontFile = in;
diff --git a/src/java/org/apache/fop/fonts/truetype/OTFSubSetFile.java b/src/java/org/apache/fop/fonts/truetype/OTFSubSetFile.java
index 4d0cce67a..9cb3458c8 100644
--- a/src/java/org/apache/fop/fonts/truetype/OTFSubSetFile.java
+++ b/src/java/org/apache/fop/fonts/truetype/OTFSubSetFile.java
@@ -861,7 +861,6 @@ public class OTFSubSetFile extends OTFFile {
return hdrTotal + total;
}
-
private BytesNumber readNumber(int b0, byte[] input, int curPos) throws IOException {
if (b0 == 28) {
int b1 = input[curPos + 1] & 0xff;
@@ -887,7 +886,7 @@ public class OTFSubSetFile extends OTFFile {
/**
* A class used to store the last number operand and also it's size in bytes
*/
- private static final class BytesNumber {
+ static class BytesNumber {
private int number;
private int numBytes;
@@ -908,6 +907,26 @@ public class OTFSubSetFile extends OTFFile {
this.number = -1;
this.numBytes = -1;
}
+
+ public String toString() {
+ return Integer.toString(number);
+ }
+
+ @Override
+ public boolean equals(Object entry) {
+ assert entry instanceof BytesNumber;
+ BytesNumber bnEntry = (BytesNumber)entry;
+ return this.number == bnEntry.getNumber()
+ && this.numBytes == bnEntry.getNumBytes();
+ }
+
+ @Override
+ public int hashCode() {
+ int hash = 1;
+ hash = hash * 17 + number;
+ hash = hash * 31 + numBytes;
+ return hash;
+ }
}
private void writeCharsetTable(boolean cidFont) throws IOException {
@@ -1094,4 +1113,12 @@ public class OTFSubSetFile extends OTFFile {
System.arraycopy(output, 0, ret, 0, realSize);
return ret;
}
+
+ /**
+ * Returns the parsed CFF data for the original font.
+ * @return The CFFDataReader contaiing the parsed data
+ */
+ public CFFDataReader getCFFReader() {
+ return cffReader;
+ }
}