Ejemplo n.º 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 });
        }
Ejemplo n.º 2
0
        private Point DrawParagraphOn(
            Page page, Paragraph paragraph, bool draw)
        {
            List <TextLine> list       = new List <TextLine>();
            float           run_length = 0f;

            for (int i = 0; i < paragraph.list.Count; i++)
            {
                TextLine line = paragraph.list[i];
                if (i == 0)
                {
                    line_height = line.font.body_height + space_between_lines;
                    if (rotate == 0)
                    {
                        y1 += line.font.ascent;
                    }
                    else if (rotate == 90)
                    {
                        x1 += line.font.ascent;
                    }
                    else if (rotate == 270)
                    {
                        x1 -= line.font.ascent;
                    }
                }

                String[] tokens = line.str.Split(new Char[] { ' ', '\r', '\n', '\t' });
                TextLine text   = null;
                for (int j = 0; j < tokens.Length; j++)
                {
                    String str = tokens[j];
                    text = new TextLine(line.font, str);
                    text.SetColor(line.GetColor());
                    text.SetUnderline(line.GetUnderline());
                    text.SetStrikeout(line.GetStrikeout());
                    text.SetURIAction(line.GetURIAction());
                    text.SetGoToAction(line.GetGoToAction());
                    text.SetFallbackFont(line.GetFallbackFont());
                    run_length += line.font.StringWidth(line.GetFallbackFont(), str);
                    if (run_length >= w)
                    {
                        DrawLineOfText(page, list, draw);
                        MoveToNextLine();
                        list.Clear();
                        list.Add(text);
                        run_length = line.font.StringWidth(line.GetFallbackFont(), str + " ");
                    }
                    else
                    {
                        list.Add(text);
                        run_length += line.font.StringWidth(line.GetFallbackFont(), " ");
                    }
                }
            }
            DrawNonJustifiedLine(page, list, draw);

            if (lineBetweenParagraphs)
            {
                return(MoveToNextLine());
            }

            return(MoveToNextParagraph(this.space_between_paragraphs));
        }
Ejemplo n.º 3
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 };
        }
Ejemplo n.º 4
0
        public float[] DrawTextLine(
            Page page, float x, float y, TextLine textLine)
        {
            this.xText = x;
            this.yText = y;

            String[] tokens = null;
            if (StringIsCJK(textLine.text))
            {
                tokens = TokenizeCJK(textLine, this.width);
            }
            else
            {
                tokens = Regex.Split(textLine.text, @"\s+");
            }

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

            for (int i = 0; i < tokens.Length; i++)
            {
                String token      = (i == 0) ? tokens[i] : (Single.space + tokens[i]);
                float  lineWidth  = textLine.font.StringWidth(textLine.fallbackFont, buf.ToString());
                float  tokenWidth = textLine.font.StringWidth(textLine.fallbackFont, token);
                if ((lineWidth + tokenWidth) < (this.x1 + this.width) - this.xText)
                {
                    buf.Append(token);
                }
                else
                {
                    if (page != null)
                    {
                        new TextLine(textLine.font, buf.ToString())
                        .SetFallbackFont(textLine.fallbackFont)
                        .SetLocation(xText, yText + textLine.GetVerticalOffset())
                        .SetColor(textLine.GetColor())
                        .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;
                    xText            = x1;
                    yText           += leading;
                    buf.Length       = 0;
                    buf.Append(tokens[i]);
                }
            }
            if (page != null)
            {
                new TextLine(textLine.font, buf.ToString())
                .SetFallbackFont(textLine.fallbackFont)
                .SetLocation(xText, yText + textLine.GetVerticalOffset())
                .SetColor(textLine.GetColor())
                .SetUnderline(textLine.GetUnderline())
                .SetStrikeout(textLine.GetStrikeout())
                .SetLanguage(textLine.GetLanguage())
                .SetAltDescription(firstTextSegment ? textLine.GetAltDescription() : Single.space)
                .SetActualText(firstTextSegment ? textLine.GetActualText() : Single.space)
                .DrawOn(page);
            }

            return(new float[] {
                xText + textLine.font.StringWidth(textLine.fallbackFont, buf.ToString()),
                yText
            });
        }
Ejemplo n.º 5
0
        public TextLine DrawTextLine(
            Page page, float x_text, float y_text, TextLine textLine, bool draw)
        {
            TextLine textLine2    = null;
            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] : (Single.space + 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 + textLine.GetVerticalOffset())
                        .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 (y_text + font.GetDescent() > (y + h))
                    {
                        i++;
                        while (i < tokens.Length)
                        {
                            buf.Append(Single.space);
                            buf.Append(tokens[i]);
                            i++;
                        }
                        textLine2 = new TextLine(font, buf.ToString());
                        textLine2.SetLocation(x, y_text);
                        return(textLine2);
                    }
                }
            }
            if (draw)
            {
                new TextLine(font, buf.ToString())
                .SetFallbackFont(textLine.GetFallbackFont())
                .SetLocation(x_text - font.StringWidth(fallbackFont, buf.ToString()),
                             y_text + textLine.GetVerticalOffset())
                .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;
            }

            textLine2 = new TextLine(font, "");
            textLine2.SetLocation(x_text, y_text);
            return(textLine2);
        }