in src/java/org/apache/fop/render/pdf/pdfbox/MergeType1Fonts.java [58:124]
public void readFont(InputStream fontFile, String name, FontContainer font,
Map<Integer, Integer> subsetGlyphs, boolean cid) throws IOException {
PFBParser pfbParser = new PFBParser();
pfbData = pfbParser.parsePFB(fontFile);
PostscriptParser psParser = new PostscriptParser();
List<Integer> glyphs = new ArrayList<Integer>();
Type1Font t1f = ((PDType1Font)font.font).getType1Font();
Encoding enc = t1f.getEncoding();
for (int i = font.getFirstChar(); i <= font.getLastChar(); i++) {
if (!enc.getName(i).equals(".notdef")) {
nameMap.put(i, enc.getName(i));
glyphs.add(i);
}
}
Collections.sort(glyphs);
headerSection = psParser.parse(pfbData.getHeaderSegment());
encoding = getElement("/Encoding", headerSection);
if (encoding.getFoundUnexpected()) {
throw new IOException("unable to interpret postscript on arrays");
}
List<String> encodingEntries = readEncoding(glyphs, encoding);
for (String e : encodingEntries) {
if (e != null && !subsetEncodingEntries.contains(e)) {
subsetEncodingEntries.add(e);
}
}
decoded = BinaryCoder.decodeBytes(pfbData.getEncryptedSegment(), 55665, 4);
mainSection = psParser.parse(decoded);
PostscriptParser.PSFixedArray subroutines = (PostscriptParser.PSFixedArray)getElement("/Subrs", mainSection);
charStrings = getElement("/CharStrings", mainSection);
if (subroutines != null) {
subrsBeforeStream.reset();
subrsBeforeStream.write(decoded, 0, subroutines.getStartPoint());
subrsEndStream.reset();
subrsEndStream.write(decoded, subroutines.getEndPoint(),
charStrings.getStartPoint() - subroutines.getEndPoint());
}
List<byte[]> subArray = t1f.getSubrsArray();
for (int i = 0; i < subArray.size(); i++) {
if (subByteMap.containsKey(i) && !Arrays.equals(subByteMap.get(i), subArray.get(i))) {
throw new IOException("Can't merge font subroutines " + font.font.getName());
}
subByteMap.put(i, subArray.get(i));
}
Map<String, byte[]> cs = t1f.getCharStringsDict();
int lenIV = 4;
PostscriptParser.PSElement element = getElement("/lenIV", mainSection);
if (element != null && element instanceof PostscriptParser.PSVariable) {
PostscriptParser.PSVariable lenIVVar = (PostscriptParser.PSVariable)element;
lenIV = Integer.parseInt(lenIVVar.getValue());
}
for (String e : cs.keySet()) {
int[] be = charStrings.getBinaryEntries().get("/" + e);
if (be != null) {
byte[] charStringEntry = getBinaryEntry(be, decoded);
if (lenIV != 4) {
charStringEntry = BinaryCoder.decodeBytes(charStringEntry, 4330, lenIV);
charStringEntry = BinaryCoder.encodeBytes(charStringEntry, 4330, 4);
}
subsetCharStrings.put("/" + e, charStringEntry);
}
}
}