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); }
public static void DrawGlyph(RendererContext context) { CFFTable cff = context.Font.Tables.CFF; HmtxTable hmtx = context.Font.Tables.hmtx; LongHorMetric hMetric = context.hMetric; //Console.WriteLine("glyphId: " + glyphId); bool hasWidth = false; if (hmtx != null) { hMetric = hmtx.GetMetric(context.GlyphId); if (cff.privateDict != null && hMetric != null) { //Console.WriteLine("advanceWidth: {0}", hMetric.advanceWidth); //Console.WriteLine("cff.privateDict.defaultWidthX: {0}", cff.privateDict.defaultWidthX); hasWidth = hMetric.advanceWidth != (ushort)cff.privateDict.defaultWidthX; } } //Console.WriteLine(); //Console.WriteLine("glyphId: {0}", context.GlyphId); //Console.WriteLine("Docode:\n{0}", CFFCharString.Decode(cff.charStrings[context.GlyphId])); GraphicsPath path = cff.GetGlyph(context.GlyphId, hasWidth); if (path == null) { if (hMetric != null) { context.X += hMetric.advanceWidth; return; } context.X += 100; return; } float imageSize = context.FontSize; float unitsPerEm = context.Font.Tables.head.unitsPerEm; float ascender = context.Font.Tables.hhea.ascender; float descender = context.Font.Tables.hhea.descender; float scale = imageSize / (ascender - descender); //float scale = imageSize / unitsPerEm; //scale *= 0.01f; float baseLine = scale * ascender; /* * GraphicsPath path = new GraphicsPath(FillMode.Alternate); * for (int i = 0; i < points.Count; i++) { * PointF p = points[i]; * Console.WriteLine("Point: {0}", points[i]); * p.X /= 10; * p.Y /= 10; * //p.X = -p.X; * //p.Y = -p.Y; * //p.X += 100; * //p.Y += 100; * points[i] = p; * } * Console.WriteLine(); */ //path.AddLines(points.ToArray()); //path.Transform(new Matrix(scale, 0, 0, -scale, (float)Math.Round(x * scale), baseLine)); float x = context.DX + context.X * scale; float y = context.DY + baseLine; path.Transform(new Matrix( scale, 0, 0, -scale, x, y) ); path.CloseFigure(); context.Graphics.FillPath(Brushes.Black, path); //Console.WriteLine("hMetric.advanceWidth: {0}", hMetric.advanceWidth); if (hMetric != null) { context.X += hMetric.advanceWidth; return; } context.X += 100; }
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 } }