Beispiel #1
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);
        }
Beispiel #2
0
 public static VDMXGroup Read(BinaryReaderFont reader)
 {
     return(new VDMXGroup {
         recs = reader.ReadUInt16(),
         startsz = reader.ReadByte(),
         endsz = reader.ReadByte()
     });
 }
Beispiel #3
0
 public static ColorRecord Read(BinaryReaderFont reader)
 {
     return(new ColorRecord {
         blue = reader.ReadByte(),
         green = reader.ReadByte(),
         red = reader.ReadByte(),
         alpha = reader.ReadByte()
     });
 }
Beispiel #4
0
 public static RatioRange Read(BinaryReaderFont reader)
 {
     return(new RatioRange {
         bCharSet = reader.ReadByte(),
         xRatio = reader.ReadByte(),
         yStartRatio = reader.ReadByte(),
         yEndRatio = reader.ReadByte()
     });
 }
Beispiel #5
0
 public static SmallGlyphMetrics Read(BinaryReaderFont reader)
 {
     return(new SmallGlyphMetrics {
         height = reader.ReadByte(),
         width = reader.ReadByte(),
         bearingX = reader.ReadSByte(),
         bearingY = reader.ReadSByte(),
         advance = reader.ReadByte()
     });
 }
Beispiel #6
0
 public static BitmapScale Read(BinaryReaderFont reader)
 {
     return(new BitmapScale {
         hori = SbitLineMetrics.Read(reader),
         vert = SbitLineMetrics.Read(reader),
         ppemX = reader.ReadByte(),
         ppemY = reader.ReadByte(),
         substitutePpemX = reader.ReadByte(),
         substitutePpemY = reader.ReadByte()
     });
 }
Beispiel #7
0
 public static BigGlyphMetrics Read(BinaryReaderFont reader)
 {
     return(new BigGlyphMetrics {
         height = reader.ReadByte(),
         width = reader.ReadByte(),
         horiBearingX = reader.ReadSByte(),
         horiBearingY = reader.ReadSByte(),
         horiAdvance = reader.ReadByte(),
         vertBearingX = reader.ReadSByte(),
         vertBearingY = reader.ReadSByte(),
         vertAdvance = reader.ReadByte()
     });
 }
Beispiel #8
0
        public static CFFTable Read(BinaryReaderFont reader)
        {
            long     position = reader.Position;
            CFFTable value    = new CFFTable();

            value.position = reader.Position;
            value.filePath = reader.FilePath;
            value.major    = reader.ReadByte();
            value.minor    = reader.ReadByte();
            value.hdrSize  = reader.ReadByte();
            value.offSize  = reader.ReadByte();

            reader.Position = position + value.hdrSize;
            value.ReadName(reader);
            value.ReadTopDict(reader);
            value.ReadString(reader);
            value.ReadGlobalSubr(reader);

            CFFTopDict topDict = value.topDict;

            //if (topDict.CharStrings > 0) {
            //	reader.Position = position + topDict.CharStrings;
            //	value.ReadCharStrings(reader);
            //}

            if (topDict.FDSelect > 0)
            {
                reader.Position = position + topDict.FDSelect;
                value.fdSelect  = CFFFDSelect.Read(reader);
            }

            if (topDict.charset > 0)
            {
                reader.Position = position + topDict.charset;
                //value.charsets = CFFCharset.Read(reader, value.CharStringsIndex.count);
            }

            if (topDict.Private.values[0] > 0)
            {
                reader.Position = position + (int)topDict.Private.values[1];
                value.ReadPrivate(reader);
            }

            //Console.WriteLine("Charset: " + value.charsets);
            //Console.WriteLine("Docode: {0}", CFFCharString.Decode(value.charStrings[0]));

            //index = CFFIndex.Read(reader);
            //Console.WriteLine("index ::4 " + index);
            return(value);
        }
Beispiel #9
0
 public static CFFRange1 Read(BinaryReaderFont reader)
 {
     return(new CFFRange1 {
         first = reader.ReadUInt16(),
         nLeft = reader.ReadByte()
     });
 }
Beispiel #10
0
        protected void ReadXCoordinates(BinaryReaderFont reader, int count)
        {
            SimpleGlyphFlags bit1 = SimpleGlyphFlags.X_SHORT_VECTOR;
            SimpleGlyphFlags bit4 = SimpleGlyphFlags.X_IS_SAME_OR_POSITIVE_X_SHORT_VECTOR;

            xCoordinates = new short[count];
            int prevX = 0;

            for (int i = 0; i < count; i++)
            {
                SimpleGlyphFlags flag = flags[i];
                int x = 0;
                if ((flag & bit1) > 0)
                {
                    x = reader.ReadByte();
                    if ((flag & bit4) == 0)
                    {
                        x = -x;
                    }
                }
                else
                {
                    if ((flag & bit4) == 0)
                    {
                        x = reader.ReadInt16();
                    }
                }
                xCoordinates[i] = (short)(x + prevX);
                prevX           = xCoordinates[i];
            }
        }
