protected void AssembleFont()
{
int[] tableLocation;
int fullFontSize = 0;
string[] tableNames;
if (includeExtras)
tableNames = tableNamesExtra;
else {
if (includeCmap)
tableNames = tableNamesCmap;
else
tableNames = tableNamesSimple;
}
int tablesUsed = 2;
int len = 0;
for (int k = 0; k < tableNames.Length; ++k) {
string name = tableNames[k];
if (name.Equals("glyf") || name.Equals("loca"))
continue;
tableDirectory.TryGetValue(name, out tableLocation);
if (tableLocation == null)
continue;
++tablesUsed;
fullFontSize += (tableLocation[TABLE_LENGTH] + 3) & (~3);
}
fullFontSize += newLocaTableOut.Length;
fullFontSize += newGlyfTable.Length;
int iref = 16 * tablesUsed + 12;
fullFontSize += iref;
outFont = new byte[fullFontSize];
fontPtr = 0;
WriteFontInt(0x00010000);
WriteFontShort(tablesUsed);
int selector = entrySelectors[tablesUsed];
WriteFontShort((1 << selector) * 16);
WriteFontShort(selector);
WriteFontShort((tablesUsed - (1 << selector)) * 16);
for (int k = 0; k < tableNames.Length; ++k) {
string name = tableNames[k];
tableDirectory.TryGetValue(name, out tableLocation);
if (tableLocation == null)
continue;
WriteFontString(name);
if (name.Equals("glyf")) {
WriteFontInt(CalculateChecksum(newGlyfTable));
len = glyfTableRealSize;
}
else if (name.Equals("loca")) {
WriteFontInt(CalculateChecksum(newLocaTableOut));
len = locaTableRealSize;
}
else {
WriteFontInt(tableLocation[TABLE_CHECKSUM]);
len = tableLocation[TABLE_LENGTH];
}
WriteFontInt(iref);
WriteFontInt(len);
iref += (len + 3) & (~3);
}
for (int k = 0; k < tableNames.Length; ++k) {
string name = tableNames[k];
tableDirectory.TryGetValue(name, out tableLocation);
if (tableLocation == null)
continue;
if (name.Equals("glyf")) {
Array.Copy(newGlyfTable, 0, outFont, fontPtr, newGlyfTable.Length);
fontPtr += newGlyfTable.Length;
newGlyfTable = null;
}
else if (name.Equals("loca")) {
Array.Copy(newLocaTableOut, 0, outFont, fontPtr, newLocaTableOut.Length);
fontPtr += newLocaTableOut.Length;
newLocaTableOut = null;
}
else {
rf.Seek(tableLocation[TABLE_OFFSET]);
rf.ReadFully(outFont, fontPtr, tableLocation[TABLE_LENGTH]);
fontPtr += (tableLocation[TABLE_LENGTH] + 3) & (~3);
}
}
}