From 909b93a2b94ac18245103d7f5e6231b0595f6fcd Mon Sep 17 00:00:00 2001 From: Jeremias Maerki Date: Mon, 28 Jul 2008 13:01:58 +0000 Subject: Reduce code duplication and make the toString() methods available to the outside (need them for debugging later). git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign@680338 13f79535-47bb-0310-9956-ffa450edef68 --- .../intermediate/AbstractXMLWritingIFPainter.java | 36 +++++++++++++++++++++- .../fop/render/intermediate/IFSerializer.java | 26 +++------------- 2 files changed, 39 insertions(+), 23 deletions(-) (limited to 'src/java') diff --git a/src/java/org/apache/fop/render/intermediate/AbstractXMLWritingIFPainter.java b/src/java/org/apache/fop/render/intermediate/AbstractXMLWritingIFPainter.java index cd341be16..9e0f97699 100644 --- a/src/java/org/apache/fop/render/intermediate/AbstractXMLWritingIFPainter.java +++ b/src/java/org/apache/fop/render/intermediate/AbstractXMLWritingIFPainter.java @@ -120,7 +120,7 @@ public abstract class AbstractXMLWritingIFPainter extends AbstractIFPainter { * @param sb the StringBuffer to write the transform method to * @return the StringBuffer passed to this method */ - protected StringBuffer toString(AffineTransform transform, StringBuffer sb) { + public static StringBuffer toString(AffineTransform transform, StringBuffer sb) { if (transform.isIdentity()) { return sb; } @@ -145,6 +145,40 @@ public abstract class AbstractXMLWritingIFPainter extends AbstractIFPainter { return sb; } + /** + * Converts an {@code AffineTransform} array to an SVG style transform method sequence. + * @param transforms the transformation matrix array + * @param sb the StringBuffer to write the transform method sequence to + * @return the StringBuffer passed to this method + */ + public static StringBuffer toString(AffineTransform[] transforms, StringBuffer sb) { + for (int i = 0, c = transforms.length; i < c; i++) { + if (i > 0) { + sb.append(' '); + } + toString(transforms[i], sb); + } + return sb; + } + + /** + * Converts an {@code AffineTransform} array to an SVG style transform method sequence. + * @param transforms the transformation matrix array + * @return the formatted array + */ + public static String toString(AffineTransform[] transforms) { + return toString(transforms, new StringBuffer()).toString(); + } + + /** + * Converts an {@code AffineTransform} instance to an SVG style transform method. + * @param transform the transformation matrix + * @return the formatted array + */ + public static String toString(AffineTransform transform) { + return toString(transform, new StringBuffer()).toString(); + } + /** * Convenience method to generate a startElement SAX event. * @param localName the local name of the element diff --git a/src/java/org/apache/fop/render/intermediate/IFSerializer.java b/src/java/org/apache/fop/render/intermediate/IFSerializer.java index f05485a59..601732b39 100644 --- a/src/java/org/apache/fop/render/intermediate/IFSerializer.java +++ b/src/java/org/apache/fop/render/intermediate/IFSerializer.java @@ -202,22 +202,13 @@ public class IFSerializer extends AbstractXMLWritingIFPainter implements IFConst /** {@inheritDoc} */ public void startViewport(AffineTransform transform, Dimension size, Rectangle clipRect) throws IFException { - StringBuffer sb = new StringBuffer(); - toString(transform, sb); - startViewport(sb.toString(), size, clipRect); + startViewport(toString(transform), size, clipRect); } /** {@inheritDoc} */ public void startViewport(AffineTransform[] transforms, Dimension size, Rectangle clipRect) throws IFException { - StringBuffer sb = new StringBuffer(); - for (int i = 0, c = transforms.length; i < c; i++) { - if (i > 0) { - sb.append(' '); - } - toString(transforms[i], sb); - } - startViewport(sb.toString(), size, clipRect); + startViewport(toString(transforms), size, clipRect); } private void startViewport(String transform, Dimension size, Rectangle clipRect) throws IFException { @@ -248,21 +239,12 @@ public class IFSerializer extends AbstractXMLWritingIFPainter implements IFConst /** {@inheritDoc} */ public void startGroup(AffineTransform[] transforms) throws IFException { - StringBuffer sb = new StringBuffer(); - for (int i = 0, c = transforms.length; i < c; i++) { - if (i > 0) { - sb.append(' '); - } - toString(transforms[i], sb); - } - startGroup(sb.toString()); + startGroup(toString(transforms)); } /** {@inheritDoc} */ public void startGroup(AffineTransform transform) throws IFException { - StringBuffer sb = new StringBuffer(); - toString(transform, sb); - startGroup(sb.toString()); + startGroup(toString(transform)); } private void startGroup(String transform) throws IFException { -- cgit v1.2.3