in src/java/org/apache/fop/render/pdf/pdfbox/MergeTTFonts.java [114:184]
private void createGlyf() throws IOException {
OFDirTabEntry entry = dirTabs.get(OFTableName.GLYF);
int size = 0;
int startPos = 0;
int endOffset = 0; // Store this as the last loca
if (entry != null) {
pad4();
startPos = currentPos;
/* Loca table must be in order by glyph index, so build
* an array first and then write the glyph info and
* location offset.
*/
glyphOffsets = new int[origIndexesLen];
for (Map.Entry<Integer, Glyph> gly : added.entrySet()) {
byte[] glyphData = gly.getValue().data;
int glyphLength = glyphData.length;
int i = gly.getKey();
if (i >= origIndexesLen) {
continue;
}
int endOffset1 = endOffset;
// Copy glyph
writeBytes(glyphData);
// Update loca table
if (cid || locaFormat == 1) {
writeULong(locaOffset + i * 4, currentPos - startPos);
}
if ((currentPos - startPos + glyphLength) > endOffset1) {
endOffset1 = currentPos - startPos + glyphLength;
}
// Store the glyph boundary positions relative to the start of the font
glyphOffsets[i] = currentPos;
currentPos += glyphLength;
realSize += glyphLength;
endOffset = endOffset1;
}
size = currentPos - startPos;
currentPos += 12;
realSize += 12;
updateCheckSum(startPos, size + 12, OFTableName.GLYF);
// Update loca checksum and last loca index
if (cid || locaFormat == 1) {
writeULong(locaOffset + added.size() * 4, endOffset);
}
int locaSize = added.size() * 4 + 4;
int checksum = getCheckSum(output, locaOffset, locaSize);
writeULong(offsets.get(OFTableName.LOCA), checksum);
int padSize = (locaOffset + locaSize) % 4;
newDirTabs.put(OFTableName.LOCA,
new OFDirTabEntry(locaOffset, locaSize + padSize));
if (!cid && locaFormat == 0) {
int i = 0;
int offset = 0;
for (Glyph e : added.values()) {
writeUShort(locaOffset + i * 2, offset / 2);
offset += e.data.length;
i++;
}
writeUShort(locaOffset + i * 2, offset / 2);
}
} else {
throw new IOException("Can't find glyf table");
}
}