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); }
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); }
static public glyph_composite GetCompositeGlyphLogicalData(header h) { glyph_composite gc = null; CompositeGlyph cg = h.GetCompositeGlyph(); if (cg != null) { // glyph is a composite glyph gc = new glyph_composite(h.xMin, h.yMin, h.xMax, h.yMax); // copy any hinting instructions if (cg.AnyComponentsHaveInstructions()) { ushort nInstructions = cg.GetNumInstructions(); gc.m_arrInstructions = new byte[nInstructions]; for (uint i = 0; i < nInstructions; i++) { gc.m_arrInstructions[i] = cg.GetInstruction(i); } } while (cg != null) { glyph_composite.component cc = new glyph_composite.component(); cc.flags = cg.flags; cc.glyphid = cg.glyphIndex; cc.arg1 = cg.arg1; cc.arg2 = cg.arg2; if ((cg.flags & (ushort)CompositeGlyph.Flags.WE_HAVE_A_SCALE) != 0) { cc.scale = cg.scale; } else if ((cg.flags & (ushort)CompositeGlyph.Flags.WE_HAVE_AN_X_AND_Y_SCALE) != 0) { cc.xscale = cg.xscale; cc.yscale = cg.yscale; } else if ((cg.flags & (ushort)CompositeGlyph.Flags.WE_HAVE_A_TWO_BY_TWO) != 0) { cc.xscale_2x2 = cg.xscale_2x2; cc.scale01_2x2 = cg.scale01_2x2; cc.scale10_2x2 = cg.scale10_2x2; cc.yscale_2x2 = cg.yscale_2x2; } gc.m_arrComponents.Add(cc); cg = cg.GetNextCompositeGlyph(); } } return(gc); }
public CompositeGlyph GetCompositeGlyph() { CompositeGlyph cg = null; if (numberOfContours < 0) { cg = new CompositeGlyph(this, m_offsetHeader + 10, m_bufTable); } return(cg); }
public CompositeGlyph GetNextCompositeGlyph() { CompositeGlyph nextCompGlyph = null; if ((flags & (uint)Flags.MORE_COMPONENTS) == (uint)Flags.MORE_COMPONENTS) { uint offset = m_offsetCompositeGlyph + GetCompositeGlyphLength(); nextCompGlyph = new CompositeGlyph(m_header, offset, m_bufTable); } return(nextCompGlyph); }
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); }
public uint CalcLength() { uint length = 0; if (AnyComponentsHaveInstructions()) { length += (uint)2 + GetNumInstructions(); } CompositeGlyph nextCG = this; while (nextCG != null) { length += nextCG.GetCompositeGlyphLength(); nextCG = nextCG.GetNextCompositeGlyph(); } return(length); }
public ushort GetNumInstructions() { ushort nInstructions = 0; if (AnyComponentsHaveInstructions()) { // instructions follow the last component CompositeGlyph lastCG = this; CompositeGlyph nextCG = GetNextCompositeGlyph(); while (nextCG != null) { lastCG = nextCG; nextCG = lastCG.GetNextCompositeGlyph(); } uint nOffset = lastCG.m_offsetCompositeGlyph + lastCG.GetCompositeGlyphLength(); nInstructions = m_bufTable.GetUshort(nOffset); } return(nInstructions); }
public byte GetInstruction(uint i) { byte byteInstruction = 0; ushort nInstructions = 0; if (AnyComponentsHaveInstructions()) { // instructions follow the last component CompositeGlyph lastCG = this; CompositeGlyph nextCG = GetNextCompositeGlyph(); while (nextCG != null) { lastCG = nextCG; nextCG = lastCG.GetNextCompositeGlyph(); } uint nOffset = lastCG.m_offsetCompositeGlyph + lastCG.GetCompositeGlyphLength(); nInstructions = m_bufTable.GetUshort(nOffset); if (i < nInstructions) { byteInstruction = m_bufTable.GetByte(nOffset + 2 + i); } else { throw new ArgumentException(); } } else { throw new ApplicationException("WE_HAVE_INSTRUCTIONS flag is clear"); } return(byteInstruction); }
public bool AnyComponentsHaveInstructions() { bool bInstructions = false; if ((flags & (uint)Flags.WE_HAVE_INSTRUCTIONS) != 0) { bInstructions = true; } else { CompositeGlyph nextCG = GetNextCompositeGlyph(); while (nextCG != null) { if ((nextCG.flags & (uint)Flags.WE_HAVE_INSTRUCTIONS) != 0) { bInstructions = true; break; } nextCG = nextCG.GetNextCompositeGlyph(); } } return(bInstructions); }
public CompositeGlyph GetNextCompositeGlyph() { CompositeGlyph nextCompGlyph = null; if ((flags & (uint)Flags.MORE_COMPONENTS) == (uint)Flags.MORE_COMPONENTS) { uint offset = m_offsetCompositeGlyph + GetCompositeGlyphLength(); nextCompGlyph = new CompositeGlyph(m_header, offset, m_bufTable); } return nextCompGlyph; }
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; }
public CompositeGlyph GetCompositeGlyph() { CompositeGlyph cg = null; if (numberOfContours < 0) { cg = new CompositeGlyph(this, m_offsetHeader + 10, m_bufTable); } return cg; }