Skip to content

Commit 1162e4b

Browse files
ars18wrwitext-teamcity
authored andcommitted
Support different border-radiuses. Some changes in border's abstraction concept.
DEVSIX-1569 Autoported commit. Original commit hash: [1dae07f83]
1 parent 750d38f commit 1162e4b

File tree

20 files changed

+783
-300
lines changed

20 files changed

+783
-300
lines changed

itext.tests/itext.layout.tests/itext/layout/BlockTest.cs

Lines changed: 56 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ public virtual void BorderRadiusTest01() {
639639
Document doc = new Document(pdfDocument);
640640
Div div = new Div();
641641
Style divStyle = new Style().SetHeight(500).SetWidth(500).SetBackgroundColor(ColorConstants.BLUE);
642-
divStyle.SetProperty(Property.BORDER_RADIUS, UnitValue.CreatePointValue(50));
642+
divStyle.SetBorderRadius(new BorderRadius(50));
643643
// solid
644644
div.AddStyle(divStyle);
645645
div.SetBorderTop(new SolidBorder(ColorConstants.RED, 20)).SetBorderRight(new SolidBorder(ColorConstants.YELLOW
@@ -681,20 +681,20 @@ public virtual void BorderRadiusTest02() {
681681
Document doc = new Document(pdfDocument);
682682
// width and height > 2 * radius
683683
Div div = new Div();
684-
div.SetHeight(500).SetWidth(500).SetBackgroundColor(ColorConstants.GREEN).SetProperty(Property.BORDER_RADIUS
685-
, UnitValue.CreatePointValue(100));
684+
div.SetHeight(500).SetWidth(500).SetBackgroundColor(ColorConstants.GREEN).SetBorderRadius(new BorderRadius
685+
(100));
686686
doc.Add(div);
687687
doc.Add(new AreaBreak());
688688
// 2 * radius > width and height > radius
689689
div = new Div();
690-
div.SetHeight(150).SetWidth(150).SetBackgroundColor(ColorConstants.GREEN).SetProperty(Property.BORDER_RADIUS
691-
, UnitValue.CreatePointValue(100));
690+
div.SetHeight(150).SetWidth(150).SetBackgroundColor(ColorConstants.GREEN).SetBorderRadius(new BorderRadius
691+
(100));
692692
doc.Add(div);
693693
doc.Add(new AreaBreak());
694694
// radius > width and height
695695
div = new Div();
696-
div.SetHeight(50).SetWidth(50).SetBackgroundColor(ColorConstants.GREEN).SetProperty(Property.BORDER_RADIUS
697-
, UnitValue.CreatePointValue(100));
696+
div.SetHeight(50).SetWidth(50).SetBackgroundColor(ColorConstants.GREEN).SetBorderRadius(new BorderRadius(100
697+
));
698698
doc.Add(div);
699699
doc.Close();
700700
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
@@ -711,7 +711,7 @@ public virtual void BorderRadiusTest03() {
711711
Document doc = new Document(pdfDocument);
712712
Div div = new Div();
713713
Style divStyle = new Style().SetHeight(500).SetWidth(500).SetBackgroundColor(ColorConstants.GREEN);
714-
divStyle.SetProperty(Property.BORDER_RADIUS, UnitValue.CreatePointValue(200));
714+
divStyle.SetBorderRadius(new BorderRadius(200));
715715
// solid
716716
div.AddStyle(divStyle);
717717
div.SetBorderLeft(new SolidBorder(ColorConstants.MAGENTA, 100)).SetBorderBottom(new SolidBorder(ColorConstants
@@ -757,7 +757,7 @@ public virtual void BorderRadiusTest04() {
757757
Document doc = new Document(pdfDocument);
758758
Div div = new Div();
759759
Style divStyle = new Style().SetHeight(120).SetWidth(120).SetBackgroundColor(ColorConstants.MAGENTA);
760-
divStyle.SetProperty(Property.BORDER_RADIUS, UnitValue.CreatePointValue(90));
760+
divStyle.SetBorderRadius(new BorderRadius(90));
761761
// solid
762762
div.AddStyle(divStyle);
763763
div.SetBorderBottom(new SolidBorder(ColorConstants.RED, 30)).SetBorderLeft(new SolidBorder(ColorConstants.
@@ -803,7 +803,53 @@ public virtual void BorderRadiusTest05() {
803803
Document doc = new Document(pdfDocument);
804804
Div div = new Div();
805805
Style divStyle = new Style().SetHeight(460).SetWidth(360).SetBackgroundColor(ColorConstants.MAGENTA);
806-
divStyle.SetProperty(Property.BORDER_RADIUS, UnitValue.CreatePointValue(100));
806+
divStyle.SetBorderRadius(new BorderRadius(100));
807+
// solid
808+
div.AddStyle(divStyle);
809+
div.SetBorderBottom(new SolidBorder(ColorConstants.RED, 30)).SetBorderLeft(new SolidBorder(ColorConstants.
810+
BLUE, 15)).SetBorderTop(new SolidBorder(ColorConstants.GREEN, 60)).SetBorderRight(new SolidBorder(ColorConstants
811+
.YELLOW, 150));
812+
doc.Add(div);
813+
doc.Add(new AreaBreak());
814+
// dashed
815+
div = new Div();
816+
div.AddStyle(divStyle);
817+
div.SetBorderBottom(new DashedBorder(ColorConstants.RED, 30)).SetBorderLeft(new DashedBorder(ColorConstants
818+
.BLUE, 15)).SetBorderTop(new DashedBorder(ColorConstants.GREEN, 60)).SetBorderRight(new DashedBorder(ColorConstants
819+
.YELLOW, 150));
820+
doc.Add(div);
821+
doc.Add(new AreaBreak());
822+
// dotted
823+
div = new Div();
824+
div.AddStyle(divStyle);
825+
div.SetBorderBottom(new DottedBorder(ColorConstants.RED, 30)).SetBorderLeft(new DottedBorder(ColorConstants
826+
.BLUE, 15)).SetBorderTop(new DottedBorder(ColorConstants.GREEN, 60)).SetBorderRight(new DottedBorder(ColorConstants
827+
.YELLOW, 150));
828+
doc.Add(div);
829+
doc.Add(new AreaBreak());
830+
// round dotted
831+
div = new Div();
832+
div.AddStyle(divStyle);
833+
div.SetBorderBottom(new RoundDotsBorder(ColorConstants.RED, 30)).SetBorderLeft(new RoundDotsBorder(ColorConstants
834+
.BLUE, 15)).SetBorderTop(new RoundDotsBorder(ColorConstants.GREEN, 60)).SetBorderRight(new RoundDotsBorder
835+
(ColorConstants.YELLOW, 150));
836+
doc.Add(div);
837+
doc.Close();
838+
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
839+
, "diff"));
840+
}
841+
842+
/// <exception cref="System.IO.IOException"/>
843+
/// <exception cref="System.Exception"/>
844+
[NUnit.Framework.Test]
845+
public virtual void BorderRadiusTest06() {
846+
String outFileName = destinationFolder + "borderRadiusTest06.pdf";
847+
String cmpFileName = sourceFolder + "cmp_borderRadiusTest06.pdf";
848+
PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outFileName));
849+
Document doc = new Document(pdfDocument);
850+
Div div = new Div();
851+
Style divStyle = new Style().SetHeight(460).SetWidth(360).SetBackgroundColor(ColorConstants.MAGENTA);
852+
divStyle.SetBorderRadius(new BorderRadius(40, 120));
807853
// solid
808854
div.AddStyle(divStyle);
809855
div.SetBorderBottom(new SolidBorder(ColorConstants.RED, 30)).SetBorderLeft(new SolidBorder(ColorConstants.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

itext/itext.io/itext/io/LogMessageConstant.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ public sealed class LogMessageConstant {
160160

161161
public const String MAPPING_IN_STRUCT_ROOT_OVERWRITTEN = "Existing mapping for {0} in structure tree root role map was {1} and it was overwritten with {2}.";
162162

163+
public const String METHOD_IS_NOT_IMPLEMENTED_BY_DEFAULT_OTHER_METHOD_WILL_BE_USED = "Method {0} is not implemented by default: please, override and implement it. {1} will be used instead.";
164+
163165
public const String NAME_ALREADY_EXISTS_IN_THE_NAME_TREE = "Name \"{0}\" already exists in the name tree; old value will be replaced by the new one.";
164166

165167
public const String NOT_TAGGED_PAGES_IN_TAGGED_DOCUMENT = "Not tagged pages are copied to the tagged document. Destination document now may contain not tagged content.";

itext/itext.layout/itext/layout/ElementPropertyContainer.cs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,61 @@ public virtual T SetBorderLeft(Border border) {
457457
return (T)(Object)this;
458458
}
459459

460+
/// <summary>Sets a border radius for all four edges of this Element.</summary>
461+
/// <param name="borderRadius">
462+
/// a customized
463+
/// <see cref="iText.Layout.Properties.BorderRadius"/>
464+
/// </param>
465+
/// <returns>this Element.</returns>
466+
public virtual T SetBorderRadius(BorderRadius borderRadius) {
467+
SetProperty(Property.BORDER_RADIUS, borderRadius);
468+
return (T)(Object)this;
469+
}
470+
471+
/// <summary>Sets a border radius for the bottom left corner of this Element.</summary>
472+
/// <param name="borderRadius">
473+
/// a customized
474+
/// <see cref="iText.Layout.Properties.BorderRadius"/>
475+
/// </param>
476+
/// <returns>this Element.</returns>
477+
public virtual T SetBorderBottomLeftRadius(BorderRadius borderRadius) {
478+
SetProperty(Property.BORDER_BOTTOM_LEFT_RADIUS, borderRadius);
479+
return (T)(Object)this;
480+
}
481+
482+
/// <summary>Sets a border radius for the bottom right corner of this Element.</summary>
483+
/// <param name="borderRadius">
484+
/// a customized
485+
/// <see cref="iText.Layout.Properties.BorderRadius"/>
486+
/// </param>
487+
/// <returns>this Element.</returns>
488+
public virtual T SetBorderBottomRightRadius(BorderRadius borderRadius) {
489+
SetProperty(Property.BORDER_BOTTOM_RIGHT_RADIUS, borderRadius);
490+
return (T)(Object)this;
491+
}
492+
493+
/// <summary>Sets a border radius for the top left corner of this Element.</summary>
494+
/// <param name="borderRadius">
495+
/// a customized
496+
/// <see cref="iText.Layout.Properties.BorderRadius"/>
497+
/// </param>
498+
/// <returns>this Element.</returns>
499+
public virtual T SetBorderTopLeftRadius(BorderRadius borderRadius) {
500+
SetProperty(Property.BORDER_TOP_LEFT_RADIUS, borderRadius);
501+
return (T)(Object)this;
502+
}
503+
504+
/// <summary>Sets a border radius for the top right corner of this Element.</summary>
505+
/// <param name="borderRadius">
506+
/// a customized
507+
/// <see cref="iText.Layout.Properties.BorderRadius"/>
508+
/// </param>
509+
/// <returns>this Element.</returns>
510+
public virtual T SetBorderTopRightRadius(BorderRadius borderRadius) {
511+
SetProperty(Property.BORDER_TOP_RIGHT_RADIUS, borderRadius);
512+
return (T)(Object)this;
513+
}
514+
460515
/// <summary>Sets a rule for splitting strings when they don't fit into one line.</summary>
461516
/// <remarks>
462517
/// Sets a rule for splitting strings when they don't fit into one line.

itext/itext.layout/itext/layout/borders/Border.cs

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ source product.
4242
4343
*/
4444
using System;
45+
using Common.Logging;
46+
using iText.IO.Util;
4547
using iText.Kernel.Colors;
4648
using iText.Kernel.Geom;
4749
using iText.Kernel.Pdf.Canvas;
@@ -204,22 +206,80 @@ public abstract void Draw(PdfCanvas canvas, float x1, float y1, float x2, float
204206
/// <code>borderWidthAfter</code> - width of the left border. Those width are used to handle areas
205207
/// of border joins.
206208
/// </p>
209+
/// <p>
210+
/// <code>borderRadius</code> is used to draw rounded borders.
211+
/// </p>
207212
/// </remarks>
208213
/// <param name="canvas">PdfCanvas to be written to</param>
209214
/// <param name="x1">x coordinate of the beginning point of the element side, that should be bordered</param>
210215
/// <param name="y1">y coordinate of the beginning point of the element side, that should be bordered</param>
211216
/// <param name="x2">x coordinate of the ending point of the element side, that should be bordered</param>
212217
/// <param name="y2">y coordinate of the ending point of the element side, that should be bordered</param>
213-
/// <param name="borderRadius">border radius</param>
218+
/// <param name="borderRadius">defines the radius of the element's corners</param>
214219
/// <param name="defaultSide">
215220
/// the
216221
/// <see cref="Side"/>
217222
/// , that we will fallback to, if it cannot be determined by border coordinates
218223
/// </param>
219224
/// <param name="borderWidthBefore">defines width of the border that is before the current one</param>
220225
/// <param name="borderWidthAfter">defines width of the border that is after the current one</param>
221-
public abstract void Draw(PdfCanvas canvas, float x1, float y1, float x2, float y2, float borderRadius, Border.Side
222-
defaultSide, float borderWidthBefore, float borderWidthAfter);
226+
public virtual void Draw(PdfCanvas canvas, float x1, float y1, float x2, float y2, float borderRadius, Border.Side
227+
defaultSide, float borderWidthBefore, float borderWidthAfter) {
228+
Draw(canvas, x1, y1, x2, y2, borderRadius, borderRadius, borderRadius, borderRadius, defaultSide, borderWidthBefore
229+
, borderWidthAfter);
230+
}
231+
232+
/// <summary>
233+
/// <p>
234+
/// All borders are supposed to be drawn in such way, that inner content of the element is on the right from the
235+
/// drawing direction.
236+
/// </summary>
237+
/// <remarks>
238+
/// <p>
239+
/// All borders are supposed to be drawn in such way, that inner content of the element is on the right from the
240+
/// drawing direction. Borders are drawn in this order: top, right, bottom, left.
241+
/// </p>
242+
/// <p>
243+
/// Given points specify the line which lies on the border of the content area,
244+
/// therefore the border itself should be drawn to the left from the drawing direction.
245+
/// </p>
246+
/// <p>
247+
/// <code>borderWidthBefore</code> and <code>borderWidthAfter</code> parameters are used to
248+
/// define the widths of the borders that are before and after the current border, e.g. for
249+
/// the bottom border, <code>borderWidthBefore</code> specifies width of the right border and
250+
/// <code>borderWidthAfter</code> - width of the left border. Those width are used to handle areas
251+
/// of border joins.
252+
/// </p>
253+
/// <p>
254+
/// <code>horizontalRadius1</code>, <code>verticalRadius1</code>, <code>horizontalRadius2</code>
255+
/// and <code>verticalRadius2</code> are used to draw rounded borders.
256+
/// </p>
257+
/// </remarks>
258+
/// <param name="canvas">PdfCanvas to be written to</param>
259+
/// <param name="x1">x coordinate of the beginning point of the element side, that should be bordered</param>
260+
/// <param name="y1">y coordinate of the beginning point of the element side, that should be bordered</param>
261+
/// <param name="x2">x coordinate of the ending point of the element side, that should be bordered</param>
262+
/// <param name="y2">y coordinate of the ending point of the element side, that should be bordered</param>
263+
/// <param name="horizontalRadius1">defines the horizontal radius of the border's first corner</param>
264+
/// <param name="verticalRadius1">defines the vertical radius of the border's first corner</param>
265+
/// <param name="horizontalRadius2">defines the horizontal radius of the border's second corner</param>
266+
/// <param name="verticalRadius2">defines the vertical radius of the border's second corner</param>
267+
/// <param name="defaultSide">
268+
/// the
269+
/// <see cref="Side"/>
270+
/// , that we will fallback to, if it cannot be determined by border coordinates
271+
/// </param>
272+
/// <param name="borderWidthBefore">defines width of the border that is before the current one</param>
273+
/// <param name="borderWidthAfter">defines width of the border that is after the current one</param>
274+
public virtual void Draw(PdfCanvas canvas, float x1, float y1, float x2, float y2, float horizontalRadius1
275+
, float verticalRadius1, float horizontalRadius2, float verticalRadius2, Border.Side defaultSide, float
276+
borderWidthBefore, float borderWidthAfter) {
277+
ILog logger = LogManager.GetLogger(typeof(iText.Layout.Borders.Border));
278+
logger.Warn(MessageFormatUtil.Format(iText.IO.LogMessageConstant.METHOD_IS_NOT_IMPLEMENTED_BY_DEFAULT_OTHER_METHOD_WILL_BE_USED
279+
, "Border#draw(PdfCanvas, float, float, float, float, float, float, float, float, Side, float, float",
280+
"Border#draw(PdfCanvas, float, float, float, float, Side, float, float)"));
281+
Draw(canvas, x1, y1, x2, y2, defaultSide, borderWidthBefore, borderWidthAfter);
282+
}
223283

224284
/// <summary>Draws the border of a cell.</summary>
225285
/// <param name="canvas">PdfCanvas to be written to</param>

0 commit comments

Comments
 (0)