Example #1
0
        public float[] DrawTextLine(
            Page page, float x_text, float y_text, TextLine textLine, bool draw)
        {
            Font font         = textLine.GetFont();
            Font fallbackFont = textLine.GetFallbackFont();
            int  color        = textLine.GetColor();

            StringBuilder buf = new StringBuilder();

            String[] tokens           = Regex.Split(textLine.GetText(), "\\s+");
            bool     firstTextSegment = true;

            for (int i = 0; i < tokens.Length; i++)
            {
                String token = (i == 0) ? tokens[i] : (" " + tokens[i]);
                if (font.StringWidth(fallbackFont, token) < (this.w - (x_text - x)))
                {
                    buf.Append(token);
                    x_text += font.StringWidth(fallbackFont, token);
                }
                else
                {
                    if (draw)
                    {
                        new TextLine(font, buf.ToString())
                        .SetFallbackFont(textLine.GetFallbackFont())
                        .SetLocation(x_text - font.StringWidth(fallbackFont, buf.ToString()), y_text)
                        .SetColor(color)
                        .SetUnderline(textLine.GetUnderline())
                        .SetStrikeout(textLine.GetStrikeout())
                        .SetLanguage(textLine.GetLanguage())
                        .SetAltDescription(firstTextSegment ? textLine.GetAltDescription() : Single.space)
                        .SetActualText(firstTextSegment ? textLine.GetActualText() : Single.space)
                        .DrawOn(page);
                        firstTextSegment = false;
                    }
                    x_text     = x + font.StringWidth(fallbackFont, tokens[i]);
                    y_text    += leading;
                    buf.Length = 0;
                    buf.Append(tokens[i]);
                }
            }
            if (draw)
            {
                new TextLine(font, buf.ToString())
                .SetFallbackFont(textLine.GetFallbackFont())
                .SetLocation(x_text - font.StringWidth(fallbackFont, buf.ToString()), y_text)
                .SetColor(color)
                .SetUnderline(textLine.GetUnderline())
                .SetStrikeout(textLine.GetStrikeout())
                .SetLanguage(textLine.GetLanguage())
                .SetAltDescription(firstTextSegment ? textLine.GetAltDescription() : Single.space)
                .SetActualText(firstTextSegment ? textLine.GetActualText() : Single.space)
                .DrawOn(page);
                firstTextSegment = false;
            }

            return(new float[] { x_text, y_text });
        }
Example #2
0
 /**
  *  Returns the width of this TextLine.
  *
  *  @return the width.
  */
 public float GetWidth()
 {
     if (fallbackFont == null)
     {
         return(font.StringWidth(str));
     }
     return(font.StringWidth(fallbackFont, str));
 }
        public void DrawOn(Page page, bool draw)
        {
            if (!draw)
            {
                return;
            }

            page.SetTextDirection(degrees);
            x += box_x;
            y += box_y;
            if (uri != null)
            {
                page.annots.Add(new Annotation(uri,
                                               x,
                                               page.height - (y - font.ascent),
                                               x + font.StringWidth(str),
                                               page.height - (y - font.descent)));
            }

            if (str != null)
            {
                page.SetBrushColor(
                    color[0], color[1], color[2]);
                page.drawString(font, str, x, y);
            }

            if (underline)
            {
                page.setPenWidth(font.underlineThickness);
                page.SetPenColor(color[0], color[1], color[2]);
                double lineLength = font.StringWidth(str);
                double radians    = Math.PI * degrees / 180.0;
                double x_adjust   = font.underlinePosition * Math.Sin(radians);
                double y_adjust   = font.underlinePosition * Math.Cos(radians);
                double x2         = x + lineLength * Math.Cos(radians);
                double y2         = y - lineLength * Math.Sin(radians);
                page.moveTo(x + x_adjust, y + y_adjust);
                page.lineTo(x2 + x_adjust, y2 + y_adjust);
                page.strokePath();
            }

            if (strike)
            {
                page.setPenWidth(font.underlineThickness);
                page.SetPenColor(color[0], color[1], color[2]);
                double lineLength = font.StringWidth(str);
                double radians    = Math.PI * degrees / 180.0;
                double x_adjust   = (font.body_height / 4.0) * Math.Sin(radians);
                double y_adjust   = (font.body_height / 4.0) * Math.Cos(radians);
                double x2         = x + lineLength * Math.Cos(radians);
                double y2         = y - lineLength * Math.Sin(radians);
                page.moveTo(x - x_adjust, y - y_adjust);
                page.lineTo(x2 - x_adjust, y2 - y_adjust);
                page.strokePath();
            }

            page.SetTextDirection(0);
        }
