Skip to content

Commit a140124

Browse files
committed
Merge branch 'develop' into devsecops
2 parents 5bd30b8 + 80389f8 commit a140124

File tree

28 files changed

+677
-95
lines changed

28 files changed

+677
-95
lines changed

itext.tests/itext.commons.tests/itext/commons/datastructures/Tuple2Test.cs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,49 @@ public virtual void TestTuple2_TestWithNullFirstValue() {
4545
NUnit.Framework.Assert.IsNull(tuple.GetFirst());
4646
NUnit.Framework.Assert.AreEqual(Convert.ToInt32(1), tuple.GetSecond());
4747
}
48+
49+
[NUnit.Framework.Test]
50+
public virtual void EqualsTest() {
51+
Tuple2<String, int> tuple1 = new Tuple2<String, int>("test", 1);
52+
Tuple2<String, int> tuple2 = new Tuple2<String, int>("test", 1);
53+
NUnit.Framework.Assert.AreEqual(tuple1, tuple2);
54+
}
55+
56+
[NUnit.Framework.Test]
57+
public virtual void EqualsSameTest() {
58+
Tuple2<String, int> tuple = new Tuple2<String, int>("test", 1);
59+
NUnit.Framework.Assert.AreEqual(tuple, tuple);
60+
}
61+
62+
[NUnit.Framework.Test]
63+
public virtual void EqualsNullTest() {
64+
Tuple2<String, int> tuple = new Tuple2<String, int>("test", 1);
65+
NUnit.Framework.Assert.AreNotEqual(tuple, null);
66+
}
67+
68+
[NUnit.Framework.Test]
69+
public virtual void NotEqualsTest() {
70+
Tuple2<String, int> tuple1 = new Tuple2<String, int>("test", 1);
71+
Tuple2<String, int> tuple2 = new Tuple2<String, int>("test", 2);
72+
Tuple2<String, int> tuple3 = new Tuple2<String, int>("test2", 2);
73+
NUnit.Framework.Assert.AreNotEqual(tuple1, tuple2);
74+
NUnit.Framework.Assert.AreNotEqual(tuple2, tuple3);
75+
NUnit.Framework.Assert.AreNotEqual(tuple1, tuple3);
76+
}
77+
78+
[NUnit.Framework.Test]
79+
public virtual void EqualsWithCustomTest() {
80+
Tuple2<String, int> tuple1 = new Tuple2<String, int>("test", 1);
81+
Tuple2<String, int> tuple2 = new Tuple2Test.CustomTuple2<String, int>("test", 1);
82+
Tuple2<String, int> tuple3 = new Tuple2Test.CustomTuple2<String, int>("test", 1);
83+
NUnit.Framework.Assert.AreNotEqual(tuple1, tuple2);
84+
NUnit.Framework.Assert.AreEqual(tuple2, tuple3);
85+
}
86+
87+
private class CustomTuple2<T1, T2> : Tuple2<T1, T2> {
88+
public CustomTuple2(T1 test, T2 i)
89+
: base(test, i) {
90+
}
91+
}
4892
}
4993
}

itext.tests/itext.io.tests/itext/io/font/TrueTypeFontTest.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,14 @@ public virtual void CheckSxHeightTtfTest() {
102102
NUnit.Framework.Assert.AreEqual(536, xHeight);
103103
}
104104

