Example #1
0
        /// <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);
        }