Example #4
0
        /**
         *  Draws this RadioButton on the specified Page.
         *
         *  @param page the Page where the RadioButton is to be drawn.
         */
        public float[] DrawOn(Page page)
        {
            page.AddBMC(StructElem.SPAN, language, altDescription, actualText);

            this.r1       = font.GetAscent() / 2;
            this.r2       = r1 / 2;
            this.penWidth = r1 / 10;

            float y_box = y - font.GetAscent();

            page.SetPenWidth(1f);
            page.SetPenColor(Color.black);
            page.SetLinePattern("[] 0");
            page.SetBrushColor(Color.black);
            page.DrawCircle(x + r1, y_box + r1, r1);

            if (this.selected)
            {
                page.DrawCircle(x + r1, y_box + r1, r2, Operation.FILL);
            }

            if (uri != null)
            {
                page.SetBrushColor(Color.blue);
            }
            page.DrawString(font, label, x + 3 * r1, y);
            page.SetPenWidth(0f);
            page.SetBrushColor(Color.black);

            page.AddEMC();

            if (uri != null)
            {
                // Please note: The font descent is a negative number.
                page.AddAnnotation(new Annotation(
                                       uri,
                                       null,
                                       x + 3 * r1,
                                       page.height - y,
                                       x + 3 * r1 + font.StringWidth(label),
                                       page.height - (y - font.GetAscent()),
                                       language,
                                       altDescription,
                                       actualText));
            }

            return(new float[] { x + 6 * r1 + font.StringWidth(label), y + font.GetBodyHeight() });
        }
Example #5
0
 private void StrikeoutText(Page page, Font font, string text, float x, float y)
 {
     page.SetPenWidth(font.underlineThickness);
     page.MoveTo((double)x, (double)y - (double)font.GetAscent() / 3.0);
     page.LineTo((double)(x + font.StringWidth(text)), (double)y - (double)font.GetAscent() / 3.0);
     page.StrokePath();
 }
Example #6
0
        /**
         * Returns the width of a string drawn using two fonts.
         *
         * @param fallbackFont the fallback font.
         * @param str the string.
         * @return the width.
         */
        public float StringWidth(Font fallbackFont, String str)
        {
            float width = 0f;

            if (this.isCoreFont || this.isCJK || fallbackFont == null || fallbackFont.isCoreFont || fallbackFont.isCJK)
            {
                return(StringWidth(str));
            }

            Font          activeFont = this;
            StringBuilder buf        = new StringBuilder();

            for (int i = 0; i < str.Length; i++)
            {
                int ch = str[i];
                if (activeFont.unicodeToGID[ch] == 0)
                {
                    width     += activeFont.StringWidth(buf.ToString());
                    buf.Length = 0;
                    // Switch the active font
                    if (activeFont == this)
                    {
                        activeFont = fallbackFont;
                    }
                    else
                    {
                        activeFont = this;
                    }
                }
                buf.Append((char)ch);
            }
            width += activeFont.StringWidth(buf.ToString());

            return(width);
        }