105+
[NUnit.Framework.Test]
106+
public virtual void ContainsCmapTest() {
107+
TrueTypeFont fontProgram = (TrueTypeFont)FontProgramFactory.CreateFont(SOURCE_FOLDER + "glyphs-fmt-6.ttf");
108+
NUnit.Framework.Assert.AreEqual(1, fontProgram.GetNumberOfCmaps());
109+
NUnit.Framework.Assert.IsTrue(fontProgram.IsCmapPresent(0, 3));
110+
NUnit.Framework.Assert.IsFalse(fontProgram.IsCmapPresent(1, 0));
111+
}
112+
105113
private void CheckCmapTableEntry(FontProgram fontProgram, char uniChar, int expectedGlyphId) {
106114
Glyph glyph = fontProgram.GetGlyph(uniChar);
107115
NUnit.Framework.Assert.AreEqual(expectedGlyphId, glyph.GetCode());

itext.tests/itext.layout.tests/itext/layout/renderer/BlockRendererTest.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,16 @@ You should have received a copy of the GNU Affero General Public License
3232
using iText.Layout.Element;
3333
using iText.Layout.Font;
3434
using iText.Layout.Layout;
35+
using iText.Layout.Minmaxwidth;
3536
using iText.Layout.Properties;
3637
using iText.Test;
3738
using iText.Test.Attributes;
3839

3940
namespace iText.Layout.Renderer {
4041
[NUnit.Framework.Category("IntegrationTest")]
4142
public class BlockRendererTest : ExtendedITextTest {
43+
private const float EPS = 0.001f;
44+
4245
public static readonly String SOURCE_FOLDER = iText.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
4346
.CurrentContext.TestDirectory) + "/resources/itext/layout/BlockRendererTest/";
4447

@@ -64,6 +67,34 @@ public virtual void ApplyMinHeightForSpecificDimensionsCausingFloatPrecisionErro
6467
NUnit.Framework.Assert.IsNull(renderer);
6568
}
6669

70+
[NUnit.Framework.Test]
71+
public virtual void RelativeWidthInMinMaxWidthCalculationsTest() {
72+
Div div = new Div();
73+
div.SetWidth(UnitValue.CreatePercentValue(42.5F));
74+
BlockRenderer divRenderer = (BlockRenderer)div.GetRenderer();
75+
MinMaxWidth minMaxWidth = divRenderer.GetMinMaxWidth(200.0F);
76+
NUnit.Framework.Assert.AreEqual(85.0F, minMaxWidth.GetMaxWidth(), EPS);
77+
}
78+
79+
[NUnit.Framework.Test]
80+
public virtual void RelativeMaxWidthInMinMaxWidthCalculationsTest() {
81+
Div div = new Div();
82+
div.SetProperty(Property.MAX_WIDTH, UnitValue.CreatePercentValue(42.5F));
83+
BlockRenderer divRenderer = (BlockRenderer)div.GetRenderer();
84+
MinMaxWidth minMaxWidth = divRenderer.GetMinMaxWidth(200.0F);
85+
NUnit.Framework.Assert.AreEqual(85.0F, minMaxWidth.GetMaxWidth(), EPS);
86+
}
87+
88+
[NUnit.Framework.Test]
89+
public virtual void RelativeMinWidthInMinMaxWidthCalculationsTest() {
90+
Div div = new Div();
91+
div.SetProperty(Property.MIN_WIDTH, UnitValue.CreatePercentValue(42.5F));
92+
BlockRenderer divRenderer = (BlockRenderer)div.GetRenderer();
93+
MinMaxWidth minMaxWidth = divRenderer.GetMinMaxWidth(200.0F);
94+
NUnit.Framework.Assert.AreEqual(85.0F, minMaxWidth.GetMinWidth(), EPS);
95+
NUnit.Framework.Assert.AreEqual(85.0F, minMaxWidth.GetMaxWidth(), EPS);
96+
}
97+
6798
[NUnit.Framework.Test]
6899
[LogMessage(iText.IO.Logs.IoLogMessageConstant.OCCUPIED_AREA_HAS_NOT_BEEN_INITIALIZED, Count = 2, LogLevel
69100
= LogLevelConstants.ERROR)]

itext.tests/itext.layout.tests/itext/layout/renderer/FlexUtilTest.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ You should have received a copy of the GNU Affero General Public License
2626
using iText.Commons.Utils;
2727
using iText.IO.Font.Constants;
2828
using iText.IO.Image;
29+
using iText.Kernel.Colors;
2930
using iText.Kernel.Geom;
3031
using iText.Kernel.Pdf;
3132
using iText.Kernel.Pdf.Xobject;
@@ -81,6 +82,24 @@ public virtual void DefaultTest01() {
8182
}
8283
}
8384

