Exemple #1
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;
        }
Exemple #2
0
        public static GlyphBitmapData5 Read(BinaryReaderFont reader, int byteSize)
        {
            GlyphBitmapData5 value = new GlyphBitmapData5();

            value.imageData = reader.ReadBytes(byteSize);
            return(value);
        }
Exemple #3
0
        public int[] ReadAllOffsets(BinaryReaderFont reader)
        {
            if (count == 0)
            {
                return(new int[0]);
            }
            switch (offSize)
            {
            case 1:
                return(Array.ConvertAll(
                           reader.ReadBytes(count + 1),
                           new Converter <byte, int>((a) => {
                    return a;
                })
                           ));

            case 2:
                return(Array.ConvertAll(
                           reader.ReadUInt16Array(count + 1),
                           new Converter <ushort, int>((a) => {
                    return a;
                })
                           ));

            case 3:
                return(reader.ReadUInt24Array(count + 1));

            case 4:
                return(reader.ReadInt32Array(count + 1));
            }
            return(new int[0]);
        }
Exemple #4
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)
     });
 }
Exemple #5
0
        public static GlyphBitmapData19 Read(BinaryReaderFont reader)
        {
            GlyphBitmapData19 value = new GlyphBitmapData19 {
                dataLen = reader.ReadUInt32()
            };

            value.data = reader.ReadBytes((int)value.dataLen);
            return(value);
        }
Exemple #6
0
        public static GlyphBitmapData18 Read(BinaryReaderFont reader)
        {
            GlyphBitmapData18 value = new GlyphBitmapData18 {
                glyphMetrics = BigGlyphMetrics.Read(reader),
                dataLen      = reader.ReadUInt32()
            };

            value.data = reader.ReadBytes((int)value.dataLen);
            return(value);
        }
Exemple #7
0
        public static GlyphBitmapData6 Read(BinaryReaderFont reader, int byteSize)
        {
            GlyphBitmapData6 value = new GlyphBitmapData6 {
                bigMetrics = BigGlyphMetrics.Read(reader)
            };

            byteSize       -= BigGlyphMetrics.ByteSize;
            value.imageData = reader.ReadBytes(byteSize);
            return(value);
        }
Exemple #8
0
        public static GlyphBitmapData2 Read(BinaryReaderFont reader, int byteSize)
        {
            GlyphBitmapData2 value = new GlyphBitmapData2 {
                smallMetrics = SmallGlyphMetrics.Read(reader)
            };

            byteSize       -= SmallGlyphMetrics.ByteSize;
            value.imageData = reader.ReadBytes(byteSize);
            return(value);
        }
Exemple #9
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);
        }
Exemple #10
0
 public byte[] ReadData()
 {
     if (File.Exists(filePath) == false)
     {
         return(null);
     }
     using (Stream stream = File.OpenRead(filePath))
         using (BinaryReaderFont reader = new BinaryReaderFont(stream)) {
             reader.Position = position;
             return(reader.ReadBytes(length));
         }
 }
Exemple #11
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);
        }
Exemple #12
0
        protected void ReadGlobalSubr(BinaryReaderFont reader)
        {
            CFFIndex index = CFFIndex.Read(reader);

            int[] offset = index.ReadAllOffsets(reader);
            //Console.WriteLine("global subr index: {0}", index);
            globalSubr = new byte[index.count][];
            int length = offset.Length - 1;

            for (int i = 0; i < length; i++)
            {
                int byteSize = offset[i + 1] - offset[i];
                globalSubr[i] = reader.ReadBytes(byteSize);
            }
            charString.globalSubr = globalSubr;
        }
Exemple #13
0
        public static MetaTable Read(BinaryReaderFont reader)
        {
            long      position = reader.Position;
            MetaTable value    = new MetaTable {
                version       = reader.ReadUInt32(),
                flags         = reader.ReadUInt32(),
                dataOffset    = reader.ReadUInt32(),
                dataMapsCount = reader.ReadUInt32(),
            };

            value.dataMaps = DataMap.ReadArray(reader, value.dataMapsCount);
            for (int i = 0; i < value.dataMapsCount; i++)
            {
                DataMap dataMap = value.dataMaps[i];
                reader.Position = position + dataMap.dataOffset;
                dataMap.data    = reader.ReadBytes((int)dataMap.dataLength);
            }
            return(value);
        }
Exemple #14
0
        public static new SimpleGlyph Read(BinaryReaderFont reader, Glyph glyph)
        {
            SimpleGlyph value = new SimpleGlyph {
                endPtsOfContours  = reader.ReadUInt16Array(glyph.numberOfContours),
                instructionLength = reader.ReadUInt16()
            };

            if (value.instructionLength > 0)
            {
                value.instructions = reader.ReadBytes(value.instructionLength);
            }
            int length = value.endPtsOfContours.Length;
            int count  = value.endPtsOfContours[length - 1] + 1;

            value.ReadFlags(reader, count);
            value.ReadXCoordinates(reader, count);
            value.ReadYCoordinates(reader, count);
            //Console.WriteLine("Glyph count: " + count);
            //Console.WriteLine("Glyph count2: " + value.flags.Length);
            return(value);
        }
Exemple #15
0
 public GraphicsPath GetGlyph(int glyphId, bool hasWidth)
 {
     if (glyphId < 0)
     {
         return(null);
     }
     if (File.Exists(filePath) == false)
     {
         return(null);
     }
     byte[] cs = null;
     using (Stream stream = File.OpenRead(filePath))
         using (BinaryReaderFont reader = new BinaryReaderFont(stream)) {
             reader.Position = position + topDict.CharStrings;
             CFFIndex index = CFFIndex.Read(reader);
             //Console.WriteLine("CharStrings index: {0}", index);
             long offsetStart = reader.Position;
             int  offset0     = 0;
             int  offset1     = 0;
             index.ReadOffset(reader, glyphId, out offset0, out offset1);
             int byteSize = offset1 - offset0;
             if (byteSize <= 0)
             {
                 return(null);
             }
             //Console.WriteLine("offset0: {0}, {1}", offset0, offset1);
             //Console.WriteLine("lastItem: {0}", offsetStart);
             offsetStart += (index.count + 1) * index.offSize;
             //Console.WriteLine("lastItem: {0}", offsetStart);
             reader.Position = offsetStart + offset0 - 1;
             cs = reader.ReadBytes(byteSize);
         }
     if (cs == null)
     {
         return(null);
     }
     //Console.WriteLine("Docode: {0}", CFFCharString.Decode(charString));
     return(charString.CreateGlyph(cs, hasWidth));
 }