Example #7
0
        public float[] DrawOn(Page page)
        {
            if (numberOfRows == 0)
            {
                return(new float[] { x, y });
            }

            float boxHeight = rowHeight * numberOfRows;
            Box   box       = new Box();

            box.SetLocation(x, y);
            box.SetSize(rowLength, boxHeight);
            box.DrawOn(page);

            float field_y  = 0f;
            int   row_span = 1;
            float row_y    = 0;

            foreach (Field field in fields)
            {
                if (field.x == 0f)
                {
                    row_y   += row_span * rowHeight;
                    row_span = field.values.Length;
                }
                field_y = row_y;
                for (int i = 0; i < field.values.Length; i++)
                {
                    Font  font     = (i == 0) ? f1 : f2;
                    float fontSize = (i == 0) ? labelFontSize : valueFontSize;
                    int   color    = (i == 0) ? labelColor : valueColor;
                    new TextLine(font, field.values[i])
                    .SetFontSize(fontSize)
                    .SetColor(color)
                    .PlaceIn(box, field.x + f1.GetDescent(), field_y - font.GetDescent())
                    .SetAltDescription((i == 0) ? field.altDescription[i] : (field.altDescription[i] + ","))
                    .SetActualText((i == 0) ? field.actualText[i] : (field.actualText[i] + ","))
                    .DrawOn(page);
                    endOfLinePoints.Add(new float[] {
                        field.x + f1.GetDescent() + font.StringWidth(field.values[i]),
                        field_y - font.GetDescent(),
                    });
                    if (i == (field.values.Length - 1))
                    {
                        new Line(0f, 0f, rowLength, 0f)
                        .PlaceIn(box, 0f, field_y)
                        .DrawOn(page);
                        if (field.x != 0f)
                        {
                            new Line(0f, -(field.values.Length - 1) * rowHeight, 0f, 0f)
                            .PlaceIn(box, field.x, field_y)
                            .DrawOn(page);
                        }
                    }
                    field_y += rowHeight;
                }
            }

            return(new float[] { x + rowLength, y + boxHeight });
        }
Example #8
0
        private void DrawText(
            Page page,
            Font font,
            Font fallbackFont,
            String text,
            float xText,
            float yText,
            Dictionary <String, Int32> colors)
        {
            page.DrawString(font, fallbackFont, text, xText, yText, colors);
            float lineLength = font.StringWidth(text);

            if (GetUnderline())
            {
                float yAdjust = font.underlinePosition;
                page.MoveTo(xText, yText + yAdjust);
                page.LineTo(xText + lineLength, yText + yAdjust);
                page.StrokePath();
            }
            if (GetStrikeout())
            {
                float yAdjust = font.bodyHeight / 4;
                page.MoveTo(xText, yText - yAdjust);
                page.LineTo(xText + lineLength, yText - yAdjust);
                page.StrokePath();
            }
        }
Example #9
0
        /**
         *  Draws this RadioButton on the specified Page.
         *
         *  @param page the page to draw on.
         *  @return x and y coordinates of the bottom right corner of this component.
         *  @throws Exception
         */
        public float[] DrawOn(Page page)
        {
            page.AddBMC(StructElem.SPAN, language, altDescription, actualText);

            this.r1       = font.GetAscent() / 2;
            this.r2       = r1 / 2;
            this.penWidth = r1 / 10;

            float yBox = y;

            page.SetPenWidth(1f);
            page.SetPenColor(Color.black);
            page.SetLinePattern("[] 0");
            page.SetBrushColor(Color.black);
            page.DrawCircle(x + r1 + penWidth, yBox + r1 + penWidth, r1);

            if (this.selected)
            {
                page.DrawCircle(x + r1 + penWidth, yBox + r1 + penWidth, r2, Operation.FILL);
            }

            if (uri != null)
            {
                page.SetBrushColor(Color.blue);
            }
            page.DrawString(font, label, x + 3 * r1, y + font.ascent);
            page.SetPenWidth(0f);
            page.SetBrushColor(Color.black);

            page.AddEMC();

            if (uri != null)
            {
                page.AddAnnotation(new Annotation(
                                       uri,
                                       null,
                                       x + 3 * r1,
                                       y,
                                       x + 3 * r1 + font.StringWidth(label),
                                       y + font.bodyHeight,
                                       language,
                                       altDescription,
                                       actualText));
            }

            return(new float[] { x + 6 * r1 + font.StringWidth(label), y + font.bodyHeight });
        }
