Example #1
0
            static public glyph_base GetGlyphLogicalData(Table_glyf.header h)
            {
                glyph_base gb = null;

                SimpleGlyph sg = h.GetSimpleGlyph();

                if (sg != null)
                {
                    // glyph is a simple glyph

                    gb = GetSimpleGlyphLogicalData(h);
                }
                else
                {
                    CompositeGlyph cg = h.GetCompositeGlyph();
                    if (cg != null)
                    {
                        // glyph is a composite glyph

                        gb = GetCompositeGlyphLogicalData(h);
                    }
                }

                return(gb);
            }
Example #2
0
            public uint CalcGlyphLength()
            {
                uint length = 0;

                if (numberOfContours >= 0)
                {
                    SimpleGlyph sg = null;
                    sg = new SimpleGlyph(this, m_offsetHeader + 10, m_bufTable);
                    if (sg != null)
                    {
                        length = sg.CalcLength();
                    }
                }
                else
                {
                    CompositeGlyph cg = null;
                    cg = new CompositeGlyph(this, m_offsetHeader + 10, m_bufTable);
                    if (cg != null)
                    {
                        length = cg.CalcLength();
                    }
                }

                return(10 + length);
            }
Example #3
0
            public SimpleGlyph GetSimpleGlyph()
            {
                SimpleGlyph sg = null;

                if (numberOfContours >= 0)
                {
                    sg = new SimpleGlyph(this, m_offsetHeader + 10, m_bufTable);
                }

                return(sg);
            }
Example #4
0
            static public glyph_simple GetSimpleGlyphLogicalData(header h)
            {
                glyph_simple gs = null;
                SimpleGlyph  sg = h.GetSimpleGlyph();

                if (sg != null)
                {
                    // glyph is a simple glyph

                    gs = new glyph_simple(h.numberOfContours, h.xMin, h.yMin, h.xMax, h.yMax);

                    SimpleGlyph.Coordinate[]  coords = sg.GetDecodedRelativeCoordinates();
                    glyph_simple.Coordinate16 prevPoint;
                    prevPoint.x = prevPoint.y = 0;
                    glyph_simple.Coordinate16 newPoint;
                    for (uint iContour = 0; iContour < h.numberOfContours; iContour++)
                    {
                        // convert the coordinates in this contour from relative to absolute
                        uint startCoord = 0;
                        if (iContour > 0)
                        {
                            startCoord = (uint)sg.GetEndPtOfContour(iContour - 1) + 1;
                        }
                        uint endCoord = sg.GetEndPtOfContour(iContour);

                        int nPoints = (int)(endCoord - startCoord + 1);
                        glyph_simple.contour Contour = new glyph_simple.contour(nPoints);

                        for (uint iCoord = startCoord; iCoord <= endCoord; iCoord++)
                        {
                            newPoint.x        = (short)(prevPoint.x + coords[iCoord].x);
                            newPoint.y        = (short)(prevPoint.y + coords[iCoord].y);
                            newPoint.bOnCurve = coords[iCoord].bOnCurve;
                            Contour.m_arrPoints.Add(newPoint);
                            prevPoint = newPoint;
                        }

                        gs.m_arrContours.Add(Contour);

                        // copy the hinting instructions
                        gs.m_arrInstructions = new byte[sg.instructionLength];
                        for (uint i = 0; i < sg.instructionLength; i++)
                        {
                            gs.m_arrInstructions[i] = sg.GetInstruction(i);
                        }
                    }
                }
                return(gs);
            }
Example #5
0
        public static GlyfTable Deserialize(BinaryReader reader, long startOffset, uint length, LocaTable locaTable)
        {
            var table = new GlyfTable();

            reader.BaseStream.Position = startOffset;
            var glyphOffsets =
                locaTable.GlyphOffsets.Select((u, i) => new { GlyphId = i, Offset = u })
                .Where(glyph => glyph.Offset != null)
                .Select(pair => new { pair.GlyphId, Offset = pair.Offset.Value }).ToList();

            for (var i = 0; i < glyphOffsets.Count; i++)
            {
                Glyph glyphToAdd;

                // Peek number of contours
                var glyphStartOffset = reader.BaseStream.Position = glyphOffsets[i].Offset + startOffset;
                var numberOfContours = DataTypeConverter.ReadShort(reader);
                if (numberOfContours >= 0)
                {
                    uint nextGlyphStartOffset;
                    if (i == glyphOffsets.Count - 1)
                    {
                        nextGlyphStartOffset = (uint)(startOffset + length);
                    }
                    else
                    {
                        nextGlyphStartOffset = (uint)(glyphOffsets[i + 1].Offset + startOffset);
                    }

                    // TODO: Remove padded zeros

                    glyphToAdd = SimpleGlyph.Deserialize(reader, glyphStartOffset,
                                                         (uint)(nextGlyphStartOffset - glyphStartOffset));
                }
                else
                {
                    glyphToAdd = CompositeGlyph.Deserialize(reader, glyphStartOffset);
                }
                glyphToAdd.Id = (uint)glyphOffsets[i].GlyphId;
                table.Glyphs.Add(glyphToAdd);
            }

            return(table);
        }
Example #6
0
            public uint CalcGlyphLength()
            {
                uint length = 0;

                if (numberOfContours >= 0)
                {
                    SimpleGlyph sg = null;
                    sg = new SimpleGlyph(this, m_offsetHeader + 10, m_bufTable);
                    if (sg != null)
                    {
                        length = sg.CalcLength();
                    }
                }
                else
                {
                    CompositeGlyph cg = null;
                    cg = new CompositeGlyph(this, m_offsetHeader + 10, m_bufTable);
                    if (cg != null)
                    {
                        length = cg.CalcLength();
                    }
                }

                return 10 + length;
            }
Example #7
0
            public SimpleGlyph GetSimpleGlyph()
            {
                SimpleGlyph sg = null;

                if (numberOfContours >= 0)
                {
                    sg = new SimpleGlyph(this, m_offsetHeader + 10, m_bufTable);
                }

                return sg;
            }