From 57e8de7087b6296e830f4e22c3983ede5f1d5635 Mon Sep 17 00:00:00 2001 From: Peter Forstmeier Date: Sat, 17 Jul 2010 01:00:51 +0000 Subject: [PATCH] Enhance PdfRectangle created by DisplayRectangle, small cleanups git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/reports@6129 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../ExportColumns/BaseExportColumn.cs | 25 ++++-- .../old_Exporter/ExportColumns/ExportImage.cs | 81 +++---------------- .../old_Exporter/ExportColumns/ExportText.cs | 70 ++++++---------- 3 files changed, 54 insertions(+), 122 deletions(-) diff --git a/src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/Project/old_Exporter/ExportColumns/BaseExportColumn.cs b/src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/Project/old_Exporter/ExportColumns/BaseExportColumn.cs index b0910f1af0..3dde415939 100644 --- a/src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/Project/old_Exporter/ExportColumns/BaseExportColumn.cs +++ b/src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/Project/old_Exporter/ExportColumns/BaseExportColumn.cs @@ -84,10 +84,10 @@ namespace ICSharpCode.Reports.Core.old_Exporter protected virtual void Decorate () { RectangleShape shape = new RectangleShape(); - iTextSharp.text.Rectangle rect = ConvertToPdfRectangle(); shape.DrawShape(this.pdfWriter.DirectContent, null, - this.styleDecorator,rect); + this.styleDecorator, + ConvertToPdfRectangle()); this.DrawFrame(); } @@ -119,14 +119,22 @@ namespace ICSharpCode.Reports.Core.old_Exporter #endregion + protected iTextSharp.text.Rectangle ConvertToPdfRectangle () { - ScreenRectToPdfRectConverter rectangleToPage = new ScreenRectToPdfRectConverter(this.converter); - return (iTextSharp.text.Rectangle)rectangleToPage.ConvertTo(null,System.Globalization.CultureInfo.InvariantCulture, - this.styleDecorator.DisplayRectangle, - typeof(iTextSharp.text.Rectangle)); + ScreenRectToPdfRectConverter rectangleConverter = new ScreenRectToPdfRectConverter(this.converter); + + iTextSharp.text.Rectangle r = (iTextSharp.text.Rectangle)rectangleConverter.ConvertTo(null,System.Globalization.CultureInfo.InvariantCulture, + this.styleDecorator.DisplayRectangle, + typeof(iTextSharp.text.Rectangle)); + + iTextSharp.text.Rectangle rr = new iTextSharp.text.Rectangle(r.Left,r.Bottom -2, + r.Left + r.Width,r.Bottom + r.Height); + + return rr; } + #region DrawFrame @@ -143,8 +151,9 @@ namespace ICSharpCode.Reports.Core.old_Exporter { if (this.styleDecorator.DrawBorder) { Border b = this.CreateDefaultBorder(); - iTextSharp.text.Rectangle rect = ConvertToPdfRectangle(); - b.DrawBorder(this.pdfWriter.DirectContent,rect,this.styleDecorator); + b.DrawBorder(this.pdfWriter.DirectContent, + ConvertToPdfRectangle(), + this.styleDecorator); } } diff --git a/src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/Project/old_Exporter/ExportColumns/ExportImage.cs b/src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/Project/old_Exporter/ExportColumns/ExportImage.cs index 70c2b85bc3..ccef0a5547 100644 --- a/src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/Project/old_Exporter/ExportColumns/ExportImage.cs +++ b/src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/Project/old_Exporter/ExportColumns/ExportImage.cs @@ -17,9 +17,10 @@ namespace ICSharpCode.Reports.Core.old_Exporter /// public class ExportImage:BaseExportColumn { - string fileName; + + System.Drawing.Image image; - bool scaleImageToSize; + #region Constructor @@ -28,13 +29,11 @@ namespace ICSharpCode.Reports.Core.old_Exporter } - public ExportImage (BaseStyleDecorator itemStyle):this(itemStyle,false) + public ExportImage (BaseStyleDecorator itemStyle):base(itemStyle,false) { + } - public ExportImage (BaseStyleDecorator itemStyle,bool isContainer):base(itemStyle,isContainer) - { - } #endregion @@ -47,7 +46,7 @@ namespace ICSharpCode.Reports.Core.old_Exporter } base.DrawItem(graphics); - if (this.scaleImageToSize) { + if (this.ScaleImageToSize) { graphics.DrawImageUnscaled(this.Image,this.StyleDecorator.DisplayRectangle); } else { @@ -71,63 +70,9 @@ namespace ICSharpCode.Reports.Core.old_Exporter } - /* - * - ColumnText ct2 = new ColumnText(t); - -> ct2.RunDirection = runDirection; - -> ct2.SetSimpleColumn(signatureRect.X, signatureRect.Y, - -> signatureRect.Width, signatureRect.Height, 0, Element.ALIGN_RIGHT); - -> - -> Image im = Image.GetInstance(SignatureGraphic); - -> im.ScaleToFit(signatureRect.Width, signatureRect.Height); - -> - -> System.Drawing.SizeF imageSize = new System.Drawing.SizeF(im.ScaledWidth, im.ScaledHeight); - -> Paragraph p = new Paragraph(); - -> // must calculate the point to draw from to make image appear in middle of column - -> System.Drawing.PointF originPoint = System.Drawing.PointF.Empty; - -> originPoint.X = 0; - -> // experimentation found this magic number to counteract Adobe's signature graphic, which - -> // offsets the y co-ordinate by 15 units - -> originPoint.Y = -im.ScaledHeight + 15; - -> - -> System.Drawing.PointF graphicLocation = System.Drawing.PointF.Empty; - -> graphicLocation.X = originPoint.X + (signatureRect.Width - im.ScaledWidth) / 2; - -> graphicLocation.Y = originPoint.Y - (signatureRect.Height - im.ScaledHeight) / 2; - -> p.Add(new Chunk(im, graphicLocation.X, graphicLocation.Y, false)); - -> ct2.AddElement(p); - -> ct2.Go(); - - - */ + #endregion - public override IBaseStyleDecorator StyleDecorator - { - get { return base.StyleDecorator; } - set { base.StyleDecorator = value; } - } // return a copy of image, otherwise pdf is not working public System.Drawing.Image Image @@ -137,14 +82,10 @@ namespace ICSharpCode.Reports.Core.old_Exporter } - public string FileName { - get { return fileName; } - set { fileName = value; } - } + public string FileName {get;set;} + + + public bool ScaleImageToSize {get;set;} - public bool ScaleImageToSize { - get { return scaleImageToSize; } - set { scaleImageToSize = value; } - } } } diff --git a/src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/Project/old_Exporter/ExportColumns/ExportText.cs b/src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/Project/old_Exporter/ExportColumns/ExportText.cs index 316b37af1f..44b2206dab 100644 --- a/src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/Project/old_Exporter/ExportColumns/ExportText.cs +++ b/src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/Project/old_Exporter/ExportColumns/ExportText.cs @@ -64,22 +64,20 @@ namespace ICSharpCode.Reports.Core.old_Exporter { base.Decorate(); PdfContentByte contentByte = base.PdfWriter.DirectContent; - iTextSharp.text.Rectangle r = base.ConvertToPdfRectangle(); + + CalculatePdfFormat pdfFormat = new CalculatePdfFormat(this.StyleDecorator,font); ColumnText columnText = new ColumnText(contentByte); - PdfFormat pdfFormat = new PdfFormat(this.StyleDecorator,font); - + 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); Chunk chunk = new Chunk(formated,font); - columnText.AddText(chunk); columnText.Go(); - } @@ -88,7 +86,7 @@ namespace ICSharpCode.Reports.Core.old_Exporter { base.DrawItem(graphics); base.Decorate(graphics); - TextDrawer.DrawString(graphics, this.text,this.StyleDecorator); + TextDrawer.DrawString(graphics, this.text,this.StyleDecorator); } #endregion @@ -123,15 +121,12 @@ namespace ICSharpCode.Reports.Core.old_Exporter { } - internal class PdfFormat { + internal class CalculatePdfFormat { - float leading; - int alignment; iTextSharp.text.Font font; TextStyleDecorator textDecorator; - float height; - public PdfFormat (TextStyleDecorator textDecorator,iTextSharp.text.Font font) + public CalculatePdfFormat (TextStyleDecorator textDecorator,iTextSharp.text.Font font) { if (textDecorator == null) { throw new ArgumentNullException ("textDecorator"); @@ -141,68 +136,55 @@ namespace ICSharpCode.Reports.Core.old_Exporter { } this.font = font; this.textDecorator = textDecorator; - this.height = Convert.ToInt16(UnitConverter.FromPixel(this.textDecorator.DisplayRectangle.Height).Point) + 1; +// this.leading = UnitConverter.FromPixel(textDecorator.Font.GetHeight()).Point; + this.Leading = font.Size; this.CalculateFormat(); } private void CalculateFormat() { - this.leading = font.Size; - this.alignment = PdfContentByte.ALIGN_LEFT; + + this.Alignment = PdfContentByte.ALIGN_LEFT; switch (textDecorator.ContentAlignment) { - //Top + //Top case ContentAlignment.TopLeft: - this.alignment = PdfContentByte.ALIGN_LEFT; - this.leading = UnitConverter.FromPixel(textDecorator.Font.GetHeight()).Point; + this.Alignment = PdfContentByte.ALIGN_LEFT; break; case ContentAlignment.TopCenter: - this.alignment = PdfContentByte.ALIGN_CENTER; -// this.leading = new UnitConverter(this.font.Size,XGraphicsUnit.Pixel).Point +1; - this.leading = UnitConverter.FromPixel(textDecorator.Font.GetHeight()).Point; + this.Alignment = PdfContentByte.ALIGN_CENTER; break; case ContentAlignment.TopRight: - this.alignment = PdfContentByte.ALIGN_RIGHT; -// this.leading = new UnitConverter(this.font.Size,XGraphicsUnit.Pixel).Point +1; - this.leading = UnitConverter.FromPixel(textDecorator.Font.GetHeight()).Point; + this.Alignment = PdfContentByte.ALIGN_RIGHT; break; - // Middle + // Middle case ContentAlignment.MiddleLeft: - this.alignment = PdfContentByte.ALIGN_LEFT; - this.leading = (float)Math.Ceiling((this.height / 2) + ((new UnitConverter(this.font.Size,XGraphicsUnit.Pixel).Point /2) - 0.5)); + this.Alignment = PdfContentByte.ALIGN_LEFT; break; case ContentAlignment.MiddleCenter: - this.alignment = PdfContentByte.ALIGN_CENTER; - this.leading = (float)Math.Ceiling((this.height / 2) + ((new UnitConverter(this.font.Size,XGraphicsUnit.Pixel).Point /2) - 0.5)); + this.Alignment = PdfContentByte.ALIGN_CENTER; break; case ContentAlignment.MiddleRight: - this.alignment = PdfContentByte.ALIGN_RIGHT; - this.leading = (float)Math.Ceiling((this.height / 2) + ((new UnitConverter(this.font.Size,XGraphicsUnit.Pixel).Point /2) - 0.5)); + this.Alignment = PdfContentByte.ALIGN_RIGHT; break; - //Bottom + //Bottom case ContentAlignment.BottomLeft: - this.alignment = PdfContentByte.ALIGN_LEFT; - this.leading = this.height - new UnitConverter(this.font.Size,XGraphicsUnit.Pixel).Point +4; + this.Alignment = PdfContentByte.ALIGN_LEFT; break; case ContentAlignment.BottomCenter: - this.alignment = PdfContentByte.ALIGN_CENTER; - this.leading = this.height - new UnitConverter(this.font.Size,XGraphicsUnit.Pixel).Point +4; + this.Alignment = PdfContentByte.ALIGN_CENTER; break; case ContentAlignment.BottomRight: - this.alignment = PdfContentByte.ALIGN_RIGHT; - this.leading = this.height - new UnitConverter(this.font.Size,XGraphicsUnit.Pixel).Point +4; + this.Alignment = PdfContentByte.ALIGN_RIGHT; break; } + } - public float Leading { - get { return leading; } - } - - public int Alignment { - get { return alignment; } - } + public float Leading {get;private set;} + public int Alignment {get;private set;} + } }