Example #10
0
 private void StrikeoutText(
     Page page, Font font, String text, float x, float y)
 {
     page.SetPenWidth(font.underlineThickness);
     page.MoveTo(x, y - font.GetAscent() / 3f);
     page.LineTo(x + font.StringWidth(text), y - font.GetAscent() / 3f);
     page.StrokePath();
 }
Example #11
0
        // Splits the text line and adds the line segments to the list.
        private void reformat(String line, float textAreaWidth, List <String> lines)
        {
            StringBuilder buf = new StringBuilder();

            for (int i = 0; i < line.Length; i++)
            {
                buf.Append(line[i]);
                String str = buf.ToString();
                if (font.StringWidth(str) > textAreaWidth)
                {
                    if ((str[str.Length - 1] == ' ') ||
                        Regex.Split(str, @"\s+").Length <= 1)
                    {
                        // TODO:
                        // lines.Add(str.TrimEnd());
                        lines.Add(str);
                    }
                    else
                    {
                        lines.Add(str.Substring(0, str.LastIndexOf(' ')));
                        while (line[i] != ' ')
                        {
                            i -= 1;
                        }
                    }
                    buf.Length = 0;
                }
            }
            if (buf.Length > 0)
            {
                lines.Add(buf.ToString());
            }
        }
Example #12
0
        private void UnderlineText(Page page, Font font, string text, float x, float y)
        {
            float descent = font.GetDescent();

            page.SetPenWidth(font.underlineThickness);
            page.MoveTo(x, y + descent);
            page.LineTo(x + font.StringWidth(text), y + descent);
            page.StrokePath();
        }
Example #13
0
        private void DrawText(
            Page page,
            double x,
            double y,
            double cell_w,
            double margin)
        {
            double y_text = y + font.ascent + margin;

            page.SetPenColor(penColor[0], penColor[1], penColor[2]);
            page.SetBrushColor(brushColor[0], brushColor[1], brushColor[2]);

            if (align == Align.RIGHT)
            {
                page.drawString(
                    font,
                    text,
                    (x + cell_w) - (font.StringWidth(text) + margin), y_text);
            }
            else if (align == Align.CENTER)
            {
                page.drawString(
                    font,
                    text,
                    x + (cell_w - font.StringWidth(text)) / 2, y_text);
            }
            else
            {
                // Use the default - Align.LEFT
                page.drawString(
                    font,
                    text,
                    x + margin,
                    y_text);
            }

            if (point != null)
            {
                point.x = (x + cell_w) - (font.ascent / 2 + margin);
                point.y = y + (font.ascent / 2 + margin);
                point.r = font.ascent / 3;
                page.drawPoint(point);
            }
        }
Example #14
0
 public Text(List <Paragraph> paragraphs)
 {
     this.paragraphs            = paragraphs;
     this.font                  = paragraphs[0].list[0].GetFont();
     this.fallbackFont          = paragraphs[0].list[0].GetFallbackFont();
     this.leading               = font.GetBodyHeight();
     this.paragraphLeading      = 2 * leading;
     this.beginParagraphPoints  = new List <float[]>();
     this.spaceBetweenTextLines = font.StringWidth(fallbackFont, Single.space);
 }
Example #15
0
 private void StrikeoutText(
     Page page, Font font, String text, float x, float y)
 {
     page.AddBMC(StructElem.SPAN, Single.space, Single.space);
     page.SetPenWidth(font.underlineThickness);
     page.MoveTo(x, y - font.GetAscent() / 3f);
     page.LineTo(x + font.StringWidth(text), y - font.GetAscent() / 3f);
     page.StrokePath();
     page.AddEMC();
 }
