Thread: [FOray-commit] SF.net SVN: foray: [9774] trunk/foray (Page 15)
Modular XSL-FO Implementation for Java.
Status: Alpha
Brought to you by:
victormote
|
From: <vic...@us...> - 2007-06-13 18:55:55
|
Revision: 9774
http://svn.sourceforge.net/foray/?rev=9774&view=rev
Author: victormote
Date: 2007-06-13 11:55:56 -0700 (Wed, 13 Jun 2007)
Log Message:
-----------
1. Use the bare color where possible instead of the PDF wrapper.
2. Move some variables to the PDF graphics state.
Modified Paths:
--------------
trunk/foray/foray-graphic/src/java/org/foray/graphic/batik/PDFGraphics2D.java
trunk/foray/foray-pdf/src/java/org/foray/pdf/PDFGraphicsState.java
trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFContentStream.java
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 17:39:26 UTC (rev 9773)
+++ trunk/foray/foray-graphic/src/java/org/foray/graphic/batik/PDFGraphics2D.java 2007-06-13 18:55:56 UTC (rev 9774)
@@ -29,6 +29,7 @@
import org.foray.common.ColorSpaceCMYK;
import org.foray.common.WKConstants;
+import org.foray.pdf.PDFGraphicsState;
import org.foray.pdf.object.PDFAnnotList;
import org.foray.pdf.object.PDFColor;
import org.foray.pdf.object.PDFDocument;
@@ -116,12 +117,6 @@
/** The PDF Document being created. */
private PDFDocument pdfDoc;
- /** The current (internal) font. */
- private org.axsl.fontR.FontUse currentFont;
-
- /** The current font size in millipoints. */
- private float currentFontSize;
-
/** The current stream to add PDF commands to. */
private StringWriter currentStream = new StringWriter();
@@ -152,6 +147,9 @@
/** The PDF context. */
private GraphicPdfContext pdfContext;
+ /** The graphics state. */
+ private PDFGraphicsState graphicsState;
+
/**
* Create a new PDFGraphics2D with the given pdf document info.
* This is used to create a Graphics object for use inside an already
@@ -177,7 +175,7 @@
this.logger = logger;
this.fontConsumer = fontConsumer;
this.pdfContext = pdfContext;
- currentFontSize = this.pdfDoc.getCurrentGraphicsState().getFontSize();
+ this.graphicsState = new PDFGraphicsState();
initGraphicalEnvironment();
transformCoordinates(contentRectangle, svgDocument);
}
@@ -447,7 +445,6 @@
public void dispose() {
pdfDoc = null;
currentStream = null;
- currentFont = null;
currentColour = null;
}
@@ -749,9 +746,10 @@
overrideFont = null;
}
- if (font != this.currentFont || (size != this.currentFontSize)) {
- this.currentFont = font;
- this.currentFontSize = size;
+ if (font != this.graphicsState.getFont()
+ || (size != this.graphicsState.getFontSize())) {
+ this.graphicsState.setFont(font);
+ this.graphicsState.setFontSize(size);
final String fontName = this.pdfContext.getFontName(font);
currentStream.write("/" + fontName + " " + size + " Tf\n");
}
@@ -808,9 +806,7 @@
fontWeight = org.axsl.fontR.Font.Weight.BOLD;
}
try {
- final FontConsumer fontConsumer =
- this.currentFont.getFontConsumer();
- return fontConsumer.selectFontXSL(
+ return this.fontConsumer.selectFontXSL(
org.axsl.fontR.Font.SelectionStrategy.AUTO,
FontUtility.foFontFamily(fontFamily),
fontStyle, fontWeight,
@@ -867,10 +863,10 @@
continue;
}
final float size = fontSize.floatValue();
- if ((font != this.currentFont)
- || (size != this.currentFontSize)) {
- this.currentFont = font;
- this.currentFontSize = size;
+ if ((font != this.graphicsState.getFont())
+ || (size != this.graphicsState.getFontSize())) {
+ this.graphicsState.setFont(font);
+ this.graphicsState.setFontSize(size);
final String fontName = this.pdfContext.getFontName(font);
currentStream.write("/" + fontName + " " + size + " Tf\n");
}
Modified: trunk/foray/foray-pdf/src/java/org/foray/pdf/PDFGraphicsState.java
===================================================================
--- trunk/foray/foray-pdf/src/java/org/foray/pdf/PDFGraphicsState.java 2007-06-13 17:39:26 UTC (rev 9773)
+++ trunk/foray/foray-pdf/src/java/org/foray/pdf/PDFGraphicsState.java 2007-06-13 18:55:56 UTC (rev 9774)
@@ -28,8 +28,6 @@
package org.foray.pdf;
-import org.foray.pdf.object.PDFColor;
-
import org.axsl.fontR.FontUse;
import org.axsl.pdfW.PDFLineCapStyle;
@@ -45,10 +43,10 @@
public class PDFGraphicsState {
/** The stroke color. */
- private PDFColor strokeColor;
+ private Color strokeColor;
/** The "non-stroke" or "other" color. */
- private PDFColor fillColor;
+ private Color fillColor;
/** The character spacing, in points. */
private float characterSpacing;
@@ -84,8 +82,8 @@
* PDF Reference, 3rd Edition, Section 4.3.
*/
public void reset() {
- this.strokeColor = new org.foray.pdf.object.PDFColor(Color.BLACK);
- this.fillColor = new org.foray.pdf.object.PDFColor(Color.BLACK);
+ this.strokeColor = Color.BLACK;
+ this.fillColor = Color.BLACK;
this.characterSpacing = 0;
this.wordSpacing = 0;
this.font = null;
@@ -97,11 +95,11 @@
/**
* Sets the stroke color (Graphics State holds two colors, one for stroke
- * operations and one for all other operations.
+ * operations and one for all other operations).
* @param newStrokeColor The color that stroke operations should now use.
* @return True if the Graphics State was changed by this operation.
*/
- public boolean setStrokeColor(final PDFColor newStrokeColor) {
+ public boolean setStrokeColor(final Color newStrokeColor) {
boolean anyChange = false;
if (! newStrokeColor.equals(this.strokeColor)) {
this.strokeColor = newStrokeColor;
@@ -112,13 +110,13 @@
/**
* Sets the "non-stroke" or "other" color (Graphics State holds two colors,
- * one for stroke operations and one for all other operations. This is the
+ * one for stroke operations and one for all other operations). This is the
* one for all other operations. The name "fill" was chosen because that is
* the common use for this color.
* @param newFillColor The color that non-stroke operations should now use.
* @return True if the Graphics State was changed by this operation.
*/
- public boolean setFillColor(final PDFColor newFillColor) {
+ public boolean setFillColor(final Color newFillColor) {
boolean anyChange = false;
if (! newFillColor.equals(this.fillColor)) {
this.fillColor = newFillColor;
Modified: trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFContentStream.java
===================================================================
--- trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFContentStream.java 2007-06-13 17:39:26 UTC (rev 9773)
+++ trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFContentStream.java 2007-06-13 18:55:56 UTC (rev 9774)
@@ -147,7 +147,7 @@
public void setStrokeColor(final Color newStrokeColor) {
final PDFColor newPDFColor = this.getPDFDocument().createPDFColor(
newStrokeColor);
- if (! this.getGS().setStrokeColor(newPDFColor)) {
+ if (! this.getGS().setStrokeColor(newStrokeColor)) {
// Nothing needs to change.
return;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2007-06-13 19:25:41
|
Revision: 9775
http://svn.sourceforge.net/foray/?rev=9775&view=rev
Author: victormote
Date: 2007-06-13 12:25:43 -0700 (Wed, 13 Jun 2007)
Log Message:
-----------
Clean up some color-related PDF code.
Modified Paths:
--------------
trunk/foray/foray-graphic/src/java/org/foray/graphic/batik/PDFGraphics2D.java
trunk/foray/foray-pdf/src/java/org/foray/pdf/PDFGraphicsState.java
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 18:55:56 UTC (rev 9774)
+++ trunk/foray/foray-graphic/src/java/org/foray/graphic/batik/PDFGraphics2D.java 2007-06-13 19:25:43 UTC (rev 9775)
@@ -27,7 +27,6 @@
*/
package org.foray.graphic.batik;
-import org.foray.common.ColorSpaceCMYK;
import org.foray.common.WKConstants;
import org.foray.pdf.PDFGraphicsState;
import org.foray.pdf.object.PDFAnnotList;
@@ -38,6 +37,7 @@
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.foray.ps.PSMatrix;
import org.foray.ps.PSReal;
@@ -120,9 +120,6 @@
/** The current stream to add PDF commands to. */
private StringWriter currentStream = new StringWriter();
- /** The current colour for use in svg. */
- private PDFColor currentColour = new PDFColor(new Color(0, 0, 0));
-
/** The current annotation list to add annotations to. */
private PDFAnnotList currentAnnotList = null;
@@ -335,8 +332,8 @@
return false;
}
- final int numChannels = this.currentColour.getColor().getColorSpace()
- .getNumComponents();
+ final int numChannels = this.graphicsState.getStrokeColor()
+ .getColorSpace().getNumComponents();
final Dimension size = new Dimension(width * numChannels,
height * numChannels);
final BufferedImage buf = new BufferedImage(size.width, size.height,
@@ -445,7 +442,7 @@
public void dispose() {
pdfDoc = null;
currentStream = null;
- currentColour = null;
+ this.graphicsState = null;
}
/**
@@ -564,42 +561,12 @@
*/
protected void applyColor(final Color col, final boolean fill) {
final Color c = col;
- if (c.getColorSpace().getType()
- == java.awt.color.ColorSpace.TYPE_RGB) {
- currentColour = new PDFColor(c);
- currentStream.write(currentColour.getSetterString(fill));
- } else if (c.getColorSpace().getType()
- == java.awt.color.ColorSpace.TYPE_CMYK) {
- final int numComponents = ColorSpace.getInstance(
- ColorSpace.TYPE_RGB).getNumComponents();
- final float[] cComps = c.getColorComponents(
- new float[numComponents]);
- final float[] cmyk = new float[numComponents];
- for (int i = 0; i < numComponents; i++) {
- // convert the float elements to doubles for pdf
- cmyk[i] = cComps[i];
- }
- final Color cmykColor = ColorSpaceCMYK.makeColor(
- cmyk[ColorSpaceCMYK.CYAN_COMPONENT_INDEX],
- cmyk[ColorSpaceCMYK.MAGENTA_COMPONENT_INDEX],
- cmyk[ColorSpaceCMYK.YELLOW_COMPONENT_INDEX],
- cmyk[ColorSpaceCMYK.KEY_COMPONENT_INDEX]);
- currentColour = new PDFColor(cmykColor);
- currentStream.write(currentColour.getSetterString(fill));
- } else if (c.getColorSpace().getType()
- == java.awt.color.ColorSpace.TYPE_2CLR) {
- // used for black/magenta
- final float[] cComps = c.getColorComponents(new float[1]);
- final double[] blackMagenta = new double[1];
- for (int i = 0; i < 1; i++) {
- blackMagenta[i] = cComps[i];
- }
- // currentColour = new PDFColor(blackMagenta[0], blackMagenta[1]);
- currentStream.write(currentColour.getSetterString(fill));
+ if (fill) {
+ this.graphicsState.setFillColor(c);
} else {
- this.logger.error("Color Space not supported by "
- + "PDFGraphics2D");
+ this.graphicsState.setStrokeColor(c);
}
+ currentStream.write(PSColor.toPS(c, fill) + "\n");
}
/**
Modified: trunk/foray/foray-pdf/src/java/org/foray/pdf/PDFGraphicsState.java
===================================================================
--- trunk/foray/foray-pdf/src/java/org/foray/pdf/PDFGraphicsState.java 2007-06-13 18:55:56 UTC (rev 9774)
+++ trunk/foray/foray-pdf/src/java/org/foray/pdf/PDFGraphicsState.java 2007-06-13 19:25:43 UTC (rev 9775)
@@ -109,6 +109,14 @@
}
/**
+ * Returns the "stroke" color.
+ * @return The stroke color.
+ */
+ public Color getStrokeColor() {
+ return this.strokeColor;
+ }
+
+ /**
* Sets the "non-stroke" or "other" color (Graphics State holds two colors,
* one for stroke operations and one for all other operations). This is the
* one for all other operations. The name "fill" was chosen because that is
@@ -126,6 +134,14 @@
}
/**
+ * Returns the "non-stroke" or "other" color.
+ * @return The fill color.
+ */
+ public Color getFillColor() {
+ return this.fillColor;
+ }
+
+ /**
* Sets the character spacing.
* @param newCharacterSpacing The new character spacing, in points.
* @return True iff the character spacing was changed.
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2007-06-13 20:14:08
|
Revision: 9776
http://svn.sourceforge.net/foray/?rev=9776&view=rev
Author: victormote
Date: 2007-06-13 13:14:09 -0700 (Wed, 13 Jun 2007)
Log Message:
-----------
1. Add new ColorUtil class with a method for converting between colorspaces.
2. Use the bare color where possible instead of the PDFColor wrapper.
Modified Paths:
--------------
trunk/foray/foray-graphic/src/java/org/foray/graphic/batik/PDFGraphics2D.java
trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFPattern.java
Added Paths:
-----------
trunk/foray/foray-common/src/java/org/foray/common/ColorUtil.java
Added: trunk/foray/foray-common/src/java/org/foray/common/ColorUtil.java
===================================================================
--- trunk/foray/foray-common/src/java/org/foray/common/ColorUtil.java (rev 0)
+++ trunk/foray/foray-common/src/java/org/foray/common/ColorUtil.java 2007-06-13 20:14:09 UTC (rev 9776)
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2007 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;
+
+import java.awt.Color;
+import java.awt.color.ColorSpace;
+
+/**
+ * Utility class for colors.
+ */
+public final class ColorUtil {
+
+ /**
+ * Private Constructor. This class is a utility class and should never be
+ * constructed.
+ */
+ private ColorUtil() { }
+
+ /**
+ * Converts a given color to a color in a given ColorSpace, returning the
+ * result.
+ * @param color The color to be converted.
+ * @param colorSpace The color space to which the color should be converted.
+ * @return A color in <code>colorSpace</code> that matches (as much as
+ * possible) the color in <code>color</code>.
+ */
+ public static Color convertColorSpace(final Color color,
+ final ColorSpace colorSpace) {
+ if (color.getColorSpace().equals(colorSpace)) {
+ /* The color is already in that color space. Return it. */
+ return color;
+ }
+ final ColorSpace srgbColorSpace = ColorSpace.getInstance(
+ ColorSpace.CS_sRGB);
+ float[] rgbComponents = new float[srgbColorSpace.getNumComponents()];
+ rgbComponents = color.getRGBColorComponents(rgbComponents);
+ final float[] csComponents = colorSpace.fromRGB(rgbComponents);
+ /* TODO: This is probably not right. Not sure how to get the alpha
+ * component (third parameter in the constructor below). */
+ return new Color(colorSpace, csComponents, -1);
+ }
+
+}
Property changes on: trunk/foray/foray-common/src/java/org/foray/common/ColorUtil.java
___________________________________________________________________
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 19:25:43 UTC (rev 9775)
+++ trunk/foray/foray-graphic/src/java/org/foray/graphic/batik/PDFGraphics2D.java 2007-06-13 20:14:09 UTC (rev 9776)
@@ -30,7 +30,6 @@
import org.foray.common.WKConstants;
import org.foray.pdf.PDFGraphicsState;
import org.foray.pdf.object.PDFAnnotList;
-import org.foray.pdf.object.PDFColor;
import org.foray.pdf.object.PDFDocument;
import org.foray.pdf.object.PDFLink;
import org.foray.pdf.object.PDFPage;
@@ -606,12 +605,10 @@
theBounds.add(new Double(0));
theBounds.add(new Double(1));
- final List<PDFColor> someColors = new ArrayList<PDFColor>();
+ final List<Color> someColors = new ArrayList<Color>();
- final PDFColor color1 = new PDFColor(c1);
- someColors.add(color1);
- final PDFColor color2 = new PDFColor(c2);
- someColors.add(color2);
+ someColors.add(c1);
+ someColors.add(c2);
final ColorSpace aColorSpace = ColorSpace.getInstance(
ColorSpace.CS_sRGB);
Modified: trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFPattern.java
===================================================================
--- trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFPattern.java 2007-06-13 19:25:43 UTC (rev 9775)
+++ trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFPattern.java 2007-06-13 20:14:09 UTC (rev 9776)
@@ -28,6 +28,7 @@
package org.foray.pdf.object;
+import org.foray.common.ColorUtil;
import org.foray.ps.PSReal;
import java.awt.Color;
@@ -195,7 +196,7 @@
* @return The pattern for the gradient.
*/
public static PDFPattern createGradient(final boolean radial,
- final ColorSpace theColorSpace, final List<PDFColor> theColors,
+ final ColorSpace theColorSpace, final List<Color> theColors,
final List<Double> theBounds, final List<Double> theCoords,
final PDFDocument document) {
PDFShading myShad;
@@ -216,23 +217,24 @@
// to have a next color when creating the function.
for (currentPosition = 0; currentPosition < lastPosition;
- currentPosition++) { // for every consecutive color pair
- final PDFColor currentColor =
- theColors.get(currentPosition);
- final PDFColor nextColor = theColors.get(currentPosition + 1);
- // colorspace must be consistant
+ currentPosition++) { // for every consecutive color pair
+ Color currentColor = theColors.get(currentPosition);
+ Color nextColor = theColors.get(currentPosition + 1);
+ /* The colorspace must be consistent. */
if (theColorSpace.getType()
!= currentColor.getColorSpace().getType()) {
- currentColor.setColorSpace(theColorSpace);
+ currentColor = ColorUtil.convertColorSpace(currentColor,
+ theColorSpace);
}
if (theColorSpace.getType()
!= nextColor.getColorSpace().getType()) {
- nextColor.setColorSpace(theColorSpace);
+ nextColor = ColorUtil.convertColorSpace(nextColor,
+ theColorSpace);
}
- theCzero = colorToDoubleList(currentColor.getColor());
- theCone = colorToDoubleList(nextColor.getColor());
+ theCzero = colorToDoubleList(currentColor);
+ theCone = colorToDoubleList(nextColor);
myfunc = new PDFFunction(document, 2, null, null,
theCzero, theCone, interpolation);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2007-06-13 20:46:24
|
Revision: 9777
http://svn.sourceforge.net/foray/?rev=9777&view=rev
Author: victormote
Date: 2007-06-13 13:46:24 -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-ps/src/java/org/foray/ps/PSArray.java
trunk/foray/foray-ps/src/java/org/foray/ps/PSMatrix.java
Added Paths:
-----------
trunk/foray/foray-common/src/java/org/foray/common/PostScriptUtil.java
Added: trunk/foray/foray-common/src/java/org/foray/common/PostScriptUtil.java
===================================================================
--- trunk/foray/foray-common/src/java/org/foray/common/PostScriptUtil.java (rev 0)
+++ trunk/foray/foray-common/src/java/org/foray/common/PostScriptUtil.java 2007-06-13 20:46:24 UTC (rev 9777)
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2007 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;
+
+/**
+ * PostScript-related tools included in the Common module to prevent unnecessary
+ * dependencies on the PostScript module.
+ */
+public final class PostScriptUtil {
+
+ /** The number of array elements in a PostScript matrix, that is, 6. */
+ public static final byte MATRIX_QTY_ELEMENTS = 6;
+
+ /**
+ * Private Constructor. This class is a utility class and should never be
+ * instantiated.
+ */
+ private PostScriptUtil() { }
+
+}
Property changes on: trunk/foray/foray-common/src/java/org/foray/common/PostScriptUtil.java
___________________________________________________________________
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 20:14:09 UTC (rev 9776)
+++ trunk/foray/foray-graphic/src/java/org/foray/graphic/batik/PDFGraphics2D.java 2007-06-13 20:46:24 UTC (rev 9777)
@@ -27,6 +27,7 @@
*/
package org.foray.graphic.batik;
+import org.foray.common.PostScriptUtil;
import org.foray.common.WKConstants;
import org.foray.pdf.PDFGraphicsState;
import org.foray.pdf.object.PDFAnnotList;
@@ -37,7 +38,6 @@
import org.foray.pdf.object.PDFString;
import org.foray.pdf.object.PDFXObject;
import org.foray.ps.PSColor;
-import org.foray.ps.PSMatrix;
import org.foray.ps.PSReal;
import org.axsl.fontR.FontConsumer;
@@ -215,7 +215,8 @@
if (!at.isIdentity()) {
/* TODO: This logic needs to be integrated with the regular PDF
* classes. */
- final double[] vals = new double[PSMatrix.QTY_ELEMENTS];
+ final double[] vals =
+ new double[PostScriptUtil.MATRIX_QTY_ELEMENTS];
at.getMatrix(vals);
final String matrixString = octalMatrixToString(vals);
currentStream.write(matrixString);
@@ -412,7 +413,7 @@
// now do any transformation required and add the actual image
// placement instance
final AffineTransform at = getTransform();
- final double[] matrix = new double[PSMatrix.QTY_ELEMENTS];
+ final double[] matrix = new double[PostScriptUtil.MATRIX_QTY_ELEMENTS];
at.getMatrix(matrix);
currentStream.write("q\n");
final Shape imclip = getClip();
@@ -463,7 +464,8 @@
applyStroke(getStroke());
final AffineTransform trans = getTransform();
- final double[] tranvals = new double[PSMatrix.QTY_ELEMENTS];
+ final double[] tranvals =
+ new double[PostScriptUtil.MATRIX_QTY_ELEMENTS];
trans.getMatrix(tranvals);
String matrixString = octalMatrixToString(tranvals);
currentStream.write(matrixString);
@@ -471,7 +473,8 @@
final PathIterator iter = s.getPathIterator(new AffineTransform());
while (!iter.isDone()) {
- final double vals[] = new double[PSMatrix.QTY_ELEMENTS];
+ final double vals[] =
+ new double[PostScriptUtil.MATRIX_QTY_ELEMENTS];
final int type = iter.currentSegment(vals);
switch (type) {
case PathIterator.SEG_CUBICTO:
@@ -517,7 +520,8 @@
final PathIterator iter = s.getPathIterator(getTransform());
String matrixString = null;
while (!iter.isDone()) {
- final double vals[] = new double[PSMatrix.QTY_ELEMENTS];
+ final double vals[] =
+ new double[PostScriptUtil.MATRIX_QTY_ELEMENTS];
final int type = iter.currentSegment(vals);
switch (type) {
case PathIterator.SEG_CUBICTO:
@@ -731,7 +735,7 @@
final AffineTransform trans = getTransform();
trans.translate(x, y);
- final double[] vals = new double[PSMatrix.QTY_ELEMENTS];
+ final double[] vals = new double[PostScriptUtil.MATRIX_QTY_ELEMENTS];
trans.getMatrix(vals);
final String matrixString = octalMatrixToString(vals);
@@ -803,7 +807,7 @@
final AffineTransform trans = getTransform();
trans.translate(x, y);
- final double[] vals = new double[PSMatrix.QTY_ELEMENTS];
+ final double[] vals = new double[PostScriptUtil.MATRIX_QTY_ELEMENTS];
trans.getMatrix(vals);
for (char ch = iterator.first(); ch != CharacterIterator.DONE;
@@ -868,7 +872,8 @@
final PathIterator iter = s.getPathIterator(getTransform());
while (!iter.isDone()) {
- final double vals[] = new double[PSMatrix.QTY_ELEMENTS];
+ final double vals[] =
+ new double[PostScriptUtil.MATRIX_QTY_ELEMENTS];
final int type = iter.currentSegment(vals);
String matrixString = null;
switch (type) {
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 20:14:09 UTC (rev 9776)
+++ trunk/foray/foray-graphic/src/java/org/foray/graphic/batik/PSGraphics2D.java 2007-06-13 20:46:24 UTC (rev 9777)
@@ -34,10 +34,10 @@
package org.foray.graphic.batik;
import org.foray.common.CharacterOutputStream;
+import org.foray.common.PostScriptUtil;
import org.foray.common.WKConstants;
import org.foray.graphic.TempImage;
import org.foray.ps.PSColor;
-import org.foray.ps.PSMatrix;
import org.foray.ps.PSReal;
import org.axsl.graphicR.Graphic;
@@ -209,7 +209,8 @@
try {
final Graphic graphic = new TempImage(null, width, height, result);
final AffineTransform at = getTransform();
- final double[] matrix = new double[PSMatrix.QTY_ELEMENTS];
+ final double[] matrix =
+ new double[PostScriptUtil.MATRIX_QTY_ELEMENTS];
at.getMatrix(matrix);
this.out.write("gsave");
final Shape imclip = getClip();
@@ -266,7 +267,8 @@
this.out.write("newpath");
final PathIterator iter = s.getPathIterator(getTransform());
while (!iter.isDone()) {
- final double vals[] = new double[PSMatrix.QTY_ELEMENTS];
+ final double vals[] =
+ new double[PostScriptUtil.MATRIX_QTY_ELEMENTS];
final int type = iter.currentSegment(vals);
String matrixString = null;
switch (type) {
@@ -330,7 +332,8 @@
final PathIterator iter = s.getPathIterator(getTransform());
this.out.write("newpath");
while (!iter.isDone()) {
- final double vals[] = new double[PSMatrix.QTY_ELEMENTS];
+ final double vals[] =
+ new double[PostScriptUtil.MATRIX_QTY_ELEMENTS];
final int type = iter.currentSegment(vals);
String matrixString = null;
switch (type) {
@@ -566,11 +569,12 @@
final AffineTransform trans = getTransform();
trans.translate(x, y);
- final double[] vals = new double[PSMatrix.QTY_ELEMENTS];
+ final double[] vals =
+ new double[PostScriptUtil.MATRIX_QTY_ELEMENTS];
trans.getMatrix(vals);
final String matrixString = matrixToString(vals,
- PSMatrix.QTY_ELEMENTS);
+ PostScriptUtil.MATRIX_QTY_ELEMENTS);
this.out.write(matrixString + "Tm [" + s + "]");
this.out.write("ET");
@@ -616,13 +620,14 @@
final AffineTransform trans = getTransform();
trans.translate(x, y);
- final double[] vals = new double[PSMatrix.QTY_ELEMENTS];
+ final double[] vals =
+ new double[PostScriptUtil.MATRIX_QTY_ELEMENTS];
trans.getMatrix(vals);
for (char ch = iterator.first(); ch != CharacterIterator.DONE;
ch = iterator.next()) {
final String matrixString = matrixToString(vals,
- PSMatrix.QTY_ELEMENTS);
+ PostScriptUtil.MATRIX_QTY_ELEMENTS);
this.out.write(matrixString + "Tm [" + ch + "]");
}
@@ -661,7 +666,8 @@
this.out.write("newpath");
final PathIterator iter = s.getPathIterator(getTransform());
while (!iter.isDone()) {
- final double vals[] = new double[PSMatrix.QTY_ELEMENTS];
+ final double vals[] =
+ new double[PostScriptUtil.MATRIX_QTY_ELEMENTS];
final int type = iter.currentSegment(vals);
String matrixString = null;
switch (type) {
Modified: trunk/foray/foray-ps/src/java/org/foray/ps/PSArray.java
===================================================================
--- trunk/foray/foray-ps/src/java/org/foray/ps/PSArray.java 2007-06-13 20:14:09 UTC (rev 9776)
+++ trunk/foray/foray-ps/src/java/org/foray/ps/PSArray.java 2007-06-13 20:46:24 UTC (rev 9777)
@@ -28,6 +28,8 @@
package org.foray.ps;
+import org.foray.common.PostScriptUtil;
+
/**
* A PostScript array.
*/
@@ -169,11 +171,12 @@
* @return A new PSMatrix instance made from this, or null if not possible.
*/
public PSMatrix convertToMatrix() {
- if (this.value.length != PSMatrix.QTY_ELEMENTS) {
+ if (this.value.length != PostScriptUtil.MATRIX_QTY_ELEMENTS) {
return null;
}
boolean allNumbers = true;
- final PSNumber[] newArray = new PSNumber[PSMatrix.QTY_ELEMENTS];
+ final PSNumber[] newArray =
+ new PSNumber[PostScriptUtil.MATRIX_QTY_ELEMENTS];
for (int i = 0; i < this.value.length; i++) {
if (this.value[i] instanceof PSNumber) {
newArray[i] = (PSNumber) this.value[i];
Modified: trunk/foray/foray-ps/src/java/org/foray/ps/PSMatrix.java
===================================================================
--- trunk/foray/foray-ps/src/java/org/foray/ps/PSMatrix.java 2007-06-13 20:14:09 UTC (rev 9776)
+++ trunk/foray/foray-ps/src/java/org/foray/ps/PSMatrix.java 2007-06-13 20:46:24 UTC (rev 9777)
@@ -28,6 +28,8 @@
package org.foray.ps;
+import org.foray.common.PostScriptUtil;
+
import java.awt.geom.Dimension2D;
import java.awt.geom.Point2D;
@@ -36,9 +38,6 @@
*/
public class PSMatrix extends PSArray {
- /** The number of array elements in a PostScript matrix, that is, 6. */
- public static final byte QTY_ELEMENTS = 6;
-
/**
* Constructor.
* @param interpreter The parent PostScript interpreter.
@@ -147,7 +146,7 @@
public static PSNumber[] concatMatrices(final PSInterpreter interpreter,
final PSNumber[] matrix1, final PSNumber[] matrix2)
throws PSException {
- if (matrix1.length != QTY_ELEMENTS) {
+ if (matrix1.length != PostScriptUtil.MATRIX_QTY_ELEMENTS) {
throw new PSException(interpreter, PSErrorDict.RANGECHECK);
}
// double[] productArray = new double[6];
@@ -166,7 +165,8 @@
public static PSNumber[] makeTranslateMatrix(
final PSInterpreter interpreter, final PSNumber x,
final PSNumber y) {
- final PSNumber[] returnArray = new PSNumber[QTY_ELEMENTS];
+ final PSNumber[] returnArray =
+ new PSNumber[PostScriptUtil.MATRIX_QTY_ELEMENTS];
int index = 0;
returnArray[index] = new PSInteger(interpreter, 1);
index ++;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2007-06-13 21:00:24
|
Revision: 9778
http://svn.sourceforge.net/foray/?rev=9778&view=rev
Author: victormote
Date: 2007-06-13 14:00:25 -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-common/src/java/org/foray/common/PostScriptUtil.java
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/PDFFunction.java
trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFPattern.java
trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFShading.java
trunk/foray/foray-ps/src/java/org/foray/ps/PSColor.java
trunk/foray/foray-ps/src/java/org/foray/ps/PSReal.java
Modified: trunk/foray/foray-common/src/java/org/foray/common/PostScriptUtil.java
===================================================================
--- trunk/foray/foray-common/src/java/org/foray/common/PostScriptUtil.java 2007-06-13 20:46:24 UTC (rev 9777)
+++ trunk/foray/foray-common/src/java/org/foray/common/PostScriptUtil.java 2007-06-13 21:00:25 UTC (rev 9778)
@@ -37,10 +37,110 @@
/** The number of array elements in a PostScript matrix, that is, 6. */
public static final byte MATRIX_QTY_ELEMENTS = 6;
+ /** A legacy magic number of unknown significance. */
+ private static final float MAGIC_NUMBER_1 = 0.95f;
+
+ /** A legacy magic number of unknown significance. */
+ private static final float MAGIC_NUMBER_2 = 0.05f;
+
+ /** A legacy magic number of unknown significance. */
+ private static final float MAGIC_NUMBER_3 = 5.0f;
+
+ /** The maximum number of digits to the right of the decimal point that
+ * should be written when the numeric value is written. */
+ private static final byte MAX_DECIMAL_DIGITS = 6;
+
/**
* Private Constructor. This class is a utility class and should never be
* instantiated.
*/
private PostScriptUtil() { }
+ /**
+ * Format a {@link Double} instance as PostScript output.
+ * @param theDouble The {@link Double} instance to format.
+ * @return The {@link Double} as PostScript output.
+ */
+ public static String doubleOut(final Double theDouble) {
+ return doubleOut(theDouble.doubleValue());
+ }
+
+ /**
+ * Format a double primitive as PostScript output.
+ * @param doubleValue The double primitive to format.
+ * @return The double primitive as PostScript output.
+ */
+ public static String doubleOut(final double doubleValue) {
+ final StringBuilder p = new StringBuilder();
+ double modifiedDoubleValue = doubleValue;
+ if (modifiedDoubleValue < 0) {
+ modifiedDoubleValue = -modifiedDoubleValue;
+ p.append("-");
+ }
+ final double trouble = modifiedDoubleValue % 1;
+
+ if (trouble > MAGIC_NUMBER_1) {
+ p.append((int) modifiedDoubleValue + 1);
+ } else if (trouble < MAGIC_NUMBER_2) {
+ p.append((int) modifiedDoubleValue);
+ } else {
+ final String doubleString = Double.toString(modifiedDoubleValue);
+ final int decimal = doubleString.indexOf(".");
+ if (decimal != -1) {
+ p.append(doubleString.substring(0, decimal));
+
+ if ((doubleString.length() - decimal) > MAX_DECIMAL_DIGITS) {
+ p.append(doubleString.substring(decimal,
+ decimal + MAX_DECIMAL_DIGITS));
+ } else {
+ p.append(doubleString.substring(decimal));
+ }
+ } else {
+ p.append(doubleString);
+ }
+ }
+ return p.toString();
+ }
+
+ /**
+ * Format a double primitive as PostScript output.
+ * @param doubleValue The double primitive to format.
+ * @param radix The root numbering system in which the number should be
+ * written. For example, for decimal, the value should be 10, for octal,
+ * the value should be 8.
+ * @return The double primitive as PostScript output.
+ */
+ public static String doubleOut(final double doubleValue, final int radix) {
+ final StringBuilder p = new StringBuilder();
+ double modifiedDoubleValue = doubleValue;
+ if (modifiedDoubleValue < 0) {
+ modifiedDoubleValue = -modifiedDoubleValue;
+ p.append("-");
+ }
+ final double trouble = modifiedDoubleValue % 1;
+
+ if (trouble > (1.0 - (MAGIC_NUMBER_3 / (Math.pow(
+ WKConstants.RADIX_BASE_10, radix))))) {
+ p.append((int) modifiedDoubleValue + 1);
+ } else if (trouble < (MAGIC_NUMBER_3 / (Math.pow(
+ WKConstants.RADIX_BASE_10, radix)))) {
+ p.append((int) modifiedDoubleValue);
+ } else {
+ final String doubleString = Double.toString(modifiedDoubleValue);
+ final int decimal = doubleString.indexOf(".");
+ if (decimal != -1) {
+ p.append(doubleString.substring(0, decimal));
+
+ if ((doubleString.length() - decimal) > radix) {
+ p.append(doubleString.substring(decimal, decimal + radix));
+ } else {
+ p.append(doubleString.substring(decimal));
+ }
+ } else {
+ p.append(doubleString);
+ }
+ }
+ return p.toString();
+ }
+
}
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 20:46:24 UTC (rev 9777)
+++ trunk/foray/foray-graphic/src/java/org/foray/graphic/batik/PDFGraphics2D.java 2007-06-13 21:00:25 UTC (rev 9778)
@@ -38,7 +38,6 @@
import org.foray.pdf.object.PDFString;
import org.foray.pdf.object.PDFXObject;
import org.foray.ps.PSColor;
-import org.foray.ps.PSReal;
import org.axsl.fontR.FontConsumer;
import org.axsl.fontR.FontException;
@@ -232,7 +231,7 @@
public static String octalMatrixToString(final double[] theMatrix) {
final StringBuilder buffer = new StringBuilder();
for (int i = 0; i < theMatrix.length; i++) {
- buffer.append(PSReal.doubleOut(theMatrix[i],
+ buffer.append(PostScriptUtil.doubleOut(theMatrix[i],
WKConstants.RADIX_BASE_8));
buffer.append(" ");
}
@@ -250,7 +249,7 @@
final int numElements) {
final StringBuilder buffer = new StringBuilder();
for (int i = 0; i < numElements; i++) {
- buffer.append(PSReal.doubleOut(theMatrix[i]) + " ");
+ buffer.append(PostScriptUtil.doubleOut(theMatrix[i]) + " ");
}
return buffer.toString();
}
@@ -676,10 +675,10 @@
break;
}
final float lw = bs.getLineWidth();
- currentStream.write(PSReal.doubleOut(lw) + " w\n");
+ currentStream.write(PostScriptUtil.doubleOut(lw) + " w\n");
final float ml = bs.getMiterLimit();
- currentStream.write(PSReal.doubleOut(ml) + " M\n");
+ currentStream.write(PostScriptUtil.doubleOut(ml) + " M\n");
}
}
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 20:46:24 UTC (rev 9777)
+++ trunk/foray/foray-graphic/src/java/org/foray/graphic/batik/PSGraphics2D.java 2007-06-13 21:00:25 UTC (rev 9778)
@@ -38,7 +38,6 @@
import org.foray.common.WKConstants;
import org.foray.graphic.TempImage;
import org.foray.ps.PSColor;
-import org.foray.ps.PSReal;
import org.axsl.graphicR.Graphic;
@@ -316,7 +315,7 @@
final int qtyElements) {
final StringBuilder buffer = new StringBuilder();
for (int i = 0; i < qtyElements; i++) {
- buffer.append(PSReal.doubleOut(
+ buffer.append(PostScriptUtil.doubleOut(
WKConstants.MILLIPOINTS_PER_POINT * matrix[i])
+ " ");
}
@@ -464,12 +463,12 @@
break;
}
final float lw = bs.getLineWidth();
- this.out.write(PSReal.doubleOut(
+ this.out.write(PostScriptUtil.doubleOut(
WKConstants.MILLIPOINTS_PER_POINT * lw)
+ " setlinewidth");
final float ml = bs.getMiterLimit();
- this.out.write(PSReal.doubleOut(
+ this.out.write(PostScriptUtil.doubleOut(
WKConstants.MILLIPOINTS_PER_POINT * ml)
+ " setmiterlimit");
}
Modified: trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFFunction.java
===================================================================
--- trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFFunction.java 2007-06-13 20:46:24 UTC (rev 9777)
+++ trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFFunction.java 2007-06-13 21:00:25 UTC (rev 9778)
@@ -28,7 +28,7 @@
package org.foray.pdf.object;
-import org.foray.ps.PSReal;
+import org.foray.common.PostScriptUtil;
import java.util.List;
@@ -433,7 +433,7 @@
p.append("/Domain [ ");
vectorSize = this.domain.size();
for (tempInt = 0; tempInt < vectorSize; tempInt++) {
- p.append(PSReal.doubleOut(
+ p.append(PostScriptUtil.doubleOut(
this.domain.get(tempInt)) + " ");
}
@@ -447,7 +447,8 @@
p.append("/Size [ ");
vectorSize = this.size.size();
for (tempInt = 0; tempInt < vectorSize; tempInt++) {
- p.append(PSReal.doubleOut(this.size.get(tempInt)) + " ");
+ p.append(PostScriptUtil.doubleOut(this.size.get(tempInt))
+ + " ");
}
p.append("]" + EOL);
}
@@ -456,7 +457,7 @@
p.append("/Encode [ ");
vectorSize = this.encode.size();
for (tempInt = 0; tempInt < vectorSize; tempInt++) {
- p.append(PSReal.doubleOut(
+ p.append(PostScriptUtil.doubleOut(
this.encode.get(tempInt)) + " ");
}
p.append("]" + EOL);
@@ -484,7 +485,7 @@
p.append("/Range [ ");
vectorSize = this.range.size();
for (tempInt = 0; tempInt < vectorSize; tempInt++) {
- p.append(PSReal.doubleOut(
+ p.append(PostScriptUtil.doubleOut(
this.range.get(tempInt)) + " ");
}
@@ -496,7 +497,7 @@
p.append("/Decode [ ");
vectorSize = this.decode.size();
for (tempInt = 0; tempInt < vectorSize; tempInt++) {
- p.append(PSReal.doubleOut(
+ p.append(PostScriptUtil.doubleOut(
this.decode.get(tempInt)) + " ");
}
@@ -539,7 +540,7 @@
p.append("/Domain [ ");
vectorSize = this.domain.size();
for (tempInt = 0; tempInt < vectorSize; tempInt++) {
- p.append(PSReal.doubleOut(
+ p.append(PostScriptUtil.doubleOut(
this.domain.get(tempInt)) + " ");
}
@@ -554,7 +555,7 @@
p.append("/Range [ ");
vectorSize = this.range.size();
for (tempInt = 0; tempInt < vectorSize; tempInt++) {
- p.append(PSReal.doubleOut(
+ p.append(PostScriptUtil.doubleOut(
this.range.get(tempInt)) + " ");
}
@@ -568,7 +569,7 @@
p.append("/C0 [ ");
vectorSize = this.cZero.size();
for (tempInt = 0; tempInt < vectorSize; tempInt++) {
- p.append(PSReal.doubleOut(
+ p.append(PostScriptUtil.doubleOut(
this.cZero.get(tempInt)) + " ");
}
p.append("]" + EOL);
@@ -579,7 +580,7 @@
p.append("/C1 [ ");
vectorSize = this.cOne.size();
for (tempInt = 0; tempInt < vectorSize; tempInt++) {
- p.append(PSReal.doubleOut(this.cOne.get(tempInt))
+ p.append(PostScriptUtil.doubleOut(this.cOne.get(tempInt))
+ " ");
}
p.append("]" + EOL);
@@ -587,7 +588,8 @@
// N: The interpolation Exponent
p.append("/N "
- + PSReal.doubleOut(new Double(this.interpolationExponentN))
+ + PostScriptUtil.doubleOut(new Double(
+ this.interpolationExponentN))
+ EOL);
p.append(">>" + EOL + "endobj" + EOL);
@@ -599,7 +601,7 @@
p.append("/Domain [ ");
vectorSize = this.domain.size();
for (tempInt = 0; tempInt < vectorSize; tempInt++) {
- p.append(PSReal.doubleOut(this.domain.get(tempInt))
+ p.append(PostScriptUtil.doubleOut(this.domain.get(tempInt))
+ " ");
}
p.append("]" + EOL);
@@ -612,7 +614,7 @@
p.append("/Range [ ");
vectorSize = this.range.size();
for (tempInt = 0; tempInt < vectorSize; tempInt++) {
- p.append(PSReal.doubleOut(
+ p.append(PostScriptUtil.doubleOut(
this.range.get(tempInt)) + " ");
}
@@ -637,7 +639,7 @@
p.append("/Encode [ ");
vectorSize = this.encode.size();
for (tempInt = 0; tempInt < vectorSize; tempInt++) {
- p.append(PSReal.doubleOut(
+ p.append(PostScriptUtil.doubleOut(
this.encode.get(tempInt)) + " ");
}
@@ -659,7 +661,7 @@
vectorSize = this.bounds.size();
for (tempInt = 0; tempInt < vectorSize; tempInt++) {
- p.append(PSReal.doubleOut(
+ p.append(PostScriptUtil.doubleOut(
this.bounds.get(tempInt)) + " ");
}
@@ -672,7 +674,7 @@
// [ 0.25 0.25 0.25 ]
String functionsFraction
- = PSReal.doubleOut(new Double(1.0
+ = PostScriptUtil.doubleOut(new Double(1.0
/ numberOfFunctions));
for (tempInt = 0; tempInt + 1 < numberOfFunctions;
@@ -696,7 +698,7 @@
p.append("/Domain [ ");
vectorSize = this.domain.size();
for (tempInt = 0; tempInt < vectorSize; tempInt++) {
- p.append(PSReal.doubleOut(
+ p.append(PostScriptUtil.doubleOut(
this.domain.get(tempInt)) + " ");
}
@@ -710,7 +712,7 @@
p.append("/Range [ ");
vectorSize = this.range.size();
for (tempInt = 0; tempInt < vectorSize; tempInt++) {
- p.append(PSReal.doubleOut(
+ p.append(PostScriptUtil.doubleOut(
this.range.get(tempInt)) + " ");
}
Modified: trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFPattern.java
===================================================================
--- trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFPattern.java 2007-06-13 20:46:24 UTC (rev 9777)
+++ trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFPattern.java 2007-06-13 21:00:25 UTC (rev 9778)
@@ -29,7 +29,7 @@
package org.foray.pdf.object;
import org.foray.common.ColorUtil;
-import org.foray.ps.PSReal;
+import org.foray.common.PostScriptUtil;
import java.awt.Color;
import java.awt.color.ColorSpace;
@@ -323,22 +323,22 @@
vectorSize = this.bBox.size();
p.append("/BBox [ ");
for (tempInt = 0; tempInt < vectorSize; tempInt++) {
- p.append(PSReal.doubleOut(
+ p.append(PostScriptUtil.doubleOut(
this.bBox.get(tempInt)));
p.append(" ");
}
p.append("]" + EOL);
}
- p.append("/XStep " + PSReal.doubleOut(new Double(this.xStep))
- + EOL);
- p.append("/YStep " + PSReal.doubleOut(new Double(this.yStep))
- + EOL);
+ p.append("/XStep " + PostScriptUtil.doubleOut(
+ new Double(this.xStep)) + EOL);
+ p.append("/YStep " + PostScriptUtil.doubleOut(
+ new Double(this.yStep)) + EOL);
if (this.matrix != null) {
vectorSize = this.matrix.size();
p.append("/Matrix [ ");
for (tempInt = 0; tempInt < vectorSize; tempInt++) {
- p.append(PSReal.doubleOut(
+ p.append(PostScriptUtil.doubleOut(
this.matrix.get(tempInt)));
p.append(" ");
}
@@ -385,7 +385,7 @@
vectorSize = this.matrix.size();
p.append("/Matrix [ ");
for (tempInt = 0; tempInt < vectorSize; tempInt++) {
- p.append(PSReal.doubleOut(
+ p.append(PostScriptUtil.doubleOut(
this.matrix.get(tempInt)));
p.append(" ");
}
Modified: trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFShading.java
===================================================================
--- trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFShading.java 2007-06-13 20:46:24 UTC (rev 9777)
+++ trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFShading.java 2007-06-13 21:00:25 UTC (rev 9778)
@@ -28,7 +28,7 @@
package org.foray.pdf.object;
-import org.foray.ps.PSReal;
+import org.foray.common.PostScriptUtil;
import java.awt.color.ColorSpace;
import java.util.List;
@@ -385,7 +385,7 @@
p.append("/Background [ ");
vectorSize = this.background.size();
for (tempInt = 0; tempInt < vectorSize; tempInt++) {
- p.append(PSReal.doubleOut(
+ p.append(PostScriptUtil.doubleOut(
this.background.get(tempInt)) + " ");
}
p.append("]" + EOL);
@@ -397,7 +397,7 @@
p.append("/BBox [ ");
vectorSize = this.bBox.size();
for (tempInt = 0; tempInt < vectorSize; tempInt++) {
- p.append(PSReal.doubleOut(this.bBox.get(tempInt))
+ p.append(PostScriptUtil.doubleOut(this.bBox.get(tempInt))
+ " ");
}
p.append("]" + EOL);
@@ -413,7 +413,7 @@
p.append("/Domain [ ");
vectorSize = this.domain.size();
for (tempInt = 0; tempInt < vectorSize; tempInt++) {
- p.append(PSReal.doubleOut(
+ p.append(PostScriptUtil.doubleOut(
this.domain.get(tempInt)) + " ");
}
p.append("]" + EOL);
@@ -425,7 +425,7 @@
p.append("/Matrix [ ");
vectorSize = this.matrix.size();
for (tempInt = 0; tempInt < vectorSize; tempInt++) {
- p.append(PSReal.doubleOut(
+ p.append(PostScriptUtil.doubleOut(
this.matrix.get(tempInt)) + " ");
}
p.append("]" + EOL);
@@ -441,7 +441,7 @@
p.append("/Coords [ ");
vectorSize = this.coords.size();
for (tempInt = 0; tempInt < vectorSize; tempInt++) {
- p.append(PSReal.doubleOut(
+ p.append(PostScriptUtil.doubleOut(
this.coords.get(tempInt)) + " ");
}
p.append("]" + EOL);
@@ -452,7 +452,7 @@
p.append("/Domain [ ");
vectorSize = this.domain.size();
for (tempInt = 0; tempInt < vectorSize; tempInt++) {
- p.append(PSReal.doubleOut(
+ p.append(PostScriptUtil.doubleOut(
this.domain.get(tempInt)) + " ");
}
p.append("]" + EOL);
Modified: 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 20:46:24 UTC (rev 9777)
+++ trunk/foray/foray-ps/src/java/org/foray/ps/PSColor.java 2007-06-13 21:00:25 UTC (rev 9778)
@@ -28,6 +28,8 @@
package org.foray.ps;
+import org.foray.common.PostScriptUtil;
+
import java.awt.Color;
import java.awt.color.ColorSpace;
@@ -89,21 +91,21 @@
// fill
if (fillNotStroke) {
if (isGray) {
- buffer.append(PSReal.doubleOut(rgbColors[0]) + " g");
+ buffer.append(PostScriptUtil.doubleOut(rgbColors[0]) + " g");
} else {
- buffer.append(PSReal.doubleOut(rgbColors[0]) + " "
- + PSReal.doubleOut(rgbColors[1]) + " "
- + PSReal.doubleOut(rgbColors[2])
+ buffer.append(PostScriptUtil.doubleOut(rgbColors[0]) + " "
+ + PostScriptUtil.doubleOut(rgbColors[1]) + " "
+ + PostScriptUtil.doubleOut(rgbColors[2])
+ " rg");
}
// stroke/border
} else {
if (isGray) {
- buffer.append(PSReal.doubleOut(rgbColors[0]) + " G");
+ buffer.append(PostScriptUtil.doubleOut(rgbColors[0]) + " G");
} else {
- buffer.append(PSReal.doubleOut(rgbColors[0]) + " "
- + PSReal.doubleOut(rgbColors[1]) + " "
- + PSReal.doubleOut(rgbColors[2])
+ buffer.append(PostScriptUtil.doubleOut(rgbColors[0]) + " "
+ + PostScriptUtil.doubleOut(rgbColors[1]) + " "
+ + PostScriptUtil.doubleOut(rgbColors[2])
+ " RG");
}
}
@@ -125,22 +127,22 @@
int index = 0;
if (fillNotStroke) {
/* Fill */
- buffer.append(PSReal.doubleOut(cmykColors[index]) + " ");
+ buffer.append(PostScriptUtil.doubleOut(cmykColors[index]) + " ");
index ++;
- buffer.append(PSReal.doubleOut(cmykColors[index]) + " ");
+ buffer.append(PostScriptUtil.doubleOut(cmykColors[index]) + " ");
index ++;
- buffer.append(PSReal.doubleOut(cmykColors[index]) + " ");
+ buffer.append(PostScriptUtil.doubleOut(cmykColors[index]) + " ");
index ++;
- buffer.append(PSReal.doubleOut(cmykColors[index]) + " k");
+ buffer.append(PostScriptUtil.doubleOut(cmykColors[index]) + " k");
} else {
/* Stroke ?? */
- buffer.append(PSReal.doubleOut(cmykColors[index]) + " ");
+ buffer.append(PostScriptUtil.doubleOut(cmykColors[index]) + " ");
index ++;
- buffer.append(PSReal.doubleOut(cmykColors[index]) + " ");
+ buffer.append(PostScriptUtil.doubleOut(cmykColors[index]) + " ");
index ++;
- buffer.append(PSReal.doubleOut(cmykColors[index]) + " ");
+ buffer.append(PostScriptUtil.doubleOut(cmykColors[index]) + " ");
index ++;
- buffer.append(PSReal.doubleOut(cmykColors[index]) + " K");
+ buffer.append(PostScriptUtil.doubleOut(cmykColors[index]) + " K");
}
return buffer.toString();
}
@@ -158,9 +160,9 @@
final StringBuilder buffer = new StringBuilder("");
final float[] grayColors = color.getComponents(null);
if (fillNotStroke) {
- buffer.append(PSReal.doubleOut(grayColors[0]) + " g");
+ buffer.append(PostScriptUtil.doubleOut(grayColors[0]) + " g");
} else {
- buffer.append(PSReal.doubleOut(grayColors[0]) + " G");
+ buffer.append(PostScriptUtil.doubleOut(grayColors[0]) + " G");
}
return buffer.toString();
}
Modified: trunk/foray/foray-ps/src/java/org/foray/ps/PSReal.java
===================================================================
--- trunk/foray/foray-ps/src/java/org/foray/ps/PSReal.java 2007-06-13 20:46:24 UTC (rev 9777)
+++ trunk/foray/foray-ps/src/java/org/foray/ps/PSReal.java 2007-06-13 21:00:25 UTC (rev 9778)
@@ -28,26 +28,11 @@
package org.foray.ps;
-import org.foray.common.WKConstants;
-
/**
* Class representing PostScript object that is a real number.
*/
public class PSReal extends PSNumber implements Comparable<Object> {
- /** A legacy magic number of unknown significance. */
- private static final float MAGIC_NUMBER_1 = 0.95f;
-
- /** A legacy magic number of unknown significance. */
- private static final float MAGIC_NUMBER_2 = 0.05f;
-
- /** A legacy magic number of unknown significance. */
- private static final float MAGIC_NUMBER_3 = 5.0f;
-
- /** The maximum number of digits to the right of the decimal point that
- * should be written when the numeric value is written. */
- private static final byte MAX_DECIMAL_DIGITS = 6;
-
/** The encapsulated value for this object. */
private double value;
@@ -208,91 +193,4 @@
return "Real: " + Double.toString(this.value);
}
- /**
- * Format a {@link Double} instance as PostScript output.
- * @param theDouble The {@link Double} instance to format.
- * @return The {@link Double} as PostScript output.
- */
- public static String doubleOut(final Double theDouble) {
- return doubleOut(theDouble.doubleValue());
- }
-
- /**
- * Format a double primitive as PostScript output.
- * @param doubleValue The double primitive to format.
- * @return The double primitive as PostScript output.
- */
- public static String doubleOut(final double doubleValue) {
- final StringBuilder p = new StringBuilder();
- double modifiedDoubleValue = doubleValue;
- if (modifiedDoubleValue < 0) {
- modifiedDoubleValue = -modifiedDoubleValue;
- p.append("-");
- }
- final double trouble = modifiedDoubleValue % 1;
-
- if (trouble > MAGIC_NUMBER_1) {
- p.append((int) modifiedDoubleValue + 1);
- } else if (trouble < MAGIC_NUMBER_2) {
- p.append((int) modifiedDoubleValue);
- } else {
- final String doubleString = Double.toString(modifiedDoubleValue);
- final int decimal = doubleString.indexOf(".");
- if (decimal != -1) {
- p.append(doubleString.substring(0, decimal));
-
- if ((doubleString.length() - decimal) > MAX_DECIMAL_DIGITS) {
- p.append(doubleString.substring(decimal,
- decimal + MAX_DECIMAL_DIGITS));
- } else {
- p.append(doubleString.substring(decimal));
- }
- } else {
- p.append(doubleString);
- }
- }
- return p.toString();
- }
-
- /**
- * Format a double primitive as PostScript output.
- * @param doubleValue The double primitive to format.
- * @param radix The root numbering system in which the number should be
- * written. For example, for decimal, the value should be 10, for octal,
- * the value should be 8.
- * @return The double primitive as PostScript output.
- */
- public static String doubleOut(final double doubleValue, final int radix) {
- final StringBuilder p = new StringBuilder();
- double modifiedDoubleValue = doubleValue;
- if (modifiedDoubleValue < 0) {
- modifiedDoubleValue = -modifiedDoubleValue;
- p.append("-");
- }
- final double trouble = modifiedDoubleValue % 1;
-
- if (trouble > (1.0 - (MAGIC_NUMBER_3 / (Math.pow(
- WKConstants.RADIX_BASE_10, radix))))) {
- p.append((int) modifiedDoubleValue + 1);
- } else if (trouble < (MAGIC_NUMBER_3 / (Math.pow(
- WKConstants.RADIX_BASE_10, radix)))) {
- p.append((int) modifiedDoubleValue);
- } else {
- final String doubleString = Double.toString(modifiedDoubleValue);
- final int decimal = doubleString.indexOf(".");
- if (decimal != -1) {
- p.append(doubleString.substring(0, decimal));
-
- if ((doubleString.length() - decimal) > radix) {
- p.append(doubleString.substring(decimal, decimal + radix));
- } else {
- p.append(doubleString.substring(decimal));
- }
- } else {
- p.append(doubleString);
- }
- }
- return p.toString();
- }
-
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
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.
|
|
From: <vic...@us...> - 2007-06-13 21:43:52
|
Revision: 9782
http://svn.sourceforge.net/foray/?rev=9782&view=rev
Author: victormote
Date: 2007-06-13 14:43:53 -0700 (Wed, 13 Jun 2007)
Log Message:
-----------
Move and rename PostScriptUtil class.
Modified Paths:
--------------
trunk/foray/foray-common/src/java/org/foray/common/ps/PSColor.java
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/PDFFunction.java
trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFPattern.java
trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFShading.java
trunk/foray/foray-ps/src/java/org/foray/ps/PSArray.java
trunk/foray/foray-ps/src/java/org/foray/ps/PSMatrix.java
Added Paths:
-----------
trunk/foray/foray-common/src/java/org/foray/common/ps/PsUtil.java
Removed Paths:
-------------
trunk/foray/foray-common/src/java/org/foray/common/PostScriptUtil.java
Deleted: trunk/foray/foray-common/src/java/org/foray/common/PostScriptUtil.java
===================================================================
--- trunk/foray/foray-common/src/java/org/foray/common/PostScriptUtil.java 2007-06-13 21:36:00 UTC (rev 9781)
+++ trunk/foray/foray-common/src/java/org/foray/common/PostScriptUtil.java 2007-06-13 21:43:53 UTC (rev 9782)
@@ -1,146 +0,0 @@
-/*
- * Copyright 2007 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;
-
-/**
- * PostScript-related tools included in the Common module to prevent unnecessary
- * dependencies on the PostScript module.
- */
-public final class PostScriptUtil {
-
- /** The number of array elements in a PostScript matrix, that is, 6. */
- public static final byte MATRIX_QTY_ELEMENTS = 6;
-
- /** A legacy magic number of unknown significance. */
- private static final float MAGIC_NUMBER_1 = 0.95f;
-
- /** A legacy magic number of unknown significance. */
- private static final float MAGIC_NUMBER_2 = 0.05f;
-
- /** A legacy magic number of unknown significance. */
- private static final float MAGIC_NUMBER_3 = 5.0f;
-
- /** The maximum number of digits to the right of the decimal point that
- * should be written when the numeric value is written. */
- private static final byte MAX_DECIMAL_DIGITS = 6;
-
- /**
- * Private Constructor. This class is a utility class and should never be
- * instantiated.
- */
- private PostScriptUtil() { }
-
- /**
- * Format a {@link Double} instance as PostScript output.
- * @param theDouble The {@link Double} instance to format.
- * @return The {@link Double} as PostScript output.
- */
- public static String doubleOut(final Double theDouble) {
- return doubleOut(theDouble.doubleValue());
- }
-
- /**
- * Format a double primitive as PostScript output.
- * @param doubleValue The double primitive to format.
- * @return The double primitive as PostScript output.
- */
- public static String doubleOut(final double doubleValue) {
- final StringBuilder p = new StringBuilder();
- double modifiedDoubleValue = doubleValue;
- if (modifiedDoubleValue < 0) {
- modifiedDoubleValue = -modifiedDoubleValue;
- p.append("-");
- }
- final double trouble = modifiedDoubleValue % 1;
-
- if (trouble > MAGIC_NUMBER_1) {
- p.append((int) modifiedDoubleValue + 1);
- } else if (trouble < MAGIC_NUMBER_2) {
- p.append((int) modifiedDoubleValue);
- } else {
- final String doubleString = Double.toString(modifiedDoubleValue);
- final int decimal = doubleString.indexOf(".");
- if (decimal != -1) {
- p.append(doubleString.substring(0, decimal));
-
- if ((doubleString.length() - decimal) > MAX_DECIMAL_DIGITS) {
- p.append(doubleString.substring(decimal,
- decimal + MAX_DECIMAL_DIGITS));
- } else {
- p.append(doubleString.substring(decimal));
- }
- } else {
- p.append(doubleString);
- }
- }
- return p.toString();
- }
-
- /**
- * Format a double primitive as PostScript output.
- * @param doubleValue The double primitive to format.
- * @param radix The root numbering system in which the number should be
- * written. For example, for decimal, the value should be 10, for octal,
- * the value should be 8.
- * @return The double primitive as PostScript output.
- */
- public static String doubleOut(final double doubleValue, final int radix) {
- final StringBuilder p = new StringBuilder();
- double modifiedDoubleValue = doubleValue;
- if (modifiedDoubleValue < 0) {
- modifiedDoubleValue = -modifiedDoubleValue;
- p.append("-");
- }
- final double trouble = modifiedDoubleValue % 1;
-
- if (trouble > (1.0 - (MAGIC_NUMBER_3 / (Math.pow(
- WKConstants.RADIX_BASE_10, radix))))) {
- p.append((int) modifiedDoubleValue + 1);
- } else if (trouble < (MAGIC_NUMBER_3 / (Math.pow(
- WKConstants.RADIX_BASE_10, radix)))) {
- p.append((int) modifiedDoubleValue);
- } else {
- final String doubleString = Double.toString(modifiedDoubleValue);
- final int decimal = doubleString.indexOf(".");
- if (decimal != -1) {
- p.append(doubleString.substring(0, decimal));
-
- if ((doubleString.length() - decimal) > radix) {
- p.append(doubleString.substring(decimal, decimal + radix));
- } else {
- p.append(doubleString.substring(decimal));
- }
- } else {
- p.append(doubleString);
- }
- }
- return p.toString();
- }
-
-}
Modified: trunk/foray/foray-common/src/java/org/foray/common/ps/PSColor.java
===================================================================
--- trunk/foray/foray-common/src/java/org/foray/common/ps/PSColor.java 2007-06-13 21:36:00 UTC (rev 9781)
+++ trunk/foray/foray-common/src/java/org/foray/common/ps/PSColor.java 2007-06-13 21:43:53 UTC (rev 9782)
@@ -28,7 +28,6 @@
package org.foray.common.ps;
-import org.foray.common.PostScriptUtil;
import java.awt.Color;
import java.awt.color.ColorSpace;
@@ -91,21 +90,21 @@
// fill
if (fillNotStroke) {
if (isGray) {
- buffer.append(PostScriptUtil.doubleOut(rgbColors[0]) + " g");
+ buffer.append(PsUtil.doubleOut(rgbColors[0]) + " g");
} else {
- buffer.append(PostScriptUtil.doubleOut(rgbColors[0]) + " "
- + PostScriptUtil.doubleOut(rgbColors[1]) + " "
- + PostScriptUtil.doubleOut(rgbColors[2])
+ buffer.append(PsUtil.doubleOut(rgbColors[0]) + " "
+ + PsUtil.doubleOut(rgbColors[1]) + " "
+ + PsUtil.doubleOut(rgbColors[2])
+ " rg");
}
// stroke/border
} else {
if (isGray) {
- buffer.append(PostScriptUtil.doubleOut(rgbColors[0]) + " G");
+ buffer.append(PsUtil.doubleOut(rgbColors[0]) + " G");
} else {
- buffer.append(PostScriptUtil.doubleOut(rgbColors[0]) + " "
- + PostScriptUtil.doubleOut(rgbColors[1]) + " "
- + PostScriptUtil.doubleOut(rgbColors[2])
+ buffer.append(PsUtil.doubleOut(rgbColors[0]) + " "
+ + PsUtil.doubleOut(rgbColors[1]) + " "
+ + PsUtil.doubleOut(rgbColors[2])
+ " RG");
}
}
@@ -127,22 +126,22 @@
int index = 0;
if (fillNotStroke) {
/* Fill */
- buffer.append(PostScriptUtil.doubleOut(cmykColors[index]) + " ");
+ buffer.append(PsUtil.doubleOut(cmykColors[index]) + " ");
index ++;
- buffer.append(PostScriptUtil.doubleOut(cmykColors[index]) + " ");
+ buffer.append(PsUtil.doubleOut(cmykColors[index]) + " ");
index ++;
- buffer.append(PostScriptUtil.doubleOut(cmykColors[index]) + " ");
+ buffer.append(PsUtil.doubleOut(cmykColors[index]) + " ");
index ++;
- buffer.append(PostScriptUtil.doubleOut(cmykColors[index]) + " k");
+ buffer.append(PsUtil.doubleOut(cmykColors[index]) + " k");
} else {
/* Stroke ?? */
- buffer.append(PostScriptUtil.doubleOut(cmykColors[index]) + " ");
+ buffer.append(PsUtil.doubleOut(cmykColors[index]) + " ");
index ++;
- buffer.append(PostScriptUtil.doubleOut(cmykColors[index]) + " ");
+ buffer.append(PsUtil.doubleOut(cmykColors[index]) + " ");
index ++;
- buffer.append(PostScriptUtil.doubleOut(cmykColors[index]) + " ");
+ buffer.append(PsUtil.doubleOut(cmykColors[index]) + " ");
index ++;
- buffer.append(PostScriptUtil.doubleOut(cmykColors[index]) + " K");
+ buffer.append(PsUtil.doubleOut(cmykColors[index]) + " K");
}
return buffer.toString();
}
@@ -160,9 +159,9 @@
final StringBuilder buffer = new StringBuilder("");
final float[] grayColors = color.getComponents(null);
if (fillNotStroke) {
- buffer.append(PostScriptUtil.doubleOut(grayColors[0]) + " g");
+ buffer.append(PsUtil.doubleOut(grayColors[0]) + " g");
} else {
- buffer.append(PostScriptUtil.doubleOut(grayColors[0]) + " G");
+ buffer.append(PsUtil.doubleOut(grayColors[0]) + " G");
}
return buffer.toString();
}
Added: trunk/foray/foray-common/src/java/org/foray/common/ps/PsUtil.java
===================================================================
--- trunk/foray/foray-common/src/java/org/foray/common/ps/PsUtil.java (rev 0)
+++ trunk/foray/foray-common/src/java/org/foray/common/ps/PsUtil.java 2007-06-13 21:43:53 UTC (rev 9782)
@@ -0,0 +1,148 @@
+/*
+ * Copyright 2007 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.WKConstants;
+
+/**
+ * PostScript-related tools included in the Common module to prevent unnecessary
+ * dependencies on the PostScript module.
+ */
+public final class PsUtil {
+
+ /** The number of array elements in a PostScript matrix, that is, 6. */
+ public static final byte MATRIX_QTY_ELEMENTS = 6;
+
+ /** A legacy magic number of unknown significance. */
+ private static final float MAGIC_NUMBER_1 = 0.95f;
+
+ /** A legacy magic number of unknown significance. */
+ private static final float MAGIC_NUMBER_2 = 0.05f;
+
+ /** A legacy magic number of unknown significance. */
+ private static final float MAGIC_NUMBER_3 = 5.0f;
+
+ /** The maximum number of digits to the right of the decimal point that
+ * should be written when the numeric value is written. */
+ private static final byte MAX_DECIMAL_DIGITS = 6;
+
+ /**
+ * Private Constructor. This class is a utility class and should never be
+ * instantiated.
+ */
+ private PsUtil() { }
+
+ /**
+ * Format a {@link Double} instance as PostScript output.
+ * @param theDouble The {@link Double} instance to format.
+ * @return The {@link Double} as PostScript output.
+ */
+ public static String doubleOut(final Double theDouble) {
+ return doubleOut(theDouble.doubleValue());
+ }
+
+ /**
+ * Format a double primitive as PostScript output.
+ * @param doubleValue The double primitive to format.
+ * @return The double primitive as PostScript output.
+ */
+ public static String doubleOut(final double doubleValue) {
+ final StringBuilder p = new StringBuilder();
+ double modifiedDoubleValue = doubleValue;
+ if (modifiedDoubleValue < 0) {
+ modifiedDoubleValue = -modifiedDoubleValue;
+ p.append("-");
+ }
+ final double trouble = modifiedDoubleValue % 1;
+
+ if (trouble > MAGIC_NUMBER_1) {
+ p.append((int) modifiedDoubleValue + 1);
+ } else if (trouble < MAGIC_NUMBER_2) {
+ p.append((int) modifiedDoubleValue);
+ } else {
+ final String doubleString = Double.toString(modifiedDoubleValue);
+ final int decimal = doubleString.indexOf(".");
+ if (decimal != -1) {
+ p.append(doubleString.substring(0, decimal));
+
+ if ((doubleString.length() - decimal) > MAX_DECIMAL_DIGITS) {
+ p.append(doubleString.substring(decimal,
+ decimal + MAX_DECIMAL_DIGITS));
+ } else {
+ p.append(doubleString.substring(decimal));
+ }
+ } else {
+ p.append(doubleString);
+ }
+ }
+ return p.toString();
+ }
+
+ /**
+ * Format a double primitive as PostScript output.
+ * @param doubleValue The double primitive to format.
+ * @param radix The root numbering system in which the number should be
+ * written. For example, for decimal, the value should be 10, for octal,
+ * the value should be 8.
+ * @return The double primitive as PostScript output.
+ */
+ public static String doubleOut(final double doubleValue, final int radix) {
+ final StringBuilder p = new StringBuilder();
+ double modifiedDoubleValue = doubleValue;
+ if (modifiedDoubleValue < 0) {
+ modifiedDoubleValue = -modifiedDoubleValue;
+ p.append("-");
+ }
+ final double trouble = modifiedDoubleValue % 1;
+
+ if (trouble > (1.0 - (MAGIC_NUMBER_3 / (Math.pow(
+ WKConstants.RADIX_BASE_10, radix))))) {
+ p.append((int) modifiedDoubleValue + 1);
+ } else if (trouble < (MAGIC_NUMBER_3 / (Math.pow(
+ WKConstants.RADIX_BASE_10, radix)))) {
+ p.append((int) modifiedDoubleValue);
+ } else {
+ final String doubleString = Double.toString(modifiedDoubleValue);
+ final int decimal = doubleString.indexOf(".");
+ if (decimal != -1) {
+ p.append(doubleString.substring(0, decimal));
+
+ if ((doubleString.length() - decimal) > radix) {
+ p.append(doubleString.substring(decimal, decimal + radix));
+ } else {
+ p.append(doubleString.substring(decimal));
+ }
+ } else {
+ p.append(doubleString);
+ }
+ }
+ return p.toString();
+ }
+
+}
Property changes on: trunk/foray/foray-common/src/java/org/foray/common/ps/PsUtil.java
___________________________________________________________________
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:36:00 UTC (rev 9781)
+++ trunk/foray/foray-graphic/src/java/org/foray/graphic/batik/PDFGraphics2D.java 2007-06-13 21:43:53 UTC (rev 9782)
@@ -27,9 +27,9 @@
*/
package org.foray.graphic.batik;
-import org.foray.common.PostScriptUtil;
import org.foray.common.WKConstants;
import org.foray.common.ps.PSColor;
+import org.foray.common.ps.PsUtil;
import org.foray.pdf.PDFGraphicsState;
import org.foray.pdf.object.PDFAnnotList;
import org.foray.pdf.object.PDFDocument;
@@ -215,7 +215,7 @@
/* TODO: This logic needs to be integrated with the regular PDF
* classes. */
final double[] vals =
- new double[PostScriptUtil.MATRIX_QTY_ELEMENTS];
+ new double[PsUtil.MATRIX_QTY_ELEMENTS];
at.getMatrix(vals);
final String matrixString = octalMatrixToString(vals);
currentStream.write(matrixString);
@@ -231,7 +231,7 @@
public static String octalMatrixToString(final double[] theMatrix) {
final StringBuilder buffer = new StringBuilder();
for (int i = 0; i < theMatrix.length; i++) {
- buffer.append(PostScriptUtil.doubleOut(theMatrix[i],
+ buffer.append(PsUtil.doubleOut(theMatrix[i],
WKConstants.RADIX_BASE_8));
buffer.append(" ");
}
@@ -249,7 +249,7 @@
final int numElements) {
final StringBuilder buffer = new StringBuilder();
for (int i = 0; i < numElements; i++) {
- buffer.append(PostScriptUtil.doubleOut(theMatrix[i]) + " ");
+ buffer.append(PsUtil.doubleOut(theMatrix[i]) + " ");
}
return buffer.toString();
}
@@ -412,7 +412,7 @@
// now do any transformation required and add the actual image
// placement instance
final AffineTransform at = getTransform();
- final double[] matrix = new double[PostScriptUtil.MATRIX_QTY_ELEMENTS];
+ final double[] matrix = new double[PsUtil.MATRIX_QTY_ELEMENTS];
at.getMatrix(matrix);
currentStream.write("q\n");
final Shape imclip = getClip();
@@ -464,7 +464,7 @@
final AffineTransform trans = getTransform();
final double[] tranvals =
- new double[PostScriptUtil.MATRIX_QTY_ELEMENTS];
+ new double[PsUtil.MATRIX_QTY_ELEMENTS];
trans.getMatrix(tranvals);
String matrixString = octalMatrixToString(tranvals);
currentStream.write(matrixString);
@@ -473,7 +473,7 @@
final PathIterator iter = s.getPathIterator(new AffineTransform());
while (!iter.isDone()) {
final double vals[] =
- new double[PostScriptUtil.MATRIX_QTY_ELEMENTS];
+ new double[PsUtil.MATRIX_QTY_ELEMENTS];
final int type = iter.currentSegment(vals);
switch (type) {
case PathIterator.SEG_CUBICTO:
@@ -520,7 +520,7 @@
String matrixString = null;
while (!iter.isDone()) {
final double vals[] =
- new double[PostScriptUtil.MATRIX_QTY_ELEMENTS];
+ new double[PsUtil.MATRIX_QTY_ELEMENTS];
final int type = iter.currentSegment(vals);
switch (type) {
case PathIterator.SEG_CUBICTO:
@@ -675,10 +675,10 @@
break;
}
final float lw = bs.getLineWidth();
- currentStream.write(PostScriptUtil.doubleOut(lw) + " w\n");
+ currentStream.write(PsUtil.doubleOut(lw) + " w\n");
final float ml = bs.getMiterLimit();
- currentStream.write(PostScriptUtil.doubleOut(ml) + " M\n");
+ currentStream.write(PsUtil.doubleOut(ml) + " M\n");
}
}
@@ -734,7 +734,7 @@
final AffineTransform trans = getTransform();
trans.translate(x, y);
- final double[] vals = new double[PostScriptUtil.MATRIX_QTY_ELEMENTS];
+ final double[] vals = new double[PsUtil.MATRIX_QTY_ELEMENTS];
trans.getMatrix(vals);
final String matrixString = octalMatrixToString(vals);
@@ -806,7 +806,7 @@
final AffineTransform trans = getTransform();
trans.translate(x, y);
- final double[] vals = new double[PostScriptUtil.MATRIX_QTY_ELEMENTS];
+ final double[] vals = new double[PsUtil.MATRIX_QTY_ELEMENTS];
trans.getMatrix(vals);
for (char ch = iterator.first(); ch != CharacterIterator.DONE;
@@ -872,7 +872,7 @@
final PathIterator iter = s.getPathIterator(getTransform());
while (!iter.isDone()) {
final double vals[] =
- new double[PostScriptUtil.MATRIX_QTY_ELEMENTS];
+ new double[PsUtil.MATRIX_QTY_ELEMENTS];
final int type = iter.currentSegment(vals);
String matrixString = null;
switch (type) {
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:36:00 UTC (rev 9781)
+++ trunk/foray/foray-graphic/src/java/org/foray/graphic/batik/PSGraphics2D.java 2007-06-13 21:43:53 UTC (rev 9782)
@@ -34,9 +34,9 @@
package org.foray.graphic.batik;
import org.foray.common.CharacterOutputStream;
-import org.foray.common.PostScriptUtil;
import org.foray.common.WKConstants;
import org.foray.common.ps.PSColor;
+import org.foray.common.ps.PsUtil;
import org.foray.graphic.TempImage;
import org.axsl.graphicR.Graphic;
@@ -209,7 +209,7 @@
final Graphic graphic = new TempImage(null, width, height, result);
final AffineTransform at = getTransform();
final double[] matrix =
- new double[PostScriptUtil.MATRIX_QTY_ELEMENTS];
+ new double[PsUtil.MATRIX_QTY_ELEMENTS];
at.getMatrix(matrix);
this.out.write("gsave");
final Shape imclip = getClip();
@@ -267,7 +267,7 @@
final PathIterator iter = s.getPathIterator(getTransform());
while (!iter.isDone()) {
final double vals[] =
- new double[PostScriptUtil.MATRIX_QTY_ELEMENTS];
+ new double[PsUtil.MATRIX_QTY_ELEMENTS];
final int type = iter.currentSegment(vals);
String matrixString = null;
switch (type) {
@@ -315,7 +315,7 @@
final int qtyElements) {
final StringBuilder buffer = new StringBuilder();
for (int i = 0; i < qtyElements; i++) {
- buffer.append(PostScriptUtil.doubleOut(
+ buffer.append(PsUtil.doubleOut(
WKConstants.MILLIPOINTS_PER_POINT * matrix[i])
+ " ");
}
@@ -332,7 +332,7 @@
this.out.write("newpath");
while (!iter.isDone()) {
final double vals[] =
- new double[PostScriptUtil.MATRIX_QTY_ELEMENTS];
+ new double[PsUtil.MATRIX_QTY_ELEMENTS];
final int type = iter.currentSegment(vals);
String matrixString = null;
switch (type) {
@@ -463,12 +463,12 @@
break;
}
final float lw = bs.getLineWidth();
- this.out.write(PostScriptUtil.doubleOut(
+ this.out.write(PsUtil.doubleOut(
WKConstants.MILLIPOINTS_PER_POINT * lw)
+ " setlinewidth");
final float ml = bs.getMiterLimit();
- this.out.write(PostScriptUtil.doubleOut(
+ this.out.write(PsUtil.doubleOut(
WKConstants.MILLIPOINTS_PER_POINT * ml)
+ " setmiterlimit");
}
@@ -569,11 +569,11 @@
final AffineTransform trans = getTransform();
trans.translate(x, y);
final double[] vals =
- new double[PostScriptUtil.MATRIX_QTY_ELEMENTS];
+ new double[PsUtil.MATRIX_QTY_ELEMENTS];
trans.getMatrix(vals);
final String matrixString = matrixToString(vals,
- PostScriptUtil.MATRIX_QTY_ELEMENTS);
+ PsUtil.MATRIX_QTY_ELEMENTS);
this.out.write(matrixString + "Tm [" + s + "]");
this.out.write("ET");
@@ -620,13 +620,13 @@
final AffineTransform trans = getTransform();
trans.translate(x, y);
final double[] vals =
- new double[PostScriptUtil.MATRIX_QTY_ELEMENTS];
+ new double[PsUtil.MATRIX_QTY_ELEMENTS];
trans.getMatrix(vals);
for (char ch = iterator.first(); ch != CharacterIterator.DONE;
ch = iterator.next()) {
final String matrixString = matrixToString(vals,
- PostScriptUtil.MATRIX_QTY_ELEMENTS);
+ PsUtil.MATRIX_QTY_ELEMENTS);
this.out.write(matrixString + "Tm [" + ch + "]");
}
@@ -666,7 +666,7 @@
final PathIterator iter = s.getPathIterator(getTransform());
while (!iter.isDone()) {
final double vals[] =
- new double[PostScriptUtil.MATRIX_QTY_ELEMENTS];
+ new double[PsUtil.MATRIX_QTY_ELEMENTS];
final int type = iter.currentSegment(vals);
String matrixString = null;
switch (type) {
Modified: trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFFunction.java
===================================================================
--- trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFFunction.java 2007-06-13 21:36:00 UTC (rev 9781)
+++ trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFFunction.java 2007-06-13 21:43:53 UTC (rev 9782)
@@ -28,7 +28,7 @@
package org.foray.pdf.object;
-import org.foray.common.PostScriptUtil;
+import org.foray.common.ps.PsUtil;
import java.util.List;
@@ -433,7 +433,7 @@
p.append("/Domain [ ");
vectorSize = this.domain.size();
for (tempInt = 0; tempInt < vectorSize; tempInt++) {
- p.append(PostScriptUtil.doubleOut(
+ p.append(PsUtil.doubleOut(
this.domain.get(tempInt)) + " ");
}
@@ -447,7 +447,7 @@
p.append("/Size [ ");
vectorSize = this.size.size();
for (tempInt = 0; tempInt < vectorSize; tempInt++) {
- p.append(PostScriptUtil.doubleOut(this.size.get(tempInt))
+ p.append(PsUtil.doubleOut(this.size.get(tempInt))
+ " ");
}
p.append("]" + EOL);
@@ -457,7 +457,7 @@
p.append("/Encode [ ");
vectorSize = this.encode.size();
for (tempInt = 0; tempInt < vectorSize; tempInt++) {
- p.append(PostScriptUtil.doubleOut(
+ p.append(PsUtil.doubleOut(
this.encode.get(tempInt)) + " ");
}
p.append("]" + EOL);
@@ -485,7 +485,7 @@
p.append("/Range [ ");
vectorSize = this.range.size();
for (tempInt = 0; tempInt < vectorSize; tempInt++) {
- p.append(PostScriptUtil.doubleOut(
+ p.append(PsUtil.doubleOut(
this.range.get(tempInt)) + " ");
}
@@ -497,7 +497,7 @@
p.append("/Decode [ ");
vectorSize = this.decode.size();
for (tempInt = 0; tempInt < vectorSize; tempInt++) {
- p.append(PostScriptUtil.doubleOut(
+ p.append(PsUtil.doubleOut(
this.decode.get(tempInt)) + " ");
}
@@ -540,7 +540,7 @@
p.append("/Domain [ ");
vectorSize = this.domain.size();
for (tempInt = 0; tempInt < vectorSize; tempInt++) {
- p.append(PostScriptUtil.doubleOut(
+ p.append(PsUtil.doubleOut(
this.domain.get(tempInt)) + " ");
}
@@ -555,7 +555,7 @@
p.append("/Range [ ");
vectorSize = this.range.size();
for (tempInt = 0; tempInt < vectorSize; tempInt++) {
- p.append(PostScriptUtil.doubleOut(
+ p.append(PsUtil.doubleOut(
this.range.get(tempInt)) + " ");
}
@@ -569,7 +569,7 @@
p.append("/C0 [ ");
vectorSize = this.cZero.size();
for (tempInt = 0; tempInt < vectorSize; tempInt++) {
- p.append(PostScriptUtil.doubleOut(
+ p.append(PsUtil.doubleOut(
this.cZero.get(tempInt)) + " ");
...
[truncated message content] |
|
From: <vic...@us...> - 2007-06-13 21:49:58
|
Revision: 9784
http://svn.sourceforge.net/foray/?rev=9784&view=rev
Author: victormote
Date: 2007-06-13 14:49:59 -0700 (Wed, 13 Jun 2007)
Log Message:
-----------
Rename class to conform to naming standards.
Modified Paths:
--------------
trunk/foray/foray-common/src/java/org/foray/common/ps/PsColor.java
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
Modified: trunk/foray/foray-common/src/java/org/foray/common/ps/PsColor.java
===================================================================
--- trunk/foray/foray-common/src/java/org/foray/common/ps/PsColor.java 2007-06-13 21:45:14 UTC (rev 9783)
+++ trunk/foray/foray-common/src/java/org/foray/common/ps/PsColor.java 2007-06-13 21:49:59 UTC (rev 9784)
@@ -35,12 +35,12 @@
/**
* Utility class for PostScript color conversions.
*/
-public final class PSColor {
+public final class PsColor {
/**
* Private constructor. This currently has only static methods.
*/
- private PSColor() {
+ private PsColor() {
}
/**
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:45:14 UTC (rev 9783)
+++ trunk/foray/foray-graphic/src/java/org/foray/graphic/batik/PDFGraphics2D.java 2007-06-13 21:49:59 UTC (rev 9784)
@@ -28,7 +28,7 @@
package org.foray.graphic.batik;
import org.foray.common.WKConstants;
-import org.foray.common.ps.PSColor;
+import org.foray.common.ps.PsColor;
import org.foray.common.ps.PsUtil;
import org.foray.pdf.PDFGraphicsState;
import org.foray.pdf.object.PDFAnnotList;
@@ -568,7 +568,7 @@
} else {
this.graphicsState.setStrokeColor(c);
}
- currentStream.write(PSColor.toPS(c, fill) + "\n");
+ currentStream.write(PsColor.toPS(c, fill) + "\n");
}
/**
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:45:14 UTC (rev 9783)
+++ trunk/foray/foray-graphic/src/java/org/foray/graphic/batik/PSGraphics2D.java 2007-06-13 21:49:59 UTC (rev 9784)
@@ -35,7 +35,7 @@
import org.foray.common.CharacterOutputStream;
import org.foray.common.WKConstants;
-import org.foray.common.ps.PSColor;
+import org.foray.common.ps.PsColor;
import org.foray.common.ps.PsUtil;
import org.foray.graphic.TempImage;
@@ -612,9 +612,9 @@
this.out.write("BT");
final Shape imclip = getClip();
writeClip(imclip);
- this.out.write(PSColor.toPS(getColor(), true));
+ this.out.write(PsColor.toPS(getColor(), true));
this.out.write("\n");
- this.out.write(PSColor.toPS(getBackground(), true));
+ this.out.write(PsColor.toPS(getBackground(), true));
this.out.write("\n");
final AffineTransform trans = getTransform();
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:45:14 UTC (rev 9783)
+++ trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFColor.java 2007-06-13 21:49:59 UTC (rev 9784)
@@ -28,7 +28,7 @@
package org.foray.pdf.object;
-import org.foray.common.ps.PSColor;
+import org.foray.common.ps.PsColor;
import java.awt.Color;
import java.awt.color.ColorSpace;
@@ -58,7 +58,7 @@
* {@inheritDoc}
*/
public String getSetterString(final boolean fillNotStroke) {
- return PSColor.toPS(this.color, fillNotStroke) + "\n";
+ return PsColor.toPS(this.color, fillNotStroke) + "\n";
}
/**
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2007-06-14 20:29:20
|
Revision: 9790
http://svn.sourceforge.net/foray/?rev=9790&view=rev
Author: victormote
Date: 2007-06-14 13:29:21 -0700 (Thu, 14 Jun 2007)
Log Message:
-----------
Add and use source code for the Batik PDF Transcoder.
Modified Paths:
--------------
trunk/foray/foray-graphic/.classpath
Added Paths:
-----------
trunk/foray/lib-build/batik/batik-1.6-pdf-transcoder-src.zip
trunk/foray/lib-build/batik/readme.txt
Modified: trunk/foray/foray-graphic/.classpath
===================================================================
--- trunk/foray/foray-graphic/.classpath 2007-06-14 19:14:32 UTC (rev 9789)
+++ trunk/foray/foray-graphic/.classpath 2007-06-14 20:29:21 UTC (rev 9790)
@@ -26,6 +26,6 @@
<classpathentry kind="lib" path="/FOray Lib/batik-1.6-awt-util.jar" sourcepath="/FOray Lib-Build/batik/batik-1.6-sources.zip"/>
<classpathentry combineaccessrules="false" kind="src" path="/axslPDF-W"/>
<classpathentry kind="lib" path="/FOray Lib/batik-1.6-ext.jar" sourcepath="/FOray Lib-Build/batik/batik-1.6-sources.zip"/>
- <classpathentry kind="lib" path="/FOray Lib/batik-1.6-pdf-transcoder.jar"/>
+ <classpathentry kind="lib" path="/FOray Lib/batik-1.6-pdf-transcoder.jar" sourcepath="/FOray Lib-Build/batik/batik-1.6-pdf-transcoder-src.zip"/>
<classpathentry kind="output" path="build/eclipse"/>
</classpath>
Added: trunk/foray/lib-build/batik/batik-1.6-pdf-transcoder-src.zip
===================================================================
(Binary files differ)
Property changes on: trunk/foray/lib-build/batik/batik-1.6-pdf-transcoder-src.zip
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/foray/lib-build/batik/readme.txt
===================================================================
--- trunk/foray/lib-build/batik/readme.txt (rev 0)
+++ trunk/foray/lib-build/batik/readme.txt 2007-06-14 20:29:21 UTC (rev 9790)
@@ -0,0 +1,8 @@
+The file batik-1.6-pdf-transcoder-src.zip in this directory was created by me
+on June 14, 2007 from the FOP sources marked with the tag "batik-1_6". It is
+hacked up and incomplete. I suppose the correct way to do this would be to run
+the FOP build to get the generated classes and such, but the cost seesm to
+exceed the benefit.
+
+Victor Mote
+June 14, 2007
\ No newline at end of file
Property changes on: trunk/foray/lib-build/batik/readme.txt
___________________________________________________________________
Name: svn:keywords
+ "Author Id Rev Date URL"
Name: svn:eol-style
+ native
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2007-06-14 21:01:10
|
Revision: 9793
http://svn.sourceforge.net/foray/?rev=9793&view=rev
Author: victormote
Date: 2007-06-14 14:01:12 -0700 (Thu, 14 Jun 2007)
Log Message:
-----------
Fix the build by making the Graphic module dependent on the FOray (not the axsl) PDF module.
Modified Paths:
--------------
trunk/foray/foray-graphic/scripts/build.xml
trunk/foray/scripts/build.xml
Modified: trunk/foray/foray-graphic/scripts/build.xml
===================================================================
--- trunk/foray/foray-graphic/scripts/build.xml 2007-06-14 20:45:48 UTC (rev 9792)
+++ trunk/foray/foray-graphic/scripts/build.xml 2007-06-14 21:01:12 UTC (rev 9793)
@@ -31,6 +31,9 @@
<fileset dir="${foray.sandbox}/foray-common/build/ant">
<include name="*.jar"/>
</fileset>
+ <fileset dir="${foray.sandbox}/foray-pdf/build/ant">
+ <include name="*.jar"/>
+ </fileset>
</path>
</target>
Modified: trunk/foray/scripts/build.xml
===================================================================
--- trunk/foray/scripts/build.xml 2007-06-14 20:45:48 UTC (rev 9792)
+++ trunk/foray/scripts/build.xml 2007-06-14 21:01:12 UTC (rev 9793)
@@ -653,7 +653,7 @@
<!-- =================================================================== -->
<!-- Build the Graphic module -->
<!-- =================================================================== -->
- <target name="graphic" depends="ps"
+ <target name="graphic" depends="pdf"
description="Compile the graphic module">
<property name="module.graphic" value=", graphic"/>
<ant antfile="${foray.sandbox}/foray-graphic/scripts/build.xml"
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2007-06-15 00:11:37
|
Revision: 9796
http://svn.sourceforge.net/foray/?rev=9796&view=rev
Author: victormote
Date: 2007-06-14 17:11:35 -0700 (Thu, 14 Jun 2007)
Log Message:
-----------
Add another test.
Modified Paths:
--------------
trunk/foray/foray-graphic/src/javatest/org/foray/graphic/TestSvgGraphic.java
trunk/foray/resource/fo-examples/svg/font-embed.svg
Modified: trunk/foray/foray-graphic/src/javatest/org/foray/graphic/TestSvgGraphic.java
===================================================================
--- trunk/foray/foray-graphic/src/javatest/org/foray/graphic/TestSvgGraphic.java 2007-06-14 22:26:07 UTC (rev 9795)
+++ trunk/foray/foray-graphic/src/javatest/org/foray/graphic/TestSvgGraphic.java 2007-06-15 00:11:35 UTC (rev 9796)
@@ -33,6 +33,7 @@
import org.apache.batik.dom.GenericText;
import org.apache.batik.dom.svg.SVGOMDocument;
import org.apache.batik.dom.svg.SVGOMRectElement;
+import org.apache.batik.dom.svg.SVGOMStyleElement;
import org.apache.batik.dom.svg.SVGOMTextElement;
import org.w3c.dom.Attr;
@@ -126,4 +127,57 @@
assertEquals(textNode.getNodeValue(), "white");
}
+ /**
+ * Functional test of the "font-embed.svg" SVG.
+ * @throws GraphicException For errors processing image.
+ * @throws IOException For errors reading image.
+ */
+ public void testFontEmbed() throws GraphicException, IOException {
+ final FOrayGraphic graphic = this.getServer().makeGraphic(
+ "font-embed.svg", this.getBaseURLs(), false);
+ assertNotNull(graphic);
+ assertTrue(graphic instanceof SVGGraphic);
+ final SVGGraphic svg = (SVGGraphic) graphic;
+
+ final SVGDocument svgDoc = svg.getSVGDocument();
+ assertNotNull(svgDoc);
+ assertTrue(svgDoc instanceof SVGOMDocument);
+ /* We need this cast to get the CSS implementation and access to the
+ * related stylesheets. */
+ final SVGOMDocument batikDoc = (SVGOMDocument) svgDoc;
+
+ /* Test the direct children of the document itself. */
+ NodeList children = batikDoc.getChildNodes();
+ int childCount = children.getLength();
+ assertEquals(2, childCount);
+
+ /* The first child is the comment, the second child is the <svg> element
+ * itself. */
+ Node child = children.item(1);
+ assertTrue(child instanceof SVGSVGElement);
+ final SVGSVGElement svgElement = (SVGSVGElement) child;
+
+ children = svgElement.getChildNodes();
+ childCount = children.getLength();
+ /* The 5 children are: 1) ignorable whitespace, 2) the style element,
+ * 3) ignorable whitespace, 4) the text element, 5) ignorable
+ * whitespace. */
+ assertEquals(5, childCount);
+
+ /* We are interested mostly in the style element, as we want to get to
+ * the embedded font contents. */
+ child = children.item(1);
+ assertTrue(child instanceof SVGOMStyleElement);
+// final SVGOMStyleElement styleElement = (SVGOMStyleElement) child;
+
+ /* Batik 1.6 throws a "not implemented" runtime exception on the DOM
+ * method "getSheet()", so we do the following instead, which returns
+ * a Batik-specific stylesheet. */
+
+ /* Following code commented for now, as Batik throws an NPE. */
+// final StyleSheet styleSheet = styleElement.getCSSStyleSheet();
+// assertNotNull(styleSheet);
+
+ }
+
}
Modified: trunk/foray/resource/fo-examples/svg/font-embed.svg
===================================================================
--- trunk/foray/resource/fo-examples/svg/font-embed.svg 2007-06-14 22:26:07 UTC (rev 9795)
+++ trunk/foray/resource/fo-examples/svg/font-embed.svg 2007-06-15 00:11:35 UTC (rev 9796)
@@ -20,10 +20,10 @@
Only the glyphs needed by this document were included in the embedded font.
-->
-<svg width="150" height="50">
-
+<svg width="150" height="50">
+
<style type="text/css">
- <![CDATA[
+ <![CDATA[
@font-face{font-family:'Saturn';src:url("data:;base64,\
T1RUTwACACAAAQAAQ0ZGIA1bsEAAAAAsAAALE2NtYXD/pwCYAAALQAAAACwBAAQCAAEBAQdTYXR1\
cm4AAQEBM/gbDAD4GASL+2IcCXIcCE4FHqAAQHFmEf+Lix6gAEBxZhH/i4sMB+0PjBDxEZMcCwsS\
@@ -77,8 +77,8 @@
WTL7RfczH/ct+z/Y+2H7ghr7gj77Yfst+z8e+0X7M/tZMvt/G/uA+1nk90X7Mx/7Lfc/Pvdg94Ma\
94HY92H3Lvc/HvdG9zT3WeT3fhsOHAkTFBwFNxUAAAAAAQAAAAMAAAAMAAQAIAAAAAQABAABAAAA\
Y///AAAAYf///6AAAQAAAAA=")}
- ]]>
- </style>
+ ]]>
+ </style>
<text x="20" y="40" font-family="Saturn" font-size="36">abc</text>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2007-06-17 01:07:26
|
Revision: 9809
http://svn.sourceforge.net/foray/?rev=9809&view=rev
Author: victormote
Date: 2007-06-16 18:07:27 -0700 (Sat, 16 Jun 2007)
Log Message:
-----------
Use a true OutputStream to output the SVG-to-PDF work.
Modified Paths:
--------------
trunk/foray/foray-graphic/src/java/org/foray/graphic/SVGGraphic.java
trunk/foray/foray-graphic/src/java/org/foray/graphic/batik/PDFGraphics2D.java
trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFContentStream.java
Modified: trunk/foray/foray-graphic/src/java/org/foray/graphic/SVGGraphic.java
===================================================================
--- trunk/foray/foray-graphic/src/java/org/foray/graphic/SVGGraphic.java 2007-06-16 23:55:21 UTC (rev 9808)
+++ trunk/foray/foray-graphic/src/java/org/foray/graphic/SVGGraphic.java 2007-06-17 01:07:27 UTC (rev 9809)
@@ -426,7 +426,8 @@
*/
public void drawPdfStreamContent(final OutputStream output,
final Rectangle2D location, final GraphicPdfContext pdfContext,
- final FontConsumer fontConsumer, final boolean strokeText) {
+ final FontConsumer fontConsumer, final boolean strokeText)
+ throws GraphicException {
SVGDocument doc = null;
try {
doc = this.getSVGDocument();
@@ -436,20 +437,14 @@
return;
}
final PDFGraphics2D graphics = getPDFContent4SVG(location,
- fontConsumer, doc, strokeText, pdfContext);
+ fontConsumer, doc, strokeText, pdfContext, output);
if (graphics == null) {
- // Error messages have already been logged.
- return;
+ throw new GraphicException("Unable to convert to PDF: "
+ + this.getUrl().toExternalForm());
}
- final String svgString = graphics.getString();
- final CharacterOutputStream stream = new CharacterOutputStream(output,
- true);
- try {
- stream.write(svgString);
- stream.close();
- } catch (final IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ if (graphics.ioErrorFound()) {
+ throw new GraphicException("I/O error(s) while converting to PDF: "
+ + this.getUrl().toExternalForm());
}
}
@@ -462,10 +457,13 @@
* @param strokeSVGText Indicates whether text should be stroked.
* @param pdfContext The PDF context in which this content is being written.
* @return The PDFGraphics2D instance for the SVG.
+ * @param outputStream The output stream to which this processor writes its
+ * PDF output.
*/
public PDFGraphics2D getPDFContent4SVG(final Rectangle2D contentRectangle,
final FontConsumer fontConsumer, final SVGDocument svgDocument,
- final boolean strokeSVGText, final GraphicPdfContext pdfContext) {
+ final boolean strokeSVGText, final GraphicPdfContext pdfContext,
+ final OutputStream outputStream) {
/* If not running in a graphical environment, log an error message
* and skip the SVG. */
if (! Environment.isGraphicalEnvironment()) {
@@ -497,7 +495,8 @@
builder = null;
final PDFGraphics2D graphics = new PDFGraphics2D(true, contentRectangle,
- svgDocument, fontConsumer, this.getLogger(), pdfContext);
+ svgDocument, fontConsumer, this.getLogger(), pdfContext,
+ outputStream);
graphics.setGraphicContext(
new org.apache.batik.ext.awt.g2d.GraphicContext());
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-16 23:55:21 UTC (rev 9808)
+++ trunk/foray/foray-graphic/src/java/org/foray/graphic/batik/PDFGraphics2D.java 2007-06-17 01:07:27 UTC (rev 9809)
@@ -27,6 +27,7 @@
*/
package org.foray.graphic.batik;
+import org.foray.common.CharacterOutputStream;
import org.foray.common.WKConstants;
import org.foray.common.ps.PsColor;
import org.foray.common.ps.PsUtil;
@@ -79,7 +80,8 @@
import java.awt.image.Raster;
import java.awt.image.RenderedImage;
import java.awt.image.renderable.RenderableImage;
-import java.io.StringWriter;
+import java.io.IOException;
+import java.io.OutputStream;
import java.text.AttributedCharacterIterator;
import java.text.CharacterIterator;
import java.util.ArrayList;
@@ -116,7 +118,7 @@
private PDFDocument pdfDoc;
/** The current stream to add PDF commands to. */
- private StringWriter currentStream = new StringWriter();
+ private CharacterOutputStream currentStream;
/** The current annotation list to add annotations to. */
private PDFAnnotList currentAnnotList = null;
@@ -145,6 +147,9 @@
/** The graphics state. */
private PDFGraphicsState graphicsState;
+ /** Indicates whether any I/O Exceptions were found while processing. */
+ private boolean ioErrorFound = false;
+
/**
* Create a new PDFGraphics2D with the given pdf document info.
* This is used to create a Graphics object for use inside an already
@@ -157,12 +162,16 @@
* @param fontConsumer The font consumer for this document.
* @param logger The logger.
* @param pdfContext The PDF context in which this content is being written.
+ * @param outputStream The output stream to which this processor writes its
+ * PDF output.
*/
public PDFGraphics2D(final boolean textAsShapes,
final Rectangle2D contentRectangle, final SVGDocument svgDocument,
final FontConsumer fontConsumer, final Log logger,
- final GraphicPdfContext pdfContext) {
+ final GraphicPdfContext pdfContext,
+ final OutputStream outputStream) {
super(textAsShapes);
+ this.currentStream = new CharacterOutputStream(outputStream, true);
/* TODO: What we really need here is a new GraphicsState, not a complete
* new document. */
@@ -204,7 +213,7 @@
// transform so that the coordinates (0,0) is from the top left
// and positive is down and to the right. (0,0) is where the
// viewBox puts it.
- currentStream.write("1 0 0 -1 " + contentRectangle.getX() + " "
+ this.write("1 0 0 -1 " + contentRectangle.getX() + " "
+ contentRectangle.getY() + " cm\n");
final SVGSVGElement svg = svgDocument.getRootElement();
@@ -218,8 +227,8 @@
new double[PsUtil.MATRIX_QTY_ELEMENTS];
at.getMatrix(vals);
final String matrixString = octalMatrixToString(vals);
- currentStream.write(matrixString);
- currentStream.write("cm\n");
+ this.write(matrixString);
+ this.write("cm\n");
}
}
@@ -255,14 +264,6 @@
}
/**
- * Returns this object as the value which should be written to the PDF file.
- * @return The PDF representation of this object.
- */
- public String getString() {
- return currentStream.toString();
- }
-
- /**
* Sets the graphic context.
* @param c The new graphic context.
*/
@@ -414,14 +415,14 @@
final AffineTransform at = getTransform();
final double[] matrix = new double[PsUtil.MATRIX_QTY_ELEMENTS];
at.getMatrix(matrix);
- currentStream.write("q\n");
+ this.write("q\n");
final Shape imclip = getClip();
writeClip(imclip);
final String matrixString = matrixToString(matrix, QTY_ELEMENTS_CUBIC);
- currentStream.write(matrixString);
- currentStream.write("cm\n");
+ this.write(matrixString);
+ this.write("cm\n");
// this.xObject must be null, so this code is not used ??!!
- currentStream.write("" + width + " 0 0 " + (-height) + " " + x
+ this.write("" + width + " 0 0 " + (-height) + " " + x
+ " " + (y + height) + " cm\n" + "/"
+ this.xObject.getXObjectName() + " Do\nQ\n");
return true;
@@ -454,7 +455,7 @@
return;
}
- currentStream.write("q\n");
+ this.write("q\n");
final Shape imclip = getClip();
writeClip(imclip);
applyColor(c, false);
@@ -467,8 +468,8 @@
new double[PsUtil.MATRIX_QTY_ELEMENTS];
trans.getMatrix(tranvals);
String matrixString = octalMatrixToString(tranvals);
- currentStream.write(matrixString);
- currentStream.write("cm\n");
+ this.write(matrixString);
+ this.write("cm\n");
final PathIterator iter = s.getPathIterator(new AffineTransform());
while (!iter.isDone()) {
@@ -478,26 +479,26 @@
switch (type) {
case PathIterator.SEG_CUBICTO:
matrixString = matrixToString(vals, QTY_ELEMENTS_CUBIC);
- currentStream.write(matrixString);
- currentStream.write("c\n");
+ this.write(matrixString);
+ this.write("c\n");
break;
case PathIterator.SEG_LINETO:
matrixString = matrixToString(vals, QTY_ELEMENTS_LINEAR);
- currentStream.write(matrixString);
- currentStream.write("l\n");
+ this.write(matrixString);
+ this.write("l\n");
break;
case PathIterator.SEG_MOVETO:
matrixString = matrixToString(vals, QTY_ELEMENTS_LINEAR);
- currentStream.write(matrixString);
- currentStream.write("m\n");
+ this.write(matrixString);
+ this.write("m\n");
break;
case PathIterator.SEG_QUADTO:
matrixString = matrixToString(vals, QTY_ELEMENTS_QUAD);
- currentStream.write(matrixString);
- currentStream.write("y\n");
+ this.write(matrixString);
+ this.write("y\n");
break;
case PathIterator.SEG_CLOSE:
- currentStream.write("h\n");
+ this.write("h\n");
break;
default:
break;
@@ -505,7 +506,7 @@
iter.next();
}
doDrawing(false, true, false);
- currentStream.write("Q\n");
+ this.write("Q\n");
}
/**
@@ -525,26 +526,26 @@
switch (type) {
case PathIterator.SEG_CUBICTO:
matrixString = matrixToString(vals, QTY_ELEMENTS_CUBIC);
- currentStream.write(matrixString);
- currentStream.write("c\n");
+ this.write(matrixString);
+ this.write("c\n");
break;
case PathIterator.SEG_LINETO:
matrixString = matrixToString(vals, QTY_ELEMENTS_LINEAR);
- currentStream.write(matrixString);
- currentStream.write("l\n");
+ this.write(matrixString);
+ this.write("l\n");
break;
case PathIterator.SEG_MOVETO:
matrixString = matrixToString(vals, QTY_ELEMENTS_LINEAR);
- currentStream.write(matrixString);
- currentStream.write("m\n");
+ this.write(matrixString);
+ this.write("m\n");
break;
case PathIterator.SEG_QUADTO:
matrixString = matrixToString(vals, QTY_ELEMENTS_QUAD);
- currentStream.write(matrixString);
- currentStream.write("y\n");
+ this.write(matrixString);
+ this.write("y\n");
break;
case PathIterator.SEG_CLOSE:
- currentStream.write("h\n");
+ this.write("h\n");
break;
default:
break;
@@ -552,8 +553,8 @@
iter.next();
}
// clip area
- currentStream.write("W\n");
- currentStream.write("n\n");
+ this.write("W\n");
+ this.write("n\n");
}
/**
@@ -569,7 +570,7 @@
anyChange = this.graphicsState.setStrokeColor(color);
}
if (anyChange) {
- currentStream.write(PsColor.toPS(color, fill) + "\n");
+ this.write(PsColor.toPS(color, fill) + "\n");
}
}
@@ -620,7 +621,7 @@
final PDFPattern myPat = PDFPattern.createGradient(false,
aColorSpace,
someColors, null, theCoords, pdfDoc);
- currentStream.write(myPat.getSetterString(fill));
+ this.write(myPat.getSetterString(fill));
} else if (paint instanceof TexturePaint) { }
}
@@ -634,53 +635,53 @@
final float[] da = bs.getDashArray();
if (da != null) {
- currentStream.write("[");
+ this.write("[");
for (int count = 0; count < da.length; count++) {
if (((int) da[count]) == 0) {
// the dasharray units in pdf are (whole) numbers
// in user space units, cannot be 0
- currentStream.write("1");
+ this.write("1");
} else {
- currentStream.write("" + ((int) da[count]));
+ this.write("" + ((int) da[count]));
}
if (count < da.length - 1) {
- currentStream.write(" ");
+ this.write(" ");
}
}
- currentStream.write("] ");
+ this.write("] ");
final float offset = bs.getDashPhase();
- currentStream.write(((int) offset) + " d\n");
+ this.write(((int) offset) + " d\n");
}
final int ec = bs.getEndCap();
switch (ec) {
case BasicStroke.CAP_BUTT:
- currentStream.write(0 + " J\n");
+ this.write(0 + " J\n");
break;
case BasicStroke.CAP_ROUND:
- currentStream.write(1 + " J\n");
+ this.write(1 + " J\n");
break;
case BasicStroke.CAP_SQUARE:
- currentStream.write(2 + " J\n");
+ this.write(2 + " J\n");
break;
}
final int lj = bs.getLineJoin();
switch (lj) {
case BasicStroke.JOIN_MITER:
- currentStream.write(0 + " j\n");
+ this.write(0 + " j\n");
break;
case BasicStroke.JOIN_ROUND:
- currentStream.write(1 + " j\n");
+ this.write(1 + " j\n");
break;
case BasicStroke.JOIN_BEVEL:
- currentStream.write(2 + " j\n");
+ this.write(2 + " j\n");
break;
}
final float lw = bs.getLineWidth();
- currentStream.write(PsUtil.doubleOut(lw) + " w\n");
+ this.write(PsUtil.doubleOut(lw) + " w\n");
final float ml = bs.getMiterLimit();
- currentStream.write(PsUtil.doubleOut(ml) + " M\n");
+ this.write(PsUtil.doubleOut(ml) + " M\n");
}
}
@@ -720,10 +721,10 @@
this.graphicsState.setFont(font);
this.graphicsState.setFontSize(size);
final String fontName = this.pdfContext.getFontName(font);
- currentStream.write("/" + fontName + " " + size + " Tf\n");
+ this.write("/" + fontName + " " + size + " Tf\n");
}
- currentStream.write("q\n");
+ this.write("q\n");
final Shape imclip = getClip();
writeClip(imclip);
@@ -732,7 +733,7 @@
c = getBackground();
applyColor(c, false);
- currentStream.write("BT\n");
+ this.write("BT\n");
final AffineTransform trans = getTransform();
trans.translate(x, y);
@@ -740,17 +741,17 @@
trans.getMatrix(vals);
final String matrixString = octalMatrixToString(vals);
- currentStream.write(matrixString);
- currentStream.write("cm\n");
- currentStream.write("1 0 0 -1 0 0 Tm ");
+ this.write(matrixString);
+ this.write("cm\n");
+ this.write("1 0 0 -1 0 0 Tm ");
final PDFString pdfString = new PDFString(this.pdfDoc, s, font,
true);
final String outputString = pdfString.toPDF();
- currentStream.write(outputString);
+ this.write(outputString);
- currentStream.write("ET\n");
- currentStream.write("Q\n");
+ this.write("ET\n");
+ this.write("Q\n");
}
/**
@@ -804,7 +805,7 @@
c = getBackground();
applyColor(c, false);
- currentStream.write("BT\n");
+ this.write("BT\n");
final AffineTransform trans = getTransform();
trans.translate(x, y);
@@ -837,15 +838,15 @@
this.graphicsState.setFont(font);
this.graphicsState.setFontSize(size);
final String fontName = this.pdfContext.getFontName(font);
- currentStream.write("/" + fontName + " " + size + " Tf\n");
+ this.write("/" + fontName + " " + size + " Tf\n");
}
final String matrixString = octalMatrixToString(vals);
- currentStream.write(matrixString);
- currentStream.write(" Tm (" + ch + ") Tj\n");
+ this.write(matrixString);
+ this.write(" Tm (" + ch + ") Tj\n");
}
- currentStream.write("ET\n");
+ this.write("ET\n");
}
/**
@@ -861,7 +862,7 @@
return;
}
}
- currentStream.write("q\n");
+ this.write("q\n");
final Shape imclip = getClip();
writeClip(imclip);
c = getColor();
@@ -880,26 +881,26 @@
switch (type) {
case PathIterator.SEG_CUBICTO:
matrixString = matrixToString(vals, QTY_ELEMENTS_CUBIC);
- currentStream.write(matrixString);
- currentStream.write("c\n");
+ this.write(matrixString);
+ this.write("c\n");
break;
case PathIterator.SEG_LINETO:
matrixString = matrixToString(vals, QTY_ELEMENTS_LINEAR);
- currentStream.write(matrixString);
- currentStream.write("l\n");
+ this.write(matrixString);
+ this.write("l\n");
break;
case PathIterator.SEG_MOVETO:
matrixString = matrixToString(vals, QTY_ELEMENTS_LINEAR);
- currentStream.write(matrixString);
- currentStream.write("m\n");
+ this.write(matrixString);
+ this.write("m\n");
break;
case PathIterator.SEG_QUADTO:
matrixString = matrixToString(vals, QTY_ELEMENTS_QUAD);
- currentStream.write(matrixString);
- currentStream.write("y\n");
+ this.write(matrixString);
+ this.write("y\n");
break;
case PathIterator.SEG_CLOSE:
- currentStream.write("h\n");
+ this.write("h\n");
break;
default:
break;
@@ -908,7 +909,7 @@
}
doDrawing(true, false,
iter.getWindingRule() == PathIterator.WIND_EVEN_ODD);
- currentStream.write("Q\n");
+ this.write("Q\n");
}
/**
@@ -922,20 +923,20 @@
if (fill) {
if (stroke) {
if (nonzero) {
- currentStream.write("B*\n");
+ this.write("B*\n");
} else {
- currentStream.write("B\n");
+ this.write("B\n");
}
} else {
if (nonzero) {
- currentStream.write("f*\n");
+ this.write("f*\n");
} else {
- currentStream.write("f\n");
+ this.write("f\n");
}
}
} else {
// if(stroke)
- currentStream.write("S\n");
+ this.write("S\n");
}
}
@@ -986,4 +987,26 @@
this.logger.info("copyArea");
}
+ /**
+ * Writes some content.
+ * @param text The content to be written.
+ */
+ private void write(final String text) {
+ try {
+ this.currentStream.write(text);
+ } catch (final IOException e) {
+ this.ioErrorFound = true;
+ }
+ }
+
+ /**
+ * Indicates whether any I/O errors were found while writing to the output
+ * stream.
+ * @return True iff there were I/O errors while writing to the output
+ * stream.
+ */
+ public boolean ioErrorFound() {
+ return this.ioErrorFound;
+ }
+
}
Modified: trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFContentStream.java
===================================================================
--- trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFContentStream.java 2007-06-16 23:55:21 UTC (rev 9808)
+++ trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFContentStream.java 2007-06-17 01:07:27 UTC (rev 9809)
@@ -331,8 +331,13 @@
add("n" + EOL);
}
- svg.drawPdfStreamContent(this.getOutputStream(), contentRectangle,
- this.getPDFDocument(), fontConsumer, strokeSVGText);
+ try {
+ svg.drawPdfStreamContent(this.getOutputStream(), contentRectangle,
+ this.getPDFDocument(), fontConsumer, strokeSVGText);
+ } catch (final GraphicException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
/* Add any links found in the SVG to the current page. */
final GraphicLink[] graphicLinks = svg.getLinks();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2007-06-20 22:06:36
|
Revision: 9821
http://svn.sourceforge.net/foray/?rev=9821&view=rev
Author: victormote
Date: 2007-06-20 15:06:33 -0700 (Wed, 20 Jun 2007)
Log Message:
-----------
1. Add methods to parse Unicode characters from string descriptions.
2. Add test for same.
Modified Paths:
--------------
trunk/foray/foray-app/src/javatest/org/foray/app/TestFOrayAll.java
trunk/foray/foray-common/.classpath
trunk/foray/foray-common/src/java/org/foray/common/UnicodeChar.java
Added Paths:
-----------
trunk/foray/foray-common/src/javatest/
trunk/foray/foray-common/src/javatest/org/
trunk/foray/foray-common/src/javatest/org/foray/
trunk/foray/foray-common/src/javatest/org/foray/common/
trunk/foray/foray-common/src/javatest/org/foray/common/TestFOrayCommon.java
trunk/foray/foray-common/src/javatest/org/foray/common/TestUnicodeChar.java
Modified: trunk/foray/foray-app/src/javatest/org/foray/app/TestFOrayAll.java
===================================================================
--- trunk/foray/foray-app/src/javatest/org/foray/app/TestFOrayAll.java 2007-06-20 20:28:26 UTC (rev 9820)
+++ trunk/foray/foray-app/src/javatest/org/foray/app/TestFOrayAll.java 2007-06-20 22:06:33 UTC (rev 9821)
@@ -29,6 +29,7 @@
package org.foray.app;
import org.foray.area.TestFOrayAreaTree;
+import org.foray.common.TestFOrayCommon;
import org.foray.font.TestFOrayFont;
import org.foray.fotree.TestFOrayFOTree;
import org.foray.graphic.TestFOrayGraphic;
@@ -50,6 +51,7 @@
*/
public static Test suite() {
final TestSuite testSuite = new TestSuite();
+ testSuite.addTest(TestFOrayCommon.suite());
testSuite.addTest(TestFOrayPS.suite());
testSuite.addTest(TestFOrayFont.suite());
testSuite.addTest(TestFOrayGraphic.suite());
Modified: trunk/foray/foray-common/.classpath
===================================================================
--- trunk/foray/foray-common/.classpath 2007-06-20 20:28:26 UTC (rev 9820)
+++ trunk/foray/foray-common/.classpath 2007-06-20 22:06:33 UTC (rev 9821)
@@ -1,9 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry excluding=".#*" kind="src" path="src/java"/>
+ <classpathentry kind="src" path="src/javatest"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="src" path="/axslCommon"/>
<classpathentry kind="lib" path="/FOray Lib/commons-io-1.2.jar" sourcepath="/FOray Lib-Build/commons-io/commons-io-1.2-src.zip"/>
<classpathentry kind="lib" path="/FOray Lib/commons-logging-1.1.jar" sourcepath="/FOray Lib-Build/commons-logging/commons-logging-1.1-src.zip"/>
+ <classpathentry kind="lib" path="/FOray Lib-Build/junit/junit.jar"/>
<classpathentry kind="output" path="build/eclipse"/>
</classpath>
Modified: trunk/foray/foray-common/src/java/org/foray/common/UnicodeChar.java
===================================================================
--- trunk/foray/foray-common/src/java/org/foray/common/UnicodeChar.java 2007-06-20 20:28:26 UTC (rev 9820)
+++ trunk/foray/foray-common/src/java/org/foray/common/UnicodeChar.java 2007-06-20 22:06:33 UTC (rev 9821)
@@ -35,6 +35,13 @@
*/
public final class UnicodeChar {
+ /** The minimum size for a Unicode String, that is, 3, for example "U+9". */
+ private static final byte MIN_UNICODE_STRING_SIZE = 3;
+
+ /** The maximum size for a Unicode String, that is, 8, for example
+ * "U+10A9B3". */
+ private static final byte MAX_UNICODE_STRING_SIZE = 8;
+
/**
* Sorted array of other non-printable characters, which can be searched
* using binary techniques.
@@ -111,4 +118,67 @@
return true;
}
+ /**
+ * Indicates whether a given string is a valid unparsed Unicode code point,
+ * that is, a string in the form "U+nnnn" where "nnnn" represents a string
+ * of 1 to 5 hex characters (0-9, a-z, A-Z).
+ * @param unparsed The unparsed String to be tested.
+ * @return True iff <code>unparsed</code> is a valid Unicode value String.
+ */
+ public static boolean isValidUnparsedCodePoint(final String unparsed) {
+ if (unparsed == null) {
+ return false;
+ }
+ final char[] chars = unparsed.toCharArray();
+ if (chars.length < MIN_UNICODE_STRING_SIZE
+ || chars.length > MAX_UNICODE_STRING_SIZE) {
+ return false;
+ }
+ if (chars[0] != 'U') {
+ return false;
+ }
+ if (chars[1] != '+') {
+ return false;
+ }
+ for (int i = 2; i < chars.length; i++) {
+ final char c = chars[i];
+ if (! StringUtil.isASCIIHex(c)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Parses a Unicode codepoint from a given String.
+ * @param unparsed The unparsed String, which must be in the form of
+ * "U+nnnn", where "nnnn" is from 1 to 4 hex digits representing the
+ * codepoint.
+ * If not in the propert form, throws an IllegalArgumentException.
+ * Use {@link #isValidUnparsedCodePoint(String)} to test for this condition
+ * first.
+ * @return The Unicode code point.
+ */
+ public static int parseCodePoint(final String unparsed) {
+ if (! isValidUnparsedCodePoint(unparsed)) {
+ throw new IllegalArgumentException("Invalid Unicode String: "
+ + unparsed);
+ }
+ int result = 0;
+ final char[] chars = unparsed.toCharArray();
+ int nibblesToShift = 0;
+ for (int i = chars.length - 1; i > 1; i--) {
+ final char c = chars[i];
+ /* The cast from char to byte is safe, as we already know the input
+ * is limited to 0-9, a-z, A-Z. */
+ int converted = StringUtil.asciiHexByteToHex((byte) c);
+ final int bitsToShift = nibblesToShift
+ * WKConstants.BITS_PER_NIBBLE;
+ converted <<= bitsToShift;
+ result |= converted;
+ nibblesToShift ++;
+ }
+ return result;
+ }
+
}
Added: trunk/foray/foray-common/src/javatest/org/foray/common/TestFOrayCommon.java
===================================================================
--- trunk/foray/foray-common/src/javatest/org/foray/common/TestFOrayCommon.java (rev 0)
+++ trunk/foray/foray-common/src/javatest/org/foray/common/TestFOrayCommon.java 2007-06-20 22:06:33 UTC (rev 9821)
@@ -0,0 +1,50 @@
+/*
+ * 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;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * Handles testing for the FOrayCommon module.
+ */
+public class TestFOrayCommon extends TestCase {
+
+ /**
+ * Builds a test suite for all classes in this module.
+ * @return The built test suite.
+ */
+ public static Test suite() {
+ final TestSuite testSuite = new TestSuite();
+ testSuite.addTestSuite(TestUnicodeChar.class);
+ return testSuite;
+ }
+
+}
Property changes on: trunk/foray/foray-common/src/javatest/org/foray/common/TestFOrayCommon.java
___________________________________________________________________
Name: svn:keywords
+ "Author Id Rev Date URL"
Name: svn:eol-style
+ native
Added: trunk/foray/foray-common/src/javatest/org/foray/common/TestUnicodeChar.java
===================================================================
--- trunk/foray/foray-common/src/javatest/org/foray/common/TestUnicodeChar.java (rev 0)
+++ trunk/foray/foray-common/src/javatest/org/foray/common/TestUnicodeChar.java 2007-06-20 22:06:33 UTC (rev 9821)
@@ -0,0 +1,85 @@
+/*
+ * Copyright 2007 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;
+
+import junit.framework.TestCase;
+
+/**
+ * JUnit test class for the class {@link UnicodeChar}.
+ */
+public class TestUnicodeChar extends TestCase {
+
+/**
+ * Unit test of the method {@link UnicodeChar#parseCodePoint(String)}.
+ */
+public void testOutput() {
+ /* First throw some garbage at it. */
+ String testString = "jhuz";
+ try {
+ UnicodeChar.parseCodePoint(testString);
+ fail("Expected IllegalArgumentException for invalid input.");
+ } catch (final IllegalArgumentException e) {
+ /* Ignore. This is the expected case. */
+ }
+
+ /* Try one a little closer to right. */
+ testString = "U+jhuz";
+ try {
+ UnicodeChar.parseCodePoint(testString);
+ fail("Expected IllegalArgumentException for invalid input.");
+ } catch (final IllegalArgumentException e) {
+ /* Ignore. This is the expected case. */
+ }
+
+ /* Try one that is too short. */
+ testString = "U+";
+ try {
+ UnicodeChar.parseCodePoint(testString);
+ fail("Expected IllegalArgumentException for invalid input.");
+ } catch (final IllegalArgumentException e) {
+ /* Ignore. This is the expected case. */
+ }
+
+ /* Try one that is too long. */
+ testString = "U+7845ABC";
+ try {
+ UnicodeChar.parseCodePoint(testString);
+ fail("Expected IllegalArgumentException for invalid input.");
+ } catch (final IllegalArgumentException e) {
+ /* Ignore. This is the expected case. */
+ }
+
+ /* Try one that is valid. */
+ testString = "U+10F23A";
+ final int parsedValue = UnicodeChar.parseCodePoint(testString);
+ assertEquals(0x10F23A, parsedValue);
+
+}
+
+}
Property changes on: trunk/foray/foray-common/src/javatest/org/foray/common/TestUnicodeChar.java
___________________________________________________________________
Name: svn:keywords
+ "Author Id Rev Date URL"
Name: svn:eol-style
+ native
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2007-06-22 19:40:13
|
Revision: 9834
http://svn.sourceforge.net/foray/?rev=9834&view=rev
Author: victormote
Date: 2007-06-22 12:40:12 -0700 (Fri, 22 Jun 2007)
Log Message:
-----------
Make the content stream independent of its page by moving the responsibility for link creation from the stream to the renderer.
Modified Paths:
--------------
trunk/foray/foray-graphic/src/java/org/foray/graphic/batik/PDFGraphics2D.java
trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFContentStream.java
trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFPage.java
trunk/foray/foray-render/src/java/org/foray/render/pdf/PDFRenderer.java
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-22 16:54:30 UTC (rev 9833)
+++ trunk/foray/foray-graphic/src/java/org/foray/graphic/batik/PDFGraphics2D.java 2007-06-22 19:40:12 UTC (rev 9834)
@@ -842,7 +842,6 @@
* {@inheritDoc}
*/
public void fill(final Shape s) {
- // this.area.getLogger().error("fill");
Color c;
c = getBackground();
if (c.getAlpha() == 0) {
@@ -851,7 +850,7 @@
return;
}
}
- this.write("q");
+// this.write("q");
final Shape imclip = getClip();
writeClip(imclip);
c = getColor();
@@ -894,7 +893,7 @@
}
doDrawing(true, false,
iter.getWindingRule() == PathIterator.WIND_EVEN_ODD);
- this.write("Q");
+// this.write("Q");
}
/**
Modified: trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFContentStream.java
===================================================================
--- trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFContentStream.java 2007-06-22 16:54:30 UTC (rev 9833)
+++ trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFContentStream.java 2007-06-22 19:40:12 UTC (rev 9834)
@@ -34,7 +34,6 @@
import org.axsl.fontR.FontUse;
import org.axsl.graphicR.Graphic;
import org.axsl.graphicR.GraphicException;
-import org.axsl.graphicR.GraphicLink;
import org.axsl.graphicR.SVGGraphic;
import org.axsl.pdfW.PDFLineCapStyle;
import org.axsl.pdfW.PDFPathPaint;
@@ -51,7 +50,6 @@
implements org.axsl.pdfW.PDFContentStream {
/** The page this content stream is attached to. */
- private PDFPage page;
/** State variable indicating whether a text object is currently open. */
private boolean textObjectOpen = false;
@@ -59,11 +57,9 @@
/**
* Create a PDFContentStream.
* @param doc The parent PDF document.
- * @param page The PDF page which content stream contains.
*/
- public PDFContentStream(final PDFDocument doc, final PDFPage page) {
+ public PDFContentStream(final PDFDocument doc) {
super(doc);
- this.page = page;
}
/**
@@ -339,16 +335,6 @@
e.printStackTrace();
}
- /* Add any links found in the SVG to the current page. */
- final GraphicLink[] graphicLinks = svg.getLinks();
- for (GraphicLink graphicLink : graphicLinks) {
- /* TODO: This is untested. */
- final PDFLink newLink = new PDFLink(this.getPDFDocument(),
- this.page, graphicLink.getShape().getBounds2D(),
- graphicLink.getUri().toString());
- this.page.addAnnotation(newLink);
- }
-
add("Q" + EOL);
}
Modified: trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFPage.java
===================================================================
--- trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFPage.java 2007-06-22 16:54:30 UTC (rev 9833)
+++ trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFPage.java 2007-06-22 19:40:12 UTC (rev 9834)
@@ -86,7 +86,7 @@
this.resources = resources;
this.pagewidth = pagewidth;
this.pageheight = pageheight;
- this.contents = new PDFContentStream(this.getPDFDocument(), this);
+ this.contents = new PDFContentStream(this.getPDFDocument());
try {
this.contents.addDefaultFilters();
} catch (final PDFException e) {
@@ -148,14 +148,6 @@
}
/**
- * Add a PDFAnnotation to the collection of annotations on this page.
- * @param annotation The {@link PDFAnnotation} to add.
- */
- public void addAnnotation(final PDFAnnotation annotation) {
- this.getAnnotList().addAnnotation(annotation);
- }
-
- /**
* Add an annotation list to the annotations on this page.
* @param listToAdd The annotation list to add.
*/
Modified: trunk/foray/foray-render/src/java/org/foray/render/pdf/PDFRenderer.java
===================================================================
--- trunk/foray/foray-render/src/java/org/foray/render/pdf/PDFRenderer.java 2007-06-22 16:54:30 UTC (rev 9833)
+++ trunk/foray/foray-render/src/java/org/foray/render/pdf/PDFRenderer.java 2007-06-22 19:40:12 UTC (rev 9834)
@@ -54,6 +54,7 @@
import org.axsl.fontR.Font;
import org.axsl.fontR.FontUse;
import org.axsl.graphicR.Graphic;
+import org.axsl.graphicR.GraphicLink;
import org.axsl.graphicR.SVGGraphic;
import org.axsl.pdfW.PDFColor;
import org.axsl.pdfW.PDFContentStream;
@@ -71,9 +72,11 @@
import java.awt.Color;
import java.awt.Rectangle;
+import java.awt.Shape;
import java.awt.geom.Line2D;
import java.awt.geom.Rectangle2D;
import java.io.IOException;
+import java.net.URI;
import java.util.Date;
import java.util.List;
@@ -254,6 +257,7 @@
clipRectangle);
getContentStream().drawSVGDocument(graphic, pdfContentRectangle,
pdfClipRectangle, area.getFontConsumer(), getStrokeSVGText());
+ addSVGLinks(graphic);
}
/**
@@ -282,9 +286,29 @@
getContentStream().drawSVGDocument(svgGraphic,
contentRectangle, null, this.getFontConsumer(),
getStrokeSVGText());
+ addSVGLinks(svgGraphic);
}
/**
+ * Adds any links in the SVG to the current page.
+ * @param svg The SVG whose links should be added to this page.
+ */
+ private void addSVGLinks(final SVGGraphic svg) {
+ /* Add any links found in the SVG to the current page. */
+ final GraphicLink[] graphicLinks = svg.getLinks();
+ for (GraphicLink graphicLink : graphicLinks) {
+ /* TODO: This is untested. */
+ final Shape shape = graphicLink.getShape();
+ final URI target = graphicLink.getUri();
+ /* TODO: Need to compute this value from the URI?? However, if
+ * computable, it doesn't need to be in the interface. */
+ final boolean isExternal = true;
+ this.currentPage.makeLink(shape.getBounds2D(), target.toString(),
+ isExternal);
+ }
+ }
+
+ /**
* {@inheritDoc}
*/
public void renderTextSegment(final GeneralInlineArea area,
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2007-06-22 20:42:38
|
Revision: 9835
http://svn.sourceforge.net/foray/?rev=9835&view=rev
Author: victormote
Date: 2007-06-22 13:42:39 -0700 (Fri, 22 Jun 2007)
Log Message:
-----------
Add a stack of graphics states, and add and use methods to save and restore graphics states.
Modified Paths:
--------------
trunk/foray/foray-graphic/src/java/org/foray/graphic/batik/PDFGraphics2D.java
trunk/foray/foray-pdf/src/java/org/foray/pdf/PDFGraphicsState.java
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-22 19:40:12 UTC (rev 9834)
+++ trunk/foray/foray-graphic/src/java/org/foray/graphic/batik/PDFGraphics2D.java 2007-06-22 20:42:39 UTC (rev 9835)
@@ -92,6 +92,7 @@
import java.text.CharacterIterator;
import java.util.ArrayList;
import java.util.List;
+import java.util.Stack;
/**
* A {@link Graphics2D} implementation used by Batik to render two-dimensional
@@ -99,6 +100,9 @@
*/
public class PDFGraphics2D
extends org.apache.batik.ext.awt.g2d.AbstractGraphics2D {
+ /* TODO: The capabilities in this class need to be merged with those of
+ * {@link PDFContentStream}. This class should essentially use the content
+ * stream to do most of the work. */
/** Constant indicating the number of elements in a cubic element, that is,
* 6. */
@@ -142,8 +146,11 @@
/** The PDF context. */
private GraphicPdfContext pdfContext;
- /** The graphics state. */
- private PDFGraphicsState graphicsState;
+ /** The graphics state stack. The top item on the stack is always the
+ * current graphics state. The next one down is what will be current after
+ * the next "restore". */
+ private Stack<PDFGraphicsState> graphicsStateStack =
+ new Stack<PDFGraphicsState>();
/** Indicates whether any I/O Exceptions were found while processing. */
private boolean ioErrorFound = false;
@@ -179,7 +186,7 @@
this.logger = logger;
this.fontConsumer = fontConsumer;
this.pdfContext = pdfContext;
- this.graphicsState = new PDFGraphicsState();
+ this.graphicsStateStack.push(new PDFGraphicsState());
initGraphicalEnvironment();
transformCoordinates(contentRectangle, svgDocument);
}
@@ -331,7 +338,7 @@
return false;
}
- final int numChannels = this.graphicsState.getStrokeColor()
+ final int numChannels = this.getGraphicsState().getStrokeColor()
.getColorSpace().getNumComponents();
final Dimension size = new Dimension(width * numChannels,
height * numChannels);
@@ -414,7 +421,7 @@
final AffineTransform at = getTransform();
final double[] matrix = new double[PsUtil.MATRIX_QTY_ELEMENTS];
at.getMatrix(matrix);
- this.write("q");
+ this.saveGraphicsState();
final Shape imclip = getClip();
writeClip(imclip);
final String matrixString = matrixToString(matrix, QTY_ELEMENTS_CUBIC);
@@ -423,7 +430,7 @@
this.write("" + width + " 0 0 " + (-height) + " " + x
+ " " + (y + height) + " cm");
this.write("/" + this.xObject.getXObjectName() + " Do");
- this.write("Q");
+ this.restoreGraphicsState();
return true;
}
@@ -442,7 +449,7 @@
this.comment("%%%% End FOrayGraphic SVG-to-PDF conversion. %%%%");
pdfDoc = null;
currentStream = null;
- this.graphicsState = null;
+ this.graphicsStateStack = null;
}
/**
@@ -455,7 +462,7 @@
return;
}
- this.write("q");
+ this.saveGraphicsState();
final Shape imclip = getClip();
writeClip(imclip);
applyColor(c, false);
@@ -501,7 +508,7 @@
iter.next();
}
doDrawing(false, true, false);
- this.write("Q");
+ this.restoreGraphicsState();
}
/**
@@ -556,9 +563,9 @@
protected void applyColor(final Color color, final boolean fill) {
boolean anyChange = false;
if (fill) {
- anyChange = this.graphicsState.setFillColor(color);
+ anyChange = this.getGraphicsState().setFillColor(color);
} else {
- anyChange = this.graphicsState.setStrokeColor(color);
+ anyChange = this.getGraphicsState().setStrokeColor(color);
}
if (anyChange) {
this.write(PsColor.toPS(color, fill));
@@ -707,15 +714,15 @@
overrideFont = null;
}
- if (font != this.graphicsState.getFont()
- || (size != this.graphicsState.getFontSize())) {
- this.graphicsState.setFont(font);
- this.graphicsState.setFontSize(size);
+ if (font != this.getGraphicsState().getFont()
+ || (size != this.getGraphicsState().getFontSize())) {
+ this.getGraphicsState().setFont(font);
+ this.getGraphicsState().setFontSize(size);
final String fontName = this.pdfContext.getFontName(font);
this.write("/" + fontName + " " + size + " Tf");
}
- this.write("q");
+ this.saveGraphicsState();
final Shape imclip = getClip();
writeClip(imclip);
@@ -741,7 +748,7 @@
this.write(outputString);
this.write("ET");
- this.write("Q");
+ this.restoreGraphicsState();
}
/**
@@ -823,10 +830,10 @@
continue;
}
final float size = fontSize.floatValue();
- if ((font != this.graphicsState.getFont())
- || (size != this.graphicsState.getFontSize())) {
- this.graphicsState.setFont(font);
- this.graphicsState.setFontSize(size);
+ if ((font != this.getGraphicsState().getFont())
+ || (size != this.getGraphicsState().getFontSize())) {
+ this.getGraphicsState().setFont(font);
+ this.getGraphicsState().setFontSize(size);
final String fontName = this.pdfContext.getFontName(font);
this.write("/" + fontName + " " + size + " Tf");
}
@@ -850,7 +857,7 @@
return;
}
}
-// this.write("q");
+ this.saveGraphicsState();
final Shape imclip = getClip();
writeClip(imclip);
c = getColor();
@@ -893,7 +900,7 @@
}
doDrawing(true, false,
iter.getWindingRule() == PathIterator.WIND_EVEN_ODD);
-// this.write("Q");
+ this.restoreGraphicsState();
}
/**
@@ -1005,4 +1012,34 @@
return this.ioErrorFound;
}
+ /**
+ * Returns the current graphics state.
+ * @return The current graphics state.
+ */
+ private PDFGraphicsState getGraphicsState() {
+ return this.graphicsStateStack.peek();
+ }
+
+ /**
+ * Saves the current PDF graphics state by pushing it onto the stack,
+ * copying it, and making the copy the current graphics state.
+ */
+ private void saveGraphicsState() {
+ this.write("q");
+ /* Create a new state with the same settings as the current state. */
+ final PDFGraphicsState newState = new PDFGraphicsState(
+ this.getGraphicsState());
+ /* Push it onto the stack. */
+ this.graphicsStateStack.push(newState);
+ }
+
+ /**
+ * Restores the previously-saved PDF graphics state by popping the current
+ * one off of the stack.
+ */
+ private void restoreGraphicsState() {
+ this.write("Q");
+ this.graphicsStateStack.pop();
+ }
+
}
Modified: trunk/foray/foray-pdf/src/java/org/foray/pdf/PDFGraphicsState.java
===================================================================
--- trunk/foray/foray-pdf/src/java/org/foray/pdf/PDFGraphicsState.java 2007-06-22 19:40:12 UTC (rev 9834)
+++ trunk/foray/foray-pdf/src/java/org/foray/pdf/PDFGraphicsState.java 2007-06-22 20:42:39 UTC (rev 9835)
@@ -73,11 +73,30 @@
* Create a PDFGraphicsState instance.
*/
public PDFGraphicsState() {
- super();
reset();
}
/**
+ * Creates a new PDFGraphicsState instance, initilializing its values to
+ * those of an existing instance.
+ * @param existingState The instance whose values should be copied into the
+ * new instance.
+ */
+ public PDFGraphicsState(final PDFGraphicsState existingState) {
+ this.strokeColor = existingState.strokeColor;
+ this.fillColor = existingState.fillColor;
+ this.characterSpacing = existingState.characterSpacing;
+ this.wordSpacing = existingState.wordSpacing;
+ this.font = existingState.font;
+ this.fontSize = existingState.fontSize;
+ this.dashArray = new float[existingState.dashArray.length];
+ System.arraycopy(existingState.dashArray, 0, this.dashArray, 0,
+ existingState.dashArray.length);
+ this.dashPhase = existingState.dashPhase;
+ this.lineCapStyle = existingState.lineCapStyle;
+ }
+
+ /**
* Resets the Graphics State to its original state, as documented in
* PDF Reference, 3rd Edition, Section 4.3.
*/
@@ -88,7 +107,7 @@
this.wordSpacing = 0;
this.font = null;
this.fontSize = -1;
- this.dashArray = null;
+ this.dashArray = new float[0];
this.dashPhase = 0;
this.lineCapStyle = PDFLineCapStyle.BUTT_CAP;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2007-06-22 21:24:41
|
Revision: 9837
http://svn.sourceforge.net/foray/?rev=9837&view=rev
Author: victormote
Date: 2007-06-22 14:24:42 -0700 (Fri, 22 Jun 2007)
Log Message:
-----------
1. Conform to axsl changes removing the resetGraphicsState() method from PDFDocument.
2. Move management of the graphics state from the document to the content stream.
Modified Paths:
--------------
trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFContentStream.java
trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFDocument.java
trunk/foray/foray-render/src/java/org/foray/render/pdf/PDFRenderer.java
Modified: trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFContentStream.java
===================================================================
--- trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFContentStream.java 2007-06-22 20:59:07 UTC (rev 9836)
+++ trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFContentStream.java 2007-06-22 21:24:42 UTC (rev 9837)
@@ -49,7 +49,8 @@
public class PDFContentStream extends PDFStream
implements org.axsl.pdfW.PDFContentStream {
- /** The page this content stream is attached to. */
+ /** The current graphics state. */
+ private PDFGraphicsState currentGraphicsState = new PDFGraphicsState();
/** State variable indicating whether a text object is currently open. */
private boolean textObjectOpen = false;
@@ -67,7 +68,7 @@
* @return The graphic state.
*/
private PDFGraphicsState getGS() {
- return this.getPDFDocument().getCurrentGraphicsState();
+ return this.currentGraphicsState;
}
/**
Modified: trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFDocument.java
===================================================================
--- trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFDocument.java 2007-06-22 20:59:07 UTC (rev 9836)
+++ trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFDocument.java 2007-06-22 21:24:42 UTC (rev 9837)
@@ -36,8 +36,6 @@
package org.foray.pdf.object;
-import org.foray.pdf.PDFGraphicsState;
-
import org.axsl.fontR.Font;
import org.axsl.fontR.FontUse;
import org.axsl.pdfW.PDFPage;
@@ -136,9 +134,6 @@
/** The colorspace for this document. */
private ColorSpace colorspace = ColorSpace.getInstance(ColorSpace.CS_sRGB);
- /** The current graphic state for this document. */
- private PDFGraphicsState currentGraphicsState;
-
/** The counter for Pattern name numbering. */
private int lastPatternAssigned = 0;
@@ -222,9 +217,6 @@
this.info = new PDFInfo(this);
registerIndirectObjectLast(this.info);
- // Make the current Graphics State
- this.currentGraphicsState = new PDFGraphicsState();
-
this.defaultBorderStyle = new PDFBorderStyle(this, 0,
PDFBorderStyle.Style.SOLID);
}
@@ -586,14 +578,6 @@
}
/**
- * Return the graphics state associated with this document.
- * @return The graphics state.
- */
- public PDFGraphicsState getCurrentGraphicsState() {
- return this.currentGraphicsState;
- }
-
- /**
* If a PDFXObject has already been created for a given URL, return that
* PDFXObject so that it can be reused.
* @param url The URL for whom a PDFXObject is sought.
@@ -705,13 +689,6 @@
/**
* {@inheritDoc}
*/
- public void resetGraphicsState() {
- this.getCurrentGraphicsState().reset();
- }
-
- /**
- * {@inheritDoc}
- */
public PDFEncryption createPDFEncryption() {
if (this.encryption == null) {
this.encryption = new org.foray.pdf.object.PDFEncryption(this);
Modified: trunk/foray/foray-render/src/java/org/foray/render/pdf/PDFRenderer.java
===================================================================
--- trunk/foray/foray-render/src/java/org/foray/render/pdf/PDFRenderer.java 2007-06-22 20:59:07 UTC (rev 9836)
+++ trunk/foray/foray-render/src/java/org/foray/render/pdf/PDFRenderer.java 2007-06-22 21:24:42 UTC (rev 9837)
@@ -434,7 +434,6 @@
currentPage = this.pdfDoc.createPDFPage(
Math.round(w / WKConstants.MILLIPOINTS_PER_POINT),
Math.round(h / WKConstants.MILLIPOINTS_PER_POINT));
- this.getPDFDocument().resetGraphicsState();
renderRegions(page);
getContentStream().close();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2007-06-25 19:06:51
|
Revision: 9838
http://svn.sourceforge.net/foray/?rev=9838&view=rev
Author: victormote
Date: 2007-06-25 12:06:35 -0700 (Mon, 25 Jun 2007)
Log Message:
-----------
Conform to axsl changes throwing OutputException.
Modified Paths:
--------------
trunk/foray/foray-core/src/java/org/foray/core/FOrayTarget.java
trunk/foray/foray-mif/.classpath
trunk/foray/foray-mif/src/java/org/foray/mif/MifBook.java
trunk/foray/foray-output/src/java/org/foray/output/MIFConverter.java
trunk/foray/foray-render/src/java/org/foray/render/Renderer.java
trunk/foray/foray-render/src/java/org/foray/render/awt/AWTPrintRenderer.java
trunk/foray/foray-render/src/java/org/foray/render/awt/AWTRenderer.java
trunk/foray/foray-render/src/java/org/foray/render/pcl/PCLRenderer.java
trunk/foray/foray-render/src/java/org/foray/render/pdf/PDFRenderer.java
trunk/foray/foray-render/src/java/org/foray/render/ps/PSRenderer.java
trunk/foray/foray-render/src/java/org/foray/render/svg/SVGRenderer.java
trunk/foray/foray-render/src/java/org/foray/render/txt/TXTRenderer.java
trunk/foray/foray-render/src/java/org/foray/render/xml/XMLRenderer.java
Modified: trunk/foray/foray-core/src/java/org/foray/core/FOrayTarget.java
===================================================================
--- trunk/foray/foray-core/src/java/org/foray/core/FOrayTarget.java 2007-06-22 21:24:42 UTC (rev 9837)
+++ trunk/foray/foray-core/src/java/org/foray/core/FOrayTarget.java 2007-06-25 19:06:35 UTC (rev 9838)
@@ -30,7 +30,6 @@
import org.foray.common.WKConstants;
-import org.axsl.areaR.AreaRException;
import org.axsl.areaW.AreaTreeEvent;
import org.axsl.areaW.AreaTreeFactory;
import org.axsl.areaW.AreaTreeListener;
@@ -43,6 +42,7 @@
import org.axsl.layout.Layout;
import org.axsl.layout.LayoutException;
import org.axsl.layout.LayoutFactory;
+import org.axsl.output.OutputException;
import org.axsl.output.OutputTarget;
import org.axsl.output.Renderer;
import org.axsl.text.TextServer;
@@ -51,7 +51,6 @@
import org.xml.sax.SAXException;
-import java.io.IOException;
import java.io.OutputStream;
/**
@@ -193,7 +192,7 @@
startTime = System.currentTimeMillis();
try {
outputTarget.startOutput();
- } catch (final IOException e) {
+ } catch (final OutputException e) {
throw new FOrayException(e);
}
}
@@ -205,7 +204,7 @@
public void stopRenderer() throws SAXException {
try {
outputTarget.stopOutput();
- } catch (final IOException e) {
+ } catch (final OutputException e) {
throw new SAXException(e);
}
@@ -303,10 +302,8 @@
final Renderer renderer = (Renderer) this.outputTarget;
try {
renderer.render(page);
- } catch (final IOException e) {
+ } catch (final OutputException e) {
this.getLogger().error("Rendering error", e);
- } catch (final AreaRException e) {
- this.getLogger().error("Rendering error", e);
}
pageCount++;
}
Modified: trunk/foray/foray-mif/.classpath
===================================================================
--- trunk/foray/foray-mif/.classpath 2007-06-22 21:24:42 UTC (rev 9837)
+++ trunk/foray/foray-mif/.classpath 2007-06-25 19:06:35 UTC (rev 9838)
@@ -5,5 +5,6 @@
<classpathentry kind="src" path="/axslCommon"/>
<classpathentry combineaccessrules="false" kind="src" path="/FOrayCommon"/>
<classpathentry kind="lib" path="/FOray Lib/commons-logging-1.1.jar" sourcepath="/FOray Lib-Build/commons-logging/commons-logging-1.1-src.zip"/>
+ <classpathentry combineaccessrules="false" kind="src" path="/axslOutput"/>
<classpathentry kind="output" path="build/eclipse"/>
</classpath>
Modified: trunk/foray/foray-mif/src/java/org/foray/mif/MifBook.java
===================================================================
--- trunk/foray/foray-mif/src/java/org/foray/mif/MifBook.java 2007-06-22 21:24:42 UTC (rev 9837)
+++ trunk/foray/foray-mif/src/java/org/foray/mif/MifBook.java 2007-06-25 19:06:35 UTC (rev 9838)
@@ -28,6 +28,8 @@
package org.foray.mif;
+import org.axsl.output.OutputException;
+
import org.apache.commons.logging.Log;
import java.io.IOException;
@@ -145,11 +147,15 @@
/**
* Writes the content of this book to a given output stream.
* @param stream The stream to which the content should be written.
- * @throws IOException For I/O errors during writing.
+ * @throws OutputException For I/O errors during writing.
*/
- public void output(final OutputStream stream) throws IOException {
+ public void output(final OutputStream stream) throws OutputException {
// Output the contents of bookComponent
- stream.write(this.bookComponent.mifContent().getBytes());
+ try {
+ stream.write(this.bookComponent.mifContent().getBytes());
+ } catch (final IOException e) {
+ throw new OutputException(e);
+ }
}
/**
Modified: trunk/foray/foray-output/src/java/org/foray/output/MIFConverter.java
===================================================================
--- trunk/foray/foray-output/src/java/org/foray/output/MIFConverter.java 2007-06-22 21:24:42 UTC (rev 9837)
+++ trunk/foray/foray-output/src/java/org/foray/output/MIFConverter.java 2007-06-25 19:06:35 UTC (rev 9838)
@@ -38,6 +38,7 @@
import org.axsl.foR.fo.TableColumn;
import org.axsl.foR.fo.TableRow;
import org.axsl.fontR.FontConsumer;
+import org.axsl.output.OutputException;
import org.apache.commons.logging.Log;
@@ -241,7 +242,7 @@
/**
* {@inheritDoc}
*/
- public void startOutput() throws IOException {
+ public void startOutput() throws OutputException {
this.mifDoc = new MifBook(getLogger());
getLogger().info("rendering areas to MIF");
this.mifDoc.setDocumentHeightWidth(pageHeight, pageWidth);
@@ -250,10 +251,14 @@
/**
* {@inheritDoc}
*/
- public void stopOutput() throws IOException {
+ public void stopOutput() throws OutputException {
getLogger().info("writing out MIF");
this.mifDoc.output(this.getOutputStream());
- this.getOutputStream().flush();
+ try {
+ this.getOutputStream().flush();
+ } catch (final IOException e) {
+ throw new OutputException(e);
+ }
}
/**
Modified: trunk/foray/foray-render/src/java/org/foray/render/Renderer.java
===================================================================
--- trunk/foray/foray-render/src/java/org/foray/render/Renderer.java 2007-06-22 21:24:42 UTC (rev 9837)
+++ trunk/foray/foray-render/src/java/org/foray/render/Renderer.java 2007-06-25 19:06:35 UTC (rev 9838)
@@ -40,7 +40,6 @@
import org.axsl.areaR.Area;
import org.axsl.areaR.AreaNode;
-import org.axsl.areaR.AreaRException;
import org.axsl.areaR.AreaTree;
import org.axsl.areaR.BackgroundArea;
import org.axsl.areaR.BeforeFloatArea;
@@ -70,13 +69,13 @@
import org.axsl.graphicR.Graphic;
import org.axsl.graphicR.GraphicException;
import org.axsl.graphicR.SVGGraphic;
+import org.axsl.output.OutputException;
import org.apache.commons.logging.Log;
import java.awt.Color;
import java.awt.Rectangle;
import java.awt.geom.Rectangle2D;
-import java.io.IOException;
/**
* Abstract base class for all renderers.
@@ -118,13 +117,9 @@
}
/**
- * Renders the given page to the output stream for this renderer.
- * @param page The page to be rendered.
- * @throws IOException For I/O errors when writing to the output stream.
- * @throws AreaRException For inconsistencies in the AreaTree.
+ * {@inheritDoc}
*/
- public abstract void render(PageArea page) throws IOException,
- AreaRException;
+ public abstract void render(PageArea page) throws OutputException;
/**
* Marks the border, if any, for the given area.
Modified: trunk/foray/foray-render/src/java/org/foray/render/awt/AWTPrintRenderer.java
===================================================================
--- trunk/foray/foray-render/src/java/org/foray/render/awt/AWTPrintRenderer.java 2007-06-22 21:24:42 UTC (rev 9837)
+++ trunk/foray/foray-render/src/java/org/foray/render/awt/AWTPrintRenderer.java 2007-06-25 19:06:35 UTC (rev 9838)
@@ -31,12 +31,12 @@
import org.foray.output.OutputConfig;
import org.axsl.areaR.PageArea;
+import org.axsl.output.OutputException;
import org.apache.commons.logging.Log;
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;
-import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@@ -97,8 +97,7 @@
/**
* {@inheritDoc}
*/
- public void stopOutput()
- throws IOException {
+ public void stopOutput() throws OutputException {
super.stopOutput();
if (endNumber == -1) {
@@ -114,7 +113,7 @@
printerJob.print();
} catch (final PrinterException e) {
e.printStackTrace();
- throw new IOException(
+ throw new OutputException(
"Unable to print: " + e.getClass().getName() +
": " + e.getMessage());
}
Modified: trunk/foray/foray-render/src/java/org/foray/render/awt/AWTRenderer.java
===================================================================
--- trunk/foray/foray-render/src/java/org/foray/render/awt/AWTRenderer.java 2007-06-22 21:24:42 UTC (rev 9837)
+++ trunk/foray/foray-render/src/java/org/foray/render/awt/AWTRenderer.java 2007-06-25 19:06:35 UTC (rev 9838)
@@ -59,6 +59,7 @@
import org.axsl.fontR.FontUse;
import org.axsl.graphicR.Graphic;
import org.axsl.graphicR.SVGGraphic;
+import org.axsl.output.OutputException;
import org.apache.commons.logging.Log;
@@ -79,7 +80,6 @@
import java.awt.print.Paper;
import java.awt.print.Printable;
import java.awt.print.PrinterException;
-import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Vector;
@@ -389,7 +389,7 @@
try {
render(pageList.get(aPageNumber));
- } catch (final IOException e) {
+ } catch (final OutputException e) {
e.printStackTrace();
// This exception can't occur because we are not dealing with
// any files
@@ -400,7 +400,7 @@
/**
* {@inheritDoc}
*/
- public void render(final PageArea page) throws IOException {
+ public void render(final PageArea page) throws OutputException {
pageWidth = Math.round(toPoints(page.getWidth()));
pageHeight = Math.round(toPoints(page.getHeight()));
@@ -830,13 +830,13 @@
/**
* {@inheritDoc}
*/
- public void startOutput() throws IOException { }
+ public void startOutput() throws OutputException { }
/**
* {@inheritDoc}
*/
- public void stopOutput() throws IOException {
+ public void stopOutput() throws OutputException {
render(0);
}
Modified: trunk/foray/foray-render/src/java/org/foray/render/pcl/PCLRenderer.java
===================================================================
--- trunk/foray/foray-render/src/java/org/foray/render/pcl/PCLRenderer.java 2007-06-22 21:24:42 UTC (rev 9837)
+++ trunk/foray/foray-render/src/java/org/foray/render/pcl/PCLRenderer.java 2007-06-25 19:06:35 UTC (rev 9838)
@@ -53,6 +53,7 @@
import org.axsl.graphicR.Graphic;
import org.axsl.graphicR.GraphicException;
import org.axsl.graphicR.SVGGraphic;
+import org.axsl.output.OutputException;
import org.apache.commons.logging.Log;
@@ -715,8 +716,7 @@
/**
* {@inheritDoc}
*/
- public void startOutput()
- throws IOException {
+ public void startOutput() throws OutputException {
getLogger().info("rendering areas to PCL");
currentStream = new PCLStream(this.getOutputStream());
@@ -727,16 +727,19 @@
/**
* {@inheritDoc}
*/
- public void stopOutput()
- throws IOException {
+ public void stopOutput() throws OutputException {
getLogger().info("writing out PCL");
- this.getOutputStream().flush();
+ try {
+ this.getOutputStream().flush();
+ } catch (final IOException e) {
+ throw new OutputException(e);
+ }
}
/**
* {@inheritDoc}
*/
- public void render(final PageArea page) throws IOException {
+ public void render(final PageArea page) throws OutputException {
getLogger().debug("PCLRenderer.renderPage() page.Height() = "
+ page.getHeight());
Modified: trunk/foray/foray-render/src/java/org/foray/render/pdf/PDFRenderer.java
===================================================================
--- trunk/foray/foray-render/src/java/org/foray/render/pdf/PDFRenderer.java 2007-06-22 21:24:42 UTC (rev 9837)
+++ trunk/foray/foray-render/src/java/org/foray/render/pdf/PDFRenderer.java 2007-06-25 19:06:35 UTC (rev 9838)
@@ -39,7 +39,6 @@
import org.axsl.areaR.Area;
import org.axsl.areaR.AreaNode;
-import org.axsl.areaR.AreaRException;
import org.axsl.areaR.AreaTree;
import org.axsl.areaR.BookmarkArea;
import org.axsl.areaR.BookmarkTitleArea;
@@ -56,6 +55,7 @@
import org.axsl.graphicR.Graphic;
import org.axsl.graphicR.GraphicLink;
import org.axsl.graphicR.SVGGraphic;
+import org.axsl.output.OutputException;
import org.axsl.pdfW.PDFColor;
import org.axsl.pdfW.PDFContentStream;
import org.axsl.pdfW.PDFDocument;
@@ -150,7 +150,7 @@
/**
* {@inheritDoc}
*/
- public void startOutput() throws IOException {
+ public void startOutput() throws OutputException {
final String pdfVersion = this.getOptions().optionPDFVersion();
if (pdfVersion != null) {
final PDFVersion pdfVersionConstant = PDFVersion.fromString(
@@ -168,20 +168,28 @@
final String filter = (String) filters.get(i);
pdfDoc.addDefaultFilter(filter);
}
- pdfDoc.writeHeader();
+ try {
+ pdfDoc.writeHeader();
+ } catch (final IOException e) {
+ throw new OutputException(e);
+ }
}
/**
* {@inheritDoc}
*/
- public void stopOutput() throws IOException {
+ public void stopOutput() throws OutputException {
/*
* Render the nodes that are children of AreaTree instead of a
* PageCollection.
*/
renderDocumentNodes();
renderDocumentMetadata();
- pdfDoc.close();
+ try {
+ pdfDoc.close();
+ } catch (final IOException e) {
+ throw new OutputException(e);
+ }
// this frees up memory and makes the renderer reusable
this.pdfDoc = null;
@@ -427,7 +435,7 @@
/**
* Render page to PDF. {@inheritDoc}
*/
- public void render(final PageArea page) throws AreaRException, IOException {
+ public void render(final PageArea page) throws OutputException {
getLogger().debug("Rendering single page to PDF.");
final float w = page.getWidth();
final float h = page.getHeight();
@@ -439,7 +447,11 @@
renderDestinations(page);
getLogger().debug("Writing out PDF.");
- this.pdfDoc.writeIndirectObjects();
+ try {
+ this.pdfDoc.writeIndirectObjects();
+ } catch (final IOException e) {
+ throw new OutputException(e);
+ }
}
/**
Modified: trunk/foray/foray-render/src/java/org/foray/render/ps/PSRenderer.java
===================================================================
--- trunk/foray/foray-render/src/java/org/foray/render/ps/PSRenderer.java 2007-06-22 21:24:42 UTC (rev 9837)
+++ trunk/foray/foray-render/src/java/org/foray/render/ps/PSRenderer.java 2007-06-25 19:06:35 UTC (rev 9838)
@@ -58,6 +58,7 @@
import org.axsl.graphicR.Graphic;
import org.axsl.graphicR.GraphicException;
import org.axsl.graphicR.SVGGraphic;
+import org.axsl.output.OutputException;
import org.axsl.psR.Encoding;
import org.axsl.psR.EncodingVector;
@@ -1088,7 +1089,7 @@
/**
* {@inheritDoc}
*/
- public void startOutput() throws IOException {
+ public void startOutput() {
getLogger().debug("rendering areas to PostScript");
this.pagecount = 0;
@@ -1168,11 +1169,15 @@
/**
* {@inheritDoc}
*/
- public void stopOutput() throws IOException {
+ public void stopOutput() throws OutputException {
write("%%Trailer");
write("%%Pages: " + this.pagecount);
write("%%EOF");
- this.out.flush();
+ try {
+ this.out.flush();
+ } catch (final IOException e) {
+ throw new OutputException(e);
+ }
getLogger().debug("written out PostScript");
}
Modified: trunk/foray/foray-render/src/java/org/foray/render/svg/SVGRenderer.java
===================================================================
--- trunk/foray/foray-render/src/java/org/foray/render/svg/SVGRenderer.java 2007-06-22 21:24:42 UTC (rev 9837)
+++ trunk/foray/foray-render/src/java/org/foray/render/svg/SVGRenderer.java 2007-06-25 19:06:35 UTC (rev 9838)
@@ -50,6 +50,7 @@
import org.axsl.graphicR.GraphicException;
import org.axsl.graphicR.GraphicServer;
import org.axsl.graphicR.SVGGraphic;
+import org.axsl.output.OutputException;
import org.apache.commons.logging.Log;
@@ -251,7 +252,7 @@
/**
* {@inheritDoc}
*/
- public void render(final PageArea page) throws IOException {
+ public void render(final PageArea page) {
this.pageNumber++;
final int lastWidth = this.pageWidth;
final int lastHeight = this.pageHeight;
@@ -613,11 +614,11 @@
/**
* {@inheritDoc}
*/
- public void startOutput() throws IOException {
+ public void startOutput() throws OutputException {
try {
this.svgDocument = this.graphicServer.makeSvgDocument();
} catch (final GraphicException e) {
- throw new IOException(e.getMessage());
+ throw new OutputException(e.getMessage());
}
final ProcessingInstruction pi =
this.svgDocument.createProcessingInstruction(
@@ -630,12 +631,16 @@
/**
* {@inheritDoc}
*/
- public void stopOutput() throws IOException {
+ public void stopOutput() throws OutputException {
this.svgRoot.setAttributeNS(null, "width", "" + this.totalWidth);
this.svgRoot.setAttributeNS(null, "height", "" + this.totalHeight);
- this.graphicServer.writeSvgDocument(this.svgDocument,
- this.getOutputStream());
- this.getOutputStream().flush();
+ try {
+ this.graphicServer.writeSvgDocument(this.svgDocument,
+ this.getOutputStream());
+ this.getOutputStream().flush();
+ } catch (final IOException e) {
+ throw new OutputException(e);
+ }
this.svgDocument = null;
this.svgRoot = null;
Modified: trunk/foray/foray-render/src/java/org/foray/render/txt/TXTRenderer.java
===================================================================
--- trunk/foray/foray-render/src/java/org/foray/render/txt/TXTRenderer.java 2007-06-22 21:24:42 UTC (rev 9837)
+++ trunk/foray/foray-render/src/java/org/foray/render/txt/TXTRenderer.java 2007-06-25 19:06:35 UTC (rev 9838)
@@ -44,6 +44,7 @@
import org.axsl.graphicR.Graphic;
import org.axsl.graphicR.GraphicException;
import org.axsl.graphicR.SVGGraphic;
+import org.axsl.output.OutputException;
import org.apache.commons.logging.Log;
@@ -545,7 +546,7 @@
/**
* {@inheritDoc}
*/
- public void startOutput() throws IOException {
+ public void startOutput() {
getLogger().info("rendering areas to TEXT");
this.currentStream = new TXTStream(this.getOutputStream());
String encoding;
@@ -569,9 +570,13 @@
/**
* {@inheritDoc}
*/
- public void stopOutput() throws IOException {
+ public void stopOutput() throws OutputException {
getLogger().info("writing out TEXT");
- this.getOutputStream().flush();
+ try {
+ this.getOutputStream().flush();
+ } catch (final IOException e) {
+ throw new OutputException(e);
+ }
}
/**
Modified: trunk/foray/foray-render/src/java/org/foray/render/xml/XMLRenderer.java
===================================================================
--- trunk/foray/foray-render/src/java/org/foray/render/xml/XMLRenderer.java 2007-06-22 21:24:42 UTC (rev 9837)
+++ trunk/foray/foray-render/src/java/org/foray/render/xml/XMLRenderer.java 2007-06-25 19:06:35 UTC (rev 9838)
@@ -71,7 +71,6 @@
import java.awt.Color;
import java.awt.Rectangle;
-import java.io.IOException;
import java.io.PrintWriter;
/**
@@ -103,7 +102,7 @@
/**
* {@inheritDoc}
*/
- public void render(final PageArea page) throws IOException {
+ public void render(final PageArea page) {
final RegionBodyArea body = page.getRegionBody();
final RegionArea before = page.getRegionBefore();
final RegionArea after = page.getRegionAfter();
@@ -546,7 +545,7 @@
/**
* {@inheritDoc}
*/
- public void startOutput() throws IOException {
+ public void startOutput() {
getLogger().debug("rendering areas to XML");
this.writer = new PrintWriter(this.getOutputStream());
final StringBuilder buffer = new StringBuilder();
@@ -566,7 +565,7 @@
/**
* {@inheritDoc}
*/
- public void stopOutput() throws IOException {
+ public void stopOutput() {
this.writer.write("</area-tree>");
this.writer.flush();
getLogger().debug("written out XML");
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2007-06-25 19:42:18
|
Revision: 9839
http://svn.sourceforge.net/foray/?rev=9839&view=rev
Author: victormote
Date: 2007-06-25 12:42:10 -0700 (Mon, 25 Jun 2007)
Log Message:
-----------
Conform to axsl changes throwing the more general PDFException.
Modified Paths:
--------------
trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFCMap.java
trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFDocument.java
trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFFontFileStream.java
trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFICCStream.java
trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFObject.java
trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFStream.java
trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFXForm.java
trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFXImage.java
trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFXObject.java
trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFXPostScript.java
trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFXReference.java
trunk/foray/foray-render/src/java/org/foray/render/pdf/PDFRenderer.java
Modified: trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFCMap.java
===================================================================
--- trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFCMap.java 2007-06-25 19:06:35 UTC (rev 9838)
+++ trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFCMap.java 2007-06-25 19:42:10 UTC (rev 9839)
@@ -28,7 +28,8 @@
package org.foray.pdf.object;
-import java.io.IOException;
+import org.axsl.pdfW.PDFException;
+
import java.io.OutputStream;
/**
@@ -227,7 +228,7 @@
/**
* {@inheritDoc}
*/
- protected int output(final OutputStream stream) throws IOException {
+ protected int output(final OutputStream stream) throws PDFException {
fillInPDF(new StringBuilder());
return super.output(stream);
}
Modified: trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFDocument.java
===================================================================
--- trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFDocument.java 2007-06-25 19:06:35 UTC (rev 9838)
+++ trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFDocument.java 2007-06-25 19:42:10 UTC (rev 9839)
@@ -38,6 +38,7 @@
import org.axsl.fontR.Font;
import org.axsl.fontR.FontUse;
+import org.axsl.pdfW.PDFException;
import org.axsl.pdfW.PDFPage;
import org.axsl.pdfW.PDFVersion;
import org.axsl.psR.Encoding;
@@ -281,7 +282,7 @@
/**
* {@inheritDoc}
*/
- public void writeIndirectObjects() throws IOException {
+ public void writeIndirectObjects() throws PDFException {
/*
* Use a "while" loop here, because as each object is written, it has
* potential to reference another object indirectly, which will add an
@@ -322,7 +323,7 @@
/**
* {@inheritDoc}
*/
- public void writeHeader() throws IOException {
+ public void writeHeader() throws PDFException {
this.position = 0;
final StringBuilder buffer = new StringBuilder();
// The PDF identifier comment.
@@ -330,22 +331,26 @@
+ PDFObject.EOL);
buffer.append("%" + BINARY_COMMENT + PDFObject.EOL);
final byte[] bytes = PDFObject.bufferToByteArray(buffer);
- this.outputStream.write(bytes);
+ try {
+ this.outputStream.write(bytes);
+ } catch (final IOException e) {
+ throw new PDFException(e);
+ }
this.position += bytes.length;
}
/**
* {@inheritDoc}
*/
- public void close() throws IOException {
+ public void close() throws PDFException {
outputTrailer();
}
/**
* Write the document trailer.
- * @throws IOException For errors while writing to the output stream.
+ * @throws PDFException For errors while writing to the output stream.
*/
- private void outputTrailer() throws IOException {
+ private void outputTrailer() throws PDFException {
writeIndirectObjects();
for (int i = 0; i < indirectObjectsLast.size(); i++) {
final PDFObject o = indirectObjectsLast.get(i);
@@ -360,7 +365,11 @@
/* output the xref table and increment the character position
by the table's length */
- this.position += outputXref(this.outputStream);
+ try {
+ this.position += outputXref(this.outputStream);
+ } catch (final IOException e) {
+ throw new PDFException(e);
+ }
/* construct the trailer */
final StringBuilder buffer = new StringBuilder();
@@ -376,7 +385,11 @@
} catch (final UnsupportedEncodingException ue) {
trailer = buffer.toString().getBytes();
}
- this.outputStream.write(trailer);
+ try {
+ this.outputStream.write(trailer);
+ } catch (final IOException e) {
+ throw new PDFException(e);
+ }
}
/**
Modified: trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFFontFileStream.java
===================================================================
--- trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFFontFileStream.java 2007-06-25 19:06:35 UTC (rev 9838)
+++ trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFFontFileStream.java 2007-06-25 19:42:10 UTC (rev 9839)
@@ -32,7 +32,6 @@
import org.axsl.fontR.output.FontPDF;
import org.axsl.pdfW.PDFException;
-import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
@@ -63,20 +62,14 @@
/* The first filter specified is the last one applied. */
addFilter("ascii-85");
addFilter("flate");
- try {
- setData(fontFileStream);
- } catch (final IOException ioe) {
- getPDFDocument().getLogger().error("Failed to embed font "
- + font.getFont().getPostscriptName() + ": "
- + ioe.getMessage());
- }
+ setData(fontFileStream);
}
/**
* {@inheritDoc}
*/
@Override
- protected int output(final OutputStream stream) throws IOException {
+ protected int output(final OutputStream stream) throws PDFException {
final FontPDF fontPDF = (FontPDF) font.getFontOutput("application/pdf");
int length = 0;
final String filterEntry = applyFilters();
@@ -95,7 +88,7 @@
p = preData.getBytes();
}
- stream.write(p);
+ this.byteArrayToStream(p, stream);
length += p.length;
length += outputStreamData(stream);
@@ -104,7 +97,7 @@
} catch (final UnsupportedEncodingException ue) {
p = ("endobj" + EOL).getBytes();
}
- stream.write(p);
+ this.byteArrayToStream(p, stream);
length += p.length;
return length;
}
Modified: trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFICCStream.java
===================================================================
--- trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFICCStream.java 2007-06-25 19:06:35 UTC (rev 9838)
+++ trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFICCStream.java 2007-06-25 19:42:10 UTC (rev 9839)
@@ -28,8 +28,9 @@
package org.foray.pdf.object;
+import org.axsl.pdfW.PDFException;
+
import java.awt.color.ICC_ColorSpace;
-import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
@@ -57,7 +58,7 @@
* around so much.
*/
@Override
- protected int output(final OutputStream stream) throws IOException {
+ protected int output(final OutputStream stream) throws PDFException {
int length = 0;
setData(cs.getProfile().getData());
final String filterEntry = applyFilters();
@@ -85,7 +86,7 @@
} catch (final UnsupportedEncodingException ue) {
p = pb.toString().getBytes();
}
- stream.write(p);
+ this.byteArrayToStream(p, stream);
length += p.length;
length += outputStreamData(stream);
try {
@@ -93,7 +94,7 @@
} catch (final UnsupportedEncodingException ue) {
p = ("endobj" + EOL).getBytes();
}
- stream.write(p);
+ this.byteArrayToStream(p, stream);
length += p.length;
return length;
}
Modified: trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFObject.java
===================================================================
--- trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFObject.java 2007-06-25 19:06:35 UTC (rev 9838)
+++ trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFObject.java 2007-06-25 19:42:10 UTC (rev 9839)
@@ -30,6 +30,8 @@
import org.foray.common.WKConstants;
+import org.axsl.pdfW.PDFException;
+
import org.apache.commons.logging.Log;
import java.io.IOException;
@@ -122,15 +124,19 @@
* Write the PDF represention of this object to a given output stream.
* @param stream The stream to which the PDF content is being written.
* @return The number of bytes written.
- * @throws IOException For I/O errors during output.
+ * @throws PDFException For I/O errors during output.
*/
- protected int output(final OutputStream stream) throws IOException {
+ protected int output(final OutputStream stream) throws PDFException {
final String pdf = this.toPDF();
if (pdf == null) {
return 0;
}
final byte[] bytes = PDFObject.stringToByteArray(pdf);
- stream.write(bytes);
+ try {
+ stream.write(bytes);
+ } catch (final IOException e) {
+ throw new PDFException(e);
+ }
return bytes.length;
}
@@ -182,6 +188,21 @@
}
/**
+ * Writes the content of a byte array to an output stream.
+ * @param stream The stream to which the array should be written.
+ * @param bytes The array to be written.
+ * @throws PDFException For IO errors during output.
+ */
+ protected void byteArrayToStream(final byte[] bytes,
+ final OutputStream stream) throws PDFException {
+ try {
+ stream.write(bytes);
+ } catch (final IOException e) {
+ throw new PDFException(e);
+ }
+ }
+
+ /**
* Returns the logger to be used for user messages.
* @return The logger.
*/
Modified: trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFStream.java
===================================================================
--- trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFStream.java 2007-06-25 19:06:35 UTC (rev 9838)
+++ trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFStream.java 2007-06-25 19:42:10 UTC (rev 9839)
@@ -187,14 +187,18 @@
/**
* Writes some data to this stream.
* @param data The data to be written.
- * @throws IOException For errors when writing.
+ * @throws PDFException For errors when writing.
*/
- public void setData(final byte[] data) throws IOException {
+ public void setData(final byte[] data) throws PDFException {
if (data == null) {
return;
}
this.filtersLocked = true;
- out.write(data);
+ try {
+ out.write(data);
+ } catch (final IOException e) {
+ throw new PDFException(e);
+ }
this.bytesWritten += data.length;
}
@@ -217,7 +221,7 @@
* {@inheritDoc}
*/
@Override
- protected int output(final OutputStream stream) throws IOException {
+ protected int output(final OutputStream stream) throws PDFException {
int length = 0;
final String filterEntry = applyFilters();
final String s = this.pdfID() + EOL
@@ -231,7 +235,7 @@
} catch (final UnsupportedEncodingException ue) {
p = s.getBytes();
}
- stream.write(p);
+ byteArrayToStream(p, stream);
length += p.length;
length += outputStreamData(stream);
try {
@@ -239,7 +243,7 @@
} catch (final UnsupportedEncodingException ue) {
p = ("endobj" + EOL).getBytes();
}
- stream.write(p);
+ byteArrayToStream(p, stream);
length += p.length;
return length;
@@ -249,10 +253,10 @@
* Output just the stream data enclosed by stream/endstream markers.
* @param stream The stream to which the data should be written.
* @return The number of bytes written.
- * @throws IOException For errors during writing.
+ * @throws PDFException For errors during writing.
*/
protected int outputStreamData(final OutputStream stream)
- throws IOException {
+ throws PDFException {
int length = 0;
byte[] p;
try {
@@ -260,18 +264,22 @@
} catch (final UnsupportedEncodingException ue) {
p = ("stream" + EOL).getBytes();
}
- stream.write(p);
+ byteArrayToStream(p, stream);
length += p.length;
- out.flush();
- out.close();
- streamData.writeTo(stream);
+ try {
+ out.flush();
+ out.close();
+ streamData.writeTo(stream);
+ } catch (final IOException e) {
+ throw new PDFException(e);
+ }
length += streamData.size();
try {
p = (EOL + "endstream" + EOL).getBytes(PDFDocument.ENCODING);
} catch (final UnsupportedEncodingException ue) {
p = (EOL + "endstream" + EOL).getBytes();
}
- stream.write(p);
+ byteArrayToStream(p, stream);
length += p.length;
return length;
}
@@ -279,9 +287,8 @@
/**
* Apply the filters to the data in the order given.
* @return The /Filter and /DecodeParms entries for the stream dictionary.
- * @throws IOException For errors during output.
*/
- protected String applyFilters() throws IOException {
+ protected String applyFilters() {
if (filters.size() < 1) {
return "";
}
Modified: trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFXForm.java
===================================================================
--- trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFXForm.java 2007-06-25 19:06:35 UTC (rev 9838)
+++ trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFXForm.java 2007-06-25 19:42:10 UTC (rev 9839)
@@ -35,6 +35,7 @@
import org.axsl.graphicR.Graphic;
import org.axsl.graphicR.GraphicException;
+import org.axsl.pdfW.PDFException;
import java.awt.geom.Rectangle2D;
import java.io.File;
@@ -69,8 +70,7 @@
/**
* {@inheritDoc}
*/
- protected void xObjectContent(final PDFStream stream)
- throws GraphicException, IOException {
+ protected void xObjectContent(final PDFStream stream) throws PDFException {
if (getGraphic().getGraphicType() == Graphic.Type.EPS) {
byte[] bytes = null;
try {
Modified: trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFXImage.java
===================================================================
--- trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFXImage.java 2007-06-25 19:06:35 UTC (rev 9838)
+++ trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFXImage.java 2007-06-25 19:42:10 UTC (rev 9839)
@@ -42,7 +42,6 @@
import java.awt.color.ColorSpace;
import java.awt.color.ICC_ColorSpace;
import java.awt.geom.Rectangle2D;
-import java.io.IOException;
/**
* A sampled image that is to be embedded in a PDF File. Images in PDF are
@@ -93,16 +92,21 @@
/**
* {@inheritDoc}
*/
- protected void xObjectContent(final PDFStream stream)
- throws GraphicException, IOException {
- if (getGraphic().getGraphicType() == Graphic.Type.JPEG
- || getGraphic().getGraphicType() == Graphic.Type.TIFF) {
- /* JPEG is natively compressed using DTD, so use its raw content.
- * TIFF is currently presumed to be compressed natively also, and
- * an appropriate filter has been added for that compression. */
- stream.setData(getGraphic().getRawSamples());
- } else {
- stream.setData(getGraphic().getContent());
+ protected void xObjectContent(final PDFStream stream) throws PDFException {
+ try {
+ if (getGraphic().getGraphicType() == Graphic.Type.JPEG
+ || getGraphic().getGraphicType() == Graphic.Type.TIFF) {
+ /* JPEG is natively compressed using DTD, so use its raw
+ * content.
+ * TIFF is currently presumed to be compressed natively also,
+ * and an appropriate filter has been added for that
+ * compression. */
+ stream.setData(getGraphic().getRawSamples());
+ } else {
+ stream.setData(getGraphic().getContent());
+ }
+ } catch (final GraphicException e) {
+ throw new PDFException(e);
}
}
Modified: trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFXObject.java
===================================================================
--- trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFXObject.java 2007-06-25 19:06:35 UTC (rev 9838)
+++ trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFXObject.java 2007-06-25 19:42:10 UTC (rev 9839)
@@ -43,7 +43,6 @@
import org.axsl.pdfW.PDFException;
import java.awt.geom.Rectangle2D;
-import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
@@ -168,11 +167,11 @@
/**
* Add the content specific to this type of XObject to the content stream.
* @param stream The Streaim into which the content should be written.
- * @throws GraphicException For errors in the graphic itself.
- * @throws IOException For errors writing to the stream.
+ * @throws PDFException For errors in the graphic or when writing to the
+ * stream.
*/
protected abstract void xObjectContent(PDFStream stream)
- throws GraphicException, IOException;
+ throws PDFException;
/**
* Returns the dictionary entries for this XObject.
@@ -248,16 +247,12 @@
* Writes this object to an output stream.
* @param stream The stream to which this object should be written.
* @return The number of bytes written ??
- * @throws IOException For I/O errors during output.
+ * @throws PDFException For I/O errors during output.
*/
- protected int output(final OutputStream stream) throws IOException {
+ protected int output(final OutputStream stream) throws PDFException {
int length = 0;
addStreamFilters(pdfStream);
- try {
- this.xObjectContent(pdfStream);
- } catch (final GraphicException e) {
- getLogger().error("Error in XObject:" + MSG_EOL + e.getMessage());
- }
+ this.xObjectContent(pdfStream);
final String dictEntries = pdfStream.applyFilters();
String p = this.pdfID() + EOL;
@@ -278,7 +273,7 @@
} catch (final UnsupportedEncodingException ue) {
pdfBytes = p.getBytes();
}
- stream.write(pdfBytes);
+ this.byteArrayToStream(pdfBytes, stream);
length += pdfBytes.length;
length += writeStream(stream);
@@ -287,7 +282,7 @@
} catch (final UnsupportedEncodingException ue) {
pdfBytes = ("endobj" + EOL).getBytes();
}
- stream.write(pdfBytes);
+ this.byteArrayToStream(pdfBytes, stream);
length += pdfBytes.length;
return length;
}
@@ -296,9 +291,9 @@
* Write this object to an output stream.
* @param stream the stream to which this object should be written.
* @return The number of bytes written ??
- * @throws IOException For errors writing the graphic.
+ * @throws PDFException For errors writing the graphic.
*/
- protected int writeStream(final OutputStream stream) throws IOException {
+ protected int writeStream(final OutputStream stream) throws PDFException {
/* Push all the image data on the writer and takes care of
* length for trailer. */
return pdfStream.outputStreamData(stream);
Modified: trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFXPostScript.java
===================================================================
--- trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFXPostScript.java 2007-06-25 19:06:35 UTC (rev 9838)
+++ trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFXPostScript.java 2007-06-25 19:42:10 UTC (rev 9839)
@@ -33,9 +33,9 @@
import org.axsl.graphicR.EPSGraphic;
import org.axsl.graphicR.Graphic;
import org.axsl.graphicR.GraphicException;
+import org.axsl.pdfW.PDFException;
import java.awt.geom.Rectangle2D;
-import java.io.IOException;
import java.io.UnsupportedEncodingException;
/**
@@ -70,9 +70,13 @@
/**
* {@inheritDoc}
*/
- protected void xObjectContent(final PDFStream stream)
- throws GraphicException, IOException {
- final byte[] imgData = epsToPDFXObject((EPSGraphic) getGraphic());
+ protected void xObjectContent(final PDFStream stream) throws PDFException {
+ byte[] imgData;
+ try {
+ imgData = epsToPDFXObject((EPSGraphic) getGraphic());
+ } catch (final GraphicException e) {
+ throw new PDFException(e);
+ }
stream.setData(imgData);
}
Modified: trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFXReference.java
===================================================================
--- trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFXReference.java 2007-06-25 19:06:35 UTC (rev 9838)
+++ trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFXReference.java 2007-06-25 19:42:10 UTC (rev 9839)
@@ -30,9 +30,9 @@
import org.axsl.graphicR.Graphic;
import org.axsl.graphicR.GraphicException;
+import org.axsl.pdfW.PDFException;
import java.awt.geom.Rectangle2D;
-import java.io.IOException;
import java.io.OutputStream;
/**
@@ -59,9 +59,12 @@
* {@inheritDoc}
*/
@Override
- protected void xObjectContent(final PDFStream stream)
- throws GraphicException, IOException {
- stream.setData(getGraphic().getContent());
+ protected void xObjectContent(final PDFStream stream) throws PDFException {
+ try {
+ stream.setData(getGraphic().getContent());
+ } catch (final GraphicException e) {
+ throw new PDFException(e);
+ }
}
/**
@@ -78,7 +81,7 @@
* {@inheritDoc}
*/
@Override
- protected int writeStream(final OutputStream stream) throws IOException {
+ protected int writeStream(final OutputStream stream) throws PDFException {
/* Don't write the related stream here. It needs to be an independent
* object. */
return 0;
Modified: trunk/foray/foray-render/src/java/org/foray/render/pdf/PDFRenderer.java
===================================================================
--- trunk/foray/foray-render/src/java/org/foray/render/pdf/PDFRenderer.java 2007-06-25 19:06:35 UTC (rev 9838)
+++ trunk/foray/foray-render/src/java/org/foray/render/pdf/PDFRenderer.java 2007-06-25 19:42:10 UTC (rev 9839)
@@ -60,6 +60,7 @@
import org.axsl.pdfW.PDFContentStream;
import org.axsl.pdfW.PDFDocument;
import org.axsl.pdfW.PDFEncryption;
+import org.axsl.pdfW.PDFException;
import org.axsl.pdfW.PDFExplicitDestination;
import org.axsl.pdfW.PDFLineCapStyle;
import org.axsl.pdfW.PDFOutlineItem;
@@ -75,7 +76,6 @@
import java.awt.Shape;
import java.awt.geom.Line2D;
import java.awt.geom.Rectangle2D;
-import java.io.IOException;
import java.net.URI;
import java.util.Date;
import java.util.List;
@@ -170,7 +170,7 @@
}
try {
pdfDoc.writeHeader();
- } catch (final IOException e) {
+ } catch (final PDFException e) {
throw new OutputException(e);
}
}
@@ -187,7 +187,7 @@
renderDocumentMetadata();
try {
pdfDoc.close();
- } catch (final IOException e) {
+ } catch (final PDFException e) {
throw new OutputException(e);
}
@@ -449,7 +449,7 @@
getLogger().debug("Writing out PDF.");
try {
this.pdfDoc.writeIndirectObjects();
- } catch (final IOException e) {
+ } catch (final PDFException e) {
throw new OutputException(e);
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2007-06-25 20:16:50
|
Revision: 9841
http://svn.sourceforge.net/foray/?rev=9841&view=rev
Author: victormote
Date: 2007-06-25 13:16:52 -0700 (Mon, 25 Jun 2007)
Log Message:
-----------
Use the static methods instead of creating a PDFString instance.
Modified Paths:
--------------
trunk/foray/foray-graphic/src/java/org/foray/graphic/batik/PDFGraphics2D.java
trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFContentStream.java
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-25 19:57:33 UTC (rev 9840)
+++ trunk/foray/foray-graphic/src/java/org/foray/graphic/batik/PDFGraphics2D.java 2007-06-25 20:16:52 UTC (rev 9841)
@@ -742,9 +742,7 @@
this.write(matrixString + "cm");
this.write("1 0 0 -1 0 0 Tm ");
- final PDFString pdfString = new PDFString(this.pdfDoc, s, font,
- true);
- final String outputString = pdfString.toPDF();
+ final String outputString = PDFString.textToPdf(s, font, true);
this.write(outputString);
this.write("ET");
Modified: trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFContentStream.java
===================================================================
--- trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFContentStream.java 2007-06-25 19:57:33 UTC (rev 9840)
+++ trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFContentStream.java 2007-06-25 20:16:52 UTC (rev 9841)
@@ -116,9 +116,9 @@
return;
}
openTextObject();
- final PDFString pdfString = new PDFString(this.getPDFDocument(), text,
+ final String stringOut = PDFString.textToPdf(text,
this.getGS().getFont(), kern);
- add(pdfString.toPDF());
+ add(stringOut);
}
/**
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2007-06-25 20:47:39
|
Revision: 9842
http://svn.sourceforge.net/foray/?rev=9842&view=rev
Author: victormote
Date: 2007-06-25 13:47:40 -0700 (Mon, 25 Jun 2007)
Log Message:
-----------
Conform to axsl changes replacing "thickness" parameter with a new method setLineWidth.
Modified Paths:
--------------
trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFContentStream.java
trunk/foray/foray-render/src/java/org/foray/render/pdf/PDFRenderer.java
Modified: trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFContentStream.java
===================================================================
--- trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFContentStream.java 2007-06-25 20:16:52 UTC (rev 9841)
+++ trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFContentStream.java 2007-06-25 20:47:40 UTC (rev 9842)
@@ -213,16 +213,15 @@
/**
* {@inheritDoc}
*/
- public void drawLine(final Line2D.Float line, final float thickness,
- final float[] dashArray, final float dashPhase,
- final PDFPathPaint stroke) {
+ public void drawLine(final Line2D.Float line, final float[] dashArray,
+ final float dashPhase, final PDFPathPaint stroke) {
closeTextObject();
add("q" + EOL);
add(stroke.getSetterString(false));
setLineDashPattern(dashArray, dashPhase);
add(line.x1 + " " + line.y1 + " m" + EOL);
add(line.x2 + " " + line.y2 + " l" + EOL);
- add(thickness + " w S" + EOL);
+ add("S" + EOL);
add("Q" + EOL);
}
@@ -370,4 +369,11 @@
add("h W n" + EOL);
}
+ /**
+ * {@inheritDoc}
+ */
+ public void setLineWidth(final float width) {
+ add(width + " w" + EOL);
+ }
+
}
Modified: trunk/foray/foray-render/src/java/org/foray/render/pdf/PDFRenderer.java
===================================================================
--- trunk/foray/foray-render/src/java/org/foray/render/pdf/PDFRenderer.java 2007-06-25 20:16:52 UTC (rev 9841)
+++ trunk/foray/foray-render/src/java/org/foray/render/pdf/PDFRenderer.java 2007-06-25 20:47:40 UTC (rev 9842)
@@ -219,8 +219,8 @@
toPoints(startY), toPoints(endX), toPoints(endY));
getContentStream().setLineCapStyle(
PDFLineCapStyle.PROJECTING_SQUARE_CAP);
- getContentStream().drawLine(line, toPoints(thickness), dashPattern, 0,
- pdfColor);
+ getContentStream().setLineWidth(toPoints(thickness));
+ getContentStream().drawLine(line, dashPattern, 0, pdfColor);
}
/**
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2007-06-25 20:58:51
|
Revision: 9843
http://svn.sourceforge.net/foray/?rev=9843&view=rev
Author: victormote
Date: 2007-06-25 13:58:52 -0700 (Mon, 25 Jun 2007)
Log Message:
-----------
Conform to axsl changes replacing dash-pattern-related parameters with a new method setDashPattern.
Modified Paths:
--------------
trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFContentStream.java
trunk/foray/foray-render/src/java/org/foray/render/pdf/PDFRenderer.java
Modified: trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFContentStream.java
===================================================================
--- trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFContentStream.java 2007-06-25 20:47:40 UTC (rev 9842)
+++ trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFContentStream.java 2007-06-25 20:58:52 UTC (rev 9843)
@@ -177,29 +177,6 @@
}
/**
- * Sets the line dash pattern value.
- * @param dashArray The dash array to set.
- * @param dashPhase The dash phase to set.
- */
- public void setLineDashPattern(final float[] dashArray,
- final float dashPhase) {
- if (! this.getGS().setLineDashPattern(dashArray, dashPhase)) {
- // Nothing needs to change.
- return;
- }
- add("[");
- if (dashArray != null) {
- for (int i = 0; i < dashArray.length; i++) {
- if (i != 0) {
- add(" ");
- }
- add(Float.toString(dashArray[i]));
- }
- }
- add("] " + dashPhase + " d" + EOL);
- }
-
- /**
* {@inheritDoc}
*/
public void setLineCapStyle(final PDFLineCapStyle newLineCapStyle) {
@@ -213,12 +190,10 @@
/**
* {@inheritDoc}
*/
- public void drawLine(final Line2D.Float line, final float[] dashArray,
- final float dashPhase, final PDFPathPaint stroke) {
+ public void drawLine(final Line2D.Float line, final PDFPathPaint stroke) {
closeTextObject();
add("q" + EOL);
add(stroke.getSetterString(false));
- setLineDashPattern(dashArray, dashPhase);
add(line.x1 + " " + line.y1 + " m" + EOL);
add(line.x2 + " " + line.y2 + " l" + EOL);
add("S" + EOL);
@@ -376,4 +351,24 @@
add(width + " w" + EOL);
}
+ /**
+ * {@inheritDoc}
+ */
+ public void setDashPattern(final float[] dashArray, final float dashPhase) {
+ if (! this.getGS().setLineDashPattern(dashArray, dashPhase)) {
+ // Nothing needs to change.
+ return;
+ }
+ add("[");
+ if (dashArray != null) {
+ for (int i = 0; i < dashArray.length; i++) {
+ if (i != 0) {
+ add(" ");
+ }
+ add(Float.toString(dashArray[i]));
+ }
+ }
+ add("] " + dashPhase + " d" + EOL);
+ }
+
}
Modified: trunk/foray/foray-render/src/java/org/foray/render/pdf/PDFRenderer.java
===================================================================
--- trunk/foray/foray-render/src/java/org/foray/render/pdf/PDFRenderer.java 2007-06-25 20:47:40 UTC (rev 9842)
+++ trunk/foray/foray-render/src/java/org/foray/render/pdf/PDFRenderer.java 2007-06-25 20:58:52 UTC (rev 9843)
@@ -204,23 +204,24 @@
final Color strokeColor) {
final PDFColor pdfColor = this.getPDFDocument().createPDFColor(
strokeColor);
- float[] dashPattern;
+ float[] dashArray;
switch (ruleStyle) {
case DASHED:
- dashPattern = DASHPATTERN_DASHED;
+ dashArray = DASHPATTERN_DASHED;
break;
case DOTTED:
- dashPattern = DASHPATTERN_DOTTED;
+ dashArray = DASHPATTERN_DOTTED;
break;
default:
- dashPattern = null;
+ dashArray = null;
}
final Line2D.Float line = new Line2D.Float(toPoints(startX),
toPoints(startY), toPoints(endX), toPoints(endY));
getContentStream().setLineCapStyle(
PDFLineCapStyle.PROJECTING_SQUARE_CAP);
getContentStream().setLineWidth(toPoints(thickness));
- getContentStream().drawLine(line, dashPattern, 0, pdfColor);
+ getContentStream().setDashPattern(dashArray, 0);
+ getContentStream().drawLine(line, pdfColor);
}
/**
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2007-06-26 18:36:29
|
Revision: 9845
http://svn.sourceforge.net/foray/?rev=9845&view=rev
Author: victormote
Date: 2007-06-26 11:36:31 -0700 (Tue, 26 Jun 2007)
Log Message:
-----------
Conform to axsl changes removing parameter from the method for drawing a line.
Modified Paths:
--------------
trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFContentStream.java
trunk/foray/foray-render/src/java/org/foray/render/pdf/PDFRenderer.java
Modified: trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFContentStream.java
===================================================================
--- trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFContentStream.java 2007-06-26 16:32:17 UTC (rev 9844)
+++ trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFContentStream.java 2007-06-26 18:36:31 UTC (rev 9845)
@@ -256,10 +256,9 @@
/**
* {@inheritDoc}
*/
- public void drawLine(final Line2D.Float line, final PDFPathPaint stroke) {
+ public void drawLine(final Line2D.Float line) {
closeTextObject();
add("q" + EOL);
- add(stroke.getSetterString(false));
add(line.x1 + " " + line.y1 + " m" + EOL);
add(line.x2 + " " + line.y2 + " l" + EOL);
add("S" + EOL);
Modified: trunk/foray/foray-render/src/java/org/foray/render/pdf/PDFRenderer.java
===================================================================
--- trunk/foray/foray-render/src/java/org/foray/render/pdf/PDFRenderer.java 2007-06-26 16:32:17 UTC (rev 9844)
+++ trunk/foray/foray-render/src/java/org/foray/render/pdf/PDFRenderer.java 2007-06-26 18:36:31 UTC (rev 9845)
@@ -56,7 +56,6 @@
import org.axsl.graphicR.GraphicLink;
import org.axsl.graphicR.SVGGraphic;
import org.axsl.output.OutputException;
-import org.axsl.pdfW.PDFColor;
import org.axsl.pdfW.PDFContentStream;
import org.axsl.pdfW.PDFDocument;
import org.axsl.pdfW.PDFEncryption;
@@ -202,8 +201,6 @@
protected void drawLine(final int startX, final int startY, final int endX,
final int endY, final int thickness, final RuleStyle ruleStyle,
final Color strokeColor) {
- final PDFColor pdfColor = this.getPDFDocument().createPDFColor(
- strokeColor);
float[] dashArray;
switch (ruleStyle) {
case DASHED:
@@ -221,7 +218,8 @@
PDFLineCapStyle.PROJECTING_SQUARE_CAP);
getContentStream().setLineWidth(toPoints(thickness));
getContentStream().setDashPattern(dashArray, 0);
- getContentStream().drawLine(line, pdfColor);
+ getContentStream().setStrokeColor(strokeColor);
+ getContentStream().drawLine(line);
}
/**
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2007-06-26 18:47:01
|
Revision: 9846
http://svn.sourceforge.net/foray/?rev=9846&view=rev
Author: victormote
Date: 2007-06-26 11:47:01 -0700 (Tue, 26 Jun 2007)
Log Message:
-----------
Conform to axsl change allowing method to set either the fill or the stroke color.
Modified Paths:
--------------
trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFContentStream.java
trunk/foray/foray-render/src/java/org/foray/render/pdf/PDFRenderer.java
Modified: trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFContentStream.java
===================================================================
--- trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFContentStream.java 2007-06-26 18:36:31 UTC (rev 9845)
+++ trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFContentStream.java 2007-06-26 18:47:01 UTC (rev 9846)
@@ -142,15 +142,22 @@
/**
* {@inheritDoc}
*/
- public void setStrokeColor(final Color newStrokeColor) {
+ public void setColor(final Color newColor, final boolean stroke) {
final PDFColor newPDFColor = this.getPDFDocument().createPDFColor(
- newStrokeColor);
- if (! this.getGS().setStrokeColor(newStrokeColor)) {
- // Nothing needs to change.
- return;
+ newColor);
+ if (stroke) {
+ if (! this.getGS().setStrokeColor(newColor)) {
+ // Nothing needs to change.
+ return;
+ }
+ add(newPDFColor.getSetterString(false));
+ } else {
+ if (! this.getGS().setFillColor(newColor)) {
+ // Nothing needs to change.
+ return;
+ }
+ add(newPDFColor.getSetterString(true));
}
- /* TODO: Why isn't the parameter on the next statement "false"?? */
- add(newPDFColor.getSetterString(true));
}
/**
Modified: trunk/foray/foray-render/src/java/org/foray/render/pdf/PDFRenderer.java
===================================================================
--- trunk/foray/foray-render/src/java/org/foray/render/pdf/PDFRenderer.java 2007-06-26 18:36:31 UTC (rev 9845)
+++ trunk/foray/foray-render/src/java/org/foray/render/pdf/PDFRenderer.java 2007-06-26 18:47:01 UTC (rev 9846)
@@ -218,7 +218,7 @@
PDFLineCapStyle.PROJECTING_SQUARE_CAP);
getContentStream().setLineWidth(toPoints(thickness));
getContentStream().setDashPattern(dashArray, 0);
- getContentStream().setStrokeColor(strokeColor);
+ getContentStream().setColor(strokeColor, true);
getContentStream().drawLine(line);
}
@@ -326,7 +326,7 @@
/* Set the color. */
final Color color = area.traitColor();
- getContentStream().setStrokeColor(color);
+ getContentStream().setColor(color, false);
/* Set the word-spacing and letter-spacing. */
final float wordSpacing = toPoints(area.wordSpacing());
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2007-06-26 19:02:46
|
Revision: 9847
http://svn.sourceforge.net/foray/?rev=9847&view=rev
Author: victormote
Date: 2007-06-26 12:02:48 -0700 (Tue, 26 Jun 2007)
Log Message:
-----------
Conform to axsl changes using booleans instead of Colors/Paint for stroke and fill.
Modified Paths:
--------------
trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFContentStream.java
trunk/foray/foray-render/src/java/org/foray/render/pdf/PDFRenderer.java
Modified: trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFContentStream.java
===================================================================
--- trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFContentStream.java 2007-06-26 18:47:01 UTC (rev 9846)
+++ trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFContentStream.java 2007-06-26 19:02:48 UTC (rev 9847)
@@ -36,7 +36,6 @@
import org.axsl.graphicR.GraphicException;
import org.axsl.graphicR.SVGGraphic;
import org.axsl.pdfW.PDFLineCapStyle;
-import org.axsl.pdfW.PDFPathPaint;
import org.axsl.pdfW.PDFTextRenderingMode;
import java.awt.Color;
@@ -276,34 +275,24 @@
* {@inheritDoc}
*/
public void drawRectangle(final Rectangle2D.Float rectangle,
- final PDFPathPaint strokePaint, final PDFPathPaint fillPaint) {
- // Bail out if stroke and fill are both missing.
- if (strokePaint == null
- && fillPaint == null) {
+ final boolean stroke, final boolean fill) {
+ /* Bail out if neither stroking nor filling. */
+ if (! stroke && ! fill) {
return;
}
closeTextObject();
add("q" + EOL);
- // Adjust the stroke paint.
- if (strokePaint != null) {
- add(strokePaint.getSetterString(false));
- }
- // Adjust the fill paint.
- if (fillPaint != null) {
- add(fillPaint.getSetterString(true));
- }
- // Draw the rectangle.
+ /* Draw the rectangle. */
add(rectangle.x + " " + rectangle.y + " " + rectangle.width + " "
+ rectangle.height + " re ");
- if (strokePaint != null
- && fillPaint != null) {
- // Close, fill, and stroke the rectangle.
+ if (stroke && fill) {
+ /* Close, fill, and stroke the rectangle. */
add("b");
- } else if (strokePaint != null) {
- // Close and stroke the rectangle.
+ } else if (stroke) {
+ /* Close and stroke the rectangle. */
add("s");
} else {
- // Fill the rectangle.
+ /* Fill the rectangle. */
add("f");
}
add(EOL);
Modified: trunk/foray/foray-render/src/java/org/foray/render/pdf/PDFRenderer.java
===================================================================
--- trunk/foray/foray-render/src/java/org/foray/render/pdf/PDFRenderer.java 2007-06-26 18:47:01 UTC (rev 9846)
+++ trunk/foray/foray-render/src/java/org/foray/render/pdf/PDFRenderer.java 2007-06-26 19:02:48 UTC (rev 9847)
@@ -237,7 +237,17 @@
}
final Rectangle2D.Float rectangle = new Rectangle2D.Float(toPoints(x),
toPoints(y), toPoints(w), toPoints(h));
- getContentStream().drawRectangle(rectangle, strokePaint, fillPaint);
+
+ /* Adjust the stroke paint. */
+ if (strokeColor != null) {
+ this.getContentStream().setColor(strokeColor, true);
+ }
+ /* Adjust the fill paint. */
+ if (fillPaint != null) {
+ this.getContentStream().setColor(fillColor, false);
+ }
+ getContentStream().drawRectangle(rectangle, strokePaint != null,
+ fillPaint != null);
}
/**
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2007-06-26 20:24:39
|
Revision: 9848
http://svn.sourceforge.net/foray/?rev=9848&view=rev
Author: victormote
Date: 2007-06-26 13:24:34 -0700 (Tue, 26 Jun 2007)
Log Message:
-----------
Fix bug of SVGs being scaled to 72 dpi, but clipped at 96 dpi. They are now scaled to 96 dpi.
Modified Paths:
--------------
trunk/foray/foray-common/src/java/org/foray/common/FOrayConstants.java
trunk/foray/foray-graphic/src/java/org/foray/graphic/batik/PDFGraphics2D.java
trunk/foray/resource/fo-examples/svg/text-001.svg
Modified: trunk/foray/foray-common/src/java/org/foray/common/FOrayConstants.java
===================================================================
--- trunk/foray/foray-common/src/java/org/foray/common/FOrayConstants.java 2007-06-26 19:02:48 UTC (rev 9847)
+++ trunk/foray/foray-common/src/java/org/foray/common/FOrayConstants.java 2007-06-26 20:24:34 UTC (rev 9848)
@@ -40,8 +40,8 @@
public static final String BINARY_SERIALIZATION_EXTENSION = "jbso";
/** Constant indicating the system-wide default screen resolution, expressed
- * in pixels-per-inch. See XSL-FO Standard 1.0, Section 6.6.5, where this
- * value is suggested. */
+ * in pixels-per-inch, that is 96.
+ * See XSL-FO Standard 1.0, Section 6.6.5, where this value is suggested. */
public static final byte DEFAULT_SCREEN_RESOLUTION = 96;
/** Standard text to designate a new line in a log message. Includes a
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-26 19:02:48 UTC (rev 9847)
+++ trunk/foray/foray-graphic/src/java/org/foray/graphic/batik/PDFGraphics2D.java 2007-06-26 20:24:34 UTC (rev 9848)
@@ -34,6 +34,7 @@
package org.foray.graphic.batik;
import org.foray.common.CharacterOutputStream;
+import org.foray.common.FOrayConstants;
import org.foray.common.WKConstants;
import org.foray.common.ps.PsColor;
import org.foray.common.ps.PsUtil;
@@ -217,12 +218,23 @@
*/
private void transformCoordinates(final Rectangle2D contentRectangle,
final SVGDocument svgDocument) {
- // transform so that the coordinates (0,0) is from the top left
- // and positive is down and to the right. (0,0) is where the
- // viewBox puts it.
- this.write("1 0 0 -1 " + contentRectangle.getX() + " "
- + contentRectangle.getY() + " cm");
+ /* Compute a scaling factor to get from 72 pixels-per-inch to our
+ * standard resolution. */
+ final float scaling = (float) WKConstants.POINTS_PER_INCH
+ / (float) FOrayConstants.DEFAULT_SCREEN_RESOLUTION;
+ /*
+ * We are doing the following with this "cm":
+ * 1. Transform so that the coordinates (0,0) is from the top left
+ * and positive is down and to the right. (0,0) is where the viewBox
+ * puts it.
+ * 2. Scale to the correct resolution (see computation above).
+ */
+ this.write(scaling + " 0 0 -" + scaling + " "
+ + contentRectangle.getX() + " "
+ + contentRectangle.getY()
+ + " cm");
+
final SVGSVGElement svg = svgDocument.getRootElement();
final AffineTransform at = ViewBox.getPreserveAspectRatioTransform(svg,
(float) contentRectangle.getWidth(),
Modified: trunk/foray/resource/fo-examples/svg/text-001.svg
===================================================================
--- trunk/foray/resource/fo-examples/svg/text-001.svg 2007-06-26 19:02:48 UTC (rev 9847)
+++ trunk/foray/resource/fo-examples/svg/text-001.svg 2007-06-26 20:24:34 UTC (rev 9848)
@@ -9,7 +9,6 @@
<svg width="200" height="50">
<rect x="0" y="0" width="200" height="50" fill="maroon"/>
-<text x="20" y="40" font-family="serif" font-size="36" fill="white">Some
-Text</text>
+<text x="20" y="40" font-family="serif" font-size="36" fill="white">Some Text</text>
</svg>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|