Esempio n. 1
0
 /**
 * Gets a chunk with a symbol character.
 * @param c a character that has to be changed into a symbol
 * @param font Font if there is no SYMBOL character corresponding with c
 * @return a SYMBOL version of a character
 */
 public static Chunk Get(char c, Font font)
 {
     char greek = SpecialSymbol.GetCorrespondingSymbol(c);
     if (greek == ' ') {
         return new Chunk(c.ToString(), font);
     }
     Font symbol = new Font(Font.SYMBOL, font.Size, font.Style, font.Color);
     return new Chunk(greek.ToString(), symbol);
 }
Esempio n. 2
0
 /**
 * Adds a <CODE>Font</CODE> to be searched for valid characters.
 * @param font the <CODE>Font</CODE>
 */
 public void AddFont(Font font)
 {
     if (font.BaseFont != null) {
         fonts.Add(font);
         return;
     }
     BaseFont bf = font.GetCalculatedBaseFont(true);
     Font f2 = new Font(bf, font.Size, font.CalculatedStyle, font.Color);
     fonts.Add(f2);
 }
Esempio n. 3
0
 /// <summary>
 /// Constructs an Anchor with a certain leading,
 /// a certain string and a certain Font.
 /// </summary>
 /// <param name="leading">the leading</param>
 /// <param name="str">a string</param>
 /// <param name="font">a Font</param>
 public Anchor(float leading, string str, Font font)
     : base(leading, str, font)
 {
 }
Esempio n. 4
0
 /// <summary>
 /// Constructs an Anchor with a certain string
 /// and a certain Font.
 /// </summary>
 /// <param name="str">a string</param>
 /// <param name="font">a Font</param>
 public Anchor(string str, Font font)
     : base(str, font)
 {
 }
Esempio n. 5
0
 /// <summary>
 /// Constructs a Phrase with a certain string and a certain Font.
 /// </summary>
 /// <param name="str">a string</param>
 /// <param name="font">a Font</param>
 public Phrase(string str, Font font) : this(float.NaN, str, font)
 {
 }
Esempio n. 6
0
 /// <summary>
 /// Constructs a Paragraph with a certain string
 /// and a certain Font.
 /// </summary>
 /// <param name="str">a string</param>
 /// <param name="font">a Font</param>
 public Paragraph(string str, Font font)
     : base(str, font)
 {
 }
Esempio n. 7
0
 /// <summary>
 /// Constructs a chunk of text with a certain content and a certain Font.
 /// </summary>
 /// <param name="content">the content</param>
 /// <param name="font">the font</param>
 public Chunk(string content, Font font)
 {
     this.content = new StringBuilder(content);
     this.font = font;
 }
Esempio n. 8
0
 // constructors
 /// <summary>
 /// Empty constructor.
 /// </summary>
 /// <overloads>
 /// Has six overloads.
 /// </overloads>
 public Chunk()
 {
     this.content = new StringBuilder();
     this.font = new Font();
 }
Esempio n. 9
0
 /// <summary>
 /// Replaces the attributes that are equal to null with
 /// the attributes of a given font.
 /// </summary>
 /// <param name="font">the font of a bigger element class</param>
 /// <returns>a Font</returns>
 public virtual Font Difference(Font font)
 {
     if (font == null) return this;
     // size
     float dSize = font.size;
     if (dSize == UNDEFINED) {
         dSize = this.size;
     }
     // style
     int dStyle = UNDEFINED;
     int style1 = this.Style;
     int style2 = font.Style;
     if (style1 != UNDEFINED || style2 != UNDEFINED) {
         if (style1 == UNDEFINED) style1 = 0;
         if (style2 == UNDEFINED) style2 = 0;
         dStyle = style1 | style2;
     }
     // color
     object dColor = (Color)font.Color;
     if (dColor == null) {
         dColor = this.Color;
     }
     // family
     if (font.baseFont != null) {
         return new Font(font.BaseFont, dSize, dStyle, (Color)dColor);
     }
     if (font.Family != UNDEFINED) {
         return new Font(font.Family, dSize, dStyle, (Color)dColor);
     }
     if (this.baseFont != null) {
         if (dStyle == style1) {
             return new Font(this.BaseFont, dSize, dStyle, (Color)dColor);
         }
         else {
             return FontFactory.GetFont(this.Familyname, dSize, dStyle, (Color)dColor);
         }
     }
     return new Font(this.Family, dSize, dStyle, (Color)dColor);
 }
