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 Sep 25, 2024
2 parents b14a748 + 7eb1313 commit 688ef6b
Show file tree
Hide file tree
Showing 51 changed files with 2,258 additions and 2,140 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ You should have received a copy of the GNU Affero General Public License
using iText.Kernel.Font;
using iText.Kernel.Pdf;
using iText.Kernel.Pdf.Colorspace;
using iText.Kernel.Pdf.Colorspace.Shading;
using iText.Kernel.Pdf.Function;
using iText.Kernel.Utils;
using iText.Test;
Expand Down Expand Up @@ -332,8 +333,8 @@ public virtual void PatternColorColoredAxialPatternTest() {
PdfDocument document = new PdfDocument(writer);
PdfPage page = document.AddNewPage();
PdfCanvas canvas = new PdfCanvas(page);
PdfShading axial = new PdfShading.Axial(new PdfDeviceCs.Rgb(), 36, 716, new float[] { 1, .784f, 0 }, 396,
788, new float[] { 0, 0, 1 }, new bool[] { true, true });
AbstractPdfShading axial = new PdfAxialShading(new PdfDeviceCs.Rgb(), 36, 716, new float[] { 1, .784f, 0 }
, 396, 788, new float[] { 0, 0, 1 }, new bool[] { true, true });
canvas.SetFillColor(new PatternColor(new PdfPattern.Shading(axial)));
canvas.Rectangle(30, 300, 400, 400).Fill();
canvas.Release();
Expand All @@ -350,8 +351,8 @@ public virtual void PatternColorColoredRadialPatternTest() {
PdfDocument document = new PdfDocument(writer);
PdfPage page = document.AddNewPage();
PdfCanvas canvas = new PdfCanvas(page);
PdfShading radial = new PdfShading.Radial(new PdfDeviceCs.Rgb(), 200, 700, 50, new float[] { 1, 0.968f, 0.58f
}, 300, 700, 100, new float[] { 0.968f, 0.541f, 0.42f });
AbstractPdfShading radial = new PdfRadialShading(new PdfDeviceCs.Rgb(), 200, 700, 50, new float[] { 1, 0.968f
, 0.58f }, 300, 700, 100, new float[] { 0.968f, 0.541f, 0.42f });
canvas.SetFillColor(new PatternColor(new PdfPattern.Shading(radial)));
canvas.Rectangle(30, 300, 400, 400).Fill();
canvas.Release();
Expand Down Expand Up @@ -500,10 +501,10 @@ private void SetColorSameColorSpacesTest(String pdfName, bool pattern) {
);
float[] colorValue1 = pattern ? null : new float[] { 1.0f, 0.6f, 0.7f };
float[] colorValue2 = pattern ? null : new float[] { 0.1f, 0.9f, 0.9f };
PdfPattern pattern1 = pattern ? new PdfPattern.Shading(new PdfShading.Axial(new PdfDeviceCs.Rgb(), 45, 750
, ColorConstants.PINK.GetColorValue(), 100, 760, ColorConstants.MAGENTA.GetColorValue())) : null;
PdfPattern pattern2 = pattern ? new PdfPattern.Shading(new PdfShading.Axial(new PdfDeviceCs.Rgb(), 45, 690
, ColorConstants.BLUE.GetColorValue(), 100, 710, ColorConstants.CYAN.GetColorValue())) : null;
PdfPattern pattern1 = pattern ? new PdfPattern.Shading(new PdfAxialShading(new PdfDeviceCs.Rgb(), 45, 750,
ColorConstants.PINK.GetColorValue(), 100, 760, ColorConstants.MAGENTA.GetColorValue())) : null;
PdfPattern pattern2 = pattern ? new PdfPattern.Shading(new PdfAxialShading(new PdfDeviceCs.Rgb(), 45, 690,
ColorConstants.BLUE.GetColorValue(), 100, 710, ColorConstants.CYAN.GetColorValue())) : null;
canvas.SetColor(space, colorValue1, pattern1, true);
canvas.SaveState();
canvas.BeginText().MoveText(50, 750).SetFontAndSize(PdfFontFactory.CreateFont(), 16).ShowText("pinkish").EndText
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ You should have received a copy of the GNU Affero General Public License
using iText.Commons.Utils;
using iText.Kernel.Pdf;
using iText.Kernel.Pdf.Canvas;
using iText.Kernel.Pdf.Colorspace.Shading;
using iText.Kernel.Pdf.Function;
using iText.Kernel.Utils;
using iText.Test;
Expand Down Expand Up @@ -61,7 +62,7 @@ public virtual void CreateAxialShadingWithStitchingFunctionTest() {
int y1 = 400;
PdfArray shadingVector = new PdfArray(new int[] { x0, y0, x1, y1 });
PdfType3Function stitchingFunction = CreateStitchingCmykShadingFunction();
PdfShading.Axial axialShading = new PdfShading.Axial(new PdfDeviceCs.Cmyk(), shadingVector, stitchingFunction
PdfAxialShading axialShading = new PdfAxialShading(new PdfDeviceCs.Cmyk(), shadingVector, stitchingFunction
);
pdfCanvas.PaintShading(axialShading);
pdfDocument.Close();
Expand All @@ -78,9 +79,9 @@ public virtual void ModifyAxialShadingTest() {
new StampingProperties().UseAppendMode());
PdfResources resources = pdfDocument.GetPage(1).GetResources();
foreach (PdfName resName in resources.GetResourceNames()) {
PdfShading shading = resources.GetShading(resName);
if (shading != null && shading.GetShadingType() == PdfShading.ShadingType.AXIAL) {
PdfShading.Axial axialShading = (PdfShading.Axial)shading;
AbstractPdfShading shading = resources.GetShading(resName);
if (shading != null && shading.GetShadingType() == ShadingType.AXIAL) {
PdfAxialShading axialShading = (PdfAxialShading)shading;
// "cut" shading and extend colors
axialShading.SetDomain(0.1f, 0.8f);
axialShading.SetExtend(true, true);
Expand All @@ -103,8 +104,8 @@ public virtual void CreateSimpleRadialShadingTest() {
int x1 = x0;
int y1 = y0;
int r1 = 50;
PdfShading.Radial radialShading = new PdfShading.Radial(new PdfDeviceCs.Gray(), x0, y0, r0, new float[] {
0.9f }, x1, y1, r1, new float[] { 0.2f }, new bool[] { false, false });
PdfRadialShading radialShading = new PdfRadialShading(new PdfDeviceCs.Gray(), x0, y0, r0, new float[] { 0.9f
}, x1, y1, r1, new float[] { 0.2f }, new bool[] { false, false });
pdfCanvas.PaintShading(radialShading);
pdfDocument.Close();
AssertShadingDictionaryResult(outName, cmpName, "Sh1");
Expand All @@ -125,7 +126,7 @@ public virtual void CreateRadialShadingWithStitchingFunctionTest() {
int r1 = 50;
PdfArray shadingVector = new PdfArray(new int[] { x0, y0, r0, x1, y1, r1 });
PdfType3Function stitchingFunction = CreateStitchingCmykShadingFunction();
PdfShading.Radial radialShading = new PdfShading.Radial(new PdfDeviceCs.Cmyk(), shadingVector, stitchingFunction
PdfRadialShading radialShading = new PdfRadialShading(new PdfDeviceCs.Cmyk(), shadingVector, stitchingFunction
);
pdfCanvas.PaintShading(radialShading);
pdfDocument.Close();
Expand All @@ -142,9 +143,9 @@ public virtual void ModifyRadialShadingTest() {
new StampingProperties().UseAppendMode());
PdfResources resources = pdfDocument.GetPage(1).GetResources();
foreach (PdfName resName in resources.GetResourceNames()) {
PdfShading shading = resources.GetShading(resName);
if (shading != null && shading.GetShadingType() == PdfShading.ShadingType.RADIAL) {
PdfShading.Radial radialShading = (PdfShading.Radial)shading;
AbstractPdfShading shading = resources.GetShading(resName);
if (shading != null && shading.GetShadingType() == ShadingType.RADIAL) {
PdfRadialShading radialShading = (PdfRadialShading)shading;
// "cut" shading and extend colors
radialShading.SetDomain(0.1f, 0.8f);
radialShading.SetExtend(true, true);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
This file is part of the iText (R) project.
Copyright (c) 1998-2024 Apryse Group NV
Authors: Apryse Software.
This program is offered under a commercial and under the AGPL license.
For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below.
AGPL licensing:
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
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 System;
using iText.Kernel.Pdf;
using iText.Kernel.Pdf.Canvas;
using iText.Kernel.Pdf.Colorspace.Shading;
using iText.Test;

namespace iText.Kernel.Pdf.Colorspace {
[NUnit.Framework.Category("IntegrationTest")]
public class PdfShadingDocumentTest : ExtendedITextTest {
public static readonly String DESTINATION_FOLDER = NUnit.Framework.TestContext.CurrentContext.TestDirectory
+ "/test/itext/kernel/pdf/colorspace/PdfShadingDocumentTest/";

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

[NUnit.Framework.Test]
public virtual void AxialDocumentTest() {
String dest = DESTINATION_FOLDER + "axialDoc.pdf";
using (PdfDocument pdfDocument = new PdfDocument(new PdfWriter(dest))) {
PdfPage pdfPage = pdfDocument.AddNewPage();
PdfCanvas canvas = new PdfCanvas(pdfPage);
int x = 36;
int y = 400;
int side = 500;
float[] green = new float[] { 0, 255, 0 };
float[] blue = new float[] { 0, 0, 255 };
PdfAxialShading axial = new PdfAxialShading(new PdfDeviceCs.Rgb(), x, y, green, x + side, y, blue);
PdfPattern.Shading shading = new PdfPattern.Shading(axial);
canvas.SetFillColorShading(shading);
canvas.MoveTo(x, y);
canvas.LineTo(x + side, y);
canvas.LineTo(x + (side / 2), (float)(y + (side * Math.Sin(Math.PI / 3))));
canvas.ClosePathFillStroke();
PdfDictionary pdfObject = pdfDocument.GetPage(1).GetResources().GetPdfObject();
NUnit.Framework.Assert.IsTrue(pdfObject.ContainsKey(PdfName.Pattern));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ You should have received a copy of the GNU Affero General Public License
using iText.Commons.Utils;
using iText.Kernel.Exceptions;
using iText.Kernel.Pdf;
using iText.Kernel.Pdf.Colorspace.Shading;
using iText.Test;

namespace iText.Kernel.Pdf.Colorspace {
Expand All @@ -41,8 +42,8 @@ public virtual void AllAboveType3FromDictionaryShouldFailTest(String shadingName
PdfDictionary dict = new PdfDictionary();
dict.Put(PdfName.ShadingType, new PdfNumber(shadingType));
dict.Put(PdfName.ColorSpace, PdfName.DeviceRGB);
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfException), () => PdfShading.MakeShading(dict), "Creating "
+ shadingName + " should throw PdfException.");
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfException), () => AbstractPdfShading.MakeShading(dict
), "Creating " + shadingName + " should throw PdfException.");
NUnit.Framework.Assert.AreEqual(KernelExceptionMessageConstant.UNEXPECTED_SHADING_TYPE, e.Message);
}
}
Expand Down
Loading

0 comments on commit 688ef6b

Please sign in to comment.