Esempio n. 1
0
        private void DrawText(
            Page page,
            float x,
            float y,
            float cell_w,
            float cell_h)
        {
            float x_text;
            float y_text;

            if (valign == Align.TOP)
            {
                y_text = y + font.ascent + this.top_padding;
            }
            else if (valign == Align.CENTER)
            {
                y_text = y + cell_h / 2 + font.ascent / 2;
            }
            else if (valign == Align.BOTTOM)
            {
                y_text = (y + cell_h) - this.bottom_padding;
            }
            else
            {
                throw new Exception("Invalid vertical text alignment option.");
            }

            page.SetPenColor(pen);
            page.SetBrushColor(brush);

            if (GetTextAlignment() == Align.RIGHT)
            {
                if (compositeTextLine == null)
                {
                    x_text = (x + cell_w) - (font.StringWidth(text) + this.right_padding);
                    page.AddBMC(StructElem.SPAN, Single.space, Single.space);
                    page.DrawString(font, fallbackFont, text, x_text, y_text);
                    page.AddEMC();
                    if (GetUnderline())
                    {
                        UnderlineText(page, font, text, x_text, y_text);
                    }
                    if (GetStrikeout())
                    {
                        StrikeoutText(page, font, text, x_text, y_text);
                    }
                }
                else
                {
                    x_text = (x + cell_w) - (compositeTextLine.GetWidth() + this.right_padding);
                    compositeTextLine.SetLocation(x_text, y_text);
                    page.AddBMC(StructElem.SPAN, Single.space, Single.space);
                    compositeTextLine.DrawOn(page);
                    page.AddEMC();
                }
            }
            else if (GetTextAlignment() == Align.CENTER)
            {
                if (compositeTextLine == null)
                {
                    x_text = x + this.left_padding +
                             (((cell_w - (left_padding + right_padding)) - font.StringWidth(text)) / 2);
                    page.AddBMC(StructElem.SPAN, Single.space, Single.space);
                    page.DrawString(font, fallbackFont, text, x_text, y_text);
                    page.AddEMC();
                    if (GetUnderline())
                    {
                        UnderlineText(page, font, text, x_text, y_text);
                    }
                    if (GetStrikeout())
                    {
                        StrikeoutText(page, font, text, x_text, y_text);
                    }
                }
                else
                {
                    x_text = x + this.left_padding +
                             (((cell_w - (left_padding + right_padding)) - compositeTextLine.GetWidth()) / 2);
                    compositeTextLine.SetLocation(x_text, y_text);
                    page.AddBMC(StructElem.SPAN, Single.space, Single.space);
                    compositeTextLine.DrawOn(page);
                    page.AddEMC();
                }
            }
            else if (GetTextAlignment() == Align.LEFT)
            {
                x_text = x + this.left_padding;
                if (compositeTextLine == null)
                {
                    page.AddBMC(StructElem.SPAN, Single.space, Single.space);
                    page.DrawString(font, fallbackFont, text, x_text, y_text);
                    page.AddEMC();
                    if (GetUnderline())
                    {
                        UnderlineText(page, font, text, x_text, y_text);
                    }
                    if (GetStrikeout())
                    {
                        StrikeoutText(page, font, text, x_text, y_text);
                    }
                }
                else
                {
                    compositeTextLine.SetLocation(x_text, y_text);
                    page.AddBMC(StructElem.SPAN, Single.space, Single.space);
                    compositeTextLine.DrawOn(page);
                    page.AddEMC();
                }
            }
            else
            {
                throw new Exception("Invalid Text Alignment!");
            }

            if (uri != null)
            {
                float w = (compositeTextLine != null) ?
                          compositeTextLine.GetWidth() : font.StringWidth(text);
                // Please note: The font descent is a negative number.
                page.AddAnnotation(new Annotation(
                                       uri,
                                       null,
                                       x_text,
                                       (page.height - y_text) + font.descent,
                                       x_text + w,
                                       (page.height - y_text) + font.ascent,
                                       null,
                                       null,
                                       null));
            }
        }
Esempio n. 2
0
        private void DrawText(
            Page page,
            float x,
            float y,
            float cell_w)
        {
            float y_text = y + font.ascent + this.top_padding;

            page.SetPenColor(pen);
            page.SetBrushColor(brush);

            if (GetTextAlignment() == Align.RIGHT)
            {
                if (compositeTextLine == null)
                {
                    float x_text = (x + cell_w) - (font.StringWidth(text) + this.right_padding);
                    page.DrawString(font, text, x_text, y_text);
                    if (GetUnderline())
                    {
                        UnderlineText(page, font, text, x_text, y_text);
                    }
                    if (GetStrikeout())
                    {
                        StrikeoutText(page, font, text, x_text, y_text);
                    }
                }
                else
                {
                    float x_text = (x + cell_w) - (compositeTextLine.GetWidth() + this.right_padding);
                    compositeTextLine.SetPosition(x_text, y_text);
                    compositeTextLine.DrawOn(page);
                }
            }
            else if (GetTextAlignment() == Align.CENTER)
            {
                if (compositeTextLine == null)
                {
                    float x_text = x + this.left_padding +
                                   (((cell_w - (left_padding + right_padding)) - font.StringWidth(text)) / 2);
                    page.DrawString(font, text, x_text, y_text);
                    if (GetUnderline())
                    {
                        UnderlineText(page, font, text, x_text, y_text);
                    }
                    if (GetStrikeout())
                    {
                        StrikeoutText(page, font, text, x_text, y_text);
                    }
                }
                else
                {
                    float x_text = x + this.left_padding +
                                   (((cell_w - (left_padding + right_padding)) - compositeTextLine.GetWidth()) / 2);
                    compositeTextLine.SetPosition(x_text, y_text);
                    compositeTextLine.DrawOn(page);
                }
            }
            else if (GetTextAlignment() == Align.LEFT)
            {
                float x_text = x + this.left_padding;
                if (compositeTextLine == null)
                {
                    page.DrawString(font, text, x_text, y_text);
                    if (GetUnderline())
                    {
                        UnderlineText(page, font, text, x_text, y_text);
                    }
                    if (GetStrikeout())
                    {
                        StrikeoutText(page, font, text, x_text, y_text);
                    }
                }
                else
                {
                    compositeTextLine.SetPosition(x_text, y_text);
                    compositeTextLine.DrawOn(page);
                }
            }
            else
            {
                throw new Exception("Invalid Text Alignment!");
            }
        }