Esempio n. 10
0
 /// <summary>
 /// Constructs a Paragraph with a certain leading, string
 /// and Font.
 /// </summary>
 /// <param name="leading">the leading</param>
 /// <param name="str">a string</param>
 /// <param name="font">a Font</param>
 public Paragraph(float leading, string str, Font font) : base(leading, str, font)
 {
 }
Esempio n. 11
0
 /// <summary>
 /// Constructs a Paragraph with a certain string
 /// and a certain Font.
 /// </summary>
 /// <param name="str">a string</param>
 /// <param name="font">a Font</param>
 public Paragraph(string str, Font font) : base(str, font)
 {
 }
Esempio n. 12
0
 /**
 * Constructs a RtfField for a RtfDocument. This is not very usefull,
 * since the RtfField by itself does not do anything. Use one of the
 * subclasses instead.
 *
 * @param doc The RtfDocument this RtfField belongs to.
 * @param font The Font this RtfField should use
 */
 protected RtfField(RtfDocument doc, Font font)
     : base("", font)
 {
     this.document = doc;
     this.font = new ST.RtfFont(this.document, font);
 }
Esempio n. 13
0
 /// <summary>
 /// Constructs a Phrase with a certain Chunk.
 /// </summary>
 /// <param name="chunk">a Chunk</param>
 public Phrase(Chunk chunk)
 {
     base.Add(chunk);
     font        = chunk.Font;
     hyphenation = chunk.GetHyphenation();
 }
Esempio n. 14
0
 /// <summary>
 /// Constructs a Phrase with a certain leading.
 /// </summary>
 /// <param name="leading">the leading</param>
 public Phrase(float leading)
 {
     this.leading = leading;
     font         = new Font();
 }
Esempio n. 15
0
 /**
 * Gets a chunk with a symbol character.
 * @param e a symbol value (see Entities class: alfa is greek alfa,...)
 * @param font the font if the symbol isn't found (otherwise Font.SYMBOL)
 * @return a Chunk
 */
 public static Chunk Get(String e, Font font)
 {
     char s = GetCorrespondingSymbol(e);
     if (s == '\0') {
         try {
             return new Chunk("" + (char)int.Parse(e), font);
         }
         catch (Exception) {
             return new Chunk(e, font);
         }
     }
     Font symbol = new Font(Font.SYMBOL, font.Size, font.Style, font.Color);
     return new Chunk(s.ToString(), symbol);
 }
Esempio n. 16
0
 // constructors
 /**
 * Copy constructor of a Font
 * @param other the font that has to be copied
 */
 public Font(Font other)
 {
     this.color = other.color;
     this.family = other.family;
     this.size = other.size;
     this.style = other.style;
     this.baseFont = other.baseFont;
 }
Esempio n. 17
0
 /**
 * Constructs a RtfTotalPageNumber object with a specific font.
 *
 * @param doc The RtfDocument this RtfTotalPageNumber belongs to
 * @param font The Font to use
 */
 public RtfTotalPageNumber(RtfDocument doc, Font font)
     : base(doc, font)
 {
 }
Esempio n. 18
0
 /**
 * set the bullet font
 * @param f
 */
 public void SetBulletFont(Font f)
 {
     this.fontBullet = new RtfFont(document, f);
 }
Esempio n. 19
0
 /**
 * Constructs a RtfTotalPageNumber with a specified Font. This can be added anywhere
 * to add a total number of pages field.
 * @param font
 */
 public RtfTotalPageNumber(Font font)
     : base(null, font)
 {
 }
