Skip to content

Commit fd7be0d

Browse files
authored
Merge pull request #645 from FastReports/sync_branch_2023.3.13
FastReport.OpenSource 2023.3.13
2 parents 7c1a078 + c53dde1 commit fd7be0d

File tree

11 files changed

+331
-46
lines changed

11 files changed

+331
-46
lines changed

FastReport.Base/Base.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ namespace FastReport
1818
/// Specifies a set of actions that cannot be performed on the object in the design mode.
1919
/// </summary>
2020
[Flags]
21+
[TypeConverter(typeof(FastReport.TypeConverters.FlagConverter))]
2122
public enum Restrictions
2223
{
2324
/// <summary>
@@ -60,6 +61,7 @@ public enum Restrictions
6061
/// Specifies a set of actions that can be performed on the object in the design mode.
6162
/// </summary>
6263
[Flags]
64+
[TypeConverter(typeof(FastReport.TypeConverters.FlagConverter))]
6365
public enum Flags
6466
{
6567
/// <summary>

FastReport.Base/Gauge/Radial/RadialGauge.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public enum RadialGaugeType
3535
/// Radial Gauge position types
3636
/// </summary>
3737
[Flags]
38+
[TypeConverter(typeof(FastReport.TypeConverters.FlagConverter))]
3839
public enum RadialGaugePosition
3940
{
4041
/// <summary>

FastReport.Base/PictureObject.cs

Lines changed: 88 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ public int GrayscaleHash
142142
set { grayscaleHash = value; }
143143
}
144144

145-
146145
/// <summary>
147146
/// Gets or sets the color of the image that will be treated as transparent.
148147
/// </summary>
@@ -180,8 +179,6 @@ public float Transparency
180179
}
181180
}
182181

183-
184-
185182
/// <summary>
186183
/// Gets or sets a value indicating that the image should be tiled.
187184
/// </summary>
@@ -193,8 +190,6 @@ public bool Tile
193190
set { tile = value; }
194191
}
195192

196-
197-
198193
/// <summary>
199194
/// Gets or sets a value indicating that the image stored in the <see cref="Image"/>
200195
/// property should be disposed when this object is disposed.
@@ -211,15 +206,6 @@ public bool ShouldDisposeImage
211206
set { shouldDisposeImage = value; }
212207
}
213208

214-
215-
216-
217-
218-
219-
220-
221-
222-
223209
/// <summary>
224210
/// Gets or sets a bitmap transparent image
225211
/// </summary>
@@ -314,6 +300,38 @@ private void UpdateTransparentImage()
314300
}
315301
}
316302
}
303+
304+
#if MONO
305+
private GraphicsPath GetRoundRectPath(RectangleF rectangleF, float radius)
306+
{
307+
GraphicsPath gp = new GraphicsPath();
308+
if (radius < 1)
309+
radius = 1;
310+
gp.AddLine(rectangleF.X + radius, rectangleF.Y, rectangleF.Width + rectangleF.X - radius, rectangleF.Y);
311+
gp.AddArc(rectangleF.Width + rectangleF.X - radius - 1, rectangleF.Y, radius + 1, radius + 1, 270, 90);
312+
gp.AddLine(rectangleF.Width + rectangleF.X, rectangleF.Y + radius, rectangleF.Width + rectangleF.X, rectangleF.Height + rectangleF.Y - radius);
313+
gp.AddArc(rectangleF.Width + rectangleF.X - radius - 1, rectangleF.Height + rectangleF.Y - radius - 1, radius + 1, radius + 1, 0, 90);
314+
gp.AddLine(rectangleF.Width + rectangleF.X - radius, rectangleF.Height + rectangleF.Y, rectangleF.X + radius, rectangleF.Height + rectangleF.Y);
315+
gp.AddArc(rectangleF.X, rectangleF.Height + rectangleF.Y - radius - 1, radius + 1, radius + 1, 90, 90);
316+
gp.AddLine(rectangleF.X, rectangleF.Height + rectangleF.Y - radius, rectangleF.X, rectangleF.Y + radius);
317+
gp.AddArc(rectangleF.X, rectangleF.Y, radius, radius, 180, 90);
318+
gp.CloseFigure();
319+
return gp;
320+
}
321+
#else
322+
private GraphicsPath GetRoundRectPath(RectangleF rectangleF, float radius)
323+
{
324+
GraphicsPath gp = new GraphicsPath();
325+
if (radius < 1)
326+
radius = 1;
327+
gp.AddArc(rectangleF.Width + rectangleF.X - radius - 1, rectangleF.Y, radius + 1, radius + 1, 270, 90);
328+
gp.AddArc(rectangleF.Width + rectangleF.X - radius - 1, rectangleF.Height + rectangleF.Y - radius - 1, radius + 1, radius + 1, 0, 90);
329+
gp.AddArc(rectangleF.X, rectangleF.Height + rectangleF.Y - radius - 1, radius + 1, radius + 1, 90, 90);
330+
gp.AddArc(rectangleF.X, rectangleF.Y, radius, radius, 180, 90);
331+
gp.CloseFigure();
332+
return gp;
333+
}
334+
#endif
317335
#endregion
318336

319337
#region Protected Methods
@@ -373,12 +391,16 @@ public override void DrawImage(FRPaintEventArgs e)
373391
drawWidth,
374392
drawHeight);
375393

