From 2ee9802889a8265a8cc97edeae592cd3c6273acc Mon Sep 17 00:00:00 2001 From: panthernet Date: Mon, 18 Jan 2016 23:49:40 +0300 Subject: [PATCH] - Exposed internal PrintHelper class with new CalculateEstimatedDPI() method which can calculate DPI required for image export based on specified criterias - Fixed arrows display issue when printing --- Documents/CHANGELOG.txt | 7 +++- GraphX.Controls/Controls/GraphArea.cs | 1 + GraphX.Controls/GraphX.WPF.Controls.csproj | 5 ++- GraphX.Controls/PrintHelper.cs | 41 ++++++++++++++++++++-- GraphX.PCL.Logic/GraphX.PCL.Logic.csproj | 13 ++++--- 5 files changed, 53 insertions(+), 14 deletions(-) diff --git a/Documents/CHANGELOG.txt b/Documents/CHANGELOG.txt index f277be90..5664c570 100644 --- a/Documents/CHANGELOG.txt +++ b/Documents/CHANGELOG.txt @@ -1,4 +1,9 @@ -RELEASE 2.3.2 +RELEASE 2.3.3 +DETAILED CHANGELOG: + - Exposed internal PrintHelper class with new CalculateEstimatedDPI() method which can calculate DPI required for image export based on specified criterias + - Fixed arrows display issue when printing + +RELEASE 2.3.2 DETAILED CHANGELOG: - Added GraphArea::ExportAsImageDialog() method which act as old ExportAsImage and the ExportAsImage() method now accepts filename to work without the dialog diff --git a/GraphX.Controls/Controls/GraphArea.cs b/GraphX.Controls/Controls/GraphArea.cs index bb6fc36f..a8e5ea70 100644 --- a/GraphX.Controls/Controls/GraphArea.cs +++ b/GraphX.Controls/Controls/GraphArea.cs @@ -2020,6 +2020,7 @@ public override void SetPrintMode(bool value, bool offsetControls = true, int ma } InvalidateMeasure(); UpdateLayout(); + EdgesList.Values.ForEach(a=> a.UpdateEdge()); #endif } diff --git a/GraphX.Controls/GraphX.WPF.Controls.csproj b/GraphX.Controls/GraphX.WPF.Controls.csproj index ef2321cc..abaef419 100644 --- a/GraphX.Controls/GraphX.WPF.Controls.csproj +++ b/GraphX.Controls/GraphX.WPF.Controls.csproj @@ -41,14 +41,14 @@ bin\x86\Debug\ TRACE;DEBUG;WPF full - x86 + AnyCPU prompt MinimumRecommendedRules.ruleset false bin\x86\Release\ - TRACE + TRACE;WPF true pdbonly x86 @@ -206,7 +206,6 @@ GraphX.PCL.Logic - diff --git a/GraphX.Controls/PrintHelper.cs b/GraphX.Controls/PrintHelper.cs index 70ae7e5f..74d12207 100644 --- a/GraphX.Controls/PrintHelper.cs +++ b/GraphX.Controls/PrintHelper.cs @@ -8,10 +8,11 @@ using GraphX.PCL.Common.Enums; using GraphX.PCL.Common.Exceptions; using Brushes = System.Windows.Media.Brushes; +using Size = System.Windows.Size; namespace GraphX.Controls { - internal static class PrintHelper + public static class PrintHelper { /// /// Default image resolution @@ -21,6 +22,34 @@ internal static class PrintHelper //Set pixelformat of image. private static readonly PixelFormat PixelFormat = PixelFormats.Pbgra32; + /// + /// Helper method which calculates estimated image DPI based on the input criterias + /// + /// GraphArea object + /// Desired DPI + /// DPI decrease step while estimating + /// Pixel quantity threshold + public static double CalculateEstimatedDPI(GraphAreaBase vis, double imgdpi, double dpiStep, int estPixelCount) + { + bool result = false; + double currentDPI = imgdpi; + while (!result) + { + if (CalulateSize(vis.ContentSize.Size, currentDPI) <= estPixelCount) + result = true; + else currentDPI -= dpiStep; + if (currentDPI < 0) return 0; + } + return currentDPI; + } + + + private static int CalulateSize(Size desiredSize, double dpi) + { + return (int) (desiredSize.Width*(dpi/DEFAULT_DPI) + 100) * + (int) (desiredSize.Height*(dpi/DEFAULT_DPI) + 100); + } + /// /// Method exports the GraphArea to an png image. /// @@ -32,7 +61,7 @@ internal static class PrintHelper /// public static void ExportToImage(GraphAreaBase surface, Uri path, ImageType itype, bool useZoomControlSurface = false, double imgdpi = DEFAULT_DPI, int imgQuality = 100) { - if(!useZoomControlSurface) + if (!useZoomControlSurface) surface.SetPrintMode(true, true, 100); //Create a render bitmap and push the surface to it UIElement vis = surface; @@ -44,10 +73,13 @@ public static void ExportToImage(GraphAreaBase surface, Uri path, ImageType ityp else { var frameworkElement = surface.Parent as FrameworkElement; - if(frameworkElement != null && frameworkElement.Parent is IZoomControl) + if (frameworkElement != null && frameworkElement.Parent is IZoomControl) vis = ((IZoomControl) frameworkElement.Parent).PresenterVisual; } } + + + var renderBitmap = new RenderTargetBitmap( (int)(vis.DesiredSize.Width * (imgdpi / DEFAULT_DPI) + 100), @@ -85,6 +117,8 @@ public static void ExportToImage(GraphAreaBase surface, Uri path, ImageType ityp //Save the data to the stream encoder.Save(outStream); } + renderBitmap.Clear(); + renderBitmap = null; //due to mem leak in wpf :( GC.Collect(); GC.WaitForPendingFinalizers(); @@ -95,6 +129,7 @@ public static void ExportToImage(GraphAreaBase surface, Uri path, ImageType ityp } + public static void ShowPrintPreview(Visual surface, string description = "") { try diff --git a/GraphX.PCL.Logic/GraphX.PCL.Logic.csproj b/GraphX.PCL.Logic/GraphX.PCL.Logic.csproj index d4bfd592..00f8ee1b 100644 --- a/GraphX.PCL.Logic/GraphX.PCL.Logic.csproj +++ b/GraphX.PCL.Logic/GraphX.PCL.Logic.csproj @@ -46,13 +46,6 @@ signature.snk - - - - {3644d44b-dec0-4b65-bba0-c68e34821aae} - GraphX.PCL.Common - - Properties\AIV.cs @@ -184,6 +177,12 @@ True + + + {3644d44b-dec0-4b65-bba0-c68e34821aae} + GraphX.PCL.Common + +