Browse Source

Rectangle with rounded corners.

pull/14/head
peterforstmeier 15 years ago
parent
commit
df7f687ebd
  1. 9
      src/AddIns/Misc/Reports/ICSharpCode.Reports.Addin/Project/ReportItems/BaseCircleItem.cs
  2. 65
      src/AddIns/Misc/Reports/ICSharpCode.Reports.Addin/Project/ReportItems/BaseRectangleItem.cs
  3. 8
      src/AddIns/Misc/Reports/ICSharpCode.Reports.Addin/Project/ReportItems/RectangleItemTypeProvider.cs
  4. 1
      src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/ICSharpCode.Reports.Core.csproj
  5. 52
      src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/Project/BaseItems/BaseGraphicItem.cs
  6. 20
      src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/Project/BaseItems/Graphics/BaseLineItem.cs
  7. 26
      src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/Project/BaseItems/Graphics/BaseRectangleItem.cs
  8. 35
      src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/Project/Exporter/Decorators/RectangleDecorator.cs
  9. 1
      src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/Project/Exporter/ExportColumns/BaseExportColumn.cs
  10. 14
      src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/Project/Exporter/ExportColumns/ExportGraphic.cs
  11. 1
      src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/Project/Printing/Graphics/BaseLine.cs
  12. 3
      src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/Project/Printing/Graphics/BaseShape.cs
  13. 65
      src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/Project/Printing/Graphics/RectangleShape.cs

9
src/AddIns/Misc/Reports/ICSharpCode.Reports.Addin/Project/ReportItems/BaseCircleItem.cs

@ -62,15 +62,6 @@ namespace ICSharpCode.Reports.Addin
} }
private BaseLine Baseline()
{
if (this.BackColor == GlobalValues.DefaultBackColor) {
return new BaseLine (this.ForeColor,this.DashStyle,this.Thickness);
} else {
return new BaseLine (this.BackColor,this.DashStyle,this.Thickness);
}
}
[Browsable(true), [Browsable(true),
Category("Appearance"), Category("Appearance"),

65
src/AddIns/Misc/Reports/ICSharpCode.Reports.Addin/Project/ReportItems/BaseRectangleItem.cs

@ -22,13 +22,14 @@ namespace ICSharpCode.Reports.Addin
private DashStyle dashStyle; private DashStyle dashStyle;
private float thickness; private float thickness;
private int cornerRadius;
public BaseRectangleItem() public BaseRectangleItem()
{ {
this.thickness = 1; this.thickness = 1;
this.dashStyle = DashStyle.Solid; this.dashStyle = DashStyle.Solid;
this.Size = new Size(GlobalValues.PreferedSize.Width,2* GlobalValues.PreferedSize.Height); this.Size = new Size(GlobalValues.PreferedSize.Width,2* GlobalValues.PreferedSize.Height);
cornerRadius = 1;
TypeDescriptor.AddProvider(new RectangleItemTypeProvider(), typeof(BaseRectangleItem)); TypeDescriptor.AddProvider(new RectangleItemTypeProvider(), typeof(BaseRectangleItem));
} }
@ -49,54 +50,62 @@ namespace ICSharpCode.Reports.Addin
} }
Rectangle rect = new Rectangle(this.ClientRectangle.Left,this.ClientRectangle.Top, Rectangle rect = new Rectangle(this.ClientRectangle.Left,this.ClientRectangle.Top,
this.ClientRectangle.Right -1, this.ClientRectangle.Right -1,
this.ClientRectangle.Bottom -1); this.ClientRectangle.Bottom -1);
backgroundShape.FillShape(graphics, // backgroundShape.FillShape(graphics,
new SolidFillPattern(this.BackColor), // new SolidFillPattern(this.BackColor),
rect); // rect);
Border b = new Border(new BaseLine (this.ForeColor,System.Drawing.Drawing2D.DashStyle.Solid,1)); Border b = new Border(new BaseLine (this.ForeColor,System.Drawing.Drawing2D.DashStyle.Solid,1));
DrawFrame(graphics,b); // DrawFrame(graphics,b);
BaseLine line = new BaseLine(base.ForeColor,DashStyle,Thickness,LineCap.Round,LineCap.Round,DashCap.Round);
using (Pen pen = line.CreatePen(line.Thickness)){
shape.CornerRadius = this.CornerRadius;
GraphicsPath path1 = shape.CreatePath(rect);
graphics.DrawPath(pen, path1);
}
shape.DrawShape (graphics, // shape.DrawShape (graphics,
this.Baseline(), // this.Baseline(),
rect); // rect);
} }
protected void DrawFrame (Graphics graphics,Border border) {
if (this.DrawBorder == true) {
border.DrawBorder(graphics,this.ClientRectangle);
}
}
private BaseLine Baseline()
{
if (this.BackColor == GlobalValues.DefaultBackColor) {
return new BaseLine (this.ForeColor,this.DashStyle,this.Thickness);
} else {
return new BaseLine (this.BackColor,this.DashStyle,this.Thickness);
}
}
[Browsable(true), [Browsable(true),
Category("Appearance"), Category("Appearance"),
Description("Linestyle")] Description("Linestyle")]
public DashStyle DashStyle { public DashStyle DashStyle {
get { return dashStyle; } get { return dashStyle; }
set { dashStyle = value; } set { dashStyle = value;
this.Invalidate();
}
} }
[Browsable(true), [Browsable(true),
Category("Appearance"), Category("Appearance"),
Description("Thickness of Line")] Description("Thickness of Line")]
public float Thickness { public float Thickness {
get { return thickness; } get { return thickness; }
set { thickness = value; } set { thickness = value;
this.Invalidate();
}
} }
[Browsable(true),
Category("Appearance"),
Description("Radius of Corners")]
public int CornerRadius
{
get{return this.cornerRadius;}
set{this.cornerRadius = value;
this.Invalidate();
}
}
} }
} }

