/// <summary> /// Creates a character indexed font from <i>cidFont</i> /// </summary> /// <remarks> /// The <i>font</i> and <i>cidFont</i> will be different object /// references since the <i>font</i> parameter will most likely /// be a <see cref="ProxyFont"/>. /// </remarks> /// <param name="pdfFontID">The Pdf font identifier, e.g. F15</param> /// <param name="font">Required to access the font descriptor.</param> /// <param name="cidFont">The underlying CID font.</param> /// <returns></returns> private PdfFont CreateCIDFont( string pdfFontID, Font font, CIDFont cidFont) { // The font descriptor is required to access licensing details are // obtain the font program itself as a byte array IFontDescriptor descriptor = font.Descriptor; // A compressed stream that stores the font program PdfFontFile fontFile = new PdfFontFile( NextObjectId(), descriptor.FontData); // Add indirect reference to FontFile object to descriptor PdfFontDescriptor pdfDescriptor = MakeFontDescriptor(pdfFontID, cidFont); pdfDescriptor.FontFile2 = fontFile; PdfCIDSystemInfo pdfCidSystemInfo = new PdfCIDSystemInfo( cidFont.Registry, cidFont.Ordering, cidFont.Supplement); PdfCIDFont pdfCidFont = new PdfCIDFont( NextObjectId(), PdfFontSubTypeEnum.CIDFontType2, font.FontName); pdfCidFont.SystemInfo = pdfCidSystemInfo; pdfCidFont.Descriptor = pdfDescriptor; pdfCidFont.DefaultWidth = new PdfNumeric(cidFont.DefaultWidth); pdfCidFont.Widths = cidFont.WArray; // Create a ToUnicode CMap that maps characters codes (GIDs) to // unicode values. Very important to ensure searching and copying // from a PDF document works correctly. PdfCMap pdfCMap = new PdfCMap(NextObjectId()); pdfCMap.AddFilter(new FlateFilter()); pdfCMap.SystemInfo = pdfCidSystemInfo; pdfCMap.AddBfRanges(cidFont.CMapEntries); // Create a PDF object to represent the CID font PdfType0Font pdfFont = new PdfType0Font( NextObjectId(), pdfFontID, font.FontName); pdfFont.Encoding = new PdfName(cidFont.Encoding); pdfFont.Descendant = pdfCidFont; pdfFont.ToUnicode = pdfCMap; // Add all the Pdf objects to the document. MakeFont will add the actual // PdfFont object to the document. creator.AddObject(pdfDescriptor); creator.AddObject(pdfCidFont); creator.AddObject(pdfCMap); creator.AddObject(fontFile); return(pdfFont); }
/// <summary> /// Creates a character indexed font from <i>cidFont</i> /// </summary> /// <remarks> /// The <i>font</i> and <i>cidFont</i> will be different object /// references since the <i>font</i> parameter will most likely /// be a <see cref="ProxyFont"/>. /// </remarks> /// <param name="pdfFontID">The Pdf font identifier, e.g. F15</param> /// <param name="font">Required to access the font descriptor.</param> /// <param name="cidFont">The underlying CID font.</param> /// <returns></returns> private PdfFont CreateCIDFont( string pdfFontID, Font font, CIDFont cidFont) { // The font descriptor is required to access licensing details are // obtain the font program itself as a byte array IFontDescriptor descriptor = font.Descriptor; // A compressed stream that stores the font program PdfFontFile fontFile = new PdfFontFile( NextObjectId(), descriptor.FontData); // Add indirect reference to FontFile object to descriptor PdfFontDescriptor pdfDescriptor = MakeFontDescriptor(pdfFontID, cidFont); pdfDescriptor.FontFile2 = fontFile; PdfCIDSystemInfo pdfCidSystemInfo = new PdfCIDSystemInfo( cidFont.Registry, cidFont.Ordering, cidFont.Supplement); PdfCIDFont pdfCidFont = new PdfCIDFont( NextObjectId(), PdfFontSubTypeEnum.CIDFontType2, font.FontName); pdfCidFont.SystemInfo = pdfCidSystemInfo; pdfCidFont.Descriptor = pdfDescriptor; pdfCidFont.DefaultWidth = new PdfNumeric(cidFont.DefaultWidth); pdfCidFont.Widths = cidFont.WArray; // Create a ToUnicode CMap that maps characters codes (GIDs) to // unicode values. Very important to ensure searching and copying // from a PDF document works correctly. PdfCMap pdfCMap = new PdfCMap(NextObjectId()); pdfCMap.AddFilter(new FlateFilter()); pdfCMap.SystemInfo = pdfCidSystemInfo; pdfCMap.AddBfRanges(cidFont.CMapEntries); // Create a PDF object to represent the CID font PdfType0Font pdfFont = new PdfType0Font( NextObjectId(), pdfFontID, font.FontName); pdfFont.Encoding = new PdfName(cidFont.Encoding); pdfFont.Descendant = pdfCidFont; pdfFont.ToUnicode = pdfCMap; // Add all the Pdf objects to the document. MakeFont will add the actual // PdfFont object to the document. creator.AddObject(pdfDescriptor); creator.AddObject(pdfCidFont); creator.AddObject(pdfCMap); creator.AddObject(fontFile); return pdfFont; }