예제 #1
0
 public static SequentialMapGroup[] ReadArray(BinaryReaderFont reader, uint count)
 {
     SequentialMapGroup[] array = new SequentialMapGroup[count];
     for (int i = 0; i < count; i++)
     {
         array[i] = Read(reader);
     }
     return(array);
 }
예제 #2
0
        public static new CmapSubtable8 Read(BinaryReaderFont reader)
        {
            CmapSubtable8 value = new CmapSubtable8 {
                format    = reader.ReadUInt16(),
                reserved  = reader.ReadUInt16(),
                length    = reader.ReadUInt32(),
                language  = reader.ReadUInt32(),
                is32      = reader.ReadBytes(8192),
                numGroups = reader.ReadUInt32()
            };

            value.groups = SequentialMapGroup.ReadArray(reader, value.numGroups);
            return(value);
        }
예제 #3
0
        public override CharToGlyphTable CreateCharToGlyphTable()
        {
            CharToGlyphTable table = new CharToGlyphTable();

            for (int i = 0; i < numGroups; i++)
            {
                SequentialMapGroup group   = groups[i];
                ushort             glyphId = (ushort)group.startGlyphID;
                int endCharCode            = (int)group.endCharCode;
                for (int n = (int)group.startCharCode; n <= endCharCode; n++)
                {
                    table.Add(n, glyphId++);
                }
            }
            return(table);
        }
예제 #4
0
        public override int GetGlyphId(int charCode)
        {
            if (File.Exists(filePath) == false)
            {
                return(0);
            }
            SequentialMapGroup group = null;

            using (Stream stream = File.OpenRead(filePath))
                using (BinaryReaderFont reader = new BinaryReaderFont(stream)) {
                    int range = (int)(numGroups / 2);
                    int index = range;
                    //int count = (int)Math.Log(index, 2);
                    //Console.WriteLine();
                    //Console.WriteLine("charCode: {0:X}", charCode);
                    while (range >= 1)
                    {
                        if (range > 1)
                        {
                            range /= 2;
                        }
                        reader.Position = position + index * SequentialMapGroup.ByteSize;
                        SequentialMapGroup g = SequentialMapGroup.Read(reader);
                        //Console.WriteLine("group: {0}, {1}, {2}", g, index, numGroups);
                        if (g.endCharCode < charCode)
                        {
                            index += range;
                            if (index >= numGroups)
                            {
                                break;
                            }
                            if (range == 1)
                            {
                                reader.Position = position + index * SequentialMapGroup.ByteSize;
                                g = SequentialMapGroup.Read(reader);
                                if (g.startCharCode > charCode)
                                {
                                    break;
                                }
                            }
                            continue;
                        }
                        if (g.startCharCode > charCode)
                        {
                            index -= range;
                            if (index < 0)
                            {
                                break;
                            }
                            continue;
                        }
                        if (g.endCharCode >= charCode && g.startCharCode <= charCode)
                        {
                            group = g;
                            break;
                        }
                        break;
                    }
                }

            /*
             * for (int i = 0; i < groups.Length; i++) {
             *      SequentialMapGroup g = groups[i];
             *      if (g.endCharCode >= charCode && g.startCharCode <= charCode) {
             *              group = g;
             *              break;
             *      }
             * }
             */
            if (group == null)
            {
                return(0);
            }
            return((ushort)(group.startGlyphID + (charCode - group.startCharCode)));

            /*
             * if (File.Exists(filePath) == false) {
             *      return 0;
             * }
             * using (Stream stream = File.OpenRead(filePath))
             * using (BinaryReaderFont reader = new BinaryReaderFont(stream)) {
             *      reader.Position = position + charCode;
             *      return reader.ReadByte();
             * }
             */
        }