public void LoadFormat0() { var writer = new BinaryWriter(); //int subtableCount = 1; writer.WriteCMapSubTable(new Format0SubTable(0, PlatformIDs.Windows, 2, new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 })); BinaryReader reader = writer.GetReader(); ushort format = reader.ReadUInt16(); // read format before we pass along as thats whet the cmap table does Assert.Equal(0, format); Format0SubTable table = Format0SubTable.Load(new[] { new EncodingRecord(PlatformIDs.Windows, 2, 0) }, reader).Single(); Assert.Equal(0, table.Language); Assert.Equal(PlatformIDs.Windows, table.Platform); Assert.Equal(2, table.Encoding); Assert.Equal(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 }, table.GlyphIds); }
public static CMapTable Load(BinaryReader reader) { ushort version = reader.ReadUInt16(); ushort numTables = reader.ReadUInt16(); var encodings = new EncodingRecord[numTables]; for (int i = 0; i < numTables; i++) { encodings[i] = EncodingRecord.Read(reader); } // foreach encoding we move forward looking for th subtables var tables = new List <CMapSubTable>(numTables); foreach (IGrouping <uint, EncodingRecord> encoding in encodings.Where(x => x.PlatformID == PlatformIDs.Windows).GroupBy(x => x.Offset)) { reader.Seek(encoding.Key, System.IO.SeekOrigin.Begin); ushort subTypeTableFormat = reader.ReadUInt16(); switch (subTypeTableFormat) { case 0: tables.AddRange(Format0SubTable.Load(encoding, reader)); break; case 4: tables.AddRange(Format4SubTable.Load(encoding, reader)); break; } } return(new CMapTable(tables.ToArray())); }