85+
[NUnit.Framework.Test]
86+
public virtual void SimpleColumnDirectionTest() {
87+
Rectangle bBox = new Rectangle(545, 842);
88+
DocumentRenderer documentRenderer = new DocumentRenderer(new Document(new PdfDocument(new PdfWriter(new MemoryStream
89+
()))));
90+
Div div = new Div();
91+
FlexContainerRenderer flexContainerRenderer = new FlexContainerRenderer(div);
92+
flexContainerRenderer.SetParent(documentRenderer);
93+
div.SetNextRenderer(flexContainerRenderer);
94+
div.AddStyle(COLUMN_STYLE);
95+
Div childDiv = new Div().SetBackgroundColor(ColorConstants.RED).SetWidth(UnitValue.CreatePercentValue(75));
96+
div.Add(childDiv);
97+
flexContainerRenderer.AddChild(childDiv.CreateRendererSubTree().SetParent(flexContainerRenderer));
98+
IList<IList<FlexItemInfo>> rectangleTable = FlexUtil.CalculateChildrenRectangles(bBox, (FlexContainerRenderer
99+
)div.GetRenderer());
100+
NUnit.Framework.Assert.AreEqual(75.0F, rectangleTable[0][0].GetRectangle().GetWidth(), EPS);
101+
}
102+
84103
[NUnit.Framework.Test]
85104
public virtual void Item1BasisGtWidthGrow0Shrink01Test01() {
86105
Rectangle bBox = new Rectangle(545, 842);

itext.tests/itext.pdfua.tests/itext/pdfua/PdfUAFontsTest.cs

Lines changed: 111 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,8 @@ public virtual void TrueTypeFontWithDifferencesTest(PdfUAConformance pdfUAConfor
162162
, 36).ShowText("world").EndText().RestoreState().CloseTag();
163163
}
164164
);
165-
// TODO DEVSIX-9017 Support PDF/UA rules for fonts.
166-
// TODO DEVSIX-9004 Support Character encodings related rules in UA-2
167-
framework.AssertOnlyVeraPdfFail("trueTypeFontWithDifferencesTest", pdfUAConformance);
165+
framework.AssertBothFail("trueTypeFontWithDifferencesTest", PdfUAExceptionMessageConstants.NON_SYMBOLIC_TTF_SHALL_SPECIFY_MAC_ROMAN_OR_WIN_ANSI_ENCODING
166+
, false, pdfUAConformance);
168167
}
169168

170169
[NUnit.Framework.TestCaseSource("Data")]
@@ -232,7 +231,7 @@ public virtual void NonSymbolicTtfWithValidEncodingTest(PdfUAConformance pdfUACo
232231
document.Add(paragraph);
233232
}
234233
);
235-
framework.AssertBothValid("nonSymbolicTtfWithIncompatibleEncoding", pdfUAConformance);
234+
framework.AssertBothValid("nonSymbolicTtfWithValidEncodingTest", pdfUAConformance);
236235
}
237236

238237
[NUnit.Framework.TestCaseSource("Data")]
@@ -251,8 +250,8 @@ public virtual void NonSymbolicTtfWithIncompatibleEncodingTest(PdfUAConformance
251250
document.Add(paragraph);
252251
}
253252
);
254-
// TODO DEVSIX-9004 Support Character encodings related rules in UA-2
255-
framework.AssertOnlyVeraPdfFail("nonSymbolicTtfWithIncompatibleEncoding", pdfUAConformance);
253+
framework.AssertBothFail("nonSymbolicTtfWithIncompatibleEncoding", PdfUAExceptionMessageConstants.NON_SYMBOLIC_TTF_SHALL_SPECIFY_MAC_ROMAN_OR_WIN_ANSI_ENCODING
254+
, false, pdfUAConformance);
256255
}
257256