Beispiel #11
0
        protected void ReadYCoordinates(BinaryReaderFont reader, int count)
        {
            SimpleGlyphFlags bit2 = SimpleGlyphFlags.Y_SHORT_VECTOR;
            SimpleGlyphFlags bit5 = SimpleGlyphFlags.Y_IS_SAME_OR_POSITIVE_Y_SHORT_VECTOR;

            yCoordinates = new short[count];
            int prevY = 0;

            for (int i = 0; i < count; i++)
            {
                SimpleGlyphFlags flag = flags[i];
                int y = 0;
                if ((flag & bit2) > 0)
                {
                    y = reader.ReadByte();
                    if ((flag & bit5) == 0)
                    {
                        y = -y;
                    }
                }
                else
                {
                    if ((flag & bit5) == 0)
                    {
                        y = reader.ReadInt16();
                    }
                }
                yCoordinates[i] = (short)(y + prevY);
                prevY           = yCoordinates[i];
            }
        }
Beispiel #12
0
 public static UnicodeRange Read(BinaryReaderFont reader)
 {
     return(new UnicodeRange {
         startUnicodeValue = reader.ReadUInt24(),
         additionalCount = reader.ReadByte()
     });
 }
Beispiel #13
0
        public static new CFFFDSelect0 Read(BinaryReaderFont reader)
        {
            CFFFDSelect0 value = new CFFFDSelect0 {
                format = reader.ReadByte()
            };

            return(value);
        }
Beispiel #14
0
 protected void ReadFlags(BinaryReaderFont reader, int count)
 {
     flags = new SimpleGlyphFlags[count];
     for (int i = 0; i < count; i++)
     {
         SimpleGlyphFlags flag = (SimpleGlyphFlags)reader.ReadByte();
         flags[i] = flag;
         if (flag.HasFlag(SimpleGlyphFlags.REPEAT_FLAG))
         {
             int repeat = reader.ReadByte();
             for (int n = 0; n <= repeat; n++)
             {
                 flags[i + n] = flag;
             }
             i += repeat;
         }
     }
 }
Beispiel #15
0
        public static new CFFCharset2 Read(BinaryReaderFont reader, int count)
        {
            CFFCharset2 value = new CFFCharset2 {
                format = reader.ReadByte()
            };

            value.Range2 = CFFRange2.ReadArray(reader, count);
            return(value);
        }
Beispiel #16
0
        public static BitmapSize Read(BinaryReaderFont reader)
        {
            BitmapSize value = new BitmapSize {
                indexSubTableArrayOffset = reader.ReadUInt32(),
                indexTablesSize          = reader.ReadUInt32(),
                numberofIndexSubTables   = reader.ReadUInt32(),
                colorRef        = reader.ReadUInt32(),
                hori            = SbitLineMetrics.Read(reader),
                vert            = SbitLineMetrics.Read(reader),
                startGlyphIndex = reader.ReadUInt16(),
                endGlyphIndex   = reader.ReadUInt16(),
                ppemX           = reader.ReadByte(),
                ppemY           = reader.ReadByte(),
                bitDepth        = (BitDepth)reader.ReadByte(),
                flags           = (BitmapFlags)reader.ReadByte()
            };

            return(value);
        }
Beispiel #17
0
 public static new CFFFDSelect3 Read(BinaryReaderFont reader)
 {
     CFFFDSelect3 value = new CFFFDSelect3 {
         format = reader.ReadByte(),
         nRanges = reader.ReadUInt16()
     };
     value.Range3 = CFFRange3.ReadArray(reader, value.nRanges);
     value.sentinel = reader.ReadUInt16();
     return value;
 }
Beispiel #18
0
        public static GlyphBitmapData8 Read(BinaryReaderFont reader)
        {
            GlyphBitmapData8 value = new GlyphBitmapData8 {
                smallMetrics  = SmallGlyphMetrics.Read(reader),
                pad           = reader.ReadByte(),
                numComponents = reader.ReadUInt16()
            };

            value.components = EbdtComponent.ReadArray(reader, value.numComponents);
            return(value);
        }
