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 }); }
private void DrawLineOfText( Page page, List <TextLine> list, bool draw) { if (alignment == Align.JUSTIFY) { float sum_of_word_widths = 0f; for (int i = 0; i < list.Count; i++) { TextLine text = list[i]; sum_of_word_widths += text.font.StringWidth(text.GetFallbackFont(), text.str); } float dx = (w - sum_of_word_widths) / (list.Count - 1); for (int i = 0; i < list.Count; i++) { TextLine text = list[i]; text.SetPosition(x1, y1); if (text.GetGoToAction() != null) { page.AddAnnotation(new Annotation( null, // The URI text.GetGoToAction(), // The destination name x, page.height - (y - text.font.ascent), x + text.font.StringWidth(text.GetFallbackFont(), text.GetText()), page.height - (y - text.font.descent), null, null, null)); } if (rotate == 0) { text.SetTextDirection(0); text.DrawOn(page, draw); x1 += text.font.StringWidth(text.GetFallbackFont(), text.str) + dx; } else if (rotate == 90) { text.SetTextDirection(90); text.DrawOn(page, draw); y1 -= text.font.StringWidth(text.GetFallbackFont(), text.str) + dx; } else if (rotate == 270) { text.SetTextDirection(270); text.DrawOn(page, draw); y1 += text.font.StringWidth(text.GetFallbackFont(), text.str) + dx; } } } else { DrawNonJustifiedLine(page, list, draw); } }
private void DrawNonJustifiedLine( Page page, List <TextLine> list, bool draw) { float run_length = 0f; for (int i = 0; i < list.Count; i++) { TextLine text = list[i]; if (i < (list.Count - 1)) { text.str += " "; } run_length += text.font.StringWidth(text.GetFallbackFont(), text.str); } if (alignment == Align.CENTER) { if (rotate == 0) { x1 = x + ((w - run_length) / 2); } else if (rotate == 90) { y1 = y - ((w - run_length) / 2); } else if (rotate == 270) { y1 = y + ((w - run_length) / 2); } } else if (alignment == Align.RIGHT) { if (rotate == 0) { x1 = x + (w - run_length); } else if (rotate == 90) { y1 = y - (w - run_length); } else if (rotate == 270) { y1 = y + (w - run_length); } } for (int i = 0; i < list.Count; i++) { TextLine text = list[i]; text.SetPosition(x1, y1); if (text.GetGoToAction() != null) { page.AddAnnotation(new Annotation( null, // The URI text.GetGoToAction(), // The destination name x, page.height - (y - text.font.ascent), x + text.font.StringWidth(text.GetFallbackFont(), text.GetText()), page.height - (y - text.font.descent), null, null, null)); } if (rotate == 0) { text.SetTextDirection(0); text.DrawOn(page, draw); x1 += text.font.StringWidth(text.GetFallbackFont(), text.str); } else if (rotate == 90) { text.SetTextDirection(90); text.DrawOn(page, draw); y1 -= text.font.StringWidth(text.GetFallbackFont(), text.str); } else if (rotate == 270) { text.SetTextDirection(270); text.DrawOn(page, draw); y1 += text.font.StringWidth(text.GetFallbackFont(), text.str); } } }
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)); }
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 }; }
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); }