예제 #1
0
        public static GlyphBitmapData5 Read(BinaryReaderFont reader, int byteSize)
        {
            GlyphBitmapData5 value = new GlyphBitmapData5();

            value.imageData = reader.ReadBytes(byteSize);
            return(value);
        }
예제 #2
0
        public static Font[] Parse(string path)
        {
            Font[] fonts = null;
            if (File.Exists(path) == false)
            {
                return(fonts);
            }
            using (Stream stream = File.OpenRead(path))
                using (BinaryReaderFont reader = new BinaryReaderFont(stream)) {
                    reader.FilePath = path;
                    string tag = reader.ReadTag();
                    stream.Position = 0;
                    switch (tag)
                    {
                    case TTCHeader.Tag:
                        fonts = ParseTTC(reader);
                        break;

                    default:
                        fonts = new Font[] { Font.Read(reader) };
                        break;
                    }
                }
            return(fonts);
        }
예제 #3
0
 public static UVSMapping Read(BinaryReaderFont reader)
 {
     return(new UVSMapping {
         unicodeValue = reader.ReadUInt24(),
         glyphID = reader.ReadUInt16()
     });
 }
예제 #4
0
 public static CoverageFormat1 Read(BinaryReaderFont reader)
 {
     return(new CoverageFormat1 {
         coverageFormat = reader.ReadUInt16(),
         glyphCount = reader.ReadUInt16()
     });
 }
예제 #5
0
 public static ScriptRecord Read(BinaryReaderFont reader)
 {
     return(new ScriptRecord {
         scriptTag = reader.ReadTag(),
         scriptOffset = reader.ReadUInt16()
     });
 }
예제 #6
0
        //public VariationStore itemVarStore;

        public static BASETable Read(BinaryReaderFont reader)
        {
            long      position = reader.Position;
            BASETable value    = new BASETable {
                majorVersion    = reader.ReadUInt16(),
                minorVersion    = reader.ReadUInt16(),
                horizAxisOffset = reader.ReadUInt16(),
                vertAxisOffset  = reader.ReadUInt16()
            };

            if (value.majorVersion == 1 && value.minorVersion == 1)
            {
                value.itemVarStoreOffset = reader.ReadUInt32();
            }
            if (value.horizAxisOffset != 0)
            {
                reader.Position = position + value.horizAxisOffset;
                value.horizAxis = AxisTable.Read(reader);
            }
            if (value.vertAxisOffset != 0)
            {
                reader.Position = position + value.vertAxisOffset;
                value.vertAxis  = AxisTable.Read(reader);
            }
            if (value.itemVarStoreOffset != 0)
            {
                reader.Position = position + value.itemVarStoreOffset;
                //value.itemVarStore =
            }
            return(value);
        }
예제 #7
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);
        }
예제 #8
0
        /*
         * public static LongHorMetric[] ReadArray(BinaryReaderFont reader, int count) {
         *      LongHorMetric[] array = new LongHorMetric[count];
         *      for (int i = 0; i < count; i++) {
         *              array[i] = Read(reader);
         *      }
         *      return array;
         * }
         */

        public static LongHorMetric Read(BinaryReaderFont reader)
        {
            return(new LongHorMetric {
                advanceWidth = reader.ReadUInt16(),
                lsb = reader.ReadInt16()
            });
        }
예제 #9
0
        public static CmapTable Read(BinaryReaderFont reader)
        {
            long      start = reader.Position;
            CmapTable value = new CmapTable {
                version   = reader.ReadUInt16(),
                numTables = reader.ReadUInt16()
            };
            ushort numTables = value.numTables;

            //value.encodingRecords = EncodingRecord.ReadArray(reader, numTables);
            value.encodingRecords = new EncodingRecord[numTables];
            value.subtables       = new CmapSubtable[numTables];
            long position = reader.Position;

            for (int i = 0; i < numTables; i++)
            {
                reader.Position = position;
                EncodingRecord record = EncodingRecord.Read(reader);
                value.encodingRecords[i] = record;
                position        = reader.Position;
                reader.Position = start + record.offset;
                //reader.Position = start + value.encodingRecords[i].offset;
                value.subtables[i] = CmapSubtable.Read(reader);
            }
            //Console.WriteLine("position: {0:X}", (reader.Position - start));
            return(value);
        }
