From 91fcce0a8225351cf34b89ed06d187427a45a082 Mon Sep 17 00:00:00 2001 From: peterforstmeier Date: Sat, 18 Sep 2010 20:27:05 +0200 Subject: [PATCH] Draw formatted String --- .../Project/BaseClasses/DataTypeHelper.cs | 12 ++++++------ .../BaseClasses/Printing/StandardFormatter.cs | 10 +++++++++- .../Project/BaseClasses/Printing/TextDrawer.cs | 10 +++++++++- .../Project/Exporter/ExportColumns/ExportText.cs | 14 +++++++++----- 4 files changed, 33 insertions(+), 13 deletions(-) diff --git a/src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/Project/BaseClasses/DataTypeHelper.cs b/src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/Project/BaseClasses/DataTypeHelper.cs index 1bc1ab8ffe..63b3c022d6 100644 --- a/src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/Project/BaseClasses/DataTypeHelper.cs +++ b/src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/Project/BaseClasses/DataTypeHelper.cs @@ -17,12 +17,12 @@ namespace ICSharpCode.Reports.Core private DataTypeHelper () { } - internal static TypeCode TypeCodeFromString (string type) { - if (String.IsNullOrEmpty(type)) { - throw new ArgumentNullException("type"); - } - return Type.GetTypeCode( Type.GetType(type)); - } +// internal static TypeCode TypeCodeFromString (string type) { +// if (String.IsNullOrEmpty(type)) { +// throw new ArgumentNullException("type"); +// } +// return Type.GetTypeCode( Type.GetType(type)); +// } /* internal static bool IsNumber(TypeCode tc){ diff --git a/src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/Project/BaseClasses/Printing/StandardFormatter.cs b/src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/Project/BaseClasses/Printing/StandardFormatter.cs index a0258dad76..4f2a48bd1b 100644 --- a/src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/Project/BaseClasses/Printing/StandardFormatter.cs +++ b/src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/Project/BaseClasses/Printing/StandardFormatter.cs @@ -18,10 +18,18 @@ namespace ICSharpCode.Reports.Core.BaseClasses.Printing internal static class StandardFormatter { + private static TypeCode TypeCodeFromString (string type) { + if (String.IsNullOrEmpty(type)) { + throw new ArgumentNullException("type"); + } + return Type.GetTypeCode( Type.GetType(type)); + } + + public static string FormatOutput(string valueToFormat,string format, string dataType, string nullValue ) { - TypeCode typeCode = DataTypeHelper.TypeCodeFromString(dataType); + TypeCode typeCode = TypeCodeFromString(dataType); return StandardFormatter.FormatItem(valueToFormat,format, typeCode,nullValue); } diff --git a/src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/Project/BaseClasses/Printing/TextDrawer.cs b/src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/Project/BaseClasses/Printing/TextDrawer.cs index 951f1f971e..36e689d4d1 100644 --- a/src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/Project/BaseClasses/Printing/TextDrawer.cs +++ b/src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/Project/BaseClasses/Printing/TextDrawer.cs @@ -54,9 +54,17 @@ namespace ICSharpCode.Reports.Core.BaseClasses.Printing throw new ArgumentNullException("decorator"); } StringFormat stringFormat = BuildStringFormat(decorator.StringTrimming,decorator.ContentAlignment); + + string formattedString = text; + + if (! String.IsNullOrEmpty(decorator.FormatString)) { + formattedString = StandardFormatter.FormatOutput(text,decorator.FormatString,decorator.DataType,"yyy"); + } + + graphics.TextRenderingHint = TextRenderingHint.AntiAlias; - graphics.DrawString (text,decorator.Font, + graphics.DrawString (formattedString,decorator.Font, new SolidBrush(decorator.ForeColor), new Rectangle(decorator.Location.X, decorator.Location.Y, diff --git a/src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/Project/Exporter/ExportColumns/ExportText.cs b/src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/Project/Exporter/ExportColumns/ExportText.cs index 0f817afaa0..9ed1cd6e39 100644 --- a/src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/Project/Exporter/ExportColumns/ExportText.cs +++ b/src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/Project/Exporter/ExportColumns/ExportText.cs @@ -70,11 +70,15 @@ namespace ICSharpCode.Reports.Core.Exporter { ColumnText columnText = new ColumnText(contentByte); iTextSharp.text.Rectangle r = base.ConvertToPdfRectangle(); columnText.SetSimpleColumn(r.Left, r.Top , r.Left + r.Width,r.Top - r.Height,pdfFormat.Leading,pdfFormat.Alignment); - - string formated = StandardFormatter.FormatOutput(this.text,this.StyleDecorator.FormatString, - this.StyleDecorator.DataType,String.Empty); - Console.WriteLine("--- {0}",formated); - Chunk chunk = new Chunk(formated,font); + + string formatedText = this.text; + + if (!String.IsNullOrEmpty(StyleDecorator.FormatString)) { + formatedText = StandardFormatter.FormatOutput(this.text,this.StyleDecorator.FormatString, + this.StyleDecorator.DataType,String.Empty); + } + + Chunk chunk = new Chunk(formatedText,font); columnText.AddText(chunk); columnText.Go();