public static GlyfTable Read(BinaryReaderFont reader, LocaTable loca) { //long position = reader.Position; //uint[] offsets = loca.offsets; GlyfTable value = new GlyfTable(); value.position = reader.Position; value.filePath = reader.FilePath; value.loca = loca; /* * int length = loca.offsets.Length - 1; * value.glyphs = new Glyph[length]; * for (int i = 0; i < length; i++) { * uint offset = offsets[i]; * uint glyphLength = offsets[i + 1] - offset; * if (glyphLength == 0) { * value.glyphs[i] = null; * continue; * } * reader.Position = position + offset; * Glyph glyph = Glyph.Read(reader); * value.glyphs[i] = glyph; * } */ return(value); }
public void ReadTables(BinaryReaderFont reader) { if (offset == null) { return; } int length = offset.numTables; for (int i = 0; i < length; i++) { TableRecord record = Records[i]; //Console.WriteLine(record); //bool checkSum = reader.TableChecksum(record); //Console.WriteLine("checkSum {0}: {1}", record.tableTag, checkSum); reader.Position = record.offset; long memory = 0; #if DEBUG memory = GC.GetTotalMemory(false); #endif switch (record.tableTag) { case AvarTable.Tag: // OpenType Font Variations avar = AvarTable.Read(reader); break; case BASETable.Tag: // Advanced Typographic Table //BASE = BASETable.Read(reader); break; case CBDTTable.Tag: // Related to Bitmap Glyphs, Related to Color Fonts CBDT = CBDTTable.Read(reader, CBLC); break; case CBLCTable.Tag: // Related to Bitmap Glyphs, Related to Color Fonts CBLC = CBLCTable.Read(reader); break; case CFFTable.Tag: // Related to CFF Outlines CFF = CFFTable.Read(reader); break; case CFF2Table.Tag: // Related to CFF Outlines //CFF2 = CFF2Table.Read(reader); break; case CmapTable.Tag: // Required Table cmap = CmapTable.Read(reader); break; case COLRTable.Tag: // Related to Color Fonts //COLR = COLRTable.Read(reader); break; case CPALTable.Tag: // Related to Color Fonts //CPAL = CPALTable.Read(reader); break; case CvarTable.Tag: // OpenType Font Variations cvar = CvarTable.Read(reader); break; case CvtTable.Tag: // Related to TrueType Outlines cvt = CvtTable.Read(reader, record); break; case DSIGTable.Tag: // Other OpenType Table //DSIG = DSIGTable.Read(reader); break; case EBDTTable.Tag: // Related to Bitmap Glyphs EBDT = EBDTTable.Read(reader, EBLC); break; case EBLCTable.Tag: // Related to Bitmap Glyphs EBLC = EBLCTable.Read(reader); break; case EBSCTable.Tag: // Related to Bitmap Glyphs //EBSC = EBSCTable.Read(reader); break; case FpgmTable.Tag: // Related to TrueType Outlines fpgm = FpgmTable.Read(reader, record); break; case FvarTable.Tag: // OpenType Font Variations fvar = FvarTable.Read(reader); break; case GaspTable.Tag: // Related to TrueType Outlines //gasp = GaspTable.Read(reader); break; case GDEFTable.Tag: // Advanced Typographic Table //GDEF = GDEFTable.Read(reader); break; case GlyfTable.Tag: // Related to TrueType Outlines glyf = GlyfTable.Read(reader, loca); break; case GPOSTable.Tag: // Advanced Typographic Table //GPOS = GPOSTable.Read(reader); break; case GSUBTable.Tag: // Advanced Typographic Table //GSUB = GSUBTable.Read(reader); break; case GvarTable.Tag: // OpenType Font Variations //gvar = GvarTable.Read(reader); break; case HdmxTable.Tag: // Other OpenType Table hdmx = HdmxTable.Read(reader); break; case HeadTable.Tag: // Required Table head = HeadTable.Read(reader); break; case HheaTable.Tag: // Required Table hhea = HheaTable.Read(reader); break; case HmtxTable.Tag: // Required Table hmtx = HmtxTable.Read(reader, hhea, maxp); break; case HVARTable.Tag: // OpenType Font Variations //HVAR = HVARTable.Read(reader); break; case JSTFTable.Tag: // Advanced Typographic Table //JSTF = JSTFTable.Read(reader); break; case KernTable.Tag: // Other OpenType Table //kern = KernTable.Read(reader); break; case LocaTable.Tag: // Related to TrueType Outlines loca = LocaTable.Read(reader, head, maxp); break; case LTSHTable.Tag: // Other OpenType Table //LTSH = LTSHTable.Read(reader); break; case MATHTable.Tag: // Advanced Typographic Table //MATH = MATHTable.Read(reader); break; case MaxpTable.Tag: // Required Table maxp = MaxpTable.Read(reader); break; case MERGTable.Tag: // Other OpenType Table //MERG = MERGTable.Read(reader); break; case MetaTable.Tag: // Other OpenType Table //meta = MetaTable.Read(reader); break; case MVARTable.Tag: // OpenType Font Variations //MVAR = MVARTable.Read(reader); break; case NameTable.Tag: // Required Table name = NameTable.Read(reader); break; case OS2Table.Tag: // Required Table //OS2 = OS2Table.Read(reader); break; case PcltTable.Tag: // Other OpenType Table pclt = PcltTable.Read(reader); break; case PostTable.Tag: // Required Table //post = PostTable.Read(reader, record); break; case PrepTable.Tag: // Related to TrueType Outlines prep = PrepTable.Read(reader, record); break; case SbixTable.Tag: // Related to Bitmap Glyphs, Related to Color Fonts sbix = SbixTable.Read(reader, maxp); break; case STATTable.Tag: // OpenType Font Variations, Other OpenType Table //STAT = STATTable.Read(reader); break; case SVGTable.Tag: // Related to SVG Outlines, Related to Color Fonts //SVG = SVGTable.Read(reader); break; case VDMXTable.Tag: // Other OpenType Table //VDMX = VDMXTable.Read(reader); break; case VheaTable.Tag: // Other OpenType Table //vhea = VheaTable.Read(reader); break; case VmtxTable.Tag: // Other OpenType Table //vmtx = VmtxTable.Read(reader); break; case VORGTable.Tag: // Related to CFF Outlines //VORG = VORGTable.Read(reader); break; case VVARTable.Tag: // OpenType Font Variations //VVAR = VVARTable.Read(reader); break; } #if DEBUG if (Font.IsDebug) { memory = GC.GetTotalMemory(false) - memory; Console.WriteLine("{0} memory: {1}", record.tableTag, memory); } #endif } }
public void DrawText(Bitmap bitmap, string text, float x, float y) { if (UseInterpreter) { interpreter.ppem = FontSize; InterpretPrep(); } context.UseInterpreter = UseInterpreter; context.UseBitmapGlyph = UseBitmapGlyph; context.DX = x; context.DY = y; context.FontSize = FontSize; context.Bitmap = bitmap; context.Graphics = Graphics.FromImage(bitmap); context.Graphics.SmoothingMode = SmoothingMode.HighQuality; HmtxTable hmtx = font.Tables.hmtx; GlyfTable glyf = font.Tables.glyf; char highSurrogate = '\0'; int length = text.Length; for (int i = 0; i < length; i++) { char charCode = text[i]; if (char.IsHighSurrogate(charCode)) { highSurrogate = charCode; continue; } int codePoint; if (char.IsLowSurrogate(charCode)) { codePoint = char.ConvertToUtf32(highSurrogate, charCode); } else { codePoint = charCode; } context.CodePoint = codePoint; context.GlyphId = font.GetGlyphId(codePoint); if (hmtx != null) { context.hMetric = hmtx.GetMetric(context.GlyphId); } if (glyf != null) { context.Glyph = glyf.GetGlyph(context.GlyphId); if (context.Glyph == null) { //context.GlyphId = 0; //context.Glyph = glyf.GetGlyph(0); if (hmtx != null) { //context.hMetric = hmtx.GetMetric(0); } } } DrawGlyph(context); } context.Reset(); }