private void AddCIDFontDictionaryObject( PDF pdf, Font font, OTF otf) { for (int i = 0; i < pdf.fonts.Count; i++) { Font f = pdf.fonts[i]; if (f.name.Equals(otf.fontName) && f.GetCidFontDictObjNumber() != -1) { font.SetCidFontDictObjNumber(f.GetCidFontDictObjNumber()); return; } } pdf.Newobj(); pdf.Append("<<\n"); pdf.Append("/Type /Font\n"); if (otf.cff) { pdf.Append("/Subtype /CIDFontType0\n"); } else { pdf.Append("/Subtype /CIDFontType2\n"); } pdf.Append("/BaseFont /"); pdf.Append(otf.fontName); pdf.Append('\n'); pdf.Append("/CIDSystemInfo <</Registry (Adobe) /Ordering (Identity) /Supplement 0>>\n"); pdf.Append("/FontDescriptor "); pdf.Append(font.GetFontDescriptorObjNumber()); pdf.Append(" 0 R\n"); pdf.Append("/DW "); pdf.Append((int) ((1000f / otf.unitsPerEm) * otf.advanceWidth[0])); pdf.Append('\n'); pdf.Append("/W [0[\n"); for (int i = 0; i < otf.advanceWidth.Length; i++) { pdf.Append((int) ((1000f / otf.unitsPerEm) * otf.advanceWidth[i])); if ((i + 1) % 10 == 0) { pdf.Append('\n'); } else { pdf.Append(' '); } } pdf.Append("]]\n"); pdf.Append("/CIDToGIDMap /Identity\n"); pdf.Append(">>\n"); pdf.Endobj(); font.SetCidFontDictObjNumber(pdf.objNumber); }
internal void RegisterAsComposite( PDF pdf, Font font, Stream inputStream, bool embed) { otf = new OTF(inputStream); if (embed) { EmbedFontFile(pdf, font, otf, false); } AddFontDescriptorObject(pdf, font, otf, embed); AddCIDFontDictionaryObject(pdf, font, otf); AddToUnicodeCMapObject(pdf, font, otf); // Type0 Font Dictionary pdf.Newobj(); pdf.Append("<<\n"); pdf.Append("/Type /Font\n"); pdf.Append("/Subtype /Type0\n"); pdf.Append("/BaseFont /"); pdf.Append(otf.fontName); 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; }
internal static void Register( PDF pdf, Font font, Stream inputStream) { font.name = DejaVuLGCSerif.name; font.unitsPerEm = DejaVuLGCSerif.unitsPerEm; font.bBoxLLx = DejaVuLGCSerif.bBoxLLx; font.bBoxLLy = DejaVuLGCSerif.bBoxLLy; font.bBoxURx = DejaVuLGCSerif.bBoxURx; font.bBoxURy = DejaVuLGCSerif.bBoxURy; font.ascent = DejaVuLGCSerif.ascent; font.descent = DejaVuLGCSerif.descent; font.capHeight = DejaVuLGCSerif.capHeight; font.firstChar = DejaVuLGCSerif.firstChar; font.lastChar = DejaVuLGCSerif.lastChar; font.underlinePosition = DejaVuLGCSerif.underlinePosition; font.underlineThickness = DejaVuLGCSerif.underlineThickness; font.compressed_size = DejaVuLGCSerif.compressed_size; font.uncompressed_size = DejaVuLGCSerif.uncompressed_size; font.advanceWidth = DecodeRLE(DejaVuLGCSerif.advanceWidth); font.glyphWidth = DecodeRLE(DejaVuLGCSerif.glyphWidth); font.unicodeToGID = DecodeRLE(DejaVuLGCSerif.unicodeToGID); EmbedFontFile(pdf, font, inputStream); AddFontDescriptorObject(pdf, font); AddCIDFontDictionaryObject(pdf, font); AddToUnicodeCMapObject(pdf, font); // Type0 Font Dictionary 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; }
internal void RegisterAsComposite( PDF pdf, Font font, Stream inputStream, bool embed) { otf = new OTF(inputStream); if (embed) { EmbedFontFile(pdf, font, otf, false); } AddFontDescriptorObject(pdf, font, otf, embed); AddCIDFontDictionaryObject(pdf, font, otf); AddToUnicodeCMapObject(pdf, font, otf); // Type0 Font Dictionary pdf.Newobj(); pdf.Append("<<\n"); pdf.Append("/Type /Font\n"); pdf.Append("/Subtype /Type0\n"); pdf.Append("/BaseFont /"); pdf.Append(otf.fontName); 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; }
internal static void Register( PDF pdf, Font font, Stream inputStream) { int len = inputStream.ReadByte(); byte[] fontName = new byte[len]; inputStream.Read(fontName, 0, len); font.name = System.Text.Encoding.UTF8.GetString(fontName); // Console.WriteLine(font.name); font.unitsPerEm = GetInt32(inputStream); font.bBoxLLx = GetInt32(inputStream); font.bBoxLLy = GetInt32(inputStream); font.bBoxURx = GetInt32(inputStream); font.bBoxURy = GetInt32(inputStream); font.ascent = GetInt32(inputStream); font.descent = GetInt32(inputStream); font.firstChar = GetInt32(inputStream); font.lastChar = GetInt32(inputStream); font.capHeight = GetInt32(inputStream); font.underlinePosition = GetInt32(inputStream); font.underlineThickness = GetInt32(inputStream); len = GetInt32(inputStream); font.advanceWidth = new int[len]; for (int i = 0; i < len; i++) { font.advanceWidth[i] = GetInt16(inputStream); } len = GetInt32(inputStream); font.glyphWidth = new int[len]; for (int i = 0; i < len; i++) { font.glyphWidth[i] = GetInt16(inputStream); } len = GetInt32(inputStream); font.unicodeToGID = new int[len]; for (int i = 0; i < len; i++) { font.unicodeToGID[i] = GetInt16(inputStream); } font.uncompressed_size = GetInt32(inputStream); font.compressed_size = GetInt32(inputStream); EmbedFontFile(pdf, font, inputStream); AddFontDescriptorObject(pdf, font); AddCIDFontDictionaryObject(pdf, font); AddToUnicodeCMapObject(pdf, font); // Type0 Font Dictionary 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; }
internal static void Register( SortedDictionary <Int32, PDFobj> objects, Font font, Stream inputStream) { int len = inputStream.ReadByte(); byte[] fontName = new byte[len]; inputStream.Read(fontName, 0, len); font.name = System.Text.Encoding.UTF8.GetString(fontName, 0, len); // Console.WriteLine(font.name); len = GetInt24(inputStream); byte[] fontInfo = new byte[len]; inputStream.Read(fontInfo, 0, len); font.info = System.Text.Encoding.UTF8.GetString(fontInfo, 0, len); // Console.WriteLine(font.info); byte[] buf = new byte[GetInt32(inputStream)]; inputStream.Read(buf, 0, buf.Length); Decompressor decompressor = new Decompressor(buf); MemoryStream stream = new MemoryStream(decompressor.GetDecompressedData()); font.unitsPerEm = GetInt32(stream); font.bBoxLLx = GetInt32(stream); font.bBoxLLy = GetInt32(stream); font.bBoxURx = GetInt32(stream); font.bBoxURy = GetInt32(stream); font.ascent = GetInt32(stream); font.descent = GetInt32(stream); font.firstChar = GetInt32(stream); font.lastChar = GetInt32(stream); font.capHeight = GetInt32(stream); font.underlinePosition = GetInt32(stream); font.underlineThickness = GetInt32(stream); len = GetInt32(stream); font.advanceWidth = new int[len]; for (int i = 0; i < len; i++) { font.advanceWidth[i] = GetInt16(stream); } len = GetInt32(stream); font.glyphWidth = new int[len]; for (int i = 0; i < len; i++) { font.glyphWidth[i] = GetInt16(stream); } len = GetInt32(stream); font.unicodeToGID = new int[len]; for (int i = 0; i < len; i++) { font.unicodeToGID[i] = GetInt16(stream); } font.cff = (inputStream.ReadByte() == 'Y') ? true : false; font.uncompressed_size = GetInt32(inputStream); font.compressed_size = GetInt32(inputStream); EmbedFontFile(objects, font, inputStream); AddFontDescriptorObject(objects, font); AddCIDFontDictionaryObject(objects, font); AddToUnicodeCMapObject(objects, font); // Type0 Font Dictionary PDFobj obj = new PDFobj(); List <String> dict = obj.GetDict(); dict.Add("<<"); dict.Add("/Type"); dict.Add("/Font"); dict.Add("/Subtype"); dict.Add("/Type0"); dict.Add("/BaseFont"); dict.Add("/" + font.name); dict.Add("/Encoding"); dict.Add("/Identity-H"); dict.Add("/DescendantFonts"); dict.Add("["); dict.Add(font.GetCidFontDictObjNumber().ToString()); dict.Add("0"); dict.Add("R"); dict.Add("]"); dict.Add("/ToUnicode"); dict.Add(font.GetToUnicodeCMapObjNumber().ToString()); dict.Add("0"); dict.Add("R"); dict.Add(">>"); obj.number = MaxKey(objects.Keys) + 1; objects.Add(obj.number, obj); font.objNumber = obj.number; }
internal static void Register( PDF pdf, Font font, Stream inputStream) { int len = inputStream.ReadByte(); byte[] fontName = new byte[len]; inputStream.Read(fontName, 0, len); font.name = System.Text.Encoding.UTF8.GetString(fontName); // Console.WriteLine(font.name); font.unitsPerEm = GetInt32(inputStream); font.bBoxLLx = GetInt32(inputStream); font.bBoxLLy = GetInt32(inputStream); font.bBoxURx = GetInt32(inputStream); font.bBoxURy = GetInt32(inputStream); font.ascent = GetInt32(inputStream); font.descent = GetInt32(inputStream); font.firstChar = GetInt32(inputStream); font.lastChar = GetInt32(inputStream); font.capHeight = GetInt32(inputStream); font.underlinePosition = GetInt32(inputStream); font.underlineThickness = GetInt32(inputStream); len = GetInt32(inputStream); font.advanceWidth = new int[len]; for (int i = 0; i < len; i++) { font.advanceWidth[i] = GetInt16(inputStream); } len = GetInt32(inputStream); font.glyphWidth = new int[len]; for (int i = 0; i < len; i++) { font.glyphWidth[i] = GetInt16(inputStream); } len = GetInt32(inputStream); font.unicodeToGID = new int[len]; for (int i = 0; i < len; i++) { font.unicodeToGID[i] = GetInt16(inputStream); } font.uncompressed_size = GetInt32(inputStream); font.compressed_size = GetInt32(inputStream); EmbedFontFile(pdf, font, inputStream); AddFontDescriptorObject(pdf, font); AddCIDFontDictionaryObject(pdf, font); AddToUnicodeCMapObject(pdf, font); // Type0 Font Dictionary 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; }