Пример #1
0
  /**
   * Create the current color from the colorspace and values.
   *
   * @return The current awt color.
   * @throws IOException If there is an error creating the color.
   */
  public Color createColor() throws IOException {
    Color retval = null;
    float[] components = colorSpaceValue.toFloatArray();
    try {

      if (colorSpace.getName().equals(PDDeviceRGB.NAME) && components.length == 3) {
        // for some reason, when using RGB and the RGB colorspace
        // the new Color doesn't maintain exactly the same values
        // I think some color conversion needs to take place first
        // for now we will just make rgb a special case.
        retval = new Color(components[0], components[1], components[2]);
      } else {

        ColorSpace cs = colorSpace.createColorSpace();

        if (colorSpace.getName().equals(PDSeparation.NAME) && components.length == 1) {

          // Use that component as a single-integer RGB value
          retval = new Color((int) components[0]);
        } else {
          retval = new Color(cs, components, 1f);
        }
      }
      return retval;
    } catch (java.lang.IllegalArgumentException IAe) {
      String Values = "Color Values: ";
      for (int i = 0; i < components.length; i++) {
        Values = Values + components[i] + "\t";
      }

      logger().severe(IAe.toString() + "\n" + Values + "\n at\n" + FullStackTrace(IAe));

      throw IAe;
    } catch (IOException IOe) {
      logger().severe(IOe.toString() + "\n at\n" + FullStackTrace(IOe));

      throw IOe;
    } catch (Exception e) {
      logger().severe(e.toString() + "\n at\n" + FullStackTrace(e));
      throw new IOException("Failed to Create Color");
    }
  }
  /**
   * Constructor creates an instance to be used for fill operations.
   *
   * @param shading the shading type to be used
   * @param colorModel the color model to be used
   * @param xform transformation for user to device space
   * @param ctm the transformation matrix
   * @param dBounds device bounds
   * @param pageHeight height of the current page
   */
  public RadialShadingContext(
      PDShadingType3 shading,
      ColorModel colorModel,
      AffineTransform xform,
      Matrix ctm,
      int pageHeight,
      Rectangle dBounds)
      throws IOException {
    super(shading, colorModel, xform, ctm, pageHeight, dBounds);
    this.radialShadingType = shading;
    coords = shading.getCoords().toFloatArray();

    if (ctm != null) {
      // the shading is used in combination with the sh-operator
      // transform the coords from shading to user space
      ctm.createAffineTransform().transform(coords, 0, coords, 0, 1);
      ctm.createAffineTransform().transform(coords, 3, coords, 3, 1);
      // scale radius to user space
      coords[2] *= ctm.getXScale();
      coords[5] *= ctm.getXScale();

      // move the 0,0-reference
      coords[1] = pageHeight - coords[1];
      coords[4] = pageHeight - coords[4];
    } else {
      // the shading is used as pattern colorspace in combination
      // with a fill-, stroke- or showText-operator
      float translateY = (float) xform.getTranslateY();
      // move the 0,0-reference including the y-translation from user to device space
      coords[1] = pageHeight + translateY - coords[1];
      coords[4] = pageHeight + translateY - coords[4];
    }

    // transform the coords from user to device space
    xform.transform(coords, 0, coords, 0, 1);
    xform.transform(coords, 3, coords, 3, 1);

    // scale radius to device space
    coords[2] *= xform.getScaleX();
    coords[5] *= xform.getScaleX();

    // a radius is always positive
    coords[2] = Math.abs(coords[2]);
    coords[5] = Math.abs(coords[5]);

    // domain values
    if (this.radialShadingType.getDomain() != null) {
      domain = shading.getDomain().toFloatArray();
    } else {
      // set default values
      domain = new float[] {0, 1};
    }

    // extend values
    COSArray extendValues = shading.getExtend();
    if (shading.getExtend() != null) {
      extend = new boolean[2];
      extend[0] = ((COSBoolean) extendValues.get(0)).getValue();
      extend[1] = ((COSBoolean) extendValues.get(1)).getValue();
    } else {
      // set default values
      extend = new boolean[] {false, false};
    }
    // calculate some constants to be used in getRaster
    x1x0 = coords[3] - coords[0];
    y1y0 = coords[4] - coords[1];
    r1r0 = coords[5] - coords[2];
    x1x0pow2 = Math.pow(x1x0, 2);
    y1y0pow2 = Math.pow(y1y0, 2);
    r0pow2 = Math.pow(coords[2], 2);
    denom = x1x0pow2 + y1y0pow2 - Math.pow(r1r0, 2);
    d1d0 = domain[1] - domain[0];

    // get background values if available
    COSArray bg = shading.getBackground();
    if (bg != null) {
      background = bg.toFloatArray();
      rgbBackground = convertToRGB(background);
    }
    longestDistance = getLongestDis();
    colorTable = calcColorTable();
  }
Пример #3
0
 /**
  * This will get the color space values. Either 1 for gray or 3 for RGB.
  *
  * @return The colorspace values.
  */
 public float[] getColorSpaceValue() {
   return colorSpaceValue.toFloatArray();
 }