Package org.apache.pdfbox.preflight.graphic

Examples of org.apache.pdfbox.preflight.graphic.ColorSpaceHelper


    protected void validImageColorSpace(PDFOperator operator) throws ContentStreamException, IOException
    {
        COSDictionary dict = operator.getImageParameters().getDictionary();

        COSBase csInlinedBase = dict.getItem(COSName.CS);
        ColorSpaceHelper csHelper = null;
        if (csInlinedBase != null)
        {
            if (COSUtils.isString(csInlinedBase, cosDocument))
            {
                /*
                 * In InlinedImage only DeviceGray/RGB/CMYK and restricted Indexed color spaces are allowed.
                 */
                String colorSpace = COSUtils.getAsString(csInlinedBase, cosDocument);
                ColorSpaces cs = null;

                try
                {
                    cs = ColorSpaces.valueOf(colorSpace);
                }
                catch (IllegalArgumentException e)
                {
                    // The color space is unknown. Try to access the resources dictionary,
                    // the color space can be a reference.
                    Map<String, PDColorSpace> colorSpaces = this.getResources().getColorSpaces();
                    if (colorSpaces != null)
                    {
                        PDColorSpace pdCS = colorSpaces.get(colorSpace);
                        if (pdCS != null)
                        {
                            cs = ColorSpaces.valueOf(pdCS.getName());
                            PreflightConfiguration cfg = context.getConfig();
                            ColorSpaceHelperFactory csFact = cfg.getColorSpaceHelperFact();
                            csHelper = csFact.getColorSpaceHelper(context, pdCS, ColorSpaceRestriction.ONLY_DEVICE);
                        }
                    }
                }

                if (cs == null)
                {
                    registerError("The ColorSpace is unknown", ERROR_GRAPHIC_UNEXPECTED_VALUE_FOR_KEY);
                    return;
                }
            }

            if (csHelper == null)
            {
                PDColorSpace pdCS = PDColorSpaceFactory.createColorSpace(csInlinedBase);
                PreflightConfiguration cfg = context.getConfig();
                ColorSpaceHelperFactory csFact = cfg.getColorSpaceHelperFact();
                csHelper = csFact.getColorSpaceHelper(context, pdCS, ColorSpaceRestriction.ONLY_DEVICE);
            }

            csHelper.validate();
        }
    }
View Full Code Here


        {
            registerError("The operand doesn't have the expected type", ERROR_GRAPHIC_UNEXPECTED_VALUE_FOR_KEY);
            return;
        }

        ColorSpaceHelper csHelper = null;
        ColorSpaces cs = null;
        try
        {
            cs = ColorSpaces.valueOf(colorSpaceName);
        }
        catch (IllegalArgumentException e)
        {
            /*
             * The color space is unknown. Try to access the resources dictionary, the color space can be a reference.
             */
            Map<String, PDColorSpace> colorSpaces = this.getResources().getColorSpaces();
            if (colorSpaces != null)
            {
                PDColorSpace pdCS = colorSpaces.get(colorSpaceName);
                if (pdCS != null)
                {
                    cs = ColorSpaces.valueOf(pdCS.getName());
                    PreflightConfiguration cfg = context.getConfig();
                    ColorSpaceHelperFactory csFact = cfg.getColorSpaceHelperFact();
                    csHelper = csFact.getColorSpaceHelper(context, pdCS, ColorSpaceRestriction.NO_RESTRICTION);
                }
            }
        }

        if (cs == null)
        {
            registerError("The ColorSpace is unknown", ERROR_GRAPHIC_UNEXPECTED_VALUE_FOR_KEY);
            return;
        }

        if (csHelper == null)
        {
            PDColorSpace pdCS = PDColorSpaceFactory.createColorSpace(COSName.getPDFName(colorSpaceName));
            PreflightConfiguration cfg = context.getConfig();
            ColorSpaceHelperFactory csFact = cfg.getColorSpaceHelperFact();
            csHelper = csFact.getColorSpaceHelper(context, pdCS, ColorSpaceRestriction.NO_RESTRICTION);
        }

        csHelper.validate();
    }
View Full Code Here

        try
        {
            PDColorSpace pColorSpace = shadingRes.getColorSpace();
            PreflightConfiguration config = context.getConfig();
            ColorSpaceHelperFactory csFact = config.getColorSpaceHelperFact();
            ColorSpaceHelper csh = csFact.getColorSpaceHelper(context, pColorSpace, ColorSpaceRestriction.NO_PATTERN);
            csh.validate();
        }
        catch (IOException e)
        {
            context.addValidationError(new ValidationError(ERROR_GRAPHIC_INVALID_UNKNOWN_COLOR_SPACE, e.getMessage()));
        }
View Full Code Here

            {
                PreflightConfiguration config = context.getConfig();
                ColorSpaceHelperFactory colorSpaceFactory = config.getColorSpaceHelperFact();
                for (PDColorSpace pdCS : colorSpaces.values())
                {
                    ColorSpaceHelper csHelper = colorSpaceFactory.getColorSpaceHelper(context, pdCS,
                            ColorSpaceRestriction.NO_RESTRICTION);
                    csHelper.validate();
                }
            }
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.pdfbox.preflight.graphic.ColorSpaceHelper

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.