Example #16
0
        /**
         * Returns the width of a string drawn using two fonts.
         *
         * @param font2 the fallback font.
         * @param str the string.
         * @return the width.
         */
        public float StringWidth(Font font2, String str)
        {
            float width = 0f;

            bool          usingFont1 = true;
            StringBuilder buf        = new StringBuilder();

            for (int i = 0; i < str.Length; i++)
            {
                int ch = str[i];
                if ((isCJK && ch >= 0x4E00 && ch <= 0x9FCC) ||
                    (!isCJK && unicodeToGID[ch] != 0))
                {
                    if (!usingFont1)
                    {
                        width     += font2.StringWidth(buf.ToString());
                        buf        = new StringBuilder();
                        usingFont1 = true;
                    }
                }
                else
                {
                    if (usingFont1)
                    {
                        width     += StringWidth(buf.ToString());
                        buf        = new StringBuilder();
                        usingFont1 = false;
                    }
                }
                buf.Append((char)ch);
            }

            if (usingFont1)
            {
                width += StringWidth(buf.ToString());
            }
            else
            {
                width += font2.StringWidth(buf.ToString());
            }

            return(width);
        }
Example #17
0
        public static String[] SplitTextIntoTokens(
            String text,
            Font font,
            Font fallbackFont,
            float width)
        {
            List <String> tokens2 = new List <String>();

            String[] tokens = Regex.Split(text, @"\s+");
            foreach (String token in tokens)
            {
                if (font.StringWidth(fallbackFont, token) <= width)
                {
                    tokens2.Add(token);
                }
                else
                {
                    StringBuilder buf = new StringBuilder();
                    for (int i = 0; i < token.Length; i++)
                    {
                        String ch = token[i].ToString();
                        if (font.StringWidth(fallbackFont, buf.ToString() + ch) <= width)
                        {
                            buf.Append(ch);
                        }
                        else
                        {
                            tokens2.Add(buf.ToString());
                            buf.Length = 0;
                            buf.Append(ch);
                        }
                    }
                    String str = buf.ToString();
                    if (!str.Equals(""))
                    {
                        tokens2.Add(str);
                    }
                }
            }

            return(tokens2.ToArray());
        }
Example #18
0
 public Text(List<Paragraph> paragraphs)
 {
     this.paragraphs = paragraphs;
     this.font = paragraphs[0].list[0].GetFont();
     this.fallbackFont = paragraphs[0].list[0].GetFallbackFont();
     this.leading = font.GetBodyHeight();
     this.paragraphLeading = 2*leading;
     this.beginParagraphPoints = new List<float[]>();
     this.endParagraphPoints = new List<float[]>();
     this.spaceBetweenTextLines = font.StringWidth(fallbackFont, " ");
 }
Example #19
0
        private void UnderlineText(
            Page page, Font font, String text, float x, float y)
        {
            float descent = font.GetDescent();

            page.AddBMC(StructElem.SPAN, Single.space, Single.space);
            page.SetPenWidth(font.underlineThickness);
            page.MoveTo(x, y + descent);
            page.LineTo(x + font.StringWidth(text), y + descent);
            page.StrokePath();
            page.AddEMC();
        }
Example #20
0
        /**
         * Returns the width of a string drawn using two fonts.
         *
         * @param font2 the fallback font.
         * @param str the string.
         * @return the width.
         */
        public float StringWidth(Font font2, String str)
        {
            if (font2 == null)
            {
                return(StringWidth(str));
            }
            float width = 0f;

            Font          activeFont = this;
            StringBuilder buf        = new StringBuilder();

            for (int i = 0; i < str.Length; i++)
            {
                int ch = str[i];
                if ((isCJK && ch >= 0x4E00 && ch <= 0x9FCC) ||
                    (!isCJK && unicodeToGID[ch] != 0))
                {
                    if (this != activeFont)
                    {
                        width     += activeFont.StringWidth(buf.ToString());
                        buf.Length = 0;
                        activeFont = this;
                    }
                }
                else
                {
                    if (font2 != activeFont)
                    {
                        width     += activeFont.StringWidth(buf.ToString());
                        buf.Length = 0;
                        activeFont = font2;
                    }
                }
                buf.Append((char)ch);
            }
            width += activeFont.StringWidth(buf.ToString());

            return(width);
        }
