aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAdrian Cumiskey <acumiskey@apache.org>2008-08-14 13:25:54 +0000
committerAdrian Cumiskey <acumiskey@apache.org>2008-08-14 13:25:54 +0000
commitf476b8a6ab330d7eadb17ff79bce220995413012 (patch)
tree2f011aa0dccacabcf76a1649729e0c88ec535d63 /src
parent24bf14675b09101f0e0d9687a6882aef40813bea (diff)
downloadxmlgraphics-fop-f476b8a6ab330d7eadb17ff79bce220995413012.tar.gz
xmlgraphics-fop-f476b8a6ab330d7eadb17ff79bce220995413012.zip
Moved static method lightenColor() from PrintRenderer to ColorUtil. Thats one less Renderer interface dependency to worry about :).
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@685885 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src')
-rw-r--r--src/java/org/apache/fop/render/PrintRenderer.java24
-rw-r--r--src/java/org/apache/fop/render/afp/AFPRenderer.java9
-rw-r--r--src/java/org/apache/fop/render/java2d/Java2DRenderer.java15
-rw-r--r--src/java/org/apache/fop/render/pdf/PDFRenderer.java15
-rw-r--r--src/java/org/apache/fop/render/ps/PSRenderer.java15
-rw-r--r--src/java/org/apache/fop/util/ColorUtil.java23
6 files changed, 52 insertions, 49 deletions
diff --git a/src/java/org/apache/fop/render/PrintRenderer.java b/src/java/org/apache/fop/render/PrintRenderer.java
index 44b0a211d..56504ff53 100644
--- a/src/java/org/apache/fop/render/PrintRenderer.java
+++ b/src/java/org/apache/fop/render/PrintRenderer.java
@@ -20,7 +20,6 @@
package org.apache.fop.render;
// FOP
-import java.awt.Color;
import java.awt.geom.Rectangle2D;
import java.util.List;
import java.util.Map;
@@ -113,29 +112,6 @@ public abstract class PrintRenderer extends AbstractRenderer {
}
/**
- * Lightens up a color for groove, ridge, inset and outset border effects.
- * @param col the color to lighten up
- * @param factor factor by which to lighten up (negative values darken the color)
- * @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]);
- }
-
- /**
* Creates a RendererContext for an image.
* @param x the x coordinate (in millipoints)
* @param y the y coordinate (in millipoints)
diff --git a/src/java/org/apache/fop/render/afp/AFPRenderer.java b/src/java/org/apache/fop/render/afp/AFPRenderer.java
index b77ce9396..d5129f167 100644
--- a/src/java/org/apache/fop/render/afp/AFPRenderer.java
+++ b/src/java/org/apache/fop/render/afp/AFPRenderer.java
@@ -88,6 +88,7 @@ import org.apache.fop.render.afp.modca.AFPConstants;
import org.apache.fop.render.afp.modca.AFPDataStream;
import org.apache.fop.render.afp.modca.ImageObject;
import org.apache.fop.render.afp.modca.PageObject;
+import org.apache.fop.util.ColorUtil;
/**
* This is an implementation of a FOP Renderer that renders areas to AFP.
@@ -850,8 +851,8 @@ public class AFPRenderer extends AbstractPathOrientedRenderer {
{
float colFactor = (style == EN_GROOVE ? 0.4f : -0.4f);
if (horz) {
- Color uppercol = lightenColor(col, -colFactor);
- Color lowercol = lightenColor(col, colFactor);
+ Color uppercol = ColorUtil.lightenColor(col, -colFactor);
+ Color lowercol = ColorUtil.lightenColor(col, colFactor);
float h3 = h / 3;
float ym1 = y1;
afpDataStream.createLine(
@@ -879,8 +880,8 @@ public class AFPRenderer extends AbstractPathOrientedRenderer {
lowercol
);
} else {
- Color leftcol = lightenColor(col, -colFactor);
- Color rightcol = lightenColor(col, colFactor);
+ Color leftcol = ColorUtil.lightenColor(col, -colFactor);
+ Color rightcol = ColorUtil.lightenColor(col, colFactor);
float w3 = w / 3;
float xm1 = x1 + (w3 / 2);
afpDataStream.createLine(
diff --git a/src/java/org/apache/fop/render/java2d/Java2DRenderer.java b/src/java/org/apache/fop/render/java2d/Java2DRenderer.java
index 1dd353b3b..e3f79dea2 100644
--- a/src/java/org/apache/fop/render/java2d/Java2DRenderer.java
+++ b/src/java/org/apache/fop/render/java2d/Java2DRenderer.java
@@ -77,6 +77,7 @@ import org.apache.fop.render.Graphics2DAdapter;
import org.apache.fop.render.RendererContext;
import org.apache.fop.render.pdf.CTMHelper;
import org.apache.fop.util.CharUtilities;
+import org.apache.fop.util.ColorUtil;
/**
* The <code>Java2DRenderer</code> class provides the abstract technical
@@ -652,8 +653,8 @@ public abstract class Java2DRenderer extends AbstractPathOrientedRenderer implem
case Constants.EN_RIDGE:
float colFactor = (style == EN_GROOVE ? 0.4f : -0.4f);
if (horz) {
- Color uppercol = lightenColor(col, -colFactor);
- Color lowercol = lightenColor(col, colFactor);
+ Color uppercol = ColorUtil.lightenColor(col, -colFactor);
+ Color lowercol = ColorUtil.lightenColor(col, colFactor);
float h3 = h / 3;
float ym1 = y1 + (h3 / 2);
g2d.setStroke(new BasicStroke(h3));
@@ -664,8 +665,8 @@ public abstract class Java2DRenderer extends AbstractPathOrientedRenderer implem
g2d.setColor(lowercol);
g2d.draw(new Line2D.Float(x1, ym1 + h3 + h3, x2, ym1 + h3 + h3));
} else {
- Color leftcol = lightenColor(col, -colFactor);
- Color rightcol = lightenColor(col, colFactor);
+ Color leftcol = ColorUtil.lightenColor(col, -colFactor);
+ Color rightcol = ColorUtil.lightenColor(col, colFactor);
float w3 = w / 3;
float xm1 = x1 + (w3 / 2);
g2d.setStroke(new BasicStroke(w3));
@@ -681,13 +682,13 @@ public abstract class Java2DRenderer extends AbstractPathOrientedRenderer implem
case Constants.EN_OUTSET:
colFactor = (style == EN_OUTSET ? 0.4f : -0.4f);
if (horz) {
- col = lightenColor(col, (startOrBefore ? 1 : -1) * colFactor);
+ col = ColorUtil.lightenColor(col, (startOrBefore ? 1 : -1) * colFactor);
g2d.setStroke(new BasicStroke(h));
float ym1 = y1 + (h / 2);
g2d.setColor(col);
g2d.draw(new Line2D.Float(x1, ym1, x2, ym1));
} else {
- col = lightenColor(col, (startOrBefore ? 1 : -1) * colFactor);
+ col = ColorUtil.lightenColor(col, (startOrBefore ? 1 : -1) * colFactor);
float xm1 = x1 + (w / 2);
g2d.setStroke(new BasicStroke(w));
g2d.setColor(col);
@@ -859,7 +860,7 @@ public abstract class Java2DRenderer extends AbstractPathOrientedRenderer implem
case EN_RIDGE:
float half = area.getRuleThickness() / 2000f;
- state.updateColor(lightenColor(col, 0.6f));
+ state.updateColor(ColorUtil.lightenColor(col, 0.6f));
moveTo(startx, starty);
lineTo(endx, starty);
lineTo(endx, starty + 2 * half);
diff --git a/src/java/org/apache/fop/render/pdf/PDFRenderer.java b/src/java/org/apache/fop/render/pdf/PDFRenderer.java
index e3aef5e7f..8c016198b 100644
--- a/src/java/org/apache/fop/render/pdf/PDFRenderer.java
+++ b/src/java/org/apache/fop/render/pdf/PDFRenderer.java
@@ -116,6 +116,7 @@ import org.apache.fop.render.Graphics2DAdapter;
import org.apache.fop.render.RendererContext;
import org.apache.fop.util.CharUtilities;
import org.apache.fop.util.ColorProfileUtil;
+import org.apache.fop.util.ColorUtil;
/**
* Renderer that renders areas to PDF.
@@ -938,8 +939,8 @@ public class PDFRenderer extends AbstractPathOrientedRenderer {
float colFactor = (style == EN_GROOVE ? 0.4f : -0.4f);
currentStream.add("[] 0 d ");
if (horz) {
- Color uppercol = lightenColor(col, -colFactor);
- Color lowercol = lightenColor(col, colFactor);
+ Color uppercol = ColorUtil.lightenColor(col, -colFactor);
+ Color lowercol = ColorUtil.lightenColor(col, colFactor);
float h3 = h / 3;
currentStream.add(format(h3) + " w\n");
float ym1 = y1 + (h3 / 2);
@@ -953,8 +954,8 @@ public class PDFRenderer extends AbstractPathOrientedRenderer {
currentStream.add(format(x1) + " " + format(ym1 + h3 + h3) + " m "
+ format(x2) + " " + format(ym1 + h3 + h3) + " l S\n");
} else {
- Color leftcol = lightenColor(col, -colFactor);
- Color rightcol = lightenColor(col, colFactor);
+ Color leftcol = ColorUtil.lightenColor(col, -colFactor);
+ Color rightcol = ColorUtil.lightenColor(col, colFactor);
float w3 = w / 3;
currentStream.add(format(w3) + " w\n");
float xm1 = x1 + (w3 / 2);
@@ -977,14 +978,14 @@ public class PDFRenderer extends AbstractPathOrientedRenderer {
currentStream.add("[] 0 d ");
Color c = col;
if (horz) {
- c = lightenColor(c, (startOrBefore ? 1 : -1) * colFactor);
+ c = ColorUtil.lightenColor(c, (startOrBefore ? 1 : -1) * colFactor);
currentStream.add(format(h) + " w\n");
float ym1 = y1 + (h / 2);
setColor(c, false, null);
currentStream.add(format(x1) + " " + format(ym1) + " m "
+ format(x2) + " " + format(ym1) + " l S\n");
} else {
- c = lightenColor(c, (startOrBefore ? 1 : -1) * colFactor);
+ c = ColorUtil.lightenColor(c, (startOrBefore ? 1 : -1) * colFactor);
currentStream.add(format(w) + " w\n");
float xm1 = x1 + (w / 2);
setColor(c, false, null);
@@ -1771,7 +1772,7 @@ public class PDFRenderer extends AbstractPathOrientedRenderer {
case EN_RIDGE:
float half = area.getRuleThickness() / 2000f;
- setColor(lightenColor(col, 0.6f), true, null);
+ setColor(ColorUtil.lightenColor(col, 0.6f), true, null);
currentStream.add(format(startx) + " " + format(starty) + " m\n");
currentStream.add(format(endx) + " " + format(starty) + " l\n");
currentStream.add(format(endx) + " " + format(starty + 2 * half) + " l\n");
diff --git a/src/java/org/apache/fop/render/ps/PSRenderer.java b/src/java/org/apache/fop/render/ps/PSRenderer.java
index 9f8cdc771..4785ea14f 100644
--- a/src/java/org/apache/fop/render/ps/PSRenderer.java
+++ b/src/java/org/apache/fop/render/ps/PSRenderer.java
@@ -106,6 +106,7 @@ import org.apache.fop.render.ps.extensions.PSExtensionAttachment;
import org.apache.fop.render.ps.extensions.PSSetPageDevice;
import org.apache.fop.render.ps.extensions.PSSetupCode;
import org.apache.fop.util.CharUtilities;
+import org.apache.fop.util.ColorUtil;
/**
* Renderer that renders to PostScript.
@@ -839,8 +840,8 @@ public class PSRenderer extends AbstractPathOrientedRenderer
float colFactor = (style == EN_GROOVE ? 0.4f : -0.4f);
gen.useDash(null);
if (horz) {
- Color uppercol = lightenColor(col, -colFactor);
- Color lowercol = lightenColor(col, colFactor);
+ Color uppercol = ColorUtil.lightenColor(col, -colFactor);
+ Color lowercol = ColorUtil.lightenColor(col, colFactor);
float h3 = h / 3;
gen.useLineWidth(h3);
float ym1 = y1 + (h3 / 2);
@@ -851,8 +852,8 @@ public class PSRenderer extends AbstractPathOrientedRenderer
gen.useColor(lowercol);
drawLine(x1, ym1 + h3 + h3, x2, ym1 + h3 + h3);
} else {
- Color leftcol = lightenColor(col, -colFactor);
- Color rightcol = lightenColor(col, colFactor);
+ Color leftcol = ColorUtil.lightenColor(col, -colFactor);
+ Color rightcol = ColorUtil.lightenColor(col, colFactor);
float w3 = w / 3;
gen.useLineWidth(w3);
float xm1 = x1 + (w3 / 2);
@@ -869,13 +870,13 @@ public class PSRenderer extends AbstractPathOrientedRenderer
colFactor = (style == EN_OUTSET ? 0.4f : -0.4f);
gen.useDash(null);
if (horz) {
- Color c = lightenColor(col, (startOrBefore ? 1 : -1) * colFactor);
+ Color c = ColorUtil.lightenColor(col, (startOrBefore ? 1 : -1) * colFactor);
gen.useLineWidth(h);
float ym1 = y1 + (h / 2);
gen.useColor(c);
drawLine(x1, ym1, x2, ym1);
} else {
- Color c = lightenColor(col, (startOrBefore ? 1 : -1) * colFactor);
+ Color c = ColorUtil.lightenColor(col, (startOrBefore ? 1 : -1) * colFactor);
gen.useLineWidth(w);
float xm1 = x1 + (w / 2);
gen.useColor(c);
@@ -1570,7 +1571,7 @@ public class PSRenderer extends AbstractPathOrientedRenderer
case EN_RIDGE:
float half = area.getRuleThickness() / 2000f;
- gen.useColor(lightenColor(col, 0.6f));
+ gen.useColor(ColorUtil.lightenColor(col, 0.6f));
moveTo(startx, starty);
lineTo(endx, starty);
lineTo(endx, starty + 2 * half);
diff --git a/src/java/org/apache/fop/util/ColorUtil.java b/src/java/org/apache/fop/util/ColorUtil.java
index b85b0c017..9534bfba3 100644
--- a/src/java/org/apache/fop/util/ColorUtil.java
+++ b/src/java/org/apache/fop/util/ColorUtil.java
@@ -658,4 +658,27 @@ public final class ColorUtil {
colorMap.put("transparent", new Color(0, 0, 0, 0));
}
+ /**
+ * Lightens up a color for groove, ridge, inset and outset border effects.
+ * @param col the color to lighten up
+ * @param factor factor by which to lighten up (negative values darken the color)
+ * @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]);
+ }
+
}