ASF Bugzilla – Attachment 24818 Details for
Bug 48237
[PATCH] afp renderer does not respect image color settings for svg
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
patch of proposed fix
bug_48237.patch (text/plain), 32.34 KB, created by
Peter Hancock
on 2010-01-08 02:34:14 UTC
(
hide
)
Description:
patch of proposed fix
Filename:
MIME Type:
Creator:
Peter Hancock
Created:
2010-01-08 02:34:14 UTC
Size:
32.34 KB
patch
obsolete
>Index: test/java/org/apache/fop/traits/BorderPropsTestCase.java >=================================================================== >--- test/java/org/apache/fop/traits/BorderPropsTestCase.java (revision 896921) >+++ test/java/org/apache/fop/traits/BorderPropsTestCase.java (working copy) >@@ -23,9 +23,10 @@ > > import junit.framework.TestCase; > >+import org.apache.xmlgraphics.java2d.CMYKColorSpace; >+import org.apache.xmlgraphics.java2d.ColorExt; >+ > import org.apache.fop.fo.Constants; >-import org.apache.fop.util.CMYKColorSpace; >-import org.apache.fop.util.ColorExt; > import org.apache.fop.util.ColorUtil; > > /** >Index: test/java/org/apache/fop/util/ColorUtilTestCase.java >=================================================================== >--- test/java/org/apache/fop/util/ColorUtilTestCase.java (revision 896921) >+++ test/java/org/apache/fop/util/ColorUtilTestCase.java (working copy) >@@ -24,6 +24,9 @@ > > import junit.framework.TestCase; > >+import org.apache.xmlgraphics.java2d.CMYKColorSpace; >+import org.apache.xmlgraphics.java2d.ColorExt; >+ > import org.apache.fop.apps.FOUserAgent; > import org.apache.fop.apps.FopFactory; > >Index: src/java/org/apache/fop/svg/PDFGraphics2D.java >=================================================================== >--- src/java/org/apache/fop/svg/PDFGraphics2D.java (revision 896921) >+++ src/java/org/apache/fop/svg/PDFGraphics2D.java (working copy) >@@ -66,6 +66,7 @@ > import org.apache.xmlgraphics.image.loader.impl.ImageRawJPEG; > import org.apache.xmlgraphics.image.loader.impl.ImageRendered; > import org.apache.xmlgraphics.java2d.AbstractGraphics2D; >+import org.apache.xmlgraphics.java2d.ColorExt; > import org.apache.xmlgraphics.java2d.GraphicContext; > > import org.apache.fop.fonts.Font; >@@ -91,7 +92,6 @@ > import org.apache.fop.render.pdf.ImageRawCCITTFaxAdapter; > import org.apache.fop.render.pdf.ImageRawJPEGAdapter; > import org.apache.fop.render.pdf.ImageRenderedAdapter; >-import org.apache.fop.util.ColorExt; > > /** > * PDF Graphics 2D. >Index: src/java/org/apache/fop/afp/modca/GraphicsObject.java >=================================================================== >--- src/java/org/apache/fop/afp/modca/GraphicsObject.java (revision 896921) >+++ src/java/org/apache/fop/afp/modca/GraphicsObject.java (working copy) >@@ -25,6 +25,8 @@ > import java.util.Iterator; > import java.util.List; > >+import org.apache.xmlgraphics.java2d.ColorConverter; >+ > import org.apache.fop.afp.AFPDataObjectInfo; > import org.apache.fop.afp.AFPObjectAreaInfo; > import org.apache.fop.afp.Completable; >@@ -65,6 +67,10 @@ > /** the graphics state */ > private final GraphicsState graphicsState = new GraphicsState(); > >+ >+ /** color converter */ >+ private ColorConverter colorConverter = null; >+ > /** > * Default constructor > * >@@ -140,12 +146,24 @@ > */ > public void setColor(Color color) { > if (!color.equals(graphicsState.color)) { >- addObject(new GraphicsSetProcessColor(color)); >+ addObject(new GraphicsSetProcessColor(colorConverter.convert(color))); > graphicsState.color = color; > } > } > >+ > /** >+ * Sets the color converter >+ * >+ * @param colorConverter ColorConverter to filter the color >+ * when creating a GraphicsSetProcessColor. >+ */ >+ public void setColorConverter(ColorConverter colorConverter) { >+ this.colorConverter = colorConverter; >+ } >+ >+ >+ /** > * Sets the current position > * > * @param coords the x and y coordinates of the current position >Index: src/java/org/apache/fop/afp/goca/GraphicsSetProcessColor.java >=================================================================== >--- src/java/org/apache/fop/afp/goca/GraphicsSetProcessColor.java (revision 896921) >+++ src/java/org/apache/fop/afp/goca/GraphicsSetProcessColor.java (working copy) >@@ -29,6 +29,16 @@ > */ > public class GraphicsSetProcessColor extends AbstractGraphicsDrawingOrder { > >+ /* >+ * GOCA Color space support: >+ * X'01' RGB >+ * X'04' CMYK >+ * X'06' Highlight color space >+ * X'08' CIELAB >+ * X'40' Standard OCA color space >+ */ >+ private static final byte RGB = 0x01, CMYK = 0x04; >+ > private final Color color; > > private final float[] colorComponents; >@@ -36,7 +46,8 @@ > /** > * Main constructor > * >- * @param color the color to set >+ * @param color >+ * the color to set > */ > public GraphicsSetProcessColor(Color color) { > this.color = color; >@@ -50,7 +61,7 @@ > > /** {@inheritDoc} */ > byte getOrderCode() { >- return (byte)0xB2; >+ return (byte) 0xB2; > } > > /** {@inheritDoc} */ >@@ -60,24 +71,24 @@ > byte colspace; > int colSpaceType = color.getColorSpace().getType(); > if (colSpaceType == ColorSpace.TYPE_CMYK) { >- colspace = 0x04; >+ colspace = CMYK; > } else if (colSpaceType == ColorSpace.TYPE_RGB) { >- colspace = 0x01; >+ colspace = RGB; > } else { > log.error("unsupported colorspace " + colSpaceType); >- colspace = 0x01; >+ colspace = RGB; > } > > // COLSIZE(S) > byte[] colsizes = new byte[] {0x00, 0x00, 0x00, 0x00}; > for (int i = 0; i < colorComponents.length; i++) { >- colsizes[i] = (byte)8; >+ colsizes[i] = (byte) 8; > } > > int len = getDataLength(); > byte[] data = new byte[len]; > data[0] = getOrderCode(); // GSPCOL order code >- data[1] = (byte)(len - 2); // LEN >+ data[1] = (byte) (len - 2); // LEN > data[2] = 0x00; // reserved; must be zero > data[3] = colspace; // COLSPCE > data[4] = 0x00; // reserved; must be zero >@@ -91,7 +102,7 @@ > > // COLVALUE(S) > for (int i = 0; i < colorComponents.length; i++) { >- data[i + 12] = (byte)(colorComponents[i] * 255); >+ data[i + 12] = (byte) (colorComponents[i] * 255); > } > > os.write(data); >@@ -101,4 +112,4 @@ > public String toString() { > return "GraphicsSetProcessColor(col=" + color + ")"; > } >-} >\ No newline at end of file >+} >Index: src/java/org/apache/fop/afp/AFPPaintingState.java >=================================================================== >--- src/java/org/apache/fop/afp/AFPPaintingState.java (revision 896921) >+++ src/java/org/apache/fop/afp/AFPPaintingState.java (working copy) >@@ -24,14 +24,19 @@ > import org.apache.commons.logging.Log; > import org.apache.commons.logging.LogFactory; > >+import org.apache.xmlgraphics.java2d.ColorConverter; >+import org.apache.xmlgraphics.java2d.DefaultColorConverter; >+import org.apache.xmlgraphics.java2d.GrayScaleColorConverter; >+ > import org.apache.fop.afp.fonts.AFPPageFonts; > import org.apache.fop.util.AbstractPaintingState; > > /** >- * This keeps information about the current painting state when writing to an AFP datastream. >+ * This keeps information about the current painting state when writing to an >+ * AFP datastream. > */ >-public class AFPPaintingState extends org.apache.fop.util.AbstractPaintingState >-implements Cloneable { >+public class AFPPaintingState extends org.apache.fop.util.AbstractPaintingState implements >+ Cloneable { > > private static final long serialVersionUID = 8206711712452344473L; > >@@ -46,9 +51,18 @@ > /** color image support */ > private boolean colorImages = false; > >- /** true if certain image formats may be embedded unchanged in their native format. */ >+ /** color image handler */ >+ private ColorConverter colorConverter = GrayScaleColorConverter.getInstance(); >+ >+ /** >+ * true if certain image formats may be embedded unchanged in their native >+ * format. >+ */ > private boolean nativeImagesSupported = false; >- /** true if CMYK images (requires IOCA FS45 suppport on the target platform) may be generated */ >+ /** >+ * true if CMYK images (requires IOCA FS45 suppport on the target platform) >+ * may be generated >+ */ > private boolean cmykImagesSupported; > > /** default value for image depth */ >@@ -60,13 +74,12 @@ > /** the current page */ > private transient AFPPagePaintingState pagePaintingState = new AFPPagePaintingState(); > >-// /** reference orientation */ >-// private int orientation = 0; >+ // /** reference orientation */ >+ // private int orientation = 0; > > /** a unit converter */ > private final transient AFPUnitConverter unitConv = new AFPUnitConverter(this); > >- > /** > * Sets the rotation to be used for portrait pages, valid values are 0 > * (default), 90, 180, 270. >@@ -75,13 +88,11 @@ > * The rotation in degrees. > */ > public void setPortraitRotation(int rotation) { >- if (rotation == 0 || rotation == 90 || rotation == 180 >- || rotation == 270) { >+ if (rotation == 0 || rotation == 90 || rotation == 180 || rotation == 270) { > portraitRotation = rotation; > } else { >- throw new IllegalArgumentException( >- "The portrait rotation must be one" >- + " of the values 0, 90, 180, 270"); >+ throw new IllegalArgumentException("The portrait rotation must be one" >+ + " of the values 0, 90, 180, 270"); > > } > } >@@ -103,13 +114,11 @@ > * The rotation in degrees. > */ > public void setLandscapeRotation(int rotation) { >- if (rotation == 0 || rotation == 90 || rotation == 180 >- || rotation == 270) { >+ if (rotation == 0 || rotation == 90 || rotation == 180 || rotation == 270) { > landscapeRotation = rotation; > } else { >- throw new IllegalArgumentException( >- "The landscape rotation must be one" >- + " of the values 0, 90, 180, 270"); >+ throw new IllegalArgumentException("The landscape rotation must be one" >+ + " of the values 0, 90, 180, 270"); > } > } > >@@ -152,13 +161,18 @@ > } > > /** >- * Sets whether images are color or not >+ * Sets whether images are color or not and instantiates a ColorHandler > * > * @param colorImages > * color image output > */ > public void setColorImages(boolean colorImages) { > this.colorImages = colorImages; >+ >+ if (colorImages) { >+ this.colorConverter = DefaultColorConverter.getInstance(); >+ } >+ > } > > /** >@@ -171,9 +185,19 @@ > } > > /** >+ * Used to convert color in respect of the colorImages flag >+ * >+ * @return the color converter >+ */ >+ public ColorConverter getColorConverter() { >+ return this.colorConverter; >+ } >+ >+ /** > * Sets whether images are natively supported or not in the AFP environment > * >- * @param nativeImagesSupported true if images are natively supported in this AFP environment >+ * @param nativeImagesSupported >+ * true if images are natively supported in this AFP environment > */ > public void setNativeImagesSupported(boolean nativeImagesSupported) { > this.nativeImagesSupported = nativeImagesSupported; >@@ -189,10 +213,12 @@ > } > > /** >- * Controls whether CMYK images (IOCA FS45) are enabled. By default, support is disabled >- * for wider compatibility. When disabled, any CMYK image is converted to the selected >- * color format. >- * @param value true to enabled CMYK images >+ * Controls whether CMYK images (IOCA FS45) are enabled. By default, support >+ * is disabled for wider compatibility. When disabled, any CMYK image is >+ * converted to the selected color format. >+ * >+ * @param value >+ * true to enabled CMYK images > */ > public void setCMYKImagesSupported(boolean value) { > this.cmykImagesSupported = value; >@@ -200,6 +226,7 @@ > > /** > * Indicates whether CMYK images (IOCA FS45) are enabled. >+ * > * @return true if IOCA FS45 is enabled > */ > public boolean isCMYKImagesSupported() { >@@ -259,7 +286,8 @@ > /** > * Sets the page width > * >- * @param pageWidth the page width >+ * @param pageWidth >+ * the page width > */ > public void setPageWidth(int pageWidth) { > pagePaintingState.setWidth(pageWidth); >@@ -277,7 +305,8 @@ > /** > * Sets the page height > * >- * @param pageHeight the page height >+ * @param pageHeight >+ * the page height > */ > public void setPageHeight(int pageHeight) { > pagePaintingState.setHeight(pageHeight); >@@ -304,10 +333,11 @@ > /** > * Sets the uri of the current image > * >- * @param uri the uri of the current image >+ * @param uri >+ * the uri of the current image > */ > public void setImageUri(String uri) { >- ((AFPData)getData()).imageUri = uri; >+ ((AFPData) getData()).imageUri = uri; > } > > /** >@@ -316,7 +346,7 @@ > * @return the uri of the current image > */ > public String getImageUri() { >- return ((AFPData)getData()).imageUri; >+ return ((AFPData) getData()).imageUri; > } > > /** >@@ -338,10 +368,13 @@ > } > > /** >- * Returns a point on the current page, taking the current painting state into account. >+ * Returns a point on the current page, taking the current painting state >+ * into account. > * >- * @param x the X-coordinate >- * @param y the Y-coordinate >+ * @param x >+ * the X-coordinate >+ * @param y >+ * the Y-coordinate > * @return a point on the current page > */ > public Point getPoint(int x, int y) { >@@ -370,12 +403,13 @@ > > /** {@inheritDoc} */ > public Object clone() { >- AFPPaintingState paintingState = (AFPPaintingState)super.clone(); >- paintingState.pagePaintingState = (AFPPagePaintingState)this.pagePaintingState.clone(); >+ AFPPaintingState paintingState = (AFPPaintingState) super.clone(); >+ paintingState.pagePaintingState = (AFPPagePaintingState) this.pagePaintingState.clone(); > paintingState.portraitRotation = this.portraitRotation; > paintingState.landscapeRotation = this.landscapeRotation; > paintingState.bitsPerPixel = this.bitsPerPixel; > paintingState.colorImages = this.colorImages; >+ paintingState.colorConverter = this.colorConverter; > paintingState.resolution = this.resolution; > return paintingState; > } >@@ -383,13 +417,9 @@ > /** {@inheritDoc} */ > public String toString() { > return "AFPPaintingState{" + "portraitRotation=" + portraitRotation >- + ", landscapeRotation=" + landscapeRotation >- + ", colorImages=" + colorImages >- + ", bitsPerPixel=" + bitsPerPixel >- + ", resolution=" + resolution >- + ", pageState=" + pagePaintingState >- + super.toString() >- + "}"; >+ + ", landscapeRotation=" + landscapeRotation + ", colorImages=" + colorImages >+ + ", bitsPerPixel=" + bitsPerPixel + ", resolution=" + resolution + ", pageState=" >+ + pagePaintingState + super.toString() + "}"; > } > > /** >@@ -423,7 +453,8 @@ > /** > * Sets the page width > * >- * @param width the page width >+ * @param width >+ * the page width > */ > protected void setWidth(int width) { > this.width = width; >@@ -441,7 +472,8 @@ > /** > * Sets the page height > * >- * @param height the page height >+ * @param height >+ * the page height > */ > protected void setHeight(int height) { > this.height = height; >@@ -459,7 +491,8 @@ > /** > * Sets the current page fonts > * >- * @param fonts the current page fonts >+ * @param fonts >+ * the current page fonts > */ > protected void setFonts(AFPPageFonts fonts) { > this.fonts = fonts; >@@ -486,7 +519,8 @@ > /** > * Sets the current page orientation > * >- * @param orientation the current page orientation >+ * @param orientation >+ * the current page orientation > */ > protected void setOrientation(int orientation) { > this.orientation = orientation; >@@ -505,12 +539,8 @@ > > /** {@inheritDoc} */ > public String toString() { >- return "AFPPagePaintingState{width=" + width >- + ", height=" + height >- + ", orientation=" + orientation >- + ", fonts=" + fonts >- + ", fontCount=" + fontCount >- + "}"; >+ return "AFPPagePaintingState{width=" + width + ", height=" + height + ", orientation=" >+ + orientation + ", fonts=" + fonts + ", fontCount=" + fontCount + "}"; > } > } > >@@ -527,7 +557,7 @@ > > /** {@inheritDoc} */ > public Object clone() { >- AFPData obj = (AFPData)super.clone(); >+ AFPData obj = (AFPData) super.clone(); > obj.filled = this.filled; > obj.imageUri = this.imageUri; > return obj; >@@ -535,10 +565,8 @@ > > /** {@inheritDoc} */ > public String toString() { >- return "AFPData{" + super.toString() >- + ", filled=" + filled >- + ", imageUri=" + imageUri >- + "}"; >+ return "AFPData{" + super.toString() + ", filled=" + filled + ", imageUri=" + imageUri >+ + "}"; > } > > /** {@inheritDoc} */ >Index: src/java/org/apache/fop/afp/AFPDataObjectFactory.java >=================================================================== >--- src/java/org/apache/fop/afp/AFPDataObjectFactory.java (revision 896921) >+++ src/java/org/apache/fop/afp/AFPDataObjectFactory.java (working copy) >@@ -165,6 +165,9 @@ > AFPGraphics2D g2d = graphicsObjectInfo.getGraphics2D(); > g2d.setGraphicsObject(graphicsObj); > >+ //set color converter (i.e. an rgb to grayscale converter) >+ graphicsObj.setColorConverter(g2d.getPaintingState().getColorConverter()); >+ > // paint to graphics object > Graphics2DImagePainter painter = graphicsObjectInfo.getPainter(); > Rectangle2D area = graphicsObjectInfo.getArea(); >Index: src/java/org/apache/fop/pdf/PDFColor.java >=================================================================== >--- src/java/org/apache/fop/pdf/PDFColor.java (revision 896921) >+++ src/java/org/apache/fop/pdf/PDFColor.java (working copy) >@@ -23,11 +23,11 @@ > import java.awt.color.ColorSpace; > import java.awt.color.ICC_ColorSpace; > import java.io.IOException; >+import java.util.ArrayList; > import java.util.List; >-import java.util.ArrayList; > >-import org.apache.fop.util.CMYKColorSpace; >-import org.apache.fop.util.ColorExt; >+import org.apache.xmlgraphics.java2d.CMYKColorSpace; >+import org.apache.xmlgraphics.java2d.ColorExt; > > /** > * PDF Color object. >Index: src/java/org/apache/fop/util/ColorUtil.java >=================================================================== >--- src/java/org/apache/fop/util/ColorUtil.java (revision 896921) >+++ src/java/org/apache/fop/util/ColorUtil.java (working copy) >@@ -27,6 +27,9 @@ > import org.apache.commons.logging.Log; > import org.apache.commons.logging.LogFactory; > >+import org.apache.xmlgraphics.java2d.CMYKColorSpace; >+import org.apache.xmlgraphics.java2d.ColorExt; >+ > import org.apache.fop.apps.FOUserAgent; > import org.apache.fop.fo.expr.PropertyException; > >@@ -679,20 +682,7 @@ > * @return the modified color > */ > public static Color lightenColor(Color col, float factor) { >- // TODO: This function converts the color into the sRGB namespace. >- // This should be avoided if possible. >- float[] cols = new float[4]; >- cols = col.getRGBComponents(cols); >- if (factor > 0) { >- cols[0] += (1.0 - cols[0]) * factor; >- cols[1] += (1.0 - cols[1]) * factor; >- cols[2] += (1.0 - cols[2]) * factor; >- } else { >- cols[0] -= cols[0] * -factor; >- cols[1] -= cols[1] * -factor; >- cols[2] -= cols[2] * -factor; >- } >- return new Color(cols[0], cols[1], cols[2], cols[3]); >+ return org.apache.xmlgraphics.java2d.ColorUtil.lightenColor(col, factor); > } > > /** >@@ -711,7 +701,7 @@ > * @return true if it is a gray value > */ > public static boolean isGray(Color col) { >- return (col.getRed() == col.getBlue() && col.getRed() == col.getGreen()); >+ return org.apache.xmlgraphics.java2d.ColorUtil.isGray(col); > } > > /** >@@ -720,10 +710,7 @@ > * @return the CMYK color > */ > public static Color toCMYKGrayColor(float black) { >- float[] cmyk = new float[] {0f, 0f, 0f, 1.0f - black}; >- CMYKColorSpace cmykCs = CMYKColorSpace.getInstance(); >- float[] rgb = cmykCs.toRGB(cmyk); >- return ColorExt.createFromFoRgbIcc(rgb[0], rgb[1], rgb[2], >- CMYK_PSEUDO_PROFILE, null, cmykCs, cmyk); >+ >+ return org.apache.xmlgraphics.java2d.ColorUtil.toCMYKGrayColor(black); > } > } >Index: src/java/org/apache/fop/util/CMYKColorSpace.java >=================================================================== >--- src/java/org/apache/fop/util/CMYKColorSpace.java (revision 896921) >+++ src/java/org/apache/fop/util/CMYKColorSpace.java (working copy) >@@ -1,81 +0,0 @@ >-/* >- * Licensed to the Apache Software Foundation (ASF) under one or more >- * contributor license agreements. See the NOTICE file distributed with >- * this work for additional information regarding copyright ownership. >- * The ASF licenses this file to You under the Apache License, Version 2.0 >- * (the "License"); you may not use this file except in compliance with >- * the License. You may obtain a copy of the License at >- * >- * http://www.apache.org/licenses/LICENSE-2.0 >- * >- * Unless required by applicable law or agreed to in writing, software >- * distributed under the License is distributed on an "AS IS" BASIS, >- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. >- * See the License for the specific language governing permissions and >- * limitations under the License. >- */ >- >-/* $Id$ */ >- >-package org.apache.fop.util; >- >-import java.awt.color.ColorSpace; >- >-/** >- * This class represents an uncalibrated CMYK color space. It is used by >- * the JpegImage class. >- */ >-public class CMYKColorSpace extends ColorSpace { >- >- private static CMYKColorSpace instance; >- >- /** >- * @see java.awt.color.ColorSpace#ColorSpace(int, int) >- */ >- protected CMYKColorSpace(int type, int numcomponents) { >- super(type, numcomponents); >- } >- >- /** >- * Returns an instance of an uncalibrated CMYK color space. >- * @return CMYKColorSpace the requested color space object >- */ >- public static CMYKColorSpace getInstance() { >- if (instance == null) { >- instance = new CMYKColorSpace(TYPE_CMYK, 4); >- } >- return instance; >- } >- >- /** >- * {@inheritDoc} >- */ >- public float[] toRGB(float[] colorvalue) { >- return new float [] { >- (1 - colorvalue[0]) * (1 - colorvalue[3]), >- (1 - colorvalue[1]) * (1 - colorvalue[3]), >- (1 - colorvalue[2]) * (1 - colorvalue[3])}; >- } >- >- /** >- * {@inheritDoc} >- */ >- public float[] fromRGB(float[] rgbvalue) { >- throw new UnsupportedOperationException("NYI"); >- } >- >- /** >- * {@inheritDoc} >- */ >- public float[] toCIEXYZ(float[] colorvalue) { >- throw new UnsupportedOperationException("NYI"); >- } >- >- /** >- * {@inheritDoc} >- */ >- public float[] fromCIEXYZ(float[] colorvalue) { >- throw new UnsupportedOperationException("NYI"); >- } >- >-} >Index: src/java/org/apache/fop/util/ColorExt.java >=================================================================== >--- src/java/org/apache/fop/util/ColorExt.java (revision 896921) >+++ src/java/org/apache/fop/util/ColorExt.java (working copy) >@@ -1,249 +0,0 @@ >-/* >- * Licensed to the Apache Software Foundation (ASF) under one or more >- * contributor license agreements. See the NOTICE file distributed with >- * this work for additional information regarding copyright ownership. >- * The ASF licenses this file to You under the Apache License, Version 2.0 >- * (the "License"); you may not use this file except in compliance with >- * the License. You may obtain a copy of the License at >- * >- * http://www.apache.org/licenses/LICENSE-2.0 >- * >- * Unless required by applicable law or agreed to in writing, software >- * distributed under the License is distributed on an "AS IS" BASIS, >- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. >- * See the License for the specific language governing permissions and >- * limitations under the License. >- */ >- >-/* $Id$ */ >- >-package org.apache.fop.util; >- >-import java.awt.Color; >-import java.awt.color.ColorSpace; >-import java.util.Arrays; >- >-/** >- * Color helper class. >- * <p> >- * This class extends java.awt.Color class keeping track of the original color >- * property values specified by the fo user in a rgb-icc call. >- */ >-public final class ColorExt extends Color { >- // >- private static final long serialVersionUID = 1L; >- >- // Values of fop-rgb-icc arguments >- private float rgbReplacementRed; >- private float rgbReplacementGreen; >- private float rgbReplacementBlue; >- >- private String iccProfileName; >- private String iccProfileSrc; >- private ColorSpace colorSpace; >- >- private float[] colorValues; >- >- /* >- * Helper for createFromFoRgbIcc >- */ >- private ColorExt(ColorSpace colorSpace, float[] colorValues, float opacity) { >- super(colorSpace, colorValues, opacity); >- } >- >- /* >- * Helper for createFromSvgIccColor >- */ >- private ColorExt(float red, float green, float blue, float opacity) { >- super(red, green, blue, opacity); >- } >- >- /** >- * Create ColorExt object backup up FO's rgb-icc color function >- * >- * @param redReplacement >- * Red part of RGB replacement color that will be used when ICC >- * profile can not be loaded >- * @param greenReplacement >- * Green part of RGB replacement color that will be used when ICC >- * profile can not be loaded >- * @param blueReplacement >- * Blue part of RGB replacement color that will be used when ICC >- * profile can not be loaded >- * @param profileName >- * Name of ICC profile >- * @param profileSrc >- * Source of ICC profile >- * @param colorSpace >- * ICC ColorSpace for the ICC profile >- * @param iccValues >- * color values >- * @return the requested color object >- */ >- public static ColorExt createFromFoRgbIcc(float redReplacement, >- float greenReplacement, float blueReplacement, String profileName, >- String profileSrc, ColorSpace colorSpace, float[] iccValues) { >- ColorExt ce = new ColorExt(colorSpace, iccValues, 1.0f); >- ce.rgbReplacementRed = redReplacement; >- ce.rgbReplacementGreen = greenReplacement; >- ce.rgbReplacementBlue = blueReplacement; >- ce.iccProfileName = profileName; >- ce.iccProfileSrc = profileSrc; >- ce.colorSpace = colorSpace; >- ce.colorValues = iccValues; >- return ce; >- } >- >- /** >- * Create ColorExt object backing up SVG's icc-color function. >- * >- * @param red >- * Red value resulting from the conversion from the user provided >- * (icc) color values to the batik (rgb) color space >- * @param green >- * Green value resulting from the conversion from the user >- * provided (icc) color values to the batik (rgb) color space >- * @param blue >- * Blue value resulting from the conversion from the user >- * provided (icc) color values to the batik (rgb) color space >- * @param opacity >- * Opacity >- * @param profileName >- * ICC profile name >- * @param profileHref >- * the URI to the color profile >- * @param profileCS >- * ICC ColorSpace profile >- * @param colorValues >- * ICC color values >- * @return the requested color object >- */ >- public static ColorExt createFromSvgIccColor(float red, float green, >- float blue, float opacity, String profileName, String profileHref, >- ColorSpace profileCS, float[] colorValues) { >- //TODO this method is not referenced by FOP, can it be deleted? >- ColorExt ce = new ColorExt(red, green, blue, opacity); >- ce.rgbReplacementRed = -1; >- ce.rgbReplacementGreen = -1; >- ce.rgbReplacementBlue = -1; >- ce.iccProfileName = profileName; >- ce.iccProfileSrc = profileHref; >- ce.colorSpace = profileCS; >- ce.colorValues = colorValues; >- return ce; >- >- } >- >- /** {@inheritDoc} */ >- public int hashCode() { >- //implementation from the superclass should be good enough for our purposes >- return super.hashCode(); >- } >- >- /** {@inheritDoc} */ >- public boolean equals(Object obj) { >- if (this == obj) { >- return true; >- } >- if (!super.equals(obj)) { >- return false; >- } >- if (getClass() != obj.getClass()) { >- return false; >- } >- ColorExt other = (ColorExt)obj; >- //TODO maybe use super.getColorComponents() instead >- if (!Arrays.equals(colorValues, other.colorValues)) { >- return false; >- } >- if (iccProfileName == null) { >- if (other.iccProfileName != null) { >- return false; >- } >- } else if (!iccProfileName.equals(other.iccProfileName)) { >- return false; >- } >- if (iccProfileSrc == null) { >- if (other.iccProfileSrc != null) { >- return false; >- } >- } else if (!iccProfileSrc.equals(other.iccProfileSrc)) { >- return false; >- } >- if (Float.floatToIntBits(rgbReplacementBlue) >- != Float.floatToIntBits(other.rgbReplacementBlue)) { >- return false; >- } >- if (Float.floatToIntBits(rgbReplacementGreen) >- != Float.floatToIntBits(other.rgbReplacementGreen)) { >- return false; >- } >- if (Float.floatToIntBits(rgbReplacementRed) >- != Float.floatToIntBits(other.rgbReplacementRed)) { >- return false; >- } >- return true; >- } >- >- /** >- * Get ICC profile name >- * >- * @return ICC profile name >- */ >- public String getIccProfileName() { >- return this.iccProfileName; >- } >- >- /** >- * Get ICC profile source >- * >- * @return ICC profile source >- */ >- public String getIccProfileSrc() { >- return this.iccProfileSrc; >- } >- >- /** >- * @return the original ColorSpace >- */ >- public ColorSpace getOrigColorSpace() { >- //TODO this method is probably unnecessary due to super.cs and getColorSpace() >- return this.colorSpace; >- } >- >- /** >- * Returns the original color values. >- * @return the original color values >- */ >- public float[] getOriginalColorComponents() { >- //TODO this method is probably unnecessary due to super.fvalue and getColorComponents() >- float[] copy = new float[this.colorValues.length]; >- System.arraycopy(this.colorValues, 0, copy, 0, copy.length); >- return copy; >- } >- >- /** >- * Create string representation of fop-rgb-icc function call to map this >- * ColorExt settings >- * @return the string representing the internal fop-rgb-icc() function call >- */ >- public String toFunctionCall() { >- StringBuffer sb = new StringBuffer(40); >- sb.append("fop-rgb-icc("); >- sb.append(this.rgbReplacementRed + ","); >- sb.append(this.rgbReplacementGreen + ","); >- sb.append(this.rgbReplacementBlue + ","); >- sb.append(this.iccProfileName + ","); >- if (this.iccProfileSrc != null) { >- sb.append("\"" + this.iccProfileSrc + "\""); >- } >- float[] colorComponents = this.getColorComponents(null); >- for (int ix = 0; ix < colorComponents.length; ix++) { >- sb.append(","); >- sb.append(colorComponents[ix]); >- } >- sb.append(")"); >- return sb.toString(); >- } >- >-} >Index: lib/xmlgraphics-commons-1.4svn.jar >=================================================================== >Cannot display: file marked as a binary type. >svn:mime-type = application/octet-stream
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 48237
:
24564
|
24606
|
24725
|
24779
| 24818