Example #21
0
        public float StringWidth(Font font2, string str)
        {
            float         num           = 0f;
            bool          flag          = true;
            StringBuilder stringBuilder = new StringBuilder();

            for (int i = 0; i < str.Length; i++)
            {
                int num2 = (int)str[i];
                if ((this.isCJK && num2 >= 19968 && num2 <= 40908) || (!this.isCJK && this.unicodeToGID[num2] != 0))
                {
                    if (!flag)
                    {
                        num          += font2.StringWidth(stringBuilder.ToString());
                        stringBuilder = new StringBuilder();
                        flag          = true;
                    }
                }
                else
                {
                    if (flag)
                    {
                        num          += this.StringWidth(stringBuilder.ToString());
                        stringBuilder = new StringBuilder();
                        flag          = false;
                    }
                }
                stringBuilder.Append((char)num2);
            }
            if (flag)
            {
                num += this.StringWidth(stringBuilder.ToString());
            }
            else
            {
                num += font2.StringWidth(stringBuilder.ToString());
            }
            return(num);
        }
Example #22
0
 public void AddChineseParagraph(Font font, String chinese)
 {
     Paragraph p = null;
     StringBuilder buf = new StringBuilder();
     for (int i = 0; i < chinese.Length; i++) {
     char ch = chinese[i];
     if (font.StringWidth(buf.ToString() + ch) > w) {
         p = new Paragraph();
         p.Add(new TextLine(font, buf.ToString()));
         AddParagraph(p);
         buf.Length = 0;
     }
     buf.Append(ch);
     }
     p = new Paragraph();
     p.Add(new TextLine(font, buf.ToString()));
     AddParagraph(p);
 }
Example #23
0
        public float[] DrawOn(Page page)
        {
            for (int row = 0; row < 7; row++)
            {
                for (int col = 0; col < 7; col++)
                {
                    if (row == 0)
                    {
                        float    offset = (dx - f1.StringWidth(days[col])) / 2;
                        TextLine text   = new TextLine(f1, days[col]);
                        text.SetLocation(x1 + col * dx + offset, y1 + (dy / 2) - f1.descent);
                        text.DrawOn(page);
                        // Draw the line separating the title from the dates.
                        Line line = new Line(
                            x1,
                            y1 + dy / 2 + f1.descent,
                            x1 + 7 * dx,
                            y1 + dy / 2 + f1.descent);
                        line.DrawOn(page);
                    }
                    else
                    {
                        int dayOfMonth = ((7 * row + col) - 6) - dayOfWeek;
                        if (dayOfMonth > 0 && dayOfMonth <= daysInMonth)
                        {
                            String   s1     = dayOfMonth.ToString();
                            float    offset = (dx - f2.StringWidth(s1)) / 2;
                            TextLine text   = new TextLine(f2, s1);
                            text.SetLocation(x1 + col * dx + offset, y1 + row * dy + f2.ascent);
                            text.DrawOn(page);

                            page.SetPenWidth(1.5f);
                            page.SetPenColor(Color.blue);
                            page.DrawEllipse(
                                x1 + col * dx + dx / 2,
                                y1 + row * dy + f2.GetHeight() / 2,
                                dx / 2.5,
                                dy / 2.5);
                        }
                    }
                }
            }
            return(new float[] { this.x1 + 7 * this.dx, this.y1 + 7 * this.dy });
        }
        private void DrawText(
            Page page,
            Font font,
            Font fallbackFont,
            String text,
            float x_text,
            float y_text,
            Dictionary <String, Int32> colors)
        {
            if (fallbackFont == null)
            {
                if (colors == null)
                {
                    page.DrawString(font, text, x_text, y_text);
                }
                else
                {
                    page.DrawString(font, text, x_text, y_text, colors);
                }
            }
            else
            {
                page.DrawString(font, fallbackFont, text, x_text, y_text);
            }

            float lineLength = font.StringWidth(text);

            if (GetUnderline())
            {
                float y_adjust = font.underlinePosition;
                page.MoveTo(x_text, y_text + y_adjust);
                page.LineTo(x_text + lineLength, y_text + y_adjust);
                page.StrokePath();
            }
            if (GetStrikeout())
            {
                float y_adjust = font.body_height / 4;
                page.MoveTo(x_text, y_text - y_adjust);
                page.LineTo(x_text + lineLength, y_text - y_adjust);
                page.StrokePath();
            }
        }
