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 Aug 20, 2024
2 parents 0f0548b + c0edf88 commit d490ed4
Show file tree
Hide file tree
Showing 24 changed files with 162 additions and 56 deletions.
7 changes: 0 additions & 7 deletions itext.tests/itext.kernel.tests/itext/kernel/geom/PointTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,6 @@ public virtual void PointVsItLocationTest() {
NUnit.Framework.Assert.IsTrue(first != location && first.Equals(location));
}

[NUnit.Framework.Test]
public virtual void CopyConstructorTest() {
Point second = new Point(new Point(0.13, 1.1));
NUnit.Framework.Assert.AreEqual(0.13, second.GetX(), EPSILON_COMPARISON);
NUnit.Framework.Assert.AreEqual(1.1, second.GetY(), EPSILON_COMPARISON);
}

[NUnit.Framework.Test]
public virtual void SetLocationByDoubleParamTest() {
Point first = new Point(1.23, 1.1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,138 @@ public virtual void ParseInlineImageTest() {
NUnit.Framework.Assert.AreEqual(cmpImgBytes, data);
}

[NUnit.Framework.Test]
public virtual void ParseInlineImageCalRGBColorSpaceTest() {
using (PdfDocument pdf = new PdfDocument(new PdfReader(sourceFolder + "inlineImageCalRGBColorSpace.pdf"))) {
PdfCanvasProcessor pdfCanvasProcessor = new PdfCanvasProcessor(new SimpleTextExtractionStrategy());
pdfCanvasProcessor.ProcessPageContent(pdf.GetPage(1));
PdfName name = new PdfName("Cs1");
PdfColorSpace colorSpace = pdf.GetPage(1).GetResources().GetColorSpace(name);
PdfArray pdfArray = (PdfArray)colorSpace.GetPdfObject();
PdfName actualName = (PdfName)pdfArray.Get(0);
NUnit.Framework.Assert.AreEqual(PdfName.CalRGB, actualName);
}
}

[NUnit.Framework.Test]
public virtual void ParseInlineImageCalGrayColorSpaceTest() {
using (PdfDocument pdf = new PdfDocument(new PdfReader(sourceFolder + "inlineImageCalGrayColorSpace.pdf"))
) {
PdfCanvasProcessor pdfCanvasProcessor = new PdfCanvasProcessor(new SimpleTextExtractionStrategy());
pdfCanvasProcessor.ProcessPageContent(pdf.GetPage(1));
PdfName name = new PdfName("Cs1");
PdfColorSpace colorSpace = pdf.GetPage(1).GetResources().GetColorSpace(name);
PdfArray pdfArray = (PdfArray)colorSpace.GetPdfObject();
PdfName actualName = (PdfName)pdfArray.Get(0);
NUnit.Framework.Assert.AreEqual(PdfName.CalGray, actualName);
}
}

[NUnit.Framework.Test]
public virtual void ParseInlineImageLabColorSpaceTest() {
using (PdfDocument pdf = new PdfDocument(new PdfReader(sourceFolder + "inlineImageLabColorSpace.pdf"))) {
PdfCanvasProcessor pdfCanvasProcessor = new PdfCanvasProcessor(new SimpleTextExtractionStrategy());
pdfCanvasProcessor.ProcessPageContent(pdf.GetPage(1));
PdfName name = new PdfName("Cs1");
PdfColorSpace colorSpace = pdf.GetPage(1).GetResources().GetColorSpace(name);
PdfArray pdfArray = (PdfArray)colorSpace.GetPdfObject();
PdfName actualName = (PdfName)pdfArray.Get(0);
NUnit.Framework.Assert.AreEqual(PdfName.Lab, actualName);
}
}

[NUnit.Framework.Test]
public virtual void ParseInlineImageICCBasedColorSpaceTest() {
using (PdfDocument pdf = new PdfDocument(new PdfReader(sourceFolder + "inlineImageICCBasedColorSpace.pdf")
)) {
PdfCanvasProcessor pdfCanvasProcessor = new PdfCanvasProcessor(new SimpleTextExtractionStrategy());
pdfCanvasProcessor.ProcessPageContent(pdf.GetPage(1));
PdfName name = new PdfName("Cs1");
PdfColorSpace colorSpace = pdf.GetPage(1).GetResources().GetColorSpace(name);
PdfArray pdfArray = (PdfArray)colorSpace.GetPdfObject();
PdfName actualName = (PdfName)pdfArray.Get(0);
NUnit.Framework.Assert.AreEqual(PdfName.ICCBased, actualName);
}
}

[NUnit.Framework.Test]
public virtual void ParseInlineImageDeviceRGBColorSpaceTest() {
using (PdfDocument pdf = new PdfDocument(new PdfReader(sourceFolder + "inlineImageDeviceRGBColorSpace.pdf"
))) {
PdfCanvasProcessor pdfCanvasProcessor = new PdfCanvasProcessor(new SimpleTextExtractionStrategy());
pdfCanvasProcessor.ProcessPageContent(pdf.GetPage(1));
PdfStream stream = pdf.GetPage(1).GetContentStream(0);
String firstPageData = iText.Commons.Utils.JavaUtil.GetStringForBytes(stream.GetBytes());
NUnit.Framework.Assert.IsTrue(firstPageData.Contains(PdfName.DeviceRGB.GetValue()));
}
}

[NUnit.Framework.Test]
public virtual void ParseInlineImageDeviceCMYKColorSpaceTest() {
using (PdfDocument pdf = new PdfDocument(new PdfReader(sourceFolder + "inlineImageDeviceCMYKColorSpace.pdf"
))) {
PdfCanvasProcessor pdfCanvasProcessor = new PdfCanvasProcessor(new SimpleTextExtractionStrategy());
pdfCanvasProcessor.ProcessPageContent(pdf.GetPage(1));
PdfStream stream = pdf.GetPage(1).GetContentStream(0);
String firstPageData = iText.Commons.Utils.JavaUtil.GetStringForBytes(stream.GetBytes());
NUnit.Framework.Assert.IsTrue(firstPageData.Contains(PdfName.DeviceCMYK.GetValue()));
}
}

[NUnit.Framework.Test]
public virtual void ParseInlineImageDeviceGrayColorSpaceTest() {
using (PdfDocument pdf = new PdfDocument(new PdfReader(sourceFolder + "inlineImageDeviceGrayColorSpace.pdf"
))) {
PdfCanvasProcessor pdfCanvasProcessor = new PdfCanvasProcessor(new SimpleTextExtractionStrategy());
pdfCanvasProcessor.ProcessPageContent(pdf.GetPage(1));
PdfStream stream = pdf.GetPage(1).GetContentStream(0);
String firstPageData = iText.Commons.Utils.JavaUtil.GetStringForBytes(stream.GetBytes());
NUnit.Framework.Assert.IsTrue(firstPageData.Contains(PdfName.DeviceGray.GetValue()));
}
}

[NUnit.Framework.Test]
public virtual void ParseInlineImageSeparationColorSpaceTest() {
using (PdfDocument pdf = new PdfDocument(new PdfReader(sourceFolder + "inlineImageSeparationColorSpace.pdf"
))) {
PdfCanvasProcessor pdfCanvasProcessor = new PdfCanvasProcessor(new SimpleTextExtractionStrategy());
pdfCanvasProcessor.ProcessPageContent(pdf.GetPage(1));
PdfName name = new PdfName("Cs1");
PdfColorSpace colorSpace = pdf.GetPage(1).GetResources().GetColorSpace(name);
PdfArray pdfArray = (PdfArray)colorSpace.GetPdfObject();
PdfName actualName = (PdfName)pdfArray.Get(0);
NUnit.Framework.Assert.AreEqual(PdfName.Separation, actualName);
}
}

[NUnit.Framework.Test]
public virtual void ParseInlineImageDeviceNColorSpaceTest() {
using (PdfDocument pdf = new PdfDocument(new PdfReader(sourceFolder + "inlineImageDeviceNColorSpace.pdf"))
) {
PdfCanvasProcessor pdfCanvasProcessor = new PdfCanvasProcessor(new SimpleTextExtractionStrategy());
pdfCanvasProcessor.ProcessPageContent(pdf.GetPage(1));
PdfName name = new PdfName("Cs1");
PdfColorSpace colorSpace = pdf.GetPage(1).GetResources().GetColorSpace(name);
PdfArray pdfArray = (PdfArray)colorSpace.GetPdfObject();
PdfName actualName = (PdfName)pdfArray.Get(0);
NUnit.Framework.Assert.AreEqual(PdfName.DeviceN, actualName);
}
}

[NUnit.Framework.Test]
public virtual void ParseInlineImageIndexedColorSpaceTest() {
using (PdfDocument pdf = new PdfDocument(new PdfReader(sourceFolder + "inlineImageIndexedColorSpace.pdf"))
) {
PdfCanvasProcessor pdfCanvasProcessor = new PdfCanvasProcessor(new SimpleTextExtractionStrategy());
pdfCanvasProcessor.ProcessPageContent(pdf.GetPage(1));
PdfName name = new PdfName("Cs1");
PdfColorSpace colorSpace = pdf.GetPage(1).GetResources().GetColorSpace(name);
PdfArray pdfArray = (PdfArray)colorSpace.GetPdfObject();
PdfName actualName = (PdfName)pdfArray.Get(0);
NUnit.Framework.Assert.AreEqual(PdfName.Indexed, actualName);
}
}

private class InlineImageEventListener : IEventListener {
private readonly IList<PdfStream> inlineImages = new List<PdfStream>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,22 +76,6 @@ public virtual void CsInDictAsNameNullTest() {
, "/ICCBased"), exception.Message);
}

[NUnit.Framework.Test]
public virtual void NotSupportedCsWithCsDictionaryTest() {
PdfName colorSpace = PdfName.ICCBased;
PdfDictionary dictionary = new PdfDictionary();
PdfArray array = new PdfArray();
array.Add(PdfName.Pattern);
PdfStream stream = new PdfStream();
stream.Put(PdfName.N, new PdfNumber(4));
array.Add(stream);
dictionary.Put(colorSpace, array);
Exception exception = NUnit.Framework.Assert.Catch(typeof(InlineImageParsingUtils.InlineImageParseException
), () => InlineImageParsingUtils.GetComponentsPerPixel(colorSpace, dictionary));
NUnit.Framework.Assert.AreEqual(MessageFormatUtil.Format(KernelExceptionMessageConstant.UNEXPECTED_COLOR_SPACE
, "/ICCBased"), exception.Message);
}

[NUnit.Framework.Test]
public virtual void NullCsTest() {
NUnit.Framework.Assert.AreEqual(1, InlineImageParsingUtils.GetComponentsPerPixel(null, null));
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.
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ private void AddContentToDocInCustomNs(PdfDocument pdfDocument, PdfNamespace def
if (defaultNamespace == null) {
Text i = new Text("italic text");
i.GetAccessibilityProperties().SetRole("I");
Paragraph pi = new Paragraph(i.SetItalic());
Paragraph pi = new Paragraph(i.SimulateItalic());
document.Add(pi);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -997,7 +997,7 @@ private IBlockElement CreateTable(bool useCaption) {
Div div = new Div();
div.GetAccessibilityProperties().SetRole(StandardRoles.TABLE);
Paragraph p = new Paragraph("Caption").SetNeutralRole();
p.SetTextAlignment(TextAlignment.CENTER).SetBold();
p.SetTextAlignment(TextAlignment.CENTER).SimulateBold();
Div caption = new Div().Add(p);
caption.GetAccessibilityProperties().SetRole(StandardRoles.CAPTION);
div.Add(caption);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1590,7 +1590,7 @@ public virtual void TableWithHeaderFooterTest14() {
}
}
table.GetHeader().SetBorderTop(new SolidBorder(2)).SetBorderBottom(new SolidBorder(1));
table.GetFooter().SetBold().SetBorderTop(new SolidBorder(10)).SetBorderBottom(new SolidBorder(1)).SetBackgroundColor
table.GetFooter().SimulateBold().SetBorderTop(new SolidBorder(10)).SetBorderBottom(new SolidBorder(1)).SetBackgroundColor
(ColorConstants.LIGHT_GRAY);
doc.Add(table);
doc.Add(new AreaBreak());
Expand Down
8 changes: 4 additions & 4 deletions itext.tests/itext.layout.tests/itext/layout/TableTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1879,11 +1879,11 @@ public virtual void AutoLayoutTest01() {
doc.Add(table);
doc.Add(new Paragraph("A cell with bold text:"));
table = new Table(new float[1]);
table.AddCell("A cell").SetBold();
table.AddCell("A cell").SimulateBold();
doc.Add(table);
doc.Add(new Paragraph("A cell with italic text:"));
table = new Table(new float[1]);
table.AddCell("A cell").SetItalic();
table.AddCell("A cell").SimulateItalic();
doc.Add(table);
doc.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
Expand Down Expand Up @@ -2762,7 +2762,7 @@ public virtual void InheritHeaderPropsWhileMinMaxWidthCalculationsTest() {
table.AddCell(new Cell().Add(new Paragraph("He")));
// If this property is not inherited while calculating min/max widths,
// then while layouting header will request more space than the layout box's width
table.GetHeader().SetBold();
table.GetHeader().SimulateBold();
document.Add(table);
document.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + filename, sourceFolder
Expand Down Expand Up @@ -2928,7 +2928,7 @@ public virtual void PreciseFittingBoldSimulatedTextInCellsTest() {
table.UseAllAvailableWidth();
table.SetFixedLayout();
for (int i = 0; i < numberOfColumns; i++) {
table.AddCell(new Cell().Add(new Paragraph("Description").SetBold()));
table.AddCell(new Cell().Add(new Paragraph("Description").SimulateBold()));
}
doc.Add(table);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,12 +210,12 @@ public virtual void FontStyleSimulationTest01() {
document.Add(new Paragraph("I'm underlined").SetUnderline());
document.Add(new Paragraph("I'm strikethrough").SetLineThrough());
document.Add(new Paragraph(new Text("I'm a bold simulation font").SetBackgroundColor(ColorConstants.GREEN)
).SetBold());
).SimulateBold());
document.Add(new Paragraph(new Text("I'm an italic simulation font").SetBackgroundColor(ColorConstants.GREEN
)).SetItalic());
)).SimulateItalic());
document.Add(new Paragraph(new Text("I'm a super bold italic underlined linethrough piece of text and no one can be better than me, even if "
+ "such a long description will cause me to occupy two lines").SetBackgroundColor(ColorConstants.GREEN
)).SetItalic().SetBold().SetUnderline().SetLineThrough());
)).SimulateItalic().SimulateBold().SetUnderline().SetLineThrough());
document.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
, "diff"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ private void AddContent(Document document, bool wrapImages, int imageWidthProper
}
div.Add(image);
div.Add(new Paragraph("Figure for Div" + i + ": This is longer text that wraps This is longer text that wraps"
).SetTextAlignment(TextAlignment.CENTER)).SetBold();
).SetTextAlignment(TextAlignment.CENTER)).SimulateBold();
document.Add(div);
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,6 @@ public virtual void OverflowWrapBreakWordProperty() {
[NUnit.Framework.Test]
public virtual void OverflowWrapAnywhereBoldSimulationMaxWidth() {
Text text = new Text("wow");
text.SetBold();
TextRenderer textRenderer = (TextRenderer)text.GetRenderer();
textRenderer.SetParent(CreateDummyDocument().GetRenderer());
float maxWidthNoOverflowWrap = textRenderer.GetMinMaxWidth().GetMaxWidth();
Expand All @@ -275,7 +274,7 @@ public virtual void OverflowWrapAnywhereBoldSimulationMaxWidth() {
[NUnit.Framework.Test]
public virtual void OverflowWrapAnywhereItalicSimulationMaxWidth() {
Text text = new Text("wow");
text.SetItalic();
text.SimulateItalic();
TextRenderer textRenderer = (TextRenderer)text.GetRenderer();
textRenderer.SetParent(CreateDummyDocument().GetRenderer());
float maxWidthNoOverflowWrap = textRenderer.GetMinMaxWidth().GetMaxWidth();
Expand All @@ -291,7 +290,7 @@ public virtual void OverflowWrapAnywhereBoldSimulationMinWidth() {
TextRenderer textRenderer = (TextRenderer)text.GetRenderer();
textRenderer.SetParent(CreateDummyDocument().GetRenderer());
float minWidthNoBoldSimulation = textRenderer.GetMinMaxWidth().GetMinWidth();
text.SetBold();
text.SimulateBold();
float minWidthAndBoldSimulation = textRenderer.GetMinMaxWidth().GetMinWidth();
NUnit.Framework.Assert.IsTrue(minWidthAndBoldSimulation > minWidthNoBoldSimulation);
}
Expand All @@ -303,7 +302,7 @@ public virtual void OverflowWrapAnywhereItalicSimulationMinWidth() {
TextRenderer textRenderer = (TextRenderer)text.GetRenderer();
textRenderer.SetParent(CreateDummyDocument().GetRenderer());
float minWidthNoItalicSimulation = textRenderer.GetMinMaxWidth().GetMinWidth();
text.SetItalic();
text.SimulateItalic();
float minWidthAndItalicSimulation = textRenderer.GetMinMaxWidth().GetMinWidth();
NUnit.Framework.Assert.IsTrue(minWidthAndItalicSimulation > minWidthNoItalicSimulation);
}
Expand Down
10 changes: 0 additions & 10 deletions itext/itext.kernel/itext/kernel/geom/Point.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,6 @@ public Point(double x, double y) {
SetLocation(x, y);
}

/// <summary>
/// Instantiates a new
/// <see cref="Point"/>
/// instance based on another point.
/// </summary>
/// <param name="p">the point which will be copied</param>
public Point(iText.Kernel.Geom.Point p) {
SetLocation(p.x, p.y);
}

/// <summary>Gets x coordinate of the point.</summary>
/// <returns>the x coordinate</returns>
public virtual double GetX() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,20 @@ internal static int GetComponentsPerPixel(PdfName colorSpaceName, PdfDictionary
}
}
else {
if (PdfName.Indexed.Equals(colorSpace.GetAsName(0))) {
if (PdfName.Indexed.Equals(colorSpace.GetAsName(0)) || PdfName.CalGray.Equals(colorSpace.GetAsName(0)) ||
PdfName.Pattern.Equals(colorSpace.GetAsName(0)) || PdfName.Separation.Equals(colorSpace.GetAsName(0))) {
return 1;
}
if (PdfName.CalRGB.Equals(colorSpace.GetAsName(0)) || PdfName.Lab.Equals(colorSpace.GetAsName(0))) {
return 3;
}
if (PdfName.ICCBased.Equals(colorSpace.GetAsName(0))) {
return colorSpace.GetAsStream(1).GetAsNumber(PdfName.N).IntValue();
}
if (PdfName.DeviceN.Equals(colorSpace.GetAsName(0))) {
//Checking colorants dict size
return colorSpace.GetAsArray(1).Size();
}
}
}
throw new InlineImageParsingUtils.InlineImageParseException(KernelExceptionMessageConstant.UNEXPECTED_COLOR_SPACE
Expand Down
Loading

0 comments on commit d490ed4

Please sign in to comment.