[FOray-commit] SF.net SVN: foray: [9779] trunk/foray
Modular XSL-FO Implementation for Java.
Status: Alpha
Brought to you by:
victormote
|
From: <vic...@us...> - 2007-06-13 21:04:36
|
Revision: 9779
http://svn.sourceforge.net/foray/?rev=9779&view=rev
Author: victormote
Date: 2007-06-13 14:04:33 -0700 (Wed, 13 Jun 2007)
Log Message:
-----------
Remove some dependencies on the PostScript module by moving some common PS code to Common.
Modified Paths:
--------------
trunk/foray/foray-graphic/src/java/org/foray/graphic/batik/PDFGraphics2D.java
trunk/foray/foray-graphic/src/java/org/foray/graphic/batik/PSGraphics2D.java
trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFColor.java
Added Paths:
-----------
trunk/foray/foray-common/src/java/org/foray/common/ps/
trunk/foray/foray-common/src/java/org/foray/common/ps/PSColor.java
trunk/foray/foray-common/src/java/org/foray/common/ps/package.html
Removed Paths:
-------------
trunk/foray/foray-ps/src/java/org/foray/ps/PSColor.java
Copied: trunk/foray/foray-common/src/java/org/foray/common/ps/PSColor.java (from rev 9778, trunk/foray/foray-ps/src/java/org/foray/ps/PSColor.java)
===================================================================
--- trunk/foray/foray-common/src/java/org/foray/common/ps/PSColor.java (rev 0)
+++ trunk/foray/foray-common/src/java/org/foray/common/ps/PSColor.java 2007-06-13 21:04:33 UTC (rev 9779)
@@ -0,0 +1,170 @@
+/*
+ * Copyright 2006 The FOray Project.
+ * http://www.foray.org
+ *
+ * Licensed 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.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.common.ps;
+
+import org.foray.common.PostScriptUtil;
+
+import java.awt.Color;
+import java.awt.color.ColorSpace;
+
+/**
+ * Utility class for PostScript color conversions.
+ */
+public final class PSColor {
+
+ /**
+ * Private constructor. This currently has only static methods.
+ */
+ private PSColor() {
+ }
+
+ /**
+ * Convert a Color to PostScript.
+ * @param color The AWT color instance that should be expressed in
+ * PostScript.
+ * @param fillNotStroke Set to true iff the color should be used for the
+ * fill but not for the stroke.
+ * @return The PostScript code that represents this color.
+ */
+ public static String toPS(final Color color, final boolean fillNotStroke) {
+ final int colorSpace = color.getColorSpace().getType();
+ switch (colorSpace) {
+ case ColorSpace.TYPE_RGB: {
+ return rgbToPS(color, fillNotStroke);
+ }
+ case ColorSpace.TYPE_CMYK: {
+ return cmykToPS(color, fillNotStroke);
+ }
+ default: {
+ return grayToPS(color, fillNotStroke);
+ }
+ }
+ }
+
+ /**
+ * Convert an RGB Color to PostScript.
+ * @param color The AWT color instance that should be expressed in
+ * PostScript.
+ * @param fillNotStroke Set to true iff the color should be used for the
+ * fill but not for the stroke.
+ * @return The PostScript code that represents this color.
+ */
+ private static String rgbToPS(final Color color,
+ final boolean fillNotStroke) {
+ final StringBuilder buffer = new StringBuilder("");
+
+ /* According to pdfspec 12.1 p.399, if the colors are the same then
+ * just use the g or G operator (DeviceGray). */
+ boolean isGray = false;
+ if (color.getRed() == color.getGreen()
+ && color.getRed() == color.getBlue()) {
+ isGray = true;
+ }
+ final float[] rgbColors = color.getComponents(null);
+
+ // fill
+ if (fillNotStroke) {
+ if (isGray) {
+ buffer.append(PostScriptUtil.doubleOut(rgbColors[0]) + " g");
+ } else {
+ buffer.append(PostScriptUtil.doubleOut(rgbColors[0]) + " "
+ + PostScriptUtil.doubleOut(rgbColors[1]) + " "
+ + PostScriptUtil.doubleOut(rgbColors[2])
+ + " rg");
+ }
+ // stroke/border
+ } else {
+ if (isGray) {
+ buffer.append(PostScriptUtil.doubleOut(rgbColors[0]) + " G");
+ } else {
+ buffer.append(PostScriptUtil.doubleOut(rgbColors[0]) + " "
+ + PostScriptUtil.doubleOut(rgbColors[1]) + " "
+ + PostScriptUtil.doubleOut(rgbColors[2])
+ + " RG");
+ }
+ }
+ return buffer.toString();
+ }
+
+ /**
+ * Convert a CMYK Color to PostScript.
+ * @param color The AWT color instance that should be expressed in
+ * PostScript.
+ * @param fillNotStroke Set to true iff the color should be used for the
+ * fill but not for the stroke.
+ * @return The PostScript code that represents this color.
+ */
+ private static String cmykToPS(final Color color,
+ final boolean fillNotStroke) {
+ final StringBuilder buffer = new StringBuilder("");
+ final float[] cmykColors = color.getComponents(null);
+ int index = 0;
+ if (fillNotStroke) {
+ /* Fill */
+ buffer.append(PostScriptUtil.doubleOut(cmykColors[index]) + " ");
+ index ++;
+ buffer.append(PostScriptUtil.doubleOut(cmykColors[index]) + " ");
+ index ++;
+ buffer.append(PostScriptUtil.doubleOut(cmykColors[index]) + " ");
+ index ++;
+ buffer.append(PostScriptUtil.doubleOut(cmykColors[index]) + " k");
+ } else {
+ /* Stroke ?? */
+ buffer.append(PostScriptUtil.doubleOut(cmykColors[index]) + " ");
+ index ++;
+ buffer.append(PostScriptUtil.doubleOut(cmykColors[index]) + " ");
+ index ++;
+ buffer.append(PostScriptUtil.doubleOut(cmykColors[index]) + " ");
+ index ++;
+ buffer.append(PostScriptUtil.doubleOut(cmykColors[index]) + " K");
+ }
+ return buffer.toString();
+ }
+
+ /**
+ * Convert a DeviceGray Color to PostScript.
+ * @param color The AWT color instance that should be expressed in
+ * PostScript.
+ * @param fillNotStroke Set to true iff the color should be used for the
+ * fill but not for the stroke.
+ * @return The PostScript code that represents this color.
+ */
+ private static String grayToPS(final Color color,
+ final boolean fillNotStroke) {
+ final StringBuilder buffer = new StringBuilder("");
+ final float[] grayColors = color.getComponents(null);
+ if (fillNotStroke) {
+ buffer.append(PostScriptUtil.doubleOut(grayColors[0]) + " g");
+ } else {
+ buffer.append(PostScriptUtil.doubleOut(grayColors[0]) + " G");
+ }
+ return buffer.toString();
+ }
+
+}
Added: trunk/foray/foray-common/src/java/org/foray/common/ps/package.html
===================================================================
--- trunk/foray/foray-common/src/java/org/foray/common/ps/package.html (rev 0)
+++ trunk/foray/foray-common/src/java/org/foray/common/ps/package.html 2007-06-13 21:04:33 UTC (rev 9779)
@@ -0,0 +1,11 @@
+<html>
+
+<head>
+<title>org.foray.common.ps Package</title>
+</head>
+
+<body>
+<p>Utility classes useful for working with PostScript.</p>
+</body>
+
+</html>
Property changes on: trunk/foray/foray-common/src/java/org/foray/common/ps/package.html
___________________________________________________________________
Name: svn:keywords
+ "Author Id Rev Date URL"
Name: svn:eol-style
+ native
Modified: trunk/foray/foray-graphic/src/java/org/foray/graphic/batik/PDFGraphics2D.java
===================================================================
--- trunk/foray/foray-graphic/src/java/org/foray/graphic/batik/PDFGraphics2D.java 2007-06-13 21:00:25 UTC (rev 9778)
+++ trunk/foray/foray-graphic/src/java/org/foray/graphic/batik/PDFGraphics2D.java 2007-06-13 21:04:33 UTC (rev 9779)
@@ -29,6 +29,7 @@
import org.foray.common.PostScriptUtil;
import org.foray.common.WKConstants;
+import org.foray.common.ps.PSColor;
import org.foray.pdf.PDFGraphicsState;
import org.foray.pdf.object.PDFAnnotList;
import org.foray.pdf.object.PDFDocument;
@@ -37,7 +38,6 @@
import org.foray.pdf.object.PDFPattern;
import org.foray.pdf.object.PDFString;
import org.foray.pdf.object.PDFXObject;
-import org.foray.ps.PSColor;
import org.axsl.fontR.FontConsumer;
import org.axsl.fontR.FontException;
Modified: trunk/foray/foray-graphic/src/java/org/foray/graphic/batik/PSGraphics2D.java
===================================================================
--- trunk/foray/foray-graphic/src/java/org/foray/graphic/batik/PSGraphics2D.java 2007-06-13 21:00:25 UTC (rev 9778)
+++ trunk/foray/foray-graphic/src/java/org/foray/graphic/batik/PSGraphics2D.java 2007-06-13 21:04:33 UTC (rev 9779)
@@ -36,8 +36,8 @@
import org.foray.common.CharacterOutputStream;
import org.foray.common.PostScriptUtil;
import org.foray.common.WKConstants;
+import org.foray.common.ps.PSColor;
import org.foray.graphic.TempImage;
-import org.foray.ps.PSColor;
import org.axsl.graphicR.Graphic;
Modified: trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFColor.java
===================================================================
--- trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFColor.java 2007-06-13 21:00:25 UTC (rev 9778)
+++ trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFColor.java 2007-06-13 21:04:33 UTC (rev 9779)
@@ -28,7 +28,7 @@
package org.foray.pdf.object;
-import org.foray.ps.PSColor;
+import org.foray.common.ps.PSColor;
import java.awt.Color;
import java.awt.color.ColorSpace;
Deleted: trunk/foray/foray-ps/src/java/org/foray/ps/PSColor.java
===================================================================
--- trunk/foray/foray-ps/src/java/org/foray/ps/PSColor.java 2007-06-13 21:00:25 UTC (rev 9778)
+++ trunk/foray/foray-ps/src/java/org/foray/ps/PSColor.java 2007-06-13 21:04:33 UTC (rev 9779)
@@ -1,170 +0,0 @@
-/*
- * Copyright 2006 The FOray Project.
- * http://www.foray.org
- *
- * Licensed 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.
- *
- * This work is in part derived from the following work(s), used with the
- * permission of the licensor:
- * Apache FOP, licensed by the Apache Software Foundation
- *
- */
-
-/*
- * $LastChangedRevision$
- * $LastChangedDate$
- * $LastChangedBy$
- */
-
-package org.foray.ps;
-
-import org.foray.common.PostScriptUtil;
-
-import java.awt.Color;
-import java.awt.color.ColorSpace;
-
-/**
- * Utility class for PostScript color conversions.
- */
-public final class PSColor {
-
- /**
- * Private constructor. This currently has only static methods.
- */
- private PSColor() {
- }
-
- /**
- * Convert a Color to PostScript.
- * @param color The AWT color instance that should be expressed in
- * PostScript.
- * @param fillNotStroke Set to true iff the color should be used for the
- * fill but not for the stroke.
- * @return The PostScript code that represents this color.
- */
- public static String toPS(final Color color, final boolean fillNotStroke) {
- final int colorSpace = color.getColorSpace().getType();
- switch (colorSpace) {
- case ColorSpace.TYPE_RGB: {
- return rgbToPS(color, fillNotStroke);
- }
- case ColorSpace.TYPE_CMYK: {
- return cmykToPS(color, fillNotStroke);
- }
- default: {
- return grayToPS(color, fillNotStroke);
- }
- }
- }
-
- /**
- * Convert an RGB Color to PostScript.
- * @param color The AWT color instance that should be expressed in
- * PostScript.
- * @param fillNotStroke Set to true iff the color should be used for the
- * fill but not for the stroke.
- * @return The PostScript code that represents this color.
- */
- private static String rgbToPS(final Color color,
- final boolean fillNotStroke) {
- final StringBuilder buffer = new StringBuilder("");
-
- /* According to pdfspec 12.1 p.399, if the colors are the same then
- * just use the g or G operator (DeviceGray). */
- boolean isGray = false;
- if (color.getRed() == color.getGreen()
- && color.getRed() == color.getBlue()) {
- isGray = true;
- }
- final float[] rgbColors = color.getComponents(null);
-
- // fill
- if (fillNotStroke) {
- if (isGray) {
- buffer.append(PostScriptUtil.doubleOut(rgbColors[0]) + " g");
- } else {
- buffer.append(PostScriptUtil.doubleOut(rgbColors[0]) + " "
- + PostScriptUtil.doubleOut(rgbColors[1]) + " "
- + PostScriptUtil.doubleOut(rgbColors[2])
- + " rg");
- }
- // stroke/border
- } else {
- if (isGray) {
- buffer.append(PostScriptUtil.doubleOut(rgbColors[0]) + " G");
- } else {
- buffer.append(PostScriptUtil.doubleOut(rgbColors[0]) + " "
- + PostScriptUtil.doubleOut(rgbColors[1]) + " "
- + PostScriptUtil.doubleOut(rgbColors[2])
- + " RG");
- }
- }
- return buffer.toString();
- }
-
- /**
- * Convert a CMYK Color to PostScript.
- * @param color The AWT color instance that should be expressed in
- * PostScript.
- * @param fillNotStroke Set to true iff the color should be used for the
- * fill but not for the stroke.
- * @return The PostScript code that represents this color.
- */
- private static String cmykToPS(final Color color,
- final boolean fillNotStroke) {
- final StringBuilder buffer = new StringBuilder("");
- final float[] cmykColors = color.getComponents(null);
- int index = 0;
- if (fillNotStroke) {
- /* Fill */
- buffer.append(PostScriptUtil.doubleOut(cmykColors[index]) + " ");
- index ++;
- buffer.append(PostScriptUtil.doubleOut(cmykColors[index]) + " ");
- index ++;
- buffer.append(PostScriptUtil.doubleOut(cmykColors[index]) + " ");
- index ++;
- buffer.append(PostScriptUtil.doubleOut(cmykColors[index]) + " k");
- } else {
- /* Stroke ?? */
- buffer.append(PostScriptUtil.doubleOut(cmykColors[index]) + " ");
- index ++;
- buffer.append(PostScriptUtil.doubleOut(cmykColors[index]) + " ");
- index ++;
- buffer.append(PostScriptUtil.doubleOut(cmykColors[index]) + " ");
- index ++;
- buffer.append(PostScriptUtil.doubleOut(cmykColors[index]) + " K");
- }
- return buffer.toString();
- }
-
- /**
- * Convert a DeviceGray Color to PostScript.
- * @param color The AWT color instance that should be expressed in
- * PostScript.
- * @param fillNotStroke Set to true iff the color should be used for the
- * fill but not for the stroke.
- * @return The PostScript code that represents this color.
- */
- private static String grayToPS(final Color color,
- final boolean fillNotStroke) {
- final StringBuilder buffer = new StringBuilder("");
- final float[] grayColors = color.getComponents(null);
- if (fillNotStroke) {
- buffer.append(PostScriptUtil.doubleOut(grayColors[0]) + " g");
- } else {
- buffer.append(PostScriptUtil.doubleOut(grayColors[0]) + " G");
- }
- return buffer.toString();
- }
-
-}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|