public float[] DrawOn(Page page) { if (numberOfRows == 0) { return(new float[] { x, y }); } float boxHeight = rowHeight * numberOfRows; Box box = new Box(); box.SetLocation(x, y); box.SetSize(rowLength, boxHeight); box.DrawOn(page); float field_y = 0f; int row_span = 1; float row_y = 0; foreach (Field field in fields) { if (field.x == 0f) { row_y += row_span * rowHeight; row_span = field.values.Length; } field_y = row_y; for (int i = 0; i < field.values.Length; i++) { Font font = (i == 0) ? f1 : f2; float fontSize = (i == 0) ? labelFontSize : valueFontSize; int color = (i == 0) ? labelColor : valueColor; new TextLine(font, field.values[i]) .SetFontSize(fontSize) .SetColor(color) .PlaceIn(box, field.x + f1.GetDescent(), field_y - font.GetDescent()) .SetAltDescription((i == 0) ? field.altDescription[i] : (field.altDescription[i] + ",")) .SetActualText((i == 0) ? field.actualText[i] : (field.actualText[i] + ",")) .DrawOn(page); endOfLinePoints.Add(new float[] { field.x + f1.GetDescent() + font.StringWidth(field.values[i]), field_y - font.GetDescent(), }); if (i == (field.values.Length - 1)) { new Line(0f, 0f, rowLength, 0f) .PlaceIn(box, 0f, field_y) .DrawOn(page); if (field.x != 0f) { new Line(0f, -(field.values.Length - 1) * rowHeight, 0f, 0f) .PlaceIn(box, field.x, field_y) .DrawOn(page); } } field_y += rowHeight; } } return(new float[] { x + rowLength, y + boxHeight }); }
public float[] DrawOn(Page page, bool draw) { this.x_text = x; this.y_text = y + font.GetAscent(); foreach (Paragraph paragraph in paragraphs) { int numberOfTextLines = paragraph.list.Count; StringBuilder buf = new StringBuilder(); for (int i = 0; i < numberOfTextLines; i++) { TextLine textLine = paragraph.list[i]; buf.Append(textLine.GetText()); } for (int i = 0; i < numberOfTextLines; i++) { TextLine textLine = paragraph.list[i]; if (i == 0) { beginParagraphPoints.Add(new float[] { x_text, y_text }); } textLine.SetAltDescription((i == 0) ? buf.ToString() : Single.space); textLine.SetActualText((i == 0) ? buf.ToString() : Single.space); float[] point = DrawTextLine(page, x_text, y_text, textLine, draw); if (i == (numberOfTextLines - 1)) { endParagraphPoints.Add(new float[] { point[0], point[1] }); } x_text = point[0] + spaceBetweenTextLines; y_text = point[1]; } x_text = x; y_text += paragraphLeading; } return(new float[] { x_text, y_text + font.GetDescent() }); }
private void UnderlineText(Page page, Font font, string text, float x, float y) { float descent = font.GetDescent(); page.SetPenWidth(font.underlineThickness); page.MoveTo(x, y + descent); page.LineTo(x + font.StringWidth(text), y + descent); page.StrokePath(); }
private void UnderlineText( Page page, Font font, String text, float x, float y) { float descent = font.GetDescent(); page.AddBMC(StructElem.SPAN, Single.space, Single.space); page.SetPenWidth(font.underlineThickness); page.MoveTo(x, y + descent); page.LineTo(x + font.StringWidth(text), y + descent); page.StrokePath(); page.AddEMC(); }
/** * Draws this RadioButton 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) { 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.GetDescent() }); }
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 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 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 }); }
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); }
public TextFrame DrawOn(Page page, bool draw) { this.x_text = x; this.y_text = y + font.GetAscent(); Paragraph paragraph = null; for (int i = 0; i < paragraphs.Count; i++) { paragraph = paragraphs[i]; StringBuilder buf = new StringBuilder(); foreach (TextLine textLine in paragraph.list) { buf.Append(textLine.GetText()); buf.Append(Single.space); } int numOfTextLines = paragraph.list.Count; for (int j = 0; j < numOfTextLines; j++) { TextLine textLine = paragraph.list[j]; if (j == 0) { beginParagraphPoints.Add(new float[] { x_text, y_text }); } textLine.SetAltDescription((i == 0) ? buf.ToString() : Single.space); textLine.SetActualText((i == 0) ? buf.ToString() : Single.space); TextLine textLine2 = DrawTextLine(page, x_text, y_text, textLine, draw); if (!textLine2.GetText().Equals("")) { List <Paragraph> theRest = new List <Paragraph>(); Paragraph paragraph2 = new Paragraph(textLine2); j++; while (j < numOfTextLines) { paragraph2.Add(paragraph.list[j]); j++; } theRest.Add(paragraph2); i++; while (i < paragraphs.Count) { theRest.Add(paragraphs[i]); i++; } return(new TextFrame(theRest)); } if (j == (numOfTextLines - 1)) { endParagraphPoints.Add(new float[] { textLine2.x, textLine2.y }); } x_text = textLine2.x; if (textLine.GetTrailingSpace()) { x_text += spaceBetweenTextLines; } y_text = textLine2.y; } x_text = x; y_text += paragraphLeading; } TextFrame textFrame = new TextFrame(null); textFrame.SetLocation(x_text, y_text + font.GetDescent()); return(textFrame); }
/** * Draws this CheckBox 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) { 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.GetDescent() }); }