diff options
author | Jeremias Maerki <jeremias@apache.org> | 2008-07-28 07:02:41 +0000 |
---|---|---|
committer | Jeremias Maerki <jeremias@apache.org> | 2008-07-28 07:02:41 +0000 |
commit | fecc2c5cb1c3f5487fd66af4f6dd173859810dae (patch) | |
tree | 1c48d63275602fd450ad236e7de3a977a6386a17 /src/sandbox | |
parent | b681486f5c6d36ac028ddee082b7b8c58144f576 (diff) | |
download | xmlgraphics-fop-fecc2c5cb1c3f5487fd66af4f6dd173859810dae.tar.gz xmlgraphics-fop-fecc2c5cb1c3f5487fd66af4f6dd173859810dae.zip |
Renamed "box" to "viewport". Introduced "group" for pure reference areas (only transformation, no clipping).
"viewport" and "group" are implemented in IFSerializer, SVG and PDF. Some minor problems remain.
Fixed a few minor bugs (like NPEs) found while testing.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign@680266 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/sandbox')
-rw-r--r-- | src/sandbox/org/apache/fop/render/svg/AbstractSVGPainter.java | 92 | ||||
-rw-r--r-- | src/sandbox/org/apache/fop/render/svg/SVGPainter.java | 11 |
2 files changed, 86 insertions, 17 deletions
diff --git a/src/sandbox/org/apache/fop/render/svg/AbstractSVGPainter.java b/src/sandbox/org/apache/fop/render/svg/AbstractSVGPainter.java index 38b439fe0..980a67945 100644 --- a/src/sandbox/org/apache/fop/render/svg/AbstractSVGPainter.java +++ b/src/sandbox/org/apache/fop/render/svg/AbstractSVGPainter.java @@ -83,16 +83,14 @@ public abstract class AbstractSVGPainter extends AbstractXMLWritingIFPainter } /** {@inheritDoc} */ - public void startBox(AffineTransform transform, Dimension size, boolean clip) + public void startViewport(AffineTransform transform, Dimension size, Rectangle clipRect) throws IFException { StringBuffer sb = new StringBuffer(); toString(transform, sb); - startBox(sb.toString(), size, clip); + startViewport(sb.toString(), size, clipRect); } - /** {@inheritDoc} */ - public void startBox(AffineTransform[] transforms, Dimension size, boolean clip) - throws IFException { + private String toString(AffineTransform[] transforms) { StringBuffer sb = new StringBuffer(); for (int i = 0, c = transforms.length; i < c; i++) { if (i > 0) { @@ -100,32 +98,61 @@ public abstract class AbstractSVGPainter extends AbstractXMLWritingIFPainter } toString(transforms[i], sb); } - startBox(sb.toString(), size, clip); + return sb.toString(); + } + + /** {@inheritDoc} */ + public void startViewport(AffineTransform[] transforms, Dimension size, Rectangle clipRect) + throws IFException { + startViewport(toString(transforms), size, clipRect); } - private void startBox(String transform, Dimension size, boolean clip) throws IFException { + private void startViewport(String transform, Dimension size, Rectangle clipRect) + throws IFException { try { establish(MODE_NORMAL); AttributesImpl atts = new AttributesImpl(); - atts.addAttribute("", "transform", "transform", CDATA, transform); - /* - if (size != null) { - atts.addAttribute("", "width", "width", CDATA, Integer.toString(size.width)); - atts.addAttribute("", "height", "height", CDATA, Integer.toString(size.height)); + if (transform != null && transform.length() > 0) { + atts.addAttribute("", "transform", "transform", CDATA, transform); } - if (clip) { - atts.addAttribute("", "clip", "clip", CDATA, "true"); - }*/ startElement("g", atts); + + atts.clear(); + atts.addAttribute("", "width", "width", CDATA, Integer.toString(size.width)); + atts.addAttribute("", "height", "height", CDATA, Integer.toString(size.height)); + if (clipRect != null) { + int[] v = new int[] { + clipRect.y, + -clipRect.x + size.width - clipRect.width, + -clipRect.y + size.height - clipRect.height, + clipRect.x}; + int sum = 0; + for (int i = 0; i < 4; i++) { + sum += Math.abs(v[i]); + } + if (sum != 0) { + StringBuffer sb = new StringBuffer("rect("); + sb.append(v[0]).append(','); + sb.append(v[1]).append(','); + sb.append(v[2]).append(','); + sb.append(v[3]).append(')'); + atts.addAttribute("", "clip", "clip", CDATA, sb.toString()); + } + atts.addAttribute("", "overflow", "overflow", CDATA, "hidden"); + } else { + atts.addAttribute("", "overflow", "overflow", CDATA, "visible"); + } + startElement("svg", atts); } catch (SAXException e) { throw new IFException("SAX error in startBox()", e); } } /** {@inheritDoc} */ - public void endBox() throws IFException { + public void endViewport() throws IFException { try { establish(MODE_NORMAL); + endElement("svg"); endElement("g"); } catch (SAXException e) { throw new IFException("SAX error in endBox()", e); @@ -133,6 +160,39 @@ public abstract class AbstractSVGPainter extends AbstractXMLWritingIFPainter } /** {@inheritDoc} */ + public void startGroup(AffineTransform[] transforms) throws IFException { + startGroup(toString(transforms)); + } + + /** {@inheritDoc} */ + public void startGroup(AffineTransform transform) throws IFException { + StringBuffer sb = new StringBuffer(); + toString(transform, sb); + startGroup(sb.toString()); + } + + private void startGroup(String transform) throws IFException { + try { + AttributesImpl atts = new AttributesImpl(); + if (transform != null && transform.length() > 0) { + atts.addAttribute("", "transform", "transform", CDATA, transform); + } + startElement("g", atts); + } catch (SAXException e) { + throw new IFException("SAX error in startGroup()", e); + } + } + + /** {@inheritDoc} */ + public void endGroup() throws IFException { + try { + endElement("g"); + } catch (SAXException e) { + throw new IFException("SAX error in endGroup()", e); + } + } + + /** {@inheritDoc} */ public void startImage(Rectangle rect) throws IFException { //establish(MODE_NORMAL); // TODO Auto-generated method stub diff --git a/src/sandbox/org/apache/fop/render/svg/SVGPainter.java b/src/sandbox/org/apache/fop/render/svg/SVGPainter.java index 25d11a3ad..112144e73 100644 --- a/src/sandbox/org/apache/fop/render/svg/SVGPainter.java +++ b/src/sandbox/org/apache/fop/render/svg/SVGPainter.java @@ -133,7 +133,16 @@ public class SVGPainter extends AbstractSVGPainter { public void startPage(int index, String name, Dimension size) throws IFException { OutputStream out; try { - out = this.multiFileUtil.createOutputStream(index); + if (index == 0) { + out = null; + } else { + out = this.multiFileUtil.createOutputStream(index); + if (out == null) { + //TODO Convert to event + throw new IFException( + "No filename information available. Stopping after first page.", null); + } + } } catch (IOException ioe) { throw new IFException("I/O exception while setting up output file", ioe); } |