From bd1b9e2852cb03ea6a96bd1d3178664d45ef28f1 Mon Sep 17 00:00:00 2001 From: Peter Forstmeier Date: Wed, 14 Aug 2013 20:18:27 +0200 Subject: [PATCH] ContentAlignment in Pdf --- .../Exporter/ExportColumns/ExportText.cs | 61 ++++++------------- 1 file changed, 20 insertions(+), 41 deletions(-) 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 d35d9bc1ce..e6a45c422e 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 @@ -36,23 +36,22 @@ namespace ICSharpCode.Reports.Core.Exporter { throw new ArgumentNullException("converter"); } base.DrawItem(pdfWriter,converter); - base.Decorate(); PdfContentByte contentByte = base.PdfWriter.DirectContent; - iTextSharp.text.Font font = CreateFontFromFactory(this.StyleDecorator); - CalculatePdfFormat pdfFormat = new CalculatePdfFormat(this.StyleDecorator,font); + var font = CreateFontFromFactory(this.StyleDecorator); - ColumnText columnText = new ColumnText(contentByte); + var columnText = new ColumnText(contentByte); if (StyleDecorator.RightToLeft.ToString() == "Yes") { columnText.RunDirection = PdfWriter.RUN_DIRECTION_RTL; } - iTextSharp.text.Rectangle r = base.ConvertToPdfRectangle(); - columnText.SetSimpleColumn(r.Left, r.Top , r.Left + r.Width,r.Top - r.Height,pdfFormat.Leading,pdfFormat.Alignment); - + var pdfRectangle = base.ConvertToPdfRectangle(); + + columnText.SetSimpleColumn(pdfRectangle.Left, pdfRectangle.Top , pdfRectangle.Left + pdfRectangle.Width,pdfRectangle.Top - pdfRectangle.Height); + string formatedText = this.Text; if (!String.IsNullOrEmpty(StyleDecorator.FormatString)) { @@ -63,7 +62,7 @@ namespace ICSharpCode.Reports.Core.Exporter { Chunk chunk = new Chunk(formatedText,font); columnText.AddText(chunk); - + columnText.Alignment = CalculatePdfFormat.PdfAlignment(this.StyleDecorator); columnText.Go(); } @@ -125,67 +124,47 @@ namespace ICSharpCode.Reports.Core.Exporter { } + internal class CalculatePdfFormat { - TextStyleDecorator textDecorator; - - public CalculatePdfFormat (TextStyleDecorator textDecorator,iTextSharp.text.Font font) - { - if (textDecorator == null) { - throw new ArgumentNullException ("textDecorator"); - } - if (font == null) { - throw new ArgumentNullException("font"); - } - this.textDecorator = textDecorator; - this.Leading = font.Size; - this.CalculateFormat(); - } - - - private void CalculateFormat() + public static int PdfAlignment(TextStyleDecorator textDecorator) { - - this.Alignment = PdfContentByte.ALIGN_LEFT; + int retVal = 0; switch (textDecorator.ContentAlignment) { //Top case ContentAlignment.TopLeft: - this.Alignment = PdfContentByte.ALIGN_LEFT; + retVal = PdfContentByte.ALIGN_LEFT; break; case ContentAlignment.TopCenter: - this.Alignment = PdfContentByte.ALIGN_CENTER; + retVal = PdfContentByte.ALIGN_CENTER; break; case ContentAlignment.TopRight: - this.Alignment = PdfContentByte.ALIGN_RIGHT; + retVal = PdfContentByte.ALIGN_RIGHT; break; // Middle case ContentAlignment.MiddleLeft: - this.Alignment = PdfContentByte.ALIGN_LEFT; + retVal = PdfContentByte.ALIGN_LEFT; break; case ContentAlignment.MiddleCenter: - this.Alignment = PdfContentByte.ALIGN_CENTER; + retVal = PdfContentByte.ALIGN_CENTER; break; case ContentAlignment.MiddleRight: - this.Alignment = PdfContentByte.ALIGN_RIGHT; + retVal = PdfContentByte.ALIGN_RIGHT; break; //Bottom case ContentAlignment.BottomLeft: - this.Alignment = PdfContentByte.ALIGN_LEFT; + retVal = PdfContentByte.ALIGN_LEFT; break; case ContentAlignment.BottomCenter: - this.Alignment = PdfContentByte.ALIGN_CENTER; + retVal = PdfContentByte.ALIGN_CENTER; break; case ContentAlignment.BottomRight: - this.Alignment = PdfContentByte.ALIGN_RIGHT; + retVal = PdfContentByte.ALIGN_RIGHT; break; } + return retVal; } - - public float Leading {get;private set;} - - public int Alignment {get;private set;} - } }