Exemplo n.º 1
0
 public virtual void AxialShadingConstructorInvalidExtendArgumentTest()
 {
     bool[] extendArray = new bool[] { true };
     NUnit.Framework.Assert.That(() => {
         PdfShading.Axial axial = new PdfShading.Axial(new PdfDeviceCs.Rgb(), 0f, 0f, new float[] { 0f, 0f, 0f }, 0.5f
                                                       , 0.5f, new float[] { 0.5f, 0.5f, 0.5f }, extendArray);
     }
                                 , NUnit.Framework.Throws.InstanceOf <ArgumentException>().With.Message.EqualTo("extend"))
     ;
 }
Exemplo n.º 2
0
        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);
            NUnit.Framework.Assert.AreEqual(coordsArray, axial.GetCoords().ToFloatArray());
            NUnit.Framework.Assert.AreEqual(defaultDomainArray, axial.GetDomain().ToFloatArray());
            NUnit.Framework.Assert.AreEqual(defaultExtendArray, axial.GetExtend().ToBooleanArray());
            NUnit.Framework.Assert.AreEqual(PdfShading.ShadingType.AXIAL, axial.GetShadingType());
        }
Exemplo n.º 3
0
        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
                                                                         .AXIAL);

            PdfShading.Axial axial = new PdfShading.Axial(axialShadingDictionary);
            NUnit.Framework.Assert.AreEqual(coordsArray, axial.GetCoords().ToFloatArray());
            NUnit.Framework.Assert.AreEqual(domainArray, axial.GetDomain().ToFloatArray());
            NUnit.Framework.Assert.AreEqual(extendArray, axial.GetExtend().ToBooleanArray());
            NUnit.Framework.Assert.AreEqual(PdfShading.ShadingType.AXIAL, axial.GetShadingType());
        }
Exemplo n.º 4
0
        public virtual void CreateAxialShadingWithStitchingFunctionTest()
        {
            String      testName      = "createAxialShadingWithStitchingFunctionTest";
            String      outName       = destinationFolder + testName + ".pdf";
            String      cmpName       = sourceFolder + "cmp_" + testName + ".pdf";
            PdfDocument pdfDocument   = new PdfDocument(new PdfWriter(outName));
            PdfCanvas   pdfCanvas     = new PdfCanvas(pdfDocument.AddNewPage());
            int         x0            = 40;
            int         y0            = 500;
            int         x1            = 80;
            int         y1            = 400;
            PdfArray    shadingVector = new PdfArray(new int[] { x0, y0, x1, y1 });

            PdfFunction.Type3 stitchingFunction = CreateStitchingCmykShadingFunction();
            PdfShading.Axial  axialShading      = new PdfShading.Axial(new PdfDeviceCs.Cmyk(), shadingVector, stitchingFunction
                                                                       );
            pdfCanvas.PaintShading(axialShading);
            pdfDocument.Close();
            AssertShadingDictionaryResult(outName, cmpName, "Sh1");
        }
Exemplo n.º 5
0
        public virtual void ModifyAxialShadingTest()
        {
            String      testName    = "modifyAxialShadingTest";
            String      outName     = destinationFolder + testName + ".pdf";
            String      cmpName     = sourceFolder + "cmp_" + testName + ".pdf";
            String      input       = sourceFolder + "axialShading.pdf";
            PdfDocument pdfDocument = new PdfDocument(new PdfReader(input), new PdfWriter(outName), 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;
                    // "cut" shading and extend colors
                    axialShading.SetDomain(0.1f, 0.8f);
                    axialShading.SetExtend(true, true);
                }
            }
            pdfDocument.Close();
            AssertShadingDictionaryResult(outName, cmpName, "Sh1");
        }
Exemplo n.º 6
0
        public static PdfShading MakeShading(PdfDictionary shadingDictionary)
        {
            if (!shadingDictionary.ContainsKey(PdfName.ShadingType))
            {
                throw new PdfException(PdfException.UnexpectedShadingType);
            }
            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(PdfException.UnexpectedShadingType);
                }
                shading = new PdfShading.FreeFormGouraudShadedTriangleMesh((PdfStream)shadingDictionary);
                break;
            }

            case PdfShading.ShadingType.LATTICE_FORM_GOURAUD_SHADED_TRIANGLE_MESH: {
                if (!shadingDictionary.IsStream())
                {
                    throw new PdfException(PdfException.UnexpectedShadingType);
                }
                shading = new PdfShading.LatticeFormGouraudShadedTriangleMesh((PdfStream)shadingDictionary);
                break;
            }

            case PdfShading.ShadingType.COONS_PATCH_MESH: {
                if (!shadingDictionary.IsStream())
                {
                    throw new PdfException(PdfException.UnexpectedShadingType);
                }
                shading = new PdfShading.CoonsPatchMesh((PdfStream)shadingDictionary);
                break;
            }

            case PdfShading.ShadingType.TENSOR_PRODUCT_PATCH_MESH: {
                if (!shadingDictionary.IsStream())
                {
                    throw new PdfException(PdfException.UnexpectedShadingType);
                }
                shading = new PdfShading.TensorProductPatchMesh((PdfStream)shadingDictionary);
                break;
            }

            default: {
                throw new PdfException(PdfException.UnexpectedShadingType);
            }
            }
            return(shading);
        }