public TextFrame(List <TextLine> paragraphs) { this.paragraphs = new List <TextLine>(paragraphs); this.font = paragraphs[0].font; this.leading = font.GetBodyHeight(); this.paragraphLeading = 2 * leading; this.beginParagraphPoints = new List <float[]>(); Font fallbackFont = paragraphs[0].fallbackFont; if (fallbackFont != null && (fallbackFont.GetBodyHeight() > this.leading)) { this.leading = fallbackFont.GetBodyHeight(); } this.paragraphs.Reverse(); }
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); }
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, " "); }
/** * 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 }); }
/** * 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() }); }
private float[] DrawTextAndBorders(Page page) { float textAreaWidth = width - (font.StringWidth("w") + 2 * margin); List <String> textLines = new List <String>(); String[] lines = text.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None); foreach (String line in lines) { if (font.StringWidth(line) < textAreaWidth) { textLines.Add(line); } else { reformat(line, textAreaWidth, textLines); } } lines = textLines.ToArray(); float lineHeight = font.GetBodyHeight() + spacing; float xText; float yText = y + font.ascent + margin; if ((lines.Length * lineHeight) > this.height) { this.height = lines.Length * lineHeight; } if (page != null) { if (GetBgColor() != Color.transparent) { DrawBackground(page); } page.SetPenColor(this.pen); page.SetBrushColor(this.brush); page.SetPenWidth(this.font.underlineThickness); } if (height > 0f) { if (valign == Align.BOTTOM) { yText += height - lines.Length * lineHeight; } else if (valign == Align.CENTER) { yText += (height - lines.Length * lineHeight) / 2; } for (int i = 0; i < lines.Length; i++) { if (GetTextAlignment() == Align.RIGHT) { xText = (x + width) - (font.StringWidth(lines[i]) + margin); } else if (GetTextAlignment() == Align.CENTER) { xText = x + (width - font.StringWidth(lines[i])) / 2; } else { // Align.LEFT xText = x + margin; } if (yText + font.GetBodyHeight() + spacing + font.descent >= y + height && i < (lines.Length - 1)) { String str = lines[i]; int index = str.LastIndexOf(' '); if (index != -1) { lines[i] = str.Substring(0, index) + " ..."; } else { lines[i] = str + " ..."; } } if (yText + font.descent < y + height) { if (page != null) { DrawText(page, font, fallbackFont, lines[i], xText, yText, colors); } yText += font.GetBodyHeight() + spacing; } } } else { for (int i = 0; i < lines.Length; i++) { if (GetTextAlignment() == Align.RIGHT) { xText = (x + width) - (font.StringWidth(lines[i]) + margin); } else if (GetTextAlignment() == Align.CENTER) { xText = x + (width - font.StringWidth(lines[i])) / 2; } else { // Align.LEFT xText = x + margin; } if (page != null) { DrawText(page, font, fallbackFont, lines[i], xText, yText, colors); } yText += font.GetBodyHeight() + spacing; } height = yText - (y + font.ascent + margin); } if (page != null) { DrawBorders(page); } return(new float[] { x + width, y + height }); }
private TextBlock DrawText(Page page) { List <String> list = new List <String>(); StringBuilder buf = new StringBuilder(); String[] lines = text.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None); foreach (String line in lines) { if (IsCJK(line)) { buf.Length = 0; for (int i = 0; i < line.Length; i++) { Char ch = line[i]; if (font.StringWidth(fallbackFont, buf.ToString() + ch) < this.w) { buf.Append(ch); } else { list.Add(buf.ToString()); buf.Length = 0; buf.Append(ch); } } if (!buf.ToString().Trim().Equals("")) { list.Add(buf.ToString().Trim()); } } else { if (font.StringWidth(fallbackFont, line) < this.w) { list.Add(line); } else { buf.Length = 0; String[] tokens = Regex.Split(line, @"\s+"); foreach (String token in tokens) { if (font.StringWidth(fallbackFont, buf.ToString() + " " + token) < this.w) { buf.Append(" " + token); } else { list.Add(buf.ToString().Trim()); buf.Length = 0; buf.Append(token); } } if (!buf.ToString().Trim().Equals("")) { list.Add(buf.ToString().Trim()); } } } } lines = list.ToArray(); float x_text; float y_text = y + font.GetAscent(); for (int i = 0; i < lines.Length; i++) { if (textAlign == Align.LEFT) { x_text = x; } else if (textAlign == Align.RIGHT) { x_text = (x + this.w) - (font.StringWidth(fallbackFont, lines[i])); } else if (textAlign == Align.CENTER) { x_text = x + (this.w - font.StringWidth(fallbackFont, lines[i])) / 2; } else { throw new Exception("Invalid text alignment option."); } if (page != null) { page.DrawString( font, fallbackFont, lines[i], x_text, y_text); } if (i < (lines.Length - 1)) { y_text += font.GetBodyHeight() + space; } else { y_text += font.GetDescent() + space; } } this.h = y_text - y; return(this); }
private void DrawText(Page page) { page.SetPenColor(this.pen); page.SetBrushColor(this.brush); page.SetPenWidth(this.font.underlineThickness); float textAreaWidth = width - 2 * margin; List <String> list = new List <String>(); StringBuilder buf = new StringBuilder(); String[] lines = Regex.Split(text, "\n"); foreach (String line in lines) { if (font.StringWidth(line) < textAreaWidth) { list.Add(line); } else { buf.Length = 0; String[] tokens = Regex.Split(line, "\\s+"); foreach (String token in tokens) { if (font.StringWidth(buf.ToString() + " " + token) < textAreaWidth) { buf.Append(" " + token); } else { list.Add(buf.ToString().Trim()); buf.Length = 0; buf.Append(token); } } if (!buf.ToString().Trim().Equals("")) { list.Add(buf.ToString().Trim()); } } } lines = list.ToArray(); float lineHeight = font.GetBodyHeight() + spacing; float x_text; float y_text = y + font.ascent + margin; if (valign == TextAlign.BOTTOM) { y_text += height - lines.Length * lineHeight; } else if (valign == TextAlign.CENTER) { y_text += (height - lines.Length * lineHeight) / 2f; } for (int i = 0; i < lines.Length; i++) { if (GetTextAlignment() == Align.RIGHT) { x_text = (x + width) - (font.StringWidth(lines[i]) + margin); } else if (GetTextAlignment() == Align.CENTER) { x_text = x + (width - font.StringWidth(lines[i])) / 2f; } else { // Align.LEFT x_text = x + margin; } if (y_text + font.GetBodyHeight() + spacing + font.GetDescent() >= y + height && i < (lines.Length - 1)) { String str = lines[i]; int index = str.LastIndexOf(' '); if (index != -1) { lines[i] = str.Substring(0, index) + " ..."; } else { lines[i] = str + " ..."; } } if (y_text + font.GetDescent() < y + height) { if (fallbackFont == null) { if (colors == null) { page.DrawString(font, lines[i], x_text, y_text); } else { page.DrawString(font, lines[i], x_text, y_text, colors); } } else { page.DrawString(font, fallbackFont, lines[i], x_text, y_text); } float lineLength = font.StringWidth(lines[i]); 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 / 4f; page.MoveTo(x_text, y_text - y_adjust); page.LineTo(x_text + lineLength, y_text - y_adjust); page.StrokePath(); } y_text += font.GetBodyHeight() + spacing; } } }
private float[] DrawTextAndBorders(Page page, bool draw) { float textAreaWidth = width - (font.StringWidth("w") + 2 * margin); List <String> list = new List <String>(); StringBuilder buf = new StringBuilder(); String[] lines = text.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None); for (int i = 0; i < lines.Length; i++) { String line = lines[i]; if (font.StringWidth(line) < textAreaWidth) { list.Add(line); } else { buf.Length = 0; for (int j = 0; j < line.Length; j++) { buf.Append(line[j]); String str = buf.ToString(); if (font.StringWidth(str) > textAreaWidth) { if ((str[str.Length - 1] == ' ') || Regex.Split(str, @"\s+").Length <= 1) { list.Add(str.TrimEnd()); } else { list.Add(str.Substring(0, str.LastIndexOf(' '))); while (line[j] != ' ') { j -= 1; } } buf.Length = 0; } } if (buf.Length > 0) { list.Add(buf.ToString()); } } } lines = list.ToArray(); float lineHeight = font.GetBodyHeight() + spacing; float x_text; float y_text = y + font.ascent + margin; if ((lines.Length * lineHeight) > this.height) { this.height = lines.Length * lineHeight; } if (draw) { if (GetBgColor() != Color.transparent) { DrawBackground(page); } page.SetPenColor(this.pen); page.SetBrushColor(this.brush); page.SetPenWidth(this.font.underlineThickness); } if (height > 0f) { if (valign == Align.BOTTOM) { y_text += height - lines.Length * lineHeight; } else if (valign == Align.CENTER) { y_text += (height - lines.Length * lineHeight) / 2; } for (int i = 0; i < lines.Length; i++) { if (GetTextAlignment() == Align.RIGHT) { x_text = (x + width) - (font.StringWidth(lines[i]) + margin); } else if (GetTextAlignment() == Align.CENTER) { x_text = x + (width - font.StringWidth(lines[i])) / 2; } else { // Align.LEFT x_text = x + margin; } if (y_text + font.GetBodyHeight() + spacing + font.GetDescent() >= y + height && i < (lines.Length - 1)) { String str = lines[i]; int index = str.LastIndexOf(' '); if (index != -1) { lines[i] = str.Substring(0, index) + " ..."; } else { lines[i] = str + " ..."; } } if (y_text + font.GetDescent() < y + height) { if (draw) { DrawText(page, font, fallbackFont, lines[i], x_text, y_text, colors); } y_text += font.GetBodyHeight() + spacing; } } } else { for (int i = 0; i < lines.Length; i++) { if (GetTextAlignment() == Align.RIGHT) { x_text = (x + width) - (font.StringWidth(lines[i]) + margin); } else if (GetTextAlignment() == Align.CENTER) { x_text = x + (width - font.StringWidth(lines[i])) / 2; } else { // Align.LEFT x_text = x + margin; } if (draw) { DrawText(page, font, fallbackFont, lines[i], x_text, y_text, colors); } y_text += font.GetBodyHeight() + spacing; } height = y_text - (y + font.ascent + margin); } if (draw) { DrawBorders(page); } return(new float[] { x + width, y + height }); }
/** * Draws this CheckBox on the specified Page. * * @param page the Page where the CheckBox is to be drawn. */ public float[] DrawOn(Page page) { page.AddBMC(StructElem.SPAN, language, altDescription, actualText); this.w = font.GetAscent(); this.h = this.w; this.penWidth = this.w / 15; this.checkWidth = this.w / 5; float y_box = y - font.GetAscent(); page.SetPenWidth(penWidth); page.SetPenColor(boxColor); page.SetLinePattern("[] 0"); page.DrawRect(x, y_box, w, h); if (mark == Mark.CHECK || mark == Mark.X) { page.SetPenWidth(checkWidth); page.SetPenColor(checkColor); if (mark == Mark.CHECK) { // Draw check mark page.MoveTo(x + checkWidth, y_box + h / 2); page.LineTo(x + w / 6 + checkWidth, (y_box + h) - 4f * checkWidth / 3f); page.LineTo((x + w) - checkWidth, y_box + checkWidth); page.StrokePath(); } else { // Draw 'X' mark page.MoveTo(x + checkWidth, y_box + checkWidth); page.LineTo((x + w) - checkWidth, (y_box + h) - checkWidth); page.MoveTo((x + w) - checkWidth, y_box + checkWidth); page.LineTo(x + checkWidth, (y_box + h) - checkWidth); page.StrokePath(); } } if (uri != null) { page.SetBrushColor(Color.blue); } page.DrawString(font, label, x + 3f * w / 2f, y); page.SetPenWidth(0f); page.SetPenColor(Color.black); 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 + 3f * w / 2f, page.height - y, x + 3f * w / 2f + font.StringWidth(label), page.height - (y - font.GetAscent()), language, altDescription, actualText)); } return(new float[] { x + 3f * w + font.StringWidth(label), y + font.GetBodyHeight() }); }