8
src/AddIns/Misc/Reports/ICSharpCode.Reports.Addin/Project/ReportItems/RectangleItemTypeProvider.cs

@ -57,15 +57,17 @@ namespace ICSharpCode.Reports.Addin
prop = props.Find("ForeColor",true); prop = props.Find("ForeColor",true);
allProperties.Add(prop); allProperties.Add(prop);
prop = props.Find("DrawBorder",true); // prop = props.Find("DrawBorder",true);
allProperties.Add(prop); // allProperties.Add(prop);
//
prop = props.Find("DashStyle",true); prop = props.Find("DashStyle",true);
allProperties.Add(prop); allProperties.Add(prop);
prop = props.Find("Thickness",true); prop = props.Find("Thickness",true);
allProperties.Add(prop); allProperties.Add(prop);
prop = props.Find("CornerRadius",true);
allProperties.Add(prop);
return new PropertyDescriptorCollection(allProperties.ToArray()); return new PropertyDescriptorCollection(allProperties.ToArray());
} }
} }

1
src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/ICSharpCode.Reports.Core.csproj

@ -137,6 +137,7 @@
<Compile Include="Project\Exceptions\WrongColumnException.cs" /> <Compile Include="Project\Exceptions\WrongColumnException.cs" />
<Compile Include="Project\Exceptions\WrongSectionException.cs" /> <Compile Include="Project\Exceptions\WrongSectionException.cs" />
<Compile Include="Project\Exporter\Converters\GroupedTableConverter.cs" /> <Compile Include="Project\Exporter\Converters\GroupedTableConverter.cs" />
<Compile Include="Project\Exporter\Decorators\RectangleDecorator.cs" />
<Compile Include="Project\Expressions\SimpleExpressionEvaluator\Compilation\Functions\ReportingService\FieldReference.cs" /> <Compile Include="Project\Expressions\SimpleExpressionEvaluator\Compilation\Functions\ReportingService\FieldReference.cs" />
<Compile Include="Project\Exporter\BasePager.cs" /> <Compile Include="Project\Exporter\BasePager.cs" />
<Compile Include="Project\Exporter\Converters\BaseConverter.cs" /> <Compile Include="Project\Exporter\Converters\BaseConverter.cs" />

