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)); }