From d6a9f13d54708bbfe69156af805b6f03b96a827c Mon Sep 17 00:00:00 2001 From: Peter Forstmeier Date: Sat, 28 Dec 2013 20:15:20 +0100 Subject: [PATCH] StringMeasurement inside Container, StringTrimming in TextBlock --- .../Src/Arrange/MeasurementStrategy.cs | 4 + .../ExportRenderer/FixedDocumentCreator.cs | 130 ++++++------------ .../Src/Exporter/Visitors/CanvasExtension.cs | 6 +- .../Src/Globals/MeasurementService.cs | 7 +- 4 files changed, 52 insertions(+), 95 deletions(-) diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Arrange/MeasurementStrategy.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Arrange/MeasurementStrategy.cs index ff77a9124f..0234653559 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Arrange/MeasurementStrategy.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Arrange/MeasurementStrategy.cs @@ -31,6 +31,10 @@ namespace ICSharpCode.Reporting.Arrange var items = ((ExportContainer)exportColumn).ExportedItems; foreach (var element in items) { + if (element is IExportContainer) { + Console.WriteLine("Measure -> Container found"); + Measure(element,graphics); + } var tbi = element as IExportText; if (tbi != null) { element.DesiredSize = MeasurementService.Measure(tbi,graphics); 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 d25526c95c..3949de05ae 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/ExportRenderer/FixedDocumentCreator.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/ExportRenderer/FixedDocumentCreator.cs @@ -7,7 +7,6 @@ * To change this template use Tools | Options | Coding | Edit Standard Headers. */ using System; - using System.Globalization; using System.Windows; using System.Windows.Controls; @@ -56,25 +55,35 @@ namespace ICSharpCode.Reporting.ExportRenderer canvas.UpdateLayout(); return canvas; } + public TextBlock CreateTextBlock(ExportText exportText,bool setBackcolor){ - var textBlock = new TextBlock(); + var textBlock = new TextBlock(); + textBlock.Foreground = ConvertBrush(exportText.ForeColor); - + /* if (setBackcolor) { textBlock.Background = ConvertBrush(exportText.BackColor); } + */ + textBlock.Background = ConvertBrush(System.Drawing.Color.LightPink); -// textBlock.Background = ConvertBrush(System.Drawing.Color.LightGray); - SetFont(textBlock,exportText); - textBlock.TextWrapping = TextWrapping.WrapWithOverflow; + textBlock.TextWrapping = TextWrapping.Wrap; + textBlock.TextTrimming = TextTrimming.CharacterEllipsis; - string [] inlines = exportText.Text.Split(System.Environment.NewLine.ToCharArray()); - + CheckForNewLine (textBlock,exportText); + SetContentAlignment(textBlock,exportText); + MeasureTextBlock (textBlock,exportText); + return textBlock; + } + + + static void CheckForNewLine(TextBlock textBlock,ExportText exportText) { + string [] inlines = exportText.Text.Split(Environment.NewLine.ToCharArray()); for (int i = 0; i < inlines.Length; i++) { if (inlines[i].Length > 0) { textBlock.Inlines.Add(new Run(inlines[i])); @@ -83,45 +92,37 @@ namespace ICSharpCode.Reporting.ExportRenderer } var li = textBlock.Inlines.LastInline; textBlock.Inlines.Remove(li); - SetContentAlignment(textBlock,exportText); + } + + + static void MeasureTextBlock(TextBlock textBlock,ExportText exportText) + { var wpfSize = MeasureTextInWpf(exportText); textBlock.Width = wpfSize.Width; textBlock.Height = wpfSize.Height; - -// textBlock.Background = ConvertBrush(exportText.StyleDecorator.BackColor); -// SetContendAlignment(textBlock,exportText.StyleDecorator); - if (exportText.ContentAlignment != System.Drawing.ContentAlignment.TopLeft) { - Console.WriteLine("----Aliogn --------{0}",exportText.ContentAlignment.ToString()); - } -// SetContentAlignment(textBlock,exportText); - return textBlock; - } - + } static Size MeasureTextInWpf(ExportText exportText){ if (exportText.CanGrow) { - - FormattedText ft = new FormattedText(exportText.Text, - CultureInfo.CurrentCulture, - System.Windows.FlowDirection.LeftToRight, - new Typeface(exportText.Font.FontFamily.Name), - exportText.Font.Size, -// System.Windows.Media.Brushes.Black, - new SolidColorBrush(exportText.ForeColor.ToWpf()), - - null, - TextFormattingMode.Display); - - ft.MaxTextWidth = exportText.Size.Width * 96.0 / 72.0; - ft.MaxTextHeight = Double.MaxValue ; - - ft.SetFontSize(exportText.Font.Size * 96.0 / 72.0); - - var ss = new Size { - Width = ft.WidthIncludingTrailingWhitespace, - Height = ft.Height}; - return ss; + FormattedText ft = new FormattedText(exportText.Text, + CultureInfo.CurrentCulture, + System.Windows.FlowDirection.LeftToRight, + new Typeface(exportText.Font.FontFamily.Name), + exportText.Font.Size, + new SolidColorBrush(exportText.ForeColor.ToWpf()), + null, + TextFormattingMode.Display); + + ft.MaxTextWidth = exportText.Size.Width * 96.0 / 72.0; + ft.MaxTextHeight = Double.MaxValue ; + + ft.SetFontSize(exportText.Font.Size * 96.0 / 72.0); + + var size = new Size { + Width = ft.WidthIncludingTrailingWhitespace, + Height = ft.Height}; + return size; } return new Size(exportText.Size.Width,exportText.Size.Height); } @@ -185,7 +186,6 @@ namespace ICSharpCode.Reporting.ExportRenderer // http://social.msdn.microsoft.com/Forums/vstudio/en-US/e480abb9-a86c-4f78-8955-dddb866bcfef/vertical-text-alignment-in-textblock?forum=wpf //Vertical alignment not working - Console.WriteLine("align {0}",exportText.ContentAlignment); switch (exportText.ContentAlignment) { case System.Drawing.ContentAlignment.TopLeft: textBlock.VerticalAlignment = VerticalAlignment.Top; @@ -227,52 +227,8 @@ namespace ICSharpCode.Reporting.ExportRenderer break; } } - /* - private void SetContendAlignment(TextBlock textBlock,TextStyleDecorator decorator) - { - switch (decorator.ContentAlignment) - { - case ContentAlignment.TopLeft: - textBlock.VerticalAlignment = VerticalAlignment.Top; - textBlock.TextAlignment = TextAlignment.Left; - break; - case ContentAlignment.TopCenter: - textBlock.VerticalAlignment = VerticalAlignment.Top; - textBlock.TextAlignment = TextAlignment.Center; - break; - case ContentAlignment.TopRight: - textBlock.VerticalAlignment = VerticalAlignment.Top; - textBlock.TextAlignment = TextAlignment.Right; - break; - // Middle - case ContentAlignment.MiddleLeft: - textBlock.VerticalAlignment = VerticalAlignment.Center; - textBlock.TextAlignment = TextAlignment.Left; - break; - case ContentAlignment.MiddleCenter: - textBlock.VerticalAlignment = VerticalAlignment.Center; - textBlock.TextAlignment = TextAlignment.Center; - break; - case ContentAlignment.MiddleRight: - textBlock.VerticalAlignment = VerticalAlignment.Center; - textBlock.TextAlignment = TextAlignment.Right; - break; - //Bottom - case ContentAlignment.BottomLeft: - textBlock.VerticalAlignment = VerticalAlignment.Bottom; - textBlock.TextAlignment = TextAlignment.Left; - break; - case ContentAlignment.BottomCenter: - textBlock.VerticalAlignment = VerticalAlignment.Bottom; - textBlock.TextAlignment = TextAlignment.Center; - break; - case ContentAlignment.BottomRight: - textBlock.VerticalAlignment = VerticalAlignment.Bottom; - textBlock.TextAlignment = TextAlignment.Right; - break; - } - } - */ + + void CreateStrikeout (TextBlock textBlock,IExportText exportColumn ){ if (textBlock == null) throw new ArgumentNullException("textBlock"); diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Exporter/Visitors/CanvasExtension.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Exporter/Visitors/CanvasExtension.cs index be8701e153..94e6f65970 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Exporter/Visitors/CanvasExtension.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Exporter/Visitors/CanvasExtension.cs @@ -15,7 +15,7 @@ namespace ICSharpCode.Reporting.Exporter.Visitors public static void AddChild(this Canvas canvas, T element) { - UIElement uiElement = element as UIElement; + var uiElement = element as UIElement; if (uiElement != null && !canvas.Children.Contains(uiElement)) canvas.Children.Add(uiElement); } @@ -23,7 +23,7 @@ namespace ICSharpCode.Reporting.Exporter.Visitors public static void RemoveChild(this Canvas canvas, T element) { - UIElement uiElement = element as UIElement; + var uiElement = element as UIElement; if (uiElement != null && canvas.Children.Contains(uiElement)) canvas.Children.Remove(uiElement); } @@ -31,7 +31,7 @@ namespace ICSharpCode.Reporting.Exporter.Visitors public static void InsertChild(this Canvas canvas, int index, T element) { - UIElement uiElement = element as UIElement; + var uiElement = element as UIElement; if (uiElement != null && !canvas.Children.Contains(uiElement)) canvas.Children.Insert(index, uiElement); } diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Globals/MeasurementService.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Globals/MeasurementService.cs index 17208e050b..3188c6bec3 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Globals/MeasurementService.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Globals/MeasurementService.cs @@ -15,15 +15,12 @@ namespace ICSharpCode.Reporting.Globals /// /// Description of MeasurementService. /// - internal class MeasurementService + internal static class MeasurementService { - public MeasurementService() - { - } public static Size Measure (IExportText item,Graphics graphics) { - + Console.WriteLine("Measure {0}",item.Text); if (!item.CanGrow) { return item.Size; }