Example #25
0
        public CalendarMonth(Font f1, Font f2, int year, int month)
        {
            this.f1     = f1;
            this.f2     = f2;
            daysInMonth = GetDaysInMonth(year, month - 1);
            Calendar calendar = new GregorianCalendar();
            DateTime dateTime = new DateTime(year, month, 1, calendar);

            dayOfWeek = (int)calendar.GetDayOfWeek(dateTime);

            foreach (String day in days)
            {
                float w = 2 * ((float)f1.StringWidth(day));
                if (w > dx)
                {
                    dx = w;
                }
            }
            dy = dx;
        }
Example #26
0
        /**
         *  Draws this PlainText on the specified page.
         *
         *  @param page the page to draw on.
         *  @return x and y coordinates of the bottom right corner of this component.
         *  @throws Exception
         */
        public float[] DrawOn(Page page)
        {
            float originalSize = font.GetSize();

            font.SetSize(fontSize);
            float y_text = y + font.GetAscent();

            page.AddBMC(StructElem.SPAN, language, Single.space, Single.space);
            page.SetBrushColor(backgroundColor);
            leading = font.GetBodyHeight();
            float h = font.GetBodyHeight() * textLines.Length;

            page.FillRect(x, y, w, h);
            page.SetPenColor(borderColor);
            page.SetPenWidth(0f);
            page.DrawRect(x, y, w, h);
            page.AddEMC();

            page.AddBMC(StructElem.SPAN, language, altDescription, actualText);
            page.SetTextStart();
            page.SetTextFont(font);
            page.SetBrushColor(textColor);
            page.SetTextLeading(leading);
            page.SetTextLocation(x, y_text);
            foreach (String str in textLines)
            {
                if (font.skew15)
                {
                    SetTextSkew(page, 0.26f, x, y_text);
                }
                page.Println(str);
                endOfLinePoints.Add(new float[] { x + font.StringWidth(str), y_text });
                y_text += leading;
            }
            page.SetTextEnd();
            page.AddEMC();

            font.SetSize(originalSize);

            return(new float[] { x + w, y + h });
        }
Example #27
0
        public void AddChineseParagraph(Font font, String chinese)
        {
            Paragraph     p   = null;
            StringBuilder buf = new StringBuilder();

            for (int i = 0; i < chinese.Length; i++)
            {
                char ch = chinese[i];
                if (font.StringWidth(buf.ToString() + ch) > w)
                {
                    p = new Paragraph();
                    p.Add(new TextLine(font, buf.ToString()));
                    AddParagraph(p);
                    buf.Length = 0;
                }
                buf.Append(ch);
            }
            p = new Paragraph();
            p.Add(new TextLine(font, buf.ToString()));
            AddParagraph(p);
        }
