public Font(PDF pdf, Stream inputStream) { this.isStandard = false; this.isComposite = true; this.codePage = CodePage.UNICODE; FastFont.Register(pdf, this, inputStream); this.ascent = this.bBoxURy * this.size / (float)this.unitsPerEm; this.descent = this.bBoxLLy * this.size / (float)this.unitsPerEm; this.body_height = this.ascent - this.descent; this.underlineThickness = (float)this.fontUnderlineThickness * this.size / (float)this.unitsPerEm; this.underlinePosition = (float)this.fontUnderlinePosition * this.size / (float)(-(float)this.unitsPerEm) + this.underlineThickness / 2f; pdf.fonts.Add(this); }
// Constructor for the DejaVuLGCSerif.ttf font. public Font(PDF pdf, Stream inputStream) { this.isStandard = false; this.isComposite = true; this.codePage = CodePage.UNICODE; FastFont.Register(pdf, this, inputStream); ascent = bBoxURy * size / unitsPerEm; descent = bBoxLLy * size / unitsPerEm; body_height = ascent - descent; underlineThickness = fontUnderlineThickness * size / unitsPerEm; underlinePosition = fontUnderlinePosition * size / -unitsPerEm + underlineThickness / 2f; pdf.fonts.Add(this); }
internal static void Register(PDF pdf, Font font, Stream inputStream) { font.name = DejaVuLGCSerif.name; font.unitsPerEm = DejaVuLGCSerif.unitsPerEm; font.bBoxLLx = (float)DejaVuLGCSerif.bBoxLLx; font.bBoxLLy = (float)DejaVuLGCSerif.bBoxLLy; font.bBoxURx = (float)DejaVuLGCSerif.bBoxURx; font.bBoxURy = (float)DejaVuLGCSerif.bBoxURy; font.ascent = (float)DejaVuLGCSerif.ascent; font.descent = (float)DejaVuLGCSerif.descent; font.capHeight = (float)DejaVuLGCSerif.capHeight; font.firstChar = DejaVuLGCSerif.firstChar; font.lastChar = DejaVuLGCSerif.lastChar; font.underlinePosition = (float)DejaVuLGCSerif.underlinePosition; font.underlineThickness = (float)DejaVuLGCSerif.underlineThickness; font.compressed_size = DejaVuLGCSerif.compressed_size; font.uncompressed_size = DejaVuLGCSerif.uncompressed_size; font.advanceWidth = FastFont.DecodeRLE(DejaVuLGCSerif.advanceWidth); font.glyphWidth = FastFont.DecodeRLE(DejaVuLGCSerif.glyphWidth); font.unicodeToGID = FastFont.DecodeRLE(DejaVuLGCSerif.unicodeToGID); FastFont.EmbedFontFile(pdf, font, inputStream); FastFont.AddFontDescriptorObject(pdf, font); FastFont.AddCIDFontDictionaryObject(pdf, font); FastFont.AddToUnicodeCMapObject(pdf, font); pdf.Newobj(); pdf.Append("<<\n"); pdf.Append("/Type /Font\n"); pdf.Append("/Subtype /Type0\n"); pdf.Append("/BaseFont /"); pdf.Append(font.name); pdf.Append('\n'); pdf.Append("/Encoding /Identity-H\n"); pdf.Append("/DescendantFonts ["); pdf.Append(font.GetCidFontDictObjNumber()); pdf.Append(" 0 R]\n"); pdf.Append("/ToUnicode "); pdf.Append(font.GetToUnicodeCMapObjNumber()); pdf.Append(" 0 R\n"); pdf.Append(">>\n"); pdf.Endobj(); font.objNumber = pdf.objNumber; }
private static void AddToUnicodeCMapObject(PDF pdf, Font font) { for (int i = 0; i < pdf.fonts.Count; i++) { Font font2 = pdf.fonts[i]; if (font2.name.Equals(font.name) && font2.GetToUnicodeCMapObjNumber() != -1) { font.SetToUnicodeCMapObjNumber(font2.GetToUnicodeCMapObjNumber()); return; } } StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append("/CIDInit /ProcSet findresource begin\n"); stringBuilder.Append("12 dict begin\n"); stringBuilder.Append("begincmap\n"); stringBuilder.Append("/CIDSystemInfo <</Registry (Adobe) /Ordering (Identity) /Supplement 0>> def\n"); stringBuilder.Append("/CMapName /Adobe-Identity def\n"); stringBuilder.Append("/CMapType 2 def\n"); stringBuilder.Append("1 begincodespacerange\n"); stringBuilder.Append("<0000> <FFFF>\n"); stringBuilder.Append("endcodespacerange\n"); List <string> list = new List <string>(); StringBuilder stringBuilder2 = new StringBuilder(); for (int j = 0; j <= 65535; j++) { int num = font.unicodeToGID[j]; if (num > 0) { stringBuilder2.Append('<'); stringBuilder2.Append(FastFont.ToHexString(num)); stringBuilder2.Append("> <"); stringBuilder2.Append(FastFont.ToHexString(j)); stringBuilder2.Append(">\n"); list.Add(stringBuilder2.ToString()); stringBuilder2.Length = 0; if (list.Count == 100) { FastFont.WriteListToBuffer(list, stringBuilder); } } } if (list.Count > 0) { FastFont.WriteListToBuffer(list, stringBuilder); } stringBuilder.Append("endcmap\n"); stringBuilder.Append("CMapName currentdict /CMap defineresource pop\n"); stringBuilder.Append("end\nend"); pdf.Newobj(); pdf.Append("<<\n"); pdf.Append("/Length "); pdf.Append(stringBuilder.Length); pdf.Append("\n"); pdf.Append(">>\n"); pdf.Append("stream\n"); pdf.Append(stringBuilder.ToString()); pdf.Append("\nendstream\n"); pdf.Endobj(); font.SetToUnicodeCMapObjNumber(pdf.objNumber); }