Пример #1
0
 public TrueTypeFont(Header header, Maxp maxp, Loca loca, Glyf glyf)
 {
     Header = header;
     Maxp = maxp;
     Loca = loca;
     Glyf = glyf;
 }
Пример #2
0
        private Glyf ExtractAsGlyf(BinaryReader reader, int numGlyphs, Loca loca, Table table)
        {
            //see: https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6glyf.html

            var glyphs = new Glyph[numGlyphs];

            for (int i = 0; i < numGlyphs; i++)
            {
                reader.BaseStream.Seek(table.Offset, SeekOrigin.Begin);
                reader.BaseStream.Seek(loca.Offsets[i], SeekOrigin.Current);
                var length = loca.Offsets[i + 1] - loca.Offsets[i];

                if (length > 0)
                {
                    var numberOfContours = reader.ReadInt16();
                    var xMin = reader.ReadInt16();
                    var yMin = reader.ReadInt16();
                    var xMax = reader.ReadInt16();
                    var yMax = reader.ReadInt16();

                    if (numberOfContours >= 0)
                    {
                        //If the number of contours is positive or zero, it is a single glyph;
                        glyphs[i] = ReadSimpleGlyph(reader, numberOfContours, xMin, yMin, xMax, yMax);
                    }
                    else
                    {
                        //If the number of contours less than zero, the glyph is compound
                        glyphs[i] = ReadCompoundGlyph(reader, -numberOfContours, xMin, yMin, xMax, yMax);
                    }
                }
                else
                {
                    glyphs[i] = Glyph.Empty;
                }
            }

            return new Glyf(
                glyphs
            );
        }