Exemple #1
0
        public static OffsetTable Read(BinaryReaderFont reader)
        {
            OffsetTable value = new OffsetTable();

            value.sfntVersion = reader.ReadUInt32();
            if (value.sfntVersion != Version1 && value.sfntVersion != VersionOTTO)
            {
                throw new Exception(
                          string.Format("Parse error: sfntVersion is not valid. 0x{0:X8}", value.sfntVersion)
                          );
            }
            value.numTables   = reader.ReadUInt16();
            value.searchRange = reader.ReadUInt16();
            if (MaximumPowerOf2(value.numTables) * 16 != value.searchRange)
            {
                throw new Exception(
                          string.Format("Parse error: searchRange is not valid. {0}", value.searchRange)
                          );
            }
            value.entrySelector = reader.ReadUInt16();
            if ((ushort)Math.Log(MaximumPowerOf2(value.numTables), 2) != value.entrySelector)
            {
                throw new Exception(
                          string.Format("Parse error: entrySelector is not valid. {0}", value.entrySelector)
                          );
            }
            value.rangeShift = reader.ReadUInt16();
            if (value.numTables * 16 - value.searchRange != value.rangeShift)
            {
                /*throw new Exception(
                 *      string.Format("Parse error: rangeShift is not valid. {0}", value.rangeShift)
                 * );*/
            }
            return(value);
        }
Exemple #2
0
 public void ReadTableRecords(BinaryReaderFont reader)
 {
     offset  = OffsetTable.Read(reader);
     Records = TableRecord.ReadArray(reader, offset.numTables);
     Array.Sort(Records, (a, b) => {
         if (a.tableTag == HeadTable.Tag)
         {
             return(-1);
         }
         if (b.tableTag == HeadTable.Tag)
         {
             return(1);
         }
         if (a.tableTag == MaxpTable.Tag)
         {
             return(-1);
         }
         if (b.tableTag == MaxpTable.Tag)
         {
             return(1);
         }
         if (a.tableTag == HheaTable.Tag)
         {
             return(-1);
         }
         if (b.tableTag == HheaTable.Tag)
         {
             return(1);
         }
         if (a.tableTag == LocaTable.Tag)
         {
             return(-1);
         }
         if (b.tableTag == LocaTable.Tag)
         {
             return(1);
         }
         if (a.tableTag == EBLCTable.Tag)
         {
             return(-1);
         }
         if (b.tableTag == EBLCTable.Tag)
         {
             return(1);
         }
         if (a.tableTag == CBLCTable.Tag)
         {
             return(-1);
         }
         if (b.tableTag == CBLCTable.Tag)
         {
             return(1);
         }
         if (a.offset < b.offset)
         {
             return(-1);
         }
         if (a.offset > b.offset)
         {
             return(1);
         }
         return(0);
     });
 }