Example #28
0
        public void DrawOn(Page page)
        {
            for (int row = 0; row < 7; row++)
            {
                for (int col = 0; col < 7; col++)
                {
                    if (row == 0)
                    {
                        float    offset = (dx - f1.StringWidth(days[col])) / 2;
                        TextLine text   = new TextLine(f1, days[col]);
                        text.SetLocation(x1 + col * dx + offset, x1 + row * dy);
                        text.DrawOn(page);
                        // Draw the line separating the title from the dates.
                        Line line = new Line(
                            x1,
                            y1 + dx / 4,
                            x1 + 7 * dx,
                            y1 + dx / 4);
                        line.SetWidth(0.5f);
                        line.DrawOn(page);
                    }
                    else
                    {
                        int day_of_month = ((7 * row + col) - 6) - day_of_week;
                        if (day_of_month > 0 && day_of_month <= days_in_month)
                        {
                            String   s1     = day_of_month.ToString();
                            float    offset = (dx - f2.StringWidth(s1)) / 2;
                            TextLine text   = new TextLine(f2, s1);
                            text.SetLocation(x1 + col * dx + offset, y1 + row * dy);
                            text.DrawOn(page);

                            page.SetPenWidth(1.5f);
                            page.SetPenColor(Color.blue);
                            page.DrawEllipse(x1 + col * dx + dx / 2, y1 + row * dy - dy / 5, 8f, 8f);
                        }
                    }
                }
            }
        }
Example #29
0
        public void DrawString(Font font1, Font font2, string str, float x, float y)
        {
            bool          flag          = true;
            StringBuilder stringBuilder = new StringBuilder();

            for (int i = 0; i < str.Length; i++)
            {
                int num = (int)str[i];
                if ((font1.isCJK && num >= 19968 && num <= 40908) || (!font1.isCJK && font1.unicodeToGID[num] != 0))
                {
                    if (!flag)
                    {
                        string str2 = stringBuilder.ToString();
                        this.DrawString(font2, str2, x, y);
                        x            += font2.StringWidth(str2);
                        stringBuilder = new StringBuilder();
                        flag          = true;
                    }
                }
                else
                {
                    if (flag)
                    {
                        string str3 = stringBuilder.ToString();
                        this.DrawString(font1, str3, x, y);
                        x            += font1.StringWidth(str3);
                        stringBuilder = new StringBuilder();
                        flag          = false;
                    }
                }
                stringBuilder.Append((char)num);
            }
            if (flag)
            {
                this.DrawString(font1, stringBuilder.ToString(), x, y);
                return;
            }
            this.DrawString(font2, stringBuilder.ToString(), x, y);
        }
Example #30
0
        private String[] TokenizeCJK(String str, float textWidth)
        {
            List <String> list = new List <String>();
            StringBuilder buf  = new StringBuilder();

            for (int i = 0; i < str.Length; i++)
            {
                char ch = str[i];
                if (font.StringWidth(fallbackFont, buf.ToString()) < textWidth)
                {
                    buf.Append(ch);
                }
                else
                {
                    list.Add(buf.ToString());
                    buf.Length = 0;
                }
            }
            if (buf.ToString().Length > 0)
            {
                list.Add(buf.ToString());
            }
            return(list.ToArray());
        }
Example #31
0
 /**
  *  Returns the width of this TextLine.
  *
  *  @return the width.
  */
 public float GetWidth()
 {
     return(font.StringWidth(fallbackFont, text));
 }
Example #32
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));
            }
        }
Example #33
0
 private void UnderlineText(
     Page page, Font font, String text, float x, float y)
 {
     float descent = font.GetDescent();
     page.AddBMC(StructElem.SPAN, Single.space, Single.space);
     page.SetPenWidth(font.underlineThickness);
     page.MoveTo(x, y + descent);
     page.LineTo(x + font.StringWidth(text), y + descent);
     page.StrokePath();
     page.AddEMC();
 }
Example #34
0
 private void StrikeoutText(
     Page page, Font font, String text, float x, float y)
 {
     page.AddBMC(StructElem.SPAN, Single.space, Single.space);
     page.SetPenWidth(font.underlineThickness);
     page.MoveTo(x, y - font.GetAscent()/3f);
     page.LineTo(x + font.StringWidth(text), y - font.GetAscent()/3f);
     page.StrokePath();
     page.AddEMC();
 }