Beispiel #19
0
        public void ReadOffset(BinaryReaderFont reader, int index, out int offset0, out int offset1)
        {
            if (index < 0 || index >= count - 1)
            {
                offset0 = 0;
                offset1 = 0;
                return;
            }
            switch (offSize)
            {
            case 1:
                reader.Position = position + index;
                offset0         = reader.ReadByte();
                offset1         = reader.ReadByte();
                return;

            case 2:
                reader.Position = position + index * 2;
                offset0         = reader.ReadUInt16();
                offset1         = reader.ReadUInt16();
                return;

            case 3:
                reader.Position = position + index * 3;
                offset0         = reader.ReadUInt24();
                offset1         = reader.ReadUInt24();
                return;

            case 4:
                reader.Position = position + index * 4;
                offset0         = reader.ReadInt32();
                offset1         = reader.ReadInt32();
                return;
            }
            offset0 = 0;
            offset1 = 0;
        }
Beispiel #20
0
 public override int GetGlyphId(int charCode)
 {
     if (charCode >= length - 6)
     {
         return(0);
     }
     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());
         }
 }
Beispiel #21
0
        public static CFFIndex Read(BinaryReaderFont reader)
        {
            CFFIndex value = new CFFIndex();

            value.count = reader.ReadUInt16();
            if (value.count == 0)
            {
                //value.offset = new int[0];
                return(value);
            }
            value.offSize  = reader.ReadByte();
            value.position = reader.Position;

            /*
             * switch (value.offSize) {
             *      case 1:
             *              value.offset = Array.ConvertAll(
             *                      reader.ReadBytes(value.count + 1),
             *                      new Converter<byte, int>((a) => {
             *                              return a;
             *                      })
             *              );
             *              break;
             *      case 2:
             *              value.offset = Array.ConvertAll(
             *                      reader.ReadUInt16Array(value.count + 1),
             *                      new Converter<ushort, int>((a) => {
             *                              return a;
             *                      })
             *              );
             *              break;
             *      case 3:
             *              value.offset = reader.ReadUInt24Array(value.count + 1);
             *              break;
             *      case 4:
             *              value.offset = reader.ReadInt32Array(value.count + 1);
             *              break;
             * }
             */
            //value.offset = reader.ReadBytes(value.offSize + 1);
            //for (int i = 0; i < value.offset.Length; i += 2) {
            //	int length = value.offset[i + 1] - value.offset[i];
            //	value.data = reader.ReadBytes(length);
            //}
            return(value);
        }
Beispiel #22
0
 public static SbitLineMetrics Read(BinaryReaderFont reader)
 {
     return(new SbitLineMetrics {
         ascender = reader.ReadSByte(),
         descender = reader.ReadSByte(),
         widthMax = reader.ReadByte(),
         caretSlopeNumerator = reader.ReadSByte(),
         caretSlopeDenominator = reader.ReadSByte(),
         caretOffset = reader.ReadSByte(),
         minOriginSB = reader.ReadSByte(),
         minAdvanceSB = reader.ReadSByte(),
         maxBeforeBL = reader.ReadSByte(),
         minAfterBL = reader.ReadSByte(),
         pad1 = reader.ReadSByte(),
         pad2 = reader.ReadSByte()
     });
 }
Beispiel #23
0
        public static PostTable Read(BinaryReaderFont reader, TableRecord record)
        {
            PostTable value = new PostTable {
                version            = reader.ReadFixed(),
                italicAngle        = reader.ReadFixed(),
                underlinePosition  = reader.ReadFWORD(),
                underlineThickness = reader.ReadFWORD(),
                isFixedPitch       = reader.ReadUInt32(),
                minMemType42       = reader.ReadUInt32(),
                maxMemType42       = reader.ReadUInt32(),
                minMemType1        = reader.ReadUInt32(),
                maxMemType1        = reader.ReadUInt32(),
            };

            if (value.version == 0x20000)
            {
                value.numGlyphs      = reader.ReadUInt16();
                value.glyphNameIndex = reader.ReadUInt16Array(value.numGlyphs);
                int remain = (int)record.length - 34;
                remain -= value.numGlyphs * 2;
                List <string> names = new List <string>();
                while (remain > 0)
                {
                    byte nameLength = reader.ReadByte();
                    if (nameLength == 0)
                    {
                        break;
                    }
                    string name = reader.ReadString(nameLength);
                    remain -= nameLength + 1;
                    names.Add(name);
                }
                value.names = names.ToArray();
            }
            return(value);
        }
Beispiel #24
0
 public static CFFCharset0 Read(BinaryReaderFont reader)
 {
     return(new CFFCharset0 {
         format = reader.ReadByte()
     });
 }