Esempio n. 1
0
        /**
         *  Constructor for the 14 standard fonts.
         *  Creates a font object and adds it to the PDF.
         *
         *  <pre>
         *  Examples:
         *      Font font1 = new Font(pdf, CoreFont.HELVETICA);
         *      Font font2 = new Font(pdf, CoreFont.TIMES_ITALIC);
         *      Font font3 = new Font(pdf, CoreFont.ZAPF_DINGBATS);
         *      ...
         *  </pre>
         *
         *  @param pdf the PDF to add this font to.
         *  @param coreFont the core font. Must be one the names defined in the CoreFont class.
         */
        public Font(PDF pdf, CoreFont coreFont)
        {
            StandardFont font = StandardFont.GetInstance(coreFont);

            this.isCoreFont             = true;
            this.name                   = font.name;
            this.bBoxLLx                = font.bBoxLLx;
            this.bBoxLLy                = font.bBoxLLy;
            this.bBoxURx                = font.bBoxURx;
            this.bBoxURy                = font.bBoxURy;
            this.metrics                = font.metrics;
            this.fontUnderlinePosition  = font.underlinePosition;
            this.fontUnderlineThickness = font.underlineThickness;
            this.fontAscent             = font.bBoxURy;
            this.fontDescent            = font.bBoxLLy;
            SetSize(size);

            pdf.Newobj();
            pdf.Append("<<\n");
            pdf.Append("/Type /Font\n");
            pdf.Append("/Subtype /Type1\n");
            pdf.Append("/BaseFont /");
            pdf.Append(this.name);
            pdf.Append('\n');
            if (!this.name.Equals("Symbol") && !this.name.Equals("ZapfDingbats"))
            {
                pdf.Append("/Encoding /WinAnsiEncoding\n");
            }
            pdf.Append(">>\n");
            pdf.Endobj();
            objNumber = pdf.GetObjNumber();

            pdf.fonts.Add(this);
        }
Esempio n. 2
0
        private void AddCoreFont(PDF pdf, CoreFont coreFont)
        {
            StandardFont instance = StandardFont.GetInstance(coreFont);

            this.name    = instance.name;
            this.bBoxLLx = (float)instance.bBoxLLx;
            this.bBoxLLy = (float)instance.bBoxLLy;
            this.bBoxURx = (float)instance.bBoxURx;
            this.bBoxURy = (float)instance.bBoxURy;
            this.fontUnderlinePosition  = instance.underlinePosition;
            this.fontUnderlineThickness = instance.underlineThickness;
            this.metrics = instance.metrics;
            pdf.Newobj();
            pdf.Append("<<\n");
            pdf.Append("/Type /Font\n");
            pdf.Append("/Subtype /Type1\n");
            pdf.Append("/BaseFont /");
            pdf.Append(this.name);
            pdf.Append('\n');
            if (!this.name.Equals("Symbol") && !this.name.Equals("ZapfDingbats"))
            {
                pdf.Append("/Encoding /WinAnsiEncoding\n");
            }
            pdf.Append(">>\n");
            pdf.Endobj();
            this.objNumber          = pdf.objNumber;
            this.ascent             = this.bBoxURy * this.size / (float)this.unitsPerEm;
            this.descent            = this.bBoxLLy * this.size / (float)this.unitsPerEm;
            this.body_height        = this.ascent - this.descent;
            this.underlineThickness = (float)this.fontUnderlineThickness * this.size / (float)this.unitsPerEm;
            this.underlinePosition  = (float)this.fontUnderlinePosition * this.size / (float)(-(float)this.unitsPerEm) + this.underlineThickness / 2f;
            pdf.fonts.Add(this);
        }
