/// <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(); if (_fontOptions.FontEmbedding == PdfFontEmbedding.Always) { 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 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)FontDescriptorStock.Global.CreateDescriptor(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); //if (this.fontOptions.BaseFont != "") //{ // BaseFont = this.fontOptions.BaseFont; //} //else { BaseFont = font.Name.Replace(" ", ""); switch (font.Style & (XFontStyle.Bold | XFontStyle.Italic)) { case XFontStyle.Bold: BaseFont += ",Bold"; break; case XFontStyle.Italic: BaseFont += ",Italic"; break; case XFontStyle.Bold | XFontStyle.Italic: BaseFont += ",BoldItalic"; break; } } // CID fonts are always embedded 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; }
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); fontDescriptor = new PdfFontDescriptor(document, ttDescriptor); fontOptions = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always); 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(" ", ""); //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 = 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; }
/// <summary> /// This is an external helper function. /// </summary> public static byte[] F74167FFE4044F53B28A4AF049E9EF25(XFont font, XPdfFontOptions options, bool subset) { byte[] data = null; if (subset) { OpenTypeDescriptor descriptor = new OpenTypeDescriptor(font, options); FontData image = descriptor.fontData; CMapInfo cmapInfo = new CMapInfo(descriptor); cmapInfo.AddAnsiChars(); image = image.CreateFontSubSet(cmapInfo.GlyphIndices, false); data = image.Data; } else { FontData fontData = new FontData(font, options); data = fontData.Data; } return(data); }
/// <summary> /// This is an external helper function. /// </summary> public static byte[] F74167FFE4044F53B28A4AF049E9EF25(XFont font, XPdfFontOptions options, bool subset) { byte[] data = null; if (subset) { OpenTypeDescriptor descriptor = new OpenTypeDescriptor(font, options); FontData image = descriptor.fontData; CMapInfo cmapInfo = new CMapInfo(descriptor); cmapInfo.AddAnsiChars(); image = image.CreateFontSubSet(cmapInfo.GlyphIndices, false); data = image.Data; } else { FontData fontData = new FontData(font, options); data = fontData.Data; } return data; }
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; }
public PDFToUnicodeMap(PDFDocument document, CMapInfo cmapInfo) : base(document) => CMapInfo = cmapInfo;
public PdfToUnicodeMap(PdfDocument document, CMapInfo cmapInfo) : base(document) { _cmapInfo = cmapInfo; }
private CMapInfo CreteMapFromDto(CMapDto mapDto) { return(CMapInfo.Create(mapDto.Id, mapDto.Name, mapDto.Width, mapDto.Height)); }
/// <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)FontDescriptorStock.Global.CreateDescriptor(font); fontDescriptor = new PdfFontDescriptor(document, ttDescriptor); fontOptions = font.PdfOptions; Debug.Assert(fontOptions != null); //this.cmapInfo = new CMapInfo(null/*ttDescriptor*/); cmapInfo = new CMapInfo(ttDescriptor); BaseFont = font.Name.Replace(" ", ""); switch (font.Style & (XFontStyle.Bold | XFontStyle.Italic)) { case XFontStyle.Bold: BaseFont += ",Bold"; break; case XFontStyle.Italic: BaseFont += ",Italic"; break; case XFontStyle.Bold | XFontStyle.Italic: BaseFont += ",BoldItalic"; break; } if (fontOptions.FontEmbedding == PdfFontEmbedding.Always) { BaseFont = CreateEmbeddedFontSubsetName(BaseFont); } fontDescriptor.FontName = BaseFont; Debug.Assert(fontOptions.FontEncoding == PdfFontEncoding.WinAnsi); if (!IsSymbolFont) { Encoding = "/WinAnsiEncoding"; } // { //#if true // throw new NotImplementedException("Specifying a font file is not yet supported."); //#else // // Testcode // FileStream stream = new FileStream("WAL____I.AFM", FileAccess.Read); // int length = stream.Length; // byte[] fontProgram = new byte[length]; // PdfDictionary fontStream = new PdfDictionary(this.Document); // this.Document.xrefTable.Add(fontStream); // this.fontDescriptor.Elements[PdfFontDescriptor.Keys.FontFile] = fontStream.XRef; // fontStream.Elements["/Length1"] = new PdfInteger(fontProgram.Length); // if (!this.Document.Options.NoCompression) // { // fontProgram = Filtering.FlateDecode.Encode(fontProgram); // fontStream.Elements["/Filter"] = new PdfName("/FlateDecode"); // } // fontStream.Elements["/Length"] = new PdfInteger(fontProgram.Length); // fontStream.CreateStream(fontProgram); //#endif // } Owner.irefTable.Add(fontDescriptor); Elements[Keys.FontDescriptor] = fontDescriptor.Reference; FontEncoding = font.PdfOptions.FontEncoding; FontEmbedding = font.PdfOptions.FontEmbedding; }