52
src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/Project/BaseItems/BaseGraphicItem.cs

@ -19,12 +19,13 @@ namespace ICSharpCode.Reports.Core {
/// </remarks> /// </remarks>
public class BaseGraphicItem : BaseReportItem { public class BaseGraphicItem : BaseReportItem {
private int thickness = 1; public BaseGraphicItem():base()
private DashStyle dashStyle = DashStyle.Solid; {
this.Thickness = 1;
public BaseGraphicItem():base() { DashStyle = DashStyle.Solid;
} }
protected IGraphicStyleDecorator CreateItemStyle (BaseShape shape) { protected IGraphicStyleDecorator CreateItemStyle (BaseShape shape) {
GraphicStyleDecorator style = new GraphicStyleDecorator(shape); GraphicStyleDecorator style = new GraphicStyleDecorator(shape);
@ -34,8 +35,8 @@ namespace ICSharpCode.Reports.Core {
style.ForeColor = this.ForeColor; style.ForeColor = this.ForeColor;
style.FrameColor = this.FrameColor; style.FrameColor = this.FrameColor;
style.Thickness = this.thickness; style.Thickness = this.Thickness;
style.DashStyle = this.dashStyle; style.DashStyle = this.DashStyle;
return style; return style;
} }
@ -54,7 +55,8 @@ namespace ICSharpCode.Reports.Core {
return new BaseLine (this.BackColor,this.DashStyle,this.Thickness); return new BaseLine (this.BackColor,this.DashStyle,this.Thickness);
} }
} }
#region Overrides #region Overrides
public override string ToString() public override string ToString()
@ -70,41 +72,9 @@ namespace ICSharpCode.Reports.Core {
/// Line Thickness of graphical Element /// Line Thickness of graphical Element
/// </summary> /// </summary>
public virtual int Thickness { public virtual int Thickness {get;set;}
get {
return thickness;
}
set {
thickness = value;
}
}
public virtual DashStyle DashStyle {
get {
return dashStyle;
}
set {
dashStyle = value;
}
}
[XmlIgnoreAttribute]
[Browsable(false)]
public override bool DrawBorder {
get { return base.DrawBorder; }
set { base.DrawBorder = value; }
}
[XmlIgnoreAttribute]
[Browsable(false)]
public override Font Font {
get { return base.Font; }
set { base.Font = value; }
}
public virtual DashStyle DashStyle {get;set;}
#endregion #endregion
} }

20
src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/Project/BaseItems/Graphics/BaseLineItem.cs

