Exemplo n.º 1
0
        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);
            NUnit.Framework.Assert.AreEqual(coordsArray, radial.GetCoords().ToFloatArray());
            NUnit.Framework.Assert.AreEqual(defaultDomainArray, radial.GetDomain().ToFloatArray());
            NUnit.Framework.Assert.AreEqual(defaultExtendArray, radial.GetExtend().ToBooleanArray());
            NUnit.Framework.Assert.AreEqual(PdfShading.ShadingType.RADIAL, radial.GetShadingType());
        }
Exemplo n.º 2
0
        public virtual void CreateSimpleRadialShadingTest()
        {
            String      testName    = "createSimpleRadialShadingTest";
            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          = 100;
            int         y0          = 500;
            int         r0          = 25;
            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 });
            pdfCanvas.PaintShading(radialShading);
            pdfDocument.Close();
            AssertShadingDictionaryResult(outName, cmpName, "Sh1");
        }
Exemplo n.º 3
0
        public virtual void CreateRadialShadingWithStitchingFunctionTest()
        {
            String      testName      = "createRadialShadingWithStitchingFunctionTest";
            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         r0            = 25;
            int         x1            = 380;
            int         y1            = 400;
            int         r1            = 50;
            PdfArray    shadingVector = new PdfArray(new int[] { x0, y0, r0, x1, y1, r1 });

            PdfFunction.Type3 stitchingFunction = CreateStitchingCmykShadingFunction();
            PdfShading.Radial radialShading     = new PdfShading.Radial(new PdfDeviceCs.Cmyk(), shadingVector, stitchingFunction
                                                                        );
            pdfCanvas.PaintShading(radialShading);
            pdfDocument.Close();
            AssertShadingDictionaryResult(outName, cmpName, "Sh1");
        }
Exemplo n.º 4
0
        public virtual void ModifyRadialShadingTest()
        {
            String      testName    = "modifyRadialAxialShadingTest";
            String      outName     = destinationFolder + testName + ".pdf";
            String      cmpName     = sourceFolder + "cmp_" + testName + ".pdf";
            String      input       = sourceFolder + "radialShading.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.RADIAL)
                {
                    PdfShading.Radial radialShading = (PdfShading.Radial)shading;
                    // "cut" shading and extend colors
                    radialShading.SetDomain(0.1f, 0.8f);
                    radialShading.SetExtend(true, true);
                }
            }
            pdfDocument.Close();
            AssertShadingDictionaryResult(outName, cmpName, "Sh1");
        }
Exemplo n.º 5
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);
        }