394+
GraphicsPath path = new GraphicsPath();
376395
IGraphicsState state = g.Save();
377396
try
378397
{
379398
//if (Config.IsRunningOnMono) // strange behavior of mono - we need to reset clip before we set new one
380-
g.ResetClip();
381-
g.SetClip(drawRect);
399+
g.ResetClip();
400+
401+
EstablishImageForm(path, drawLeft, drawTop, drawWidth, drawHeight);
402+
403+
g.SetClip(path, CombineMode.Replace);
382404
Report report = Report;
383405
if (report != null && report.SmoothGraphics)
384406
{
@@ -411,6 +433,8 @@ public override void DrawImage(FRPaintEventArgs e)
411433
finally
412434
{
413435
g.Restore(state);
436+
g.ResetClip();
437+
path.Dispose();
414438
}
415439

416440
if (IsPrinting)
@@ -552,17 +576,6 @@ public override void Deserialize(FRReader reader)
552576
}
553577
}
554578

555-
556-
557-
558-
559-
560-
//static int number = 0;
561-
562-
563-
564-
565-
566579
/// <summary>
567580
/// Loads image
568581
/// </summary>
@@ -602,9 +615,56 @@ protected override void ResetImageIndex()
602615
{
603616
imageIndex = -1;
604617
}
618+
619+
/// <summary>
620+
/// The shape of the image is set using GraphicsPath
621+
/// </summary>
622+
/// <param name="path"></param>
623+
/// <param name="drawLeft"></param>
624+
/// <param name="drawTop"></param>
625+
/// <param name="drawWidth"></param>
626+
/// <param name="drawHeight"></param>
627+
public void EstablishImageForm(GraphicsPath path, float drawLeft, float drawTop, float drawWidth, float drawHeight)
628+
{
629+
RectangleF drawRect = new RectangleF(
630+
drawLeft,
631+
drawTop,
632+
drawWidth,
633+
drawHeight);
634+
635+
switch (Shape)
636+
{
637+
case ShapeKind.Rectangle:
638+
path.AddRectangle(drawRect);
639+
break;
640+
case ShapeKind.RoundRectangle:
641+
float min = Math.Min(drawWidth, drawHeight) / 4;
642+
path.AddPath(GetRoundRectPath(drawRect, min), false);
643+
break;
644+
case ShapeKind.Ellipse:
645+
path.AddEllipse(drawLeft, drawTop, drawWidth, drawHeight);
646+
break;
647+
case ShapeKind.Triangle:
648+
PointF[] triPoints =
649+
{
650+
new PointF(drawLeft + drawWidth, drawTop + drawHeight), new PointF(drawLeft, drawTop + drawHeight),
651+
new PointF(drawLeft + drawWidth / 2, drawTop), new PointF(drawLeft + drawWidth, drawTop + drawHeight)
652+
};
653+
path.AddPolygon(triPoints);
654+
break;
655+
case ShapeKind.Diamond:
656+
PointF[] diaPoints =
657+
{
658+
new PointF(drawLeft + drawWidth / 2, drawTop), new PointF(drawLeft + drawWidth, drawTop + drawHeight / 2),
659+
new PointF(drawLeft + drawWidth / 2, drawTop + drawHeight), new PointF(drawLeft, drawTop + drawHeight / 2)
660+
};
661+
path.AddPolygon(diaPoints);
662+
break;
663+
}
664+
}
605665
#endregion
606666

607-
#region Report Engine
667+
#region Report Engine
608668

609669

610670
/// <inheritdoc/>

FastReport.Base/PictureObjectBase.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ public abstract partial class PictureObjectBase : ReportComponentBase
9292
private bool showErrorImage;
9393
private PictureBoxSizeMode sizeModeInternal;
9494
private ImageAlign imageAlign;
95+
private ShapeKind shape;
9596

9697
#endregion Private Fields
9798

@@ -333,6 +334,17 @@ public ImageAlign ImageAlign
333334
set { imageAlign = value; }
334335
}
335336

337+
/// <summary>
338+
/// Gets or sets a shape kind.
339+
/// </summary>
340+
[DefaultValue(ShapeKind.Rectangle)]
341+
[Category("Appearance")]
342+
public ShapeKind Shape
343+
{
344+
get { return shape; }
345+
set { shape = value; }
346+
}
347+
336348

337349
#endregion Public Properties
338350

@@ -358,6 +370,7 @@ public ImageAlign ImageAlign
358370
public PictureObjectBase()
359371
{
360372
sizeModeInternal = PictureBoxSizeMode.Zoom;
373+
shape = ShapeKind.Rectangle;
361374
padding = new Padding();
362375
imageLocation = "";
363376
dataColumn = "";
@@ -387,6 +400,7 @@ public override void Assign(Base source)
387400
Grayscale = src.Grayscale;
388401
ShowErrorImage = src.ShowErrorImage;
389402
ImageAlign = src.ImageAlign;
403+
Shape = src.Shape;
390404
}
391405
}
392406

@@ -668,8 +682,6 @@ private void UpdateAlign(RectangleF drawRect, ref PointF upperLeft, ref PointF u
668682
lowerLeft.Y += offsetY;
669683
}
670684

671-
672-
673685
/// <summary>
674686
/// Loads image
675687
/// </summary>
@@ -776,6 +788,8 @@ public override void Serialize(FRWriter writer)
776788
writer.WriteBool("ShowErrorImage", ShowErrorImage);
777789
if (ImageAlign != ImageAlign.None)
778790
writer.WriteValue("ImageAlign", ImageAlign);
791+
if (Shape != c.Shape)
792+
writer.WriteValue("Shape", Shape);
779793
}
780794

781795
#endregion Public Methods

0 commit comments

Comments
 (0)