private void RenderBorder(XRect elementBounds, IGraphics gfx, XSize headerSize) { if (ContentBorderColor != null || ContentBackgroundColor != null) { var borderPen = new XPen(ContentBorderColor ?? ContentBackgroundColor.Value, 0.1); //TODO: Set the thickness of the boarder if (ContentBackgroundColor != null) { var brush = new XSolidBrush(XColor.FromArgb(ContentBackgroundColor.Value)); gfx.DrawRectangle(borderPen, brush, new XRect(elementBounds.Left, elementBounds.Top + headerSize.Height, elementBounds.Width, elementBounds.Height - headerSize.Height)); } else { gfx.DrawRectangle(borderPen, new XRect(elementBounds.Left, elementBounds.Top + headerSize.Height, elementBounds.Width, elementBounds.Height - headerSize.Height)); } } if (HeaderBorderColor != null || HeaderBackgroundColor != null) { var borderPen = new XPen(HeaderBorderColor ?? HeaderBackgroundColor.Value, 0.1); //TODO: Se the thickness of the boarder if (HeaderBackgroundColor != null) { var brush = new XSolidBrush(XColor.FromArgb(HeaderBackgroundColor.Value)); gfx.DrawRectangle(borderPen, brush, new XRect(elementBounds.Left, elementBounds.Top, elementBounds.Width, headerSize.Height)); } else { gfx.DrawRectangle(borderPen, new XRect(elementBounds.Left, elementBounds.Top, elementBounds.Width, headerSize.Height)); } } }
public ClsPDF() { this.m_ListBorders = new List <ClsPDFBorders>(); this.m_ListFootArea = new List <ClsPDFArea>(); this.m_ListHeadArea = new List <ClsPDFArea>(); this.m_ListPrintArea = new List <ClsPDFArea>(); this.m_language = ClsSingeltonLanguage.CreateInstance(); this.m_Rectangle = new Rectangle(); this.m_XBrush = new XSolidBrush(XBrushes.Black); this.m_XPen = new XPen(Color.Black, 1); this.m_FileName = "pdftest.pdf"; this.m_FontName = "Arial"; this.m_Size1 = 22; this.m_Size2 = 18; this.m_Size3 = 12; this.m_Size4 = 10; this.m_FontSize1Bold = new XFont(this.m_FontName, this.m_Size1, XFontStyle.Bold); this.m_FontSize2Bold = new XFont(this.m_FontName, this.m_Size2, XFontStyle.Bold); this.m_FontSize3Bold = new XFont(this.m_FontName, this.m_Size3, XFontStyle.Bold); this.m_FontSize4Bold = new XFont(this.m_FontName, this.m_Size4, XFontStyle.Bold); this.m_PdfDokument = new PdfDocument(); }
/// <summary> /// /// </summary> /// <param name="style"></param> /// <param name="scale"></param> /// <returns></returns> private static XPen ToXPen(Test2d.BaseStyle style, Func <double, double> scale) { var pen = new XPen(ToXColor(style.Stroke), XUnit.FromPresentation(style.Thickness)); switch (style.LineCap) { case Test2d.LineCap.Flat: pen.LineCap = XLineCap.Flat; break; case Test2d.LineCap.Square: pen.LineCap = XLineCap.Square; break; case Test2d.LineCap.Round: pen.LineCap = XLineCap.Round; break; } if (style.Dashes != null) { // TODO: Convert to correct dash values. pen.DashPattern = style.Dashes; } pen.DashOffset = style.DashOffset; return(pen); }
void DrawCurve(XGraphics gfx) { XPen pen = new XPen(XColors.Navy, 4); gfx.DrawLine(pen, 0, 20, 250, 20); pen = new XPen(XColors.Firebrick, 6); pen.DashStyle = XDashStyle.Dash; gfx.DrawLine(pen, 0, 40, 250, 40); pen.Width = 7.3; pen.DashStyle = XDashStyle.DashDotDot; gfx.DrawLine(pen, 0, 60, 250, 60); pen = new XPen(XColors.Goldenrod, 10); pen.LineCap = XLineCap.Flat; gfx.DrawLine(pen, 10, 90, 240, 90); gfx.DrawLine(XPens.Black, 10, 90, 240, 90); pen = new XPen(XColors.Goldenrod, 10); pen.LineCap = XLineCap.Square; gfx.DrawLine(pen, 10, 110, 240, 110); gfx.DrawLine(XPens.Black, 10, 110, 240, 110); pen = new XPen(XColors.Goldenrod, 10); pen.LineCap = XLineCap.Round; gfx.DrawLine(pen, 10, 130, 240, 130); gfx.DrawLine(XPens.Black, 10, 130, 240, 130); }
private void DrawPolygon(XGraphics gfx, int number) { base.BeginBox(gfx, number, "DrawPolygon"); XPen xPen = new XPen(XColors.DarkBlue, 2.5); base.EndBox(gfx); }
void DrawPathAlternateAndWinding(XGraphics gfx, int number) { BeginBox(gfx, number, "DrawPath (alternate / winding)"); XPen pen = new XPen(XColors.Navy, 2.5); // Alternate fill mode XGraphicsPath path = new XGraphicsPath(); path.FillMode = XFillMode.Alternate; path.AddLine(10, 130, 10, 40); path.AddBeziers(new XPoint[] { new XPoint(10, 40), new XPoint(30, 0), new XPoint(40, 20), new XPoint(60, 40), new XPoint(80, 60), new XPoint(100, 60), new XPoint(120, 40) }); path.AddLine(120, 40, 120, 130); path.CloseFigure(); path.AddEllipse(40, 80, 50, 40); gfx.DrawPath(pen, XBrushes.DarkOrange, path); // Winding fill mode path = new XGraphicsPath(); path.FillMode = XFillMode.Winding; path.AddLine(130, 130, 130, 40); path.AddBeziers(new XPoint[] { new XPoint(130, 40), new XPoint(150, 0), new XPoint(160, 20), new XPoint(180, 40), new XPoint(200, 60), new XPoint(220, 60), new XPoint(240, 40) }); path.AddLine(240, 40, 240, 130); path.CloseFigure(); path.AddEllipse(160, 80, 50, 40); gfx.DrawPath(pen, XBrushes.DarkOrange, path); EndBox(gfx); }
public override void Process(iPDF owner, ref PdfDocument Document, ref PdfPage Page, ref XGraphics Graphics) { if (!string.IsNullOrEmpty(Data)) { var watermark = Data; XSize size = Graphics.MeasureString(watermark, owner.Font); // Define a rotation transformation at the center of the page Graphics.TranslateTransform(Page.Width / 2, Page.Height / 2); Graphics.RotateTransform(-Math.Atan(Page.Height / Page.Width) * 180 / Math.PI); Graphics.TranslateTransform(-Page.Width / 2, -Page.Height / 2); // Create a graphical path XGraphicsPath path = new XGraphicsPath(); // Add the text to the path path.AddString(watermark, owner.Font.FontFamily, XFontStyle.BoldItalic, 150, new XPoint(0, (Page.Height / 2) - 80), XStringFormats.TopLeft); // Create a dimmed red pen and brush XPen pen = new XPen(XColor.FromArgb(50, 75, 0, 130), 3); XBrush brush = new XSolidBrush(XColor.FromArgb(50, 106, 90, 205)); // Stroke the outline of the path Graphics.DrawPath(pen, brush, path); } }
public CalendarPdfDrawer() { prevSize = XSize.Empty; monthDivider = new XPen(XColor.FromArgb(127, 127, 127), 3); dayDivider = new XPen(XColor.FromArgb(0, 0, 0), 1); todayBorder = new XPen(XColor.FromArgb(0, 0, 0, 255), 3); }
private void DrawLine(XGraphics gfx, int number) { base.BeginBox(gfx, number, "DrawLine"); gfx.DrawLine(XPens.DarkGreen, 0, 0, 250, 0); gfx.DrawLine(XPens.Gold, 15, 7, 230, 15); XPen xPen = new XPen(XColors.Navy, 4.0); gfx.DrawLine(xPen, 0, 20, 250, 20); xPen = new XPen(XColors.Firebrick, 6.0); xPen.DashStyle = XDashStyle.Dash; gfx.DrawLine(xPen, 0, 40, 250, 40); xPen.Width = 7.3; xPen.DashStyle = XDashStyle.DashDotDot; gfx.DrawLine(xPen, 0, 60, 250, 60); gfx.DrawLine(new XPen(XColors.Goldenrod, 10.0) { LineCap = XLineCap.Flat }, 10, 90, 240, 90); gfx.DrawLine(XPens.Black, 10, 90, 240, 90); gfx.DrawLine(new XPen(XColors.Goldenrod, 10.0) { LineCap = XLineCap.Square }, 10, 110, 240, 110); gfx.DrawLine(XPens.Black, 10, 110, 240, 110); gfx.DrawLine(new XPen(XColors.Goldenrod, 10.0) { LineCap = XLineCap.Round }, 10, 130, 240, 130); gfx.DrawLine(XPens.Black, 10, 130, 240, 130); base.EndBox(gfx); }
/// <inheritdoc/> public override void Draw(object dc, LineShape line, double dx, double dy, object db, object r) { if (!line.IsStroked) { return; } var _gfx = dc as XGraphics; XPen strokeLine = ToXPen(line.Style, _scaleToPage, _sourceDpi, _targetDpi); DrawLineArrowsInternal(_gfx, line, dx, dy, out XPoint pt1, out XPoint pt2); if (line.Style.LineStyle.IsCurved) { DrawLineCurveInternal( _gfx, strokeLine, line.IsStroked, ref pt1, ref pt2, line.Style.LineStyle.Curvature, line.Style.LineStyle.CurveOrientation, line.Start.Alignment, line.End.Alignment); } else { DrawLineInternal(_gfx, strokeLine, line.IsStroked, ref pt1, ref pt2); } }
void DrawGridline(XGraphics gfx, XPoint origin, XPen pen, double delta, XRect box) { double xmin = box.X, ymin = box.Y, xmax = box.X + box.Width, ymax = box.Y + box.Height; double x, y; y = origin.Y; while (y < ymax) { gfx.DrawLine(pen, xmin, y, xmax, y); y += delta; } y = origin.Y - delta; while (y > ymin) { gfx.DrawLine(pen, xmin, y, xmax, y); y -= delta; } x = origin.X; while (x < xmax) { gfx.DrawLine(pen, x, ymin, x, ymax); x += delta; } x = origin.X - delta; while (x > xmin) { gfx.DrawLine(pen, x, ymin, x, ymax); x -= delta; } }
private static void DrawLineInternal(XGraphics gfx, XPen pen, bool isStroked, ref XPoint p0, ref XPoint p1) { if (isStroked) { gfx.DrawLine(pen, p0, p1); } }
/// <summary> /// Demonstrates the use of XGraphics.DrawBeziers. /// </summary> public override void RenderPage(XGraphics gfx) { base.RenderPage(gfx); int n = 2; int count = 1 + 3 * n; XPoint[] points = new XPoint[count]; Random rnd = new Random(42); for (int idx = 0; idx < count; idx++) { points[idx].X = 20 + rnd.Next(600); points[idx].Y = 50 + rnd.Next(800); } // Draw the points XPen pen = new XPen(XColors.Red, 0.5); pen.DashStyle = XDashStyle.Dash; for (int idx = 0; idx + 3 < count; idx += 3) { gfx.DrawEllipse(XBrushes.Red, MakeRect(points[idx])); gfx.DrawEllipse(XBrushes.Red, MakeRect(points[idx + 1])); gfx.DrawEllipse(XBrushes.Red, MakeRect(points[idx + 2])); gfx.DrawEllipse(XBrushes.Red, MakeRect(points[idx + 3])); gfx.DrawLine(pen, points[idx], points[idx + 1]); gfx.DrawLine(pen, points[idx + 2], points[idx + 3]); } // Draw the curve gfx.DrawBeziers(properties.Pen2.Pen, points); }
private void DrawGridInternal(XGraphics gfx, XPen stroke, ref Core2D.Math.Rect2 rect, double offsetX, double offsetY, double cellWidth, double cellHeight, bool isStroked) { double ox = rect.X; double oy = rect.Y; double sx = ox + offsetX; double sy = oy + offsetY; double ex = ox + rect.Width; double ey = oy + rect.Height; for (double x = sx; x < ex; x += cellWidth) { var p0 = new XPoint( _scaleToPage(x), _scaleToPage(oy)); var p1 = new XPoint( _scaleToPage(x), _scaleToPage(ey)); DrawLineInternal(gfx, stroke, isStroked, ref p0, ref p1); } for (double y = sy; y < ey; y += cellHeight) { var p0 = new XPoint( _scaleToPage(ox), _scaleToPage(y)); var p1 = new XPoint( _scaleToPage(ex), _scaleToPage(y)); DrawLineInternal(gfx, stroke, isStroked, ref p0, ref p1); } }
/// <inheritdoc/> public override void Draw(object dc, Core2D.Shapes.XLine line, double dx, double dy, ImmutableArray <Core2D.Data.XProperty> db, Core2D.Data.Database.XRecord r) { if (!line.IsStroked) { return; } var _gfx = dc as XGraphics; XPen strokeLine = ToXPen(line.Style, _scaleToPage, _sourceDpi, _targetDpi); XPoint pt1, pt2; DrawLineArrowsInternal(_gfx, line, dx, dy, out pt1, out pt2); if (line.Style.LineStyle.IsCurved) { DrawLineCurveInternal( _gfx, strokeLine, line.IsStroked, ref pt1, ref pt2, line.Style.LineStyle.Curvature, line.Style.LineStyle.CurveOrientation, line.Start.Alignment, line.End.Alignment); } else { DrawLineInternal(_gfx, strokeLine, line.IsStroked, ref pt1, ref pt2); } }
/// <summary> /// Creates a XPen based on the specified line format. If not specified color, width and dash style /// will be taken from the defaultColor, defaultWidth and defaultDashStyle parameters. /// </summary> internal static XPen ToXPen(LineFormat lineFormat, XColor defaultColor, double defaultWidth, XDashStyle defaultDashStyle) { XPen pen = null; if (lineFormat == null) { pen = new XPen(defaultColor, defaultWidth); pen.DashStyle = defaultDashStyle; } else { XColor color = defaultColor; if (!lineFormat.Color.IsEmpty) { color = lineFormat.Color; } double width = lineFormat.Width.Point; if (!lineFormat.Visible) { width = 0; } if (lineFormat.Visible && width == 0) { width = defaultWidth; } pen = new XPen(color, width); pen.DashStyle = lineFormat.dashStyle; pen.DashOffset = 10 * width; } return(pen); }
private void DrawLineArrowsInternal(XGraphics gfx, Core2D.Shapes.XLine line, double dx, double dy, out XPoint pt1, out XPoint pt2) { XSolidBrush fillStartArrow = ToXSolidBrush(line.Style.StartArrowStyle.Fill); XPen strokeStartArrow = ToXPen(line.Style.StartArrowStyle, _scaleToPage, _sourceDpi, _targetDpi); XSolidBrush fillEndArrow = ToXSolidBrush(line.Style.EndArrowStyle.Fill); XPen strokeEndArrow = ToXPen(line.Style.EndArrowStyle, _scaleToPage, _sourceDpi, _targetDpi); double _x1 = line.Start.X + dx; double _y1 = line.Start.Y + dy; double _x2 = line.End.X + dx; double _y2 = line.End.Y + dy; Core2D.Shapes.XLineExtensions.GetMaxLength(line, ref _x1, ref _y1, ref _x2, ref _y2); double x1 = _scaleToPage(_x1); double y1 = _scaleToPage(_y1); double x2 = _scaleToPage(_x2); double y2 = _scaleToPage(_y2); var sas = line.Style.StartArrowStyle; var eas = line.Style.EndArrowStyle; double a1 = Math.Atan2(y1 - y2, x1 - x2) * 180.0 / Math.PI; double a2 = Math.Atan2(y2 - y1, x2 - x1) * 180.0 / Math.PI; // Draw start arrow. pt1 = DrawLineArrowInternal(gfx, strokeStartArrow, fillStartArrow, x1, y1, a1, sas); // Draw end arrow. pt2 = DrawLineArrowInternal(gfx, strokeEndArrow, fillEndArrow, x2, y2, a2, eas); }
/// <summary> /// Draws the graphical lines one the polling card /// </summary> /// <param name="gfx">XGraphics object</param> private void DrawGraphics(XGraphics gfx) { //the size and color of the lines XPen pen = new XPen(XColor.FromName("Black"), 0.5); //The rectangle around the polling venue address gfx.DrawRectangle(pen, LeftMargin, 80, 220, 60); //The rectangle around the polling table gfx.DrawRectangle(pen, LeftMargin, 150, 220, 20); //The rectangle around the voter id gfx.DrawRectangle(pen, LeftMargin, 180, 220, 20); //The rectangle around the voting timespan gfx.DrawRectangle(pen, LeftMargin, 210, 220, 20); //The vertical separate line gfx.DrawLine(pen, 300, 20, 300, 250); //The horizontal separate linjes gfx.DrawLine(pen, LeftMargin, 250, gfx.PageSize.Width - RightMargin, 250); gfx.DrawLine(pen, 300, 80, gfx.PageSize.Width - RightMargin, 80); gfx.DrawLine(pen, 300, 140, gfx.PageSize.Width - RightMargin, 140); //The crossed lines on the sender address gfx.DrawLine(pen, 300, 80, 450, 140); gfx.DrawLine(pen, 300, 140, 450, 80); }
public static void BeginBox(XGraphics gfx, int number, string title, double borderWidth, double borderHeight, XColor shadowColor, XColor backColor, XColor backColor2, XPen borderPen) { const int dEllipse = 15; XRect rect = new XRect(0, 20, 300, 200); if (number % 2 == 0) { rect.X = 300 - 5; } rect.Y = 40 + ((number - 1) / 2) * (200 - 5); rect.Inflate(-10, -10); XRect rect2 = rect; rect2.Offset(borderWidth, borderHeight); gfx.DrawRoundedRectangle(new XSolidBrush(shadowColor), rect2, new XSize(dEllipse + 8, dEllipse + 8)); XLinearGradientBrush brush = new XLinearGradientBrush(rect, backColor, backColor2, XLinearGradientMode.Vertical); gfx.DrawRoundedRectangle(borderPen, brush, rect, new XSize(dEllipse, dEllipse)); rect.Inflate(-5, -5); XFont font = new XFont("Verdana", 12, XFontStyle.Regular); gfx.DrawString(title, font, XBrushes.Navy, rect, XStringFormats.TopCenter); rect.Inflate(-10, -5); rect.Y += 20; rect.Height -= 20; state = gfx.Save(); gfx.TranslateTransform(rect.X, rect.Y); }
private static void AddAbout(XGraphics gfx, AssesmentReportTO report) { XPen separatorsPen = new XPen(XColor.FromArgb(0, 238, 238, 238), 1); // About font XFont aboutFont = new XFont(fontName, 7, XFontStyle.Regular); XBrush aboutBrushText = XBrushes.Silver; //Logo and Separators int imageX = 200; int imageWidth = 41; int imageHeight = 58; int separatorX = imageX + imageWidth + 15; int aboutTextX = separatorX + 20; int imageY = 770; XImage laboruImage = XImage.FromFile(HttpContext.Current.Server.MapPath("~/Static/dist/images/logo-laboru.png")); gfx.DrawImage(laboruImage, imageX, imageY, imageWidth, imageHeight); gfx.DrawLine(separatorsPen, separatorX, imageY, separatorX, imageY + imageHeight); //Text gfx.DrawString("Elaborado por Laboru para " + report.AssesmentInfo.Company.Name, aboutFont, aboutBrushText, new XRect(aboutTextX, imageY + 10, 200, 20), XStringFormats.TopLeft); gfx.DrawString("Todos los derechos reservados", aboutFont, aboutBrushText, new XRect(aboutTextX, imageY + 25, 200, 20), XStringFormats.TopLeft); gfx.DrawString("http://laboru.co/tech", aboutFont, aboutBrushText, new XRect(aboutTextX, imageY + 40, 200, 20), XStringFormats.TopLeft); }
public void DrawBox(XGraphics gfx, XRect rect, XPen borderPen) { //int dEllipse = 15; //XRect rect = new XRect(75, 130, 400, 300); //if (number % 2 == 0) // rect.X = 300 - 5; //rect.Y = 40 + ((number - 1) / 2) * (200 - 5); //rect.Inflate(-10, -10); //XRect rect2 = rect; //rect2.Offset(this.borderWidth, this.borderWidth); gfx.DrawRectangle(borderPen, rect); //gfx.DrawRoundedRectangle(this.borderPen, new XSolidBrush(this.backColor), rect, new XSize(dEllipse, dEllipse)); //rect.Inflate(-5, -5); //XFont font = new XFont("Verdana", 12, XFontStyle.Regular); //gfx.DrawString(title, font, XBrushes.Black, rect, XStringFormat.CenterTop); //rect.Inflate(-10, -5); //rect.Y += 20; //rect.Height -= 20; //gfx.DrawRectangle(XPens.Red, rect); this._state = gfx.Save(); gfx.TranslateTransform(rect.X, rect.Y); SetBoxX(0); SetBoxY(0); }
public static void DrawTable(XGraphics graph, XPen pen, double x1, double y1, double x2, double y2, byte rowCnt, byte clmnCnt, double firstClmnWdth , bool noDiv1stRow) { double cellHeight = (y2 - y1) / rowCnt; double cellWidth; graph.DrawRectangle(pen, new XRect(x1, y1, x2 - x1, y2 - y1)); // xbrush 추가 if (clmnCnt == 1) { cellWidth = firstClmnWdth; } else { cellWidth = (x2 - (x1 + firstClmnWdth)) / (clmnCnt - 1); } if (rowCnt >= 2) { for (int i = 1; i <= rowCnt - 1; i++) { graph.DrawLine(pen, x1, y1 + i * cellHeight, x2, y1 + i * cellHeight); } } if (clmnCnt >= 2) { for (int i = 1; i <= clmnCnt - 1; i++) { graph.DrawLine(pen, x1 + firstClmnWdth + (i - 1) * cellWidth, y1 + (noDiv1stRow ? 1 : 0) * cellHeight, x1 + firstClmnWdth + (i - 1) * cellWidth, y2); } } if (noDiv1stRow) { graph.DrawRectangle(new XPen(XColor.Empty), new XSolidBrush(XColor.FromArgb(250, 250, 250)), new XRect(x1, y1, x2 - x1, cellHeight)); } }
public void FillRectangle(double x, double y, double w, double h, ColorPreset FillColor, ColorPreset BorderColor) { // y2 = y2 - InitPageOffset(ref y); using (XGraphics gfx = XGraphics.FromPdfPage(currentPage)) { XPen pen = new XPen(XColors.White); XBrush brush = XBrushes.White; gfx.DrawRectangle(pen, brush, x, y, w, h); } /* Rectangle rect = new Rectangle(); * rect.Width = x2 - x2; * rect.Height = y2 - y1; * #if !SILVERLIGHT * rect.Fill = Brushes.WhiteSmoke; #else * rect.Fill = WhiteBrush; #endif * * Canvas.SetTop(rect, y1); * Canvas.SetLeft(rect, x1); * * canvas.Children.Add(rect); */ }
public static void ColumnContentsFill(XGraphics graph, XPen pen, XFont font, int Column, double[] PositionX, double[] PositionY, string[] contents, Enums.ContentsAlignment align) { for (int i = 0; i <= contents.Length - 1; i++) { DrawTextinCellmm(graph, font, pen, contents[i], align, PositionX[Column], PositionY[i], PositionX[Column + 1], PositionY[i + 1], false); } }
public static void DrawTextinCellmm(XGraphics graph, XFont font, XPen pen, string str, Enums.ContentsAlignment align, double x1, double y1, double x2, double y2, bool wraptext, double margin = 1) { double wdth = graph.MeasureString(str, font).Width; double hght = graph.MeasureString(str, font).Height; if (wraptext) { int txtCursor = 0; int chrsTmp = 0; List <int> chrs = new List <int>(); double cellWdth = GetPtfrommm(x2) - GetPtfrommm(x1) - 2 * GetPtfrommm(margin); while (txtCursor < str.Length - 1) { while (graph.MeasureString(str.Substring(chrsTmp, txtCursor - chrsTmp + 1), font).Width < cellWdth) { if (txtCursor < str.Length - 1) { txtCursor += 1; } else { break; } } chrsTmp = txtCursor; chrs.Add(txtCursor); } chrsTmp = 0; int lineno = 0; foreach (int cur in chrs) { graph.DrawString(str.Substring(chrsTmp, cur - chrsTmp + 1), font, XBrushes.Black, new XRect(GetPtfrommm(x1) + GetPtfrommm(margin), (GetPtfrommm(y1) + GetPtfrommm(margin) - GetPtfrommm(0.7) + hght * lineno), x2 - x1 - 2 * GetPtfrommm(margin), hght), XStringFormats.TopLeft); chrsTmp = cur + 1; lineno += 1; } } else { switch (align) { case Enums.ContentsAlignment.Left: graph.DrawString(str, font, XBrushes.Black, new XRect(GetPtfrommm(x1) + GetPtfrommm(margin), (GetPtfrommm(y1) / 2) + (GetPtfrommm(y2) / 2) - (hght / 2), wdth, hght), XStringFormats.TopLeft); break; case Enums.ContentsAlignment.Right: graph.DrawString(str, font, XBrushes.Black, new XRect(GetPtfrommm(x2) - GetPtfrommm(margin) - wdth, (GetPtfrommm(y1) / 2) + (GetPtfrommm(y2) / 2) - (hght / 2), wdth, hght), XStringFormats.TopLeft); break; case Enums.ContentsAlignment.Center: graph.DrawString(str, font, XBrushes.Black, new XRect((GetPtfrommm(x1) / 2) + (GetPtfrommm(x2) / 2) - (wdth / 2), (GetPtfrommm(y1) / 2) + (GetPtfrommm(y2) / 2) - (hght / 2), wdth, hght), XStringFormats.TopLeft); break; } } }
public static XPen ToXPen(this Drawing.Pen pen) { var xPen = new XPen(pen.Color.ToXColor(), pen.Width); xPen.DashStyle = (XDashStyle)pen.DashStyle; return(xPen); }
private static XPen ToXPen(Core2D.Style.BaseStyle style, Func <double, double> scale, double sourceDpi, double targetDpi) { var pen = new XPen(ToXColor(style.Stroke), scale(style.Thickness * targetDpi / sourceDpi)); switch (style.LineCap) { case Core2D.Style.LineCap.Flat: pen.LineCap = XLineCap.Flat; break; case Core2D.Style.LineCap.Square: pen.LineCap = XLineCap.Square; break; case Core2D.Style.LineCap.Round: pen.LineCap = XLineCap.Round; break; } if (style.Dashes != null) { // TODO: Convert to correct dash values. pen.DashPattern = Core2D.Style.ShapeStyle.ConvertDashesToDoubleArray(style.Dashes); } pen.DashOffset = style.DashOffset; return(pen); }
private void DrawHeader(XGraphics gfx) { gfx.DrawLine(XPens.Orange, 50, 50, 250, 50); XRect rcImage = new XRect(50, 35, 100, 15); gfx.DrawRectangle(XBrushes.Orange, rcImage); gfx.DrawString("APPLICANT", FontUtility.HeaderTitle, XBrushes.White, rcImage, XStringFormats.Center); gfx.DrawString("John Doe", FontUtility.HeaderContentBig, XBrushes.Black, new XRect(50, 62, 100, 0)); gfx.DrawString("*****@*****.**", FontUtility.HeaderContentNormal, XBrushes.Black, new XRect(50, 75, 100, 0)); gfx.DrawString("802-123-4567", FontUtility.HeaderContentNormal, XBrushes.Black, new XRect(50, 85, 100, 0)); gfx.DrawLine(XPens.DarkBlue, 280, 50, 500, 50); XRect rcImage2 = new XRect(280, 35, 100, 15); gfx.DrawRectangle(XBrushes.DarkBlue, rcImage2); gfx.DrawString("APPLYING FOR", FontUtility.HeaderTitle, XBrushes.White, rcImage2, XStringFormats.Center); gfx.DrawString("Cyber Reverse Engineer", FontUtility.HeaderContentBig, XBrushes.Black, new XRect(280, 62, 100, 0)); gfx.DrawString("iNovex Information Systems Savage, MD", FontUtility.HeaderContentNormal, XBrushes.Black, new XRect(280, 75, 100, 0)); XPen pen = new XPen(XColors.Orange, 1); pen.DashStyle = XDashStyle.Solid; gfx.DrawPie(pen, XBrushes.OrangeRed, 545, 5, 60, 60, 90, 90); gfx.DrawString("18", FontUtility.HeaderTitle, XBrushes.White, new XRect(555, 50, 50, 0)); }
XPen GetPen(XUnit width) { if (width == 0) { return(null); } XPen pen = new XPen(GetColor(), width); switch (_lineFormat.DashStyle) { case DashStyle.Dash: pen.DashStyle = XDashStyle.Dash; break; case DashStyle.DashDot: pen.DashStyle = XDashStyle.DashDot; break; case DashStyle.DashDotDot: pen.DashStyle = XDashStyle.DashDotDot; break; case DashStyle.Solid: pen.DashStyle = XDashStyle.Solid; break; case DashStyle.SquareDot: pen.DashStyle = XDashStyle.Dot; break; } return(pen); }
public static void DrawBorder(XRect rect, IExportColumn column, XGraphics graphics) { var pen = new XPen(ToXColor(column.ForeColor), 1); rect.Inflate(new XSize(2, 2)); graphics.DrawRectangle(pen, rect); }
// ----- DrawLines ---------------------------------------------------------------------------- public void DrawLines(XPen pen, PointF[] points) { if (this.gfx != null) this.gfx.DrawLines(pen.RealizeGdiPen(), points); if (this.pdfPage != null) this.pdfPage.PageContent.DrawLines(pen, points); }
// ----- DrawLine ----------------------------------------------------------------------------- public void DrawLine(XPen pen, float x1, float y1, float x2, float y2) { if (this.gfx != null) this.gfx.DrawLine(pen.RealizeGdiPen(), x1, y1, x2, y2); if (this.pdfPage != null) this.pdfPage.PageContent.DrawLines(pen, new PointF[2]{new PointF(x1, y1), new PointF(x2, y2)}); }
// ----- DrawRectangle ------------------------------------------------------------------------ public void DrawRectangle(XPen pen, XSolidBrush brush, float x, float y, float width, float height) { if (this.gfx != null) { this.gfx.FillRectangle(brush.RealizeGdiBrush(), x, y, width, height); this.gfx.DrawRectangle(pen.RealizeGdiPen(), x, y, width, height); } if (this.pdfPage != null) this.pdfPage.PageContent.DrawRectangle(pen, brush, x, y, width, height); }
// ----- DrawArc ------------------------------------------------------------------------------ public void DrawArc(XPen pen, double x, double y, double width, double height, double startAngle, double sweepAngle) { if (pen == null) throw new ArgumentNullException("pen"); Realize(pen); AppendPartialArc(x, y, width, height, startAngle, sweepAngle, PathStart.MoveTo1st, new XMatrix()); AppendStrokeFill(pen, null, XFillMode.Alternate, false); }
// ----- DrawCurve ---------------------------------------------------------------------------- public void DrawCurve(XPen pen, XPoint[] points, double tension) { if (pen == null) throw new ArgumentNullException("pen"); if (points == null) throw new ArgumentNullException("points"); int count = points.Length; if (count == 0) return; if (count < 2) throw new ArgumentException("Not enough points", "points"); // See http://pubpages.unh.edu/~cs770/a5/cardinal.html tension /= 3; Realize(pen); AppendFormat("{0:0.###} {1:0.###} m\n", points[0].X, points[0].Y); if (count == 2) { // Just draws a line... AppendCurveSegment(points[0], points[0], points[1], points[1], tension); } else { AppendCurveSegment(points[0], points[0], points[1], points[2], tension); for (int idx = 1; idx < count - 2; idx++) AppendCurveSegment(points[idx - 1], points[idx], points[idx + 1], points[idx + 2], tension); AppendCurveSegment(points[count - 3], points[count - 2], points[count - 1], points[count - 1], tension); } AppendStrokeFill(pen, null, XFillMode.Alternate, false); }
// ----- DrawBeziers -------------------------------------------------------------------------- public void DrawBeziers(XPen pen, XPoint[] points) { if (pen == null) throw new ArgumentNullException("pen"); if (points == null) throw new ArgumentNullException("points"); int count = points.Length; if (count == 0) return; if ((count - 1) % 3 != 0) throw new ArgumentException("Invalid number of points for bezier curves. Number must fulfil 4+3n.", "points"); Realize(pen); AppendFormat("{0:0.####} {1:0.####} m\n", points[0].X, points[0].Y); for (int idx = 1; idx < count; idx += 3) AppendFormat("{0:0.####} {1:0.####} {2:0.####} {3:0.####} {4:0.####} {5:0.####} c\n", points[idx].X, points[idx].Y, points[idx + 1].X, points[idx + 1].Y, points[idx + 2].X, points[idx + 2].Y); AppendStrokeFill(pen, null, XFillMode.Alternate, false); }
// ----- DrawBezier --------------------------------------------------------------------------- public void DrawBezier(XPen pen, double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4) { DrawBeziers(pen, new XPoint[4] { new XPoint(x1, y1), new XPoint(x2, y2), new XPoint(x3, y3), new XPoint(x4, y4) }); }
// ----- DrawLines ---------------------------------------------------------------------------- /// <summary> /// Strokes a series of connected points. /// </summary> public void DrawLines(XPen pen, XPoint[] points) { if (pen == null) throw new ArgumentNullException("pen"); if (points == null) throw new ArgumentNullException("points"); int count = points.Length; if (count == 0) return; Realize(pen); AppendFormat("{0:0.###} {1:0.###} m\n", points[0].X, points[0].Y); for (int idx = 1; idx < count; idx++) AppendFormat("{0:0.###} {1:0.###} l\n", points[idx].X, points[idx].Y); this.content.Append("S\n"); }
/// <summary> /// Makes the specified pen to the current graphics object. /// </summary> void Realize(XPen pen) { Realize(pen, null); }
// ----- DrawClosedCurve ---------------------------------------------------------------------- public void DrawClosedCurve(XPen pen, XBrush brush, XPoint[] points, double tension, XFillMode fillmode) { int count = points.Length; if (count == 0) return; if (count < 2) throw new ArgumentException("Not enough points", "points"); // Simply tried out. Not proofed why it is correct. tension /= 3; Realize(pen, brush); AppendFormat("{0:0.####} {1:0.####} m\n", points[0].X, points[0].Y); if (count == 2) { // Just draws a line... AppendCurveSegment(points[0], points[0], points[1], points[1], tension); } else { AppendCurveSegment(points[count - 1], points[0], points[1], points[2], tension); for (int idx = 1; idx < count - 2; idx++) AppendCurveSegment(points[idx - 1], points[idx], points[idx + 1], points[idx + 2], tension); AppendCurveSegment(points[count - 3], points[count - 2], points[count - 1], points[0], tension); AppendCurveSegment(points[count - 2], points[count - 1], points[0], points[1], tension); } AppendStrokeFill(pen, brush, fillmode, true); }
// ----- DrawLine ----------------------------------------------------------------------------- /// <summary> /// Strokes a single connection of two points. /// </summary> public void DrawLine(XPen pen, double x1, double y1, double x2, double y2) { DrawLines(pen, new XPoint[2] { new XPoint(x1, y1), new XPoint(x2, y2) }); }
void AppendStrokeFill(XPen pen, XBrush brush, XFillMode fillMode, bool closePath) { if (closePath) this.content.Append("h "); if (fillMode == XFillMode.Winding) { if (pen != null && brush != null) this.content.Append("B\n"); else if (pen != null) this.content.Append("S\n"); else this.content.Append("f\n"); } else { if (pen != null && brush != null) this.content.Append("B*\n"); else if (pen != null) this.content.Append("S\n"); else this.content.Append("f*\n"); } }
// ----- DrawRoundedRectangle ----------------------------------------------------------------- public void DrawRoundedRectangle(XPen pen, XBrush brush, double x, double y, double width, double height, double ellipseWidth, double ellipseHeight) { XGraphicsPath path = new XGraphicsPath(); path.AddRoundedRectangle(x, y, width, height, ellipseWidth, ellipseHeight); DrawPath(pen, brush, path); }
// ----- DrawRectangles ----------------------------------------------------------------------- //public void DrawRectangles(XPen pen, XSolidBrush brush, Rectangle[] rects) //{ // if (this.gfx != null) // { // this.gfx.FillRectangles(brush.RealizeGdiBrush(), rects); // this.gfx.DrawRectangles(pen.RealizeGdiPen(), rects); // } // if (this.pdfPage != null) // { // int count = rects.Length; // for (int idx = 0; idx < count; idx++) // { // Rectangle rect = rects[idx]; // this.pdfPage.PageContent.DrawRectangle(pen, brush, rect.X, rect.Y, rect.Width, rect.Height); // } // } //} public void DrawRectangles(XPen pen, XSolidBrush brush, RectangleF[] rects) { if (this.gfx != null) { this.gfx.FillRectangles(brush.RealizeGdiBrush(), rects); this.gfx.DrawRectangles(pen.RealizeGdiPen(), rects); } if (this.pdfPage != null) { int count = rects.Length; for (int idx = 0; idx < count; idx++) { RectangleF rect = rects[idx]; this.pdfPage.PageContent.DrawRectangle(pen, brush, rect.X, rect.Y, rect.Width, rect.Height); } } }
// ----- DrawRectangle ------------------------------------------------------------------------ public void DrawRectangle(XPen pen, XBrush brush, double x, double y, double width, double height) { if (pen == null && brush == null) throw new ArgumentNullException("pen and brush"); Realize(pen, brush); AppendFormat("{0:0.###} {1:0.###} {2:0.###} {3:0.###} re\n", x, y, width, height); if (pen != null && brush != null) this.content.Append("B\n"); else if (pen != null) this.content.Append("S\n"); else this.content.Append("f\n"); }
/// <summary> /// Makes the specified pen and brush to the current graphics objects. /// </summary> void Realize(XPen pen, XBrush brush) { BeginPage(); BeginGraphic(); RealizeTransform(); if (pen != null) this.gfxState.RealizePen(pen, this.colorMode); // this.page.document.Options.ColorMode); if (brush != null) this.gfxState.RealizeBrush(brush, this.colorMode); // this.page.document.Options.ColorMode); }
// ----- DrawRectangles ----------------------------------------------------------------------- public void DrawRectangles(XPen pen, XBrush brush, XRect[] rects) { int count = rects.Length; for (int idx = 0; idx < count; idx++) { XRect rect = rects[idx]; DrawRectangle(pen, brush, rect.X, rect.Y, rect.Width, rect.Height); } }
// ----- DrawPolygon -------------------------------------------------------------------------- public void DrawPolygon(XPen pen, XBrush brush, XPoint[] points, XFillMode fillmode) { Realize(pen, brush); int count = points.Length; if (points.Length < 2) throw new ArgumentException("points", PSSR.PointArrayAtLeast(2)); AppendFormat("{0:0.####} {1:0.####} m\n", points[0].X, points[0].Y); for (int idx = 1; idx < count; idx++) AppendFormat("{0:0.####} {1:0.####} l\n", points[idx].X, points[idx].Y); AppendStrokeFill(pen, brush, fillmode, true); }
// ----- DrawEllipse -------------------------------------------------------------------------- public void DrawEllipse(XPen pen, XBrush brush, double x, double y, double width, double height) { Realize(pen, brush); // Useful information are here http://home.t-online.de/home/Robert.Rossmair/ellipse.htm // or here http://www.whizkidtech.redprince.net/bezier/circle/ // Deeper but more difficult: http://www.tinaja.com/cubic01.asp // Petzold: 4/3 * tan(α / 4) const double κ = 0.5522847498; // := 4/3 * (1 - cos(-π/4)) / sin(π/4)) <=> 4/3 * sqrt(2) - 1 XRect rect = new XRect(x, y, width, height); double δx = rect.Width / 2; double δy = rect.Height / 2; double fx = δx * κ; double fy = δy * κ; double x0 = rect.X + δx; double y0 = rect.Y + δy; AppendFormat("{0:0.####} {1:0.####} m\n", x0 + δx, y0); AppendFormat("{0:0.####} {1:0.####} {2:0.####} {3:0.####} {4:0.####} {5:0.####} c\n", x0 + δx, y0 + fy, x0 + fx, y0 + δy, x0, y0 + δy); AppendFormat("{0:0.####} {1:0.####} {2:0.####} {3:0.####} {4:0.####} {5:0.####} c\n", x0 - fx, y0 + δy, x0 - δx, y0 + fy, x0 - δx, y0); AppendFormat("{0:0.####} {1:0.####} {2:0.####} {3:0.####} {4:0.####} {5:0.####} c\n", x0 - δx, y0 - fy, x0 - fx, y0 - δy, x0, y0 - δy); AppendFormat("{0:0.####} {1:0.####} {2:0.####} {3:0.####} {4:0.####} {5:0.####} c\n", x0 + fx, y0 - δy, x0 + δx, y0 - fy, x0 + δx, y0); AppendStrokeFill(pen, brush, XFillMode.Winding, true); }
/// <summary> /// Makes the specified pen and brush to the current graphics objects. /// </summary> private void Realize(XPen pen, XBrush brush) { BeginPage(); BeginGraphicMode(); RealizeTransform(); if (pen != null) _gfxState.RealizePen(pen, _colorMode); // page.document.Options.ColorMode); if (brush != null) { // Render mode is 0 except for bold simulation. _gfxState.RealizeBrush(brush, _colorMode, 0, 0); // page.document.Options.ColorMode); } }
// ----- DrawPie ------------------------------------------------------------------------------ public void DrawPie(XPen pen, XBrush brush, double x, double y, double width, double height, double startAngle, double sweepAngle) { Realize(pen, brush); AppendFormat("{0:0.####} {1:0.####} m\n", x + width / 2, y + height / 2); AppendPartialArc(x, y, width, height, startAngle, sweepAngle, PathStart.LineTo1st, new XMatrix()); AppendStrokeFill(pen, brush, XFillMode.Alternate, true); }
// ----- DrawRectangle ------------------------------------------------------------------------ public void DrawRectangle(XPen pen, XBrush brush, double x, double y, double width, double height) { if (pen == null && brush == null) throw new ArgumentNullException("pen and brush"); const string format = Config.SignificantFigures3; Realize(pen, brush); //AppendFormat123("{0:" + format + "} {1:" + format + "} {2:" + format + "} {3:" + format + "} re\n", x, y, width, -height); AppendFormatRect("{0:" + format + "} {1:" + format + "} {2:" + format + "} {3:" + format + "} re\n", x, y + height, width, height); if (pen != null && brush != null) _content.Append("B\n"); else if (pen != null) _content.Append("S\n"); else _content.Append("f\n"); }
// ----- DrawPath ----------------------------------------------------------------------------- public void DrawPath(XPen pen, XBrush brush, XGraphicsPath path) { if (pen == null && brush == null) throw new ArgumentNullException("pen"); #if GDI && !WPF Realize(pen, brush); AppendPath(path.gdipPath); AppendStrokeFill(pen, brush, path.FillMode, false); #endif #if WPF && !GDI Realize(pen, brush); AppendPath(path.pathGeometry); AppendStrokeFill(pen, brush, path.FillMode, false); #endif #if WPF && GDI Realize(pen, brush); if (this.gfx.targetContext == XGraphicTargetContext.GDI) AppendPath(path.gdipPath); else AppendPath(path.pathGeometry); AppendStrokeFill(pen, brush, path.FillMode, false); #endif }
// ----- DrawEllipse -------------------------------------------------------------------------- public void DrawEllipse(XPen pen, XBrush brush, double x, double y, double width, double height) { Realize(pen, brush); // Useful information is here http://home.t-online.de/home/Robert.Rossmair/ellipse.htm (note: link was dead on November 2, 2015) // or here http://www.whizkidtech.redprince.net/bezier/circle/ // Deeper but more difficult: http://www.tinaja.com/cubic01.asp XRect rect = new XRect(x, y, width, height); double δx = rect.Width / 2; double δy = rect.Height / 2; double fx = δx * Const.κ; double fy = δy * Const.κ; double x0 = rect.X + δx; double y0 = rect.Y + δy; // Approximate an ellipse by drawing four cubic splines. const string format = Config.SignificantFigures4; AppendFormatPoint("{0:" + format + "} {1:" + format + "} m\n", x0 + δx, y0); AppendFormat3Points("{0:" + format + "} {1:" + format + "} {2:" + format + "} {3:" + format + "} {4:" + format + "} {5:" + format + "} c\n", x0 + δx, y0 + fy, x0 + fx, y0 + δy, x0, y0 + δy); AppendFormat3Points("{0:" + format + "} {1:" + format + "} {2:" + format + "} {3:" + format + "} {4:" + format + "} {5:" + format + "} c\n", x0 - fx, y0 + δy, x0 - δx, y0 + fy, x0 - δx, y0); AppendFormat3Points("{0:" + format + "} {1:" + format + "} {2:" + format + "} {3:" + format + "} {4:" + format + "} {5:" + format + "} c\n", x0 - δx, y0 - fy, x0 - fx, y0 - δy, x0, y0 - δy); AppendFormat3Points("{0:" + format + "} {1:" + format + "} {2:" + format + "} {3:" + format + "} {4:" + format + "} {5:" + format + "} c\n", x0 + fx, y0 - δy, x0 + δx, y0 - fy, x0 + δx, y0); AppendStrokeFill(pen, brush, XFillMode.Winding, true); }
// ----- DrawEllipse -------------------------------------------------------------------------- //public void DrawEllipse(XPen pen, Rectangle rect); //public void DrawEllipse(XPen pen, RectangleF rect); //public void DrawEllipse(XPen pen, int x, int y, int width, int height); //public void DrawEllipse(XPen pen, float x, float y, float width, float height); // ----- DrawPolygon -------------------------------------------------------------------------- //public void DrawPolygon(XPen pen, Point[] points); //public void DrawPolygon(XPen pen, PointF[] points); // ----- DrawPath ----------------------------------------------------------------------------- public void DrawPath(XPen pen, XSolidBrush brush, XGraphicsPath path) { if (this.gfx != null) { this.gfx.FillPath(brush.RealizeGdiBrush(), path.RealizeGdiPath()); this.gfx.DrawPath(pen.RealizeGdiPen(), path.RealizeGdiPath()); } if (this.pdfPage != null) this.pdfPage.PageContent.DrawPath(pen, brush, path); }
// ----- DrawPolygon -------------------------------------------------------------------------- public void DrawPolygon(XPen pen, XBrush brush, XPoint[] points, XFillMode fillmode) { Realize(pen, brush); int count = points.Length; if (points.Length < 2) throw new ArgumentException("points", PSSR.PointArrayAtLeast(2)); const string format = Config.SignificantFigures4; AppendFormatPoint("{0:" + format + "} {1:" + format + "} m\n", points[0].X, points[0].Y); for (int idx = 1; idx < count; idx++) AppendFormatPoint("{0:" + format + "} {1:" + format + "} l\n", points[idx].X, points[idx].Y); AppendStrokeFill(pen, brush, fillmode, true); }
// ----- DrawPie ------------------------------------------------------------------------------ public void DrawPie(XPen pen, XBrush brush, double x, double y, double width, double height, double startAngle, double sweepAngle) { Realize(pen, brush); const string format = Config.SignificantFigures4; AppendFormatPoint("{0:" + format + "} {1:" + format + "} m\n", x + width / 2, y + height / 2); AppendPartialArc(x, y, width, height, startAngle, sweepAngle, PathStart.LineTo1st, new XMatrix()); AppendStrokeFill(pen, brush, XFillMode.Alternate, true); }
public void RealizePen(XPen pen, PdfColorMode colorMode) { const string frmt2 = Config.SignificantFigures2; const string format = Config.SignificantFigures3; XColor color = pen.Color; bool overPrint = pen.Overprint; color = ColorSpaceHelper.EnsureColorMode(colorMode, color); if (_realizedLineWith != pen._width) { _renderer.AppendFormatArgs("{0:" + format + "} w\n", pen._width); _realizedLineWith = pen._width; } if (_realizedLineCap != (int)pen._lineCap) { _renderer.AppendFormatArgs("{0} J\n", (int)pen._lineCap); _realizedLineCap = (int)pen._lineCap; } if (_realizedLineJoin != (int)pen._lineJoin) { _renderer.AppendFormatArgs("{0} j\n", (int)pen._lineJoin); _realizedLineJoin = (int)pen._lineJoin; } if (_realizedLineCap == (int)XLineJoin.Miter) { if (_realizedMiterLimit != (int)pen._miterLimit && (int)pen._miterLimit != 0) { _renderer.AppendFormatInt("{0} M\n", (int)pen._miterLimit); _realizedMiterLimit = (int)pen._miterLimit; } } if (_realizedDashStyle != pen._dashStyle || pen._dashStyle == XDashStyle.Custom) { double dot = pen.Width; double dash = 3 * dot; // Line width 0 is not recommended but valid. XDashStyle dashStyle = pen.DashStyle; if (dot == 0) dashStyle = XDashStyle.Solid; switch (dashStyle) { case XDashStyle.Solid: _renderer.Append("[]0 d\n"); break; case XDashStyle.Dash: _renderer.AppendFormatArgs("[{0:" + frmt2 + "} {1:" + frmt2 + "}]0 d\n", dash, dot); break; case XDashStyle.Dot: _renderer.AppendFormatArgs("[{0:" + frmt2 + "}]0 d\n", dot); break; case XDashStyle.DashDot: _renderer.AppendFormatArgs("[{0:" + frmt2 + "} {1:" + frmt2 + "} {1:" + frmt2 + "} {1:" + frmt2 + "}]0 d\n", dash, dot); break; case XDashStyle.DashDotDot: _renderer.AppendFormatArgs("[{0:" + frmt2 + "} {1:" + frmt2 + "} {1:" + frmt2 + "} {1:" + frmt2 + "} {1:" + frmt2 + "} {1:" + frmt2 + "}]0 d\n", dash, dot); break; case XDashStyle.Custom: { StringBuilder pdf = new StringBuilder("[", 256); int len = pen._dashPattern == null ? 0 : pen._dashPattern.Length; for (int idx = 0; idx < len; idx++) { if (idx > 0) pdf.Append(' '); pdf.Append(PdfEncoders.ToString(pen._dashPattern[idx] * pen._width)); } // Make an even number of values look like in GDI+ if (len > 0 && len % 2 == 1) { pdf.Append(' '); pdf.Append(PdfEncoders.ToString(0.2 * pen._width)); } pdf.AppendFormat(CultureInfo.InvariantCulture, "]{0:" + format + "} d\n", pen._dashOffset * pen._width); string pattern = pdf.ToString(); // BUG: [email protected] reported a realizing problem // HACK: I remove the if clause //if (_realizedDashPattern != pattern) { _realizedDashPattern = pattern; _renderer.Append(pattern); } } break; } _realizedDashStyle = dashStyle; } if (colorMode != PdfColorMode.Cmyk) { if (_realizedStrokeColor.Rgb != color.Rgb) { _renderer.Append(PdfEncoders.ToString(color, PdfColorMode.Rgb)); _renderer.Append(" RG\n"); } } else { if (!ColorSpaceHelper.IsEqualCmyk(_realizedStrokeColor, color)) { _renderer.Append(PdfEncoders.ToString(color, PdfColorMode.Cmyk)); _renderer.Append(" K\n"); } } if (_renderer.Owner.Version >= 14 && (_realizedStrokeColor.A != color.A || _realizedStrokeOverPrint != overPrint)) { PdfExtGState extGState = _renderer.Owner.ExtGStateTable.GetExtGStateStroke(color.A, overPrint); string gs = _renderer.Resources.AddExtGState(extGState); _renderer.AppendFormatString("{0} gs\n", gs); // Must create transparency group. if (_renderer._page != null && color.A < 1) _renderer._page.TransparencyUsed = true; } _realizedStrokeColor = color; _realizedStrokeOverPrint = overPrint; }
public void RealizePen(XPen pen, PdfColorMode colorMode) { XColor color = pen.Color; color = ColorSpaceHelper.EnsureColorMode(colorMode, color); if (this.realizedLineWith != pen.width) { this.renderer.AppendFormat("{0:0.###} w\n", pen.width); this.realizedLineWith = pen.width; } if (this.realizedLineCap != (int)pen.lineCap) { this.renderer.AppendFormat("{0} J\n", (int)pen.lineCap); this.realizedLineCap = (int)pen.lineCap; } if (this.realizedLineJoin != (int)pen.lineJoin) { this.renderer.AppendFormat("{0} j\n", (int)pen.lineJoin); this.realizedLineJoin = (int)pen.lineJoin; } if (this.realizedLineCap == (int)XLineJoin.Miter) { if (this.realizedMiterLimit != (int)pen.miterLimit && (int)pen.miterLimit != 0) { this.renderer.AppendFormat("{0} M\n", (int)pen.miterLimit); this.realizedMiterLimit = (int)pen.miterLimit; } } if (this.realizedDashStyle != pen.dashStyle || pen.dashStyle == XDashStyle.Custom) { double dot = pen.Width; double dash = 3 * dot; // Line width 0 is not recommended but valid XDashStyle dashStyle = pen.DashStyle; if (dot == 0) dashStyle = XDashStyle.Solid; switch (dashStyle) { case XDashStyle.Solid: this.renderer.Append("[]0 d\n"); break; case XDashStyle.Dash: this.renderer.AppendFormat("[{0:0.##} {1:0.##}]0 d\n", dash, dot); break; case XDashStyle.Dot: this.renderer.AppendFormat("[{0:0.##}]0 d\n", dot); break; case XDashStyle.DashDot: this.renderer.AppendFormat("[{0:0.##} {1:0.##} {1:0.##} {1:0.##}]0 d\n", dash, dot); break; case XDashStyle.DashDotDot: this.renderer.AppendFormat("[{0:0.##} {1:0.##} {1:0.##} {1:0.##} {1:0.##} {1:0.##}]0 d\n", dash, dot); break; case XDashStyle.Custom: { StringBuilder pdf = new StringBuilder("[", 256); int len = pen.dashPattern == null ? 0 : pen.dashPattern.Length; for (int idx = 0; idx < len; idx++) { if (idx > 0) pdf.Append(' '); pdf.Append(PdfEncoders.ToString(pen.dashPattern[idx] * pen.width)); } // Make an even number of values look like in GDI+ if (len > 0 && len % 2 == 1) { pdf.Append(' '); pdf.Append(PdfEncoders.ToString(0.2 * pen.width)); } pdf.AppendFormat(CultureInfo.InvariantCulture, "]{0:0.###} d\n", pen.dashOffset * pen.width); string pattern = pdf.ToString(); // BUG: [email protected] reported a realizing problem // HACK: I romove the if clause //if (this.realizedDashPattern != pattern) { this.realizedDashPattern = pattern; this.renderer.Append(pattern); } } break; } this.realizedDashStyle = dashStyle; } if (colorMode != PdfColorMode.Cmyk) { if (this.realizedStrokeColor.Rgb != color.Rgb) { this.renderer.Append(PdfEncoders.ToString(color, PdfColorMode.Rgb)); this.renderer.Append(" RG\n"); } } else { if (!ColorSpaceHelper.IsEqualCmyk(this.realizedStrokeColor, color)) { this.renderer.Append(PdfEncoders.ToString(color, PdfColorMode.Cmyk)); this.renderer.Append(" K\n"); } } if (this.renderer.Owner.Version >= 14 && this.realizedStrokeColor.A != color.A) { PdfExtGState extGState = this.renderer.Owner.ExtGStateTable.GetExtGStateStroke(color.A); string gs = this.renderer.Resources.AddExtGState(extGState); this.renderer.AppendFormat("{0} gs\n", gs); // Must create transparany group if (this.renderer.page != null && color.A < 1) this.renderer.page.transparencyUsed = true; } this.realizedStrokeColor = color; }
// ----- DrawLines ---------------------------------------------------------------------------- /// <summary> /// Strokes a series of connected points. /// </summary> public void DrawLines(XPen pen, XPoint[] points) { if (pen == null) throw new ArgumentNullException("pen"); if (points == null) throw new ArgumentNullException("points"); int count = points.Length; if (count == 0) return; Realize(pen); const string format = Config.SignificantFigures4; AppendFormatPoint("{0:" + format + "} {1:" + format + "} m\n", points[0].X, points[0].Y); for (int idx = 1; idx < count; idx++) AppendFormatPoint("{0:" + format + "} {1:" + format + "} l\n", points[idx].X, points[idx].Y); _content.Append("S\n"); }