Skip to content

Commit

Permalink
Merge branch 'develop' into devsecops
Browse files Browse the repository at this point in the history
  • Loading branch information
aleks-ivanov committed Feb 18, 2025
2 parents d9f0ada + 856819e commit c8e2cc6
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 23 deletions.
20 changes: 18 additions & 2 deletions itext.tests/itext.layout.tests/itext/layout/AnonymousBoxTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public static void BeforeClass() {

[NUnit.Framework.Test]
public virtual void RelativeHeightTest() {
String outFileName = DESTINATION_FOLDER + "relativeHeightTest.pdf";
String cmpFileName = SOURCE_FOLDER + "cmp_relativeHeightTest.pdf";
String outFileName = DESTINATION_FOLDER + "relativeHeight.pdf";
String cmpFileName = SOURCE_FOLDER + "cmp_relativeHeight.pdf";
using (PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outFileName))) {
Document doc = new Document(pdfDocument);
Div div = new Div();
Expand All @@ -63,5 +63,21 @@ public virtual void RelativeHeightTest() {
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, DESTINATION_FOLDER
, "diff"));
}

[NUnit.Framework.Test]
public virtual void DefaultRoleTest() {
String outFileName = DESTINATION_FOLDER + "defaultRole.pdf";
String cmpFileName = SOURCE_FOLDER + "cmp_defaultRole.pdf";
using (PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outFileName))) {
pdfDocument.SetTagged();
Document doc = new Document(pdfDocument);
AnonymousBox ab = new AnonymousBox();
ab.Add(new Paragraph("Some text"));
doc.Add(ab);
doc.Close();
}
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, DESTINATION_FOLDER
, "diff"));
}
}
}
67 changes: 49 additions & 18 deletions itext.tests/itext.layout.tests/itext/layout/ParagraphTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,21 @@ You should have received a copy of the GNU Affero General Public License
namespace iText.Layout {
[NUnit.Framework.Category("IntegrationTest")]
public class ParagraphTest : ExtendedITextTest {
public static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
private static readonly String DESTINATION_FOLDER = NUnit.Framework.TestContext.CurrentContext.TestDirectory
+ "/test/itext/layout/ParagraphTest/";

public static readonly String sourceFolder = iText.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
private static readonly String SOURCE_FOLDER = iText.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/itext/layout/ParagraphTest/";

[NUnit.Framework.OneTimeSetUp]
public static void BeforeClass() {
CreateDestinationFolder(destinationFolder);
CreateDestinationFolder(DESTINATION_FOLDER);
}

[NUnit.Framework.Test]
public virtual void CannotPlaceABigChunkOnALineTest01() {
String outFileName = destinationFolder + "cannotPlaceABigChunkOnALineTest01.pdf";
String cmpFileName = sourceFolder + "cmp_cannotPlaceABigChunkOnALineTest01.pdf";
String outFileName = DESTINATION_FOLDER + "cannotPlaceABigChunkOnALineTest01.pdf";
String cmpFileName = SOURCE_FOLDER + "cmp_cannotPlaceABigChunkOnALineTest01.pdf";
PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outFileName));
Document doc = new Document(pdfDocument);
Paragraph p = new Paragraph().SetBorder(new SolidBorder(ColorConstants.YELLOW, 0));
Expand All @@ -56,14 +56,14 @@ public virtual void CannotPlaceABigChunkOnALineTest01() {
p.Add(new Text("b").SetFontSize(100).SetBorder(new SolidBorder(ColorConstants.BLUE, 0)));
doc.Add(p);
doc.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, DESTINATION_FOLDER
, "diff"));
}

[NUnit.Framework.Test]
public virtual void CannotPlaceABigChunkOnALineTest02() {
String outFileName = destinationFolder + "cannotPlaceABigChunkOnALineTest02.pdf";
String cmpFileName = sourceFolder + "cmp_cannotPlaceABigChunkOnALineTest02.pdf";
String outFileName = DESTINATION_FOLDER + "cannotPlaceABigChunkOnALineTest02.pdf";
String cmpFileName = SOURCE_FOLDER + "cmp_cannotPlaceABigChunkOnALineTest02.pdf";
PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outFileName));
Document doc = new Document(pdfDocument);
Paragraph p = new Paragraph().SetBorder(new SolidBorder(ColorConstants.YELLOW, 0));
Expand All @@ -73,14 +73,14 @@ public virtual void CannotPlaceABigChunkOnALineTest02() {
).SetFontSize(20).SetBorder(new SolidBorder(ColorConstants.BLUE, 0)));
doc.Add(p);
doc.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, DESTINATION_FOLDER
, "diff"));
}

