/** * Create a Java colorspace for this colorspace. * * @return A color space that can be used for Java AWT operations. * @throws IOException If there is an error creating the color space. */ public ColorSpace createColorSpace() throws IOException { // throw new IOException( "Not implemented" ); try { /// dump some information to help figure these things out // logger().info( array.toString()); PDColorSpace alt = getAlternateColorSpace(); // logger().info(alt.toString()); ColorSpace CS = alt.createColorSpace(); // /dwilson 12/15/07 // logger().info(CS.toString() + " reporting type " + CS.getType() + " and having component // count of " + CS.getNumComponents()); return CS; } 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 ColorSpace"); } }
/** * 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"); } }