public PdfType0Font(PdfDocument document, string idName, byte[] fontData, bool vertical) : base(document) { Elements.SetName(Keys.Type, "/Font"); Elements.SetName(Keys.Subtype, "/Type0"); Elements.SetName(Keys.Encoding, vertical ? "/Identity-V" : "/Identity-H"); OpenTypeDescriptor ttDescriptor = (OpenTypeDescriptor)FontDescriptorStock.Global.CreateDescriptor(idName, fontData); this.fontDescriptor = new PdfFontDescriptor(document, ttDescriptor); this.fontOptions = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always); Debug.Assert(this.fontOptions != null); this.cmapInfo = new CMapInfo(ttDescriptor); this.descendantFont = new PdfCIDFont(document, this.fontDescriptor, fontData); this.descendantFont.CMapInfo = this.cmapInfo; // Create ToUnicode map this.toUnicode = new PdfToUnicodeMap(document, this.cmapInfo); document.Internals.AddObject(toUnicode); Elements.Add(Keys.ToUnicode, toUnicode); BaseFont = ttDescriptor.FontName.Replace(" ", ""); //switch (font.Style & (XFontStyle.Bold | XFontStyle.Italic)) //{ // case XFontStyle.Bold: // this.BaseFont += ",Bold"; // break; // case XFontStyle.Italic: // this.BaseFont += ",Italic"; // break; // case XFontStyle.Bold | XFontStyle.Italic: // this.BaseFont += ",BoldItalic"; // break; //} // CID fonts are always embedded if (!BaseFont.Contains("+")) // HACK in PdfType0Font { BaseFont = PdfFont.CreateEmbeddedFontSubsetName(BaseFont); } this.fontDescriptor.FontName = BaseFont; this.descendantFont.BaseFont = BaseFont; PdfArray descendantFonts = new PdfArray(document); Owner.irefTable.Add(descendantFont); descendantFonts.Elements.Add(descendantFont.Reference); Elements[Keys.DescendantFonts] = descendantFonts; }
public PDFType0Font(PDFDocument document, string idName, byte[] fontData, bool vertical) : base(document) { Elements.SetName(Keys.Type, "/Font"); Elements.SetName(Keys.Subtype, "/Type0"); Elements.SetName(Keys.Encoding, vertical ? "/Identity-V" : "/Identity-H"); OpenTypeDescriptor ttDescriptor = (OpenTypeDescriptor)FontDescriptorCache.GetOrCreateDescriptor(idName, fontData); FontDescriptor = new PDFFontDescriptor(document, ttDescriptor); FontOptions = new XPDFFontOptions(PDFFontEncoding.Unicode); Debug.Assert(FontOptions != null); _cmapInfo = new CMapInfo(ttDescriptor); DescendantFont = new PDFCIDFont(document, FontDescriptor, fontData) { CMapInfo = _cmapInfo }; // Create ToUnicode map _toUnicode = new PDFToUnicodeMap(document, _cmapInfo); document.Internals.AddObject(_toUnicode); Elements.Add(Keys.ToUnicode, _toUnicode); //BaseFont = ttDescriptor.FontName.Replace(" ", ""); BaseFont = ttDescriptor.FontName; // CID fonts are always embedded if (!BaseFont.Contains("+")) // HACK in PDFType0Font { BaseFont = CreateEmbeddedFontSubsetName(BaseFont); } FontDescriptor.FontName = BaseFont; DescendantFont.BaseFont = BaseFont; PDFArray descendantFonts = new PDFArray(document); Owner.IrefTable.Add(DescendantFont); descendantFonts.Elements.Add(DescendantFont.Reference); Elements[Keys.DescendantFonts] = descendantFonts; }