Beispiel #1
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);
        }
Beispiel #2
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
            });
        }
Beispiel #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();

            String[] tokens = null;
            String   str    = textLine.GetText();

            if (StringIsCJK(str))
            {
                tokens = TokenizeCJK(str, this.w);
            }
            else
            {
                tokens = Regex.Split(textLine.GetText(), @"\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]);
                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 (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;
            }

            return(new float[] { x_text, y_text });
        }