Esempio n. 3
0
        /**
         *  Constructor for the 14 standard fonts.
         *  Creates a font object and adds it to the PDF.
         *
         *  <pre>
         *  Examples:
         *      Font font1 = new Font(pdf, CoreFont.HELVETICA);
         *      Font font2 = new Font(pdf, CoreFont.TIMES_ITALIC);
         *      Font font3 = new Font(pdf, CoreFont.ZAPF_DINGBATS);
         *      ...
         *  </pre>
         *
         *  @param pdf the PDF to add this font to.
         *  @param coreFont the core font. Must be one the names defined in the CoreFont class.
         */
        public Font(PDF pdf, CoreFont coreFont)
        {
            StandardFont font = StandardFont.GetInstance(coreFont);

            this.name    = font.name;
            this.bBoxLLx = font.bBoxLLx;
            this.bBoxLLy = font.bBoxLLy;
            this.bBoxURx = font.bBoxURx;
            this.bBoxURy = font.bBoxURy;
            this.fontUnderlinePosition  = font.underlinePosition;
            this.fontUnderlineThickness = font.underlineThickness;
            this.metrics            = font.metrics;
            this.ascent             = bBoxURy * size / unitsPerEm;
            this.descent            = bBoxLLy * size / unitsPerEm;
            this.body_height        = ascent - descent;
            this.underlineThickness = fontUnderlineThickness * size / unitsPerEm;
            this.underlinePosition  = fontUnderlinePosition * size / -unitsPerEm + underlineThickness / 2.0f;

            pdf.Newobj();
            pdf.Append("<<\n");
            pdf.Append("/Type /Font\n");
            pdf.Append("/Subtype /Type1\n");
            pdf.Append("/BaseFont /");
            pdf.Append(this.name);
            pdf.Append('\n');
            if (!this.name.Equals("Symbol") && !this.name.Equals("ZapfDingbats"))
            {
                pdf.Append("/Encoding /WinAnsiEncoding\n");
            }
            pdf.Append(">>\n");
            pdf.Endobj();
            objNumber = pdf.objNumber;

            pdf.fonts.Add(this);
        }
Esempio n. 4
0
        public Font AddFontResource(CoreFont coreFont, SortedDictionary <Int32, PDFobj> objects)
        {
            Font font = new Font(coreFont);

            font.fontID = font.name.Replace('-', '_').ToUpper();

            PDFobj obj = new PDFobj();

            int maxObjNumber = -1;

            foreach (int number in objects.Keys)
            {
                if (number > maxObjNumber)
                {
                    maxObjNumber = number;
                }
            }
            obj.number = maxObjNumber + 1;

            obj.dict.Add("<<");
            obj.dict.Add("/Type");
            obj.dict.Add("/Font");
            obj.dict.Add("/Subtype");
            obj.dict.Add("/Type1");
            obj.dict.Add("/BaseFont");
            obj.dict.Add("/" + font.name);
            if (!font.name.Equals("Symbol") && !font.name.Equals("ZapfDingbats"))
            {
                obj.dict.Add("/Encoding");
                obj.dict.Add("/WinAnsiEncoding");
            }
            obj.dict.Add(">>");

            objects.Add(obj.number, obj);

            for (int i = 0; i < dict.Count; i++)
            {
                if (dict[i].Equals("/Resources"))
                {
                    String token = dict[++i];
                    if (token.Equals("<<"))                 // Direct resources object
                    {
                        AddFontResource(this, objects, font.fontID, obj.number);
                    }
                    else if (Char.IsDigit(token[0]))        // Indirect resources object
                    {
                        AddFontResource(objects[Int32.Parse(token)], objects, font.fontID, obj.number);
                    }
                }
            }

            return(font);
        }
Esempio n. 5
0
        // Used by PDFobj
        internal Font(CoreFont coreFont)
        {
            StandardFont font = StandardFont.GetInstance(coreFont);

            this.isCoreFont             = true;
            this.name                   = font.name;
            this.bBoxLLx                = font.bBoxLLx;
            this.bBoxLLy                = font.bBoxLLy;
            this.bBoxURx                = font.bBoxURx;
            this.bBoxURy                = font.bBoxURy;
            this.metrics                = font.metrics;
            this.fontUnderlinePosition  = font.underlinePosition;
            this.fontUnderlineThickness = font.underlineThickness;
            this.fontAscent             = font.bBoxURy;
            this.fontDescent            = font.bBoxLLy;
            SetSize(size);
        }