258257
[NUnit.Framework.TestCaseSource("Data")]
@@ -261,7 +260,8 @@ public virtual void SymbolicTtfTest(PdfUAConformance pdfUAConformance) {
261260
Document document = new Document(pdfDoc);
262261
PdfFont font;
263262
try {
264-
font = PdfFontFactory.CreateFont(FONT_FOLDER + "Symbols1.ttf");
263+
font = PdfFontFactory.CreateFont(FONT_FOLDER + "Symbols1.ttf", PdfEncodings.MACROMAN, PdfFontFactory.EmbeddingStrategy
264+
.FORCE_EMBEDDED);
265265
}
266266
catch (System.IO.IOException) {
267267
throw new Exception();
@@ -280,19 +280,83 @@ public virtual void SymbolicTtfWithEncodingTest(PdfUAConformance pdfUAConformanc
280280
Document document = new Document(pdfDoc);
281281
PdfFont font;
282282
try {
283-
// if we specify encoding, symbolic font is treated as non-symbolic
284283
font = PdfFontFactory.CreateFont(FONT_FOLDER + "Symbols1.ttf", PdfEncodings.MACROMAN, PdfFontFactory.EmbeddingStrategy
285284
.FORCE_EMBEDDED);
286285
}
287286
catch (System.IO.IOException) {
288287
throw new Exception();
289288
}
289+
font.GetPdfObject().Put(PdfName.Encoding, PdfName.MacRomanEncoding);
290+
document.SetFont(font);
291+
Paragraph paragraph = new Paragraph("ABC");
292+
document.Add(paragraph);
293+
}
294+
);
295+
// VeraPDF is valid since iText fixes symbolic flag to non-symbolic on closing.
296+
framework.AssertOnlyITextFail("symbolicTtfWithEncoding", PdfUAExceptionMessageConstants.SYMBOLIC_TTF_SHALL_NOT_CONTAIN_ENCODING
297+
, pdfUAConformance);
298+
}
299+
300+
[NUnit.Framework.TestCaseSource("Data")]
301+
public virtual void SymbolicTtfWithInvalidCmapTest(PdfUAConformance pdfUAConformance) {
302+
framework.AddBeforeGenerationHook((pdfDoc) => {
303+
Document document = new Document(pdfDoc);
304+
PdfFont font;
305+
try {
306+
TrueTypeFont fontProgram = new PdfUAFontsTest.CustomSymbolicTrueTypeFont(FONT);
307+
font = PdfFontFactory.CreateFont(fontProgram, PdfEncodings.MACROMAN, PdfFontFactory.EmbeddingStrategy.FORCE_EMBEDDED
308+
);
309+
}
310+
catch (System.IO.IOException) {
311+
throw new Exception();
312+
}
313+
document.SetFont(font);
314+
Paragraph paragraph = new Paragraph("ABC");
315+
document.Add(paragraph);
316+
}
317+
);
318+
// VeraPDF is valid since iText fixes symbolic flag to non-symbolic on closing.
319+
if (PdfUAConformance.PDF_UA_1 == pdfUAConformance) {
320+
framework.AssertOnlyITextFail("symbolicTtfWithInvalidCmapTest", PdfUAExceptionMessageConstants.SYMBOLIC_TTF_SHALL_CONTAIN_EXACTLY_ONE_OR_AT_LEAST_MICROSOFT_SYMBOL_CMAP
321+
, pdfUAConformance);
322+
}
323+
else {
324+
if (PdfUAConformance.PDF_UA_2 == pdfUAConformance) {
325+
framework.AssertOnlyITextFail("symbolicTtfWithInvalidCmapTest", PdfUAExceptionMessageConstants.SYMBOLIC_TTF_SHALL_CONTAIN_MAC_ROMAN_OR_MICROSOFT_SYMBOL_CMAP
326+
, pdfUAConformance);
327+
}
328+
}
329+
}
330+
331+
[NUnit.Framework.TestCaseSource("Data")]
332+
public virtual void NonSymbolicTtfWithInvalidCmapTest(PdfUAConformance pdfUAConformance) {
333+
framework.AddBeforeGenerationHook((pdfDoc) => {
334+
Document document = new Document(pdfDoc);
335+
PdfFont font;
336+
try {
337+
TrueTypeFont fontProgram = new PdfUAFontsTest.CustomNonSymbolicTrueTypeFont(FONT);
338+
font = PdfFontFactory.CreateFont(fontProgram, PdfEncodings.MACROMAN, PdfFontFactory.EmbeddingStrategy.FORCE_EMBEDDED
339+
);
340+
}
341+
catch (System.IO.IOException) {
342+
throw new Exception();
343+
}
290344
document.SetFont(font);
291345
Paragraph paragraph = new Paragraph("ABC");
292346
document.Add(paragraph);
293347
}
294348
);
295-
framework.AssertBothValid("symbolicTtfWithEncoding", pdfUAConformance);
349+
// VeraPDF is valid since the file itself is valid, but itext code is modified for testing.
350+
if (PdfUAConformance.PDF_UA_1 == pdfUAConformance) {
351+
framework.AssertOnlyITextFail("nonSymbolicTtfWithInvalidCmapTest", PdfUAExceptionMessageConstants.NON_SYMBOLIC_TTF_SHALL_CONTAIN_NON_SYMBOLIC_CMAP
352+
, pdfUAConformance);
353+
}
354+
else {
355+
if (PdfUAConformance.PDF_UA_2 == pdfUAConformance) {
356+
framework.AssertOnlyITextFail("nonSymbolicTtfWithInvalidCmapTest", PdfUAExceptionMessageConstants.NON_SYMBOLIC_TTF_SHALL_CONTAIN_MAC_ROMAN_OR_MICROSOFT_UNI_CMAP
357+
, pdfUAConformance);
358+
}
359+
}
296360
}
297361

