Skip to content

Commit

Permalink
SVG: support text-decoration attribute
Browse files Browse the repository at this point in the history
DEVSIX-2270

Autoported commit.
Original commit hash: [2cd532dff]
  • Loading branch information
AnhelinaM authored and iText-CI committed Jan 15, 2025
1 parent 03aae8b commit 06be501
Show file tree
Hide file tree
Showing 41 changed files with 449 additions and 50 deletions.
35 changes: 35 additions & 0 deletions itext.tests/itext.layout.tests/itext/layout/TextWritingTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,41 @@ public virtual void UnderlineTest() {
, "diff"));
}

[NUnit.Framework.Test]
public virtual void StrokedUnderlineTest() {
String outFileName = destinationFolder + "strokedUnderline.pdf";
String cmpFileName = sourceFolder + "cmp_strokedUnderline.pdf";
using (PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outFileName))) {
using (Document document = new Document(pdfDocument)) {
Paragraph p = new Paragraph("Yellow text with pink stroked underline.").SetFontSize(50).SetFontColor(ColorConstants
.YELLOW);
Underline underline = new Underline(null, 0, 0.1f, 0, -0.1f, PdfCanvasConstants.LineCapStyle.BUTT).SetStrokeWidth
(2).SetStrokeColor(new TransparentColor(ColorConstants.PINK, 0.5f));
p.SetUnderline(underline);
Paragraph p2 = new Paragraph("Text with line-through and default underline.").SetFontSize(50).SetStrokeWidth
(1).SetFontColor(ColorConstants.DARK_GRAY).SetStrokeColor(ColorConstants.GREEN);
Underline underline2 = new Underline(ColorConstants.DARK_GRAY, 0, 0.1f, 0, 0.3f, PdfCanvasConstants.LineCapStyle
.BUTT).SetStrokeWidth(1).SetStrokeColor(new TransparentColor(ColorConstants.GREEN));
p2.SetUnderline(underline2);
p2.SetUnderline();
Paragraph p3 = new Paragraph("Text with transparent font color and default overline.").SetFontSize(50).SetFontColor
(new TransparentColor(ColorConstants.BLUE, 0));
Underline underline3 = new Underline(null, 0, 0.1f, 0, 0.9f, PdfCanvasConstants.LineCapStyle.BUTT);
p3.SetUnderline(underline3);
p3.SetBackgroundColor(ColorConstants.PINK);
Paragraph p4 = new Paragraph("Text with null font color and default overline.").SetFontSize(50).SetFontColor
((TransparentColor)null);
p4.SetUnderline(underline3);
document.Add(p);
document.Add(p2);
document.Add(p3);
document.Add(p4);
}
}
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
, "diff"));
}

[NUnit.Framework.Test]
public virtual void LineThroughTest() {
//TODO: update after DEVSIX-2623 fix
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static void BeforeClass() {

[NUnit.Framework.Test]
public virtual void UnicodeRangeTest() {
// TODO fix cmp file after DEVSIX-2256 is finished. Right now unicode range is not processed correctly
// Unicode range is processed correctly: in case Droid Serif font doesn't include current glyph, Times font is used.
ConvertAndCompare(sourceFolder, destinationFolder, "unicodeRangeTest");
}

Expand Down Expand Up @@ -88,6 +88,11 @@ public virtual void FontSelectorTest01() {
ConvertAndCompare(sourceFolder, destinationFolder, "fontSelectorTest01");
}

[NUnit.Framework.Test]
public virtual void FontSelectorTest03() {
ConvertAndCompare(sourceFolder, destinationFolder, "fontSelectorTest03");
}

[NUnit.Framework.Test]
public virtual void FontSelectorMissingFontWithSize() {
ConvertAndCompare(sourceFolder, destinationFolder, "fontSelectorMissingWithFontSize");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,19 @@ public virtual void TspanCombinedAttributesTest() {
}

[NUnit.Framework.Test]
public virtual void Text_decoration_Test() {
//TODO: update cmp-file after DEVSIX-2270 fixed
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "text_decoration");
public virtual void TextDecorationSvgTest() {
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "textDecorationSvg");
}

[NUnit.Framework.Test]
public virtual void TextDecorationCssTest() {
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "textDecorationCss");
}

[NUnit.Framework.Test]
public virtual void TextDecorationStyleTest() {
// TODO update after DEVSIX-4063 is closed
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "textDecorationStyle");
}

[NUnit.Framework.Test]
Expand Down Expand Up @@ -294,13 +304,11 @@ public virtual void NestedPositioningTest() {
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "nestedPositioningTest");
}