예제 #10
0
 public static LayerRecord Read(BinaryReaderFont reader)
 {
     return(new LayerRecord {
         gID = reader.ReadUInt16(),
         paletteIndex = reader.ReadUInt16()
     });
 }
예제 #11
0
 public static TupleVariationHeader Read(BinaryReaderFont reader)
 {
     return(new TupleVariationHeader {
         variationDataSize = reader.ReadUInt16(),
         tupleIndex = reader.ReadUInt16()
     });
 }
예제 #12
0
        public GlyphData GetGlyphData(int index)
        {
            if (index < 0 || index >= numGlyphs)
            {
                return(null);
            }
            if (File.Exists(filePath) == false)
            {
                return(null);
            }
            GlyphData data = null;

            using (Stream stream = File.OpenRead(filePath))
                using (BinaryReaderFont reader = new BinaryReaderFont(stream)) {
                    uint offset      = glyphDataOffsets[index];
                    uint glyphLength = glyphDataOffsets[index + 1] - offset;
                    reader.Position = position + offset;
                    data            = GlyphData.Read(reader, glyphLength);
                }
            return(data);

            /*
             * if (index >= glyphData.Length) {
             *      return null;
             * }
             * return glyphData[index];
             * //*/
        }
예제 #13
0
        public static Strike Read(BinaryReaderFont reader, uint numGlyphs)
        {
            Strike value = new Strike();

            value.position         = reader.Position;
            value.numGlyphs        = numGlyphs;
            value.filePath         = reader.FilePath;
            value.ppem             = reader.ReadUInt16();
            value.ppi              = reader.ReadUInt16();
            value.glyphDataOffsets = reader.ReadUInt32Array((int)numGlyphs + 1);

            /*
             * value.glyphData = new GlyphData[numGlyphs];
             * uint[] glyphDataOffsets = value.glyphDataOffsets;
             * int length = value.glyphDataOffsets.Length - 1;
             * for (int i = 0; i < length; i++) {
             *      uint offset = glyphDataOffsets[i];
             *      uint glyphLength = glyphDataOffsets[i + 1] - offset;
             *      reader.Position = position + offset;
             *      GlyphData glyphData = GlyphData.Read(reader, glyphLength);
             *      value.glyphData[i] = glyphData;
             * }
             */
            return(value);
        }
예제 #14
0
 public static CoverageFormat2 Read(BinaryReaderFont reader)
 {
     return(new CoverageFormat2 {
         coverageFormat = reader.ReadUInt16(),
         rangeCount = reader.ReadUInt16()
     });
 }
예제 #15
0
 public static GaspRange Read(BinaryReaderFont reader)
 {
     return(new GaspRange {
         rangeMaxPPEM = reader.ReadUInt16(),
         rangeGaspBehavior = reader.ReadUInt16()
     });
 }
예제 #16
0
        protected void ReadPrivate(BinaryReaderFont reader)
        {
            long start = reader.Position;

            //Console.WriteLine("private dict: {0}", topDict.Private);
            privateDict = CFFPrivateDict.Read(reader, (int)topDict.Private.values[0]);
            //Console.WriteLine("private dict: {0}", privateDict);
            //reader.Position = position + (int)topDict.Private.values[1];
            //CFFIndex index = CFFIndex.Read(reader);
            //int[] offset = index.offset;
            //Console.WriteLine("local subr index: {0}", index);

            if (privateDict.Subrs > 0)
            {
                reader.Position = start + (int)privateDict.Subrs;
                CFFIndex index  = CFFIndex.Read(reader);
                int[]    offset = index.ReadAllOffsets(reader);
                //Console.WriteLine("local subr index: {0}", index);
                localSubr = new byte[index.count][];
                for (int i = 0; i < offset.Length - 1; i++)
                {
                    int length = offset[i + 1] - offset[i];
                    localSubr[i] = reader.ReadBytes(length);
                }
            }
            charString.localSubr = localSubr;
        }
