Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
 public static LangSysRecord Read(BinaryReaderFont reader)
 {
     return(new LangSysRecord {
         langSysTag = reader.ReadTag(),
         langSysOffset = reader.ReadUInt16()
     });
 }
Exemplo n.º 3
0
 public static ScriptRecord Read(BinaryReaderFont reader)
 {
     return(new ScriptRecord {
         scriptTag = reader.ReadTag(),
         scriptOffset = reader.ReadUInt16()
     });
 }
Exemplo n.º 4
0
 public static FeatureRecord Read(BinaryReaderFont reader)
 {
     return(new FeatureRecord {
         featureTag = reader.ReadTag(),
         featureOffset = reader.ReadUInt16()
     });
 }
Exemplo n.º 5
0
 public static BaseLangSysRecord Read(BinaryReaderFont reader)
 {
     return(new BaseLangSysRecord {
         baseLangSysTag = reader.ReadTag(),
         minMaxOffset = reader.ReadUInt16()
     });
 }
Exemplo n.º 6
0
 public static DataMap Read(BinaryReaderFont reader)
 {
     return(new DataMap {
         tag = reader.ReadTag(),
         dataOffset = reader.ReadUInt32(),
         dataLength = reader.ReadUInt32()
     });
 }
Exemplo n.º 7
0
 public static FeatMinMaxRecord Read(BinaryReaderFont reader)
 {
     return(new FeatMinMaxRecord {
         featureTableTag = reader.ReadTag(),
         minCoord = reader.ReadUInt16(),
         maxCoord = reader.ReadUInt16()
     });
 }
Exemplo n.º 8
0
 public static MvarValueRecord Read(BinaryReaderFont reader)
 {
     return(new MvarValueRecord {
         valueTag = reader.ReadTag(),
         deltaSetOuterIndex = reader.ReadUInt16(),
         deltaSetInnerIndex = reader.ReadUInt16()
     });
 }
Exemplo n.º 9
0
 public static AxisRecord Read(BinaryReaderFont reader)
 {
     return(new AxisRecord {
         axisTag = reader.ReadTag(),
         axisNameID = reader.ReadUInt16(),
         axisOrdering = reader.ReadUInt16()
     });
 }
Exemplo n.º 10
0
 public static GlyphData Read(BinaryReaderFont reader, uint dataLength)
 {
     return(new GlyphData {
         originOffsetX = reader.ReadInt16(),
         originOffsetY = reader.ReadInt16(),
         graphicType = reader.ReadTag(),
         data = reader.ReadBytes((int)dataLength)
     });
 }
Exemplo n.º 11
0
 public static TableRecord Read(BinaryReaderFont reader)
 {
     return(new TableRecord {
         tableTag = reader.ReadTag(),
         checkSum = reader.ReadUInt32(),
         offset = reader.ReadUInt32(),
         length = reader.ReadUInt32()
     });
 }
Exemplo n.º 12
0
        public static OS2Table Read(BinaryReaderFont reader)
        {
            OS2Table value = new OS2Table {
                version             = reader.ReadUInt16(),
                xAvgCharWidth       = reader.ReadInt16(),
                usWeightClass       = reader.ReadUInt16(),
                usWidthClass        = reader.ReadUInt16(),
                fsType              = reader.ReadUInt16(),
                ySubscriptXSize     = reader.ReadInt16(),
                ySubscriptYSize     = reader.ReadInt16(),
                ySubscriptXOffset   = reader.ReadInt16(),
                ySubscriptYOffset   = reader.ReadInt16(),
                ySuperscriptXSize   = reader.ReadInt16(),
                ySuperscriptYSize   = reader.ReadInt16(),
                ySuperscriptXOffset = reader.ReadInt16(),
                ySuperscriptYOffset = reader.ReadInt16(),
                yStrikeoutSize      = reader.ReadInt16(),
                yStrikeoutPosition  = reader.ReadInt16(),
                sFamilyClass        = reader.ReadInt16(),
                panose              = reader.ReadBytes(10),
                ulUnicodeRange1     = reader.ReadUInt32(),
                ulUnicodeRange2     = reader.ReadUInt32(),
                ulUnicodeRange3     = reader.ReadUInt32(),
                ulUnicodeRange4     = reader.ReadUInt32(),
                achVendID           = reader.ReadTag(),
                fsSelection         = reader.ReadUInt16(),
                usFirstCharIndex    = reader.ReadUInt16(),
                usLastCharIndex     = reader.ReadUInt16(),
                sTypoAscender       = reader.ReadInt16(),
                sTypoDescender      = reader.ReadInt16(),
                sTypoLineGap        = reader.ReadInt16(),
                usWinAscent         = reader.ReadUInt16(),
                usWinDescent        = reader.ReadUInt16()
            };

            if (value.version >= 1)
            {
                value.ulCodePageRange1 = reader.ReadUInt32();
                value.ulCodePageRange2 = reader.ReadUInt32();
            }
            if (value.version >= 4)
            {
                value.sxHeight      = reader.ReadInt16();
                value.sCapHeight    = reader.ReadInt16();
                value.usDefaultChar = reader.ReadUInt16();
                value.usBreakChar   = reader.ReadUInt16();
                value.usMaxContext  = reader.ReadUInt16();
            }
            if (value.version >= 5)
            {
                value.usLowerOpticalPointSize = reader.ReadUInt16();
                value.usUpperOpticalPointSize = reader.ReadUInt16();
            }
            return(value);
        }
Exemplo n.º 13
0
 public static VariationAxisRecord Read(BinaryReaderFont reader)
 {
     return(new VariationAxisRecord {
         axisTag = reader.ReadTag(),
         minValue = reader.ReadUInt32(),
         defaultValue = reader.ReadUInt32(),
         maxValue = reader.ReadUInt32(),
         flags = reader.ReadUInt16(),
         axisNameID = reader.ReadUInt16()
     });
 }
Exemplo n.º 14
0
        public static BaseScriptRecord Read(BinaryReaderFont reader, long start)
        {
            BaseScriptRecord value = new BaseScriptRecord {
                baseScriptTag    = reader.ReadTag(),
                baseScriptOffset = reader.ReadUInt16()
            };
            long position = reader.Position;

            if (value.baseScriptOffset != 0)
            {
                reader.Position  = start + value.baseScriptOffset;
                value.baseScript = BaseScript.Read(reader);
            }
            reader.Position = position;
            return(value);
        }
Exemplo n.º 15
0
        public static TTCHeader Read(BinaryReaderFont reader)
        {
            TTCHeader value = new TTCHeader();

            value.ttcTag = reader.ReadTag();
            if (value.ttcTag != Tag)
            {
                throw new System.Exception(
                          string.Format("Parse error: ttcTag is not valid. {0}", value.ttcTag)
                          );
            }
            value.majorVersion = reader.ReadUInt16();
            value.minorVersion = reader.ReadUInt16();
            value.numFonts     = reader.ReadUInt32();
            value.offsetTable  = reader.ReadUInt32Array((int)value.numFonts);
            if (value.majorVersion >= 2)
            {
                value.dsigTag    = reader.ReadUInt32();
                value.dsigLength = reader.ReadUInt32();
                value.dsigOffset = reader.ReadUInt32();
            }
            return(value);
        }