//TODO DEVSIX-2507: Update cmp file after supporting
[NUnit.Framework.Test]
public virtual void TextDecorationTspanTest() {
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "textDecorationTspan");
}

//TODO DEVSIX-2507: Update cmp file after supporting
[NUnit.Framework.Test]
public virtual void TextDecorationTspanSubTest() {
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "textDecorationTspanSub");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,19 +283,16 @@ public virtual void TextComplexStrokeDasharrayTest() {

[NUnit.Framework.Test]
public virtual void TextTextDecorationUnderlineTest() {
//TODO: DEVSIX-2270, DEVSIX-4586 update cmp file after fix
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "textTextDecorationUnderline");
}

[NUnit.Framework.Test]
public virtual void TextTextDecorationLineThroughTest() {
//TODO: DEVSIX-2270, DEVSIX-4586 update cmp file after fix
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "textTextDecorationLineThrough");
}

[NUnit.Framework.Test]
public virtual void TextTextDecorationOverlineTest() {
//TODO: DEVSIX-2270, DEVSIX-4586 update cmp file after fix
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "textTextDecorationOverline");
}

Expand Down
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 26 additions & 9 deletions itext/itext.layout/itext/layout/ElementPropertyContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -763,9 +763,9 @@ public virtual T SetUnderline(Color color, float thickness, float thicknessMul,
return SetUnderline(color, 1f, thickness, thicknessMul, yPosition, yPositionMul, lineCapStyle);
}

/// <summary>Sets an horizontal line that can be an underline or a strikethrough.</summary>
/// <summary>Sets horizontal line that can be an underline or a strikethrough.</summary>
/// <remarks>
/// Sets an horizontal line that can be an underline or a strikethrough.
/// Sets horizontal line that can be an underline or a strikethrough.
/// Actually, the line can be anywhere vertically due to position parameter.
/// Multiple call to this method will produce multiple lines.
/// <para />
Expand All @@ -778,8 +778,10 @@ public virtual T SetUnderline(Color color, float thickness, float thicknessMul,
/// the color of the line or <c>null</c> to follow the
/// text color
/// </param>
/// <param name="opacity">the opacity of the line; a float between 0 and 1, where 1 stands for fully opaque color and 0 - for fully transparent
/// </param>
/// <param name="opacity">
/// the opacity of the line; a float between 0 and 1, where 1 stands for fully opaque color and
/// 0 - for fully transparent
/// </param>
/// <param name="thickness">the absolute thickness of the line</param>
/// <param name="thicknessMul">the thickness multiplication factor with the font size</param>
/// <param name="yPosition">the absolute y position relative to the baseline</param>
Expand All @@ -791,21 +793,36 @@ public virtual T SetUnderline(Color color, float thickness, float thicknessMul,
/// <returns>this element</returns>
public virtual T SetUnderline(Color color, float opacity, float thickness, float thicknessMul, float yPosition
, float yPositionMul, int lineCapStyle) {
Underline newUnderline = new Underline(color, opacity, thickness, thicknessMul, yPosition, yPositionMul, lineCapStyle
);
return SetUnderline(new Underline(color, opacity, thickness, thicknessMul, yPosition, yPositionMul, lineCapStyle
));
}

/// <summary>Sets horizontal line that can be an underline, overline or a strikethrough.</summary>
/// <remarks>
/// Sets horizontal line that can be an underline, overline or a strikethrough.
/// Actually, the line can be anywhere vertically due to position parameter.
/// Multiple call to this method will produce multiple lines.
/// </remarks>
/// <param name="underline">
///
/// <see cref="iText.Layout.Properties.Underline"/>
/// to set
/// </param>
/// <returns>this element</returns>
public virtual T SetUnderline(Underline underline) {
Object currentProperty = this.GetProperty<Object>(Property.UNDERLINE);
if (currentProperty is IList) {
((IList)currentProperty).Add(newUnderline);
((IList)currentProperty).Add(underline);
}
else {
if (currentProperty is Underline) {
IList<Underline> mergedUnderlines = new List<Underline>();
mergedUnderlines.Add((Underline)currentProperty);
mergedUnderlines.Add(newUnderline);
mergedUnderlines.Add(underline);
SetProperty(Property.UNDERLINE, mergedUnderlines);
}
else {
SetProperty(Property.UNDERLINE, newUnderline);
SetProperty(Property.UNDERLINE, underline);
}
}
return (T)(Object)this;
Expand Down
Loading

0 comments on commit 06be501

Please sign in to comment.