/// <summary> /// Generates the font descriptor for this font or /// <see langword="null"/> /// if it is one of the 14 built in fonts. /// </summary> /// <returns> /// the PdfDictionary containing the font descriptor or /// <see langword="null"/> /// . /// </returns> protected internal override PdfDictionary GetFontDescriptor(String fontName) { FontMetrics fontMetrics = fontProgram.GetFontMetrics(); FontNames fontNames = fontProgram.GetFontNames(); PdfDictionary fontDescriptor = new PdfDictionary(); MakeObjectIndirect(fontDescriptor); fontDescriptor.Put(PdfName.Type, PdfName.FontDescriptor); fontDescriptor.Put(PdfName.FontName, new PdfName(fontName)); fontDescriptor.Put(PdfName.Ascent, new PdfNumber(fontMetrics.GetTypoAscender())); fontDescriptor.Put(PdfName.CapHeight, new PdfNumber(fontMetrics.GetCapHeight())); fontDescriptor.Put(PdfName.Descent, new PdfNumber(fontMetrics.GetTypoDescender())); fontDescriptor.Put(PdfName.FontBBox, new PdfArray(ArrayUtil.CloneArray(fontMetrics.GetBbox()))); fontDescriptor.Put(PdfName.ItalicAngle, new PdfNumber(fontMetrics.GetItalicAngle())); fontDescriptor.Put(PdfName.StemV, new PdfNumber(fontMetrics.GetStemV())); if (fontMetrics.GetXHeight() > 0) { fontDescriptor.Put(PdfName.XHeight, new PdfNumber(fontMetrics.GetXHeight())); } if (fontMetrics.GetStemH() > 0) { fontDescriptor.Put(PdfName.StemH, new PdfNumber(fontMetrics.GetStemH())); } if (fontNames.GetFontWeight() > 0) { fontDescriptor.Put(PdfName.FontWeight, new PdfNumber(fontNames.GetFontWeight())); } if (fontNames.GetFamilyName() != null && fontNames.GetFamilyName().Length > 0 && fontNames.GetFamilyName() [0].Length >= 4) { fontDescriptor.Put(PdfName.FontFamily, new PdfString(fontNames.GetFamilyName()[0][3])); } //add font stream and flush it immediately AddFontStream(fontDescriptor); int flags = fontProgram.GetPdfFontFlags(); if (fontProgram.IsFontSpecific() != fontEncoding.IsFontSpecific()) { flags &= ~(4 | 32); // reset both flags flags |= fontEncoding.IsFontSpecific() ? 4 : 32; } // set based on font encoding fontDescriptor.Put(PdfName.Flags, new PdfNumber(flags)); return(fontDescriptor); }
/// <summary> /// Generates the font descriptor for this font or /// <see langword="null"/> /// if it is one of the 14 built in fonts. /// </summary> /// <returns> /// the PdfDictionary containing the font descriptor or /// <see langword="null"/> /// . /// </returns> protected internal override PdfDictionary GetFontDescriptor(String fontName) { FontMetrics fontMetrics = fontProgram.GetFontMetrics(); FontNames fontNames = fontProgram.GetFontNames(); PdfDictionary fontDescriptor = new PdfDictionary(); MarkObjectAsIndirect(fontDescriptor); fontDescriptor.Put(PdfName.Type, PdfName.FontDescriptor); fontDescriptor.Put(PdfName.FontName, new PdfName(fontName)); fontDescriptor.Put(PdfName.Ascent, new PdfNumber(fontMetrics.GetTypoAscender())); fontDescriptor.Put(PdfName.CapHeight, new PdfNumber(fontMetrics.GetCapHeight())); fontDescriptor.Put(PdfName.Descent, new PdfNumber(fontMetrics.GetTypoDescender())); fontDescriptor.Put(PdfName.FontBBox, new PdfArray(ArrayUtil.CloneArray(fontMetrics.GetBbox()))); fontDescriptor.Put(PdfName.ItalicAngle, new PdfNumber(fontMetrics.GetItalicAngle())); fontDescriptor.Put(PdfName.StemV, new PdfNumber(fontMetrics.GetStemV())); if (fontMetrics.GetXHeight() > 0) { fontDescriptor.Put(PdfName.XHeight, new PdfNumber(fontMetrics.GetXHeight())); } if (fontMetrics.GetStemH() > 0) { fontDescriptor.Put(PdfName.StemH, new PdfNumber(fontMetrics.GetStemH())); } if (fontNames.GetFontWeight() > 0) { fontDescriptor.Put(PdfName.FontWeight, new PdfNumber(fontNames.GetFontWeight())); } if (fontNames.GetFamilyName() != null && fontNames.GetFamilyName().Length > 0 && fontNames.GetFamilyName() [0].Length >= 4) { fontDescriptor.Put(PdfName.FontFamily, new PdfString(fontNames.GetFamilyName()[0][3])); } AddFontStream(fontDescriptor); int flags = fontProgram.GetPdfFontFlags(); if (!fontEncoding.IsFontSpecific()) { flags &= ~64; } fontDescriptor.Put(PdfName.Flags, new PdfNumber(flags)); return(fontDescriptor); }
protected internal override PdfDictionary GetFontDescriptor(String fontName) { if (fontName != null && fontName.Length > 0) { PdfDictionary fontDescriptor = new PdfDictionary(); MakeObjectIndirect(fontDescriptor); fontDescriptor.Put(PdfName.Type, PdfName.FontDescriptor); FontMetrics fontMetrics = fontProgram.GetFontMetrics(); fontDescriptor.Put(PdfName.CapHeight, new PdfNumber(fontMetrics.GetCapHeight())); fontDescriptor.Put(PdfName.ItalicAngle, new PdfNumber(fontMetrics.GetItalicAngle())); FontNames fontNames = fontProgram.GetFontNames(); fontDescriptor.Put(PdfName.FontWeight, new PdfNumber(fontNames.GetFontWeight())); fontDescriptor.Put(PdfName.FontName, new PdfName(fontName)); if (fontNames.GetFamilyName() != null && fontNames.GetFamilyName().Length > 0 && fontNames.GetFamilyName() [0].Length >= 4) { fontDescriptor.Put(PdfName.FontFamily, new PdfString(fontNames.GetFamilyName()[0][3])); } int flags = fontProgram.GetPdfFontFlags(); // reset both flags flags &= ~(FontDescriptorFlags.Symbolic | FontDescriptorFlags.Nonsymbolic); // set fontSpecific based on font encoding flags |= fontEncoding.IsFontSpecific() ? FontDescriptorFlags.Symbolic : FontDescriptorFlags.Nonsymbolic; fontDescriptor.Put(PdfName.Flags, new PdfNumber(flags)); return(fontDescriptor); } else { if (GetPdfObject().GetIndirectReference() != null && GetPdfObject().GetIndirectReference().GetDocument().IsTagged ()) { ILog logger = LogManager.GetLogger(typeof(iText.Kernel.Font.PdfType3Font)); logger.Warn(iText.IO.LogMessageConstant.TYPE3_FONT_ISSUE_TAGGED_PDF); } } return(null); }