Esempio n. 6
0
        // Used by PDFobj
        internal Font(CoreFont coreFont)
        {
            StandardFont font = StandardFont.GetInstance(coreFont);

            this.name                   = font.name;
            this.bBoxLLx                = font.bBoxLLx;
            this.bBoxLLy                = font.bBoxLLy;
            this.bBoxURx                = font.bBoxURx;
            this.bBoxURy                = font.bBoxURy;
            this.metrics                = font.metrics;
            this.ascent                 = bBoxURy * size / unitsPerEm;
            this.descent                = bBoxLLy * size / unitsPerEm;
            this.body_height            = ascent - descent;
            this.fontUnderlinePosition  = font.underlinePosition;
            this.fontUnderlineThickness = font.underlineThickness;
            this.underlineThickness     = fontUnderlineThickness * size / unitsPerEm;
            this.underlinePosition      = fontUnderlinePosition * size / -unitsPerEm + underlineThickness / 2.0f;
        }
Esempio n. 7
0
        // Constructor for standard fonts
        public Font(PDF pdf, String fontName)
        {
            this.pdf  = pdf;
            this.name = fontName;

            pdf.newobj();
            pdf.Append("<<\n");
            pdf.Append("/Type /Font\n");
            pdf.Append("/Subtype /Type1\n");
            pdf.Append("/BaseFont /");
            pdf.Append(fontName);
            pdf.Append('\n');
            if (fontName.Equals("Symbol") || fontName.Equals("ZapfDingbats"))
            {
                // Use the built-in encoding
            }
            else
            {
                pdf.Append("/Encoding /WinAnsiEncoding\n");
            }
            pdf.Append(">>\n");
            pdf.endobj();
            objNumber = pdf.objNumber;

            CoreFont font = (CoreFont)Activator.CreateInstance(Type.GetType("PDFjet.NET." + name.Replace('-', '_')));

            bBoxLLx     = font.getBBoxLLx();
            bBoxLLy     = font.getBBoxLLy();
            bBoxURx     = font.getBBoxURx();
            bBoxURy     = font.getBBoxURy();
            metrics     = font.getMetrics();
            ascent      = bBoxURy * size / unitsPerEm;
            descent     = bBoxLLy * size / unitsPerEm;
            body_height = ascent - descent;

            fontUnderlineThickness = font.getUnderlineThickness();
            fontUnderlinePosition  = font.getUnderlinePosition();

            underlineThickness = fontUnderlineThickness * size / unitsPerEm;
            underlinePosition  = fontUnderlinePosition * size / -unitsPerEm + underlineThickness / 2.0;

            pdf.fonts.Add(this);
        }
Esempio n. 8
0
 public Font(PDF pdf, CoreFont coreFont)
 {
     this.AddCoreFont(pdf, coreFont);
 }
