void IDrawingCanvas.IntersectClip(RectangleF rect) { if (_clipBounds.Width == 0 || _clipBounds.Height == 0) { _clipBounds = rect; } else { _clipBounds = RectangleF.Intersect(_clipBounds, rect); } _graphics.IntersectClip(PdfConverter.Convert(rect)); }
void IDrawingCanvas.DrawString(string value, FontInfo font, BrushEx brush, RectangleF rect, StringFormatEx format) { if (string.IsNullOrEmpty(value)) { return; } XGraphicsContainer clipState = _graphics.BeginContainer(); var xRect = PdfConverter.Convert(rect); var xFont = _fonts.GetPdfFont(font); _graphics.IntersectClip(xRect); var resultRect = _graphics.MeasureString(value, xFont, GetFormat(format)); if ((format.WrapMode == WrapMode.NoWrap && !value.Contains('\n')) || (resultRect.Width * PdfConverter.TwipsPerPoint <= rect.Width)) { _graphics.DrawString(value, xFont, (BrushBase)brush, xRect, GetFormat(format)); _graphics.EndContainer(clipState); return; } if (format.WrapMode == WrapMode.NoWrap && value.Contains('\n')) { var lines = value.Split('\n'); var y = xRect.Y; for (var i = 0; i < lines.Length; i++) { var line = lines[i].Trim('\r'); _graphics.DrawString(line, xFont, (BrushBase)brush, new XRect(xRect.X, y, xRect.Width, resultRect.Height), GetFormat(format)); y += resultRect.Height; } _graphics.EndContainer(clipState); return; } // http://developer.th-soft.com/developer/2015/07/17/pdfsharp-improving-the-xtextformatter-class-measuring-the-height-of-the-text/ // http://developer.th-soft.com/developer/2015/09/21/xtextformatter-revisited-xtextformatterex2-for-pdfsharp-1-50-beta-2/ var tf = new XTextFormatter(_graphics) { Alignment = GetAlignment(format) }; tf.DrawString(value, xFont, (BrushBase)brush, xRect); _graphics.EndContainer(clipState); }
public static XGraphicsPath GetPath(PathEx pathEx) { var path = new XGraphicsPath(); path.FillMode = (XFillMode)Enum.Parse(typeof(XFillMode), pathEx.FillMode.ToString()); path.StartFigure(); var start = new XPoint(); foreach (var segment in pathEx.Segments) { switch (segment.Type) { case PathEx.SegmentType.MoveTo: start = PdfConverter.Convert(segment.Point1.ToPoint()); break; case PathEx.SegmentType.LineTo: var end = PdfConverter.Convert(segment.Point1.ToPoint()); path.AddLine(start, end); start = end; break; case PathEx.SegmentType.BezierTo: var p1 = PdfConverter.Convert(segment.Point1.ToPoint()); var p2 = PdfConverter.Convert(segment.Point2.ToPoint()); var bEnd = PdfConverter.Convert(segment.Point3.ToPoint()); path.AddBezier(start, p1, p2, bEnd); start = bEnd; break; case PathEx.SegmentType.FigureEnd: if (segment.Closed) { path.CloseFigure(); } break; } } return(path); }
void IDrawingCanvas.DrawLine(PenEx pen, PointF from, PointF to) { _graphics.DrawLine((Pen)pen, PdfConverter.Convert(from), PdfConverter.Convert(to)); }
void IDrawingCanvas.DrawImage(ImageEx image, float x, float y, float width, float height, float opacity) { _graphics.DrawImage((Image)image, PdfConverter.Convert(new RectangleF(x, y, width, height))); }
void IDrawingCanvas.DrawLines(PenEx pen, PointF[] polyLine) { _graphics.DrawLines((Pen)pen, polyLine.Select(p => PdfConverter.Convert(p)).ToArray()); }
void IDrawingCanvas.FillPolygon(BrushEx brush, PointF[] polygon) { _graphics.DrawPolygon((BrushBase)brush, polygon.Select(p => PdfConverter.Convert(p)).ToArray(), XFillMode.Winding); }
void IDrawingCanvas.DrawPolygon(PenEx pen, PointF[] points) { _graphics.DrawPolygon((Pen)pen, points.Select(p => PdfConverter.Convert(p)).ToArray()); }
void IDrawingCanvas.FillEllipse(BrushEx brush, RectangleF rect) { _graphics.DrawEllipse((BrushBase)brush, PdfConverter.Convert(rect)); }
void IDrawingCanvas.DrawEllipse(PenEx pen, RectangleF rect) { _graphics.DrawEllipse((Pen)pen, PdfConverter.Convert(rect)); }
void IGenerator.UrlGoTo(string link, int sourcePage, RectangleF sourceArea) { _document.Pages[sourcePage - 1].AddWebLink(new PdfRectangle(PdfConverter.Convert(sourceArea)), link); }
public LinearGradientBrush(PointF point1, PointF point2, Color color1, Color color2) { _brushInfo = new XLinearGradientBrush(PdfConverter.Convert(point1), PdfConverter.Convert(point2), XColor.FromArgb(color1.ToArgb()), XColor.FromArgb(color2.ToArgb())); }