List of usage examples for java.awt Color getColorSpace
public ColorSpace getColorSpace()
From source file:org.apache.fop.util.ColorUtil.java
private static Color getsRGBFallback(ColorWithAlternatives color) { Color fallbackColor; if (color instanceof ColorWithFallback) { fallbackColor = ((ColorWithFallback) color).getFallbackColor(); if (!fallbackColor.getColorSpace().isCS_sRGB()) { fallbackColor = toSRGBColor(fallbackColor); }//from w ww .j a v a 2 s .co m } else { fallbackColor = toSRGBColor(color); } return fallbackColor; }
From source file:org.apache.fop.util.ColorUtil.java
/** * Create string representation of a fop-rgb-icc (or fop-rgb-named-color) function call from * the given color.// w w w .jav a2 s. com * @param color the color to turn into a function call * @return the string representing the internal fop-rgb-icc() or fop-rgb-named-color() * function call */ private static String toFunctionCall(ColorWithAlternatives color) { ColorSpace cs = color.getColorSpace(); if (cs.isCS_sRGB() && !color.hasAlternativeColors()) { return toRGBFunctionCall(color); } if (cs instanceof CIELabColorSpace) { return toCIELabFunctionCall(color); } Color specColor = color; if (color.hasAlternativeColors()) { Color alt = color.getAlternativeColors()[0]; if (ColorSpaces.isDeviceColorSpace(alt.getColorSpace())) { cs = alt.getColorSpace(); specColor = alt; } } ColorSpaceOrigin origin = ColorSpaces.getColorSpaceOrigin(cs); String functionName; Color fallbackColor = getsRGBFallback(color); float[] rgb = fallbackColor.getColorComponents(null); assert rgb.length == 3; StringBuffer sb = new StringBuffer(40); sb.append("("); sb.append(rgb[0]).append(","); sb.append(rgb[1]).append(","); sb.append(rgb[2]).append(","); String profileName = origin.getProfileName(); sb.append(profileName).append(","); if (origin.getProfileURI() != null) { sb.append("\"").append(origin.getProfileURI()).append("\""); } if (cs instanceof NamedColorSpace) { NamedColorSpace ncs = (NamedColorSpace) cs; if (SEPARATION_PSEUDO_PROFILE.equalsIgnoreCase(profileName)) { functionName = "fop-rgb-icc"; } else { functionName = "fop-rgb-named-color"; } sb.append(",").append(ncs.getColorName()); } else { functionName = "fop-rgb-icc"; float[] colorComponents = specColor.getColorComponents(null); for (float colorComponent : colorComponents) { sb.append(","); sb.append(colorComponent); } } sb.append(")"); return functionName + sb.toString(); }
From source file:org.apache.pdfbox.pdfviewer.PageDrawer.java
/** * You should override this method if you want to perform an action when a * text is being processed./*from www . jav a2 s. co m*/ * * @param text The text to process */ protected void processTextPosition(TextPosition text) { try { PDGraphicsState graphicsState = getGraphicsState(); Composite composite; Paint paint; switch (graphicsState.getTextState().getRenderingMode()) { case PDTextState.RENDERING_MODE_FILL_TEXT: composite = graphicsState.getNonStrokeJavaComposite(); paint = graphicsState.getNonStrokingColor().getJavaColor(); if (paint == null) { paint = graphicsState.getNonStrokingColor().getPaint(pageSize.height); } break; case PDTextState.RENDERING_MODE_STROKE_TEXT: composite = graphicsState.getStrokeJavaComposite(); paint = graphicsState.getStrokingColor().getJavaColor(); if (paint == null) { paint = graphicsState.getStrokingColor().getPaint(pageSize.height); } break; case PDTextState.RENDERING_MODE_NEITHER_FILL_NOR_STROKE_TEXT: //basic support for text rendering mode "invisible" Color nsc = graphicsState.getStrokingColor().getJavaColor(); float[] components = { Color.black.getRed(), Color.black.getGreen(), Color.black.getBlue() }; paint = new Color(nsc.getColorSpace(), components, 0f); composite = graphicsState.getStrokeJavaComposite(); break; default: // TODO : need to implement.... LOG.debug("Unsupported RenderingMode " + this.getGraphicsState().getTextState().getRenderingMode() + " in PageDrawer.processTextPosition()." + " Using RenderingMode " + PDTextState.RENDERING_MODE_FILL_TEXT + " instead"); composite = graphicsState.getNonStrokeJavaComposite(); paint = graphicsState.getNonStrokingColor().getJavaColor(); } graphics.setComposite(composite); graphics.setPaint(paint); PDFont font = text.getFont(); Matrix textPos = text.getTextPos().copy(); float x = textPos.getXPosition(); // the 0,0-reference has to be moved from the lower left (PDF) to the upper left (AWT-graphics) float y = pageSize.height - textPos.getYPosition(); // Set translation to 0,0. We only need the scaling and shearing textPos.setValue(2, 0, 0); textPos.setValue(2, 1, 0); // because of the moved 0,0-reference, we have to shear in the opposite direction textPos.setValue(0, 1, (-1) * textPos.getValue(0, 1)); textPos.setValue(1, 0, (-1) * textPos.getValue(1, 0)); AffineTransform at = textPos.createAffineTransform(); PDMatrix fontMatrix = font.getFontMatrix(); at.scale(fontMatrix.getValue(0, 0) * 1000f, fontMatrix.getValue(1, 1) * 1000f); //TODO setClip() is a massive performance hot spot. Investigate optimization possibilities graphics.setClip(graphicsState.getCurrentClippingPath()); // the fontSize is no longer needed as it is already part of the transformation // we should remove it from the parameter list in the long run font.drawString(text.getCharacter(), text.getCodePoints(), graphics, 1, at, x, y); } catch (IOException io) { io.printStackTrace(); } }
From source file:org.apache.pdfbox.pdmodel.edit.PDPageContentStream.java
/** * Set the stroking color, specified as RGB. * * @param color The color to set./*from w ww . j a v a 2s . com*/ * @throws IOException If an IO error occurs while writing to the stream. */ public void setStrokingColor(Color color) throws IOException { ColorSpace colorSpace = color.getColorSpace(); if (colorSpace.getType() == ColorSpace.TYPE_RGB) { setStrokingColor(color.getRed(), color.getGreen(), color.getBlue()); } else if (colorSpace.getType() == ColorSpace.TYPE_GRAY) { color.getColorComponents(colorComponents); setStrokingColor(colorComponents[0]); } else if (colorSpace.getType() == ColorSpace.TYPE_CMYK) { color.getColorComponents(colorComponents); setStrokingColor(colorComponents[0], colorComponents[2], colorComponents[2], colorComponents[3]); } else { throw new IOException("Error: unknown colorspace:" + colorSpace); } }
From source file:org.apache.pdfbox.pdmodel.edit.PDPageContentStream.java
/** * Set the non stroking color, specified as RGB. * * @param color The color to set.// w w w .ja va 2 s. co m * @throws IOException If an IO error occurs while writing to the stream. */ public void setNonStrokingColor(Color color) throws IOException { ColorSpace colorSpace = color.getColorSpace(); if (colorSpace.getType() == ColorSpace.TYPE_RGB) { setNonStrokingColor(color.getRed(), color.getGreen(), color.getBlue()); } else if (colorSpace.getType() == ColorSpace.TYPE_GRAY) { color.getColorComponents(colorComponents); setNonStrokingColor(colorComponents[0]); } else if (colorSpace.getType() == ColorSpace.TYPE_CMYK) { color.getColorComponents(colorComponents); setNonStrokingColor(colorComponents[0], colorComponents[2], colorComponents[2], colorComponents[3]); } else { throw new IOException("Error: unknown colorspace:" + colorSpace); } }
From source file:org.apache.xmlgraphics.ps.PSGenerator.java
private boolean establishColorFromColor(StringBuffer codeBuffer, Color color) { //Important: see above note about color handling! float[] comps = color.getColorComponents(null); if (color.getColorSpace().getType() == ColorSpace.TYPE_CMYK) { // colorspace is CMYK writeSetColor(codeBuffer, comps, "setcmykcolor"); return true; }/* w w w .jav a2 s .com*/ return false; }
From source file:org.apache.xmlgraphics.ps.PSGenerator.java
private void establishFallbackRGB(StringBuffer codeBuffer, Color color) { float[] comps; if (color.getColorSpace().isCS_sRGB()) { comps = color.getColorComponents(null); } else {/* w w w . j a v a2s .com*/ if (log.isDebugEnabled()) { log.debug("Converting color to sRGB as a fallback: " + color); } ColorSpace sRGB = ColorSpace.getInstance(ColorSpace.CS_sRGB); comps = color.getColorComponents(sRGB, null); } assert comps.length == 3; boolean gray = ColorUtil.isGray(color); if (gray) { comps = new float[] { comps[0] }; } writeSetColor(codeBuffer, comps, gray ? "setgray" : "setrgbcolor"); }