Esempio n. 9
0
        internal static StandardFont GetInstance(CoreFont coreFont)
        {
            StandardFont font = new StandardFont();

            switch (coreFont)
            {
            case CoreFont.COURIER:
                font.name               = Courier.name;
                font.bBoxLLx            = Courier.bBoxLLx;
                font.bBoxLLy            = Courier.bBoxLLy;
                font.bBoxURx            = Courier.bBoxURx;
                font.bBoxURy            = Courier.bBoxURy;
                font.underlinePosition  = Courier.underlinePosition;
                font.underlineThickness = Courier.underlineThickness;
                font.metrics            = Courier.metrics;
                break;

            case CoreFont.COURIER_BOLD:
                font.name               = Courier_Bold.name;
                font.bBoxLLx            = Courier_Bold.bBoxLLx;
                font.bBoxLLy            = Courier_Bold.bBoxLLy;
                font.bBoxURx            = Courier_Bold.bBoxURx;
                font.bBoxURy            = Courier_Bold.bBoxURy;
                font.underlinePosition  = Courier_Bold.underlinePosition;
                font.underlineThickness = Courier_Bold.underlineThickness;
                font.metrics            = Courier_Bold.metrics;
                break;

            case CoreFont.COURIER_OBLIQUE:
                font.name               = Courier_Oblique.name;
                font.bBoxLLx            = Courier_Oblique.bBoxLLx;
                font.bBoxLLy            = Courier_Oblique.bBoxLLy;
                font.bBoxURx            = Courier_Oblique.bBoxURx;
                font.bBoxURy            = Courier_Oblique.bBoxURy;
                font.underlinePosition  = Courier_Oblique.underlinePosition;
                font.underlineThickness = Courier_Oblique.underlineThickness;
                font.metrics            = Courier_Oblique.metrics;
                break;

            case CoreFont.COURIER_BOLD_OBLIQUE:
                font.name               = Courier_BoldOblique.name;
                font.bBoxLLx            = Courier_BoldOblique.bBoxLLx;
                font.bBoxLLy            = Courier_BoldOblique.bBoxLLy;
                font.bBoxURx            = Courier_BoldOblique.bBoxURx;
                font.bBoxURy            = Courier_BoldOblique.bBoxURy;
                font.underlinePosition  = Courier_BoldOblique.underlinePosition;
                font.underlineThickness = Courier_BoldOblique.underlineThickness;
                font.metrics            = Courier_BoldOblique.metrics;
                break;

            case CoreFont.HELVETICA:
                font.name               = Helvetica.name;
                font.bBoxLLx            = Helvetica.bBoxLLx;
                font.bBoxLLy            = Helvetica.bBoxLLy;
                font.bBoxURx            = Helvetica.bBoxURx;
                font.bBoxURy            = Helvetica.bBoxURy;
                font.underlinePosition  = Helvetica.underlinePosition;
                font.underlineThickness = Helvetica.underlineThickness;
                font.metrics            = Helvetica.metrics;
                break;

            case CoreFont.HELVETICA_BOLD:
                font.name               = Helvetica_Bold.name;
                font.bBoxLLx            = Helvetica_Bold.bBoxLLx;
                font.bBoxLLy            = Helvetica_Bold.bBoxLLy;
                font.bBoxURx            = Helvetica_Bold.bBoxURx;
                font.bBoxURy            = Helvetica_Bold.bBoxURy;
                font.underlinePosition  = Helvetica_Bold.underlinePosition;
                font.underlineThickness = Helvetica_Bold.underlineThickness;
                font.metrics            = Helvetica_Bold.metrics;
                break;

            case CoreFont.HELVETICA_OBLIQUE:
                font.name               = Helvetica_Oblique.name;
                font.bBoxLLx            = Helvetica_Oblique.bBoxLLx;
                font.bBoxLLy            = Helvetica_Oblique.bBoxLLy;
                font.bBoxURx            = Helvetica_Oblique.bBoxURx;
                font.bBoxURy            = Helvetica_Oblique.bBoxURy;
                font.underlinePosition  = Helvetica_Oblique.underlinePosition;
                font.underlineThickness = Helvetica_Oblique.underlineThickness;
                font.metrics            = Helvetica_Oblique.metrics;
                break;

            case CoreFont.HELVETICA_BOLD_OBLIQUE:
                font.name               = Helvetica_BoldOblique.name;
                font.bBoxLLx            = Helvetica_BoldOblique.bBoxLLx;
                font.bBoxLLy            = Helvetica_BoldOblique.bBoxLLy;
                font.bBoxURx            = Helvetica_BoldOblique.bBoxURx;
                font.bBoxURy            = Helvetica_BoldOblique.bBoxURy;
                font.underlinePosition  = Helvetica_BoldOblique.underlinePosition;
                font.underlineThickness = Helvetica_BoldOblique.underlineThickness;
                font.metrics            = Helvetica_BoldOblique.metrics;
                break;

            case CoreFont.TIMES_ROMAN:
                font.name               = Times_Roman.name;
                font.bBoxLLx            = Times_Roman.bBoxLLx;
                font.bBoxLLy            = Times_Roman.bBoxLLy;
                font.bBoxURx            = Times_Roman.bBoxURx;
                font.bBoxURy            = Times_Roman.bBoxURy;
                font.underlinePosition  = Times_Roman.underlinePosition;
                font.underlineThickness = Times_Roman.underlineThickness;
                font.metrics            = Times_Roman.metrics;
                break;

            case CoreFont.TIMES_BOLD:
                font.name               = Times_Bold.name;
                font.bBoxLLx            = Times_Bold.bBoxLLx;
                font.bBoxLLy            = Times_Bold.bBoxLLy;
                font.bBoxURx            = Times_Bold.bBoxURx;
                font.bBoxURy            = Times_Bold.bBoxURy;
                font.underlinePosition  = Times_Bold.underlinePosition;
                font.underlineThickness = Times_Bold.underlineThickness;
                font.metrics            = Times_Bold.metrics;
                break;

            case CoreFont.TIMES_ITALIC:
                font.name               = Times_Italic.name;
                font.bBoxLLx            = Times_Italic.bBoxLLx;
                font.bBoxLLy            = Times_Italic.bBoxLLy;
                font.bBoxURx            = Times_Italic.bBoxURx;
                font.bBoxURy            = Times_Italic.bBoxURy;
                font.underlinePosition  = Times_Italic.underlinePosition;
                font.underlineThickness = Times_Italic.underlineThickness;
                font.metrics            = Times_Italic.metrics;
                break;

            case CoreFont.TIMES_BOLD_ITALIC:
                font.name               = Times_BoldItalic.name;
                font.bBoxLLx            = Times_BoldItalic.bBoxLLx;
                font.bBoxLLy            = Times_BoldItalic.bBoxLLy;
                font.bBoxURx            = Times_BoldItalic.bBoxURx;
                font.bBoxURy            = Times_BoldItalic.bBoxURy;
                font.underlinePosition  = Times_BoldItalic.underlinePosition;
                font.underlineThickness = Times_BoldItalic.underlineThickness;
                font.metrics            = Times_BoldItalic.metrics;
                break;

            case CoreFont.SYMBOL:
                font.name               = Symbol.name;
                font.bBoxLLx            = Symbol.bBoxLLx;
                font.bBoxLLy            = Symbol.bBoxLLy;
                font.bBoxURx            = Symbol.bBoxURx;
                font.bBoxURy            = Symbol.bBoxURy;
                font.underlinePosition  = Symbol.underlinePosition;
                font.underlineThickness = Symbol.underlineThickness;
                font.metrics            = Symbol.metrics;
                break;

            case CoreFont.ZAPF_DINGBATS:
                font.name               = ZapfDingbats.name;
                font.bBoxLLx            = ZapfDingbats.bBoxLLx;
                font.bBoxLLy            = ZapfDingbats.bBoxLLy;
                font.bBoxURx            = ZapfDingbats.bBoxURx;
                font.bBoxURy            = ZapfDingbats.bBoxURy;
                font.underlinePosition  = ZapfDingbats.underlinePosition;
                font.underlineThickness = ZapfDingbats.underlineThickness;
                font.metrics            = ZapfDingbats.metrics;
                break;
            }

            return(font);
        }
