コード例 #1
0
        private int GetInfo(String character, PdfAcroForm form, String name)
        {
            PdfFormField field       = form.GetField(name);
            PdfFont      font        = field.GetFont();
            FontMetrics  fontMetrics = font.GetFontProgram().GetFontMetrics();
            float        fontSize    = field.GetFontSize();

            if (fontSize == 0)
            {
                return(1000);
            }

            Rectangle rectangle = field.GetWidgets()[0].GetRectangle().ToRectangle();

            // Factor here is a leading value. We calculate it by subtracting lower left corner value from
            // the upper right corner value of the glyph bounding box
            float factor = (fontMetrics.GetBbox()[3] - fontMetrics.GetBbox()[1]) / 1000f;

            int rows    = (int)Math.Round(rectangle.GetHeight() / (fontSize * factor) + 0.5f);
            int columns = (int)Math.Round(rectangle.GetWidth() / font.GetWidth(character, fontSize) + 0.5f);

            return(rows * columns);
        }
コード例 #2
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);
        }
コード例 #3
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();

            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);
        }