Browse Source

ContentAlignment in Pdf

reports
Peter Forstmeier 12 years ago
parent
commit
bd1b9e2852
  1. 61
      src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/Project/Exporter/ExportColumns/ExportText.cs

61
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"); throw new ArgumentNullException("converter");
} }
base.DrawItem(pdfWriter,converter); base.DrawItem(pdfWriter,converter);
base.Decorate(); base.Decorate();
PdfContentByte contentByte = base.PdfWriter.DirectContent; PdfContentByte contentByte = base.PdfWriter.DirectContent;
iTextSharp.text.Font font = CreateFontFromFactory(this.StyleDecorator); var font = CreateFontFromFactory(this.StyleDecorator);
CalculatePdfFormat pdfFormat = new CalculatePdfFormat(this.StyleDecorator,font);
ColumnText columnText = new ColumnText(contentByte); var columnText = new ColumnText(contentByte);
if (StyleDecorator.RightToLeft.ToString() == "Yes") { if (StyleDecorator.RightToLeft.ToString() == "Yes") {
columnText.RunDirection = PdfWriter.RUN_DIRECTION_RTL; columnText.RunDirection = PdfWriter.RUN_DIRECTION_RTL;
} }
iTextSharp.text.Rectangle r = base.ConvertToPdfRectangle(); var pdfRectangle = base.ConvertToPdfRectangle();
columnText.SetSimpleColumn(r.Left, r.Top , r.Left + r.Width,r.Top - r.Height,pdfFormat.Leading,pdfFormat.Alignment);
columnText.SetSimpleColumn(pdfRectangle.Left, pdfRectangle.Top , pdfRectangle.Left + pdfRectangle.Width,pdfRectangle.Top - pdfRectangle.Height);
string formatedText = this.Text; string formatedText = this.Text;
if (!String.IsNullOrEmpty(StyleDecorator.FormatString)) { if (!String.IsNullOrEmpty(StyleDecorator.FormatString)) {
@ -63,7 +62,7 @@ namespace ICSharpCode.Reports.Core.Exporter {
Chunk chunk = new Chunk(formatedText,font); Chunk chunk = new Chunk(formatedText,font);
columnText.AddText(chunk); columnText.AddText(chunk);
columnText.Alignment = CalculatePdfFormat.PdfAlignment(this.StyleDecorator);
columnText.Go(); columnText.Go();
} }
@ -125,67 +124,47 @@ namespace ICSharpCode.Reports.Core.Exporter {
} }
internal class CalculatePdfFormat { internal class CalculatePdfFormat {
TextStyleDecorator textDecorator; public static int PdfAlignment(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()
{ {
int retVal = 0;
this.Alignment = PdfContentByte.ALIGN_LEFT;
switch (textDecorator.ContentAlignment) { switch (textDecorator.ContentAlignment) {
//Top //Top
case ContentAlignment.TopLeft: case ContentAlignment.TopLeft:
this.Alignment = PdfContentByte.ALIGN_LEFT; retVal = PdfContentByte.ALIGN_LEFT;
break; break;
case ContentAlignment.TopCenter: case ContentAlignment.TopCenter:
this.Alignment = PdfContentByte.ALIGN_CENTER; retVal = PdfContentByte.ALIGN_CENTER;
break; break;
case ContentAlignment.TopRight: case ContentAlignment.TopRight:
this.Alignment = PdfContentByte.ALIGN_RIGHT; retVal = PdfContentByte.ALIGN_RIGHT;
break; break;
// Middle // Middle
case ContentAlignment.MiddleLeft: case ContentAlignment.MiddleLeft:
this.Alignment = PdfContentByte.ALIGN_LEFT; retVal = PdfContentByte.ALIGN_LEFT;
break; break;
case ContentAlignment.MiddleCenter: case ContentAlignment.MiddleCenter:
this.Alignment = PdfContentByte.ALIGN_CENTER; retVal = PdfContentByte.ALIGN_CENTER;
break; break;
case ContentAlignment.MiddleRight: case ContentAlignment.MiddleRight:
this.Alignment = PdfContentByte.ALIGN_RIGHT; retVal = PdfContentByte.ALIGN_RIGHT;
break; break;
//Bottom //Bottom
case ContentAlignment.BottomLeft: case ContentAlignment.BottomLeft:
this.Alignment = PdfContentByte.ALIGN_LEFT; retVal = PdfContentByte.ALIGN_LEFT;
break; break;
case ContentAlignment.BottomCenter: case ContentAlignment.BottomCenter:
this.Alignment = PdfContentByte.ALIGN_CENTER; retVal = PdfContentByte.ALIGN_CENTER;
break; break;
case ContentAlignment.BottomRight: case ContentAlignment.BottomRight:
this.Alignment = PdfContentByte.ALIGN_RIGHT; retVal = PdfContentByte.ALIGN_RIGHT;
break; break;
} }
return retVal;
} }
public float Leading {get;private set;}
public int Alignment {get;private set;}
} }
} }

Loading…
Cancel
Save