Esempio n. 20
0
 /**
 * A <CODE>Chunk</CODE> copy constructor.
 * @param ck the <CODE>Chunk</CODE> to be copied
 */
 public Chunk(Chunk ck)
 {
     if (ck.content != null) {
         content = new StringBuilder(ck.content.ToString());
     }
     if (ck.font != null) {
         font = new Font(ck.font);
     }
 }
 /**
 * Fits the text to some rectangle adjusting the font size as needed.
 * @param font the font to use
 * @param text the text
 * @param rect the rectangle where the text must fit
 * @param maxFontSize the maximum font size
 * @param runDirection the run direction
 * @return the calculated font size that makes the text fit
 */
 public static float FitText(Font font, String text, Rectangle rect, float maxFontSize, int runDirection)
 {
     ColumnText ct = null;
     int status = 0;
     if (maxFontSize <= 0) {
         int cr = 0;
         int lf = 0;
         char[] t = text.ToCharArray();
         for (int k = 0; k < t.Length; ++k) {
             if (t[k] == '\n')
                 ++lf;
             else if (t[k] == '\r')
                 ++cr;
         }
         int minLines = Math.Max(cr, lf) + 1;
         maxFontSize = Math.Abs(rect.Height) / minLines - 0.001f;
     }
     font.Size = maxFontSize;
     Phrase ph = new Phrase(text, font);
     ct = new ColumnText(null);
     ct.SetSimpleColumn(ph, rect.Left, rect.Bottom, rect.Right, rect.Top, maxFontSize, Element.ALIGN_LEFT);
     ct.RunDirection = runDirection;
     status = ct.Go(true);
     if ((status & ColumnText.NO_MORE_TEXT) != 0)
         return maxFontSize;
     float precision = 0.1f;
     float min = 0;
     float max = maxFontSize;
     float size = maxFontSize;
     for (int k = 0; k < 50; ++k) { //just in case it doesn't converge
         size = (min + max) / 2;
         ct = new ColumnText(null);
         font.Size = size;
         ct.SetSimpleColumn(new Phrase(text, font), rect.Left, rect.Bottom, rect.Right, rect.Top, size, Element.ALIGN_LEFT);
         ct.RunDirection = runDirection;
         status = ct.Go(true);
         if ((status & ColumnText.NO_MORE_TEXT) != 0) {
             if (max - min < size * precision)
                 return size;
             min = size;
         }
         else
             max = size;
     }
     return size;
 }
