Skip to content

Commit 0282bb8

Browse files
AlexanderRasolkoiText-CI
authored andcommitted
Move PdfColorSpace test from samples internal, add unit test
DEVSIX-3772 Autoported commit. Original commit hash: [9a233f1e4]
1 parent ce9a063 commit 0282bb8

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

itext.tests/itext.kernel.tests/itext/kernel/pdf/PdfArrayTest.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,14 @@ source product.
4040
For more information, please contact iText Software Corp. at this
4141
4242
*/
43+
using System;
44+
using System.Collections.Generic;
4345
using iText.IO.Source;
46+
using iText.Kernel.Geom;
47+
using iText.Kernel.Pdf.Canvas.Parser;
48+
using iText.Kernel.Pdf.Canvas.Parser.Data;
49+
using iText.Kernel.Pdf.Canvas.Parser.Listener;
50+
using iText.Kernel.Pdf.Colorspace;
4451
using iText.Test;
4552

4653
namespace iText.Kernel.Pdf {
@@ -197,5 +204,36 @@ public virtual void TestIndexOf2() {
197204
NUnit.Framework.Assert.AreEqual(i, array.IndexOf(array2.Get(i)));
198205
}
199206
}
207+
208+
[NUnit.Framework.Test]
209+
public virtual void PdfUncoloredPatternColorSize1Test() {
210+
PdfDocument pdfDocument = new PdfDocument(new PdfWriter(new ByteArrayOutputStream()));
211+
String contentColorSpace = "/Cs1 cs\n";
212+
PdfDictionary pageDictionary = (PdfDictionary)new PdfDictionary().MakeIndirect(pdfDocument);
213+
PdfStream contentStream = new PdfStream(contentColorSpace.GetBytes());
214+
pageDictionary.Put(PdfName.Contents, contentStream);
215+
PdfPage page = pdfDocument.AddNewPage();
216+
page.GetPdfObject().Put(PdfName.Contents, contentStream);
217+
PdfArray pdfArray = new PdfArray();
218+
pdfArray.Add(PdfName.Pattern);
219+
PdfColorSpace space = PdfColorSpace.MakeColorSpace(pdfArray);
220+
page.GetResources().AddColorSpace(space);
221+
Rectangle rectangle = new Rectangle(50, 50, 1000, 1000);
222+
page.SetMediaBox(rectangle);
223+
PdfCanvasProcessor processor = new PdfCanvasProcessor(new PdfArrayTest.NoOpListener());
224+
processor.ProcessPageContent(page);
225+
// Check if we reach the end of the test without failings together with verifying expected color space instance
226+
NUnit.Framework.Assert.IsTrue(processor.GetGraphicsState().GetFillColor().GetColorSpace() is PdfSpecialCs.Pattern
227+
);
228+
}
229+
230+
private class NoOpListener : IEventListener {
231+
public virtual void EventOccurred(IEventData data, EventType type) {
232+
}
233+
234+
public virtual ICollection<EventType> GetSupportedEvents() {
235+
return null;
236+
}
237+
}
200238
}
201239
}

port-hash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1b38d220f049ca28e662d2ec8ecb7d2832197957
1+
9a233f1e4fde03c882c7b29a81f9524137a3a8b2

0 commit comments

Comments
 (0)