Esempio n. 10
0
        internal static StandardFont GetInstance(CoreFont coreFont)
        {
            StandardFont font = new StandardFont();
            switch (coreFont) {
            case CoreFont.COURIER:
            font.name = Courier.name;
            font.bBoxLLx = Courier.bBoxLLx;
            font.bBoxLLy = Courier.bBoxLLy;
            font.bBoxURx = Courier.bBoxURx;
            font.bBoxURy = Courier.bBoxURy;
            font.underlinePosition = Courier.underlinePosition;
            font.underlineThickness = Courier.underlineThickness;
            font.metrics = Courier.metrics;
            break;

            case CoreFont.COURIER_BOLD:
            font.name  = Courier_Bold.name;
            font.bBoxLLx = Courier_Bold.bBoxLLx;
            font.bBoxLLy = Courier_Bold.bBoxLLy;
            font.bBoxURx = Courier_Bold.bBoxURx;
            font.bBoxURy = Courier_Bold.bBoxURy;
            font.underlinePosition = Courier_Bold.underlinePosition;
            font.underlineThickness = Courier_Bold.underlineThickness;
            font.metrics = Courier_Bold.metrics;
            break;

            case CoreFont.COURIER_OBLIQUE:
            font.name  = Courier_Oblique.name;
            font.bBoxLLx = Courier_Oblique.bBoxLLx;
            font.bBoxLLy = Courier_Oblique.bBoxLLy;
            font.bBoxURx = Courier_Oblique.bBoxURx;
            font.bBoxURy = Courier_Oblique.bBoxURy;
            font.underlinePosition = Courier_Oblique.underlinePosition;
            font.underlineThickness = Courier_Oblique.underlineThickness;
            font.metrics = Courier_Oblique.metrics;
            break;

            case CoreFont.COURIER_BOLD_OBLIQUE:
            font.name  = Courier_BoldOblique.name;
            font.bBoxLLx = Courier_BoldOblique.bBoxLLx;
            font.bBoxLLy = Courier_BoldOblique.bBoxLLy;
            font.bBoxURx = Courier_BoldOblique.bBoxURx;
            font.bBoxURy = Courier_BoldOblique.bBoxURy;
            font.underlinePosition = Courier_BoldOblique.underlinePosition;
            font.underlineThickness = Courier_BoldOblique.underlineThickness;
            font.metrics = Courier_BoldOblique.metrics;
            break;

            case CoreFont.HELVETICA:
            font.name  = Helvetica.name;
            font.bBoxLLx = Helvetica.bBoxLLx;
            font.bBoxLLy = Helvetica.bBoxLLy;
            font.bBoxURx = Helvetica.bBoxURx;
            font.bBoxURy = Helvetica.bBoxURy;
            font.underlinePosition = Helvetica.underlinePosition;
            font.underlineThickness = Helvetica.underlineThickness;
            font.metrics = Helvetica.metrics;
            break;

            case CoreFont.HELVETICA_BOLD:
            font.name = Helvetica_Bold.name;
            font.bBoxLLx = Helvetica_Bold.bBoxLLx;
            font.bBoxLLy = Helvetica_Bold.bBoxLLy;
            font.bBoxURx = Helvetica_Bold.bBoxURx;
            font.bBoxURy = Helvetica_Bold.bBoxURy;
            font.underlinePosition = Helvetica_Bold.underlinePosition;
            font.underlineThickness = Helvetica_Bold.underlineThickness;
            font.metrics = Helvetica_Bold.metrics;
            break;

            case CoreFont.HELVETICA_OBLIQUE:
            font.name = Helvetica_Oblique.name;
            font.bBoxLLx = Helvetica_Oblique.bBoxLLx;
            font.bBoxLLy = Helvetica_Oblique.bBoxLLy;
            font.bBoxURx = Helvetica_Oblique.bBoxURx;
            font.bBoxURy = Helvetica_Oblique.bBoxURy;
            font.underlinePosition = Helvetica_Oblique.underlinePosition;
            font.underlineThickness = Helvetica_Oblique.underlineThickness;
            font.metrics = Helvetica_Oblique.metrics;
            break;

            case CoreFont.HELVETICA_BOLD_OBLIQUE:
            font.name = Helvetica_BoldOblique.name;
            font.bBoxLLx = Helvetica_BoldOblique.bBoxLLx;
            font.bBoxLLy = Helvetica_BoldOblique.bBoxLLy;
            font.bBoxURx = Helvetica_BoldOblique.bBoxURx;
            font.bBoxURy = Helvetica_BoldOblique.bBoxURy;
            font.underlinePosition = Helvetica_BoldOblique.underlinePosition;
            font.underlineThickness = Helvetica_BoldOblique.underlineThickness;
            font.metrics = Helvetica_BoldOblique.metrics;
            break;

            case CoreFont.TIMES_ROMAN:
            font.name = Times_Roman.name;
            font.bBoxLLx = Times_Roman.bBoxLLx;
            font.bBoxLLy = Times_Roman.bBoxLLy;
            font.bBoxURx = Times_Roman.bBoxURx;
            font.bBoxURy = Times_Roman.bBoxURy;
            font.underlinePosition = Times_Roman.underlinePosition;
            font.underlineThickness = Times_Roman.underlineThickness;
            font.metrics = Times_Roman.metrics;
            break;

            case CoreFont.TIMES_BOLD:
            font.name = Times_Bold.name;
            font.bBoxLLx = Times_Bold.bBoxLLx;
            font.bBoxLLy = Times_Bold.bBoxLLy;
            font.bBoxURx = Times_Bold.bBoxURx;
            font.bBoxURy = Times_Bold.bBoxURy;
            font.underlinePosition = Times_Bold.underlinePosition;
            font.underlineThickness = Times_Bold.underlineThickness;
            font.metrics = Times_Bold.metrics;
            break;

            case CoreFont.TIMES_ITALIC:
            font.name = Times_Italic.name;
            font.bBoxLLx = Times_Italic.bBoxLLx;
            font.bBoxLLy = Times_Italic.bBoxLLy;
            font.bBoxURx = Times_Italic.bBoxURx;
            font.bBoxURy = Times_Italic.bBoxURy;
            font.underlinePosition = Times_Italic.underlinePosition;
            font.underlineThickness = Times_Italic.underlineThickness;
            font.metrics = Times_Italic.metrics;
            break;

            case CoreFont.TIMES_BOLD_ITALIC:
            font.name = Times_BoldItalic.name;
            font.bBoxLLx = Times_BoldItalic.bBoxLLx;
            font.bBoxLLy = Times_BoldItalic.bBoxLLy;
            font.bBoxURx = Times_BoldItalic.bBoxURx;
            font.bBoxURy = Times_BoldItalic.bBoxURy;
            font.underlinePosition = Times_BoldItalic.underlinePosition;
            font.underlineThickness = Times_BoldItalic.underlineThickness;
            font.metrics = Times_BoldItalic.metrics;
            break;

            case CoreFont.SYMBOL:
            font.name = Symbol.name;
            font.bBoxLLx = Symbol.bBoxLLx;
            font.bBoxLLy = Symbol.bBoxLLy;
            font.bBoxURx = Symbol.bBoxURx;
            font.bBoxURy = Symbol.bBoxURy;
            font.underlinePosition = Symbol.underlinePosition;
            font.underlineThickness = Symbol.underlineThickness;
            font.metrics = Symbol.metrics;
            break;

            case CoreFont.ZAPF_DINGBATS:
            font.name = ZapfDingbats.name;
            font.bBoxLLx = ZapfDingbats.bBoxLLx;
            font.bBoxLLy = ZapfDingbats.bBoxLLy;
            font.bBoxURx = ZapfDingbats.bBoxURx;
            font.bBoxURy = ZapfDingbats.bBoxURy;
            font.underlinePosition = ZapfDingbats.underlinePosition;
            font.underlineThickness = ZapfDingbats.underlineThickness;
            font.metrics = ZapfDingbats.metrics;
            break;
            }

            return font;
        }
