diff --git a/itext.tests/itext.kernel.tests/itext/kernel/pdf/canvas/PdfCanvasColorTest.cs b/itext.tests/itext.kernel.tests/itext/kernel/pdf/canvas/PdfCanvasColorTest.cs index 12a466409f..b0950e1d10 100644 --- a/itext.tests/itext.kernel.tests/itext/kernel/pdf/canvas/PdfCanvasColorTest.cs +++ b/itext.tests/itext.kernel.tests/itext/kernel/pdf/canvas/PdfCanvasColorTest.cs @@ -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; @@ -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(); @@ -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(); @@ -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 diff --git a/itext.tests/itext.kernel.tests/itext/kernel/pdf/colorspace/CreateShadingTest.cs b/itext.tests/itext.kernel.tests/itext/kernel/pdf/colorspace/CreateShadingTest.cs index f94e694553..1b88bc04be 100644 --- a/itext.tests/itext.kernel.tests/itext/kernel/pdf/colorspace/CreateShadingTest.cs +++ b/itext.tests/itext.kernel.tests/itext/kernel/pdf/colorspace/CreateShadingTest.cs @@ -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; @@ -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(); @@ -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); @@ -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"); @@ -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(); @@ -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); diff --git a/itext.tests/itext.kernel.tests/itext/kernel/pdf/colorspace/PdfShadingDocumentTest.cs b/itext.tests/itext.kernel.tests/itext/kernel/pdf/colorspace/PdfShadingDocumentTest.cs new file mode 100644 index 0000000000..ad9677f1c0 --- /dev/null +++ b/itext.tests/itext.kernel.tests/itext/kernel/pdf/colorspace/PdfShadingDocumentTest.cs @@ -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 . +*/ +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)); + } + } + } +} diff --git a/itext.tests/itext.kernel.tests/itext/kernel/pdf/colorspace/PdfShadingParameterizedTest.cs b/itext.tests/itext.kernel.tests/itext/kernel/pdf/colorspace/PdfShadingParameterizedTest.cs index ad2cd67377..78861365fd 100644 --- a/itext.tests/itext.kernel.tests/itext/kernel/pdf/colorspace/PdfShadingParameterizedTest.cs +++ b/itext.tests/itext.kernel.tests/itext/kernel/pdf/colorspace/PdfShadingParameterizedTest.cs @@ -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 { @@ -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); } } diff --git a/itext.tests/itext.kernel.tests/itext/kernel/pdf/colorspace/PdfShadingTest.cs b/itext.tests/itext.kernel.tests/itext/kernel/pdf/colorspace/PdfShadingTest.cs index fed9ffc8d5..13a23f698f 100644 --- a/itext.tests/itext.kernel.tests/itext/kernel/pdf/colorspace/PdfShadingTest.cs +++ b/itext.tests/itext.kernel.tests/itext/kernel/pdf/colorspace/PdfShadingTest.cs @@ -23,6 +23,7 @@ You should have received a copy of the GNU Affero General Public License using System; using iText.Kernel.Exceptions; using iText.Kernel.Pdf; +using iText.Kernel.Pdf.Colorspace.Shading; using iText.Kernel.Pdf.Function; using iText.Test; @@ -33,8 +34,8 @@ public class PdfShadingTest : ExtendedITextTest { public virtual void AxialShadingConstructorNullExtendArgumentTest() { bool[] extendArray = null; PdfDeviceCs.Rgb color = new PdfDeviceCs.Rgb(); - Exception e = NUnit.Framework.Assert.Catch(typeof(ArgumentException), () => new PdfShading.Axial(color, 0f - , 0f, new float[] { 0f, 0f, 0f }, 0.5f, 0.5f, new float[] { 0.5f, 0.5f, 0.5f }, extendArray)); + Exception e = NUnit.Framework.Assert.Catch(typeof(ArgumentException), () => new PdfAxialShading(color, 0f, + 0f, new float[] { 0f, 0f, 0f }, 0.5f, 0.5f, new float[] { 0.5f, 0.5f, 0.5f }, extendArray)); NUnit.Framework.Assert.AreEqual("extend", e.Message); } @@ -42,8 +43,8 @@ public virtual void AxialShadingConstructorNullExtendArgumentTest() { public virtual void AxialShadingConstructorInvalidExtendArgumentTest() { bool[] extendArray = new bool[] { true }; PdfDeviceCs.Rgb color = new PdfDeviceCs.Rgb(); - Exception e = NUnit.Framework.Assert.Catch(typeof(ArgumentException), () => new PdfShading.Axial(color, 0f - , 0f, new float[] { 0f, 0f, 0f }, 0.5f, 0.5f, new float[] { 0.5f, 0.5f, 0.5f }, extendArray)); + Exception e = NUnit.Framework.Assert.Catch(typeof(ArgumentException), () => new PdfAxialShading(color, 0f, + 0f, new float[] { 0f, 0f, 0f }, 0.5f, 0.5f, new float[] { 0.5f, 0.5f, 0.5f }, extendArray)); NUnit.Framework.Assert.AreEqual("extend", e.Message); } @@ -51,7 +52,7 @@ public virtual void AxialShadingConstructorInvalidExtendArgumentTest() { public virtual void RadialShadingConstructorNullExtendArgumentTest() { bool[] extendArray = null; PdfDeviceCs.Rgb color = new PdfDeviceCs.Rgb(); - Exception e = NUnit.Framework.Assert.Catch(typeof(ArgumentException), () => new PdfShading.Radial(color, 0f + Exception e = NUnit.Framework.Assert.Catch(typeof(ArgumentException), () => new PdfRadialShading(color, 0f , 0f, 0f, new float[] { 0f, 0f, 0f }, 0.5f, 0.5f, 10f, new float[] { 0.5f, 0.5f, 0.5f }, extendArray)); NUnit.Framework.Assert.AreEqual("extend", e.Message); } @@ -60,7 +61,7 @@ public virtual void RadialShadingConstructorNullExtendArgumentTest() { public virtual void RadialShadingConstructorInvalidExtendArgumentTest() { bool[] extendArray = new bool[] { true, false, false }; PdfDeviceCs.Rgb color = new PdfDeviceCs.Rgb(); - Exception e = NUnit.Framework.Assert.Catch(typeof(ArgumentException), () => new PdfShading.Radial(color, 0f + Exception e = NUnit.Framework.Assert.Catch(typeof(ArgumentException), () => new PdfRadialShading(color, 0f , 0f, 0f, new float[] { 0f, 0f, 0f }, 0.5f, 0.5f, 10f, new float[] { 0.5f, 0.5f, 0.5f }, extendArray)); NUnit.Framework.Assert.AreEqual("extend", e.Message); } @@ -70,13 +71,13 @@ public virtual void AxialShadingGettersTest() { float[] coordsArray = new float[] { 0f, 0f, 0.5f, 0.5f }; float[] domainArray = new float[] { 0f, 0.8f }; bool[] extendArray = new bool[] { true, false }; - PdfDictionary axialShadingDictionary = InitShadingDictionary(coordsArray, domainArray, extendArray, PdfShading.ShadingType + PdfDictionary axialShadingDictionary = InitShadingDictionary(coordsArray, domainArray, extendArray, ShadingType .AXIAL); - PdfShading.Axial axial = new PdfShading.Axial(axialShadingDictionary); + PdfAxialShading axial = new PdfAxialShading(axialShadingDictionary); iText.Test.TestUtil.AreEqual(coordsArray, axial.GetCoords().ToFloatArray(), 0f); iText.Test.TestUtil.AreEqual(domainArray, axial.GetDomain().ToFloatArray(), 0f); NUnit.Framework.Assert.AreEqual(extendArray, axial.GetExtend().ToBooleanArray()); - NUnit.Framework.Assert.AreEqual(PdfShading.ShadingType.AXIAL, axial.GetShadingType()); + NUnit.Framework.Assert.AreEqual(ShadingType.AXIAL, axial.GetShadingType()); NUnit.Framework.Assert.AreEqual(PdfName.DeviceRGB, axial.GetColorSpace()); } @@ -85,9 +86,9 @@ public virtual void SetFunctionsTest() { float[] coordsArray = new float[] { 0f, 0f, 0.5f, 0.5f }; float[] domainArray = new float[] { 0f, 0.8f }; bool[] extendArray = new bool[] { true, false }; - PdfDictionary axialShadingDictionary = InitShadingDictionary(coordsArray, domainArray, extendArray, PdfShading.ShadingType + PdfDictionary axialShadingDictionary = InitShadingDictionary(coordsArray, domainArray, extendArray, ShadingType .AXIAL); - PdfShading.Axial axial = new PdfShading.Axial(axialShadingDictionary); + PdfAxialShading axial = new PdfAxialShading(axialShadingDictionary); NUnit.Framework.Assert.IsTrue(axial.GetFunction() is PdfDictionary); byte[] ps = "{2 copy sin abs sin abs 3 index 10 mul sin 1 sub abs}".GetBytes(iText.Commons.Utils.EncodingUtil.ISO_8859_1 ); @@ -106,13 +107,13 @@ public virtual void AxialShadingViaPdfObjectTest() { float[] coordsArray = new float[] { 0f, 0f, 0.5f, 0.5f }; float[] domainArray = new float[] { 0f, 0.8f }; bool[] extendArray = new bool[] { true, false }; - PdfDictionary axialShadingDictionary = InitShadingDictionary(coordsArray, domainArray, extendArray, PdfShading.ShadingType + PdfDictionary axialShadingDictionary = InitShadingDictionary(coordsArray, domainArray, extendArray, ShadingType .AXIAL); - PdfShading.Axial axial = (PdfShading.Axial)PdfShading.MakeShading(axialShadingDictionary); + PdfAxialShading axial = (PdfAxialShading)AbstractPdfShading.MakeShading(axialShadingDictionary); iText.Test.TestUtil.AreEqual(coordsArray, axial.GetCoords().ToFloatArray(), 0f); iText.Test.TestUtil.AreEqual(domainArray, axial.GetDomain().ToFloatArray(), 0f); NUnit.Framework.Assert.AreEqual(extendArray, axial.GetExtend().ToBooleanArray()); - NUnit.Framework.Assert.AreEqual(PdfShading.ShadingType.AXIAL, axial.GetShadingType()); + NUnit.Framework.Assert.AreEqual(ShadingType.AXIAL, axial.GetShadingType()); } [NUnit.Framework.Test] @@ -120,13 +121,12 @@ public virtual void AxialShadingGettersWithDomainExtendDefaultValuesTest() { float[] coordsArray = new float[] { 0f, 0f, 0.5f, 0.5f }; float[] defaultDomainArray = new float[] { 0f, 1f }; bool[] defaultExtendArray = new bool[] { false, false }; - PdfDictionary axialShadingDictionary = InitShadingDictionary(coordsArray, null, null, PdfShading.ShadingType - .AXIAL); - PdfShading.Axial axial = new PdfShading.Axial(axialShadingDictionary); + PdfDictionary axialShadingDictionary = InitShadingDictionary(coordsArray, null, null, ShadingType.AXIAL); + PdfAxialShading axial = new PdfAxialShading(axialShadingDictionary); iText.Test.TestUtil.AreEqual(coordsArray, axial.GetCoords().ToFloatArray(), 0f); iText.Test.TestUtil.AreEqual(defaultDomainArray, axial.GetDomain().ToFloatArray(), 0f); NUnit.Framework.Assert.AreEqual(defaultExtendArray, axial.GetExtend().ToBooleanArray()); - NUnit.Framework.Assert.AreEqual(PdfShading.ShadingType.AXIAL, axial.GetShadingType()); + NUnit.Framework.Assert.AreEqual(ShadingType.AXIAL, axial.GetShadingType()); } [NUnit.Framework.Test] @@ -134,13 +134,13 @@ public virtual void RadialShadingGettersTest() { float[] coordsArray = new float[] { 0f, 0f, 0f, 0.5f, 0.5f, 10f }; float[] domainArray = new float[] { 0f, 0.8f }; bool[] extendArray = new bool[] { true, false }; - PdfDictionary radialShadingDictionary = InitShadingDictionary(coordsArray, domainArray, extendArray, PdfShading.ShadingType + PdfDictionary radialShadingDictionary = InitShadingDictionary(coordsArray, domainArray, extendArray, ShadingType .RADIAL); - PdfShading.Radial radial = new PdfShading.Radial(radialShadingDictionary); + PdfRadialShading radial = new PdfRadialShading(radialShadingDictionary); iText.Test.TestUtil.AreEqual(coordsArray, radial.GetCoords().ToFloatArray(), 0f); iText.Test.TestUtil.AreEqual(domainArray, radial.GetDomain().ToFloatArray(), 0f); NUnit.Framework.Assert.AreEqual(extendArray, radial.GetExtend().ToBooleanArray()); - NUnit.Framework.Assert.AreEqual(PdfShading.ShadingType.RADIAL, radial.GetShadingType()); + NUnit.Framework.Assert.AreEqual(ShadingType.RADIAL, radial.GetShadingType()); } [NUnit.Framework.Test] @@ -148,13 +148,13 @@ public virtual void RadialShadingViaMakeShadingTest() { float[] coordsArray = new float[] { 0f, 0f, 0f, 0.5f, 0.5f, 10f }; float[] domainArray = new float[] { 0f, 0.8f }; bool[] extendArray = new bool[] { true, false }; - PdfDictionary radialShadingDictionary = InitShadingDictionary(coordsArray, domainArray, extendArray, PdfShading.ShadingType + PdfDictionary radialShadingDictionary = InitShadingDictionary(coordsArray, domainArray, extendArray, ShadingType .RADIAL); - PdfShading.Radial radial = (PdfShading.Radial)PdfShading.MakeShading(radialShadingDictionary); + PdfRadialShading radial = (PdfRadialShading)AbstractPdfShading.MakeShading(radialShadingDictionary); iText.Test.TestUtil.AreEqual(coordsArray, radial.GetCoords().ToFloatArray(), 0f); iText.Test.TestUtil.AreEqual(domainArray, radial.GetDomain().ToFloatArray(), 0f); NUnit.Framework.Assert.AreEqual(extendArray, radial.GetExtend().ToBooleanArray()); - NUnit.Framework.Assert.AreEqual(PdfShading.ShadingType.RADIAL, radial.GetShadingType()); + NUnit.Framework.Assert.AreEqual(ShadingType.RADIAL, radial.GetShadingType()); } [NUnit.Framework.Test] @@ -162,20 +162,20 @@ public virtual void RadialShadingGettersWithDomainExtendDefaultValuesTest() { float[] coordsArray = new float[] { 0f, 0f, 0f, 0.5f, 0.5f, 10f }; float[] defaultDomainArray = new float[] { 0f, 1f }; bool[] defaultExtendArray = new bool[] { false, false }; - PdfDictionary radialShadingDictionary = InitShadingDictionary(coordsArray, null, null, PdfShading.ShadingType - .RADIAL); - PdfShading.Radial radial = new PdfShading.Radial(radialShadingDictionary); + PdfDictionary radialShadingDictionary = InitShadingDictionary(coordsArray, null, null, ShadingType.RADIAL); + PdfRadialShading radial = new PdfRadialShading(radialShadingDictionary); iText.Test.TestUtil.AreEqual(coordsArray, radial.GetCoords().ToFloatArray(), 0f); iText.Test.TestUtil.AreEqual(defaultDomainArray, radial.GetDomain().ToFloatArray(), 0f); NUnit.Framework.Assert.AreEqual(defaultExtendArray, radial.GetExtend().ToBooleanArray()); - NUnit.Framework.Assert.AreEqual(PdfShading.ShadingType.RADIAL, radial.GetShadingType()); + NUnit.Framework.Assert.AreEqual(ShadingType.RADIAL, radial.GetShadingType()); } [NUnit.Framework.Test] public virtual void MakeShadingShouldFailOnMissingShadeType() { PdfDictionary shade = new PdfDictionary(); shade.Put(PdfName.ColorSpace, new PdfArray()); - Exception error = NUnit.Framework.Assert.Catch(typeof(PdfException), () => PdfShading.MakeShading(shade)); + Exception error = NUnit.Framework.Assert.Catch(typeof(PdfException), () => AbstractPdfShading.MakeShading( + shade)); NUnit.Framework.Assert.AreEqual(KernelExceptionMessageConstant.SHADING_TYPE_NOT_FOUND, error.Message); } @@ -183,7 +183,8 @@ public virtual void MakeShadingShouldFailOnMissingShadeType() { public virtual void MakeShadingShouldFailOnMissingColorSpace() { PdfDictionary shade = new PdfDictionary(); shade.Put(PdfName.ShadingType, new PdfArray()); - Exception error = NUnit.Framework.Assert.Catch(typeof(PdfException), () => PdfShading.MakeShading(shade)); + Exception error = NUnit.Framework.Assert.Catch(typeof(PdfException), () => AbstractPdfShading.MakeShading( + shade)); NUnit.Framework.Assert.AreEqual(KernelExceptionMessageConstant.COLOR_SPACE_NOT_FOUND, error.Message); } @@ -194,8 +195,8 @@ public virtual void UsingPatternColorSpaceThrowsException() { IPdfFunction function = new PdfType4Function(new float[] { 0, 1000, 0, 1000 }, new float[] { 0, 1, 0, 1, 0 , 1 }, ps); PdfSpecialCs.Pattern colorSpace = new PdfSpecialCs.Pattern(); - Exception ex = NUnit.Framework.Assert.Catch(typeof(ArgumentException), () => new PdfShading.FunctionBased( - colorSpace, function)); + Exception ex = NUnit.Framework.Assert.Catch(typeof(ArgumentException), () => new PdfFunctionBasedShading(colorSpace + , function)); NUnit.Framework.Assert.AreEqual("colorSpace", ex.Message); } @@ -206,7 +207,7 @@ public virtual void MakeShadingFunctionBased1Test() { float[] domain = new float[] { 0, 1000, 0, 1000 }; float[] range = new float[] { 0, 1, 0, 1, 0, 1 }; IPdfFunction function = new PdfType4Function(domain, range, ps); - PdfShading.FunctionBased shade = new PdfShading.FunctionBased(new PdfDeviceCs.Rgb(), function); + PdfFunctionBasedShading shade = new PdfFunctionBasedShading(new PdfDeviceCs.Rgb(), function); PdfDictionary @object = shade.GetPdfObject(); NUnit.Framework.Assert.AreEqual(1, @object.GetAsInt(PdfName.ShadingType).Value); NUnit.Framework.Assert.AreEqual(PdfName.DeviceRGB, @object.GetAsName(PdfName.ColorSpace)); @@ -234,7 +235,7 @@ public virtual void MakeShadingFunctionBased2Test() { shadingDict.Put(PdfName.Function, stream); stream.SetData(ps); shadingDict.Put(PdfName.Function, stream); - PdfShading shade = PdfShading.MakeShading(shadingDict); + AbstractPdfShading shade = AbstractPdfShading.MakeShading(shadingDict); PdfDictionary @object = shade.GetPdfObject(); NUnit.Framework.Assert.AreEqual(1, @object.GetAsInt(PdfName.ShadingType).Value); NUnit.Framework.Assert.AreEqual(PdfName.DeviceRGB, @object.GetAsName(PdfName.ColorSpace)); @@ -251,7 +252,7 @@ public virtual void MakeShadingFunctionBased2Test() { public virtual void MakeShadingWithInvalidShadeType() { float[] coordsArray = new float[] { 0f, 0f, 0f, 0.5f, 0.5f, 10f }; PdfDictionary radialShadingDictionary = InitShadingDictionary(coordsArray, null, null, 21); - Exception e = NUnit.Framework.Assert.Catch(typeof(PdfException), () => PdfShading.MakeShading(radialShadingDictionary + Exception e = NUnit.Framework.Assert.Catch(typeof(PdfException), () => AbstractPdfShading.MakeShading(radialShadingDictionary )); NUnit.Framework.Assert.AreEqual(KernelExceptionMessageConstant.UNEXPECTED_SHADING_TYPE, e.Message); } @@ -273,7 +274,7 @@ public virtual void MakeFreeFormGouraudShadedTriangleMeshTest() { stream.Put(PdfName.Decode, new PdfArray(new float[] { x, x + side, y, y + (int)(side * Math.Sin(Math.PI / 3)), 0, 1, 0, 1, 0, 1 })); stream.Put(PdfName.Matrix, new PdfArray(new float[] { 1, 0, 0, -1, 0, 0 })); - PdfShading.FreeFormGouraudShadedTriangleMesh shade = (PdfShading.FreeFormGouraudShadedTriangleMesh)PdfShading + PdfFreeFormGouraudShadedTriangleShading shade = (PdfFreeFormGouraudShadedTriangleShading)AbstractPdfShading .MakeShading(stream); NUnit.Framework.Assert.AreEqual(PdfName.DeviceRGB, shade.GetColorSpace()); NUnit.Framework.Assert.AreEqual(4, shade.GetShadingType()); @@ -300,7 +301,7 @@ public virtual void MakeLatticeFormGouraudShadedTriangleMeshTest() { stream.Put(PdfName.Decode, new PdfArray(new float[] { x, x + side, y, y + (int)(side * Math.Sin(Math.PI / 3)), 0, 1, 0, 1, 0, 1 })); stream.Put(PdfName.Matrix, new PdfArray(new float[] { 1, 0, 0, -1, 0, 0 })); - PdfShading.LatticeFormGouraudShadedTriangleMesh shade = (PdfShading.LatticeFormGouraudShadedTriangleMesh)PdfShading + PdfLatticeFormGouraudShadedTriangleShading shade = (PdfLatticeFormGouraudShadedTriangleShading)AbstractPdfShading .MakeShading(stream); NUnit.Framework.Assert.AreEqual(PdfName.DeviceRGB, shade.GetColorSpace()); NUnit.Framework.Assert.AreEqual(5, shade.GetShadingType()); @@ -385,7 +386,7 @@ public virtual void CoonsPatchMeshGradientTest() { stream.Put(PdfName.Decode, new PdfArray(new float[] { x, x + side, y, y + (int)(side * Math.Sin(Math.PI / 3)), 0, 1, 0, 1, 0, 1 })); stream.Put(PdfName.Matrix, new PdfArray(new float[] { 1, 0, 0, -1, 0, 0 })); - PdfShading.CoonsPatchMesh shade = (PdfShading.CoonsPatchMesh)PdfShading.MakeShading(stream); + PdfCoonsPatchShading shade = (PdfCoonsPatchShading)AbstractPdfShading.MakeShading(stream); NUnit.Framework.Assert.AreEqual(PdfName.DeviceRGB, shade.GetColorSpace()); NUnit.Framework.Assert.AreEqual(6, shade.GetShadingType()); NUnit.Framework.Assert.AreEqual(32, shade.GetBitsPerCoordinate()); @@ -485,8 +486,7 @@ public virtual void TensorProductPatchMeshShadingTest() { stream.Put(PdfName.Decode, new PdfArray(new float[] { x, x + side, y, y + (int)(side * Math.Sin(Math.PI / 3)), 0, 1, 0, 1, 0, 1 })); stream.Put(PdfName.Matrix, new PdfArray(new float[] { -1, 0, 0, 1, 0, 0 })); - PdfShading.TensorProductPatchMesh shade = (PdfShading.TensorProductPatchMesh)PdfShading.MakeShading(stream - ); + PdfTensorProductPatchShading shade = (PdfTensorProductPatchShading)AbstractPdfShading.MakeShading(stream); NUnit.Framework.Assert.AreEqual(PdfName.DeviceRGB, shade.GetColorSpace()); NUnit.Framework.Assert.AreEqual(7, shade.GetShadingType()); NUnit.Framework.Assert.AreEqual(32, shade.GetBitsPerCoordinate()); @@ -500,10 +500,133 @@ public virtual void InvalidShadingTypeShouldFailTest() { PdfDictionary dict = new PdfDictionary(); dict.Put(PdfName.ShadingType, new PdfNumber(8)); dict.Put(PdfName.ColorSpace, PdfName.DeviceRGB); - Exception e = NUnit.Framework.Assert.Catch(typeof(PdfException), () => PdfShading.MakeShading(dict)); + Exception e = NUnit.Framework.Assert.Catch(typeof(PdfException), () => AbstractPdfShading.MakeShading(dict + )); NUnit.Framework.Assert.AreEqual(KernelExceptionMessageConstant.UNEXPECTED_SHADING_TYPE, e.Message); } + [NUnit.Framework.Test] + public virtual void BasicCoonsPathMeshTest() { + int x = 36; + int y = 400; + int side = 500; + PdfArray decode = new PdfArray(new float[] { x, x + side, y, y + (int)(side * Math.Sin(Math.PI / 3)), 0, 1 + , 0, 1, 0, 1 }); + PdfColorSpace cs = PdfColorSpace.MakeColorSpace(PdfName.DeviceRGB); + PdfCoonsPatchShading coonsPatchMesh = new PdfCoonsPatchShading(cs, 32, 16, 8, decode); + NUnit.Framework.Assert.AreEqual(PdfName.DeviceRGB, coonsPatchMesh.GetColorSpace()); + NUnit.Framework.Assert.AreEqual(6, coonsPatchMesh.GetShadingType()); + NUnit.Framework.Assert.AreEqual(32, coonsPatchMesh.GetBitsPerCoordinate()); + NUnit.Framework.Assert.AreEqual(16, coonsPatchMesh.GetBitsPerComponent()); + NUnit.Framework.Assert.AreEqual(8, coonsPatchMesh.GetBitsPerFlag()); + NUnit.Framework.Assert.AreEqual(y, coonsPatchMesh.GetDecode().GetAsNumber(2).IntValue()); + } + + [NUnit.Framework.Test] + public virtual void BasicFreeFormGouraudShadedTriangleMeshTest() { + int x = 36; + int y = 400; + int side = 500; + PdfArray pdfArray = new PdfArray(new float[] { x, x + side, y, y + (int)(side * Math.Sin(Math.PI / 3)), 0, + 1, 0, 1, 0, 1 }); + PdfColorSpace cs = PdfColorSpace.MakeColorSpace(PdfName.DeviceRGB); + PdfFreeFormGouraudShadedTriangleShading shade = new PdfFreeFormGouraudShadedTriangleShading(cs, 32, 8, 8, + pdfArray); + NUnit.Framework.Assert.AreEqual(PdfName.DeviceRGB, shade.GetColorSpace()); + NUnit.Framework.Assert.AreEqual(4, shade.GetShadingType()); + NUnit.Framework.Assert.AreEqual(32, shade.GetBitsPerCoordinate()); + NUnit.Framework.Assert.AreEqual(8, shade.GetBitsPerComponent()); + NUnit.Framework.Assert.AreEqual(8, shade.GetBitsPerFlag()); + NUnit.Framework.Assert.AreEqual(y, shade.GetDecode().GetAsNumber(2).IntValue()); + } + + [NUnit.Framework.Test] + public virtual void BasicTensorProductPatchMeshTest() { + int x = 36; + int y = 400; + int side = 500; + PdfArray pdfArray = new PdfArray(new float[] { x, x + side, y, y + (int)(side * Math.Sin(Math.PI / 3)), 0, + 1, 0, 1, 0, 1 }); + PdfColorSpace cs = PdfColorSpace.MakeColorSpace(PdfName.DeviceRGB); + PdfTensorProductPatchShading shade = new PdfTensorProductPatchShading(cs, 32, 8, 8, pdfArray); + NUnit.Framework.Assert.AreEqual(PdfName.DeviceRGB, shade.GetColorSpace()); + NUnit.Framework.Assert.AreEqual(7, shade.GetShadingType()); + NUnit.Framework.Assert.AreEqual(32, shade.GetBitsPerCoordinate()); + NUnit.Framework.Assert.AreEqual(8, shade.GetBitsPerComponent()); + NUnit.Framework.Assert.AreEqual(8, shade.GetBitsPerFlag()); + NUnit.Framework.Assert.AreEqual(y, shade.GetDecode().GetAsNumber(2).IntValue()); + } + + [NUnit.Framework.Test] + public virtual void BasicLatticeFormGouraudShadedTriangleMeshTest() { + int x = 36; + int y = 400; + int side = 500; + PdfArray pdfArray = new PdfArray(new float[] { x, x + side, y, y + (int)(side * Math.Sin(Math.PI / 3)), 0, + 1, 0, 1, 0, 1 }); + PdfColorSpace cs = PdfColorSpace.MakeColorSpace(PdfName.DeviceRGB); + PdfLatticeFormGouraudShadedTriangleShading shade = new PdfLatticeFormGouraudShadedTriangleShading(cs, 32, + 8, 2, pdfArray); + NUnit.Framework.Assert.AreEqual(PdfName.DeviceRGB, shade.GetColorSpace()); + NUnit.Framework.Assert.AreEqual(5, shade.GetShadingType()); + NUnit.Framework.Assert.AreEqual(32, shade.GetBitsPerCoordinate()); + NUnit.Framework.Assert.AreEqual(8, shade.GetBitsPerComponent()); + NUnit.Framework.Assert.AreEqual(2, shade.GetVerticesPerRow()); + NUnit.Framework.Assert.AreEqual(y, shade.GetDecode().GetAsNumber(2).IntValue()); + } + + [NUnit.Framework.Test] + public virtual void BasicFunctionBasedShadingTest() { + byte[] ps = "{2 copy sin abs sin abs 3 index 10 mul sin 1 sub abs}".GetBytes(iText.Commons.Utils.EncodingUtil.ISO_8859_1 + ); + float[] domain = new float[] { 0, 1000, 0, 1000 }; + float[] range = new float[] { 0, 1, 0, 1, 0, 1 }; + float[] transformMatrix = new float[] { 1, 0, 0, 1, 0, 0 }; + IPdfFunction function = new PdfType4Function(domain, range, ps); + PdfColorSpace cs = PdfColorSpace.MakeColorSpace(PdfName.DeviceRGB); + PdfFunctionBasedShading shade = new PdfFunctionBasedShading(cs, function); + shade.SetDomain(1, 4, 1, 4); + shade.SetMatrix(transformMatrix); + NUnit.Framework.Assert.AreEqual(PdfName.DeviceRGB, shade.GetColorSpace()); + NUnit.Framework.Assert.AreEqual(1, shade.GetShadingType()); + NUnit.Framework.Assert.AreEqual(transformMatrix, shade.GetMatrix().ToFloatArray()); + NUnit.Framework.Assert.AreEqual(new float[] { 1, 4, 1, 4 }, shade.GetDomain().ToFloatArray()); + } + + [NUnit.Framework.Test] + public virtual void ChangeFreeFormGouraudShadedTriangleMeshTest() { + int x = 36; + int y = 400; + int side = 500; + float[] decode = new float[] { x, x + side, y, y + (int)(side * Math.Sin(Math.PI / 3)), 0, 1, 0, 1, 0, 1 }; + PdfColorSpace cs = PdfColorSpace.MakeColorSpace(PdfName.DeviceRGB); + PdfFreeFormGouraudShadedTriangleShading shade = new PdfFreeFormGouraudShadedTriangleShading(cs, 16, 8, 8, + new PdfArray()); + shade.SetDecode(decode); + shade.SetBitsPerComponent(16); + shade.SetBitsPerCoordinate(32); + shade.SetBitsPerFlag(4); + NUnit.Framework.Assert.AreEqual(PdfName.DeviceRGB, shade.GetColorSpace()); + NUnit.Framework.Assert.AreEqual(4, shade.GetShadingType()); + NUnit.Framework.Assert.AreEqual(32, shade.GetBitsPerCoordinate()); + NUnit.Framework.Assert.AreEqual(16, shade.GetBitsPerComponent()); + NUnit.Framework.Assert.AreEqual(4, shade.GetBitsPerFlag()); + NUnit.Framework.Assert.AreEqual(y, shade.GetDecode().GetAsNumber(2).IntValue()); + } + + [NUnit.Framework.Test] + public virtual void SetDecodeCoonsPatchMeshTest() { + int x = 36; + int y = 400; + int side = 500; + PdfArray decode = new PdfArray(new float[] { x, x + side, y, y + (int)(side * Math.Sin(Math.PI / 3)), 0, 1 + , 0, 1, 0, 1 }); + PdfColorSpace cs = PdfColorSpace.MakeColorSpace(PdfName.DeviceRGB); + PdfCoonsPatchShading coonsPatchMesh = new PdfCoonsPatchShading(cs, 32, 16, 16, new PdfArray()); + coonsPatchMesh.SetDecode(decode); + NUnit.Framework.Assert.AreEqual(y, coonsPatchMesh.GetDecode().GetAsNumber(2).IntValue()); + } + private static PdfDictionary InitShadingDictionary(float[] coordsArray, float[] domainArray, bool[] extendArray , int radial2) { PdfDictionary axialShadingDictionary = new PdfDictionary(); diff --git a/itext.tests/itext.pdfua.tests/itext/pdfua/PdfUASignerTest.cs b/itext.tests/itext.pdfua.tests/itext/pdfua/PdfUASignerTest.cs index 5a3eec9911..1bbc456419 100644 --- a/itext.tests/itext.pdfua.tests/itext/pdfua/PdfUASignerTest.cs +++ b/itext.tests/itext.pdfua.tests/itext/pdfua/PdfUASignerTest.cs @@ -77,8 +77,7 @@ public virtual void InvisibleSignatureWithTU() { MemoryStream inPdf = GenerateSimplePdfUA1Document(); String outPdf = GenerateSignature(inPdf, "invisibleSignatureWithTU", (signer) => { signer.SetSignerProperties(new SignerProperties().SetFieldName("Signature12")); - SignatureFieldAppearance appearance = new SignatureFieldAppearance(signer.GetSignerProperties().GetFieldName - ()); + SignatureFieldAppearance appearance = new SignatureFieldAppearance(SignerProperties.IGNORED_ID); appearance.GetAccessibilityProperties().SetAlternateDescription("Some alternate description"); signer.GetSignerProperties().SetSignatureAppearance(appearance); } @@ -92,8 +91,7 @@ public virtual void VisibleSignatureWithTUButNotAFont() { MemoryStream inPdf = GenerateSimplePdfUA1Document(); String outPdf = GenerateSignature(inPdf, "visibleSignatureWithTUButNotAFont", (signer) => { signer.SetSignerProperties(new SignerProperties().SetFieldName("Signature12")); - SignatureFieldAppearance appearance = new SignatureFieldAppearance(signer.GetSignerProperties().GetFieldName - ()); + SignatureFieldAppearance appearance = new SignatureFieldAppearance(SignerProperties.IGNORED_ID); appearance.GetAccessibilityProperties().SetAlternateDescription("Some alternate description"); try { appearance.SetFont(PdfFontFactory.CreateFont(FONT)); @@ -116,8 +114,7 @@ public virtual void VisibleSignatureWithoutTUFont() { Exception e = NUnit.Framework.Assert.Catch(typeof(PdfUAConformanceException), () => { GenerateSignature(inPdf, "visibleSignatureWithoutTUFont", (signer) => { signer.SetSignerProperties(new SignerProperties().SetFieldName("Signature12")); - SignatureFieldAppearance appearance = new SignatureFieldAppearance(signer.GetSignerProperties().GetFieldName - ()); + SignatureFieldAppearance appearance = new SignatureFieldAppearance(SignerProperties.IGNORED_ID); appearance.SetContent(new SignedAppearanceText().SetLocationLine("Dummy location").SetReasonLine("Dummy reason" ).SetSignedBy("Dummy")); try { @@ -140,8 +137,7 @@ public virtual void VisibleSignatureWithNoFontSelected() { Exception e = NUnit.Framework.Assert.Catch(typeof(PdfUAConformanceException), () => { GenerateSignature(inPdf, "visibleSignatureWithNoFontSelected", (signer) => { signer.SetSignerProperties(new SignerProperties().SetFieldName("Signature12")); - SignatureFieldAppearance appearance = new SignatureFieldAppearance(signer.GetSignerProperties().GetFieldName - ()); + SignatureFieldAppearance appearance = new SignatureFieldAppearance(SignerProperties.IGNORED_ID); appearance.SetContent("Some signature content"); signer.GetSignerProperties().SetPageNumber(1).SetPageRect(new Rectangle(36, 648, 200, 100)); appearance.GetAccessibilityProperties().SetAlternateDescription("Some alternate description"); @@ -159,8 +155,7 @@ public virtual void NormalPdfSignerInvisibleSignatureWithTU() { MemoryStream inPdf = GenerateSimplePdfUA1Document(); String outPdf = GenerateSignatureNormal(inPdf, "normalPdfSignerInvisibleSignatureWithTU", (signer) => { signer.SetSignerProperties(new SignerProperties().SetFieldName("Signature12")); - SignatureFieldAppearance appearance = new SignatureFieldAppearance(signer.GetSignerProperties().GetFieldName - ()); + SignatureFieldAppearance appearance = new SignatureFieldAppearance(SignerProperties.IGNORED_ID); appearance.GetAccessibilityProperties().SetAlternateDescription("Some alternate description"); signer.GetSignerProperties().SetSignatureAppearance(appearance); } @@ -174,8 +169,7 @@ public virtual void NormalPdfSignerInvisibleSignatureWithoutTU() { MemoryStream inPdf = GenerateSimplePdfUA1Document(); String outPdf = GenerateSignatureNormal(inPdf, "normalPdfSignerInvisibleSignatureWithoutTU", (signer) => { signer.SetSignerProperties(new SignerProperties().SetFieldName("Signature12")); - SignatureFieldAppearance appearance = new SignatureFieldAppearance(signer.GetSignerProperties().GetFieldName - ()); + SignatureFieldAppearance appearance = new SignatureFieldAppearance(SignerProperties.IGNORED_ID); signer.GetSignerProperties().SetSignatureAppearance(appearance); } ); @@ -190,8 +184,7 @@ public virtual void NormalPdfSignerVisibleSignatureWithoutFont() { MemoryStream inPdf = GenerateSimplePdfUA1Document(); String outPdf = GenerateSignatureNormal(inPdf, "normalPdfSignerVisibleSignatureWithoutFont", (signer) => { signer.SetSignerProperties(new SignerProperties().SetFieldName("Signature12")); - SignatureFieldAppearance appearance = new SignatureFieldAppearance(signer.GetSignerProperties().GetFieldName - ()); + SignatureFieldAppearance appearance = new SignatureFieldAppearance(SignerProperties.IGNORED_ID); appearance.GetAccessibilityProperties().SetAlternateDescription("Some alternate description"); appearance.SetContent(new SignedAppearanceText().SetLocationLine("Dummy location").SetReasonLine("Dummy reason" ).SetSignedBy("Dummy")); @@ -209,8 +202,7 @@ public virtual void NormalPdfSignerVisibleSignatureWithFont() { PdfFont font = PdfFontFactory.CreateFont(FONT); String outPdf = GenerateSignatureNormal(inPdf, "normalPdfSignerVisibleSignatureWithFont", (signer) => { signer.SetSignerProperties(new SignerProperties().SetFieldName("Signature12")); - SignatureFieldAppearance appearance = new SignatureFieldAppearance(signer.GetSignerProperties().GetFieldName - ()); + SignatureFieldAppearance appearance = new SignatureFieldAppearance(SignerProperties.IGNORED_ID); appearance.GetAccessibilityProperties().SetAlternateDescription("Some alternate description"); appearance.SetContent(new SignedAppearanceText().SetLocationLine("Dummy location").SetReasonLine("Dummy reason" ).SetSignedBy("Dummy")); @@ -231,8 +223,7 @@ public virtual void NormalPdfSignerVisibleSignatureWithFontEmptyTU() { PdfFont font = PdfFontFactory.CreateFont(FONT); String outPdf = GenerateSignatureNormal(inPdf, "normalPdfSignerVisibleSignatureWithFontEmptyTU", (signer) => { signer.SetSignerProperties(new SignerProperties().SetFieldName("Signature12")); - SignatureFieldAppearance appearance = new SignatureFieldAppearance(signer.GetSignerProperties().GetFieldName - ()); + SignatureFieldAppearance appearance = new SignatureFieldAppearance(SignerProperties.IGNORED_ID); appearance.GetAccessibilityProperties().SetAlternateDescription(""); appearance.SetContent(new SignedAppearanceText().SetLocationLine("Dummy location").SetReasonLine("Dummy reason" ).SetSignedBy("Dummy")); @@ -253,8 +244,7 @@ public virtual void PdfSignerVisibleSignatureWithFontEmptyTU() { NUnit.Framework.Assert.Catch(typeof(PdfUAConformanceException), () => { GenerateSignature(inPdf, "pdfSignerVisibleSignatureWithFontEmptyTU", (signer) => { signer.SetSignerProperties(new SignerProperties().SetFieldName("Signature12")); - SignatureFieldAppearance appearance = new SignatureFieldAppearance(signer.GetSignerProperties().GetFieldName - ()); + SignatureFieldAppearance appearance = new SignatureFieldAppearance(SignerProperties.IGNORED_ID); appearance.GetAccessibilityProperties().SetAlternateDescription(""); appearance.SetContent(new SignedAppearanceText().SetLocationLine("Dummy location").SetReasonLine("Dummy reason" ).SetSignedBy("Dummy")); diff --git a/itext.tests/itext.sign.tests/itext/signatures/PdfSignerUnitTest.cs b/itext.tests/itext.sign.tests/itext/signatures/PdfSignerUnitTest.cs index 76e7545534..7791cb402b 100644 --- a/itext.tests/itext.sign.tests/itext/signatures/PdfSignerUnitTest.cs +++ b/itext.tests/itext.sign.tests/itext/signatures/PdfSignerUnitTest.cs @@ -228,7 +228,7 @@ public virtual void SetAlternativeName() { SignerProperties signerProperties = new SignerProperties().SetFieldName("Signature1").SetPageNumber(1).SetPageRect (new Rectangle(100, 100, 10, 10)); signer.SetSignerProperties(signerProperties); - SignatureFieldAppearance appearance = new SignatureFieldAppearance(signerProperties.GetFieldName()); + SignatureFieldAppearance appearance = new SignatureFieldAppearance(SignerProperties.IGNORED_ID); appearance.SetContent("Some text"); appearance.GetAccessibilityProperties().SetAlternateDescription("Alternate description"); signerProperties.SetSignatureAppearance(appearance); diff --git a/itext.tests/itext.sign.tests/itext/signatures/sign/AnnotationsSigningTest.cs b/itext.tests/itext.sign.tests/itext/signatures/sign/AnnotationsSigningTest.cs index 78c32ce8de..db8a70206e 100644 --- a/itext.tests/itext.sign.tests/itext/signatures/sign/AnnotationsSigningTest.cs +++ b/itext.tests/itext.sign.tests/itext/signatures/sign/AnnotationsSigningTest.cs @@ -136,8 +136,8 @@ protected internal virtual void Sign(String src, String name, String dest, IX509 SignerProperties signerProperties = new SignerProperties().SetCertificationLevel(certificationLevel).SetFieldName (name); // Creating the appearance - SignatureFieldAppearance appearance = new SignatureFieldAppearance(name).SetContent(new SignedAppearanceText - ()); + SignatureFieldAppearance appearance = new SignatureFieldAppearance(SignerProperties.IGNORED_ID).SetContent + (new SignedAppearanceText()); signerProperties.SetReason(reason).SetLocation(location).SetSignatureAppearance(appearance); if (rectangleForNewField != null) { signerProperties.SetPageRect(rectangleForNewField); diff --git a/itext.tests/itext.sign.tests/itext/signatures/sign/IsoSignatureExtensionsRoundtripTest.cs b/itext.tests/itext.sign.tests/itext/signatures/sign/IsoSignatureExtensionsRoundtripTest.cs index 62c5411ad6..03c6692b4f 100644 --- a/itext.tests/itext.sign.tests/itext/signatures/sign/IsoSignatureExtensionsRoundtripTest.cs +++ b/itext.tests/itext.sign.tests/itext/signatures/sign/IsoSignatureExtensionsRoundtripTest.cs @@ -291,7 +291,7 @@ private void DoSign(String keySampleName, String digestAlgo, String signatureAlg // and accessing that information requires APIs that are not available in older JDKs we still support. IExternalSignature pks = new PrivateKeySignature(signPrivateKey, digestAlgo, signatureAlgo, null); PdfSigner signer = new PdfSigner(new PdfReader(SOURCE_FILE), os, new StampingProperties()); - SignatureFieldAppearance appearance = new SignatureFieldAppearance(SIGNATURE_FIELD) + SignatureFieldAppearance appearance = new SignatureFieldAppearance(SignerProperties.IGNORED_ID) .SetContent("Approval test signature.\nCreated by iText."); SignerProperties signerProperties = new SignerProperties() .SetFieldName(SIGNATURE_FIELD) diff --git a/itext.tests/itext.sign.tests/itext/signatures/sign/PadesSigTest.cs b/itext.tests/itext.sign.tests/itext/signatures/sign/PadesSigTest.cs index 3eac525f2b..de720667e1 100644 --- a/itext.tests/itext.sign.tests/itext/signatures/sign/PadesSigTest.cs +++ b/itext.tests/itext.sign.tests/itext/signatures/sign/PadesSigTest.cs @@ -144,8 +144,8 @@ private void SignApproval(String signCertFileName, String outFileName, ISignatur StampingProperties()); SignerProperties signerProperties = new SignerProperties().SetFieldName("Signature1"); signer.SetSignerProperties(signerProperties); - SignatureFieldAppearance appearance = new SignatureFieldAppearance(signer.GetSignerProperties().GetFieldName - ()).SetContent("Approval test signature.\nCreated by iText."); + SignatureFieldAppearance appearance = new SignatureFieldAppearance(SignerProperties.IGNORED_ID).SetContent + ("Approval test signature.\nCreated by iText."); signerProperties.SetPageRect(new Rectangle(50, 650, 200, 100)).SetReason("Test").SetLocation("TestCity").SetSignatureAppearance (appearance); if (sigPolicyIdentifier != null) { diff --git a/itext.tests/itext.sign.tests/itext/signatures/sign/PadesSignatureLevelTest.cs b/itext.tests/itext.sign.tests/itext/signatures/sign/PadesSignatureLevelTest.cs index ae3951a486..a8be4573f1 100644 --- a/itext.tests/itext.sign.tests/itext/signatures/sign/PadesSignatureLevelTest.cs +++ b/itext.tests/itext.sign.tests/itext/signatures/sign/PadesSignatureLevelTest.cs @@ -72,7 +72,7 @@ public virtual void PadesSignatureLevelTTest01() { IPrivateKey tsaPrivateKey = PemFileHelper.ReadFirstKey(tsaCertFileName, password); PdfSigner signer = new PdfSigner(new PdfReader(srcFileName), FileUtil.GetFileOutputStream(outFileName), new StampingProperties()); - SignatureFieldAppearance appearance = new SignatureFieldAppearance("Signature1") + SignatureFieldAppearance appearance = new SignatureFieldAppearance(SignerProperties.IGNORED_ID) .SetContent("Approval test signature.\nCreated by iText."); SignerProperties signerProperties = new SignerProperties() .SetFieldName("Signature1") diff --git a/itext.tests/itext.sign.tests/itext/signatures/sign/PadesTwoPhaseSigningLevelsTest.cs b/itext.tests/itext.sign.tests/itext/signatures/sign/PadesTwoPhaseSigningLevelsTest.cs index 6b6374329f..9a18585cd1 100644 --- a/itext.tests/itext.sign.tests/itext/signatures/sign/PadesTwoPhaseSigningLevelsTest.cs +++ b/itext.tests/itext.sign.tests/itext/signatures/sign/PadesTwoPhaseSigningLevelsTest.cs @@ -313,7 +313,7 @@ public virtual void TwoStepSigningBaselineLTATest() { private SignerProperties CreateSignerProperties() { SignerProperties signerProperties = new SignerProperties(); signerProperties.SetFieldName("Signature1"); - SignatureFieldAppearance appearance = new SignatureFieldAppearance(signerProperties.GetFieldName()).SetContent + SignatureFieldAppearance appearance = new SignatureFieldAppearance(SignerProperties.IGNORED_ID).SetContent ("Approval test signature.\nCreated by iText."); signerProperties.SetPageRect(new Rectangle(50, 650, 200, 100)).SetSignatureAppearance(appearance); return signerProperties; diff --git a/itext.tests/itext.sign.tests/itext/signatures/sign/PadesTwoPhaseSigningTest.cs b/itext.tests/itext.sign.tests/itext/signatures/sign/PadesTwoPhaseSigningTest.cs index ccc545b0c1..cc601cf03b 100644 --- a/itext.tests/itext.sign.tests/itext/signatures/sign/PadesTwoPhaseSigningTest.cs +++ b/itext.tests/itext.sign.tests/itext/signatures/sign/PadesTwoPhaseSigningTest.cs @@ -125,7 +125,7 @@ public virtual void MissingTimestampClientTest() { private SignerProperties CreateSignerProperties() { SignerProperties signerProperties = new SignerProperties(); signerProperties.SetFieldName("Signature1"); - SignatureFieldAppearance appearance = new SignatureFieldAppearance(signerProperties.GetFieldName()).SetContent + SignatureFieldAppearance appearance = new SignatureFieldAppearance(SignerProperties.IGNORED_ID).SetContent ("Approval test signature.\nCreated by iText."); signerProperties.SetPageRect(new Rectangle(50, 650, 200, 100)).SetSignatureAppearance(appearance); return signerProperties; diff --git a/itext.tests/itext.sign.tests/itext/signatures/sign/Pdf20SigningTest.cs b/itext.tests/itext.sign.tests/itext/signatures/sign/Pdf20SigningTest.cs index 2b3d0d6d73..30f5349830 100644 --- a/itext.tests/itext.sign.tests/itext/signatures/sign/Pdf20SigningTest.cs +++ b/itext.tests/itext.sign.tests/itext/signatures/sign/Pdf20SigningTest.cs @@ -180,8 +180,8 @@ protected internal virtual void Sign(String src, String name, String dest, IX509 SignerProperties signerProperties = new SignerProperties().SetCertificationLevel(certificationLevel).SetFieldName (name).SetReason(reason).SetLocation(location); // Creating the appearance - SignatureFieldAppearance appearance = new SignatureFieldAppearance(name).SetContent(new SignedAppearanceText - ()); + SignatureFieldAppearance appearance = new SignatureFieldAppearance(SignerProperties.IGNORED_ID).SetContent + (new SignedAppearanceText()); if (rectangleForNewField != null) { signerProperties.SetPageRect(rectangleForNewField); } diff --git a/itext.tests/itext.sign.tests/itext/signatures/sign/PdfASigningTest.cs b/itext.tests/itext.sign.tests/itext/signatures/sign/PdfASigningTest.cs index cb10668f7a..b11e96d52c 100644 --- a/itext.tests/itext.sign.tests/itext/signatures/sign/PdfASigningTest.cs +++ b/itext.tests/itext.sign.tests/itext/signatures/sign/PdfASigningTest.cs @@ -153,8 +153,8 @@ public virtual void FailedSigningPdfA2DocumentTest() { Rectangle rect = new Rectangle(x, y, w, h); PdfFont font = PdfFontFactory.CreateFont("Helvetica", "WinAnsi", PdfFontFactory.EmbeddingStrategy.PREFER_EMBEDDED ); - SignatureFieldAppearance appearance = new SignatureFieldAppearance(signer.GetSignerProperties().GetFieldName - ()).SetContent(new SignedAppearanceText()).SetFont(font); + SignatureFieldAppearance appearance = new SignatureFieldAppearance(SignerProperties.IGNORED_ID).SetContent + (new SignedAppearanceText()).SetFont(font); signerProperties.SetPageRect(rect).SetReason("pdfA test").SetLocation("TestCity").SetSignatureAppearance(appearance ); signer.GetSignatureField().SetReuseAppearance(false); @@ -188,8 +188,8 @@ protected internal virtual void Sign(String src, String name, String dest, IX509 PdfFont font = PdfFontFactory.CreateFont(FONT, "WinAnsi", PdfFontFactory.EmbeddingStrategy.PREFER_EMBEDDED ); // Creating the appearance - SignatureFieldAppearance appearance = new SignatureFieldAppearance(name).SetContent(new SignedAppearanceText - ()); + SignatureFieldAppearance appearance = new SignatureFieldAppearance(SignerProperties.IGNORED_ID).SetContent + (new SignedAppearanceText()); appearance.SetFont(font); signerProperties.SetReason(reason).SetLocation(location).SetSignatureAppearance(appearance); if (rectangleForNewField != null) { diff --git a/itext.tests/itext.sign.tests/itext/signatures/sign/PdfPadesAdvancedTest.cs b/itext.tests/itext.sign.tests/itext/signatures/sign/PdfPadesAdvancedTest.cs index 3fa446a85b..b506d071c4 100644 --- a/itext.tests/itext.sign.tests/itext/signatures/sign/PdfPadesAdvancedTest.cs +++ b/itext.tests/itext.sign.tests/itext/signatures/sign/PdfPadesAdvancedTest.cs @@ -166,7 +166,7 @@ private String GetCertName(IX509Certificate certificate) { private SignerProperties CreateSignerProperties() { SignerProperties signerProperties = new SignerProperties(); signerProperties.SetFieldName("Signature1"); - SignatureFieldAppearance appearance = new SignatureFieldAppearance(signerProperties.GetFieldName()).SetContent + SignatureFieldAppearance appearance = new SignatureFieldAppearance(SignerProperties.IGNORED_ID).SetContent ("Approval test signature.\nCreated by iText."); signerProperties.SetPageRect(new Rectangle(50, 650, 200, 100)).SetSignatureAppearance(appearance); return signerProperties; diff --git a/itext.tests/itext.sign.tests/itext/signatures/sign/PdfPadesMissingCertificatesTest.cs b/itext.tests/itext.sign.tests/itext/signatures/sign/PdfPadesMissingCertificatesTest.cs index c76521db6c..203d806d57 100644 --- a/itext.tests/itext.sign.tests/itext/signatures/sign/PdfPadesMissingCertificatesTest.cs +++ b/itext.tests/itext.sign.tests/itext/signatures/sign/PdfPadesMissingCertificatesTest.cs @@ -282,7 +282,7 @@ private String GetCertName(IX509Certificate certificate) { private SignerProperties CreateSignerProperties() { SignerProperties signerProperties = new SignerProperties(); signerProperties.SetFieldName("Signature1"); - SignatureFieldAppearance appearance = new SignatureFieldAppearance(signerProperties.GetFieldName()).SetContent + SignatureFieldAppearance appearance = new SignatureFieldAppearance(SignerProperties.IGNORED_ID).SetContent ("Approval test signature.\nCreated by iText."); signerProperties.SetPageRect(new Rectangle(50, 650, 200, 100)).SetSignatureAppearance(appearance); return signerProperties; diff --git a/itext.tests/itext.sign.tests/itext/signatures/sign/PdfPadesSignerLevelsTest.cs b/itext.tests/itext.sign.tests/itext/signatures/sign/PdfPadesSignerLevelsTest.cs index 7f0f166d7c..1c197ac7c8 100644 --- a/itext.tests/itext.sign.tests/itext/signatures/sign/PdfPadesSignerLevelsTest.cs +++ b/itext.tests/itext.sign.tests/itext/signatures/sign/PdfPadesSignerLevelsTest.cs @@ -261,7 +261,7 @@ public virtual void ProlongDocumentSignaturesTest() { private SignerProperties CreateSignerProperties() { SignerProperties signerProperties = new SignerProperties(); signerProperties.SetFieldName("Signature1"); - SignatureFieldAppearance appearance = new SignatureFieldAppearance(signerProperties.GetFieldName()) + SignatureFieldAppearance appearance = new SignatureFieldAppearance(SignerProperties.IGNORED_ID) .SetContent("Approval test signature.\nCreated by iText."); signerProperties.SetPageRect(new Rectangle(50, 650, 200, 100)) .SetSignatureAppearance(appearance); diff --git a/itext.tests/itext.sign.tests/itext/signatures/sign/PdfPadesSignerLtvExtensionsTest.cs b/itext.tests/itext.sign.tests/itext/signatures/sign/PdfPadesSignerLtvExtensionsTest.cs index 7b76c622d9..7298bc92da 100644 --- a/itext.tests/itext.sign.tests/itext/signatures/sign/PdfPadesSignerLtvExtensionsTest.cs +++ b/itext.tests/itext.sign.tests/itext/signatures/sign/PdfPadesSignerLtvExtensionsTest.cs @@ -137,7 +137,7 @@ private String GetCertName(IX509Certificate certificate) { private SignerProperties CreateSignerProperties() { SignerProperties signerProperties = new SignerProperties(); signerProperties.SetFieldName("Signature1"); - SignatureFieldAppearance appearance = new SignatureFieldAppearance(signerProperties.GetFieldName()).SetContent + SignatureFieldAppearance appearance = new SignatureFieldAppearance(SignerProperties.IGNORED_ID).SetContent ("Approval test signature.\nCreated by iText."); signerProperties.SetPageRect(new Rectangle(50, 650, 200, 100)).SetSignatureAppearance(appearance); return signerProperties; diff --git a/itext.tests/itext.sign.tests/itext/signatures/sign/PdfPadesSignerTest.cs b/itext.tests/itext.sign.tests/itext/signatures/sign/PdfPadesSignerTest.cs index 4ee066f9e3..519ebe6d45 100644 --- a/itext.tests/itext.sign.tests/itext/signatures/sign/PdfPadesSignerTest.cs +++ b/itext.tests/itext.sign.tests/itext/signatures/sign/PdfPadesSignerTest.cs @@ -237,7 +237,7 @@ public virtual void PadesSignatureEd448Test() { private SignerProperties CreateSignerProperties() { SignerProperties signerProperties = new SignerProperties(); signerProperties.SetFieldName("Signature1"); - SignatureFieldAppearance appearance = new SignatureFieldAppearance(signerProperties.GetFieldName()).SetContent + SignatureFieldAppearance appearance = new SignatureFieldAppearance(SignerProperties.IGNORED_ID).SetContent ("Approval test signature.\nCreated by iText."); signerProperties.SetPageRect(new Rectangle(50, 650, 200, 100)).SetSignatureAppearance(appearance); return signerProperties; diff --git a/itext.tests/itext.sign.tests/itext/signatures/sign/PdfPadesWithCrlCertificateTest.cs b/itext.tests/itext.sign.tests/itext/signatures/sign/PdfPadesWithCrlCertificateTest.cs index 96532ef6b7..ee5f951f4d 100644 --- a/itext.tests/itext.sign.tests/itext/signatures/sign/PdfPadesWithCrlCertificateTest.cs +++ b/itext.tests/itext.sign.tests/itext/signatures/sign/PdfPadesWithCrlCertificateTest.cs @@ -126,7 +126,7 @@ protected internal override Stream GetIssuerCertByURI(String uri) { private SignerProperties CreateSignerProperties() { SignerProperties signerProperties = new SignerProperties(); signerProperties.SetFieldName("Signature1"); - SignatureFieldAppearance appearance = new SignatureFieldAppearance(signerProperties.GetFieldName()).SetContent + SignatureFieldAppearance appearance = new SignatureFieldAppearance(SignerProperties.IGNORED_ID).SetContent ("Approval test signature.\nCreated by iText."); signerProperties.SetPageRect(new Rectangle(50, 650, 200, 100)).SetSignatureAppearance(appearance); return signerProperties; diff --git a/itext.tests/itext.sign.tests/itext/signatures/sign/PdfPadesWithMissingCertTest.cs b/itext.tests/itext.sign.tests/itext/signatures/sign/PdfPadesWithMissingCertTest.cs index 585aa174ad..493d03d291 100644 --- a/itext.tests/itext.sign.tests/itext/signatures/sign/PdfPadesWithMissingCertTest.cs +++ b/itext.tests/itext.sign.tests/itext/signatures/sign/PdfPadesWithMissingCertTest.cs @@ -125,7 +125,7 @@ protected internal override Stream GetIssuerCertByURI(String uri) { private SignerProperties CreateSignerProperties() { SignerProperties signerProperties = new SignerProperties(); signerProperties.SetFieldName("Signature1"); - SignatureFieldAppearance appearance = new SignatureFieldAppearance(signerProperties.GetFieldName()).SetContent + SignatureFieldAppearance appearance = new SignatureFieldAppearance(SignerProperties.IGNORED_ID).SetContent ("Approval test signature.\nCreated by iText."); signerProperties.SetPageRect(new Rectangle(50, 650, 200, 100)).SetSignatureAppearance(appearance); return signerProperties; diff --git a/itext.tests/itext.sign.tests/itext/signatures/sign/PdfPadesWithOcspCertificateTest.cs b/itext.tests/itext.sign.tests/itext/signatures/sign/PdfPadesWithOcspCertificateTest.cs index b58544523c..8a0e0e585c 100644 --- a/itext.tests/itext.sign.tests/itext/signatures/sign/PdfPadesWithOcspCertificateTest.cs +++ b/itext.tests/itext.sign.tests/itext/signatures/sign/PdfPadesWithOcspCertificateTest.cs @@ -166,7 +166,7 @@ private String GetCertName(IX509Certificate certificate) { private SignerProperties CreateSignerProperties() { SignerProperties signerProperties = new SignerProperties(); signerProperties.SetFieldName("Signature1"); - SignatureFieldAppearance appearance = new SignatureFieldAppearance(signerProperties.GetFieldName()).SetContent + SignatureFieldAppearance appearance = new SignatureFieldAppearance(SignerProperties.IGNORED_ID).SetContent ("Approval test signature.\nCreated by iText."); signerProperties.SetPageRect(new Rectangle(50, 650, 200, 100)).SetSignatureAppearance(appearance); return signerProperties; diff --git a/itext.tests/itext.sign.tests/itext/signatures/sign/PdfPadesWithTimestampCertificateTest.cs b/itext.tests/itext.sign.tests/itext/signatures/sign/PdfPadesWithTimestampCertificateTest.cs index 62b84fe1e9..73cb4b26b5 100644 --- a/itext.tests/itext.sign.tests/itext/signatures/sign/PdfPadesWithTimestampCertificateTest.cs +++ b/itext.tests/itext.sign.tests/itext/signatures/sign/PdfPadesWithTimestampCertificateTest.cs @@ -101,7 +101,7 @@ private String GetCertName(IX509Certificate certificate) { private SignerProperties CreateSignerProperties() { SignerProperties signerProperties = new SignerProperties(); signerProperties.SetFieldName("Signature1"); - SignatureFieldAppearance appearance = new SignatureFieldAppearance(signerProperties.GetFieldName()).SetContent + SignatureFieldAppearance appearance = new SignatureFieldAppearance(SignerProperties.IGNORED_ID).SetContent ("Approval test signature.\nCreated by iText."); signerProperties.SetPageRect(new Rectangle(50, 650, 200, 100)).SetSignatureAppearance(appearance); return signerProperties; diff --git a/itext.tests/itext.sign.tests/itext/signatures/sign/SequentialSignaturesTest.cs b/itext.tests/itext.sign.tests/itext/signatures/sign/SequentialSignaturesTest.cs index 3fc2ffbca6..df8d5810fd 100644 --- a/itext.tests/itext.sign.tests/itext/signatures/sign/SequentialSignaturesTest.cs +++ b/itext.tests/itext.sign.tests/itext/signatures/sign/SequentialSignaturesTest.cs @@ -62,8 +62,8 @@ public virtual void SequentialSignOfFileWithAnnots() { String signatureName = "Signature2"; PdfSigner signer = new PdfSigner(new PdfReader(srcFileName), FileUtil.GetFileOutputStream(outFileName), new StampingProperties().UseAppendMode()); - SignatureFieldAppearance appearance = new SignatureFieldAppearance(signatureName).SetContent("Approval test signature.\nCreated by iText." - ); + SignatureFieldAppearance appearance = new SignatureFieldAppearance(SignerProperties.IGNORED_ID).SetContent + ("Approval test signature.\nCreated by iText."); SignerProperties signerProperties = new SignerProperties().SetFieldName(signatureName).SetPageRect(new Rectangle (50, 350, 200, 100)).SetReason("Test").SetLocation("TestCity").SetSignatureAppearance(appearance); signer.SetSignerProperties(signerProperties); @@ -87,8 +87,8 @@ public virtual void SecondSignOfTaggedDocTest() { StampingProperties().UseAppendMode()); PdfDocument document = signer.GetDocument(); document.GetWriter().SetCompressionLevel(CompressionConstants.NO_COMPRESSION); - SignatureFieldAppearance appearance = new SignatureFieldAppearance(signatureName).SetContent("Approval test signature #2.\nCreated by iText." - ); + SignatureFieldAppearance appearance = new SignatureFieldAppearance(SignerProperties.IGNORED_ID).SetContent + ("Approval test signature #2.\nCreated by iText."); SignerProperties signerProperties = new SignerProperties().SetFieldName(signatureName).SetPageNumber(1).SetPageRect (new Rectangle(50, 550, 200, 100)).SetReason("Test2").SetLocation("TestCity2").SetSignatureAppearance( appearance); diff --git a/itext.tests/itext.sign.tests/itext/signatures/sign/SignDeferredTest.cs b/itext.tests/itext.sign.tests/itext/signatures/sign/SignDeferredTest.cs index 20b3902ca5..86f93142f7 100644 --- a/itext.tests/itext.sign.tests/itext/signatures/sign/SignDeferredTest.cs +++ b/itext.tests/itext.sign.tests/itext/signatures/sign/SignDeferredTest.cs @@ -69,8 +69,8 @@ public virtual void PrepareDocForSignDeferredTest() { PdfSigner signer = new PdfSigner(reader, FileUtil.GetFileOutputStream(output), new StampingProperties()); SignerProperties signerProperties = new SignerProperties().SetFieldName(sigFieldName); signer.SetSignerProperties(signerProperties); - SignatureFieldAppearance appearance = new SignatureFieldAppearance(sigFieldName).SetContent("Signature field which signing is deferred." - ); + SignatureFieldAppearance appearance = new SignatureFieldAppearance(SignerProperties.IGNORED_ID).SetContent + ("Signature field which signing is deferred."); signerProperties.SetPageRect(new Rectangle(36, 600, 200, 100)).SetPageNumber(1).SetSignatureAppearance(appearance ); IExternalSignatureContainer external = new ExternalBlankSignatureContainer(filter, subFilter); @@ -89,8 +89,8 @@ public virtual void PrepareDocForSignDeferredNotEnoughSizeTest() { PdfSigner signer = new PdfSigner(reader, new MemoryStream(), new StampingProperties()); SignerProperties signerProperties = new SignerProperties().SetFieldName(sigFieldName); signer.SetSignerProperties(signerProperties); - SignatureFieldAppearance appearance = new SignatureFieldAppearance(sigFieldName).SetContent("Signature field which signing is deferred." - ); + SignatureFieldAppearance appearance = new SignatureFieldAppearance(SignerProperties.IGNORED_ID).SetContent + ("Signature field which signing is deferred."); signerProperties.SetPageRect(new Rectangle(36, 600, 200, 100)).SetPageNumber(1).SetSignatureAppearance(appearance ); IExternalSignatureContainer external = new ExternalBlankSignatureContainer(filter, subFilter); @@ -111,8 +111,8 @@ public virtual void PrepareDocForSignDeferredLittleSpaceTest() { PdfSigner signer = new PdfSigner(reader, new MemoryStream(), new StampingProperties()); SignerProperties signerProperties = new SignerProperties().SetFieldName(sigFieldName); signer.SetSignerProperties(signerProperties); - SignatureFieldAppearance appearance = new SignatureFieldAppearance(sigFieldName).SetContent("Signature field which signing is deferred." - ); + SignatureFieldAppearance appearance = new SignatureFieldAppearance(SignerProperties.IGNORED_ID).SetContent + ("Signature field which signing is deferred."); signerProperties.SetPageRect(new Rectangle(36, 600, 200, 100)).SetPageNumber(1).SetSignatureAppearance(appearance ); IExternalSignatureContainer external = new ExternalBlankSignatureContainer(filter, subFilter); @@ -163,8 +163,8 @@ public virtual void CalcHashOnDocCreationThenDeferredSignTest01() { SignerProperties signerProperties = new SignerProperties().SetCertificationLevel(AccessPermissions.NO_CHANGES_PERMITTED ).SetFieldName(sigFieldName); signer.SetSignerProperties(signerProperties); - SignatureFieldAppearance appearance = new SignatureFieldAppearance(sigFieldName).SetContent("Signature field which signing is deferred." - ); + SignatureFieldAppearance appearance = new SignatureFieldAppearance(SignerProperties.IGNORED_ID).SetContent + ("Signature field which signing is deferred."); signerProperties.SetPageRect(new Rectangle(36, 600, 200, 100)).SetPageNumber(1).SetSignatureAppearance(appearance ); SignDeferredTest.DigestCalcBlankSigner external = new SignDeferredTest.DigestCalcBlankSigner(filter, subFilter diff --git a/itext.tests/itext.sign.tests/itext/signatures/sign/SignatureAppearanceTest.cs b/itext.tests/itext.sign.tests/itext/signatures/sign/SignatureAppearanceTest.cs index 44d5083b76..71a5d8fd30 100644 --- a/itext.tests/itext.sign.tests/itext/signatures/sign/SignatureAppearanceTest.cs +++ b/itext.tests/itext.sign.tests/itext/signatures/sign/SignatureAppearanceTest.cs @@ -141,8 +141,8 @@ public virtual void TestSigningInAppendModeWithHybridDocument() { PdfSigner signer = new PdfSigner(new PdfReader(src), FileUtil.GetFileOutputStream(dest), new StampingProperties ().UseAppendMode()); String fieldName = "Sign1"; - SignatureFieldAppearance appearance = new SignatureFieldAppearance(fieldName).SetContent(new SignedAppearanceText - ()).SetFontSize(13.8f); + SignatureFieldAppearance appearance = new SignatureFieldAppearance(SignerProperties.IGNORED_ID).SetContent + (new SignedAppearanceText()).SetFontSize(13.8f); SignerProperties signerProperties = new SignerProperties().SetFieldName(fieldName).SetReason("Test").SetLocation ("Nagpur").SetPageRect(new Rectangle(36, 748, 250, 100)).SetPageNumber(1).SetSignatureAppearance(appearance ).SetCertificationLevel(AccessPermissions.UNSPECIFIED); @@ -168,8 +168,8 @@ public virtual void FontColorTest01() { SignerProperties signerProperties = new SignerProperties().SetFieldName("Signature1"); signer.SetSignerProperties(signerProperties); // Creating the appearance - signerProperties.SetPageRect(rect).SetSignatureAppearance(new SignatureFieldAppearance(signerProperties.GetFieldName - ()).SetFontColor(ColorConstants.RED).SetContent("Verified and signed by me.")); + signerProperties.SetPageRect(rect).SetSignatureAppearance(new SignatureFieldAppearance(SignerProperties.IGNORED_ID + ).SetFontColor(ColorConstants.RED).SetContent("Verified and signed by me.")); // Creating the signature IExternalSignature pks = new PrivateKeySignature(pk, DigestAlgorithms.SHA256); signer.SignDetached(new BouncyCastleDigest(), pks, chain, null, null, null, 0, PdfSigner.CryptoStandard.CADES @@ -212,7 +212,7 @@ public virtual void SignExistingNotMergedFieldNotReusedAPTest() { SignerProperties signerProperties = new SignerProperties().SetFieldName("Signature1").SetCertificationLevel (AccessPermissions.UNSPECIFIED).SetReason("Test 1").SetLocation("TestCity"); signer.SetSignerProperties(signerProperties); - signerProperties.SetSignatureAppearance(new SignatureFieldAppearance(signerProperties.GetFieldName()).SetContent + signerProperties.SetSignatureAppearance(new SignatureFieldAppearance(SignerProperties.IGNORED_ID).SetContent ("Verified and signed by me.")); signer.GetSignatureField().SetReuseAppearance(false); IExternalSignature pks = new PrivateKeySignature(pk, DigestAlgorithms.SHA256); @@ -233,8 +233,8 @@ public virtual void SignExistingNotMergedFieldReusedAPTest() { SignerProperties signerProperties = new SignerProperties().SetCertificationLevel(AccessPermissions.UNSPECIFIED ).SetFieldName("Signature1"); signer.SetSignerProperties(signerProperties); - SignatureFieldAppearance appearance = new SignatureFieldAppearance(signer.GetSignerProperties().GetFieldName - ()).SetContent("SIGNED").SetFontColor(ColorConstants.GREEN); + SignatureFieldAppearance appearance = new SignatureFieldAppearance(SignerProperties.IGNORED_ID).SetContent + ("SIGNED").SetFontColor(ColorConstants.GREEN); appearance.SetProperty(Property.VERTICAL_ALIGNMENT, VerticalAlignment.MIDDLE); signerProperties.SetReason("Test 1").SetLocation("TestCity").SetSignatureAppearance(appearance); signer.GetSignatureField().SetReuseAppearance(true); @@ -256,7 +256,7 @@ public virtual void SignExistingNotMergedFieldReusedAPEntryNDicTest() { SignerProperties signerProperties = new SignerProperties().SetCertificationLevel(AccessPermissions.UNSPECIFIED ).SetFieldName("Signature1").SetReason("Test 1").SetLocation("TestCity"); signer.SetSignerProperties(signerProperties); - signerProperties.SetSignatureAppearance(new SignatureFieldAppearance(signerProperties.GetFieldName()).SetContent + signerProperties.SetSignatureAppearance(new SignatureFieldAppearance(SignerProperties.IGNORED_ID).SetContent ("Verified and signed by me.")); signer.GetSignatureField().SetReuseAppearance(true); IExternalSignature pks = new PrivateKeySignature(pk, DigestAlgorithms.SHA256); @@ -312,8 +312,9 @@ public virtual void CreateAndSignSignatureFieldTest() { SignerProperties signerProperties = new SignerProperties().SetFieldName(fieldName); signer.SetSignerProperties(signerProperties); // Creating the appearance - SignatureFieldAppearance appearance = new SignatureFieldAppearance(fieldName).SetContent("Test signature field appearance. Test signature field appearance. " - + "Test signature field appearance. Test signature field appearance"); + SignatureFieldAppearance appearance = new SignatureFieldAppearance(SignerProperties.IGNORED_ID).SetContent + ("Test signature field appearance. Test signature field appearance. " + "Test signature field appearance. Test signature field appearance" + ); signerProperties.SetReason("Appearance is tested").SetLocation("TestCity").SetSignatureAppearance(appearance ); // Signing @@ -333,8 +334,8 @@ public virtual void SignExistedSignatureFieldTest() { SignerProperties signerProperties = new SignerProperties().SetFieldName("Signature1"); signer.SetSignerProperties(signerProperties); // Creating the appearance - SignatureFieldAppearance appearance = new SignatureFieldAppearance(signer.GetSignerProperties().GetFieldName - ()).SetContent("Test signature field appearance. Test signature field appearance. " + "Test signature field appearance. Test signature field appearance" + SignatureFieldAppearance appearance = new SignatureFieldAppearance(SignerProperties.IGNORED_ID).SetContent + ("Test signature field appearance. Test signature field appearance. " + "Test signature field appearance. Test signature field appearance" ); signerProperties.SetReason("Appearance is tested").SetLocation("TestCity").SetSignatureAppearance(appearance ); @@ -372,9 +373,10 @@ public virtual void SignatureFieldAppearanceTest() { ()); SignerProperties signerProperties = new SignerProperties().SetFieldName(fieldName); signer.SetSignerProperties(signerProperties); - SignatureFieldAppearance appearance = new SignatureFieldAppearance(fieldName).SetContent("Signature field" - ).SetBackgroundColor(ColorConstants.GREEN).SetBorder(new SolidBorder(ColorConstants.LIGHT_GRAY, 3)).SetFontColor - (ColorConstants.DARK_GRAY).SetFontSize(20).SetTextAlignment(TextAlignment.CENTER); + SignatureFieldAppearance appearance = new SignatureFieldAppearance(SignerProperties.IGNORED_ID).SetContent + ("Signature field").SetBackgroundColor(ColorConstants.GREEN).SetBorder(new SolidBorder(ColorConstants. + LIGHT_GRAY, 3)).SetFontColor(ColorConstants.DARK_GRAY).SetFontSize(20).SetTextAlignment(TextAlignment. + CENTER); signerProperties.SetPageRect(new Rectangle(250, 500, 100, 100)).SetReason("Test 1").SetLocation("TestCity" ).SetSignatureAppearance(appearance); // Signing @@ -392,7 +394,7 @@ public virtual void EmptySignatureAppearanceTest() { String outPdf = DESTINATION_FOLDER + "emptySignatureAppearance.pdf"; Rectangle rect = new Rectangle(36, 648, 200, 100); String fieldName = "Signature1"; - SignatureFieldAppearance appearance = new SignatureFieldAppearance(fieldName); + SignatureFieldAppearance appearance = new SignatureFieldAppearance(SignerProperties.IGNORED_ID); PdfSigner signer = new PdfSigner(new PdfReader(srcFile), FileUtil.GetFileOutputStream(outPdf), new StampingProperties ()); SignerProperties signerProperties = new SignerProperties().SetCertificationLevel(AccessPermissions.UNSPECIFIED @@ -431,7 +433,7 @@ private void TestReuseAppearance(String src, String fileName) { signer.SetSignerProperties(signerProperties); signer.GetSignatureField().SetReuseAppearance(true); signerProperties.SetReason("Test 1").SetLocation("TestCity").SetSignatureAppearance(new SignatureFieldAppearance - (fieldName).SetContent("New appearance").SetFontColor(ColorConstants.GREEN)); + (SignerProperties.IGNORED_ID).SetContent("New appearance").SetFontColor(ColorConstants.GREEN)); IExternalSignature pks = new PrivateKeySignature(pk, DigestAlgorithms.SHA256); signer.SignDetached(new BouncyCastleDigest(), pks, chain, null, null, null, 0, PdfSigner.CryptoStandard.CADES ); @@ -445,7 +447,7 @@ private void TestLayers(String src, String fileName) { ()); SignerProperties signerProperties = new SignerProperties().SetFieldName(fieldName).SetPageRect(new Rectangle (250, 500, 100, 100)).SetReason("Test 1").SetLocation("TestCity").SetSignatureAppearance(new SignatureFieldAppearance - (fieldName)); + (SignerProperties.IGNORED_ID)); signer.SetSignerProperties(signerProperties); PdfFormXObject layer0 = new PdfFormXObject(new Rectangle(0, 0, 100, 100)); // Draw pink rectangle with blue border @@ -468,7 +470,7 @@ private void TestSignatureOnRotatedPage(int pageNum, bool useDescription, bool u String fileName = "signaturesOnRotatedPages" + pageNum + "_mode_"; String src = SOURCE_FOLDER + "documentWithRotatedPages.pdf"; String signatureName = "Signature1"; - SignatureFieldAppearance appearance = new SignatureFieldAppearance(signatureName); + SignatureFieldAppearance appearance = new SignatureFieldAppearance(SignerProperties.IGNORED_ID); String description = "Digitally signed by Test User. All rights reserved. Take care!"; if (useImage) { if (useDescription) { @@ -523,8 +525,7 @@ private void TestSignatureAppearanceAutoscale(String dest, Rectangle rect, Strin SignerProperties signerProperties = new SignerProperties().SetFieldName("Signature1"); signer.SetSignerProperties(signerProperties); // Creating the appearance - SignatureFieldAppearance appearance = new SignatureFieldAppearance(signer.GetSignerProperties().GetFieldName - ()); + SignatureFieldAppearance appearance = new SignatureFieldAppearance(SignerProperties.IGNORED_ID); if (image != null) { appearance.SetContent(new SignedAppearanceText(), image); } diff --git a/itext.tests/itext.sign.tests/itext/signatures/sign/SignedAppearanceTextTest.cs b/itext.tests/itext.sign.tests/itext/signatures/sign/SignedAppearanceTextTest.cs index c5ef198112..d8469624f7 100644 --- a/itext.tests/itext.sign.tests/itext/signatures/sign/SignedAppearanceTextTest.cs +++ b/itext.tests/itext.sign.tests/itext/signatures/sign/SignedAppearanceTextTest.cs @@ -92,8 +92,8 @@ public virtual void DefaultSignedAppearanceTextTest() { String outPdf = DESTINATION_FOLDER + "defaultSignedAppearanceTextTest.pdf"; Rectangle rect = new Rectangle(36, 648, 200, 100); String fieldName = "Signature1"; - SignatureFieldAppearance appearance = new SignatureFieldAppearance(fieldName).SetContent(new SignedAppearanceText - ()); + SignatureFieldAppearance appearance = new SignatureFieldAppearance(SignerProperties.IGNORED_ID).SetContent + (new SignedAppearanceText()); Sign(srcFile, fieldName, outPdf, "Test 1", "TestCity 1", rect, appearance); NUnit.Framework.Assert.IsNull(new CompareTool().CompareVisually(outPdf, cmpPdf, DESTINATION_FOLDER, "diff_" , GetTestMap(new Rectangle(36, 676, 200, 15)))); @@ -106,8 +106,9 @@ public virtual void SignPDFADocumentWithoutSettingFont() { CreateSimplePDFADocument(srcFile).Close(); Rectangle rect = new Rectangle(50, 70, 400, 200); String fieldName = "Signature1"; - SignatureFieldAppearance appearance = new SignatureFieldAppearance(fieldName).SetContent(new SignedAppearanceText - ().SetSignedBy("Test").SetSignDate(DateTimeUtil.GetCurrentTime()).SetLocationLine("Test City")); + SignatureFieldAppearance appearance = new SignatureFieldAppearance(SignerProperties.IGNORED_ID).SetContent + (new SignedAppearanceText().SetSignedBy("Test").SetSignDate(DateTimeUtil.GetCurrentTime()).SetLocationLine + ("Test City")); String outPdf = DESTINATION_FOLDER + "signPDFADocumentWithoutSettingFont.pdf"; Exception e = NUnit.Framework.Assert.Catch(typeof(Exception), () => { Sign(srcFile, fieldName, outPdf, "Test 1", "TestCity 1", rect, appearance); @@ -122,9 +123,9 @@ public virtual void SignPDFADocumentSettingBadFont() { CreateSimplePDFADocument(srcFile).Close(); Rectangle rect = new Rectangle(50, 70, 400, 200); String fieldName = "Signature1"; - SignatureFieldAppearance appearance = new SignatureFieldAppearance(fieldName).SetFont(PdfFontFactory.CreateFont - (StandardFonts.COURIER)).SetContent(new SignedAppearanceText().SetSignedBy("Test").SetSignDate(DateTimeUtil - .GetCurrentTime()).SetLocationLine("Test City")); + SignatureFieldAppearance appearance = new SignatureFieldAppearance(SignerProperties.IGNORED_ID).SetFont(PdfFontFactory + .CreateFont(StandardFonts.COURIER)).SetContent(new SignedAppearanceText().SetSignedBy("Test").SetSignDate + (DateTimeUtil.GetCurrentTime()).SetLocationLine("Test City")); String outPdf = DESTINATION_FOLDER + "signPDFADocumentBadFont.pdf"; Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => { Sign(srcFile, fieldName, outPdf, "Test 1", "TestCity 1", rect, appearance); @@ -146,9 +147,9 @@ public virtual void DefaultPdfATextTest() { PdfFont font = PdfFontFactory.CreateFont(FONT_FOLDER + "FreeSans.ttf", PdfFontFactory.EmbeddingStrategy.FORCE_EMBEDDED ); String fieldName = "Signature1"; - SignatureFieldAppearance appearance = new SignatureFieldAppearance(fieldName).SetFont(font).SetContent(new - SignedAppearanceText().SetSignedBy("Test").SetSignDate(DateTimeUtil.GetCurrentTime()).SetLocationLine( - "Test City")); + SignatureFieldAppearance appearance = new SignatureFieldAppearance(SignerProperties.IGNORED_ID).SetFont(font + ).SetContent(new SignedAppearanceText().SetSignedBy("Test").SetSignDate(DateTimeUtil.GetCurrentTime()) + .SetLocationLine("Test City")); Sign(srcFile, fieldName, outPdf, "Test 1", "TestCity 1", rect, appearance); NUnit.Framework.Assert.IsNull(new VeraPdfValidator().Validate(outPdf)); // Android-Conversion-Skip-Line (TODO DEVSIX-7377 introduce pdf\a validation on Android) @@ -175,9 +176,9 @@ public virtual void SignPdfAWithFormfieldAlreadyExistingTest() { Rectangle rect = new Rectangle(50, 200, 400, 100); PdfFont font1 = PdfFontFactory.CreateFont(FONT_FOLDER + "FreeSans.ttf", PdfFontFactory.EmbeddingStrategy.FORCE_EMBEDDED ); - SignatureFieldAppearance appearance = new SignatureFieldAppearance(fieldName).SetFont(font1).SetContent(new - SignedAppearanceText().SetSignedBy("Test").SetSignDate(DateTimeUtil.GetCurrentTime()).SetLocationLine( - "Test City")); + SignatureFieldAppearance appearance = new SignatureFieldAppearance(SignerProperties.IGNORED_ID).SetFont(font1 + ).SetContent(new SignedAppearanceText().SetSignedBy("Test").SetSignDate(DateTimeUtil.GetCurrentTime()) + .SetLocationLine("Test City")); Sign(srcFile, fieldName, outPdf, "Test 1", "TestCity 1", rect, appearance); NUnit.Framework.Assert.IsNull(new VeraPdfValidator().Validate(outPdf)); // Android-Conversion-Skip-Line (TODO DEVSIX-7377 introduce pdf\a validation on Android) @@ -206,8 +207,8 @@ public virtual void DefaultSignedAppearanceTextAndSignerTest() { String outPdf = DESTINATION_FOLDER + "defaultSignedAppearanceTextAndSignerTest.pdf"; Rectangle rect = new Rectangle(36, 648, 200, 100); String fieldName = "Signature2"; - SignatureFieldAppearance appearance = new SignatureFieldAppearance(fieldName).SetContent("", new SignedAppearanceText - ()); + SignatureFieldAppearance appearance = new SignatureFieldAppearance(SignerProperties.IGNORED_ID).SetContent + ("", new SignedAppearanceText()); Sign(srcFile, fieldName, outPdf, "Test 2", "TestCity 2", rect, appearance); NUnit.Framework.Assert.IsNull(new CompareTool().CompareVisually(outPdf, cmpPdf, DESTINATION_FOLDER, "diff_" , GetTestMap(new Rectangle(136, 686, 100, 25)))); @@ -223,8 +224,8 @@ public virtual void DefaultSignedAppearanceTextWithImageTest() { String outPdf = DESTINATION_FOLDER + "defaultSignedAppearanceTextWithImageTest.pdf"; Rectangle rect = new Rectangle(36, 648, 300, 100); String fieldName = "Signature3"; - SignatureFieldAppearance appearance = new SignatureFieldAppearance(fieldName).SetContent(new SignedAppearanceText - (), ImageDataFactory.Create(imagePath)); + SignatureFieldAppearance appearance = new SignatureFieldAppearance(SignerProperties.IGNORED_ID).SetContent + (new SignedAppearanceText(), ImageDataFactory.Create(imagePath)); Sign(srcFile, fieldName, outPdf, "Test 3", "TestCity 3", rect, appearance); NUnit.Framework.Assert.IsNull(new CompareTool().CompareVisually(outPdf, cmpPdf, DESTINATION_FOLDER, "diff_" , GetTestMap(new Rectangle(186, 681, 150, 36)))); @@ -240,9 +241,9 @@ public virtual void ModifiedSignedAppearanceTextTest() { String fieldName = "Signature4"; String reason = "Test 4"; String location = "TestCity 4"; - SignatureFieldAppearance appearance = new SignatureFieldAppearance(fieldName).SetContent(new SignedAppearanceText - ().SetSignedBy(" wrong signer ").SetReasonLine(" Signing reason: " + reason).SetLocationLine(" Signing location: " - + location).SetSignDate(DateTimeUtil.GetCurrentTime())); + SignatureFieldAppearance appearance = new SignatureFieldAppearance(SignerProperties.IGNORED_ID).SetContent + (new SignedAppearanceText().SetSignedBy(" wrong signer ").SetReasonLine(" Signing reason: " + reason + ).SetLocationLine(" Signing location: " + location).SetSignDate(DateTimeUtil.GetCurrentTime())); Sign(srcFile, fieldName, outPdf, reason, location, rect, appearance); NUnit.Framework.Assert.IsNull(new CompareTool().CompareVisually(outPdf, cmpPdf, DESTINATION_FOLDER, "diff_" , GetTestMap(new Rectangle(36, 676, 200, 15)))); diff --git a/itext.tests/itext.sign.tests/itext/signatures/sign/SimpleSigningTest.cs b/itext.tests/itext.sign.tests/itext/signatures/sign/SimpleSigningTest.cs index cca3ea221f..a08e514527 100644 --- a/itext.tests/itext.sign.tests/itext/signatures/sign/SimpleSigningTest.cs +++ b/itext.tests/itext.sign.tests/itext/signatures/sign/SimpleSigningTest.cs @@ -156,8 +156,8 @@ private static IDictionary> GetTestMap(Rectangle ignoredAr private static void CreateAppearance(PdfSigner signer, String signatureName, String reason, String location , bool setReuseAppearance, Rectangle rectangleForNewField, float? fontSize) { - SignatureFieldAppearance appearance = new SignatureFieldAppearance(signatureName).SetContent(new SignedAppearanceText - ()); + SignatureFieldAppearance appearance = new SignatureFieldAppearance(SignerProperties.IGNORED_ID).SetContent + (new SignedAppearanceText()); signer.GetSignerProperties().SetReason(reason).SetLocation(location).SetSignatureAppearance(appearance); if (rectangleForNewField != null) { signer.GetSignerProperties().SetPageRect(rectangleForNewField); diff --git a/itext.tests/itext.sign.tests/itext/signatures/sign/TaggedPdfSigningTest.cs b/itext.tests/itext.sign.tests/itext/signatures/sign/TaggedPdfSigningTest.cs index 535f92132e..9afb7e55a3 100644 --- a/itext.tests/itext.sign.tests/itext/signatures/sign/TaggedPdfSigningTest.cs +++ b/itext.tests/itext.sign.tests/itext/signatures/sign/TaggedPdfSigningTest.cs @@ -114,8 +114,8 @@ protected internal virtual void Sign(String src, String name, String dest, IX509 (name); signer.SetSignerProperties(signerProperties); // Creating the appearance - SignatureFieldAppearance appearance = new SignatureFieldAppearance(name).SetContent(new SignedAppearanceText - ()); + SignatureFieldAppearance appearance = new SignatureFieldAppearance(SignerProperties.IGNORED_ID).SetContent + (new SignedAppearanceText()); if (rectangleForNewField != null) { signerProperties.SetPageRect(rectangleForNewField); } diff --git a/itext/itext.forms/itext/forms/form/element/SignatureFieldAppearance.cs b/itext/itext.forms/itext/forms/form/element/SignatureFieldAppearance.cs index e25b75d451..b391e2bbb0 100644 --- a/itext/itext.forms/itext/forms/form/element/SignatureFieldAppearance.cs +++ b/itext/itext.forms/itext/forms/form/element/SignatureFieldAppearance.cs @@ -62,12 +62,24 @@ public class SignatureFieldAppearance : FormField /// instance. /// - /// the id. + /// + /// signature field name if you use this + /// + /// in pure layout for the new + /// interactive signature field creation. ID will be ignored if this + /// + /// is used for signing or for existing signature field + /// public SignatureFieldAppearance(String id) : base( - // We should support signing of existing fields with dots in name. + // ID is required for the new interactive signature field creation. We can't provide parameterless constructor + + // since the user might misuse it for unintended purpose, and we have to generate a unique field name + + // that doesn't exist in the document acroform, which we don't have access to at this level. id != null && id.Contains(".") ? "" : id) { if (id.Contains(".")) { + // We should support signing of existing fields with dots in name. idWithDots = id; } // Draw the borders inside the element by default diff --git a/itext/itext.kernel/itext/kernel/colors/gradients/AbstractLinearGradientBuilder.cs b/itext/itext.kernel/itext/kernel/colors/gradients/AbstractLinearGradientBuilder.cs index b6581c6c46..895da3e6ab 100644 --- a/itext/itext.kernel/itext/kernel/colors/gradients/AbstractLinearGradientBuilder.cs +++ b/itext/itext.kernel/itext/kernel/colors/gradients/AbstractLinearGradientBuilder.cs @@ -29,6 +29,7 @@ You should have received a copy of the GNU Affero General Public License using iText.Kernel.Geom; using iText.Kernel.Pdf; using iText.Kernel.Pdf.Colorspace; +using iText.Kernel.Pdf.Colorspace.Shading; using iText.Kernel.Pdf.Function; namespace iText.Kernel.Colors.Gradients { @@ -158,7 +159,7 @@ public virtual Color BuildColor(Rectangle targetBoundingBox, AffineTransform con ); } } - PdfShading.Axial axial = CreateAxialShading(baseCoordinatesVector, this.stops, this.spreadMethod, targetBoundingBox + PdfAxialShading axial = CreateAxialShading(baseCoordinatesVector, this.stops, this.spreadMethod, targetBoundingBox ); if (axial == null) { return null; @@ -272,8 +273,8 @@ protected internal static Point[] CreateCoordinatesForNewDomain(double[] newDoma return targetCoords; } - private static PdfShading.Axial CreateAxialShading(Point[] baseCoordinatesVector, IList - stops, GradientSpreadMethod spreadMethod, Rectangle targetBoundingBox) { + private static PdfAxialShading CreateAxialShading(Point[] baseCoordinatesVector, IList + stops, GradientSpreadMethod spreadMethod, Rectangle targetBoundingBox) { double baseVectorLength = baseCoordinatesVector[1].Distance(baseCoordinatesVector[0]); IList stopsToConstruct = NormalizeStops(stops, baseVectorLength); double[] coordinatesDomain = new double[] { 0, 1 }; @@ -313,7 +314,7 @@ private static PdfShading.Axial CreateAxialShading(Point[] baseCoordinatesVector System.Diagnostics.Debug.Assert(coordinatesDomain[0] <= coordinatesDomain[1]); actualCoordinates = CreateCoordinatesForNewDomain(coordinatesDomain, baseCoordinatesVector); } - return new PdfShading.Axial(new PdfDeviceCs.Rgb(), CreateCoordsPdfArray(actualCoordinates), new PdfArray(coordinatesDomain + return new PdfAxialShading(new PdfDeviceCs.Rgb(), CreateCoordsPdfArray(actualCoordinates), new PdfArray(coordinatesDomain ), ConstructFunction(stopsToConstruct)); } diff --git a/itext/itext.kernel/itext/kernel/pdf/PdfResources.cs b/itext/itext.kernel/itext/kernel/pdf/PdfResources.cs index 947e5e1b1b..6cad98579b 100644 --- a/itext/itext.kernel/itext/kernel/pdf/PdfResources.cs +++ b/itext/itext.kernel/itext/kernel/pdf/PdfResources.cs @@ -25,6 +25,7 @@ You should have received a copy of the GNU Affero General Public License using iText.Commons.Utils; using iText.Kernel.Font; using iText.Kernel.Pdf.Colorspace; +using iText.Kernel.Pdf.Colorspace.Shading; using iText.Kernel.Pdf.Extgstate; using iText.Kernel.Pdf.Xobject; @@ -335,16 +336,16 @@ public virtual PdfPattern GetPattern(PdfName name) { /// /// Adds - /// + /// /// object to the resources. /// /// /// the - /// + /// /// to add. /// /// added shading resource name. - public virtual PdfName AddShading(PdfShading shading) { + public virtual PdfName AddShading(AbstractPdfShading shading) { return AddResource(shading, shadingNamesGen); } @@ -363,9 +364,9 @@ public virtual PdfName AddShading(PdfDictionary shading) { return AddResource(shading, shadingNamesGen); } - public virtual PdfShading GetShading(PdfName name) { + public virtual AbstractPdfShading GetShading(PdfName name) { PdfObject shading = GetResourceObject(PdfName.Shading, name); - return shading is PdfDictionary ? PdfShading.MakeShading((PdfDictionary)shading) : null; + return shading is PdfDictionary ? AbstractPdfShading.MakeShading((PdfDictionary)shading) : null; } protected internal virtual bool IsReadOnly() { diff --git a/itext/itext.kernel/itext/kernel/pdf/canvas/PdfCanvas.cs b/itext/itext.kernel/itext/kernel/pdf/canvas/PdfCanvas.cs index 615906b583..057d1e4272 100644 --- a/itext/itext.kernel/itext/kernel/pdf/canvas/PdfCanvas.cs +++ b/itext/itext.kernel/itext/kernel/pdf/canvas/PdfCanvas.cs @@ -36,6 +36,7 @@ You should have received a copy of the GNU Affero General Public License using iText.Kernel.Pdf; using iText.Kernel.Pdf.Canvas.Wmf; using iText.Kernel.Pdf.Colorspace; +using iText.Kernel.Pdf.Colorspace.Shading; using iText.Kernel.Pdf.Extgstate; using iText.Kernel.Pdf.Layer; using iText.Kernel.Pdf.Tagutils; @@ -1103,7 +1104,7 @@ public virtual iText.Kernel.Pdf.Canvas.PdfCanvas Circle(double x, double y, doub /// Paints a shading object and adds it to the resources of this canvas /// a shading object to be painted /// current canvas. - public virtual iText.Kernel.Pdf.Canvas.PdfCanvas PaintShading(PdfShading shading) { + public virtual iText.Kernel.Pdf.Canvas.PdfCanvas PaintShading(AbstractPdfShading shading) { PdfName shadingName = resources.AddShading(shading); contentStream.GetOutputStream().Write((PdfObject)shadingName).WriteSpace().WriteBytes(sh); return this; diff --git a/itext/itext.kernel/itext/kernel/pdf/colorspace/PdfPattern.cs b/itext/itext.kernel/itext/kernel/pdf/colorspace/PdfPattern.cs index b28109e1fc..ce55ed1028 100644 --- a/itext/itext.kernel/itext/kernel/pdf/colorspace/PdfPattern.cs +++ b/itext/itext.kernel/itext/kernel/pdf/colorspace/PdfPattern.cs @@ -23,6 +23,7 @@ You should have received a copy of the GNU Affero General Public License using System; using iText.Kernel.Geom; using iText.Kernel.Pdf; +using iText.Kernel.Pdf.Colorspace.Shading; namespace iText.Kernel.Pdf.Colorspace { /// @@ -440,11 +441,11 @@ public Shading(PdfDictionary pdfObject) /// Creates a new instance of Shading Pattern. /// /// the - /// + /// /// that specifies the details of a particular /// gradient fill /// - public Shading(PdfShading shading) + public Shading(AbstractPdfShading shading) : base(new PdfDictionary()) { GetPdfObject().Put(PdfName.Type, PdfName.Pattern); GetPdfObject().Put(PdfName.PatternType, new PdfNumber(2)); @@ -453,11 +454,11 @@ public Shading(PdfShading shading) /// /// Gets the dictionary of the pattern's - /// . + /// . /// /// /// the dictionary of the pattern's - /// + /// /// public virtual PdfDictionary GetShading() { return (PdfDictionary)GetPdfObject().Get(PdfName.Shading); @@ -465,15 +466,15 @@ public virtual PdfDictionary GetShading() { /// /// Sets the - /// + /// /// that specifies the details of a particular gradient fill. /// /// /// the - /// + /// /// that specifies the details of a particular gradient fill /// - public virtual void SetShading(PdfShading shading) { + public virtual void SetShading(AbstractPdfShading shading) { GetPdfObject().Put(PdfName.Shading, shading.GetPdfObject()); SetModified(); } @@ -481,7 +482,7 @@ public virtual void SetShading(PdfShading shading) { /// Sets the dictionary which specifies the details of a particular gradient fill. /// /// the dictionary of the pattern's - /// + /// /// public virtual void SetShading(PdfDictionary shading) { GetPdfObject().Put(PdfName.Shading, shading); diff --git a/itext/itext.kernel/itext/kernel/pdf/colorspace/PdfShading.cs b/itext/itext.kernel/itext/kernel/pdf/colorspace/PdfShading.cs deleted file mode 100644 index a3ed2dbba5..0000000000 --- a/itext/itext.kernel/itext/kernel/pdf/colorspace/PdfShading.cs +++ /dev/null @@ -1,1955 +0,0 @@ -/* -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 . -*/ -using System; -using iText.Kernel.Exceptions; -using iText.Kernel.Pdf; -using iText.Kernel.Pdf.Function; - -namespace iText.Kernel.Pdf.Colorspace { - /// The abstract PdfShading class that represents the Shading Dictionary PDF object. - public abstract class PdfShading : PdfObjectWrapper { -//\cond DO_NOT_DOCUMENT - /// constants of shading type (see ISO-320001 Table 78) - internal sealed class ShadingType { - /// The int value of function-based shading type - public const int FUNCTION_BASED = 1; - - /// The int value of axial shading type - public const int AXIAL = 2; - - /// The int value of radial shading type - public const int RADIAL = 3; - - /// The int value of free-form Gouraud-shaded triangle mesh shading type - public const int FREE_FORM_GOURAUD_SHADED_TRIANGLE_MESH = 4; - - /// The int value of lattice-form Gouraud-shaded triangle mesh shading type - public const int LATTICE_FORM_GOURAUD_SHADED_TRIANGLE_MESH = 5; - - /// The int value of coons patch meshes shading type - public const int COONS_PATCH_MESH = 6; - - /// The int value of tensor-product patch meshes shading type - public const int TENSOR_PRODUCT_PATCH_MESH = 7; - - private ShadingType() { - } - } -//\endcond - - /// - /// Creates the - /// - /// object from the existing - /// - /// with corresponding type. - /// - /// - /// - /// - /// from which the - /// - /// object will be created. - /// - /// - /// Created - /// - /// object. - /// - public static PdfShading MakeShading(PdfDictionary shadingDictionary) { - if (!shadingDictionary.ContainsKey(PdfName.ShadingType)) { - throw new PdfException(KernelExceptionMessageConstant.SHADING_TYPE_NOT_FOUND); - } - if (!shadingDictionary.ContainsKey(PdfName.ColorSpace)) { - throw new PdfException(KernelExceptionMessageConstant.COLOR_SPACE_NOT_FOUND); - } - PdfShading shading; - switch (shadingDictionary.GetAsNumber(PdfName.ShadingType).IntValue()) { - case PdfShading.ShadingType.FUNCTION_BASED: { - shading = new PdfShading.FunctionBased(shadingDictionary); - break; - } - - case PdfShading.ShadingType.AXIAL: { - shading = new PdfShading.Axial(shadingDictionary); - break; - } - - case PdfShading.ShadingType.RADIAL: { - shading = new PdfShading.Radial(shadingDictionary); - break; - } - - case PdfShading.ShadingType.FREE_FORM_GOURAUD_SHADED_TRIANGLE_MESH: { - if (!shadingDictionary.IsStream()) { - throw new PdfException(KernelExceptionMessageConstant.UNEXPECTED_SHADING_TYPE); - } - shading = new PdfShading.FreeFormGouraudShadedTriangleMesh((PdfStream)shadingDictionary); - break; - } - - case PdfShading.ShadingType.LATTICE_FORM_GOURAUD_SHADED_TRIANGLE_MESH: { - if (!shadingDictionary.IsStream()) { - throw new PdfException(KernelExceptionMessageConstant.UNEXPECTED_SHADING_TYPE); - } - shading = new PdfShading.LatticeFormGouraudShadedTriangleMesh((PdfStream)shadingDictionary); - break; - } - - case PdfShading.ShadingType.COONS_PATCH_MESH: { - if (!shadingDictionary.IsStream()) { - throw new PdfException(KernelExceptionMessageConstant.UNEXPECTED_SHADING_TYPE); - } - shading = new PdfShading.CoonsPatchMesh((PdfStream)shadingDictionary); - break; - } - - case PdfShading.ShadingType.TENSOR_PRODUCT_PATCH_MESH: { - if (!shadingDictionary.IsStream()) { - throw new PdfException(KernelExceptionMessageConstant.UNEXPECTED_SHADING_TYPE); - } - shading = new PdfShading.TensorProductPatchMesh((PdfStream)shadingDictionary); - break; - } - - default: { - throw new PdfException(KernelExceptionMessageConstant.UNEXPECTED_SHADING_TYPE); - } - } - return shading; - } - - /// - /// Creates the - /// - /// object from the existing - /// . - /// - /// - /// - /// - /// from which the - /// - /// object will be created. - /// - protected internal PdfShading(PdfDictionary pdfObject) - : base(pdfObject) { - } - - /// - /// Creates the - /// - /// object from the existing - /// - /// , - /// using provided type and colorspace. - /// - /// - /// - /// - /// from which the - /// - /// object will be created. - /// - /// - /// type with which this - /// - /// object will be created. - /// - /// - /// - /// - /// with which this - /// - /// object will be created. - /// - protected internal PdfShading(PdfDictionary pdfObject, int type, PdfColorSpace colorSpace) - : base(pdfObject) { - GetPdfObject().Put(PdfName.ShadingType, new PdfNumber(type)); - if (colorSpace is PdfSpecialCs.Pattern) { - throw new ArgumentException("colorSpace"); - } - GetPdfObject().Put(PdfName.ColorSpace, colorSpace.GetPdfObject()); - } - - /// Gets the shading type. - /// - /// int value of - /// . - /// - public virtual int GetShadingType() { - return (int)GetPdfObject().GetAsInt(PdfName.ShadingType); - } - - /// Gets the color space in which colour values shall be expressed. - /// - /// - /// - /// Color space - /// - public virtual PdfObject GetColorSpace() { - return GetPdfObject().Get(PdfName.ColorSpace); - } - - /// - /// Gets the function PdfObject that represents color transitions - /// across the shading geometry. - /// - /// - /// - /// - /// Function - /// - public virtual PdfObject GetFunction() { - return GetPdfObject().Get(PdfName.Function); - } - - /// - /// Sets the function that represents color transitions - /// across the shading geometry as one object. - /// - /// - /// The - /// - /// to set. - /// - public virtual void SetFunction(IPdfFunction function) { - GetPdfObject().Put(PdfName.Function, function.GetAsPdfObject()); - SetModified(); - } - - /// - /// Sets the function object that represents color transitions - /// across the shading geometry as an array of functions. - /// - /// - /// The array of - /// - /// to be set. - /// - public virtual void SetFunction(IPdfFunction[] functions) { - PdfArray arr = new PdfArray(); - foreach (IPdfFunction func in functions) { - arr.Add(func.GetAsPdfObject()); - } - GetPdfObject().Put(PdfName.Function, arr); - SetModified(); - } - - /// - /// To manually flush a - /// PdfObject - /// behind this wrapper, you have to ensure - /// that this object is added to the document, i.e. it has an indirect reference. - /// - /// - /// To manually flush a - /// PdfObject - /// behind this wrapper, you have to ensure - /// that this object is added to the document, i.e. it has an indirect reference. - /// Basically this means that before flushing you need to explicitly call - /// . - /// For example: wrapperInstance.makeIndirect(document).flush(); - /// Note that not every wrapper require this, only those that have such warning in documentation. - /// - public override void Flush() { - base.Flush(); - } - - /// - protected internal override bool IsWrappedObjectMustBeIndirect() { - return true; - } - - /// - /// The class that extends - /// - /// class and is in charge of Shading Dictionary with function-based type, - /// that defines color at every point in the domain by a specified mathematical function. - /// - public class FunctionBased : PdfShading { - /// - /// Creates the new instance of the class from the existing - /// . - /// - /// - /// from which this - /// - /// will be created - /// - protected internal FunctionBased(PdfDictionary pdfDictionary) - : base(pdfDictionary) { - } - - /// Creates the new instance of the class. - /// - /// the - /// - /// object in which colour values shall be expressed. - /// - /// - /// the - /// - /// , that is used to calculate color transitions. - /// - public FunctionBased(PdfColorSpace colorSpace, IPdfFunction function) - : this(colorSpace.GetPdfObject(), function) { - } - - /// Creates the new instance of the class. - /// - /// the - /// - /// , that represents color space in which colour values shall be expressed. - /// - /// - /// the - /// - /// , that is used to calculate color transitions. - /// - public FunctionBased(PdfObject colorSpace, IPdfFunction function) - : base(new PdfDictionary(), PdfShading.ShadingType.FUNCTION_BASED, PdfColorSpace.MakeColorSpace(colorSpace - )) { - SetFunction(function); - } - - /// - /// Gets the - /// - /// domain rectangle object that establishes an internal coordinate space - /// for the shading that is independent of the target coordinate space in which it shall be painted. - /// - /// - /// - /// - /// domain rectangle. - /// - public virtual PdfArray GetDomain() { - return GetPdfObject().GetAsArray(PdfName.Domain); - } - - /// - /// Sets the - /// - /// domain rectangle object that establishes an internal coordinate space - /// for the shading that is independent of the target coordinate space in which it shall be painted. - /// - /// the Xmin coordinate of rectangle. - /// the Xmax coordinate of rectangle. - /// the Ymin coordinate of rectangle. - /// the Ymax coordinate of rectangle. - public virtual void SetDomain(float xmin, float xmax, float ymin, float ymax) { - SetDomain(new PdfArray(new float[] { xmin, xmax, ymin, ymax })); - } - - /// - /// Sets the - /// - /// domain rectangle object that establishes an internal coordinate space - /// for the shading that is independent of the target coordinate space in which it shall be painted. - /// - /// - /// the - /// - /// domain rectangle object to be set. - /// - public virtual void SetDomain(PdfArray domain) { - GetPdfObject().Put(PdfName.Domain, domain); - SetModified(); - } - - /// - /// Gets the - /// - /// of floats that represents the transformation matrix that maps the domain rectangle - /// into a corresponding figure in the target coordinate space. - /// - /// - /// the - /// - /// of transformation matrix (identical matrix by default). - /// - public virtual PdfArray GetMatrix() { - PdfArray matrix = GetPdfObject().GetAsArray(PdfName.Matrix); - if (matrix == null) { - matrix = new PdfArray(new float[] { 1, 0, 0, 1, 0, 0 }); - SetMatrix(matrix); - } - return matrix; - } - - /// - /// Sets the array of floats that represents the transformation matrix that maps the domain rectangle - /// into a corresponding figure in the target coordinate space. - /// - /// - /// the - /// float[] - /// of transformation matrix to be set. - /// - public virtual void SetMatrix(float[] matrix) { - SetMatrix(new PdfArray(matrix)); - } - - /// - /// Sets the array of floats that represents the transformation matrix that maps the domain rectangle - /// into a corresponding figure in the target coordinate space. - /// - /// - /// the - /// - /// transformation matrix object to be set. - /// - public virtual void SetMatrix(PdfArray matrix) { - GetPdfObject().Put(PdfName.Matrix, matrix); - SetModified(); - } - } - - /// - /// The class that extends - /// - /// class and is in charge of Shading Dictionary with axial type, - /// that define a colour blend that varies along a linear axis between two endpoints - /// and extends indefinitely perpendicular to that axis. - /// - public class Axial : PdfShading { - /// - /// Creates the new instance of the class from the existing - /// . - /// - /// - /// from which this - /// - /// will be created - /// - protected internal Axial(PdfDictionary pdfDictionary) - : base(pdfDictionary) { - } - - /// Creates the new instance of the class. - /// - /// the - /// - /// object in which colour values shall be expressed. - /// The special Pattern space isn't excepted. - /// - /// the start coordinate of X axis expressed in the shading's target coordinate space. - /// the start coordinate of Y axis expressed in the shading's target coordinate space. - /// - /// the - /// float[] - /// that represents the color in the start point. - /// - /// the end coordinate of X axis expressed in the shading's target coordinate space. - /// the end coordinate of Y axis expressed in the shading's target coordinate space. - /// - /// the - /// float[] - /// that represents the color in the end point. - /// - public Axial(PdfColorSpace cs, float x0, float y0, float[] color0, float x1, float y1, float[] color1) - : base(new PdfDictionary(), PdfShading.ShadingType.AXIAL, cs) { - SetCoords(x0, y0, x1, y1); - IPdfFunction func = new PdfType2Function(new float[] { 0, 1 }, null, color0, color1, 1); - SetFunction(func); - } - - /// Creates the new instance of the class. - /// - /// the - /// - /// object in which colour values shall be expressed. - /// The special Pattern space isn't excepted. - /// - /// the start coordinate of X axis expressed in the shading's target coordinate space. - /// the start coordinate of Y axis expressed in the shading's target coordinate space. - /// - /// the - /// float[] - /// that represents the color in the start point. - /// - /// the end coordinate of X axis expressed in the shading's target coordinate space. - /// the end coordinate of Y axis expressed in the shading's target coordinate space. - /// - /// the - /// float[] - /// that represents the color in the end point. - /// - /// - /// the array of two booleans that specified whether to extend the shading - /// beyond the starting and ending points of the axis, respectively. - /// - public Axial(PdfColorSpace cs, float x0, float y0, float[] color0, float x1, float y1, float[] color1, bool - [] extend) - : this(cs, x0, y0, color0, x1, y1, color1) { - if (extend == null || extend.Length != 2) { - throw new ArgumentException("extend"); - } - SetExtend(extend[0], extend[1]); - } - - /// Creates the new instance of the class. - /// - /// the - /// - /// object in which colour values shall be expressed. - /// The special Pattern space isn't excepted. - /// - /// - /// the - /// - /// of four numbers [x0 y0 x1 y1] that specified the starting - /// and the endings coordinates of thew axis, expressed in the shading's target coordinate space. - /// - /// - /// the - /// - /// object, that is used to calculate color transitions. - /// - public Axial(PdfColorSpace cs, PdfArray coords, IPdfFunction function) - : this(cs, coords, null, function) { - } - - /// Creates the new instance of the class. - /// - /// the - /// - /// object in which colour values shall be expressed. - /// The special Pattern space isn't excepted. - /// - /// - /// the - /// - /// of four numbers [x0 y0 x1 y1] that specified - /// the starting and the endings coordinates of thew axis, expressed - /// in the shading's target coordinate space. - /// - /// - /// the - /// - /// of two numbers [t0 t1] specifying the limiting values - /// of a parametric variable t which is considered to vary linearly between - /// these two values and becomes the input argument to the colour function. - /// - /// - /// the - /// - /// object, that is used to calculate color transitions. - /// - public Axial(PdfColorSpace cs, PdfArray coords, PdfArray domain, IPdfFunction function) - : base(new PdfDictionary(), PdfShading.ShadingType.AXIAL, cs) { - SetCoords(coords); - if (domain != null) { - SetDomain(domain); - } - SetFunction(function); - } - - /// - /// Gets the Coords object - a - /// - /// of four numbers [x0 y0 x1 y1] that specified the starting - /// and the endings coordinates of thew axis, expressed in the shading's target coordinate space. - /// - /// - /// the - /// - /// Coords object. - /// - public virtual PdfArray GetCoords() { - return GetPdfObject().GetAsArray(PdfName.Coords); - } - - /// Sets the Choords object with the four params expressed in the shading's target coordinate space. - /// the start coordinate of X axis to be set. - /// the start coordinate of Y axis to be set. - /// the end coordinate of X axis to be set. - /// the end coordinate of Y axis to be set. - public virtual void SetCoords(float x0, float y0, float x1, float y1) { - SetCoords(new PdfArray(new float[] { x0, y0, x1, y1 })); - } - - /// - /// Sets the Choords object with the - /// - /// of four numbers [x0 y0 x1 y1], - /// that specified the starting and the endings coordinates of thew axis, - /// expressed in the shading's target coordinate space. - /// - /// - /// the Chords - /// - /// to be set. - /// - public virtual void SetCoords(PdfArray coords) { - GetPdfObject().Put(PdfName.Coords, coords); - SetModified(); - } - - /// - /// Gets the - /// - /// of two - /// float - /// [t0, t1] that represent the limiting values of a parametric - /// variable t, that becomes an input of color function(s). - /// - /// - /// the - /// - /// of Domain object ([0.0 1.0] by default) - /// - public virtual PdfArray GetDomain() { - PdfArray domain = GetPdfObject().GetAsArray(PdfName.Domain); - if (domain == null) { - domain = new PdfArray(new float[] { 0, 1 }); - SetDomain(domain); - } - return domain; - } - - /// - /// Sets the Domain with the array of two - /// float - /// [t0, t1] that represent the limiting values - /// of a parametric variable t, that becomes an input of color function(s). - /// - /// first limit of variable t - /// second limit of variable t - public virtual void SetDomain(float t0, float t1) { - SetDomain(new PdfArray(new float[] { t0, t1 })); - } - - /// - /// Sets the Domain with the - /// - /// of two - /// float - /// [t0, t1] that represent the limiting values - /// of a parametric variable t, that becomes an input of color function(s). - /// - /// - /// the - /// - /// that represents domain - /// - public virtual void SetDomain(PdfArray domain) { - GetPdfObject().Put(PdfName.Domain, domain); - SetModified(); - } - - /// - /// Gets the - /// - /// of two - /// boolean - /// that specified whether to extend the shading - /// beyond the starting and ending points of the axis, respectively. - /// - /// - /// the - /// - /// of Extended object ([false false] by default) - /// - public virtual PdfArray GetExtend() { - PdfArray extend = GetPdfObject().GetAsArray(PdfName.Extend); - if (extend == null) { - extend = new PdfArray(new bool[] { false, false }); - SetExtend(extend); - } - return extend; - } - - /// - /// Sets the Extend object with the two - /// boolean - /// value. - /// - /// if true will extend shading beyond the starting point of Coords - /// if true will extend shading beyond the ending point of Coords - public virtual void SetExtend(bool extendStart, bool extendEnd) { - SetExtend(new PdfArray(new bool[] { extendStart, extendEnd })); - } - - /// - /// Sets the Extend object with the - /// - /// of two - /// boolean. - /// - /// - /// Sets the Extend object with the - /// - /// of two - /// boolean. - /// If first is true shading will extend beyond the starting point of Coords. - /// If second is true shading will extend beyond the ending point of Coords. - /// - /// - /// the - /// - /// representing Extend object - /// - public virtual void SetExtend(PdfArray extend) { - GetPdfObject().Put(PdfName.Extend, extend); - SetModified(); - } - } - - /// - /// The class that extends - /// - /// class and is in charge of Shading Dictionary with radial type, - /// that define a colour blend that varies between two circles. - /// - /// - /// The class that extends - /// - /// class and is in charge of Shading Dictionary with radial type, - /// that define a colour blend that varies between two circles. - /// This type of shading shall not be used with an Indexed colour space - /// - public class Radial : PdfShading { - /// - /// Creates the new instance of the class from the existing - /// . - /// - /// - /// from which this - /// - /// will be created - /// - protected internal Radial(PdfDictionary pdfDictionary) - : base(pdfDictionary) { - } - - /// Creates the new instance of the class. - /// - /// the - /// - /// object in which colour values shall be expressed. - /// The Indexed color space isn't excepted. - /// - /// the X coordinate of starting circle's centre, expressed in in the shading’s target coordinate space. - /// - /// the Y coordinate of starting circle's centre, expressed in in the shading’s target coordinate space. - /// - /// - /// the radius of starting circle's centre, should be greater or equal to 0. - /// If 0 then starting circle is treated as point. - /// If both radii are 0, nothing shall be painted. - /// - /// - /// the - /// float[] - /// that represents the color in the start circle. - /// - /// the X coordinate of ending circle's centre, expressed in in the shading’s target coordinate space. - /// - /// the Y coordinate of ending circle's centre, expressed in in the shading’s target coordinate space. - /// - /// - /// the radius of ending circle's centre, should be greater or equal to 0. - /// If 0 then ending circle is treated as point. - /// If both radii are 0, nothing shall be painted. - /// - /// - /// the - /// float[] - /// that represents the color in the end circle. - /// - public Radial(PdfColorSpace cs, float x0, float y0, float r0, float[] color0, float x1, float y1, float r1 - , float[] color1) - : base(new PdfDictionary(), PdfShading.ShadingType.RADIAL, cs) { - SetCoords(x0, y0, r0, x1, y1, r1); - IPdfFunction func = new PdfType2Function(new float[] { 0, 1 }, null, color0, color1, 1); - SetFunction(func); - } - - /// Creates the new instance of the class. - /// - /// the - /// - /// object in which colour values shall be expressed. - /// The Indexed color space isn't excepted. - /// - /// the X coordinate of starting circle's centre, expressed in in the shading’s target coordinate space. - /// - /// the Y coordinate of starting circle's centre, expressed in in the shading’s target coordinate space. - /// - /// - /// the radius of starting circle's centre, should be greater or equal to 0. - /// If 0 then starting circle is treated as point. - /// If both radii are 0, nothing shall be painted. - /// - /// - /// the - /// float[] - /// that represents the color in the start circle. - /// - /// the X coordinate of ending circle's centre, expressed in in the shading’s target coordinate space. - /// - /// the Y coordinate of ending circle's centre, expressed in in the shading’s target coordinate space. - /// - /// - /// the radius of ending circle's centre, should be greater or equal to 0. - /// If 0 then ending circle is treated as point. - /// If both radii are 0, nothing shall be painted. - /// - /// - /// the - /// float[] - /// that represents the color in the end circle. - /// - /// - /// the array of two - /// boolean - /// that specified whether to extend the shading - /// beyond the starting and ending points of the axis, respectively. - /// - public Radial(PdfColorSpace cs, float x0, float y0, float r0, float[] color0, float x1, float y1, float r1 - , float[] color1, bool[] extend) - : this(cs, x0, y0, r0, color0, x1, y1, r1, color1) { - if (extend == null || extend.Length != 2) { - throw new ArgumentException("extend"); - } - SetExtend(extend[0], extend[1]); - } - - /// Creates the new instance of the class. - /// - /// the - /// - /// object in which colour values shall be expressed. - /// The Indexed color space isn't excepted. - /// - /// - /// the - /// - /// of of six numbers [x0 y0 r0 x1 y1 r1], - /// specifying the centres and radii of the starting and ending circles, - /// expressed in the shading’s target coordinate space. - /// The radii r0 and r1 shall both be greater than or equal to 0. - /// If one radius is 0, the corresponding circle shall be treated as a point; - /// if both are 0, nothing shall be painted. - /// - /// - /// the - /// - /// object, that is used to calculate color transitions. - /// - public Radial(PdfColorSpace cs, PdfArray coords, IPdfFunction function) - : base(new PdfDictionary(), PdfShading.ShadingType.RADIAL, cs) { - SetCoords(coords); - SetFunction(function); - } - - /// - /// Gets the coords - /// - /// object - an array of six numbers [x0 y0 r0 x1 y1 r1], - /// specifying the centres and radii of the starting and ending circles, - /// expressed in the shading’s target coordinate space. - /// - /// - /// Gets the coords - /// - /// object - an array of six numbers [x0 y0 r0 x1 y1 r1], - /// specifying the centres and radii of the starting and ending circles, - /// expressed in the shading’s target coordinate space. - /// The radii r0 and r1 shall both be greater than or equal to 0. - /// If one radius is 0, the corresponding circle shall be treated as a point; - /// if both are 0, nothing shall be painted. - /// - /// - /// the - /// - /// coords object. - /// - public virtual PdfArray GetCoords() { - return GetPdfObject().GetAsArray(PdfName.Coords); - } - - /// Sets the coords object. - /// the X coordinate of starting circle's centre, expressed in in the shading’s target coordinate space. - /// - /// the Y coordinate of starting circle's centre, expressed in in the shading’s target coordinate space. - /// - /// - /// the radius of starting circle's centre, should be greater or equal to 0. - /// If 0 then starting circle is treated as point. - /// If both radii are 0, nothing shall be painted. - /// - /// the X coordinate of ending circle's centre, expressed in in the shading’s target coordinate space. - /// - /// the Y coordinate of ending circle's centre, expressed in in the shading’s target coordinate space. - /// - /// - /// the radius of ending circle's centre, should be greater or equal to 0. - /// If 0 then ending circle is treated as point. - /// If both radii are 0, nothing shall be painted. - /// - public virtual void SetCoords(float x0, float y0, float r0, float x1, float y1, float r1) { - SetCoords(new PdfArray(new float[] { x0, y0, r0, x1, y1, r1 })); - } - - /// - /// Sets the coords - /// - /// object - an array of six numbers [x0 y0 r0 x1 y1 r1], - /// specifying the centres and radii of the starting and ending circles, - /// expressed in the shading’s target coordinate space. - /// - /// - /// Sets the coords - /// - /// object - an array of six numbers [x0 y0 r0 x1 y1 r1], - /// specifying the centres and radii of the starting and ending circles, - /// expressed in the shading’s target coordinate space. - /// The radii r0 and r1 shall both be greater than or equal to 0. - /// If one radius is 0, the corresponding circle shall be treated as a point; - /// if both are 0, nothing shall be painted. - /// - /// - /// - - /// - /// choords object to be set. - /// - public virtual void SetCoords(PdfArray coords) { - GetPdfObject().Put(PdfName.Coords, coords); - SetModified(); - } - - /// - /// Gets the - /// - /// of two - /// float - /// [t0, t1] that represent the limiting values of a parametric - /// variable t, that becomes an input of color function(s). - /// - /// - /// the - /// - /// of Domain object ([0.0 1.0] by default) - /// - public virtual PdfArray GetDomain() { - PdfArray domain = GetPdfObject().GetAsArray(PdfName.Domain); - if (domain == null) { - domain = new PdfArray(new float[] { 0, 1 }); - SetDomain(domain); - } - return domain; - } - - /// - /// Sets the Domain with the array of two - /// float - /// [t0, t1] that represent the limiting values - /// of a parametric variable t, that becomes an input of color function(s). - /// - /// first limit of variable t - /// second limit of variable t - public virtual void SetDomain(float t0, float t1) { - SetDomain(new PdfArray(new float[] { t0, t1 })); - } - - /// - /// Sets the Domain with the - /// - /// of two - /// float - /// [t0, t1] that represent the limiting values - /// of a parametric variable t, that becomes an input of color function(s). - /// - /// - /// the - /// - /// that represents domain - /// - public virtual void SetDomain(PdfArray domain) { - GetPdfObject().Put(PdfName.Domain, domain); - SetModified(); - } - - /// - /// Gets the - /// - /// of two - /// boolean - /// that specified whether to extend the shading - /// beyond the starting and ending circles of the axis, respectively. - /// - /// - /// the - /// - /// of Extended object ([false false] by default) - /// - public virtual PdfArray GetExtend() { - PdfArray extend = GetPdfObject().GetAsArray(PdfName.Extend); - if (extend == null) { - extend = new PdfArray(new bool[] { false, false }); - SetExtend(extend); - } - return extend; - } - - /// - /// Sets the Extend object with the two - /// boolean - /// value. - /// - /// if true will extend shading beyond the starting circle of Coords. - /// if true will extend shading beyond the ending circle of Coords. - public virtual void SetExtend(bool extendStart, bool extendEnd) { - SetExtend(new PdfArray(new bool[] { extendStart, extendEnd })); - } - - /// - /// Sets the Extend object with the - /// - /// of two - /// boolean. - /// - /// - /// Sets the Extend object with the - /// - /// of two - /// boolean. - /// If first is true shading will extend beyond the starting circle of Coords. - /// If second is true shading will extend beyond the ending circle of Coords. - /// - /// - /// the - /// - /// representing Extend object - /// - public virtual void SetExtend(PdfArray extend) { - GetPdfObject().Put(PdfName.Extend, extend); - SetModified(); - } - } - - /// - /// The class that extends - /// - /// class and is in charge of Shading Dictionary with - /// free-form Gouraud-shaded triangle mesh type. - /// - /// - /// The class that extends - /// - /// class and is in charge of Shading Dictionary with - /// free-form Gouraud-shaded triangle mesh type. - /// The area to be shaded is defined by a path composed entirely of triangles. - /// The colour at each vertex of the triangles is specified, - /// and a technique known as Gouraud interpolation is used to colour the interiors. - /// The object shall be represented as stream containing a sequence of vertex data. - /// Each vertex is specified by the following values, in the order shown: - /// f x y c1 ... cn where: - /// f - the vertex's edge flag, that determines the vertex is connected to other vertices of the triangle mesh. - /// For full description, see ISO-320001 Paragraph 8.7.4.5.5 - /// x, y - vertex's horizontal and vertical coordinates, expressed in the shading's target coordinate space. - /// c1...cn - vertex's colour components. - /// If the shading dictionary includes a Function entry, only a single parametric value, t, - /// shall be specified for each vertex in place of the colour components c1...cn. - /// - public class FreeFormGouraudShadedTriangleMesh : PdfShading { - /// - /// Creates the new instance of the class from the existing - /// . - /// - /// - /// from which this - /// - /// will be created - /// - protected internal FreeFormGouraudShadedTriangleMesh(PdfStream pdfStream) - : base(pdfStream) { - } - - /// Creates the new instance of the class. - /// - /// the - /// - /// object in which colour values shall be expressed. - /// The special Pattern space isn't excepted. - /// - /// - /// the number of bits used to represent each vertex coordinate. - /// The value shall be 1, 2, 4, 8, 12, 16, 24, or 32. - /// - /// - /// the number of bits used to represent each colour component. - /// The value shall be 1, 2, 4, 8, 12, or 16. - /// - /// - /// the number of bits used to represent the edge flag for each vertex. - /// The value of BitsPerFlag shall be 2, 4, or 8, - /// but only the least significant 2 bits in each flag value shall be used. - /// The value for the edge flag shall be 0, 1, or 2. - /// - /// - /// the - /// int[] - /// of numbers specifying how to map vertex coordinates and colour components - /// into the appropriate ranges of values. The ranges shall be specified as follows: - /// [x_min x_max y_min y_max c1_min c1_max … cn_min cn_max]. - /// Only one pair of color values shall be specified if a Function entry is present. - /// - public FreeFormGouraudShadedTriangleMesh(PdfColorSpace cs, int bitsPerCoordinate, int bitsPerComponent, int - bitsPerFlag, float[] decode) - : this(cs, bitsPerCoordinate, bitsPerComponent, bitsPerFlag, new PdfArray(decode)) { - } - - /// Creates the new instance of the class. - /// - /// the - /// - /// object in which colour values shall be expressed. - /// The special Pattern space isn't excepted. - /// - /// - /// the number of bits used to represent each vertex coordinate. - /// The value shall be 1, 2, 4, 8, 12, 16, 24, or 32. - /// - /// - /// the number of bits used to represent each colour component. - /// The value shall be 1, 2, 4, 8, 12, or 16. - /// - /// - /// the number of bits used to represent the edge flag for each vertex. - /// The value of BitsPerFlag shall be 2, 4, or 8, - /// but only the least significant 2 bits in each flag value shall be used. - /// The value for the edge flag shall be 0, 1, or 2. - /// - /// - /// the - /// - /// of numbers specifying how to map vertex coordinates and colour components - /// into the appropriate ranges of values. The ranges shall be specified as follows: - /// [x_min x_max y_min y_max c1_min c1_max … cn_min cn_max]. - /// Only one pair of color values shall be specified if a Function entry is present. - /// - public FreeFormGouraudShadedTriangleMesh(PdfColorSpace cs, int bitsPerCoordinate, int bitsPerComponent, int - bitsPerFlag, PdfArray decode) - : base(new PdfStream(), PdfShading.ShadingType.FREE_FORM_GOURAUD_SHADED_TRIANGLE_MESH, cs) { - SetBitsPerCoordinate(bitsPerCoordinate); - SetBitsPerComponent(bitsPerComponent); - SetBitsPerFlag(bitsPerFlag); - SetDecode(decode); - } - - /// Gets the number of bits used to represent each vertex coordinate. - /// the number of bits. Can be 1, 2, 4, 8, 12, 16, 24, or 32. - public virtual int GetBitsPerCoordinate() { - return (int)GetPdfObject().GetAsInt(PdfName.BitsPerCoordinate); - } - - /// Sets the number of bits used to represent each vertex coordinate. - /// the number of bits to be set. Shall be 1, 2, 4, 8, 12, 16, 24, or 32. - public virtual void SetBitsPerCoordinate(int bitsPerCoordinate) { - GetPdfObject().Put(PdfName.BitsPerCoordinate, new PdfNumber(bitsPerCoordinate)); - SetModified(); - } - - /// Gets the number of bits used to represent each colour component. - /// the number of bits. Can be 1, 2, 4, 8, 12, or 16. - public virtual int GetBitsPerComponent() { - return (int)GetPdfObject().GetAsInt(PdfName.BitsPerComponent); - } - - /// Sets the number of bits used to represent each colour component. - /// the number of bits to be set. Shall be 1, 2, 4, 8, 12, or 16. - public virtual void SetBitsPerComponent(int bitsPerComponent) { - GetPdfObject().Put(PdfName.BitsPerComponent, new PdfNumber(bitsPerComponent)); - SetModified(); - } - - /// Gets the number of bits used to represent the edge flag for each vertex. - /// - /// Gets the number of bits used to represent the edge flag for each vertex. - /// But only the least significant 2 bits in each flag value shall be used. - /// The valid flag values are 0, 1 or 2. - /// - /// the number of bits. Can be 2, 4 or 8. - public virtual int GetBitsPerFlag() { - return (int)GetPdfObject().GetAsInt(PdfName.BitsPerFlag); - } - - /// Sets the number of bits used to represent the edge flag for each vertex. - /// - /// Sets the number of bits used to represent the edge flag for each vertex. - /// But only the least significant 2 bits in each flag value shall be used. - /// The valid flag values are 0, 1 or 2. - /// - /// the number of bits to be set. Shall be 2, 4 or 8. - public virtual void SetBitsPerFlag(int bitsPerFlag) { - GetPdfObject().Put(PdfName.BitsPerFlag, new PdfNumber(bitsPerFlag)); - SetModified(); - } - - /// - /// Gets the - /// - /// of numbers specifying how to map vertex coordinates and colour components - /// into the appropriate ranges of values. - /// - /// - /// Gets the - /// - /// of numbers specifying how to map vertex coordinates and colour components - /// into the appropriate ranges of values. The ranges shall be specified as follows: - /// [x_min x_max y_min y_max c1_min c1_max … cn_min cn_max]. - /// Only one pair of color values shall be specified if a Function entry is present. - /// - /// - /// the - /// - /// Decode object. - /// - public virtual PdfArray GetDecode() { - return GetPdfObject().GetAsArray(PdfName.Decode); - } - - /// - /// Sets the - /// float[] - /// of numbers specifying how to map vertex coordinates and colour components - /// into the appropriate ranges of values. - /// - /// - /// Sets the - /// float[] - /// of numbers specifying how to map vertex coordinates and colour components - /// into the appropriate ranges of values. The ranges shall be specified as follows: - /// [x_min x_max y_min y_max c1_min c1_max … cn_min cn_max]. - /// Only one pair of color values shall be specified if a Function entry is present. - /// - /// - /// the - /// float[] - /// of Decode object to set. - /// - public virtual void SetDecode(float[] decode) { - SetDecode(new PdfArray(decode)); - } - - /// - /// Sets the - /// - /// of numbers specifying how to map vertex coordinates and colour components - /// into the appropriate ranges of values. - /// - /// - /// Sets the - /// - /// of numbers specifying how to map vertex coordinates and colour components - /// into the appropriate ranges of values. The ranges shall be specified as follows: - /// [x_min x_max y_min y_max c1_min c1_max … cn_min cn_max]. - /// Only one pair of color values shall be specified if a Function entry is present. - /// - /// - /// the - /// - /// Decode object to set. - /// - public virtual void SetDecode(PdfArray decode) { - GetPdfObject().Put(PdfName.Decode, decode); - SetModified(); - } - } - - /// - /// The class that extends - /// - /// class and is in charge of Shading Dictionary with - /// lattice-form Gouraud-shaded triangle mesh type. - /// - /// - /// The class that extends - /// - /// class and is in charge of Shading Dictionary with - /// lattice-form Gouraud-shaded triangle mesh type. - /// This type is similar to - /// - /// but instead of using free-form geometry, - /// the vertices are arranged in a pseudorectangular lattice, - /// which is topologically equivalent to a rectangular grid. - /// The vertices are organized into rows, which need not be geometrically linear. - /// The verticals data in stream is similar to - /// - /// , - /// except there is no edge flag. - /// - public class LatticeFormGouraudShadedTriangleMesh : PdfShading { - /// - /// Creates the new instance of the class from the existing - /// . - /// - /// - /// from which this - /// - /// will be created - /// - protected internal LatticeFormGouraudShadedTriangleMesh(PdfStream pdfStream) - : base(pdfStream) { - } - - /// Creates the new instance of the class. - /// - /// the - /// - /// object in which colour values shall be expressed. - /// The special Pattern space isn't excepted. - /// - /// - /// the number of bits used to represent each vertex coordinate. - /// The value shall be 1, 2, 4, 8, 12, 16, 24, or 32. - /// - /// - /// the number of bits used to represent each colour component. - /// The value shall be 1, 2, 4, 8, 12, or 16. - /// - /// - /// the number of vertices in each row of the lattice (shall be > 1). - /// The number of rows need not be specified. - /// - /// - /// the - /// int[] - /// of numbers specifying how to map vertex coordinates and colour components - /// into the appropriate ranges of values. The ranges shall be specified as follows: - /// [x_min x_max y_min y_max c1_min c1_max … cn_min cn_max]. - /// Only one pair of color values shall be specified if a Function entry is present. - /// - public LatticeFormGouraudShadedTriangleMesh(PdfColorSpace cs, int bitsPerCoordinate, int bitsPerComponent, - int verticesPerRow, float[] decode) - : this(cs, bitsPerCoordinate, bitsPerComponent, verticesPerRow, new PdfArray(decode)) { - } - - /// Creates the new instance of the class. - /// - /// the - /// - /// object in which colour values shall be expressed. - /// The special Pattern space isn't excepted. - /// - /// - /// the number of bits used to represent each vertex coordinate. - /// The value shall be 1, 2, 4, 8, 12, 16, 24, or 32. - /// - /// - /// the number of bits used to represent each colour component. - /// The value shall be 1, 2, 4, 8, 12, or 16. - /// - /// - /// the number of vertices in each row of the lattice (shall be > 1). - /// The number of rows need not be specified. - /// - /// - /// the - /// - /// of numbers specifying how to map vertex coordinates and colour components - /// into the appropriate ranges of values. The ranges shall be specified as follows: - /// [x_min x_max y_min y_max c1_min c1_max … cn_min cn_max]. - /// Only one pair of color values shall be specified if a Function entry is present. - /// - public LatticeFormGouraudShadedTriangleMesh(PdfColorSpace cs, int bitsPerCoordinate, int bitsPerComponent, - int verticesPerRow, PdfArray decode) - : base(new PdfStream(), PdfShading.ShadingType.LATTICE_FORM_GOURAUD_SHADED_TRIANGLE_MESH, cs) { - SetBitsPerCoordinate(bitsPerCoordinate); - SetBitsPerComponent(bitsPerComponent); - SetVerticesPerRow(verticesPerRow); - SetDecode(decode); - } - - /// Gets the number of bits used to represent each vertex coordinate. - /// the number of bits. Can be 1, 2, 4, 8, 12, 16, 24, or 32. - public virtual int GetBitsPerCoordinate() { - return (int)GetPdfObject().GetAsInt(PdfName.BitsPerCoordinate); - } - - /// Sets the number of bits used to represent each vertex coordinate. - /// the number of bits to be set. Shall be 1, 2, 4, 8, 12, 16, 24, or 32. - public virtual void SetBitsPerCoordinate(int bitsPerCoordinate) { - GetPdfObject().Put(PdfName.BitsPerCoordinate, new PdfNumber(bitsPerCoordinate)); - SetModified(); - } - - /// Gets the number of bits used to represent each colour component. - /// the number of bits. Can be 1, 2, 4, 8, 12, or 16. - public virtual int GetBitsPerComponent() { - return (int)GetPdfObject().GetAsInt(PdfName.BitsPerComponent); - } - - /// Sets the number of bits used to represent each colour component. - /// the number of bits to be set. Shall be 1, 2, 4, 8, 12, or 16. - public virtual void SetBitsPerComponent(int bitsPerComponent) { - GetPdfObject().Put(PdfName.BitsPerComponent, new PdfNumber(bitsPerComponent)); - SetModified(); - } - - /// Gets the number of vertices in each row of the lattice. - /// the number of vertices. Can only be greater than 1. - public virtual int GetVerticesPerRow() { - return (int)GetPdfObject().GetAsInt(PdfName.VerticesPerRow); - } - - /// Sets the number of vertices in each row of the lattice. - /// - /// Sets the number of vertices in each row of the lattice. - /// The number of rows need not be specified. - /// - /// the number of vertices to be set. Shall be greater than 1. - public virtual void SetVerticesPerRow(int verticesPerRow) { - GetPdfObject().Put(PdfName.VerticesPerRow, new PdfNumber(verticesPerRow)); - SetModified(); - } - - /// - /// Gets the - /// - /// of numbers specifying how to map vertex coordinates and colour components - /// into the appropriate ranges of values. - /// - /// - /// Gets the - /// - /// of numbers specifying how to map vertex coordinates and colour components - /// into the appropriate ranges of values. The ranges shall be specified as follows: - /// [x_min x_max y_min y_max c1_min c1_max … cn_min cn_max]. - /// Only one pair of color values shall be specified if a Function entry is present. - /// - /// - /// the - /// - /// Decode object. - /// - public virtual PdfArray GetDecode() { - return GetPdfObject().GetAsArray(PdfName.Decode); - } - - /// - /// Sets the - /// float[] - /// of numbers specifying how to map vertex coordinates and colour components - /// into the appropriate ranges of values. - /// - /// - /// Sets the - /// float[] - /// of numbers specifying how to map vertex coordinates and colour components - /// into the appropriate ranges of values. The ranges shall be specified as follows: - /// [x_min x_max y_min y_max c1_min c1_max … cn_min cn_max]. - /// Only one pair of color values shall be specified if a Function entry is present. - /// - /// - /// the - /// float[] - /// of Decode object to set. - /// - public virtual void SetDecode(float[] decode) { - SetDecode(new PdfArray(decode)); - } - - /// - /// Sets the - /// - /// of numbers specifying how to map vertex coordinates and colour components - /// into the appropriate ranges of values. - /// - /// - /// Sets the - /// - /// of numbers specifying how to map vertex coordinates and colour components - /// into the appropriate ranges of values. The ranges shall be specified as follows: - /// [x_min x_max y_min y_max c1_min c1_max … cn_min cn_max]. - /// Only one pair of color values shall be specified if a Function entry is present. - /// - /// - /// the - /// - /// Decode object to set. - /// - public virtual void SetDecode(PdfArray decode) { - GetPdfObject().Put(PdfName.Decode, decode); - SetModified(); - } - } - - /// - /// The class that extends - /// - /// class and is in charge of Shading Dictionary with - /// Coons Patch mesh type. - /// - /// - /// The class that extends - /// - /// class and is in charge of Shading Dictionary with - /// Coons Patch mesh type. - /// This type of shading is constructed from one or more colour patches, each bounded by four cubic Bézier curves. - /// Degenerate Bézier curves are allowed and are useful for certain graphical effects. - /// At least one complete patch shall be specified. - /// The shape of patch is defined by 12 control points. - /// Colours are specified for each corner of the unit square, - /// and bilinear interpolation is used to fill in colours over the entire unit square. - /// Coordinates are mapped from the unit square into a four-sided patch whose sides are not necessarily linear. - /// The mapping is continuous: the corners of the unit square map to corners of the patch - /// and the sides of the unit square map to sides of the patch. - /// For the format of data stream, that defines patches (see ISO-320001 Table 85). - /// If the shading dictionary contains a Function entry, the colour data for each corner of a patch - /// shall be specified by a single parametric value t rather than by n separate colour components c1...cn. - /// - public class CoonsPatchMesh : PdfShading { - /// - /// Creates the new instance of the class from the existing - /// . - /// - /// - /// from which this - /// - /// will be created - /// - protected internal CoonsPatchMesh(PdfStream pdfStream) - : base(pdfStream) { - } - - /// Creates the new instance of the class. - /// - /// the - /// - /// object in which colour values shall be expressed. - /// The special Pattern space isn't excepted. - /// - /// - /// the number of bits used to represent each vertex coordinate. - /// The value shall be 1, 2, 4, 8, 12, 16, 24, or 32. - /// - /// - /// the number of bits used to represent each colour component. - /// The value shall be 1, 2, 4, 8, 12, or 16. - /// - /// - /// the number of bits used to represent the edge flag for each vertex. - /// The value of BitsPerFlag shall be 2, 4, or 8, - /// but only the least significant 2 bits in each flag value shall be used. - /// The value for the edge flag shall be 0, 1, 2 or 3. - /// - /// - /// the - /// int[] - /// of numbers specifying how to map vertex coordinates and colour components - /// into the appropriate ranges of values. The ranges shall be specified as follows: - /// [x_min x_max y_min y_max c1_min c1_max … cn_min cn_max]. - /// Only one pair of color values shall be specified if a Function entry is present. - /// - public CoonsPatchMesh(PdfColorSpace cs, int bitsPerCoordinate, int bitsPerComponent, int bitsPerFlag, float - [] decode) - : this(cs, bitsPerCoordinate, bitsPerComponent, bitsPerFlag, new PdfArray(decode)) { - } - - /// Creates the new instance of the class. - /// - /// the - /// - /// object in which colour values shall be expressed. - /// The special Pattern space isn't excepted. - /// - /// - /// the number of bits used to represent each vertex coordinate. - /// The value shall be 1, 2, 4, 8, 12, 16, 24, or 32. - /// - /// - /// the number of bits used to represent each colour component. - /// The value shall be 1, 2, 4, 8, 12, or 16. - /// - /// - /// the number of bits used to represent the edge flag for each vertex. - /// The value of BitsPerFlag shall be 2, 4, or 8, - /// but only the least significant 2 bits in each flag value shall be used. - /// The value for the edge flag shall be 0, 1, 2 or 3. - /// - /// - /// the - /// - /// of numbers specifying how to map vertex coordinates and colour components - /// into the appropriate ranges of values. The ranges shall be specified as follows: - /// [x_min x_max y_min y_max c1_min c1_max … cn_min cn_max]. - /// Only one pair of color values shall be specified if a Function entry is present. - /// - public CoonsPatchMesh(PdfColorSpace cs, int bitsPerCoordinate, int bitsPerComponent, int bitsPerFlag, PdfArray - decode) - : base(new PdfStream(), PdfShading.ShadingType.COONS_PATCH_MESH, cs) { - SetBitsPerCoordinate(bitsPerCoordinate); - SetBitsPerComponent(bitsPerComponent); - SetBitsPerFlag(bitsPerFlag); - SetDecode(decode); - } - - /// Gets the number of bits used to represent each vertex coordinate. - /// the number of bits. Can be 1, 2, 4, 8, 12, 16, 24, or 32. - public virtual int GetBitsPerCoordinate() { - return (int)GetPdfObject().GetAsInt(PdfName.BitsPerCoordinate); - } - - /// Sets the number of bits used to represent each vertex coordinate. - /// the number of bits to be set. Shall be 1, 2, 4, 8, 12, 16, 24, or 32. - public virtual void SetBitsPerCoordinate(int bitsPerCoordinate) { - GetPdfObject().Put(PdfName.BitsPerCoordinate, new PdfNumber(bitsPerCoordinate)); - SetModified(); - } - - /// Gets the number of bits used to represent each colour component. - /// the number of bits. Can be 1, 2, 4, 8, 12, or 16. - public virtual int GetBitsPerComponent() { - return (int)GetPdfObject().GetAsInt(PdfName.BitsPerComponent); - } - - /// Sets the number of bits used to represent each colour component. - /// the number of bits to be set. Shall be 1, 2, 4, 8, 12, or 16. - public virtual void SetBitsPerComponent(int bitsPerComponent) { - GetPdfObject().Put(PdfName.BitsPerComponent, new PdfNumber(bitsPerComponent)); - SetModified(); - } - - /// Gets the number of bits used to represent the edge flag for each vertex. - /// - /// Gets the number of bits used to represent the edge flag for each vertex. - /// But only the least significant 2 bits in each flag value shall be used. - /// The valid flag values are 0, 1, 2 or 3. - /// - /// the number of bits. Can be 2, 4 or 8. - public virtual int GetBitsPerFlag() { - return (int)GetPdfObject().GetAsInt(PdfName.BitsPerFlag); - } - - /// Sets the number of bits used to represent the edge flag for each vertex. - /// - /// Sets the number of bits used to represent the edge flag for each vertex. - /// But only the least significant 2 bits in each flag value shall be used. - /// The valid flag values are 0, 1, 2 or 3. - /// - /// the number of bits to be set. Shall be 2, 4 or 8. - public virtual void SetBitsPerFlag(int bitsPerFlag) { - GetPdfObject().Put(PdfName.BitsPerFlag, new PdfNumber(bitsPerFlag)); - SetModified(); - } - - /// - /// Gets the - /// - /// of numbers specifying how to map vertex coordinates and colour components - /// into the appropriate ranges of values. - /// - /// - /// Gets the - /// - /// of numbers specifying how to map vertex coordinates and colour components - /// into the appropriate ranges of values. The ranges shall be specified as follows: - /// [x_min x_max y_min y_max c1_min c1_max … cn_min cn_max]. - /// Only one pair of color values shall be specified if a Function entry is present. - /// - /// - /// the - /// - /// Decode object. - /// - public virtual PdfArray GetDecode() { - return GetPdfObject().GetAsArray(PdfName.Decode); - } - - /// - /// Sets the - /// float[] - /// of numbers specifying how to map vertex coordinates and colour components - /// into the appropriate ranges of values. - /// - /// - /// Sets the - /// float[] - /// of numbers specifying how to map vertex coordinates and colour components - /// into the appropriate ranges of values. The ranges shall be specified as follows: - /// [x_min x_max y_min y_max c1_min c1_max … cn_min cn_max]. - /// Only one pair of color values shall be specified if a Function entry is present. - /// - /// - /// the - /// float[] - /// of Decode object to set. - /// - public virtual void SetDecode(float[] decode) { - SetDecode(new PdfArray(decode)); - } - - /// - /// Sets the - /// - /// of numbers specifying how to map vertex coordinates and colour components - /// into the appropriate ranges of values. - /// - /// - /// Sets the - /// - /// of numbers specifying how to map vertex coordinates and colour components - /// into the appropriate ranges of values. The ranges shall be specified as follows: - /// [x_min x_max y_min y_max c1_min c1_max … cn_min cn_max]. - /// Only one pair of color values shall be specified if a Function entry is present. - /// - /// - /// the - /// - /// Decode object to set. - /// - public virtual void SetDecode(PdfArray decode) { - GetPdfObject().Put(PdfName.Decode, decode); - SetModified(); - } - } - - /// - /// The class that extends - /// - /// class and is in charge of Shading Dictionary with - /// Tensor-Product Patch mesh type. - /// - /// - /// The class that extends - /// - /// class and is in charge of Shading Dictionary with - /// Tensor-Product Patch mesh type. - /// This type of shading is identical to - /// - /// , except that it's based on a - /// bicubic tensor-product patch defined by 16 control points. - /// For the format of data stream, that defines patches, see ISO-320001 Table 86. - /// - public class TensorProductPatchMesh : PdfShading { - /// - /// Creates the new instance of the class from the existing - /// . - /// - /// - /// from which this - /// - /// will be created - /// - protected internal TensorProductPatchMesh(PdfStream pdfStream) - : base(pdfStream) { - } - - /// Creates the new instance of the class. - /// - /// the - /// - /// object in which colour values shall be expressed. - /// The special Pattern space isn't excepted. - /// - /// - /// the number of bits used to represent each vertex coordinate. - /// The value shall be 1, 2, 4, 8, 12, 16, 24, or 32. - /// - /// - /// the number of bits used to represent each colour component. - /// The value shall be 1, 2, 4, 8, 12, or 16. - /// - /// - /// the number of bits used to represent the edge flag for each vertex. - /// The value of BitsPerFlag shall be 2, 4, or 8, - /// but only the least significant 2 bits in each flag value shall be used. - /// The value for the edge flag shall be 0, 1, 2 or 3. - /// - /// - /// the - /// int[] - /// of numbers specifying how to map vertex coordinates and colour components - /// into the appropriate ranges of values. The ranges shall be specified as follows: - /// [x_min x_max y_min y_max c1_min c1_max … cn_min cn_max]. - /// Only one pair of color values shall be specified if a Function entry is present. - /// - public TensorProductPatchMesh(PdfColorSpace cs, int bitsPerCoordinate, int bitsPerComponent, int bitsPerFlag - , float[] decode) - : this(cs, bitsPerCoordinate, bitsPerComponent, bitsPerFlag, new PdfArray(decode)) { - } - - /// Creates the new instance of the class. - /// - /// the - /// - /// object in which colour values shall be expressed. - /// The special Pattern space isn't excepted. - /// - /// - /// the number of bits used to represent each vertex coordinate. - /// The value shall be 1, 2, 4, 8, 12, 16, 24, or 32. - /// - /// - /// the number of bits used to represent each colour component. - /// The value shall be 1, 2, 4, 8, 12, or 16. - /// - /// - /// the number of bits used to represent the edge flag for each vertex. - /// The value of BitsPerFlag shall be 2, 4, or 8, - /// but only the least significant 2 bits in each flag value shall be used. - /// The value for the edge flag shall be 0, 1, 2 or 3. - /// - /// - /// the - /// - /// of numbers specifying how to map vertex coordinates and colour components - /// into the appropriate ranges of values. The ranges shall be specified as follows: - /// [x_min x_max y_min y_max c1_min c1_max … cn_min cn_max]. - /// Only one pair of color values shall be specified if a Function entry is present. - /// - public TensorProductPatchMesh(PdfColorSpace cs, int bitsPerCoordinate, int bitsPerComponent, int bitsPerFlag - , PdfArray decode) - : base(new PdfStream(), PdfShading.ShadingType.TENSOR_PRODUCT_PATCH_MESH, cs) { - SetBitsPerCoordinate(bitsPerCoordinate); - SetBitsPerComponent(bitsPerComponent); - SetBitsPerFlag(bitsPerFlag); - SetDecode(decode); - } - - /// Gets the number of bits used to represent each vertex coordinate. - /// the number of bits. Can be 1, 2, 4, 8, 12, 16, 24, or 32. - public virtual int GetBitsPerCoordinate() { - return (int)GetPdfObject().GetAsInt(PdfName.BitsPerCoordinate); - } - - /// Sets the number of bits used to represent each vertex coordinate. - /// the number of bits to be set. Shall be 1, 2, 4, 8, 12, 16, 24, or 32. - public virtual void SetBitsPerCoordinate(int bitsPerCoordinate) { - GetPdfObject().Put(PdfName.BitsPerCoordinate, new PdfNumber(bitsPerCoordinate)); - SetModified(); - } - - /// Gets the number of bits used to represent each colour component. - /// the number of bits. Can be 1, 2, 4, 8, 12, or 16. - public virtual int GetBitsPerComponent() { - return (int)GetPdfObject().GetAsInt(PdfName.BitsPerComponent); - } - - /// Sets the number of bits used to represent each colour component. - /// the number of bits to be set. Shall be 1, 2, 4, 8, 12, or 16. - public virtual void SetBitsPerComponent(int bitsPerComponent) { - GetPdfObject().Put(PdfName.BitsPerComponent, new PdfNumber(bitsPerComponent)); - SetModified(); - } - - /// Gets the number of bits used to represent the edge flag for each vertex. - /// - /// Gets the number of bits used to represent the edge flag for each vertex. - /// But only the least significant 2 bits in each flag value shall be used. - /// The valid flag values are 0, 1, 2 or 3. - /// - /// the number of bits. Can be 2, 4 or 8. - public virtual int GetBitsPerFlag() { - return (int)GetPdfObject().GetAsInt(PdfName.BitsPerFlag); - } - - /// Sets the number of bits used to represent the edge flag for each vertex. - /// - /// Sets the number of bits used to represent the edge flag for each vertex. - /// But only the least significant 2 bits in each flag value shall be used. - /// The valid flag values are 0, 1, 2 or 3. - /// - /// the number of bits to be set. Shall be 2, 4 or 8. - public virtual void SetBitsPerFlag(int bitsPerFlag) { - GetPdfObject().Put(PdfName.BitsPerFlag, new PdfNumber(bitsPerFlag)); - SetModified(); - } - - /// - /// Gets the - /// - /// of numbers specifying how to map vertex coordinates and colour components - /// into the appropriate ranges of values. - /// - /// - /// Gets the - /// - /// of numbers specifying how to map vertex coordinates and colour components - /// into the appropriate ranges of values. The ranges shall be specified as follows: - /// [x_min x_max y_min y_max c1_min c1_max … cn_min cn_max]. - /// Only one pair of color values shall be specified if a Function entry is present. - /// - /// - /// the - /// - /// Decode object. - /// - public virtual PdfArray GetDecode() { - return GetPdfObject().GetAsArray(PdfName.Decode); - } - - /// - /// Sets the - /// float[] - /// of numbers specifying how to map vertex coordinates and colour components - /// into the appropriate ranges of values. - /// - /// - /// Sets the - /// float[] - /// of numbers specifying how to map vertex coordinates and colour components - /// into the appropriate ranges of values. The ranges shall be specified as follows: - /// [x_min x_max y_min y_max c1_min c1_max … cn_min cn_max]. - /// Only one pair of color values shall be specified if a Function entry is present. - /// - /// - /// the - /// float[] - /// of Decode object to set. - /// - public virtual void SetDecode(float[] decode) { - SetDecode(new PdfArray(decode)); - } - - /// - /// Sets the - /// - /// of numbers specifying how to map vertex coordinates and colour components - /// into the appropriate ranges of values. - /// - /// - /// Sets the - /// - /// of numbers specifying how to map vertex coordinates and colour components - /// into the appropriate ranges of values. The ranges shall be specified as follows: - /// [x_min x_max y_min y_max c1_min c1_max … cn_min cn_max]. - /// Only one pair of color values shall be specified if a Function entry is present. - /// - /// - /// the - /// - /// Decode object to set. - /// - public virtual void SetDecode(PdfArray decode) { - GetPdfObject().Put(PdfName.Decode, decode); - SetModified(); - } - } - } -} diff --git a/itext/itext.kernel/itext/kernel/pdf/colorspace/shading/AbstractPdfShading.cs b/itext/itext.kernel/itext/kernel/pdf/colorspace/shading/AbstractPdfShading.cs new file mode 100644 index 0000000000..10653413e9 --- /dev/null +++ b/itext/itext.kernel/itext/kernel/pdf/colorspace/shading/AbstractPdfShading.cs @@ -0,0 +1,257 @@ +/* +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 . +*/ +using System; +using iText.Kernel.Exceptions; +using iText.Kernel.Pdf; +using iText.Kernel.Pdf.Colorspace; +using iText.Kernel.Pdf.Function; + +namespace iText.Kernel.Pdf.Colorspace.Shading { + /// The PdfShading class that represents the Shading Dictionary PDF object. + public abstract class AbstractPdfShading : PdfObjectWrapper { + /// + /// Creates the + /// + /// object from the existing + /// + /// with corresponding type. + /// + /// + /// + /// + /// from which the + /// + /// object will be created + /// + /// + /// Created + /// + /// object + /// + public static iText.Kernel.Pdf.Colorspace.Shading.AbstractPdfShading MakeShading(PdfDictionary shadingDictionary + ) { + if (!shadingDictionary.ContainsKey(PdfName.ShadingType)) { + throw new PdfException(KernelExceptionMessageConstant.SHADING_TYPE_NOT_FOUND); + } + if (!shadingDictionary.ContainsKey(PdfName.ColorSpace)) { + throw new PdfException(KernelExceptionMessageConstant.COLOR_SPACE_NOT_FOUND); + } + iText.Kernel.Pdf.Colorspace.Shading.AbstractPdfShading shading; + switch (shadingDictionary.GetAsNumber(PdfName.ShadingType).IntValue()) { + case ShadingType.FUNCTION_BASED: { + shading = new PdfFunctionBasedShading(shadingDictionary); + break; + } + + case ShadingType.AXIAL: { + shading = new PdfAxialShading(shadingDictionary); + break; + } + + case ShadingType.RADIAL: { + shading = new PdfRadialShading(shadingDictionary); + break; + } + + case ShadingType.FREE_FORM_GOURAUD_SHADED_TRIANGLE_MESH: { + if (!shadingDictionary.IsStream()) { + throw new PdfException(KernelExceptionMessageConstant.UNEXPECTED_SHADING_TYPE); + } + shading = new PdfFreeFormGouraudShadedTriangleShading((PdfStream)shadingDictionary); + break; + } + + case ShadingType.LATTICE_FORM_GOURAUD_SHADED_TRIANGLE_MESH: { + if (!shadingDictionary.IsStream()) { + throw new PdfException(KernelExceptionMessageConstant.UNEXPECTED_SHADING_TYPE); + } + shading = new PdfLatticeFormGouraudShadedTriangleShading((PdfStream)shadingDictionary); + break; + } + + case ShadingType.COONS_PATCH_MESH: { + if (!shadingDictionary.IsStream()) { + throw new PdfException(KernelExceptionMessageConstant.UNEXPECTED_SHADING_TYPE); + } + shading = new PdfCoonsPatchShading((PdfStream)shadingDictionary); + break; + } + + case ShadingType.TENSOR_PRODUCT_PATCH_MESH: { + if (!shadingDictionary.IsStream()) { + throw new PdfException(KernelExceptionMessageConstant.UNEXPECTED_SHADING_TYPE); + } + shading = new PdfTensorProductPatchShading((PdfStream)shadingDictionary); + break; + } + + default: { + throw new PdfException(KernelExceptionMessageConstant.UNEXPECTED_SHADING_TYPE); + } + } + return shading; + } + + /// + /// Creates the + /// + /// object from the existing + /// . + /// + /// + /// + /// + /// from which the + /// + /// object will be created + /// + protected internal AbstractPdfShading(PdfDictionary pdfObject) + : base(pdfObject) { + } + + /// + /// Creates the + /// + /// object from the existing + /// + /// , + /// using provided type and colorspace. + /// + /// + /// + /// + /// from which the + /// + /// object will be created + /// + /// + /// type with which this + /// + /// object will be created + /// + /// + /// + /// + /// with which this + /// + /// object will be created + /// + protected internal AbstractPdfShading(PdfDictionary pdfObject, int type, PdfColorSpace colorSpace) + : base(pdfObject) { + GetPdfObject().Put(PdfName.ShadingType, new PdfNumber(type)); + if (colorSpace is PdfSpecialCs.Pattern) { + throw new ArgumentException("colorSpace"); + } + GetPdfObject().Put(PdfName.ColorSpace, colorSpace.GetPdfObject()); + } + + /// Gets the shading type. + /// + /// int value of + /// + /// + public virtual int GetShadingType() { + return (int)GetPdfObject().GetAsInt(PdfName.ShadingType); + } + + /// Gets the color space in which colour values shall be expressed. + /// + /// + /// + /// Color space + /// + public virtual PdfObject GetColorSpace() { + return GetPdfObject().Get(PdfName.ColorSpace); + } + + /// + /// Gets the function PdfObject that represents color transitions + /// across the shading geometry. + /// + /// + /// + /// + /// Function + /// + public virtual PdfObject GetFunction() { + return GetPdfObject().Get(PdfName.Function); + } + + /// + /// Sets the function that represents color transitions + /// across the shading geometry as one object. + /// + /// + /// The + /// + /// to set + /// + public void SetFunction(IPdfFunction function) { + GetPdfObject().Put(PdfName.Function, function.GetAsPdfObject()); + SetModified(); + } + + /// + /// Sets the function object that represents color transitions + /// across the shading geometry as an array of functions. + /// + /// + /// The array of + /// + /// to be set + /// + public void SetFunction(IPdfFunction[] functions) { + PdfArray arr = new PdfArray(); + foreach (IPdfFunction func in functions) { + arr.Add(func.GetAsPdfObject()); + } + GetPdfObject().Put(PdfName.Function, arr); + SetModified(); + } + + /// + /// To manually flush a + /// PdfObject + /// behind this wrapper, you have to ensure + /// that this object is added to the document, i.e. it has an indirect reference. + /// + /// + /// To manually flush a + /// PdfObject + /// behind this wrapper, you have to ensure + /// that this object is added to the document, i.e. it has an indirect reference. + /// Basically this means that before flushing you need to explicitly call + /// . + /// For example: wrapperInstance.makeIndirect(document).flush(); + /// Note that not every wrapper require this, only those that have such warning in documentation. + /// + public sealed override void Flush() { + base.Flush(); + } + + /// + protected internal override bool IsWrappedObjectMustBeIndirect() { + return true; + } + } +} diff --git a/itext/itext.kernel/itext/kernel/pdf/colorspace/shading/AbstractPdfShadingBlend.cs b/itext/itext.kernel/itext/kernel/pdf/colorspace/shading/AbstractPdfShadingBlend.cs new file mode 100644 index 0000000000..f2cf510d50 --- /dev/null +++ b/itext/itext.kernel/itext/kernel/pdf/colorspace/shading/AbstractPdfShadingBlend.cs @@ -0,0 +1,188 @@ +/* +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 . +*/ +using iText.Kernel.Pdf; +using iText.Kernel.Pdf.Colorspace; + +namespace iText.Kernel.Pdf.Colorspace.Shading { + /// + /// The PdfShadingBlend class which extends + /// + /// and represents shadings which are + /// based on a blend, with Coords, Domain and Extend fields in the PDF object. + /// + public abstract class AbstractPdfShadingBlend : AbstractPdfShading { + /// + /// Gets the coords + /// + /// object. + /// + /// + /// the + /// + /// coords object + /// + public virtual PdfArray GetCoords() { + return GetPdfObject().GetAsArray(PdfName.Coords); + } + + /// + /// Sets the Coords object with the + /// + /// , + /// that specified the starting and the endings coordinates of thew axis, + /// expressed in the shading's target coordinate space. + /// + /// + /// the Chords + /// + /// to be set + /// + public void SetCoords(PdfArray coords) { + GetPdfObject().Put(PdfName.Coords, coords); + SetModified(); + } + + /// + /// Gets the + /// + /// of two + /// float + /// [t0, t1] that represent the limiting values of a parametric + /// variable t, that becomes an input of color function(s). + /// + /// + /// the + /// + /// of Domain object ([0.0 1.0] by default) + /// + public virtual PdfArray GetDomain() { + PdfArray domain = GetPdfObject().GetAsArray(PdfName.Domain); + if (domain == null) { + domain = new PdfArray(new float[] { 0, 1 }); + SetDomain(domain); + } + return domain; + } + + /// + /// Sets the Domain with the array of two + /// float + /// [t0, t1] that represent the limiting values + /// of a parametric variable t, that becomes an input of color function(s). + /// + /// first limit of variable t + /// second limit of variable t + public void SetDomain(float t0, float t1) { + SetDomain(new PdfArray(new float[] { t0, t1 })); + } + + /// + /// Sets the Domain with the + /// + /// of two + /// float + /// [t0, t1] that represent the limiting values + /// of a parametric variable t, that becomes an input of color function(s). + /// + /// + /// the + /// + /// that represents domain + /// + public void SetDomain(PdfArray domain) { + GetPdfObject().Put(PdfName.Domain, domain); + SetModified(); + } + + /// + /// Gets the + /// + /// of two + /// boolean + /// that specified whether to extend the shading + /// beyond the starting and ending points of the axis, respectively. + /// + /// + /// the + /// + /// of Extended object ([false false] by default) + /// + public virtual PdfArray GetExtend() { + PdfArray extend = GetPdfObject().GetAsArray(PdfName.Extend); + if (extend == null) { + extend = new PdfArray(new bool[] { false, false }); + SetExtend(extend); + } + return extend; + } + + /// + /// Sets the Extend object with the two + /// boolean + /// value. + /// + /// if true will extend shading beyond the starting point of Coords + /// if true will extend shading beyond the ending point of Coords + public void SetExtend(bool extendStart, bool extendEnd) { + SetExtend(new PdfArray(new bool[] { extendStart, extendEnd })); + } + + /// + /// Sets the Extend object with the + /// + /// of two + /// boolean. + /// + /// + /// Sets the Extend object with the + /// + /// of two + /// boolean. + /// If first is true shading will extend beyond the starting point of Coords. + /// If second is true shading will extend beyond the ending point of Coords. + /// + /// + /// the + /// + /// representing Extend object + /// + public void SetExtend(PdfArray extend) { + GetPdfObject().Put(PdfName.Extend, extend); + SetModified(); + } + + /// Constructor for PdfShadingBlend object using a PdfDictionary. + /// input PdfDictionary + protected internal AbstractPdfShadingBlend(PdfDictionary pdfObject) + : base(pdfObject) { + } + + /// Constructor for PdfShadingBlend object using PdfDictionary, shading type and colorspace value. + /// input PdfDictionary + /// shading type + /// color space + protected internal AbstractPdfShadingBlend(PdfDictionary pdfObject, int shadingType, PdfColorSpace cs) + : base(pdfObject, shadingType, cs) { + } + } +} diff --git a/itext/itext.kernel/itext/kernel/pdf/colorspace/shading/AbstractPdfShadingMesh.cs b/itext/itext.kernel/itext/kernel/pdf/colorspace/shading/AbstractPdfShadingMesh.cs new file mode 100644 index 0000000000..632fd0784a --- /dev/null +++ b/itext/itext.kernel/itext/kernel/pdf/colorspace/shading/AbstractPdfShadingMesh.cs @@ -0,0 +1,144 @@ +/* +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 . +*/ +using iText.Kernel.Pdf; +using iText.Kernel.Pdf.Colorspace; + +namespace iText.Kernel.Pdf.Colorspace.Shading { + /// + /// The PdfShadingMesh class which extends + /// + /// and represents shadings which are based on a mesh, + /// with BitsPerCoordinate, BitsPerComponent and Decode fields in the PDF object. + /// + public abstract class AbstractPdfShadingMesh : AbstractPdfShading { + /// Gets the number of bits used to represent each vertex coordinate. + /// the number of bits. Can be 1, 2, 4, 8, 12, 16, 24, or 32 + public virtual int GetBitsPerCoordinate() { + return (int)GetPdfObject().GetAsInt(PdfName.BitsPerCoordinate); + } + + /// Sets the number of bits used to represent each vertex coordinate. + /// the number of bits to be set. Shall be 1, 2, 4, 8, 12, 16, 24, or 32 + public void SetBitsPerCoordinate(int bitsPerCoordinate) { + GetPdfObject().Put(PdfName.BitsPerCoordinate, new PdfNumber(bitsPerCoordinate)); + SetModified(); + } + + /// Gets the number of bits used to represent each colour component. + /// the number of bits. Can be 1, 2, 4, 8, 12, or 16 + public virtual int GetBitsPerComponent() { + return (int)GetPdfObject().GetAsInt(PdfName.BitsPerComponent); + } + + /// Sets the number of bits used to represent each colour component. + /// the number of bits to be set. Shall be 1, 2, 4, 8, 12, or 16 + public void SetBitsPerComponent(int bitsPerComponent) { + GetPdfObject().Put(PdfName.BitsPerComponent, new PdfNumber(bitsPerComponent)); + SetModified(); + } + + /// + /// Gets the + /// + /// of numbers specifying how to map vertex coordinates and colour components + /// into the appropriate ranges of values. + /// + /// + /// Gets the + /// + /// of numbers specifying how to map vertex coordinates and colour components + /// into the appropriate ranges of values. The ranges shall be specified as follows: + /// [x_min x_max y_min y_max c1_min c1_max … cn_min cn_max]. + /// Only one pair of color values shall be specified if a Function entry is present. + /// + /// + /// the + /// + /// Decode object + /// + public virtual PdfArray GetDecode() { + return GetPdfObject().GetAsArray(PdfName.Decode); + } + + /// + /// Sets the + /// float[] + /// of numbers specifying how to map vertex coordinates and colour components + /// into the appropriate ranges of values. + /// + /// + /// Sets the + /// float[] + /// of numbers specifying how to map vertex coordinates and colour components + /// into the appropriate ranges of values. The ranges shall be specified as follows: + /// [x_min x_max y_min y_max c1_min c1_max … cn_min cn_max]. + /// Only one pair of color values shall be specified if a Function entry is present. + /// + /// + /// the + /// float[] + /// of Decode object to set + /// + public void SetDecode(float[] decode) { + SetDecode(new PdfArray(decode)); + } + + /// + /// Sets the + /// + /// of numbers specifying how to map vertex coordinates and colour components + /// into the appropriate ranges of values. + /// + /// + /// Sets the + /// + /// of numbers specifying how to map vertex coordinates and colour components + /// into the appropriate ranges of values. The ranges shall be specified as follows: + /// [x_min x_max y_min y_max c1_min c1_max … cn_min cn_max]. + /// Only one pair of color values shall be specified if a Function entry is present. + /// + /// + /// the + /// + /// Decode object to set + /// + public void SetDecode(PdfArray decode) { + GetPdfObject().Put(PdfName.Decode, decode); + SetModified(); + } + + /// Constructor for PdfShadingBlend object using a PdfDictionary. + /// input PdfDictionary + protected internal AbstractPdfShadingMesh(PdfDictionary pdfObject) + : base(pdfObject) { + } + + /// Constructor for PdfShadingBlend object using a PdfDictionary, shading type and color space. + /// input PdfDictionary + /// shading type + /// color space + protected internal AbstractPdfShadingMesh(PdfDictionary pdfObject, int type, PdfColorSpace colorSpace) + : base(pdfObject, type, colorSpace) { + } + } +} diff --git a/itext/itext.kernel/itext/kernel/pdf/colorspace/shading/AbstractPdfShadingMeshWithFlags.cs b/itext/itext.kernel/itext/kernel/pdf/colorspace/shading/AbstractPdfShadingMeshWithFlags.cs new file mode 100644 index 0000000000..9db1ea87da --- /dev/null +++ b/itext/itext.kernel/itext/kernel/pdf/colorspace/shading/AbstractPdfShadingMeshWithFlags.cs @@ -0,0 +1,75 @@ +/* +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 . +*/ +using iText.Kernel.Pdf; +using iText.Kernel.Pdf.Colorspace; + +namespace iText.Kernel.Pdf.Colorspace.Shading { + /// + /// The PdfShadingMeshFlags class which extends + /// + /// and + /// + /// and represents shadings which are based on a mesh, with all fields from + /// + /// as well as BitsPerFlag in the PDF object. + /// + public abstract class AbstractPdfShadingMeshWithFlags : AbstractPdfShadingMesh { + /// Gets the number of bits used to represent the edge flag for each vertex. + /// + /// Gets the number of bits used to represent the edge flag for each vertex. + /// But only the least significant 2 bits in each flag value shall be used. + /// The valid flag values are 0, 1, 2 or 3. + /// + /// the number of bits. Can be 2, 4 or 8 + public virtual int GetBitsPerFlag() { + return (int)GetPdfObject().GetAsInt(PdfName.BitsPerFlag); + } + + /// Sets the number of bits used to represent the edge flag for each vertex. + /// + /// Sets the number of bits used to represent the edge flag for each vertex. + /// But only the least significant 2 bits in each flag value shall be used. + /// The valid flag values are 0, 1, 2 or 3. + /// + /// the number of bits to be set. Shall be 2, 4 or 8 + public void SetBitsPerFlag(int bitsPerFlag) { + GetPdfObject().Put(PdfName.BitsPerFlag, new PdfNumber(bitsPerFlag)); + SetModified(); + } + + /// Constructor for PdfShadingBlend object using a PdfDictionary. + /// input PdfDictionary + protected internal AbstractPdfShadingMeshWithFlags(PdfDictionary pdfObject) + : base(pdfObject) { + } + + /// Constructor for PdfShadingBlend object using a PdfDictionary, shading type and color space. + /// input PdfDictionary + /// shading type + /// color space + protected internal AbstractPdfShadingMeshWithFlags(PdfDictionary pdfObject, int type, PdfColorSpace colorSpace + ) + : base(pdfObject, type, colorSpace) { + } + } +} diff --git a/itext/itext.kernel/itext/kernel/pdf/colorspace/shading/PdfAxialShading.cs b/itext/itext.kernel/itext/kernel/pdf/colorspace/shading/PdfAxialShading.cs new file mode 100644 index 0000000000..befac6ed1f --- /dev/null +++ b/itext/itext.kernel/itext/kernel/pdf/colorspace/shading/PdfAxialShading.cs @@ -0,0 +1,181 @@ +/* +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 . +*/ +using System; +using iText.Kernel.Pdf; +using iText.Kernel.Pdf.Colorspace; +using iText.Kernel.Pdf.Function; + +namespace iText.Kernel.Pdf.Colorspace.Shading { + /// + /// The class that extends + /// + /// and + /// + /// classes + /// and is in charge of Shading Dictionary with axial type, that define a colour blend that varies along + /// a linear axis between two endpoints and extends indefinitely perpendicular to that axis. + /// + public class PdfAxialShading : AbstractPdfShadingBlend { + /// + /// Creates the new instance of the class from the existing + /// . + /// + /// + /// from which this + /// + /// will be created + /// + public PdfAxialShading(PdfDictionary pdfDictionary) + : base(pdfDictionary) { + } + + /// Creates the new instance of the class. + /// + /// the + /// + /// object in which colour values shall be expressed. + /// The special Pattern space isn't excepted + /// + /// the start coordinate of X axis expressed in the shading's target coordinate space + /// the start coordinate of Y axis expressed in the shading's target coordinate space + /// + /// the + /// float[] + /// that represents the color in the start point + /// + /// the end coordinate of X axis expressed in the shading's target coordinate space + /// the end coordinate of Y axis expressed in the shading's target coordinate space + /// + /// the + /// float[] + /// that represents the color in the end point + /// + public PdfAxialShading(PdfColorSpace cs, float x0, float y0, float[] color0, float x1, float y1, float[] color1 + ) + : base(new PdfDictionary(), ShadingType.AXIAL, cs) { + SetCoords(x0, y0, x1, y1); + IPdfFunction func = new PdfType2Function(new float[] { 0, 1 }, null, color0, color1, 1); + SetFunction(func); + } + + /// Creates the new instance of the class. + /// + /// the + /// + /// object in which colour values shall be expressed. + /// The special Pattern space isn't excepted + /// + /// the start coordinate of X axis expressed in the shading's target coordinate space + /// the start coordinate of Y axis expressed in the shading's target coordinate space + /// + /// the + /// float[] + /// that represents the color in the start point + /// + /// the end coordinate of X axis expressed in the shading's target coordinate space + /// the end coordinate of Y axis expressed in the shading's target coordinate space + /// + /// the + /// float[] + /// that represents the color in the end point + /// + /// + /// the array of two booleans that specified whether to extend the shading + /// beyond the starting and ending points of the axis, respectively + /// + public PdfAxialShading(PdfColorSpace cs, float x0, float y0, float[] color0, float x1, float y1, float[] color1 + , bool[] extend) + : this(cs, x0, y0, color0, x1, y1, color1) { + if (extend == null || extend.Length != 2) { + throw new ArgumentException("extend"); + } + SetExtend(extend[0], extend[1]); + } + + /// Creates the new instance of the class. + /// + /// the + /// + /// object in which colour values shall be expressed. + /// The special Pattern space isn't excepted + /// + /// + /// the + /// + /// of four numbers [x0 y0 x1 y1] that specified the starting + /// and the endings coordinates of thew axis, expressed in the shading's target coordinate space + /// + /// + /// the + /// + /// object, that is used to calculate color transitions + /// + public PdfAxialShading(PdfColorSpace cs, PdfArray coords, IPdfFunction function) + : this(cs, coords, null, function) { + } + + /// Creates the new instance of the class. + /// + /// the + /// + /// object in which colour values shall be expressed. + /// The special Pattern space isn't excepted + /// + /// + /// the + /// + /// of four numbers [x0 y0 x1 y1] that specified + /// the starting and the endings coordinates of thew axis, expressed + /// in the shading's target coordinate space + /// + /// + /// the + /// + /// of two numbers [t0 t1] specifying the limiting values + /// of a parametric variable t which is considered to vary linearly between + /// these two values and becomes the input argument to the colour function + /// + /// + /// the + /// + /// object, that is used to calculate color transitions + /// + public PdfAxialShading(PdfColorSpace cs, PdfArray coords, PdfArray domain, IPdfFunction function) + : base(new PdfDictionary(), ShadingType.AXIAL, cs) { + SetCoords(coords); + if (domain != null) { + SetDomain(domain); + } + SetFunction(function); + } + + /// Sets the Choords object with the four params expressed in the shading's target coordinate space. + /// the start coordinate of X axis to be set + /// the start coordinate of Y axis to be set + /// the end coordinate of X axis to be set + /// the end coordinate of Y axis to be set + public void SetCoords(float x0, float y0, float x1, float y1) { + SetCoords(new PdfArray(new float[] { x0, y0, x1, y1 })); + } + } +} diff --git a/itext/itext.kernel/itext/kernel/pdf/colorspace/shading/PdfCoonsPatchShading.cs b/itext/itext.kernel/itext/kernel/pdf/colorspace/shading/PdfCoonsPatchShading.cs new file mode 100644 index 0000000000..a7116617e6 --- /dev/null +++ b/itext/itext.kernel/itext/kernel/pdf/colorspace/shading/PdfCoonsPatchShading.cs @@ -0,0 +1,149 @@ +/* +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 . +*/ +using iText.Kernel.Pdf; +using iText.Kernel.Pdf.Colorspace; + +namespace iText.Kernel.Pdf.Colorspace.Shading { + /// + /// The class that extends + /// + /// , + /// + /// and + /// + /// classes and is in charge of Shading Dictionary with Coons Patch mesh type. + /// + /// + /// The class that extends + /// + /// , + /// + /// and + /// + /// classes and is in charge of Shading Dictionary with Coons Patch mesh type. + /// + /// This type of shading is constructed from one or more colour patches, each bounded by four cubic Bézier curves. + /// Degenerate Bézier curves are allowed and are useful for certain graphical effects. + /// At least one complete patch shall be specified. + /// + /// The shape of patch is defined by 12 control points. + /// + /// Colours are specified for each corner of the unit square, + /// and bilinear interpolation is used to fill in colours over the entire unit square. + /// + /// Coordinates are mapped from the unit square into a four-sided patch whose sides are not necessarily linear. + /// The mapping is continuous: the corners of the unit square map to corners of the patch + /// and the sides of the unit square map to sides of the patch. + /// + /// For the format of data stream, that defines patches (see ISO-320001 Table 85). + /// + /// If the shading dictionary contains a Function entry, the colour data for each corner of a patch + /// shall be specified by a single parametric value t rather than by n separate colour components c1...cn. + /// + public class PdfCoonsPatchShading : AbstractPdfShadingMeshWithFlags { + /// + /// Creates the new instance of the class from the existing + /// . + /// + /// + /// from which this + /// + /// will be created + /// + public PdfCoonsPatchShading(PdfStream pdfStream) + : base(pdfStream) { + } + + /// Creates the new instance of the class. + /// + /// the + /// + /// object in which colour values shall be expressed. + /// The special Pattern space isn't excepted + /// + /// + /// the number of bits used to represent each vertex coordinate. + /// The value shall be 1, 2, 4, 8, 12, 16, 24, or 32 + /// + /// + /// the number of bits used to represent each colour component. + /// The value shall be 1, 2, 4, 8, 12, or 16 + /// + /// + /// the number of bits used to represent the edge flag for each vertex. + /// The value of BitsPerFlag shall be 2, 4, or 8, + /// but only the least significant 2 bits in each flag value shall be used. + /// The value for the edge flag shall be 0, 1, 2 or 3 + /// + /// + /// the + /// int[] + /// of numbers specifying how to map vertex coordinates and colour components + /// into the appropriate ranges of values. The ranges shall be specified as follows: + /// [x_min x_max y_min y_max c1_min c1_max … cn_min cn_max]. + /// Only one pair of color values shall be specified if a Function entry is present + /// + public PdfCoonsPatchShading(PdfColorSpace cs, int bitsPerCoordinate, int bitsPerComponent, int bitsPerFlag + , float[] decode) + : this(cs, bitsPerCoordinate, bitsPerComponent, bitsPerFlag, new PdfArray(decode)) { + } + + /// Creates the new instance of the class. + /// + /// the + /// + /// object in which colour values shall be expressed. + /// The special Pattern space isn't excepted + /// + /// + /// the number of bits used to represent each vertex coordinate. + /// The value shall be 1, 2, 4, 8, 12, 16, 24, or 32 + /// + /// + /// the number of bits used to represent each colour component. + /// The value shall be 1, 2, 4, 8, 12, or 16 + /// + /// + /// the number of bits used to represent the edge flag for each vertex. + /// The value of BitsPerFlag shall be 2, 4, or 8, + /// but only the least significant 2 bits in each flag value shall be used. + /// The value for the edge flag shall be 0, 1, 2 or 3 + /// + /// + /// the + /// + /// of numbers specifying how to map vertex coordinates and colour components + /// into the appropriate ranges of values. The ranges shall be specified as follows: + /// [x_min x_max y_min y_max c1_min c1_max … cn_min cn_max]. + /// Only one pair of color values shall be specified if a Function entry is present + /// + public PdfCoonsPatchShading(PdfColorSpace cs, int bitsPerCoordinate, int bitsPerComponent, int bitsPerFlag + , PdfArray decode) + : base(new PdfStream(), ShadingType.COONS_PATCH_MESH, cs) { + SetBitsPerCoordinate(bitsPerCoordinate); + SetBitsPerComponent(bitsPerComponent); + SetBitsPerFlag(bitsPerFlag); + SetDecode(decode); + } + } +} diff --git a/itext/itext.kernel/itext/kernel/pdf/colorspace/shading/PdfFreeFormGouraudShadedTriangleShading.cs b/itext/itext.kernel/itext/kernel/pdf/colorspace/shading/PdfFreeFormGouraudShadedTriangleShading.cs new file mode 100644 index 0000000000..d38c935fb1 --- /dev/null +++ b/itext/itext.kernel/itext/kernel/pdf/colorspace/shading/PdfFreeFormGouraudShadedTriangleShading.cs @@ -0,0 +1,148 @@ +/* +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 . +*/ +using iText.Kernel.Pdf; +using iText.Kernel.Pdf.Colorspace; + +namespace iText.Kernel.Pdf.Colorspace.Shading { + /// + /// The class that extends + /// + /// , + /// + /// and + /// + /// classes and is in charge of Shading Dictionary + /// with free-form Gouraud-shaded triangle mesh type. + /// + /// + /// The class that extends + /// + /// , + /// + /// and + /// + /// classes and is in charge of Shading Dictionary + /// with free-form Gouraud-shaded triangle mesh type. + /// + /// The area to be shaded is defined by a path composed entirely of triangles. + /// The colour at each vertex of the triangles is specified, + /// and a technique known as Gouraud interpolation is used to colour the interiors. + /// + /// The object shall be represented as stream containing a sequence of vertex data. + /// Each vertex is specified by the following values, in the order shown: + /// f x y c1 ... cn where: + /// f - the vertex's edge flag, that determines the vertex is connected to other vertices of the triangle mesh. + /// For full description, see ISO-320001 Paragraph 8.7.4.5.5 + /// x, y - vertex's horizontal and vertical coordinates, expressed in the shading's target coordinate space. + /// c1...cn - vertex's colour components. + /// + /// If the shading dictionary includes a Function entry, only a single parametric value, t, + /// shall be specified for each vertex in place of the colour components c1...cn. + /// + public class PdfFreeFormGouraudShadedTriangleShading : AbstractPdfShadingMeshWithFlags { + /// + /// Creates the new instance of the class from the existing + /// . + /// + /// + /// from which this + /// + /// will be created + /// + public PdfFreeFormGouraudShadedTriangleShading(PdfStream pdfStream) + : base(pdfStream) { + } + + /// Creates the new instance of the class. + /// + /// the + /// + /// object in which colour values shall be expressed. + /// The special Pattern space isn't excepted. + /// + /// + /// the number of bits used to represent each vertex coordinate. + /// The value shall be 1, 2, 4, 8, 12, 16, 24, or 32 + /// + /// + /// the number of bits used to represent each colour component. + /// The value shall be 1, 2, 4, 8, 12, or 16 + /// + /// + /// the number of bits used to represent the edge flag for each vertex. + /// The value of BitsPerFlag shall be 2, 4, or 8, + /// but only the least significant 2 bits in each flag value shall be used. + /// The value for the edge flag shall be 0, 1, or 2 + /// + /// + /// the + /// int[] + /// of numbers specifying how to map vertex coordinates and colour components + /// into the appropriate ranges of values. The ranges shall be specified as follows: + /// [x_min x_max y_min y_max c1_min c1_max … cn_min cn_max]. + /// Only one pair of color values shall be specified if a Function entry is present + /// + public PdfFreeFormGouraudShadedTriangleShading(PdfColorSpace cs, int bitsPerCoordinate, int bitsPerComponent + , int bitsPerFlag, float[] decode) + : this(cs, bitsPerCoordinate, bitsPerComponent, bitsPerFlag, new PdfArray(decode)) { + } + + /// Creates the new instance of the class. + /// + /// the + /// + /// object in which colour values shall be expressed. + /// The special Pattern space isn't excepted + /// + /// + /// the number of bits used to represent each vertex coordinate. + /// The value shall be 1, 2, 4, 8, 12, 16, 24, or 32 + /// + /// + /// the number of bits used to represent each colour component. + /// The value shall be 1, 2, 4, 8, 12, or 16 + /// + /// + /// the number of bits used to represent the edge flag for each vertex. + /// The value of BitsPerFlag shall be 2, 4, or 8, + /// but only the least significant 2 bits in each flag value shall be used. + /// The value for the edge flag shall be 0, 1, or 2 + /// + /// + /// the + /// + /// of numbers specifying how to map vertex coordinates and colour components + /// into the appropriate ranges of values. The ranges shall be specified as follows: + /// [x_min x_max y_min y_max c1_min c1_max … cn_min cn_max]. + /// Only one pair of color values shall be specified if a Function entry is present + /// + public PdfFreeFormGouraudShadedTriangleShading(PdfColorSpace cs, int bitsPerCoordinate, int bitsPerComponent + , int bitsPerFlag, PdfArray decode) + : base(new PdfStream(), ShadingType.FREE_FORM_GOURAUD_SHADED_TRIANGLE_MESH, cs) { + SetBitsPerCoordinate(bitsPerCoordinate); + SetBitsPerComponent(bitsPerComponent); + SetBitsPerFlag(bitsPerFlag); + SetDecode(decode); + } + } +} diff --git a/itext/itext.kernel/itext/kernel/pdf/colorspace/shading/PdfFunctionBasedShading.cs b/itext/itext.kernel/itext/kernel/pdf/colorspace/shading/PdfFunctionBasedShading.cs new file mode 100644 index 0000000000..f5c4126b2b --- /dev/null +++ b/itext/itext.kernel/itext/kernel/pdf/colorspace/shading/PdfFunctionBasedShading.cs @@ -0,0 +1,171 @@ +/* +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 . +*/ +using iText.Kernel.Pdf; +using iText.Kernel.Pdf.Colorspace; +using iText.Kernel.Pdf.Function; + +namespace iText.Kernel.Pdf.Colorspace.Shading { + /// + /// The class that extends + /// + /// class and is in charge of Shading Dictionary + /// with function-based type, that defines color at every point in the domain by a specified mathematical function. + /// + public class PdfFunctionBasedShading : AbstractPdfShading { + /// + /// Creates the new instance of the class from the existing + /// . + /// + /// + /// from which this + /// + /// will be created + /// + public PdfFunctionBasedShading(PdfDictionary pdfDictionary) + : base(pdfDictionary) { + } + + /// Creates the new instance of the class. + /// + /// the + /// + /// object in which colour values shall be expressed + /// + /// + /// the + /// + /// , that is used to calculate color transitions + /// + public PdfFunctionBasedShading(PdfColorSpace colorSpace, IPdfFunction function) + : this(colorSpace.GetPdfObject(), function) { + } + + /// Creates the new instance of the class. + /// + /// the + /// + /// , that represents color space in which colour values shall be expressed + /// + /// + /// the + /// + /// , that is used to calculate color transitions + /// + public PdfFunctionBasedShading(PdfObject colorSpace, IPdfFunction function) + : base(new PdfDictionary(), ShadingType.FUNCTION_BASED, PdfColorSpace.MakeColorSpace(colorSpace)) { + SetFunction(function); + } + + /// + /// Gets the + /// + /// domain rectangle object that establishes an internal coordinate space + /// for the shading that is independent of the target coordinate space in which it shall be painted. + /// + /// + /// + /// + /// domain rectangle + /// + public virtual PdfArray GetDomain() { + return GetPdfObject().GetAsArray(PdfName.Domain); + } + + /// + /// Sets the + /// + /// domain rectangle object that establishes an internal coordinate space + /// for the shading that is independent of the target coordinate space in which it shall be painted. + /// + /// the Xmin coordinate of rectangle + /// the Xmax coordinate of rectangle + /// the Ymin coordinate of rectangle + /// the Ymax coordinate of rectangle + public virtual void SetDomain(float xmin, float xmax, float ymin, float ymax) { + SetDomain(new PdfArray(new float[] { xmin, xmax, ymin, ymax })); + } + + /// + /// Sets the + /// + /// domain rectangle object that establishes an internal coordinate space + /// for the shading that is independent of the target coordinate space in which it shall be painted. + /// + /// + /// the + /// + /// domain rectangle object to be set + /// + public virtual void SetDomain(PdfArray domain) { + GetPdfObject().Put(PdfName.Domain, domain); + SetModified(); + } + + /// + /// Gets the + /// + /// of floats that represents the transformation matrix that maps the domain rectangle + /// into a corresponding figure in the target coordinate space. + /// + /// + /// the + /// + /// of transformation matrix (identical matrix by default) + /// + public virtual PdfArray GetMatrix() { + PdfArray matrix = GetPdfObject().GetAsArray(PdfName.Matrix); + if (matrix == null) { + matrix = new PdfArray(new float[] { 1, 0, 0, 1, 0, 0 }); + SetMatrix(matrix); + } + return matrix; + } + + /// + /// Sets the array of floats that represents the transformation matrix that maps the domain rectangle + /// into a corresponding figure in the target coordinate space. + /// + /// + /// the + /// float[] + /// of transformation matrix to be set + /// + public virtual void SetMatrix(float[] matrix) { + SetMatrix(new PdfArray(matrix)); + } + + /// + /// Sets the array of floats that represents the transformation matrix that maps the domain rectangle + /// into a corresponding figure in the target coordinate space. + /// + /// + /// the + /// + /// transformation matrix object to be set + /// + public virtual void SetMatrix(PdfArray matrix) { + GetPdfObject().Put(PdfName.Matrix, matrix); + SetModified(); + } + } +} diff --git a/itext/itext.kernel/itext/kernel/pdf/colorspace/shading/PdfLatticeFormGouraudShadedTriangleShading.cs b/itext/itext.kernel/itext/kernel/pdf/colorspace/shading/PdfLatticeFormGouraudShadedTriangleShading.cs new file mode 100644 index 0000000000..db42e37882 --- /dev/null +++ b/itext/itext.kernel/itext/kernel/pdf/colorspace/shading/PdfLatticeFormGouraudShadedTriangleShading.cs @@ -0,0 +1,154 @@ +/* +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 . +*/ +using iText.Kernel.Pdf; +using iText.Kernel.Pdf.Colorspace; + +namespace iText.Kernel.Pdf.Colorspace.Shading { + /// + /// The class that extends + /// + /// and + /// + /// classes + /// and is in charge of Shading Dictionary with lattice-form Gouraud-shaded triangle mesh type. + /// + /// + /// The class that extends + /// + /// and + /// + /// classes + /// and is in charge of Shading Dictionary with lattice-form Gouraud-shaded triangle mesh type. + /// + /// This type is similar to + /// + /// but instead of using free-form geometry, + /// the vertices are arranged in a pseudorectangular lattice, + /// which is topologically equivalent to a rectangular grid. + /// The vertices are organized into rows, which need not be geometrically linear. + /// + /// The verticals data in stream is similar to + /// + /// , + /// except there is no edge flag. + /// + public class PdfLatticeFormGouraudShadedTriangleShading : AbstractPdfShadingMesh { + /// + /// Creates the new instance of the class from the existing + /// . + /// + /// + /// from which this + /// + /// will be created + /// + public PdfLatticeFormGouraudShadedTriangleShading(PdfStream pdfStream) + : base(pdfStream) { + } + + /// Creates the new instance of the class. + /// + /// the + /// + /// object in which colour values shall be expressed. + /// The special Pattern space isn't excepted + /// + /// + /// the number of bits used to represent each vertex coordinate. + /// The value shall be 1, 2, 4, 8, 12, 16, 24, or 32 + /// + /// + /// the number of bits used to represent each colour component. + /// The value shall be 1, 2, 4, 8, 12, or 16 + /// + /// + /// the number of vertices in each row of the lattice (shall be > 1). + /// The number of rows need not be specified + /// + /// + /// the + /// int[] + /// of numbers specifying how to map vertex coordinates and colour components + /// into the appropriate ranges of values. The ranges shall be specified as follows: + /// [x_min x_max y_min y_max c1_min c1_max … cn_min cn_max]. + /// Only one pair of color values shall be specified if a Function entry is present + /// + public PdfLatticeFormGouraudShadedTriangleShading(PdfColorSpace cs, int bitsPerCoordinate, int bitsPerComponent + , int verticesPerRow, float[] decode) + : this(cs, bitsPerCoordinate, bitsPerComponent, verticesPerRow, new PdfArray(decode)) { + } + + /// Creates the new instance of the class. + /// + /// the + /// + /// object in which colour values shall be expressed. + /// The special Pattern space isn't excepted + /// + /// + /// the number of bits used to represent each vertex coordinate. + /// The value shall be 1, 2, 4, 8, 12, 16, 24, or 32 + /// + /// + /// the number of bits used to represent each colour component. + /// The value shall be 1, 2, 4, 8, 12, or 16 + /// + /// + /// the number of vertices in each row of the lattice (shall be > 1). + /// The number of rows need not be specified + /// + /// + /// the + /// + /// of numbers specifying how to map vertex coordinates and colour components + /// into the appropriate ranges of values. The ranges shall be specified as follows: + /// [x_min x_max y_min y_max c1_min c1_max … cn_min cn_max]. + /// Only one pair of color values shall be specified if a Function entry is present + /// + public PdfLatticeFormGouraudShadedTriangleShading(PdfColorSpace cs, int bitsPerCoordinate, int bitsPerComponent + , int verticesPerRow, PdfArray decode) + : base(new PdfStream(), ShadingType.LATTICE_FORM_GOURAUD_SHADED_TRIANGLE_MESH, cs) { + SetBitsPerCoordinate(bitsPerCoordinate); + SetBitsPerComponent(bitsPerComponent); + SetVerticesPerRow(verticesPerRow); + SetDecode(decode); + } + + /// Gets the number of vertices in each row of the lattice. + /// the number of vertices. Can only be greater than 1 + public virtual int GetVerticesPerRow() { + return (int)GetPdfObject().GetAsInt(PdfName.VerticesPerRow); + } + + /// Sets the number of vertices in each row of the lattice. + /// + /// Sets the number of vertices in each row of the lattice. + /// The number of rows need not be specified. + /// + /// the number of vertices to be set. Shall be greater than 1 + public void SetVerticesPerRow(int verticesPerRow) { + GetPdfObject().Put(PdfName.VerticesPerRow, new PdfNumber(verticesPerRow)); + SetModified(); + } + } +} diff --git a/itext/itext.kernel/itext/kernel/pdf/colorspace/shading/PdfRadialShading.cs b/itext/itext.kernel/itext/kernel/pdf/colorspace/shading/PdfRadialShading.cs new file mode 100644 index 0000000000..7470a2b665 --- /dev/null +++ b/itext/itext.kernel/itext/kernel/pdf/colorspace/shading/PdfRadialShading.cs @@ -0,0 +1,205 @@ +/* +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 . +*/ +using System; +using iText.Kernel.Pdf; +using iText.Kernel.Pdf.Colorspace; +using iText.Kernel.Pdf.Function; + +namespace iText.Kernel.Pdf.Colorspace.Shading { + /// + /// The class that extends + /// + /// and + /// + /// classes + /// and is in charge of Shading Dictionary with radial type, that defines a colour blend that varies between two circles. + /// + /// + /// The class that extends + /// + /// and + /// + /// classes + /// and is in charge of Shading Dictionary with radial type, that defines a colour blend that varies between two circles. + /// + /// This type of shading shall not be used with an Indexed colour space + /// + public class PdfRadialShading : AbstractPdfShadingBlend { + /// + /// Creates the new instance of the class from the existing + /// . + /// + /// + /// from which this + /// + /// will be created + /// + public PdfRadialShading(PdfDictionary pdfDictionary) + : base(pdfDictionary) { + } + + /// Creates the new instance of the class. + /// + /// the + /// + /// object in which colour values shall be expressed. + /// The Indexed color space isn't excepted + /// + /// the X coordinate of starting circle's centre, expressed in in the shading’s target coordinate space + /// + /// the Y coordinate of starting circle's centre, expressed in in the shading’s target coordinate space + /// + /// + /// the radius of starting circle's centre, should be greater or equal to 0. + /// If 0 then starting circle is treated as point. + /// If both radii are 0, nothing shall be painted + /// + /// + /// the + /// float[] + /// that represents the color in the start circle + /// + /// the X coordinate of ending circle's centre, expressed in in the shading’s target coordinate space + /// + /// the Y coordinate of ending circle's centre, expressed in in the shading’s target coordinate space + /// + /// + /// the radius of ending circle's centre, should be greater or equal to 0. + /// If 0 then ending circle is treated as point. + /// If both radii are 0, nothing shall be painted + /// + /// + /// the + /// float[] + /// that represents the color in the end circle + /// + public PdfRadialShading(PdfColorSpace cs, float x0, float y0, float r0, float[] color0, float x1, float y1 + , float r1, float[] color1) + : base(new PdfDictionary(), ShadingType.RADIAL, cs) { + SetCoords(x0, y0, r0, x1, y1, r1); + IPdfFunction func = new PdfType2Function(new float[] { 0, 1 }, null, color0, color1, 1); + SetFunction(func); + } + + /// Creates the new instance of the class. + /// + /// the + /// + /// object in which colour values shall be expressed. + /// The Indexed color space isn't excepted + /// + /// the X coordinate of starting circle's centre, expressed in in the shading’s target coordinate space + /// + /// the Y coordinate of starting circle's centre, expressed in in the shading’s target coordinate space + /// + /// + /// the radius of starting circle's centre, should be greater or equal to 0. + /// If 0 then starting circle is treated as point. + /// If both radii are 0, nothing shall be painted + /// + /// + /// the + /// float[] + /// that represents the color in the start circle + /// + /// the X coordinate of ending circle's centre, expressed in in the shading’s target coordinate space + /// + /// the Y coordinate of ending circle's centre, expressed in in the shading’s target coordinate space + /// + /// + /// the radius of ending circle's centre, should be greater or equal to 0. + /// If 0 then ending circle is treated as point. + /// If both radii are 0, nothing shall be painted + /// + /// + /// the + /// float[] + /// that represents the color in the end circle + /// + /// + /// the array of two + /// boolean + /// that specified whether to extend the shading + /// beyond the starting and ending points of the axis, respectively + /// + public PdfRadialShading(PdfColorSpace cs, float x0, float y0, float r0, float[] color0, float x1, float y1 + , float r1, float[] color1, bool[] extend) + : this(cs, x0, y0, r0, color0, x1, y1, r1, color1) { + if (extend == null || extend.Length != 2) { + throw new ArgumentException("extend"); + } + SetExtend(extend[0], extend[1]); + } + + /// Creates the new instance of the class. + /// + /// the + /// + /// object in which colour values shall be expressed. + /// The Indexed color space isn't excepted + /// + /// + /// the + /// + /// of of six numbers [x0 y0 r0 x1 y1 r1], + /// specifying the centres and radii of the starting and ending circles, + /// expressed in the shading’s target coordinate space. + /// The radii r0 and r1 shall both be greater than or equal to 0. + /// If one radius is 0, the corresponding circle shall be treated as a point; + /// if both are 0, nothing shall be painted + /// + /// + /// the + /// + /// object, that is used to calculate color transitions + /// + public PdfRadialShading(PdfColorSpace cs, PdfArray coords, IPdfFunction function) + : base(new PdfDictionary(), ShadingType.RADIAL, cs) { + SetCoords(coords); + SetFunction(function); + } + + /// Sets the coords object. + /// the X coordinate of starting circle's centre, expressed in in the shading’s target coordinate space + /// + /// the Y coordinate of starting circle's centre, expressed in in the shading’s target coordinate space + /// + /// + /// the radius of starting circle's centre, should be greater or equal to 0. + /// If 0 then starting circle is treated as point. + /// If both radii are 0, nothing shall be painted + /// + /// the X coordinate of ending circle's centre, expressed in in the shading’s target coordinate space + /// + /// the Y coordinate of ending circle's centre, expressed in in the shading’s target coordinate space + /// + /// + /// the radius of ending circle's centre, should be greater or equal to 0. + /// If 0 then ending circle is treated as point. + /// If both radii are 0, nothing shall be painted + /// + public void SetCoords(float x0, float y0, float r0, float x1, float y1, float r1) { + SetCoords(new PdfArray(new float[] { x0, y0, r0, x1, y1, r1 })); + } + } +} diff --git a/itext/itext.kernel/itext/kernel/pdf/colorspace/shading/PdfTensorProductPatchShading.cs b/itext/itext.kernel/itext/kernel/pdf/colorspace/shading/PdfTensorProductPatchShading.cs new file mode 100644 index 0000000000..a1b6d64bae --- /dev/null +++ b/itext/itext.kernel/itext/kernel/pdf/colorspace/shading/PdfTensorProductPatchShading.cs @@ -0,0 +1,140 @@ +/* +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 . +*/ +using iText.Kernel.Pdf; +using iText.Kernel.Pdf.Colorspace; + +namespace iText.Kernel.Pdf.Colorspace.Shading { + /// + /// The class that extends + /// + /// , + /// + /// and + /// + /// classes and is in charge of Shading Dictionary + /// with Tensor-Product Patch mesh type. + /// + /// + /// The class that extends + /// + /// , + /// + /// and + /// + /// classes and is in charge of Shading Dictionary + /// with Tensor-Product Patch mesh type. + /// + /// This type of shading is identical to + /// + /// , except that it's based on a + /// bicubic tensor-product patch defined by 16 control points. + /// + /// For the format of data stream, that defines patches, see ISO-320001 Table 86. + /// + public class PdfTensorProductPatchShading : AbstractPdfShadingMeshWithFlags { + /// + /// Creates the new instance of the class from the existing + /// . + /// + /// + /// from which this + /// + /// will be created + /// + public PdfTensorProductPatchShading(PdfStream pdfStream) + : base(pdfStream) { + } + + /// Creates the new instance of the class. + /// + /// the + /// + /// object in which colour values shall be expressed. + /// The special Pattern space isn't excepted + /// + /// + /// the number of bits used to represent each vertex coordinate. + /// The value shall be 1, 2, 4, 8, 12, 16, 24, or 32 + /// + /// + /// the number of bits used to represent each colour component. + /// The value shall be 1, 2, 4, 8, 12, or 16 + /// + /// + /// the number of bits used to represent the edge flag for each vertex. + /// The value of BitsPerFlag shall be 2, 4, or 8, + /// but only the least significant 2 bits in each flag value shall be used. + /// The value for the edge flag shall be 0, 1, 2 or 3 + /// + /// + /// the + /// int[] + /// of numbers specifying how to map vertex coordinates and colour components + /// into the appropriate ranges of values. The ranges shall be specified as follows: + /// [x_min x_max y_min y_max c1_min c1_max … cn_min cn_max]. + /// Only one pair of color values shall be specified if a Function entry is present + /// + public PdfTensorProductPatchShading(PdfColorSpace cs, int bitsPerCoordinate, int bitsPerComponent, int bitsPerFlag + , float[] decode) + : this(cs, bitsPerCoordinate, bitsPerComponent, bitsPerFlag, new PdfArray(decode)) { + } + + /// Creates the new instance of the class. + /// + /// the + /// + /// object in which colour values shall be expressed. + /// The special Pattern space isn't excepted + /// + /// + /// the number of bits used to represent each vertex coordinate. + /// The value shall be 1, 2, 4, 8, 12, 16, 24, or 32 + /// + /// + /// the number of bits used to represent each colour component. + /// The value shall be 1, 2, 4, 8, 12, or 16 + /// + /// + /// the number of bits used to represent the edge flag for each vertex. + /// The value of BitsPerFlag shall be 2, 4, or 8, + /// but only the least significant 2 bits in each flag value shall be used. + /// The value for the edge flag shall be 0, 1, 2 or 3 + /// + /// + /// the + /// + /// of numbers specifying how to map vertex coordinates and colour components + /// into the appropriate ranges of values. The ranges shall be specified as follows: + /// [x_min x_max y_min y_max c1_min c1_max … cn_min cn_max]. + /// Only one pair of color values shall be specified if a Function entry is present + /// + public PdfTensorProductPatchShading(PdfColorSpace cs, int bitsPerCoordinate, int bitsPerComponent, int bitsPerFlag + , PdfArray decode) + : base(new PdfStream(), ShadingType.TENSOR_PRODUCT_PATCH_MESH, cs) { + SetBitsPerCoordinate(bitsPerCoordinate); + SetBitsPerComponent(bitsPerComponent); + SetBitsPerFlag(bitsPerFlag); + SetDecode(decode); + } + } +} diff --git a/itext/itext.kernel/itext/kernel/pdf/colorspace/shading/ShadingType.cs b/itext/itext.kernel/itext/kernel/pdf/colorspace/shading/ShadingType.cs new file mode 100644 index 0000000000..a99a451687 --- /dev/null +++ b/itext/itext.kernel/itext/kernel/pdf/colorspace/shading/ShadingType.cs @@ -0,0 +1,50 @@ +/* +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 . +*/ +namespace iText.Kernel.Pdf.Colorspace.Shading { + /// The constants of shading type (see ISO-320001 Table 78). + public sealed class ShadingType { + /// The int value of function-based shading type + public const int FUNCTION_BASED = 1; + + /// The int value of axial shading type + public const int AXIAL = 2; + + /// The int value of radial shading type + public const int RADIAL = 3; + + /// The int value of free-form Gouraud-shaded triangle mesh shading type + public const int FREE_FORM_GOURAUD_SHADED_TRIANGLE_MESH = 4; + + /// The int value of lattice-form Gouraud-shaded triangle mesh shading type + public const int LATTICE_FORM_GOURAUD_SHADED_TRIANGLE_MESH = 5; + + /// The int value of coons patch meshes shading type + public const int COONS_PATCH_MESH = 6; + + /// The int value of tensor-product patch meshes shading type + public const int TENSOR_PRODUCT_PATCH_MESH = 7; + + private ShadingType() { + } + } +} diff --git a/itext/itext.sign/itext/signatures/PdfSigner.cs b/itext/itext.sign/itext/signatures/PdfSigner.cs index 7fd7f53a6d..3a145cd2a5 100644 --- a/itext/itext.sign/itext/signatures/PdfSigner.cs +++ b/itext/itext.sign/itext/signatures/PdfSigner.cs @@ -888,8 +888,7 @@ protected internal virtual void PreClose(IDictionary exclusionSiz /// protected internal virtual SignatureFieldAppearance GetSignatureAppearance() { if (this.signerProperties.GetSignatureAppearance() == null) { - this.signerProperties.SetSignatureAppearance(new SignatureFieldAppearance(this.signerProperties.GetFieldName - ())); + this.signerProperties.SetSignatureAppearance(new SignatureFieldAppearance(SignerProperties.IGNORED_ID)); SetContent(); } else { diff --git a/itext/itext.sign/itext/signatures/SignerProperties.cs b/itext/itext.sign/itext/signatures/SignerProperties.cs index 68c26e0aa7..23c786e6c3 100644 --- a/itext/itext.sign/itext/signatures/SignerProperties.cs +++ b/itext/itext.sign/itext/signatures/SignerProperties.cs @@ -29,6 +29,8 @@ You should have received a copy of the GNU Affero General Public License namespace iText.Signatures { /// Properties to be used in signing operations. public class SignerProperties { + public const String IGNORED_ID = ""; + private PdfSigFieldLock fieldLock; private SignatureFieldAppearance appearance; @@ -76,6 +78,12 @@ public virtual iText.Signatures.SignerProperties SetClaimedSignDate(DateTime sig /// Sets the signature field layout element to customize the appearance of the signature. /// /// Sets the signature field layout element to customize the appearance of the signature. + /// ID specified for + /// + /// will be ignored and won't override field name, so + /// + /// could be used. To specify signature name use + /// . /// /// Note that if /// @@ -180,6 +188,13 @@ public virtual String GetFieldName() { /// /// Sets the name indicating the field to be signed. The field can already be presented in the /// document but shall not be signed. If the field is not presented in the document, it will be created. + /// + /// Note that ID specified for + /// + /// set by + /// + /// will be + /// ignored and won't override the field name. /// /// the name indicating the field to be signed /// this instance to support fluent interface diff --git a/port-hash b/port-hash index 3bee91861b..6f295280e6 100644 --- a/port-hash +++ b/port-hash @@ -1 +1 @@ -a1e83efe10856b980ebc96e01a9dfb89ddeeeee1 \ No newline at end of file +0acb474db7434b65fb4818a7a37746eb288a5b91