Esempio n. 22
0
 /**
 * Constructs a chunk of text with a char and a certain <CODE>Font</CODE>.
 *
 * @param    c        the content
 * @param    font        the font
 */
 public Chunk(char c, Font font)
 {
     this.content = new StringBuilder();
     this.content.Append(c);
     this.font = font;
 }
        /**
        * Gets the main appearance layer.
        * <p>
        * Consult <A HREF="http://partners.adobe.com/asn/developer/pdfs/tn/PPKAppearances.pdf">PPKAppearances.pdf</A>
        * for further details.
        * @return the main appearance layer
        * @throws DocumentException on error
        * @throws IOException on error
        */
        public PdfTemplate GetAppearance()
        {
            if (IsInvisible()) {
                PdfTemplate t = new PdfTemplate(writer);
                t.BoundingBox = new Rectangle(0, 0);
                writer.AddDirectTemplateSimple(t, null);
                return t;
            }
            if (app[0] == null) {
                PdfTemplate t = app[0] = new PdfTemplate(writer);
                t.BoundingBox = new Rectangle(100, 100);
                writer.AddDirectTemplateSimple(t, new PdfName("n0"));
                t.SetLiteral("% DSBlank\n");
            }
            if (app[1] == null && !acro6Layers) {
                PdfTemplate t = app[1] = new PdfTemplate(writer);
                t.BoundingBox = new Rectangle(100, 100);
                writer.AddDirectTemplateSimple(t, new PdfName("n1"));
                t.SetLiteral(questionMark);
            }
            if (app[2] == null) {
                String text;
                if (layer2Text == null) {
                    StringBuilder buf = new StringBuilder();
                    buf.Append("Digitally signed by ").Append(PdfPKCS7.GetSubjectFields((X509Certificate)certChain[0]).GetField("CN")).Append('\n');
                    buf.Append("Date: ").Append(signDate.ToString("yyyy.MM.dd HH:mm:ss zzz"));
                    if (reason != null)
                        buf.Append('\n').Append("Reason: ").Append(reason);
                    if (location != null)
                        buf.Append('\n').Append("Location: ").Append(location);
                    text = buf.ToString();
                }
                else
                    text = layer2Text;
                PdfTemplate t = app[2] = new PdfTemplate(writer);
                t.BoundingBox = rect;
                writer.AddDirectTemplateSimple(t, new PdfName("n2"));
                if (image != null) {
                    if (imageScale == 0) {
                        t.AddImage(image, rect.Width, 0, 0, rect.Height, 0, 0);
                    }
                    else {
                        float usableScale = imageScale;
                        if (imageScale < 0)
                            usableScale = Math.Min(rect.Width / image.Width, rect.Height / image.Height);
                        float w = image.Width * usableScale;
                        float h = image.Height * usableScale;
                        float x = (rect.Width - w) / 2;
                        float y = (rect.Height - h) / 2;
                        t.AddImage(image, w, 0, 0, h, x, y);
                    }
                }
                Font font;
                if (layer2Font == null)
                    font = new Font();
                else
                    font = new Font(layer2Font);
                float size = font.Size;

                Rectangle dataRect = null;
                Rectangle signatureRect = null;

                if (Render == SignatureRender.NameAndDescription ||
                    (Render == SignatureRender.GraphicAndDescription && this.SignatureGraphic != null)) {
                    // origin is the bottom-left
                    signatureRect = new Rectangle(
                        MARGIN,
                        MARGIN,
                        rect.Width / 2 - MARGIN,
                        rect.Height - MARGIN);
                    dataRect = new Rectangle(
                        rect.Width / 2 +  MARGIN / 2,
                        MARGIN,
                        rect.Width - MARGIN / 2,
                        rect.Height - MARGIN);

                    if (rect.Height > rect.Width) {
                        signatureRect = new Rectangle(
                            MARGIN,
                            rect.Height / 2,
                            rect.Width - MARGIN,
                            rect.Height);
                        dataRect = new Rectangle(
                            MARGIN,
                            MARGIN,
                            rect.Width - MARGIN,
                            rect.Height / 2 - MARGIN);
                    }
                }
                else {
                    dataRect = new Rectangle(
                        MARGIN,
                        MARGIN,
                        rect.Width - MARGIN,
                        rect.Height * (1 - TOP_SECTION) - MARGIN);
                }

                if (Render == SignatureRender.NameAndDescription) {
                    string signedBy = Legacy.Text.Pdf.PdfPKCS7.GetSubjectFields(this.certChain[0]).GetField("CN");
                    Rectangle sr2 = new Rectangle(signatureRect.Width - MARGIN, signatureRect.Height - MARGIN );
                    float signedSize = FitText(font, signedBy, sr2, -1, runDirection);

                    ColumnText ct2 = new ColumnText(t);
                    ct2.RunDirection = runDirection;
                    ct2.SetSimpleColumn(new Phrase(signedBy, font), signatureRect.Left, signatureRect.Bottom, signatureRect.Right, signatureRect.Top, signedSize, Element.ALIGN_LEFT);

                    ct2.Go();
                }
                else if (Render == SignatureRender.GraphicAndDescription) {
                    ColumnText ct2 = new ColumnText(t);
                    ct2.RunDirection = runDirection;
                    ct2.SetSimpleColumn(signatureRect.Left, signatureRect.Bottom, signatureRect.Right, signatureRect.Top, 0, Element.ALIGN_RIGHT);

                    Image im = Image.GetInstance(SignatureGraphic);
                    im.ScaleToFit(signatureRect.Width, signatureRect.Height);

                    Paragraph p = new Paragraph();
                    // must calculate the point to draw from to make image appear in middle of column
                    float x = 0;
                    // experimentation found this magic number to counteract Adobe's signature graphic, which
                    // offsets the y co-ordinate by 15 units
                    float y = -im.ScaledHeight + 15;

                    x = x + (signatureRect.Width - im.ScaledWidth) / 2;
                    y = y - (signatureRect.Height - im.ScaledHeight) / 2;
                    p.Add(new Chunk(im, x + (signatureRect.Width - im.ScaledWidth) / 2, y, false));
                    ct2.AddElement(p);
                    ct2.Go();
                }

                if (size <= 0) {
                    Rectangle sr = new Rectangle(dataRect.Width, dataRect.Height);
                    size = FitText(font, text, sr, 12, runDirection);
                }
                ColumnText ct = new ColumnText(t);
                ct.RunDirection = runDirection;
                ct.SetSimpleColumn(new Phrase(text, font), dataRect.Left, dataRect.Bottom, dataRect.Right, dataRect.Top, size, Element.ALIGN_LEFT);
                ct.Go();

            }
            if (app[3] == null && !acro6Layers) {
                PdfTemplate t = app[3] = new PdfTemplate(writer);
                t.BoundingBox = new Rectangle(100, 100);
                writer.AddDirectTemplateSimple(t, new PdfName("n3"));
                t.SetLiteral("% DSBlank\n");
            }
            if (app[4] == null && !acro6Layers) {
                PdfTemplate t = app[4] = new PdfTemplate(writer);
                t.BoundingBox = new Rectangle(0, rect.Height * (1 - TOP_SECTION), rect.Right, rect.Top);
                writer.AddDirectTemplateSimple(t, new PdfName("n4"));
                Font font;
                if (layer2Font == null)
                    font = new Font();
                else
                    font = new Font(layer2Font);
                float size = font.Size;
                String text = "Signature Not Verified";
                if (layer4Text != null)
                    text = layer4Text;
                Rectangle sr = new Rectangle(rect.Width - 2 * MARGIN, rect.Height * TOP_SECTION - 2 * MARGIN);
                size = FitText(font, text, sr, 15, runDirection);
                ColumnText ct = new ColumnText(t);
                ct.RunDirection = runDirection;
                ct.SetSimpleColumn(new Phrase(text, font), MARGIN, 0, rect.Width - MARGIN, rect.Height - MARGIN, size, Element.ALIGN_LEFT);
                ct.Go();
            }
            int rotation = writer.reader.GetPageRotation(page);
            Rectangle rotated = new Rectangle(rect);
            int n = rotation;
            while (n > 0) {
                rotated = rotated.Rotate();
                n -= 90;
            }
            if (frm == null) {
                frm = new PdfTemplate(writer);
                frm.BoundingBox = rotated;
                writer.AddDirectTemplateSimple(frm, new PdfName("FRM"));
                float scale = Math.Min(rect.Width, rect.Height) * 0.9f;
                float x = (rect.Width - scale) / 2;
                float y = (rect.Height - scale) / 2;
                scale /= 100;
                if (rotation == 90)
                    frm.ConcatCTM(0, 1, -1, 0, rect.Height, 0);
                else if (rotation == 180)
                    frm.ConcatCTM(-1, 0, 0, -1, rect.Width, rect.Height);
                else if (rotation == 270)
                    frm.ConcatCTM(0, -1, 1, 0, 0, rect.Width);
                frm.AddTemplate(app[0], 0, 0);
                if (!acro6Layers)
                    frm.AddTemplate(app[1], scale, 0, 0, scale, x, y);
                frm.AddTemplate(app[2], 0, 0);
                if (!acro6Layers) {
                    frm.AddTemplate(app[3], scale, 0, 0, scale, x, y);
                    frm.AddTemplate(app[4], 0, 0);
                }
            }
            PdfTemplate napp = new PdfTemplate(writer);
            napp.BoundingBox = rotated;
            writer.AddDirectTemplateSimple(napp, null);
            napp.AddTemplate(frm, 0, 0);
            return napp;
        }
Esempio n. 24
0
 /// <summary>
 /// Constructs a Paragraph with a certain leading, string
 /// and Font.
 /// </summary>
 /// <param name="leading">the leading</param>
 /// <param name="str">a string</param>
 /// <param name="font">a Font</param>
 public Paragraph(float leading, string str, Font font)
     : base(leading, str, font)
 {
 }
Esempio n. 25
0
 /**
 * Adds extra space.
 * This method should probably be rewritten.
 */
 protected internal void AddSpacing(float extraspace, float oldleading, Font f)
 {
     if (extraspace == 0) return;
     if (pageEmpty) return;
     if (currentHeight + line.Height + leading > IndentTop - IndentBottom) return;
     leading = extraspace;
     CarriageReturn();
     if (f.IsUnderlined() || f.IsStrikethru()) {
         f = new Font(f);
         int style = f.Style;
         style &= ~Font.UNDERLINE;
         style &= ~Font.STRIKETHRU;
         f.SetStyle(style);
     }
     Chunk space = new Chunk(" ", f);
     space.Process(this);
     CarriageReturn();
     leading = oldleading;
 }