Esempio n. 11
0
 // Used by PDFobj
 internal Font(CoreFont coreFont)
 {
     StandardFont font = StandardFont.GetInstance(coreFont);
     this.name = font.name;
     this.bBoxLLx = font.bBoxLLx;
     this.bBoxLLy = font.bBoxLLy;
     this.bBoxURx = font.bBoxURx;
     this.bBoxURy = font.bBoxURy;
     this.metrics = font.metrics;
     this.ascent = bBoxURy * size / unitsPerEm;
     this.descent = bBoxLLy * size / unitsPerEm;
     this.body_height = ascent - descent;
     this.fontUnderlinePosition = font.underlinePosition;
     this.fontUnderlineThickness = font.underlineThickness;
     this.underlineThickness = fontUnderlineThickness * size / unitsPerEm;
     this.underlinePosition = fontUnderlinePosition * size / -unitsPerEm + underlineThickness / 2.0f;
 }
Esempio n. 12
0
        /**
         *  Constructor for the 14 standard fonts.
         *  Creates a font object and adds it to the PDF.
         *
         *  <pre>
         *  Examples:
         *      Font font1 = new Font(pdf, CoreFont.HELVETICA);
         *      Font font2 = new Font(pdf, CoreFont.TIMES_ITALIC);
         *      Font font3 = new Font(pdf, CoreFont.ZAPF_DINGBATS);
         *      ...
         *  </pre>
         *
         *  @param pdf the PDF to add this font to.
         *  @param coreFont the core font. Must be one the names defined in the CoreFont class.
         */
        public Font(PDF pdf, CoreFont coreFont)
        {
            StandardFont font = StandardFont.GetInstance(coreFont);
            this.name = font.name;
            this.bBoxLLx = font.bBoxLLx;
            this.bBoxLLy = font.bBoxLLy;
            this.bBoxURx = font.bBoxURx;
            this.bBoxURy = font.bBoxURy;
            this.fontUnderlinePosition = font.underlinePosition;
            this.fontUnderlineThickness = font.underlineThickness;
            this.metrics = font.metrics;
            this.ascent = bBoxURy * size / unitsPerEm;
            this.descent = bBoxLLy * size / unitsPerEm;
            this.body_height = ascent - descent;
            this.underlineThickness = fontUnderlineThickness * size / unitsPerEm;
            this.underlinePosition = fontUnderlinePosition * size / -unitsPerEm + underlineThickness / 2.0f;

            pdf.Newobj();
            pdf.Append("<<\n");
            pdf.Append("/Type /Font\n");
            pdf.Append("/Subtype /Type1\n");
            pdf.Append("/BaseFont /");
            pdf.Append(this.name);
            pdf.Append('\n');
            if (!this.name.Equals("Symbol") && !this.name.Equals("ZapfDingbats")) {
            pdf.Append("/Encoding /WinAnsiEncoding\n");
            }
            pdf.Append(">>\n");
            pdf.Endobj();
            objNumber = pdf.objNumber;

            pdf.fonts.Add(this);
        }