예제 #17
0
 public static CFFRange1 Read(BinaryReaderFont reader)
 {
     return(new CFFRange1 {
         first = reader.ReadUInt16(),
         nLeft = reader.ReadByte()
     });
 }
예제 #18
0
        public static NameTable Read(BinaryReaderFont reader)
        {
            NameTable value = new NameTable {
                format       = reader.ReadUInt16(),
                count        = reader.ReadUInt16(),
                stringOffset = reader.ReadUInt16(),
            };

            value.nameRecord = NameRecord.ReadArray(reader, value.count);
            if (value.format >= 1)
            {
                value.langTagCount  = reader.ReadUInt16();
                value.langTagRecord = LangTagRecord.ReadArray(reader, value.langTagCount);
            }
            long start = reader.Position;

            for (int i = 0; i < value.count; i++)
            {
                NameRecord record = value.nameRecord[i];
                reader.Position = start + record.offset;
                record.text     = reader.ReadString(record.length, GetEncoding(record));
            }
            if (value.format >= 1)
            {
                for (int i = 0; i < value.langTagCount; i++)
                {
                    LangTagRecord record = value.langTagRecord[i];
                    reader.Position = start + record.offset;
                    record.text     = reader.ReadString(record.length, Encoding.BigEndianUnicode);
                }
            }
            return(value);
        }
예제 #19
0
 public static MarkGlyphSets Read(BinaryReaderFont reader)
 {
     return(new MarkGlyphSets {
         markGlyphSetTableFormat = reader.ReadUInt16(),
         markGlyphSetCount = reader.ReadUInt16()
     });
 }
예제 #20
0
        public static BaseScript Read(BinaryReaderFont reader)
        {
            long       position = reader.Position;
            BaseScript value    = new BaseScript {
                baseValuesOffset    = reader.ReadUInt16(),
                defaultMinMaxOffset = reader.ReadUInt16(),
                baseLangSysCount    = reader.ReadUInt16(),
            };

            if (value.baseLangSysCount != 0)
            {
                value.baseLangSysRecords = BaseLangSysRecord.ReadArray(
                    reader, value.baseLangSysCount
                    );
            }
            if (value.baseValuesOffset != 0)
            {
                reader.Position  = position + value.baseValuesOffset;
                value.baseValues = BaseValues.Read(reader);
            }
            if (value.defaultMinMaxOffset != 0)
            {
                reader.Position     = position + value.defaultMinMaxOffset;
                value.defaultMinMax = MinMax.Read(reader);
            }
            return(value);
        }
예제 #21
0
 public static ClassDefFormat2 Read(BinaryReaderFont reader)
 {
     return(new ClassDefFormat2 {
         classFormat = reader.ReadUInt16(),
         classRangeCount = reader.ReadUInt16()
     });
 }
예제 #22
0
 public static VariationRegionList Read(BinaryReaderFont reader)
 {
     return(new VariationRegionList {
         axisCount = reader.ReadUInt16(),
         regionCount = reader.ReadUInt16()
     });
 }