[NUnit.Framework.Test]
public virtual void ForceOverflowForTextRendererPartialResult01() {
String outFileName = destinationFolder + "forceOverflowForTextRendererPartialResult01.pdf";
String cmpFileName = sourceFolder + "cmp_forceOverflowForTextRendererPartialResult01.pdf";
String outFileName = DESTINATION_FOLDER + "forceOverflowForTextRendererPartialResult01.pdf";
String cmpFileName = SOURCE_FOLDER + "cmp_forceOverflowForTextRendererPartialResult01.pdf";
PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outFileName));
Document doc = new Document(pdfDocument);
Paragraph p = new Paragraph().SetBorder(new SolidBorder(ColorConstants.YELLOW, 0)).SetTextAlignment(TextAlignment
Expand All @@ -90,7 +90,7 @@ public virtual void ForceOverflowForTextRendererPartialResult01() {
}
doc.Add(p);
doc.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, DESTINATION_FOLDER
, "diff"));
}

Expand All @@ -99,23 +99,23 @@ public virtual void ForceOverflowForTextRendererPartialResult01() {
.INFO)]
public virtual void WordWasSplitAndItWillFitOntoNextLineTest02() {
// TODO DEVSIX-4622
String outFileName = destinationFolder + "wordWasSplitAndItWillFitOntoNextLineTest02.pdf";
String cmpFileName = sourceFolder + "cmp_wordWasSplitAndItWillFitOntoNextLineTest02.pdf";
String outFileName = DESTINATION_FOLDER + "wordWasSplitAndItWillFitOntoNextLineTest02.pdf";
String cmpFileName = SOURCE_FOLDER + "cmp_wordWasSplitAndItWillFitOntoNextLineTest02.pdf";
PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outFileName));
Document document = new Document(pdfDocument);
Paragraph paragraph = new Paragraph().Add(new Text("Short").SetBackgroundColor(ColorConstants.YELLOW)).Add
(new Text(" Loooooooooooooooooooong").SetBackgroundColor(ColorConstants.RED)).SetWidth(90).SetBorder(new
SolidBorder(1));
document.Add(paragraph);
document.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, DESTINATION_FOLDER
, "diff"));
}

[NUnit.Framework.Test]
public virtual void ParagraphUsingSvgRenderingModeTest() {
String outFileName = destinationFolder + "paragraphUsingSvgRenderingMode.pdf";
String cmpFileName = sourceFolder + "cmp_paragraphUsingSvgRenderingMode.pdf";
String outFileName = DESTINATION_FOLDER + "paragraphUsingSvgRenderingMode.pdf";
String cmpFileName = SOURCE_FOLDER + "cmp_paragraphUsingSvgRenderingMode.pdf";
using (PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outFileName))) {
using (Document document = new Document(pdfDocument)) {
Paragraph paragraph1 = new Paragraph().SetBorder(new SolidBorder(ColorConstants.YELLOW, 1));
Expand All @@ -135,7 +135,38 @@ public virtual void ParagraphUsingSvgRenderingModeTest() {
document.Add(paragraph2);
}
}
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, DESTINATION_FOLDER
, "diff"));
}

[NUnit.Framework.Test]
public virtual void LeadingInHtmlModeTest() {
String outFileName = DESTINATION_FOLDER + "leadingInHtmlModeTest.pdf";
String cmpFileName = SOURCE_FOLDER + "cmp_leadingInHtmlModeTest.pdf";
using (PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outFileName))) {
using (Document document = new Document(pdfDocument)) {
String longText = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus magna. " + "Cras in mi at felis aliquet congue. Ut a est eget ligula molestie gravida. Curabitur massa.";
Paragraph paragraph1 = new Paragraph(longText).SetBorder(new SolidBorder(ColorConstants.GREEN, 1));
paragraph1.SetFixedLeading(40);
Paragraph paragraph2 = new Paragraph(longText).SetBorder(new SolidBorder(ColorConstants.BLUE, 1));
paragraph2.SetProperty(Property.RENDERING_MODE, RenderingMode.HTML_MODE);
paragraph2.SetFixedLeading(40);
document.Add(new Paragraph("Default rendering mode:"));
document.Add(paragraph1);
document.Add(new Paragraph("HTML rendering mode:"));
document.Add(paragraph2);
Paragraph paragraph3 = new Paragraph(longText).SetBorder(new SolidBorder(ColorConstants.GREEN, 1));
paragraph3.SetMultipliedLeading(5);
Paragraph paragraph4 = new Paragraph(longText).SetBorder(new SolidBorder(ColorConstants.BLUE, 1));
paragraph4.SetProperty(Property.RENDERING_MODE, RenderingMode.HTML_MODE);
paragraph4.SetMultipliedLeading(5);
document.Add(new Paragraph("Default rendering mode:"));
document.Add(paragraph3);
document.Add(new Paragraph("HTML rendering mode:"));
document.Add(paragraph4);
}
}
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, DESTINATION_FOLDER
, "diff"));
}
}
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
9 changes: 9 additions & 0 deletions itext/itext.layout/itext/layout/element/AnonymousBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
using iText.Kernel.Pdf.Tagutils;
using iText.Layout.Renderer;