Esempio n. 13
0
        public Font AddFontResource(CoreFont coreFont, SortedDictionary<Int32, PDFobj> objects)
        {
            Font font = new Font(coreFont);
            font.fontID = font.name.Replace('-', '_').ToUpper();

            PDFobj obj = new PDFobj();

            int maxObjNumber = -1;
            foreach (int number in objects.Keys) {
            if (number > maxObjNumber) { maxObjNumber = number; }
            }
            obj.number = maxObjNumber + 1;

            obj.dict.Add("<<");
            obj.dict.Add("/Type");
            obj.dict.Add("/Font");
            obj.dict.Add("/Subtype");
            obj.dict.Add("/Type1");
            obj.dict.Add("/BaseFont");
            obj.dict.Add("/" + font.name);
            if (!font.name.Equals("Symbol") && !font.name.Equals("ZapfDingbats")) {
            obj.dict.Add("/Encoding");
            obj.dict.Add("/WinAnsiEncoding");
            }
            obj.dict.Add(">>");

            objects.Add(obj.number, obj);

            for (int i = 0; i < dict.Count; i++) {
            if (dict[i].Equals("/Resources")) {
                String token = dict[++i];
                if (token.Equals("<<")) {                   // Direct resources object
                    AddFontResource(this, objects, font.fontID, obj.number);
                }
                else if (Char.IsDigit(token[0])) {          // Indirect resources object
                    AddFontResource(objects[Int32.Parse(token)], objects, font.fontID, obj.number);
                }
            }
            }

            return font;
        }