コード例 #1
0
 public void validate(PreflightContext context) throws ValidationException {
   PreflightPath vPath = context.getValidationPath();
   if (vPath.isEmpty()) {
     return;
   } else if (!vPath.isExpectedType(PDFont.class)) {
     context.addValidationError(
         new ValidationError(
             PreflightConstants.ERROR_FONTS_INVALID_DATA,
             "Font validation process needs at least one PDFont object"));
   } else {
     PDFont font = (PDFont) vPath.peek();
     FontContainer fontContainer = context.getFontContainer(font.getCOSObject());
     if (fontContainer == null) { // if fontContainer isn't null the font is already checked
       FontValidator<? extends FontContainer> validator = getFontValidator(context, font);
       if (validator != null) validator.validate();
     }
   }
 }
コード例 #2
0
  /**
   * Look up in the closest PDResources objects if there are a default ColorSpace. If there are,
   * check that is a authorized ColorSpace.
   *
   * @param colorSpace
   * @return true if the default colorspace is a right one, false otherwise.
   */
  protected boolean processDefaultColorSpace(PDColorSpace colorSpace) {
    boolean result = false;

    // get default color space
    PreflightPath vPath = context.getValidationPath();
    PDResources resources = vPath.getClosestPathElement(PDResources.class);
    if (resources != null) {
      PDColorSpace defaultCS = null;

      try {
        if (colorSpace.getName().equals(ColorSpaces.DeviceCMYK.getLabel())
            && resources.hasColorSpace(COSName.DEFAULT_CMYK)) {
          defaultCS = resources.getColorSpace(COSName.DEFAULT_CMYK);
        } else if (colorSpace.getName().equals(ColorSpaces.DeviceRGB.getLabel())
            && resources.hasColorSpace(COSName.DEFAULT_RGB)) {
          defaultCS = resources.getColorSpace(COSName.DEFAULT_RGB);
        } else if (colorSpace.getName().equals(ColorSpaces.DeviceGray.getLabel())
            && resources.hasColorSpace(COSName.DEFAULT_GRAY)) {
          defaultCS = resources.getColorSpace(COSName.DEFAULT_GRAY);
        }
      } catch (IOException e) {
        context.addValidationError(
            new ValidationError(
                ERROR_GRAPHIC_INVALID_COLOR_SPACE,
                "Unable to read default color space : " + e.getMessage(),
                e));
      }

      if (defaultCS != null) {
        // defaultCS is valid if the number of errors hasn't changed
        int nbOfErrors = context.getDocument().getResult().getErrorsList().size();
        processAllColorSpace(defaultCS);
        int newNbOfErrors = context.getDocument().getResult().getErrorsList().size();
        result = (nbOfErrors == newNbOfErrors);
      }
    }

    return result;
  }