298362
[NUnit.Framework.Test]
@@ -301,5 +365,43 @@ public virtual void SymbolicTtfWithChangedCmapTest() {
301365
NUnit.Framework.Assert.Catch(typeof(NullReferenceException), () => PdfFontFactory.CreateFont(FONT_FOLDER +
302366
"Symbols1_changed_cmap.ttf", PdfFontFactory.EmbeddingStrategy.FORCE_EMBEDDED));
303367
}
368+
369+
private class CustomSymbolicTrueTypeFont : TrueTypeFont {
370+
public CustomSymbolicTrueTypeFont(String path)
371+
: base(path) {
372+
}
373+
374+
public override int GetPdfFontFlags() {
375+
return 4;
376+
}
377+
378+
public override bool IsCmapPresent(int platformID, int encodingID) {
379+
if (platformID == 1) {
380+
return false;
381+
}
382+
return base.IsCmapPresent(platformID, encodingID);
383+
}
384+
}
385+
386+
private class CustomNonSymbolicTrueTypeFont : TrueTypeFont {
387+
public CustomNonSymbolicTrueTypeFont(String path)
388+
: base(path) {
389+
}
390+
391+
public override int GetPdfFontFlags() {
392+
return 32;
393+
}
394+
395+
public override bool IsCmapPresent(int platformID, int encodingID) {
396+
if (platformID == 1 || encodingID == 1) {
397+
return false;
398+
}
399+
return base.IsCmapPresent(platformID, encodingID);
400+
}
401+
402+
public override int GetNumberOfCmaps() {
403+
return 0;
404+
}
405+
}
304406
}
305407
}

itext.tests/itext.sign.tests/itext/signatures/PdfUASignerTest.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,7 @@ public virtual void SignatureAppearanceWithImageUA2() {
291291
(appearance);
292292
}
293293
);
294-
// TODO DEVSIX-9057 setAlternativeDescription doesn't set Contents entry for PdfSigner
295-
new VeraPdfValidator().ValidateFailure(outPdf);
294+
new VeraPdfValidator().Validate(outPdf);
296295
}
297296

298297
// Android-Conversion-Skip-Line (TODO DEVSIX-7377 introduce pdf\a validation on Android)
@@ -319,9 +318,8 @@ public virtual void SignatureAppearanceImageInDivUA2() {
319318
(appearance);
320319
}
321320
);
322-
// TODO DEVSIX-9057 setAlternativeDescription doesn't set Contents entry for PdfSigner
323321
// TODO DEVSIX-9060 Image that is in Div element is not rendered in signature
324-
new VeraPdfValidator().ValidateFailure(outPdf);
322+
new VeraPdfValidator().Validate(outPdf);
325323
}
326324

327325
// Android-Conversion-Skip-Line (TODO DEVSIX-7377 introduce pdf\a validation on Android)
@@ -341,8 +339,7 @@ public virtual void SignatureAppearanceWithLineSeparatorUA2() {
341339
(appearance);
342340
}
343341
);
344-
// TODO DEVSIX-9057 setAlternativeDescription doesn't set Contents entry for PdfSigner
345-
new VeraPdfValidator().ValidateFailure(outPdf);
342+
new VeraPdfValidator().Validate(outPdf);
346343
}
347344

348345
// Android-Conversion-Skip-Line (TODO DEVSIX-7377 introduce pdf\a validation on Android)

0 commit comments

Comments
 (0)