/// <summary> /// Compiles the font to its binary representation. /// </summary> void Compile() { MemoryStream stream = new MemoryStream(); OpenTypeFontWriter writer = new OpenTypeFontWriter(stream); int tableCount = tableDictionary.Count; int selector = entrySelectors[tableCount]; offsetTable.Version = 0x00010000; offsetTable.TableCount = tableCount; offsetTable.SearchRange = (ushort)((1 << selector) * 16); offsetTable.EntrySelector = (ushort)selector; offsetTable.RangeShift = (ushort)((tableCount - (1 << selector)) * 16); offsetTable.Write(writer); // Sort tables by tag name string[] tags = new string[tableCount]; tableDictionary.Keys.CopyTo(tags, 0); Array.Sort(tags, StringComparer.Ordinal); #if VERBOSE Debug.WriteLine("Start Compile"); #endif // Write tables in alphabetical order int tablePosition = 12 + 16 * tableCount; for (int idx = 0; idx < tableCount; idx++) { TableDirectoryEntry entry = tableDictionary[tags[idx]]; #if DEBUG if (entry.Tag == "glyf" || entry.Tag == "loca") { GetType(); } #endif entry.FontTable.PrepareForCompilation(); entry.Offset = tablePosition; writer.Position = tablePosition; entry.FontTable.Write(writer); int endPosition = writer.Position; tablePosition = endPosition; writer.Position = 12 + 16 * idx; entry.Write(writer); #if VERBOSE Debug.WriteLine(String.Format(" Write Table '{0}', offset={1}, length={2}, checksum={3}, ", entry.Tag, entry.Offset, entry.Length, entry.CheckSum)); #endif } #if VERBOSE Debug.WriteLine("End Compile"); #endif writer.Stream.Flush(); int l = (int)writer.Stream.Length; l.GetType(); data = stream.ToArray(); }