in src/java/org/apache/fop/render/pdf/pdfbox/MergeCFFFonts.java [234:319]
protected void createCFF() throws IOException {
//Header
writeBytes(cffReader.getHeader());
//Name Index
writeIndex(Arrays.asList(fileFont.getName().getBytes(StandardCharsets.UTF_8)));
Offsets offsets = new Offsets();
//Top DICT Index and Data
offsets.topDictData = currentPos + writeTopDICT();
createCharStringData();
//String index
writeStringIndex();
Map<String, CFFDataReader.DICTEntry> topDICT = cffReader.getTopDictEntries();
final CFFDataReader.DICTEntry charString = topDICT.get("CharStrings");
final CFFDataReader.DICTEntry encodingEntry = topDICT.get("Encoding");
boolean hasFDSelect = cffReader.getFDSelect() != null;
if (encodingEntry != null && charString.getOffset() > encodingEntry.getOffset()) {
charsetOffset = currentPos;
if (!fallbackIndex) {
charsetOffset += 2;
}
writeCharsetTable(hasFDSelect, !fallbackIndex);
offsets.encoding = currentPos;
writeEncoding();
} else {
writeCard16(0);
offsets.encoding = currentPos;
writeEncoding();
charsetOffset = currentPos;
writeCharsetTable(hasFDSelect, false);
}
offsets.fdSelect = currentPos;
if (hasFDSelect) {
writeByte(0);
for (int i = 0; i < subsetCharStringsIndex.size(); i++) {
writeByte(0);
}
}
//Keep offset to modify later with the local subroutine index offset
offsets.privateDict = currentPos;
writePrivateDict();
//Local subroutine index
offsets.localIndex = currentPos;
readSubrs();
if (!subsetLocalIndexSubr.isEmpty()) {
writeIndex(subsetLocalIndexSubr);
}
//Char Strings Index
offsets.charString = currentPos;
writeIndex(subsetCharStringsIndex);
if (hasFDSelect) {
offsets.fdArray = currentPos;
List<byte[]> index = new ArrayList<byte[]>();
int offset = currentPos + 5;
for (CFFDataReader.FontDict fdFont : cffReader.getFDFonts()) {
byte[] fdFontByteData = fdFont.getByteData();
offset += fdFontByteData.length;
Map<String, CFFDataReader.DICTEntry> fdFontDict = cffReader.parseDictData(fdFontByteData);
//Update the Private dict reference
CFFDataReader.DICTEntry fdPrivate = fdFontDict.get("Private");
updateOffset(fdFontByteData,
fdPrivate.getOffset() + fdPrivate.getOperandLengths().get(0),
fdPrivate.getOperandLengths().get(1),
offset);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bos.write(fdFontByteData);
bos.write(fdFont.getPrivateDictData());
bos.write(new byte[3]);
index.add(bos.toByteArray());
}
writeIndex(index, 1);
updateCIDOffsets(offsets);
} else {
//Update the offsets
updateOffsets(offsets);
}
}