예제 #23
0
        public static MaxpTable Read(BinaryReaderFont reader)
        {
            MaxpTable value = new MaxpTable {
                version   = reader.ReadFixed(),
                numGlyphs = reader.ReadUInt16()
            };

            if (value.version >= 0x10000)
            {
                value.maxPoints             = reader.ReadUInt16();
                value.maxContours           = reader.ReadUInt16();
                value.maxCompositePoints    = reader.ReadUInt16();
                value.maxCompositeContours  = reader.ReadUInt16();
                value.maxZones              = reader.ReadUInt16();
                value.maxTwilightPoints     = reader.ReadUInt16();
                value.maxStorage            = reader.ReadUInt16();
                value.maxFunctionDefs       = reader.ReadUInt16();
                value.maxInstructionDefs    = reader.ReadUInt16();
                value.maxStackElements      = reader.ReadUInt16();
                value.maxSizeOfInstructions = reader.ReadUInt16();
                value.maxComponentElements  = reader.ReadUInt16();
                value.maxComponentDepth     = reader.ReadUInt16();
            }
            return(value);
        }
예제 #24
0
        public static CFFTopDict Read(BinaryReaderFont reader, int length)
        {
            CFFTopDict    value = new CFFTopDict();
            long          start = reader.Position;
            List <double> list  = new List <double>();
            byte          key0  = 0;
            byte          key1  = 0;

            while ((reader.Position - start) < length)
            {
                byte n = reader.PeekByte();
                if (n <= 21)
                {
                    key0 = reader.ReadByte();
                    if (key0 == 12)
                    {
                        key1 = reader.ReadByte();
                    }
                    //Console.WriteLine("key0: " + key0);
                    //if (key1 != 0) {
                    //	Console.WriteLine("key1: " + key1);
                    //}
                    value.SetValue(list, key0, key1);
                    key1 = 0;
                    list.Clear();
                }
                else
                {
                    list.Add(reader.ReadCFFNumber());
                }
            }
            return(value);
        }
예제 #25
0
 public static FeatureVariationRecord Read(BinaryReaderFont reader)
 {
     return(new FeatureVariationRecord {
         conditionSetOffset = reader.ReadUInt32(),
         featureTableSubstitutionOffset = reader.ReadUInt32()
     });
 }
예제 #26
0
 public static FeatureTableSubstitutionRecord Read(BinaryReaderFont reader)
 {
     return(new FeatureTableSubstitutionRecord {
         featureIndex = reader.ReadUInt16(),
         alternateFeatureTable = reader.ReadUInt32()
     });
 }
예제 #27
0
 public static LangSysRecord Read(BinaryReaderFont reader)
 {
     return(new LangSysRecord {
         langSysTag = reader.ReadTag(),
         langSysOffset = reader.ReadUInt16()
     });
 }
예제 #28
0
        public GlyphBitmapData GetGlyphBitmapData(int index, int glyphId)
        {
            if (index < 0 || index >= EBLC.bitmapSizes.Length)
            {
                return(null);
            }
            if (File.Exists(filePath) == false)
            {
                return(null);
            }
            BitmapSize         size  = EBLC.bitmapSizes[index];
            IndexSubTableArray array = size.FindSubTableArray(glyphId);

            if (array == null)
            {
                return(null);
            }
            using (Stream stream = File.OpenRead(filePath))
                using (BinaryReaderFont reader = new BinaryReaderFont(stream)) {
                    reader.Position = position + array.subTable.header.imageDataOffset;
                    return(array.subTable.ReadBitmapData(reader, glyphId, glyphId - array.firstGlyphIndex));
                }

            /*
             * if (index < 0 || index >= bitmapData.Count) {
             *      return null;
             * }
             * if (bitmapData[index].ContainsKey((ushort)glyphId) == false) {
             *      return null;
             * }
             * return bitmapData[index][(ushort)glyphId];
             * //*/
        }
예제 #29
0
 public static UnicodeRange Read(BinaryReaderFont reader)
 {
     return(new UnicodeRange {
         startUnicodeValue = reader.ReadUInt24(),
         additionalCount = reader.ReadByte()
     });
 }
예제 #30
0
 public static AttachList Read(BinaryReaderFont reader)
 {
     return(new AttachList {
         coverageOffset = reader.ReadUInt16(),
         glyphCount = reader.ReadUInt16()
     });
 }