コード例 #1
0
  private void writeColorSpace(PDColorSpace colorSpace) throws IOException {
    COSName key = null;
    if (colorSpace instanceof PDDeviceGray
        || colorSpace instanceof PDDeviceRGB
        || colorSpace instanceof PDDeviceCMYK) {
      key = COSName.getPDFName(colorSpace.getName());
    } else {
      COSDictionary colorSpaces =
          (COSDictionary) resources.getCOSDictionary().getDictionaryObject(COSName.COLORSPACE);
      if (colorSpaces == null) {
        colorSpaces = new COSDictionary();
        resources.getCOSDictionary().setItem(COSName.COLORSPACE, colorSpaces);
      }
      key = colorSpaces.getKeyForValue(colorSpace.getCOSObject());

      if (key == null) {
        int counter = 0;
        String csName = "CS";
        while (colorSpaces.containsValue(csName + counter)) {
          counter++;
        }
        key = COSName.getPDFName(csName + counter);
        colorSpaces.setItem(key, colorSpace);
      }
    }
    key.writePDF(output);
    appendRawCommands(SPACE);
  }
コード例 #2
0
 /**
  * Method called by the processAllColorSpace if the ColorSpace to check is Separation. Because
  * this kind of ColorSpace can have an alternate color space, the processAllColorSpace is called
  * to check this alternate color space. (Indexed, Separation, DeviceN and Pattern can't be a Base
  * color space)
  *
  * @param colorSpace the color space object to check.
  */
 protected void processSeparationColorSpace(PDColorSpace colorSpace) {
   try {
     COSBase cosAlt = ((COSArray) colorSpace.getCOSObject()).getObject(2);
     PDColorSpace altCol = PDColorSpace.create(cosAlt);
     if (altCol != null) {
       ColorSpaces acs = ColorSpaces.valueOf(altCol.getName());
       switch (acs) {
         case Separation:
         case DeviceN:
         case Pattern:
         case Indexed:
         case I:
           context.addValidationError(
               new ValidationError(
                   ERROR_GRAPHIC_INVALID_COLOR_SPACE_ALTERNATE,
                   acs.getLabel() + " color space can't be used as alternate color space"));
           break;
         default:
           processAllColorSpace(altCol);
       }
     }
   } catch (IOException e) {
     context.addValidationError(
         new ValidationError(
             ERROR_GRAPHIC_INVALID_COLOR_SPACE,
             "Unable to read Separation color space : " + e.getMessage(),
             e));
   }
 }
コード例 #3
0
ファイル: PDSeparation.java プロジェクト: fabled1/DiscVac
 /**
  * This will set the alternate color space.
  *
  * @param cs The alternate color space.
  */
 public void setAlternateColorSpace(PDColorSpace cs) {
   COSBase space = null;
   if (cs != null) {
     space = cs.getCOSObject();
   }
   array.set(2, space);
 }
コード例 #4
0
  /**
   * Method called by the processAllColorSpace if the ColorSpace to check is DeviceN. Because this
   * kind of ColorSpace can have alternate color space, the processAllColorSpace is called to check
   * this alternate color space. (There are no restrictions on the Alternate Color space)
   *
   * @param colorSpace the color space object to check.
   */
  protected void processDeviceNColorSpace(PDColorSpace colorSpace) {
    PDDeviceN deviceN = (PDDeviceN) colorSpace;
    try {
      if (iccpw == null) {
        context.addValidationError(
            new ValidationError(
                ERROR_GRAPHIC_INVALID_COLOR_SPACE_MISSING, "DestOutputProfile is missing"));
        return;
      }

      COSBase cosAlt = ((COSArray) colorSpace.getCOSObject()).getObject(2);
      PDColorSpace altColor = PDColorSpace.create(cosAlt);
      if (altColor != null) {
        processAllColorSpace(altColor);
      }

      int numberOfColorants = 0;
      PDDeviceNAttributes attr = deviceN.getAttributes();
      if (attr != null) {
        final Map<String, PDSeparation> colorants = attr.getColorants();
        if (colorants != null) {
          numberOfColorants = colorants.size();
          for (PDSeparation col : colorants.values()) {
            if (col != null) {
              processAllColorSpace(col);
            }
          }
        }
      }
      int numberOfComponents = deviceN.getNumberOfComponents();
      if (numberOfColorants > MAX_DEVICE_N_LIMIT || numberOfComponents > MAX_DEVICE_N_LIMIT) {
        context.addValidationError(
            new ValidationError(
                ERROR_GRAPHIC_INVALID_COLOR_SPACE_TOO_MANY_COMPONENTS_DEVICEN,
                "DeviceN has too many tint components or colorants"));
      }
    } catch (IOException e) {
      context.addValidationError(
          new ValidationError(
              ERROR_GRAPHIC_INVALID_COLOR_SPACE,
              "Unable to read DeviceN color space : " + e.getMessage(),
              e));
    }
  }