/// <summary> /// Initializes a new instance of PdfTrueTypeFont from an XFont. /// </summary> public PdfTrueTypeFont(PdfDocument document, XFont font) : base(document) { Elements.SetName(Keys.Type, "/Font"); Elements.SetName(Keys.Subtype, "/TrueType"); // TrueType with WinAnsiEncoding only. OpenTypeDescriptor ttDescriptor = (OpenTypeDescriptor)FontDescriptorCache.GetOrCreateDescriptorFor(font); FontDescriptor = new PdfFontDescriptor(document, ttDescriptor); _fontOptions = font.PdfOptions; Debug.Assert(_fontOptions != null); //cmapInfo = new CMapInfo(null/*ttDescriptor*/); _cmapInfo = new CMapInfo(ttDescriptor); BaseFont = font.GlyphTypeface.GetBaseName(); BaseFont = PdfFont.CreateEmbeddedFontSubsetName(BaseFont); FontDescriptor.FontName = BaseFont; Debug.Assert(_fontOptions.FontEncoding == PdfFontEncoding.WinAnsi); if (!IsSymbolFont) { Encoding = "/WinAnsiEncoding"; } Owner._irefTable.Add(FontDescriptor); Elements[Keys.FontDescriptor] = FontDescriptor.Reference; FontEncoding = font.PdfOptions.FontEncoding; }
public PdfType0Font(PdfDocument document, XFont font, 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.GetOrCreateDescriptorFor(font); FontDescriptor = new PdfFontDescriptor(document, ttDescriptor); _fontOptions = font.PdfOptions; Debug.Assert(_fontOptions != null); _cmapInfo = new CMapInfo(ttDescriptor); _descendantFont = new PdfCIDFont(document, FontDescriptor, font); _descendantFont.CMapInfo = _cmapInfo; // Create ToUnicode map _toUnicode = new PdfToUnicodeMap(document, _cmapInfo); document.Internals.AddObject(_toUnicode); Elements.Add(Keys.ToUnicode, _toUnicode); BaseFont = font.GlyphTypeface.GetBaseName(); // CID fonts are always embedded BaseFont = PdfFont.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; }
public PdfCIDFont(PdfDocument document, PdfFontDescriptor fontDescriptor, byte[] fontData) : base(document) { Elements.SetName(Keys.Type, "/Font"); Elements.SetName(Keys.Subtype, "/CIDFontType2"); PdfDictionary cid = new PdfDictionary(); cid.Elements.SetString("/Ordering", "Identity"); cid.Elements.SetString("/Registry", "Adobe"); cid.Elements.SetInteger("/Supplement", 0); Elements.SetValue(Keys.CIDSystemInfo, cid); FontDescriptor = fontDescriptor; // ReSharper disable once DoNotCallOverridableMethodsInConstructor Owner._irefTable.Add(fontDescriptor); Elements[Keys.FontDescriptor] = fontDescriptor.Reference; FontEncoding = PdfFontEncoding.Unicode; }
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); _descendantFont.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; }