@ -46,17 +46,17 @@ namespace ICSharpCode.Reports.Core {
private LineDecorator CreateLineShape () private LineDecorator CreateLineShape ()
{ {
LineDecorator ld = new LineDecorator(this.shape); LineDecorator decorator = new LineDecorator(this.shape);
ld.Size = this.Size; decorator.Size = this.Size;
ld.Location = this.Location; decorator.Location = this.Location;
ld.BackColor = this.BackColor; decorator.BackColor = this.BackColor;
ld.ForeColor = this.ForeColor; decorator.ForeColor = this.ForeColor;
ld.Thickness = base.Thickness; decorator.Thickness = base.Thickness;
ld.DashStyle = base.DashStyle; decorator.DashStyle = base.DashStyle;
ld.From = this.fromPoint; decorator.From = this.fromPoint;
ld.To = this.toPoint; decorator.To = this.toPoint;
return ld; return decorator;
} }

26
src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/Project/BaseItems/Graphics/BaseRectangleItem.cs

@ -3,9 +3,12 @@
using System; using System;
using System.Drawing; using System.Drawing;
using System.Drawing.Drawing2D;
using ICSharpCode.Reports.Core.BaseClasses.Printing; using ICSharpCode.Reports.Core.BaseClasses.Printing;
using ICSharpCode.Reports.Core.Exporter; using ICSharpCode.Reports.Core.Exporter;
/// <summary> /// <summary>
/// This class draws a Rectangle /// This class draws a Rectangle
/// </summary> /// </summary>
@ -14,7 +17,9 @@ using ICSharpCode.Reports.Core.Exporter;
/// created on - 29.09.2005 11:57:30 /// created on - 29.09.2005 11:57:30
/// </remarks> /// </remarks>
namespace ICSharpCode.Reports.Core { namespace ICSharpCode.Reports.Core {
public class BaseRectangleItem : BaseGraphicItem,IExportColumnBuilder {
public class BaseRectangleItem : BaseGraphicItem,IExportColumnBuilder
{
RectangleShape shape = new RectangleShape(); RectangleShape shape = new RectangleShape();
@ -29,11 +34,13 @@ namespace ICSharpCode.Reports.Core {
#region IExportColumnBuilder #region IExportColumnBuilder
public BaseExportColumn CreateExportColumn(){ public BaseExportColumn CreateExportColumn(){
shape.CornerRadius = CornerRadius;
IGraphicStyleDecorator style = base.CreateItemStyle(this.shape); IGraphicStyleDecorator style = base.CreateItemStyle(this.shape);
ExportGraphic item = new ExportGraphic(style,false); ExportGraphic item = new ExportGraphic(style,false);
return item as ExportGraphic; return item as ExportGraphic;
} }
#endregion #endregion
public override void Render(ReportPageEventArgs rpea) { public override void Render(ReportPageEventArgs rpea) {
@ -42,14 +49,23 @@ namespace ICSharpCode.Reports.Core {
} }
base.Render(rpea); base.Render(rpea);
Rectangle rect = base.DisplayRectangle; Rectangle rect = base.DisplayRectangle;
StandardPrinter.FillBackground(rpea.PrintPageEventArgs.Graphics,this.BaseStyleDecorator); StandardPrinter.FillBackground(rpea.PrintPageEventArgs.Graphics,this.BaseStyleDecorator);
shape.DrawShape (rpea.PrintPageEventArgs.Graphics, BaseLine line = new BaseLine(base.ForeColor,base.DashStyle,base.Thickness,LineCap.Round,LineCap.Round,DashCap.Round);
base.Baseline(),
rect); using (Pen pen = line.CreatePen(line.Thickness)){
if (pen != null)
{
shape.CornerRadius = this.CornerRadius;
GraphicsPath path1 = shape.CreatePath(rect);
rpea.PrintPageEventArgs.Graphics.DrawPath(pen, path1);
}
}
} }
public int CornerRadius {get;set;}
public override string ToString() { public override string ToString() {
return "BaseRectangleItem"; return "BaseRectangleItem";
} }

35
src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/Project/Exporter/Decorators/RectangleDecorator.cs

@ -0,0 +1,35 @@
/*
* Created by SharpDevelop.
* User: Peter Forstmeier
* Date: 30.12.2010
* Time: 19:41
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using ICSharpCode.Reports.Core.Exporter;
namespace ICSharpCode.Reports.Core.Exporter
{
/// <summary>
/// Description of RectangleDecorator.
/// </summary>
public class aaRectangleDecorator: GraphicStyleDecorator
{
public aaRectangleDecorator(BaseShape shape):base(shape)
{
}
private int corner;
public int CornerRadius {
get {
return corner;
}
set { corner = value; }
}
}
}

1
src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/Project/Exporter/ExportColumns/BaseExportColumn.cs

@ -123,6 +123,7 @@ namespace ICSharpCode.Reports.Core.Exporter
iTextSharp.text.Rectangle r = (iTextSharp.text.Rectangle)rectangleConverter.ConvertTo(null,System.Globalization.CultureInfo.InvariantCulture, iTextSharp.text.Rectangle r = (iTextSharp.text.Rectangle)rectangleConverter.ConvertTo(null,System.Globalization.CultureInfo.InvariantCulture,
this.styleDecorator.DisplayRectangle, this.styleDecorator.DisplayRectangle,
typeof(iTextSharp.text.Rectangle)); typeof(iTextSharp.text.Rectangle));
iTextSharp.text.Rectangle rr = new iTextSharp.text.Rectangle(r.Left,r.Bottom -2, iTextSharp.text.Rectangle rr = new iTextSharp.text.Rectangle(r.Left,r.Bottom -2,
r.Left + r.Width,r.Bottom + r.Height); r.Left + r.Width,r.Bottom + r.Height);

14
src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/Project/Exporter/ExportColumns/ExportGraphic.cs

@ -105,14 +105,14 @@ namespace ICSharpCode.Reports.Core.Exporter
if (lineDecorator != null) { if (lineDecorator != null) {
PdfLineDrawer (); PdfLineDrawer ();
} }
else { else
{
// http://www.mikesdotnetting.com/Article/88/iTextSharp-Drawing-shapes-and-Graphics
IGraphicStyleDecorator style = base.StyleDecorator as GraphicStyleDecorator; IGraphicStyleDecorator style = base.StyleDecorator as GraphicStyleDecorator;
if (style != null) { style.Shape.DrawShape(base.PdfWriter.DirectContent,
style.Shape.DrawShape(base.PdfWriter.DirectContent, new BaseLine (style.ForeColor,style.DashStyle,style.Thickness),
new BaseLine (style.ForeColor,style.DashStyle,style.Thickness), style,
style, base.ConvertToPdfRectangle());
base.ConvertToPdfRectangle());
}
} }
} }

1
src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/Project/Printing/Graphics/BaseLine.cs

@ -33,6 +33,7 @@ namespace ICSharpCode.Reports.Core
{ {
} }
public BaseLine(Color color, DashStyle dashStyle,float thickness, LineCap startLineCap, LineCap endLineCap, DashCap dashLineCap) public BaseLine(Color color, DashStyle dashStyle,float thickness, LineCap startLineCap, LineCap endLineCap, DashCap dashLineCap)
{ {
if (color == Color.White) { if (color == Color.White) {

3
src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/Project/Printing/Graphics/BaseShape.cs

@ -86,7 +86,7 @@ namespace ICSharpCode.Reports.Core {
} }
public void DrawShape(Graphics graphics, BaseLine line, Rectangle rectangle) public virtual void DrawShape(Graphics graphics, BaseLine line, Rectangle rectangle)
{ {
if (graphics == null) { if (graphics == null) {
throw new ArgumentNullException("graphics"); throw new ArgumentNullException("graphics");
@ -114,6 +114,7 @@ namespace ICSharpCode.Reports.Core {
cb.SetColorFill(style.PdfBackColor); cb.SetColorFill(style.PdfBackColor);
} }
protected static void FillBackGround (iTextSharp.text.pdf.PdfContentByte contentByte, protected static void FillBackGround (iTextSharp.text.pdf.PdfContentByte contentByte,
IBaseStyleDecorator style, IBaseStyleDecorator style,
iTextSharp.text.Rectangle rectangle) iTextSharp.text.Rectangle rectangle)

65
src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/Project/Printing/Graphics/RectangleShape.cs

@ -15,9 +15,11 @@ using ICSharpCode.Reports.Core.Exporter;
/// created on - 09.10.2005 18:20:51 /// created on - 09.10.2005 18:20:51
/// </remarks> /// </remarks>
namespace ICSharpCode.Reports.Core { namespace ICSharpCode.Reports.Core {
public class RectangleShape : BaseShape { public class RectangleShape : BaseShape {
public RectangleShape() { public RectangleShape()
{
} }
@ -27,22 +29,46 @@ namespace ICSharpCode.Reports.Core {
} }
public override GraphicsPath CreatePath(Rectangle rectangle){ public override GraphicsPath CreatePath(Rectangle rectangle )
GraphicsPath path1 = new GraphicsPath(); {
path1.AddRectangle(rectangle); //http://stackoverflow.com/questions/628261/how-to-draw-rounded-rectangle-with-variable-width-border-inside-of-specific-bound
return path1; //http://www.switchonthecode.com/tutorials/csharp-creating-rounded-rectangles-using-a-graphics-path
//http://www.codeproject.com/KB/GDI-plus/ExtendedGraphics.aspx
GraphicsPath gfxPath = new GraphicsPath();
if (CornerRadius == 0)
{
gfxPath.AddRectangle(rectangle);
}
else
{
gfxPath.AddArc(rectangle.X, rectangle.Y,CornerRadius , CornerRadius, 180, 90);
gfxPath.AddArc(rectangle.X + rectangle.Width - CornerRadius, rectangle.Y, CornerRadius, CornerRadius, 270, 90);
gfxPath.AddArc(rectangle.X + rectangle.Width - CornerRadius, rectangle.Y + rectangle.Height - CornerRadius, CornerRadius, CornerRadius, 0, 90);
gfxPath.AddArc(rectangle.X, rectangle.Y + rectangle.Height - CornerRadius, CornerRadius, CornerRadius, 90, 90);
}
gfxPath.CloseAllFigures();
return gfxPath;
}
public override void DrawShape(Graphics graphics, BaseLine line, Rectangle rectangle)
{
base.DrawShape(graphics, line, rectangle);
} }
public override void CreatePath(iTextSharp.text.pdf.PdfContentByte contentByte, public override void CreatePath(iTextSharp.text.pdf.PdfContentByte contentByte,
BaseLine line, BaseLine line,
IBaseStyleDecorator style, IBaseStyleDecorator style,
Point from,Point to) Point from,Point to)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
// http://www.mikesdotnetting.com/Article/88/iTextSharp-Drawing-shapes-and-Graphics
public override void CreatePath(iTextSharp.text.pdf.PdfContentByte contentByte, public override void CreatePath(iTextSharp.text.pdf.PdfContentByte contentByte,
BaseLine line, BaseLine line,
@ -52,6 +78,9 @@ namespace ICSharpCode.Reports.Core {
if (contentByte == null) { if (contentByte == null) {
throw new ArgumentNullException("contentByte"); throw new ArgumentNullException("contentByte");
} }
if (line == null) {
throw new ArgumentNullException("line");
}
if (style == null) { if (style == null) {
throw new ArgumentNullException("style"); throw new ArgumentNullException("style");
} }
@ -59,21 +88,13 @@ namespace ICSharpCode.Reports.Core {
throw new ArgumentNullException("rectangle"); throw new ArgumentNullException("rectangle");
} }
if ((line == null)||(line.Thickness < 1)) { BaseShape.SetupShape(contentByte,style);
BaseShape.FillBackGround(contentByte,style,rectangle); contentByte.SetLineWidth(UnitConverter.FromPixel(line.Thickness).Point);
} contentByte.RoundRectangle(rectangle.Left, rectangle.Bottom, rectangle.Width, rectangle.Height, CornerRadius);
else if ((style.BackColor == GlobalValues.DefaultBackColor)) { BaseShape.FinishShape(contentByte);
BaseShape.SetupShape(contentByte,style);
contentByte.SetLineWidth(UnitConverter.FromPixel(line.Thickness).Point);
contentByte.MoveTo(rectangle.Left ,rectangle.Top );
contentByte.LineTo(rectangle.Left, rectangle.Top - rectangle.Height);
contentByte.LineTo(rectangle.Left + rectangle.Width, rectangle.Top - rectangle.Height);
contentByte.LineTo(rectangle.Left + rectangle.Width, rectangle.Top);
contentByte.LineTo(rectangle.Left, rectangle.Top);
BaseShape.FinishShape(contentByte);
} else {
BaseShape.FillBackGround(contentByte,style,rectangle);
}
} }
public int CornerRadius {get;set;}
} }
} }

Loading…
Cancel
Save