namespace iText.Layout.Element {
Expand All @@ -36,6 +37,14 @@ public AnonymousBox()
: base() {
}

/// <summary><inheritDoc/></summary>
public override AccessibilityProperties GetAccessibilityProperties() {
if (tagProperties == null) {
tagProperties = new DefaultAccessibilityProperties(null);
}
return tagProperties;
}

/// <summary><inheritDoc/></summary>
protected internal override IRenderer MakeNewRenderer() {
return new AnonymousBoxRenderer(this);
Expand Down
41 changes: 39 additions & 2 deletions itext/itext.layout/itext/layout/element/Paragraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -284,11 +284,29 @@ public virtual iText.Layout.Element.Paragraph SetWidowsControl(ParagraphWidowsCo
/// <see cref="iText.Layout.Properties.Leading.FIXED"/>
/// strategy.
/// </summary>
/// <remarks>
/// Sets the leading value, using the
/// <see cref="iText.Layout.Properties.Leading.FIXED"/>
/// strategy.
/// <para />
/// If for the element
/// <see cref="iText.Layout.Properties.RenderingMode?.HTML_MODE"/>
/// is enabled, than
/// <see cref="iText.Layout.Properties.Property.LINE_HEIGHT"/>
/// property will be set instead of default layout
/// <see cref="iText.Layout.Properties.Property.LEADING"/>.
/// </remarks>
/// <param name="leading">the new leading value</param>
/// <returns>this Paragraph</returns>
/// <seealso cref="iText.Layout.Properties.Leading"/>
/// <seealso cref="iText.Layout.Properties.LineHeight"/>
public virtual iText.Layout.Element.Paragraph SetFixedLeading(float leading) {
SetProperty(Property.LEADING, new Leading(Leading.FIXED, leading));
if (RenderingMode.HTML_MODE.Equals(this.GetProperty<RenderingMode?>(Property.RENDERING_MODE))) {
SetProperty(Property.LINE_HEIGHT, LineHeight.CreateFixedValue(leading));
}
else {
SetProperty(Property.LEADING, new Leading(Leading.FIXED, leading));
}
return this;
}

Expand All @@ -297,14 +315,33 @@ public virtual iText.Layout.Element.Paragraph SetFixedLeading(float leading) {
/// <see cref="iText.Layout.Properties.Leading.MULTIPLIED"/>
/// strategy.
/// </summary>
/// <remarks>
/// Sets the leading value, using the
/// <see cref="iText.Layout.Properties.Leading.MULTIPLIED"/>
/// strategy.
/// <para />
/// If for the element
/// <see cref="iText.Layout.Properties.RenderingMode?.HTML_MODE"/>
/// is enabled, than
/// <see cref="iText.Layout.Properties.Property.LINE_HEIGHT"/>
/// property will be set instead of default layout
/// <see cref="iText.Layout.Properties.Property.LEADING"/>.
/// </remarks>
/// <param name="leading">the new leading value</param>
/// <returns>this Paragraph</returns>
/// <seealso cref="iText.Layout.Properties.Leading"/>
/// <seealso cref="iText.Layout.Properties.LineHeight"/>
public virtual iText.Layout.Element.Paragraph SetMultipliedLeading(float leading) {
SetProperty(Property.LEADING, new Leading(Leading.MULTIPLIED, leading));
if (RenderingMode.HTML_MODE.Equals(this.GetProperty<RenderingMode?>(Property.RENDERING_MODE))) {
SetProperty(Property.LINE_HEIGHT, LineHeight.CreateMultipliedValue(leading));
}
else {
SetProperty(Property.LEADING, new Leading(Leading.MULTIPLIED, leading));
}
return this;
}

/// <summary><inheritDoc/></summary>
public override AccessibilityProperties GetAccessibilityProperties() {
if (tagProperties == null) {
tagProperties = new DefaultAccessibilityProperties(StandardRoles.P);
Expand Down
2 changes: 1 addition & 1 deletion port-hash
Original file line number Diff line number Diff line change
@@ -1 +1 @@
9e804bacc19abcaa5c8554951f2049701e28002c
538e56033260bba62141e3be28b2aec1a482ba49

0 comments on commit c8e2cc6

Please sign in to comment.