// // Straight insertion sort from Knuth vol. III, pg. 81 // public static void sort(DecompEntry[] table, Vector decompVector) { for (int j = 0; j < table.length; j += 1) { int i; DecompEntry v = (DecompEntry) decompVector.elementAt(j); for (i = j - 1; i >= 0; i -= 1) { if (v.compareTo(table[i]) >= 0) { break; } table[i + 1] = table[i]; } table[i + 1] = v; } }
private void snapshot() { if (snapshotSize != decompVector.size()) { snapshotSize = decompVector.size(); decompEntries = new DecompEntry[snapshotSize]; DecompEntry.sort(decompEntries, decompVector); } }
public void writeLookupSubtable(OpenTypeTableWriter writer) { snapshot(); int multipleSubstitutionsBase = writer.getOutputIndex(); int coverageTableIndex, sequenceOffsetIndex; int sequenceCount = decompEntries.length; writer.writeData(1); // format = 1 coverageTableIndex = writer.getOutputIndex(); writer.writeData(0); // coverage table offset (fixed later) writer.writeData(sequenceCount); sequenceOffsetIndex = writer.getOutputIndex(); for (int s = 0; s < sequenceCount; s += 1) { writer.writeData(0); // offset to sequence table (fixed later); } for (int s = 0; s < sequenceCount; s += 1) { DecompEntry entry = decompEntries[s]; int decompCount = entry.getDecompositionCount(); writer.fixOffset(sequenceOffsetIndex++, multipleSubstitutionsBase); writer.writeData(decompCount); // glyphCount for (int g = 0; g < decompCount; g += 1) { writer.writeData(entry.getDecomposedCharacter(g)); } } // write a format 1 coverage table writer.fixOffset(coverageTableIndex, multipleSubstitutionsBase); writer.writeData(1); // format = 1 writer.writeData(sequenceCount); // glyphCount for (int i = 0; i < sequenceCount; i += 1) { writer.writeData(decompEntries[i].getComposedCharacter()); } }