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) { float xText = x; float yText = y + font.ascent; while (paragraphs.Count > 0) { // The paragraphs are reversed so we can efficiently remove the first one: TextLine textLine = paragraphs[paragraphs.Count - 1]; paragraphs.RemoveAt(paragraphs.Count - 1); textLine.SetLocation(xText, yText); beginParagraphPoints.Add(new float[] { xText, yText }); while (true) { textLine = DrawLineOnPage(textLine, page); if (textLine.GetText().Equals("")) { break; } yText = textLine.Advance(leading); if (yText + font.descent >= (y + h)) { // The paragraphs are reversed so we can efficiently add new first paragraph: paragraphs.Add(textLine); if (page != null && drawBorder) { Box box = new Box(); box.SetLocation(x, y); box.SetSize(w, h); box.DrawOn(page); } return(new float[] { x + w, y + h }); } } xText = x; yText += paragraphLeading; } if (page != null && drawBorder) { Box box = new Box(); box.SetLocation(x, y); box.SetSize(w, h); box.DrawOn(page); } return(new float[] { x + w, y + h }); }
public float[] DrawOn(Page page) { this.xText = x1; this.yText = y1 + 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.text); } for (int i = 0; i < numberOfTextLines; i++) { TextLine textLine = paragraph.list[i]; if (i == 0) { beginParagraphPoints.Add(new float[] { xText, yText }); } textLine.SetAltDescription((i == 0) ? buf.ToString() : Single.space); textLine.SetActualText((i == 0) ? buf.ToString() : Single.space); float[] point = DrawTextLine(page, xText, yText, textLine); xText = point[0]; if (textLine.GetTrailingSpace()) { xText += spaceBetweenTextLines; } yText = point[1]; } xText = x1; yText += paragraphLeading; } float height = ((yText - paragraphLeading) - y1) + font.descent; if (page != null && drawBorder) { Box box = new Box(); box.SetLocation(x1, y1); box.SetSize(width, height); box.DrawOn(page); } return(new float[] { x1 + width, y1 + height }); }
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 }; }
/** * Draws this form 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) { foreach (Field field in fields) { if (field.format) { field.values = Format(field.values[0], field.values[1], this.f2, this.rowLength); field.altDescription = new String[field.values.Length]; field.actualText = new String[field.values.Length]; for (int i = 0; i < field.values.Length; i++) { field.altDescription[i] = field.values[i]; field.actualText[i] = field.values[i]; } } if (field.x == 0f) { numberOfRows += field.values.Length; } } if (numberOfRows == 0) { return(new float[] { x, y }); } float boxHeight = rowHeight * numberOfRows; Box box = new Box(); box.SetLocation(x, y); box.SetSize(rowLength, boxHeight); if (page != null) { box.DrawOn(page); } float yField = 0f; int rowSpan = 1; float yRow = 0; foreach (Field field in fields) { if (field.x == 0f) { yRow += rowSpan * rowHeight; rowSpan = field.values.Length; } yField = yRow; for (int i = 0; i < field.values.Length; i++) { if (page != null) { 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 + font.descent, yField - font.descent) .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.descent + font.StringWidth(field.values[i]), yField + font.descent, }); if (page != null && i == (field.values.Length - 1)) { new Line(0f, 0f, rowLength, 0f) .PlaceIn(box, 0f, yField) .DrawOn(page); if (field.x != 0f) { new Line(0f, -(field.values.Length - 1) * rowHeight, 0f, 0f) .PlaceIn(box, field.x, yField) .DrawOn(page); } } } yField += rowHeight; } } return(new float[] { x + rowLength, y + boxHeight }); }
private float[] DrawText(Page page) { List <String> list = new List <String>(); String[] lines = text.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None); foreach (String line in lines) { if (IsCJK(line)) { StringBuilder buf = new StringBuilder(); 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); } } String str = buf.ToString().Trim(); if (!str.Equals("")) { list.Add(str); } } else { if (font.StringWidth(fallbackFont, line) < this.w) { list.Add(line); } else { StringBuilder buf = new StringBuilder(); String[] tokens = TextUtils.SplitTextIntoTokens(line, font, fallbackFont, this.w); foreach (String token in tokens) { if (font.StringWidth(fallbackFont, (buf.ToString() + " " + token).Trim()) < this.w) { buf.Append(" " + token); } else { list.Add(buf.ToString().Trim()); buf.Length = 0; buf.Append(token); } } String str = buf.ToString().Trim(); if (!str.Equals("")) { list.Add(str); } } } } lines = list.ToArray(); float xText; float yText = y + font.ascent; for (int i = 0; i < lines.Length; i++) { if (textAlign == Align.LEFT) { xText = x; } else if (textAlign == Align.RIGHT) { xText = (x + this.w) - (font.StringWidth(fallbackFont, lines[i])); } else if (textAlign == Align.CENTER) { xText = 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], xText, yText); } if (i < (lines.Length - 1)) { yText += font.bodyHeight + spaceBetweenLines; } } this.h = (yText - y) + font.descent; if (page != null && drawBorder) { Box box = new Box(); box.SetLocation(x, y); box.SetSize(w, h); box.DrawOn(page); } if (page != null && (uri != null || key != null)) { page.AddAnnotation(new Annotation( uri, key, // The destination name x, y, x + w, y + h, uriLanguage, uriAltDescription, uriActualText)); } return(new float[] { this.x + this.w, this.y + this.h }); }