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); } }
/** * Draws the point, text and borders of this cell. * */ internal virtual void ImprovedPaint( Page page, float x, float y, float w, float h, string p_text) { if (background != -1) { DrawBackground(page, x, y, w, h); } if (image != null) { image.SetLocation(x + left_padding, y + top_padding); image.DrawOn(page); } DrawBorders(page, x, y, w, h); if (p_text != null) { ImprovedDrawText(page, x, y, w, p_text); } if (point != null) { if (point.align == Align.LEFT) { point.x = x + 2 * point.r; } else if (point.align == Align.RIGHT) { point.x = (x + w) - this.right_padding / 2; } point.y = y + h / 2; page.SetBrushColor(point.GetColor()); if (point.GetURIAction() != null) { page.AddAnnotation(new Annotation( point.GetURIAction(), null, point.x - point.r, page.height - (point.y - point.r), point.x + point.r, page.height - (point.y + point.r), null, null, null)); } page.DrawPoint(point); } }
/** * 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() }); }
/** * 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 yBox = y; page.SetPenWidth(1f); page.SetPenColor(Color.black); page.SetLinePattern("[] 0"); page.SetBrushColor(Color.black); page.DrawCircle(x + r1 + penWidth, yBox + r1 + penWidth, r1); if (this.selected) { page.DrawCircle(x + r1 + penWidth, yBox + r1 + penWidth, r2, Operation.FILL); } if (uri != null) { page.SetBrushColor(Color.blue); } page.DrawString(font, label, x + 3 * r1, y + font.ascent); page.SetPenWidth(0f); page.SetBrushColor(Color.black); page.AddEMC(); if (uri != null) { page.AddAnnotation(new Annotation( uri, null, x + 3 * r1, y, x + 3 * r1 + font.StringWidth(label), y + font.bodyHeight, language, altDescription, actualText)); } return(new float[] { x + 6 * r1 + font.StringWidth(label), y + font.bodyHeight }); }
public float[] DrawOn(Page page) { Annotation annotation = new Annotation( null, null, x, y, x + h, y + h, null, null, null); annotation.fileAttachment = this; page.AddAnnotation(annotation); return(new float[] { this.x + this.h, this.y + this.h }); }
/** * Draws this box 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); page.SetPenWidth(width); page.SetLinePattern(pattern); if (fillShape) { page.SetBrushColor(color); } else { page.SetPenColor(color); } page.MoveTo(x, y); page.LineTo(x + w, y); page.LineTo(x + w, y + h); page.LineTo(x, y + h); if (fillShape) { page.FillPath(); } else { page.ClosePath(); } page.AddEMC(); if (uri != null || key != null) { page.AddAnnotation(new Annotation( uri, key, // The destination name x, y, x + w, y + h, language, altDescription, actualText)); } return(new float[] { x + w, y + h + width }); }
/** * Draws this chart on the specified page. * * @param page the page to draw this chart on. */ public void DrawOn(Page page) { nf.SetMinimumFractionDigits(minFractionDigits); nf.SetMaximumFractionDigits(maxFractionDigits); x2 = x1 + w; y2 = y1; x3 = x2; y3 = y1 + h; x4 = x1; y4 = y3; SetMinAndMaxChartValues(); RoundXAxisMinAndMaxValues(); RoundYAxisMinAndMaxValues(); // Draw chart title page.DrawString( f1, title, x1 + ((w - f1.StringWidth(title)) / 2), y1 + 1.5f * f1.body_height); float top_margin = 2.5f * f1.body_height; float left_margin = GetLongestAxisYLabelWidth() + 2f * f2.body_height; float right_margin = 2f * f2.body_height; float bottom_margin = 2.5f * f2.body_height; x5 = x1 + left_margin; y5 = y1 + top_margin; x6 = x2 - right_margin; y6 = y5; x7 = x6; y7 = y3 - bottom_margin; x8 = x5; y8 = y7; DrawChartBorder(page); DrawInnerBorder(page); DrawHorizontalGridLines(page); DrawVerticalGridLines(page); if (drawXAxisLabels) { DrawXAxisLabels(page); } if (drawYAxisLabels) { DrawYAxisLabels(page); } // Translate the point coordinates for (int i = 0; i < chartData.Count; i++) { List<Point> points = chartData[i]; for (int j = 0; j < points.Count; j++) { Point point = points[j]; point.x = x5 + (point.x - x_min) * (x6 - x5) / (x_max - x_min); point.y = y8 - (point.y - y_min) * (y8 - y5) / (y_max - y_min); if (point.GetURIAction() != null) { page.AddAnnotation(new Annotation( point.GetURIAction(), null, point.x - point.r, page.height - (point.y - point.r), point.x + point.r, page.height - (point.y + point.r), null, null, null)); } } } DrawPathsAndPoints(page, chartData); // Draw the Y axis title page.SetBrushColor(Color.black); page.SetTextDirection(90); page.DrawString( f2, y_axis_title, x1 + f2.body_height, y8 - ((y8 - y5) - f2.StringWidth(y_axis_title)) / 2); // Draw the X axis title page.SetTextDirection(0); page.DrawString( f2, x_axis_title, x5 + ((x6 - x5) - f2.StringWidth(x_axis_title)) / 2, y4 - f2.body_height / 2); page.SetDefaultLineWidth(); page.SetDefaultLinePattern(); page.SetPenColor(Color.black); }
/** * Draws this image 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); x += box_x; y += box_y; page.Append("q\n"); if (degrees == 0) { page.Append(w); page.Append(' '); page.Append(0f); page.Append(' '); page.Append(0f); page.Append(' '); page.Append(h); page.Append(' '); page.Append(x); page.Append(' '); page.Append(page.height - (y + h)); page.Append(" cm\n"); } else if (degrees == 90) { page.Append(h); page.Append(' '); page.Append(0f); page.Append(' '); page.Append(0f); page.Append(' '); page.Append(w); page.Append(' '); page.Append(x); page.Append(' '); page.Append(page.height - y); page.Append(" cm\n"); page.Append("0 -1 1 0 0 0 cm\n"); } else if (degrees == 180) { page.Append(w); page.Append(' '); page.Append(0f); page.Append(' '); page.Append(0f); page.Append(' '); page.Append(h); page.Append(' '); page.Append(x + w); page.Append(' '); page.Append(page.height - y); page.Append(" cm\n"); page.Append("-1 0 0 -1 0 0 cm\n"); } else if (degrees == 270) { page.Append(h); page.Append(' '); page.Append(0f); page.Append(' '); page.Append(0f); page.Append(' '); page.Append(w); page.Append(' '); page.Append(x + h); page.Append(' '); page.Append(page.height - (y + w)); page.Append(" cm\n"); page.Append("0 1 -1 0 0 0 cm\n"); } if (flipUpsideDown) { page.Append("1 0 0 -1 0 0 cm\n"); } page.Append("/Im"); page.Append(objNumber); page.Append(" Do\n"); page.Append("Q\n"); page.AddEMC(); if (uri != null || key != null) { page.AddAnnotation(new Annotation( uri, key, // The destination name x, page.height - y, x + w, page.height - (y + h), language, altDescription, actualText)); } return(new float[] { x + w, y + h }); }
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 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); } }
/** * 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 yBox = y; page.SetPenWidth(penWidth); page.SetPenColor(boxColor); page.SetLinePattern("[] 0"); page.DrawRect(x + this.penWidth, yBox + this.penWidth, 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 + penWidth, yBox + h / 2 + penWidth); page.LineTo((x + w / 6 + checkWidth) + penWidth, ((yBox + h) - 4f * checkWidth / 3f) + penWidth); page.LineTo(((x + w) - checkWidth) + penWidth, (yBox + checkWidth) + penWidth); page.StrokePath(); } else { // Draw 'X' mark page.MoveTo(x + checkWidth + penWidth, yBox + checkWidth + penWidth); page.LineTo(((x + w) - checkWidth) + penWidth, ((yBox + h) - checkWidth) + penWidth); page.MoveTo(((x + w) - checkWidth) + penWidth, (yBox + checkWidth) + penWidth); page.LineTo((x + checkWidth) + penWidth, ((yBox + h) - checkWidth) + penWidth); page.StrokePath(); } } if (uri != null) { page.SetBrushColor(Color.blue); } page.DrawString(font, label, x + 3f * w / 2f, y + font.ascent); page.SetPenWidth(0f); page.SetPenColor(Color.black); page.SetBrushColor(Color.black); page.AddEMC(); if (uri != null) { page.AddAnnotation(new Annotation( uri, null, x + 3f * w / 2f, y, x + 3f * w / 2f + font.StringWidth(label), y + font.bodyHeight, language, altDescription, actualText)); } return(new float[] { x + 3f * w + font.StringWidth(label), y + font.bodyHeight }); }
/** * Draws this text line on the specified page if the draw parameter is true. * * @param page the page to draw this text line on. * @param draw if draw is false - no action is performed. */ internal void DrawOn(Page page, bool draw) { if (page == null || !draw || str == null || str.Equals("")) return; page.SetTextDirection(degrees); x += box_x; y += box_y; page.SetBrushColor(color); page.AddBMC(StructElem.SPAN, language, altDescription, actualText); if (fallbackFont == null) { page.DrawString(font, str, x, y); } else { page.DrawString(font, fallbackFont, str, x, y); } page.AddEMC(); if (underline) { page.SetPenWidth(font.underlineThickness); page.SetPenColor(color); double lineLength = font.StringWidth(str); double radians = Math.PI * degrees / 180.0; double x_adjust = font.underlinePosition * Math.Sin(radians); double y_adjust = font.underlinePosition * Math.Cos(radians); double x2 = x + lineLength * Math.Cos(radians); double y2 = y - lineLength * Math.Sin(radians); page.AddBMC(StructElem.SPAN, language, underlineTTS, underlineTTS); page.MoveTo(x + x_adjust, y + y_adjust); page.LineTo(x2 + x_adjust, y2 + y_adjust); page.StrokePath(); page.AddEMC(); } if (strikeout) { page.SetPenWidth(font.underlineThickness); page.SetPenColor(color); double lineLength = font.StringWidth(str); double radians = Math.PI * degrees / 180.0; double x_adjust = ( font.body_height / 4.0 ) * Math.Sin(radians); double y_adjust = ( font.body_height / 4.0 ) * Math.Cos(radians); double x2 = x + lineLength * Math.Cos(radians); double y2 = y - lineLength * Math.Sin(radians); page.AddBMC(StructElem.SPAN, language, strikeoutTTS, strikeoutTTS); page.MoveTo(x - x_adjust, y - y_adjust); page.LineTo(x2 - x_adjust, y2 - y_adjust); page.StrokePath(); page.AddEMC(); } if (uri != null || key != null) { page.AddAnnotation(new Annotation( uri, key, // The destination name x, page.height - (y - font.ascent), x + font.StringWidth(str), page.height - (y - font.descent), uriLanguage, uriAltDescription, uriActualText)); } page.SetTextDirection(0); }
/** * 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() }; }
/** * Draws this box on the specified page. * * @param page the page to draw this box on. */ public void DrawOn(Page page) { page.AddBMC(StructElem.SPAN, language, altDescription, actualText); page.SetPenWidth(width); page.SetLinePattern(pattern); if (fill_shape) { page.SetBrushColor(color); } else { page.SetPenColor(color); } page.MoveTo(x, y); page.LineTo(x + w, y); page.LineTo(x + w, y + h); page.LineTo(x, y + h); if (fill_shape) { page.FillPath(); } else { page.ClosePath(); } page.AddEMC(); if (uri != null || key != null) { page.AddAnnotation(new Annotation( uri, key, // The destination name x, page.height - y, x + w, page.height - (y + h), language, altDescription, actualText)); } }
/** * Draws this image on the specified page. * * @param page the page to draw this image on. */ public void DrawOn(Page page) { page.AddBMC(StructElem.SPAN, language, altDescription, actualText); x += box_x; y += box_y; page.Append("q\n"); if (rotate90) { page.Append(h); page.Append(' '); page.Append(0f); page.Append(' '); page.Append(0f); page.Append(' '); page.Append(w); page.Append(' '); page.Append(x); page.Append(' '); page.Append(page.height - y); page.Append(" cm\n"); // Rotate the image 2x45 degrees clockwise. The magic number is Math.sqrt(0.5): page.Append("0.7071067811 -0.7071067811 0.7071067811 0.7071067811 0.0 0.0 cm\n"); page.Append("0.7071067811 -0.7071067811 0.7071067811 0.7071067811 0.0 0.0 cm\n"); } else { page.Append(w); page.Append(' '); page.Append(0f); page.Append(' '); page.Append(0f); page.Append(' '); page.Append(h); page.Append(' '); page.Append(x); page.Append(' '); page.Append(page.height - (y + h)); page.Append(" cm\n"); } page.Append("/Im"); page.Append(objNumber); page.Append(" Do\n"); page.Append("Q\n"); page.AddEMC(); if (uri != null || key != null) { page.AddAnnotation(new Annotation( uri, key, // The destination name x, page.height - y, x + w, page.height - (y + h), language, altDescription, actualText)); } }
private void ImprovedDrawText( Page page, float x, float y, float cell_w, string p_text) { // verificando se precisa cortar o texto para caber dentro da célula string v_text; float v_renderedsize = font.StringWidth(p_text); if (v_renderedsize > cell_w) { v_text = p_text.Substring(0, (int)(((float)(cell_w * p_text.Length)) / v_renderedsize)); v_renderedsize = font.StringWidth(v_text); } else v_text = p_text; float x_text; float y_text = y + font.ascent + this.top_padding; page.SetPenColor(pen); page.SetBrushColor(brush); if (GetTextAlignment() == Align.RIGHT) { if (compositeTextLine == null) { x_text = (x + cell_w) - (v_renderedsize + this.right_padding); page.AddBMC(StructElem.SPAN, Single.space, Single.space); page.DrawString(font, fallbackFont, v_text, x_text, y_text); page.AddEMC(); if (GetUnderline()) { UnderlineText(page, font, v_text, x_text, y_text); } if (GetStrikeout()) { StrikeoutText(page, font, v_text, x_text, y_text); } } else { x_text = (x + cell_w) - (v_renderedsize + this.right_padding); compositeTextLine.SetPosition(x_text, y_text); page.AddBMC(StructElem.SPAN, Single.space, Single.space); compositeTextLine.DrawOn(page); page.AddEMC(); } } else if (GetTextAlignment() == Align.CENTER) { if (compositeTextLine == null) { x_text = x + this.left_padding + (((cell_w - (left_padding + right_padding)) - v_renderedsize) / 2); page.AddBMC(StructElem.SPAN, Single.space, Single.space); page.DrawString(font, fallbackFont, v_text, x_text, y_text); page.AddEMC(); if (GetUnderline()) { UnderlineText(page, font, v_text, x_text, y_text); } if (GetStrikeout()) { StrikeoutText(page, font, v_text, x_text, y_text); } } else { x_text = x + this.left_padding + (((cell_w - (left_padding + right_padding)) - v_renderedsize) / 2); compositeTextLine.SetPosition(x_text, y_text); page.AddBMC(StructElem.SPAN, Single.space, Single.space); compositeTextLine.DrawOn(page); page.AddEMC(); } } else if (GetTextAlignment() == Align.LEFT) { x_text = x + this.left_padding; if (compositeTextLine == null) { page.AddBMC(StructElem.SPAN, Single.space, Single.space); page.DrawString(font, fallbackFont, v_text, x_text, y_text); page.AddEMC(); if (GetUnderline()) { UnderlineText(page, font, v_text, x_text, y_text); } if (GetStrikeout()) { StrikeoutText(page, font, v_text, x_text, y_text); } } else { compositeTextLine.SetPosition(x_text, y_text); page.AddBMC(StructElem.SPAN, Single.space, Single.space); compositeTextLine.DrawOn(page); page.AddEMC(); } } else { throw new Exception("Invalid Text Alignment!"); } if (uri != null) { float w = (compositeTextLine != null) ? compositeTextLine.GetWidth() : v_renderedsize; // Please note: The font descent is a negative number. page.AddAnnotation(new Annotation( uri, null, x_text, (page.height - y_text) + font.descent, x_text + w, (page.height - y_text) + font.ascent, null, null, null)); } }
private void DrawText( Page page, float x, float y, float cell_w) { float x_text; float y_text = y + font.ascent + this.top_padding; page.SetPenColor(pen); page.SetBrushColor(brush); if (GetTextAlignment() == Align.RIGHT) { if (compositeTextLine == null) { x_text = (x + cell_w) - (font.StringWidth(text) + this.right_padding); page.AddBMC(StructElem.SPAN, Single.space, Single.space); page.DrawString(font, fallbackFont, text, x_text, y_text); page.AddEMC(); if (GetUnderline()) { UnderlineText(page, font, text, x_text, y_text); } if (GetStrikeout()) { StrikeoutText(page, font, text, x_text, y_text); } } else { x_text = (x + cell_w) - (compositeTextLine.GetWidth() + this.right_padding); compositeTextLine.SetPosition(x_text, y_text); page.AddBMC(StructElem.SPAN, Single.space, Single.space); compositeTextLine.DrawOn(page); page.AddEMC(); } } else if (GetTextAlignment() == Align.CENTER) { if (compositeTextLine == null) { x_text = x + this.left_padding + (((cell_w - (left_padding + right_padding)) - font.StringWidth(text)) / 2); page.AddBMC(StructElem.SPAN, Single.space, Single.space); page.DrawString(font, fallbackFont, text, x_text, y_text); page.AddEMC(); if (GetUnderline()) { UnderlineText(page, font, text, x_text, y_text); } if (GetStrikeout()) { StrikeoutText(page, font, text, x_text, y_text); } } else { x_text = x + this.left_padding + (((cell_w - (left_padding + right_padding)) - compositeTextLine.GetWidth()) / 2); compositeTextLine.SetPosition(x_text, y_text); page.AddBMC(StructElem.SPAN, Single.space, Single.space); compositeTextLine.DrawOn(page); page.AddEMC(); } } else if (GetTextAlignment() == Align.LEFT) { x_text = x + this.left_padding; if (compositeTextLine == null) { page.AddBMC(StructElem.SPAN, Single.space, Single.space); page.DrawString(font, fallbackFont, text, x_text, y_text); page.AddEMC(); if (GetUnderline()) { UnderlineText(page, font, text, x_text, y_text); } if (GetStrikeout()) { StrikeoutText(page, font, text, x_text, y_text); } } else { compositeTextLine.SetPosition(x_text, y_text); page.AddBMC(StructElem.SPAN, Single.space, Single.space); compositeTextLine.DrawOn(page); page.AddEMC(); } } else { throw new Exception("Invalid Text Alignment!"); } if (uri != null) { float w = (compositeTextLine != null) ? compositeTextLine.GetWidth() : font.StringWidth(text); // Please note: The font descent is a negative number. page.AddAnnotation(new Annotation( uri, null, x_text, (page.height - y_text) + font.descent, x_text + w, (page.height - y_text) + font.ascent, null, null, null)); } }
/** * Draws the point, text and borders of this cell. * */ internal virtual void Paint( Page page, float x, float y, float w, float h) { if (background != -1) { DrawBackground(page, x, y, w, h); } if (image != null) { image.SetLocation(x + left_padding, y + top_padding); image.DrawOn(page); } DrawBorders(page, x, y, w, h); if (text != null) { DrawText(page, x, y, w); } if (point != null) { if (point.align == Align.LEFT) { point.x = x + 2*point.r; } else if (point.align == Align.RIGHT) { point.x = (x + w) - this.right_padding/2; } point.y = y + h/2; page.SetBrushColor(point.GetColor()); if (point.GetURIAction() != null) { page.AddAnnotation(new Annotation( point.GetURIAction(), null, point.x - point.r, page.height - (point.y - point.r), point.x + point.r, page.height - (point.y + point.r), null, null, null)); } page.DrawPoint(point); } }
/** * Draws this text line on the specified page if the draw parameter is true. * * @param page the page to draw this text line on. * @param draw if draw is false - no action is performed. * @return x and y coordinates of the bottom right corner of this component. * @throws Exception */ internal float[] DrawOn(Page page, bool draw) { if (page == null || !draw || str == null || str.Equals("")) { return(new float[] { x, y }); } page.SetTextDirection(degrees); x += box_x; y += box_y; page.SetBrushColor(color); page.AddBMC(StructElem.SPAN, language, altDescription, actualText); if (fallbackFont == null) { page.DrawString(font, str, x, y); } else { page.DrawString(font, fallbackFont, str, x, y); } page.AddEMC(); double radians = Math.PI * degrees / 180.0; if (underline) { page.SetPenWidth(font.underlineThickness); page.SetPenColor(color); double lineLength = font.StringWidth(str); double x_adjust = font.underlinePosition * Math.Sin(radians) + verticalOffset; double y_adjust = font.underlinePosition * Math.Cos(radians) + verticalOffset; double x2 = x + lineLength * Math.Cos(radians); double y2 = y - lineLength * Math.Sin(radians); page.AddBMC(StructElem.SPAN, language, underlineTTS, underlineTTS); page.MoveTo(x + x_adjust, y + y_adjust); page.LineTo(x2 + x_adjust, y2 + y_adjust); page.StrokePath(); page.AddEMC(); } if (strikeout) { page.SetPenWidth(font.underlineThickness); page.SetPenColor(color); double lineLength = font.StringWidth(str); double x_adjust = (font.body_height / 4.0) * Math.Sin(radians); double y_adjust = (font.body_height / 4.0) * Math.Cos(radians); double x2 = x + lineLength * Math.Cos(radians); double y2 = y - lineLength * Math.Sin(radians); page.AddBMC(StructElem.SPAN, language, strikeoutTTS, strikeoutTTS); page.MoveTo(x - x_adjust, y - y_adjust); page.LineTo(x2 - x_adjust, y2 - y_adjust); page.StrokePath(); page.AddEMC(); } if (uri != null || key != null) { page.AddAnnotation(new Annotation( uri, key, // The destination name x, page.height - (y - font.ascent), x + font.StringWidth(str), page.height - (y - font.descent), uriLanguage, uriAltDescription, uriActualText)); } page.SetTextDirection(0); float len = font.StringWidth(str); double x_max = Math.Max((double)x, x + len * Math.Cos(radians)); double y_max = Math.Max((double)y, y - len * Math.Sin(radians)); return(new float[] { (float)x_max, (float)y_max }); }
/** * 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() }; }
/** * Draws the point, text and borders of this cell. */ internal void Paint( Page page, float x, float y, float w, float h) { if (background != -1) { DrawBackground(page, x, y, w, h); } if (image != null) { if (GetTextAlignment() == Align.LEFT) { image.SetLocation(x + leftPadding, y + topPadding); image.DrawOn(page); } else if (GetTextAlignment() == Align.CENTER) { image.SetLocation((x + w / 2f) - image.GetWidth() / 2f, y + topPadding); image.DrawOn(page); } else if (GetTextAlignment() == Align.RIGHT) { image.SetLocation((x + w) - (image.GetWidth() + leftPadding), y + topPadding); image.DrawOn(page); } } if (barCode != null) { try { if (GetTextAlignment() == Align.LEFT) { barCode.DrawOnPageAtLocation(page, x + leftPadding, y + topPadding); } else if (GetTextAlignment() == Align.CENTER) { float barcodeWidth = barCode.DrawOn(null)[0]; barCode.DrawOnPageAtLocation(page, (x + w / 2f) - barcodeWidth / 2f, y + topPadding); } else if (GetTextAlignment() == Align.RIGHT) { float barcodeWidth = barCode.DrawOn(null)[0]; barCode.DrawOnPageAtLocation(page, (x + w) - (barcodeWidth + leftPadding), y + topPadding); } } catch (Exception e) { Console.WriteLine(e.ToString()); } } if (textBlock != null) { textBlock.SetLocation(x + leftPadding, y + topPadding); textBlock.DrawOn(page); } DrawBorders(page, x, y, w, h); if (text != null && !text.Equals("")) { DrawText(page, x, y, w, h); } if (point != null) { if (point.align == Align.LEFT) { point.x = x + 2 * point.r; } else if (point.align == Align.RIGHT) { point.x = (x + w) - this.rightPadding / 2; } point.y = y + h / 2; page.SetBrushColor(point.GetColor()); if (point.GetURIAction() != null) { page.AddAnnotation(new Annotation( point.GetURIAction(), null, point.x - point.r, point.y - point.r, point.x + point.r, point.y + point.r, null, null, null)); } page.DrawPoint(point); } if (drawable != null) { drawable.SetPosition(x + leftPadding, y + topPadding); drawable.DrawOn(page); } }
private void ImprovedDrawText( Page page, float x, float y, float cell_w, string p_text) { // verificando se precisa cortar o texto para caber dentro da célula string v_text; float v_renderedsize = font.StringWidth(p_text); if (v_renderedsize > cell_w) { v_text = p_text.Substring(0, (int)(((float)(cell_w * p_text.Length)) / v_renderedsize)); v_renderedsize = font.StringWidth(v_text); } else { v_text = p_text; } float x_text; float y_text = y + font.ascent + this.top_padding; page.SetPenColor(pen); page.SetBrushColor(brush); if (GetTextAlignment() == Align.RIGHT) { if (compositeTextLine == null) { x_text = (x + cell_w) - (v_renderedsize + this.right_padding); page.AddBMC(StructElem.SPAN, Single.space, Single.space); page.DrawString(font, fallbackFont, v_text, x_text, y_text); page.AddEMC(); if (GetUnderline()) { UnderlineText(page, font, v_text, x_text, y_text); } if (GetStrikeout()) { StrikeoutText(page, font, v_text, x_text, y_text); } } else { x_text = (x + cell_w) - (v_renderedsize + this.right_padding); compositeTextLine.SetPosition(x_text, y_text); page.AddBMC(StructElem.SPAN, Single.space, Single.space); compositeTextLine.DrawOn(page); page.AddEMC(); } } else if (GetTextAlignment() == Align.CENTER) { if (compositeTextLine == null) { x_text = x + this.left_padding + (((cell_w - (left_padding + right_padding)) - v_renderedsize) / 2); page.AddBMC(StructElem.SPAN, Single.space, Single.space); page.DrawString(font, fallbackFont, v_text, x_text, y_text); page.AddEMC(); if (GetUnderline()) { UnderlineText(page, font, v_text, x_text, y_text); } if (GetStrikeout()) { StrikeoutText(page, font, v_text, x_text, y_text); } } else { x_text = x + this.left_padding + (((cell_w - (left_padding + right_padding)) - v_renderedsize) / 2); compositeTextLine.SetPosition(x_text, y_text); page.AddBMC(StructElem.SPAN, Single.space, Single.space); compositeTextLine.DrawOn(page); page.AddEMC(); } } else if (GetTextAlignment() == Align.LEFT) { x_text = x + this.left_padding; if (compositeTextLine == null) { page.AddBMC(StructElem.SPAN, Single.space, Single.space); page.DrawString(font, fallbackFont, v_text, x_text, y_text); page.AddEMC(); if (GetUnderline()) { UnderlineText(page, font, v_text, x_text, y_text); } if (GetStrikeout()) { StrikeoutText(page, font, v_text, x_text, y_text); } } else { compositeTextLine.SetPosition(x_text, y_text); page.AddBMC(StructElem.SPAN, Single.space, Single.space); compositeTextLine.DrawOn(page); page.AddEMC(); } } else { throw new Exception("Invalid Text Alignment!"); } if (uri != null) { float w = (compositeTextLine != null) ? compositeTextLine.GetWidth() : v_renderedsize; // Please note: The font descent is a negative number. page.AddAnnotation(new Annotation( uri, null, x_text, (page.height - y_text) + font.descent, x_text + w, (page.height - y_text) + font.ascent, null, null, null)); } }
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); } } }
/** * Draws this chart on the specified page. * * @param page the page to draw this chart on. */ public void DrawOn(Page page) { nf.SetMinimumFractionDigits(minFractionDigits); nf.SetMaximumFractionDigits(maxFractionDigits); x2 = x1 + w; y2 = y1; x3 = x2; y3 = y1 + h; x4 = x1; y4 = y3; SetMinAndMaxChartValues(); RoundXAxisMinAndMaxValues(); RoundYAxisMinAndMaxValues(); // Draw chart title page.DrawString( f1, title, x1 + ((w - f1.StringWidth(title)) / 2), y1 + 1.5f * f1.body_height); float top_margin = 2.5f * f1.body_height; float left_margin = GetLongestAxisYLabelWidth() + 2f * f2.body_height; float right_margin = 2f * f2.body_height; float bottom_margin = 2.5f * f2.body_height; x5 = x1 + left_margin; y5 = y1 + top_margin; x6 = x2 - right_margin; y6 = y5; x7 = x6; y7 = y3 - bottom_margin; x8 = x5; y8 = y7; DrawChartBorder(page); DrawInnerBorder(page); DrawHorizontalGridLines(page); DrawVerticalGridLines(page); if (drawXAxisLabels) { DrawXAxisLabels(page); } if (drawYAxisLabels) { DrawYAxisLabels(page); } // Translate the point coordinates for (int i = 0; i < chartData.Count; i++) { List <Point> points = chartData[i]; for (int j = 0; j < points.Count; j++) { Point point = points[j]; point.x = x5 + (point.x - x_min) * (x6 - x5) / (x_max - x_min); point.y = y8 - (point.y - y_min) * (y8 - y5) / (y_max - y_min); if (point.GetURIAction() != null) { page.AddAnnotation(new Annotation( point.GetURIAction(), null, point.x - point.r, page.height - (point.y - point.r), point.x + point.r, page.height - (point.y + point.r), null, null, null)); } } } DrawPathsAndPoints(page, chartData); // Draw the Y axis title page.SetBrushColor(Color.black); page.SetTextDirection(90); page.DrawString( f2, y_axis_title, x1 + f2.body_height, y8 - ((y8 - y5) - f2.StringWidth(y_axis_title)) / 2); // Draw the X axis title page.SetTextDirection(0); page.DrawString( f2, x_axis_title, x5 + ((x6 - x5) - f2.StringWidth(x_axis_title)) / 2, y4 - f2.body_height / 2); page.SetDefaultLineWidth(); page.SetDefaultLinePattern(); page.SetPenColor(Color.black); }
private void DrawText( Page page, float x, float y, float cell_w, float cell_h) { float x_text; float y_text; if (valign == Align.TOP) { y_text = y + font.ascent + this.top_padding; } else if (valign == Align.CENTER) { y_text = y + cell_h / 2 + font.ascent / 2; } else if (valign == Align.BOTTOM) { y_text = (y + cell_h) - this.bottom_padding; } else { throw new Exception("Invalid vertical text alignment option."); } page.SetPenColor(pen); page.SetBrushColor(brush); if (GetTextAlignment() == Align.RIGHT) { if (compositeTextLine == null) { x_text = (x + cell_w) - (font.StringWidth(text) + this.right_padding); page.AddBMC(StructElem.SPAN, Single.space, Single.space); page.DrawString(font, fallbackFont, text, x_text, y_text); page.AddEMC(); if (GetUnderline()) { UnderlineText(page, font, text, x_text, y_text); } if (GetStrikeout()) { StrikeoutText(page, font, text, x_text, y_text); } } else { x_text = (x + cell_w) - (compositeTextLine.GetWidth() + this.right_padding); compositeTextLine.SetLocation(x_text, y_text); page.AddBMC(StructElem.SPAN, Single.space, Single.space); compositeTextLine.DrawOn(page); page.AddEMC(); } } else if (GetTextAlignment() == Align.CENTER) { if (compositeTextLine == null) { x_text = x + this.left_padding + (((cell_w - (left_padding + right_padding)) - font.StringWidth(text)) / 2); page.AddBMC(StructElem.SPAN, Single.space, Single.space); page.DrawString(font, fallbackFont, text, x_text, y_text); page.AddEMC(); if (GetUnderline()) { UnderlineText(page, font, text, x_text, y_text); } if (GetStrikeout()) { StrikeoutText(page, font, text, x_text, y_text); } } else { x_text = x + this.left_padding + (((cell_w - (left_padding + right_padding)) - compositeTextLine.GetWidth()) / 2); compositeTextLine.SetLocation(x_text, y_text); page.AddBMC(StructElem.SPAN, Single.space, Single.space); compositeTextLine.DrawOn(page); page.AddEMC(); } } else if (GetTextAlignment() == Align.LEFT) { x_text = x + this.left_padding; if (compositeTextLine == null) { page.AddBMC(StructElem.SPAN, Single.space, Single.space); page.DrawString(font, fallbackFont, text, x_text, y_text); page.AddEMC(); if (GetUnderline()) { UnderlineText(page, font, text, x_text, y_text); } if (GetStrikeout()) { StrikeoutText(page, font, text, x_text, y_text); } } else { compositeTextLine.SetLocation(x_text, y_text); page.AddBMC(StructElem.SPAN, Single.space, Single.space); compositeTextLine.DrawOn(page); page.AddEMC(); } } else { throw new Exception("Invalid Text Alignment!"); } if (uri != null) { float w = (compositeTextLine != null) ? compositeTextLine.GetWidth() : font.StringWidth(text); // Please note: The font descent is a negative number. page.AddAnnotation(new Annotation( uri, null, x_text, (page.height - y_text) + font.descent, x_text + w, (page.height - y_text) + font.ascent, null, null, null)); } }
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 }); }