From 68352da415de17b1ed96d5554d4b86a2631e5309 Mon Sep 17 00:00:00 2001 From: Peter Forstmeier Date: Sat, 18 Jan 2014 18:00:04 +0100 Subject: [PATCH] Change Drawing in Wpf to DrawingVisual to support DashStyle + LineCap --- .../ExportRenderer/FixedDocumentCreator.cs | 68 +++++++++++++++---- .../Src/Exporter/Visitors/WpfVisitor.cs | 53 +++++++++++---- .../Src/Items/Graphics/BaseGraphics.cs | 4 ++ .../Src/Items/Graphics/BaseLineItem.cs | 2 + .../PageBuilder/ExportColumns/ExportLine.cs | 5 ++ 5 files changed, 106 insertions(+), 26 deletions(-) diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/ExportRenderer/FixedDocumentCreator.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/ExportRenderer/FixedDocumentCreator.cs index 7152264fef..e82fba468b 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/ExportRenderer/FixedDocumentCreator.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/ExportRenderer/FixedDocumentCreator.cs @@ -256,12 +256,12 @@ namespace ICSharpCode.Reporting.ExportRenderer } - Pen CreateWpfPen(IReportObject exportColumn){ + public Pen CreateWpfPen(IReportObject exportColumn){ if (exportColumn == null) throw new ArgumentNullException("exportColumn"); var myPen = new Pen(); myPen.Brush = ConvertBrush(exportColumn.ForeColor); - myPen.Thickness = 1.5; + myPen.Thickness = 1; return myPen; } @@ -274,33 +274,77 @@ namespace ICSharpCode.Reporting.ExportRenderer } } - /* - public DashStyle DashStyle (IExportGraphics exportGraphics) { + + public static PenLineCap LineCap (System.Drawing.Drawing2D.LineCap lineCap) { + var penLineCap = PenLineCap.Flat; + switch (lineCap) { + case System.Drawing.Drawing2D.LineCap.Flat: + penLineCap = PenLineCap.Flat; + break; + case System.Drawing.Drawing2D.LineCap.Square: + penLineCap = PenLineCap.Square; + break; + case System.Drawing.Drawing2D.LineCap.Round: + penLineCap = PenLineCap.Round; + break; + case System.Drawing.Drawing2D.LineCap.Triangle: + penLineCap = PenLineCap.Triangle; + break; + case System.Drawing.Drawing2D.LineCap.NoAnchor: + penLineCap = PenLineCap.Flat; + break; + case System.Drawing.Drawing2D.LineCap.SquareAnchor: + penLineCap = PenLineCap.Flat; + break; + case System.Drawing.Drawing2D.LineCap.RoundAnchor: + penLineCap = PenLineCap.Flat; + break; + case System.Drawing.Drawing2D.LineCap.DiamondAnchor: + penLineCap = PenLineCap.Flat; + break; + case System.Drawing.Drawing2D.LineCap.ArrowAnchor: + penLineCap = PenLineCap.Flat; + break; + case System.Drawing.Drawing2D.LineCap.Custom: + penLineCap = PenLineCap.Flat; + break; + case System.Drawing.Drawing2D.LineCap.AnchorMask: + + break; + default: + throw new Exception("Invalid value for LineCap"); + + } + return penLineCap; + } + + public static DashStyle DashStyle (IExportGraphics exportGraphics) { + var dashStyle = DashStyles.Solid; switch (exportGraphics.DashStyle) { case System.Drawing.Drawing2D.DashStyle.Solid: - + dashStyle = DashStyles.Solid; break; case System.Drawing.Drawing2D.DashStyle.Dash: - + dashStyle = DashStyles.Dash; break; case System.Drawing.Drawing2D.DashStyle.Dot: - + dashStyle = DashStyles.Dot; break; case System.Drawing.Drawing2D.DashStyle.DashDot: - + dashStyle = DashStyles.DashDot; break; case System.Drawing.Drawing2D.DashStyle.DashDotDot: - + dashStyle = DashStyles.DashDotDot; break; case System.Drawing.Drawing2D.DashStyle.Custom: - + dashStyle = DashStyles.Solid; break; default: throw new Exception("Invalid value for DashStyle"); } - return DashStyle.Solid(); + return dashStyle; } - */ + } } diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Exporter/Visitors/WpfVisitor.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Exporter/Visitors/WpfVisitor.cs index ca54d49926..6dd5687ebf 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Exporter/Visitors/WpfVisitor.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Exporter/Visitors/WpfVisitor.cs @@ -11,6 +11,7 @@ using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Media; +using System.Windows.Media.Imaging; using ICSharpCode.Reporting.ExportRenderer; using ICSharpCode.Reporting.Interfaces.Export; @@ -85,20 +86,13 @@ namespace ICSharpCode.Reporting.Exporter.Visitors public override void Visit(ExportLine exportGraphics) { - var line = new System.Windows.Shapes.Line(); - - line.Stroke = documentCreator.ConvertBrush(exportGraphics.ForeColor); - - line.StrokeStartLineCap = PenLineCap.Round; - line.StrokeEndLineCap = PenLineCap.Round; - - line.StrokeThickness = exportGraphics.Thickness; - - line.X1 = exportGraphics.Location.X; - line.Y1 = exportGraphics.Location.Y; - line.X2 = exportGraphics.Size.Width; - line.Y2 = exportGraphics.Location.Y; - UIElement = line; + var pen = documentCreator.CreateWpfPen(exportGraphics); + pen.Thickness = exportGraphics.Thickness; + pen.DashStyle = FixedDocumentCreator.DashStyle(exportGraphics); + pen.StartLineCap = FixedDocumentCreator.LineCap(exportGraphics.StartLineCap); + pen.EndLineCap = FixedDocumentCreator.LineCap(exportGraphics.EndLineCap); + ExtendedLine m = new ExtendedLine(exportGraphics,pen); + UIElement = m; } @@ -107,4 +101,35 @@ namespace ICSharpCode.Reporting.Exporter.Visitors public FixedPage FixedPage {get; private set;} } + + + class ExtendedLine : FrameworkElement{ + private VisualCollection children; + + public ExtendedLine(ExportLine exportGraphics,Pen pen){ + children = new VisualCollection(this); + var visual = new DrawingVisual(); + children.Add(visual); + using (var dc = visual.RenderOpen()) + { + dc.DrawLine(pen, + new Point(exportGraphics.Location.X, exportGraphics.Location.Y), + new Point(exportGraphics.Location.X + exportGraphics.Size.Width,exportGraphics.Location.Y)); + } + } + + + protected override int VisualChildrenCount{ + get { return children.Count; } + } + + protected override Visual GetVisualChild(int index){ + if (index < 0 || index >= children.Count) + { + throw new ArgumentOutOfRangeException(); + } + + return children[index]; + } + } } diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Items/Graphics/BaseGraphics.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Items/Graphics/BaseGraphics.cs index a8086ec493..c192f04e92 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Items/Graphics/BaseGraphics.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Items/Graphics/BaseGraphics.cs @@ -20,5 +20,9 @@ namespace ICSharpCode.Reporting.Items public virtual int Thickness {get;set;} public virtual DashStyle DashStyle {get;set;} + + public virtual LineCap StartLineCap {get;set;} + + public virtual LineCap EndLineCap {get;set;} } } diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Items/Graphics/BaseLineItem.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Items/Graphics/BaseLineItem.cs index 085cc1d183..dbad638e7d 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Items/Graphics/BaseLineItem.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Items/Graphics/BaseLineItem.cs @@ -24,6 +24,8 @@ namespace ICSharpCode.Reporting.Items{ ex.DesiredSize = Size; ex.Thickness = Thickness; ex.DashStyle = DashStyle; + ex.StartLineCap = StartLineCap; + ex.EndLineCap = EndLineCap; return ex; } } diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/PageBuilder/ExportColumns/ExportLine.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/PageBuilder/ExportColumns/ExportLine.cs index 1df439d934..7ddbd9cd36 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/PageBuilder/ExportColumns/ExportLine.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/PageBuilder/ExportColumns/ExportLine.cs @@ -14,6 +14,8 @@ namespace ICSharpCode.Reporting.PageBuilder.ExportColumns public interface IExportGraphics:IExportColumn { int Thickness {get;set;} DashStyle DashStyle {get;set;} + LineCap StartLineCap {get;set;} + LineCap EndLineCap {get;set;} } @@ -39,5 +41,8 @@ namespace ICSharpCode.Reporting.PageBuilder.ExportColumns public DashStyle DashStyle {get;set;} + public LineCap StartLineCap {get;set;} + + public LineCap EndLineCap {get;set;} } }