Browse Source

Enhance PdfRectangle created by DisplayRectangle, small cleanups

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/reports@6129 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
pull/1/head
Peter Forstmeier 16 years ago
parent
commit
57e8de7087
  1. 25
      src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/Project/old_Exporter/ExportColumns/BaseExportColumn.cs
  2. 81
      src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/Project/old_Exporter/ExportColumns/ExportImage.cs
  3. 70
      src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/Project/old_Exporter/ExportColumns/ExportText.cs

25
src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/Project/old_Exporter/ExportColumns/BaseExportColumn.cs

@ -84,10 +84,10 @@ namespace ICSharpCode.Reports.Core.old_Exporter @@ -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 @@ -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 @@ -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);
}
}

81
src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/Project/old_Exporter/ExportColumns/ExportImage.cs

@ -17,9 +17,10 @@ namespace ICSharpCode.Reports.Core.old_Exporter @@ -17,9 +17,10 @@ namespace ICSharpCode.Reports.Core.old_Exporter
/// </summary>
public class ExportImage:BaseExportColumn
{
string fileName;
System.Drawing.Image image;
bool scaleImageToSize;
#region Constructor
@ -28,13 +29,11 @@ namespace ICSharpCode.Reports.Core.old_Exporter @@ -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 @@ -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 @@ -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 @@ -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; }
}
}
}

70
src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/Project/old_Exporter/ExportColumns/ExportText.cs

@ -64,22 +64,20 @@ namespace ICSharpCode.Reports.Core.old_Exporter { @@ -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 { @@ -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 { @@ -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 { @@ -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;}
}
}

Loading…
Cancel
Save