aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache/fop
diff options
context:
space:
mode:
authorJeremias Maerki <jeremias@apache.org>2008-07-28 07:02:41 +0000
committerJeremias Maerki <jeremias@apache.org>2008-07-28 07:02:41 +0000
commitfecc2c5cb1c3f5487fd66af4f6dd173859810dae (patch)
tree1c48d63275602fd450ad236e7de3a977a6386a17 /src/java/org/apache/fop
parentb681486f5c6d36ac028ddee082b7b8c58144f576 (diff)
downloadxmlgraphics-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/java/org/apache/fop')
-rw-r--r--src/java/org/apache/fop/pdf/PDFTextUtil.java7
-rw-r--r--src/java/org/apache/fop/render/intermediate/AbstractIFPainter.java23
-rw-r--r--src/java/org/apache/fop/render/intermediate/AbstractXMLWritingIFPainter.java20
-rw-r--r--src/java/org/apache/fop/render/intermediate/AffineTransformArrayParser.java5
-rw-r--r--src/java/org/apache/fop/render/intermediate/IFConstants.java3
-rw-r--r--src/java/org/apache/fop/render/intermediate/IFGraphicContext.java60
-rw-r--r--src/java/org/apache/fop/render/intermediate/IFPainter.java10
-rw-r--r--src/java/org/apache/fop/render/intermediate/IFParser.java49
-rw-r--r--src/java/org/apache/fop/render/intermediate/IFRenderer.java93
-rw-r--r--src/java/org/apache/fop/render/intermediate/IFSerializer.java72
-rw-r--r--src/java/org/apache/fop/render/pdf/PDFPainter.java31
11 files changed, 307 insertions, 66 deletions
diff --git a/src/java/org/apache/fop/pdf/PDFTextUtil.java b/src/java/org/apache/fop/pdf/PDFTextUtil.java
index 735a7894d..e9e7fd049 100644
--- a/src/java/org/apache/fop/pdf/PDFTextUtil.java
+++ b/src/java/org/apache/fop/pdf/PDFTextUtil.java
@@ -270,7 +270,12 @@ public abstract class PDFTextUtil {
* @param adjust the glyph adjust value in thousands of text unit space.
*/
public void adjustGlyphTJ(double adjust) {
- bufTJ.append(endText).append(" ");
+ if (bufTJ == null) {
+ bufTJ = new StringBuffer();
+ }
+ if (bufTJ.length() > 0) {
+ bufTJ.append(endText).append(" ");
+ }
bufTJ.append(PDFNumber.doubleOut(adjust, DEC - 4));
bufTJ.append(" ");
bufTJ.append(startText);
diff --git a/src/java/org/apache/fop/render/intermediate/AbstractIFPainter.java b/src/java/org/apache/fop/render/intermediate/AbstractIFPainter.java
index 9c9dda61a..54d5b33b4 100644
--- a/src/java/org/apache/fop/render/intermediate/AbstractIFPainter.java
+++ b/src/java/org/apache/fop/render/intermediate/AbstractIFPainter.java
@@ -19,6 +19,10 @@
package org.apache.fop.render.intermediate;
+import java.awt.Dimension;
+import java.awt.Rectangle;
+import java.awt.geom.AffineTransform;
+
import org.apache.fop.apps.FOUserAgent;
/**
@@ -47,4 +51,23 @@ public abstract class AbstractIFPainter implements IFPainter {
return this.userAgent;
}
+ private AffineTransform combine(AffineTransform[] transforms) {
+ AffineTransform at = new AffineTransform();
+ for (int i = 0, c = transforms.length; i < c; i++) {
+ at.concatenate(transforms[i]);
+ }
+ return at;
+ }
+
+ /** {@inheritDoc} */
+ public void startViewport(AffineTransform[] transforms, Dimension size, Rectangle clipRect)
+ throws IFException {
+ startViewport(combine(transforms), size, clipRect);
+ }
+
+ /** {@inheritDoc} */
+ public void startGroup(AffineTransform[] transforms) throws IFException {
+ startGroup(combine(transforms));
+ }
+
}
diff --git a/src/java/org/apache/fop/render/intermediate/AbstractXMLWritingIFPainter.java b/src/java/org/apache/fop/render/intermediate/AbstractXMLWritingIFPainter.java
index 4336b0bf9..863c4564e 100644
--- a/src/java/org/apache/fop/render/intermediate/AbstractXMLWritingIFPainter.java
+++ b/src/java/org/apache/fop/render/intermediate/AbstractXMLWritingIFPainter.java
@@ -19,6 +19,7 @@
package org.apache.fop.render.intermediate;
+import java.awt.Rectangle;
import java.awt.geom.AffineTransform;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
@@ -131,6 +132,9 @@ public abstract class AbstractXMLWritingIFPainter extends AbstractIFPainter {
* @return the StringBuffer passed to this method
*/
protected StringBuffer toString(AffineTransform transform, StringBuffer sb) {
+ if (transform.isIdentity()) {
+ return sb;
+ }
double[] matrix = new double[6];
transform.getMatrix(matrix);
if (matrix[0] == 1 && matrix[3] == 1 && matrix[1] == 0 && matrix[2] == 0) {
@@ -210,4 +214,20 @@ public abstract class AbstractXMLWritingIFPainter extends AbstractIFPainter {
}
return sb.toString();
}
+
+ /**
+ * Converts a rectangle into a space-separated string.
+ * @param rect the rectangle
+ * @return the space-separated array of coordinates
+ */
+ protected String toString(Rectangle rect) {
+ if (rect == null) {
+ return "";
+ }
+ StringBuffer sb = new StringBuffer();
+ sb.append(rect.x).append(' ').append(rect.y).append(' ');
+ sb.append(rect.width).append(' ').append(rect.height);
+ return sb.toString();
+ }
+
}
diff --git a/src/java/org/apache/fop/render/intermediate/AffineTransformArrayParser.java b/src/java/org/apache/fop/render/intermediate/AffineTransformArrayParser.java
index 36a783427..f13139bdb 100644
--- a/src/java/org/apache/fop/render/intermediate/AffineTransformArrayParser.java
+++ b/src/java/org/apache/fop/render/intermediate/AffineTransformArrayParser.java
@@ -33,6 +33,8 @@ import org.apache.batik.parser.TransformListParser;
*/
public class AffineTransformArrayParser implements TransformListHandler {
+ private static final AffineTransform[] EMPTY_ARRAY = new AffineTransform[0];
+
private List transforms;
/**
@@ -60,6 +62,9 @@ public class AffineTransformArrayParser implements TransformListHandler {
*/
public static AffineTransform[] createAffineTransform(String s)
throws ParseException {
+ if (s == null) {
+ return EMPTY_ARRAY;
+ }
TransformListParser p = new TransformListParser();
AffineTransformArrayParser th = new AffineTransformArrayParser();
diff --git a/src/java/org/apache/fop/render/intermediate/IFConstants.java b/src/java/org/apache/fop/render/intermediate/IFConstants.java
index 4bd3a706e..18de496e1 100644
--- a/src/java/org/apache/fop/render/intermediate/IFConstants.java
+++ b/src/java/org/apache/fop/render/intermediate/IFConstants.java
@@ -47,5 +47,6 @@ public interface IFConstants {
String EL_PAGE_HEADER = "page-header";
String EL_PAGE_TRAILER = "page-trailer";
String EL_PAGE_CONTENT = "content";
- String EL_BOX = "box";
+ String EL_VIEWPORT = "viewport";
+ String EL_GROUP = "g";
}
diff --git a/src/java/org/apache/fop/render/intermediate/IFGraphicContext.java b/src/java/org/apache/fop/render/intermediate/IFGraphicContext.java
new file mode 100644
index 000000000..ce48775b1
--- /dev/null
+++ b/src/java/org/apache/fop/render/intermediate/IFGraphicContext.java
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.render.intermediate;
+
+import org.apache.xmlgraphics.java2d.GraphicContext;
+
+public class IFGraphicContext extends GraphicContext {
+
+ private int groupDepth;
+
+ /**
+ * Default constructor.
+ */
+ public IFGraphicContext() {
+ super();
+ }
+
+ /**
+ * Copy constructor.
+ * @param graphicContext the graphic context to make a copy of
+ */
+ protected IFGraphicContext(IFGraphicContext graphicContext) {
+ super(graphicContext);
+ //We don't clone groupDepth!
+ }
+
+ /** {@inheritDoc} */
+ public Object clone() {
+ return new IFGraphicContext(this);
+ }
+
+ public void startGroup() {
+ this.groupDepth++;
+ }
+
+ public void endGroup() {
+ this.groupDepth--;
+ }
+
+ public int getGroupDepth() {
+ return this.groupDepth;
+ }
+}
diff --git a/src/java/org/apache/fop/render/intermediate/IFPainter.java b/src/java/org/apache/fop/render/intermediate/IFPainter.java
index 66d7a0750..269c4b0ad 100644
--- a/src/java/org/apache/fop/render/intermediate/IFPainter.java
+++ b/src/java/org/apache/fop/render/intermediate/IFPainter.java
@@ -214,10 +214,14 @@ public interface IFPainter {
*/
void endPageTrailer() throws IFException;
- void startBox(AffineTransform transform, Dimension size, boolean clip) throws IFException;
- void startBox(AffineTransform[] transforms, Dimension size, boolean clip) throws IFException;
+ void startViewport(AffineTransform transform, Dimension size, Rectangle clipRect) throws IFException;
+ void startViewport(AffineTransform[] transforms, Dimension size, Rectangle clipRect) throws IFException;
//For transform, Batik's org.apache.batik.parser.TransformListHandler/Parser can be used
- void endBox() throws IFException;
+ void endViewport() throws IFException;
+
+ void startGroup(AffineTransform[] transforms) throws IFException;
+ void startGroup(AffineTransform transform) throws IFException;
+ void endGroup() throws IFException;
/**
* Updates the current font.
diff --git a/src/java/org/apache/fop/render/intermediate/IFParser.java b/src/java/org/apache/fop/render/intermediate/IFParser.java
index 6f85c5801..09358da40 100644
--- a/src/java/org/apache/fop/render/intermediate/IFParser.java
+++ b/src/java/org/apache/fop/render/intermediate/IFParser.java
@@ -122,15 +122,16 @@ public class IFParser implements IFConstants {
this.painter = painter;
this.userAgent = userAgent;
this.elementMappingRegistry = elementMappingRegistry;
- elementHandlers.put("document", new DocumentHandler());
- elementHandlers.put("header", new DocumentHeaderHandler());
- elementHandlers.put("page-sequence", new PageSequenceHandler());
- elementHandlers.put("page", new PageHandler());
- elementHandlers.put("page-header", new PageHeaderHandler());
- elementHandlers.put("content", new PageContentHandler());
- elementHandlers.put("page-trailer", new PageTrailerHandler());
+ elementHandlers.put(EL_DOCUMENT, new DocumentHandler());
+ elementHandlers.put(EL_HEADER, new DocumentHeaderHandler());
+ elementHandlers.put(EL_PAGE_SEQUENCE, new PageSequenceHandler());
+ elementHandlers.put(EL_PAGE, new PageHandler());
+ elementHandlers.put(EL_PAGE_HEADER, new PageHeaderHandler());
+ elementHandlers.put(EL_PAGE_CONTENT, new PageContentHandler());
+ elementHandlers.put(EL_PAGE_TRAILER, new PageTrailerHandler());
//Page content
- elementHandlers.put("box", new BoxHandler());
+ elementHandlers.put(EL_VIEWPORT, new ViewportHandler());
+ elementHandlers.put(EL_GROUP, new GroupHandler());
elementHandlers.put("font", new FontHandler());
elementHandlers.put("text", new TextHandler());
elementHandlers.put("rect", new RectHandler());
@@ -366,18 +367,35 @@ public class IFParser implements IFConstants {
}
- private class BoxHandler extends AbstractElementHandler {
+ private class ViewportHandler extends AbstractElementHandler {
public void startElement(Attributes attributes) throws IFException {
String transform = attributes.getValue("transform");
AffineTransform[] transforms
= AffineTransformArrayParser.createAffineTransform(transform);
- //TODO Incomplete implementation
- painter.startBox(transforms, null, false);
+ int width = Integer.parseInt(attributes.getValue("width"));
+ int height = Integer.parseInt(attributes.getValue("height"));
+ Rectangle clipRect = getAttributeAsRectangle(attributes, "clip-rect");
+ painter.startViewport(transforms, new Dimension(width, height), clipRect);
}
public void endElement() throws IFException {
- painter.endBox();
+ painter.endViewport();
+ }
+
+ }
+
+ private class GroupHandler extends AbstractElementHandler {
+
+ public void startElement(Attributes attributes) throws IFException {
+ String transform = attributes.getValue("transform");
+ AffineTransform[] transforms
+ = AffineTransformArrayParser.createAffineTransform(transform);
+ painter.startGroup(transforms);
+ }
+
+ public void endElement() throws IFException {
+ painter.endGroup();
}
}
@@ -515,8 +533,11 @@ public class IFParser implements IFConstants {
}
private static Rectangle getAttributeAsRectangle(Attributes attributes, String name) {
- String s = attributes.getValue(name).trim();
- int[] values = ConversionUtils.toIntArray(s, "\\s");
+ String s = attributes.getValue(name);
+ if (s == null) {
+ return null;
+ }
+ int[] values = ConversionUtils.toIntArray(s.trim(), "\\s");
if (values.length != 4) {
throw new IllegalArgumentException("Rectangle must consist of 4 int values!");
}
diff --git a/src/java/org/apache/fop/render/intermediate/IFRenderer.java b/src/java/org/apache/fop/render/intermediate/IFRenderer.java
index 8df052663..8935bf4e0 100644
--- a/src/java/org/apache/fop/render/intermediate/IFRenderer.java
+++ b/src/java/org/apache/fop/render/intermediate/IFRenderer.java
@@ -37,7 +37,6 @@ import org.xml.sax.SAXException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.xmlgraphics.java2d.GraphicContext;
import org.apache.xmlgraphics.xmp.Metadata;
import org.apache.xmlgraphics.xmp.schemas.DublinCoreAdapter;
import org.apache.xmlgraphics.xmp.schemas.DublinCoreSchema;
@@ -48,16 +47,19 @@ import org.apache.fop.Version;
import org.apache.fop.apps.FOPException;
import org.apache.fop.apps.MimeConstants;
import org.apache.fop.area.Block;
+import org.apache.fop.area.BlockViewport;
import org.apache.fop.area.CTM;
import org.apache.fop.area.OffDocumentExtensionAttachment;
import org.apache.fop.area.OffDocumentItem;
import org.apache.fop.area.PageSequence;
import org.apache.fop.area.PageViewport;
+import org.apache.fop.area.RegionViewport;
import org.apache.fop.area.Trait;
import org.apache.fop.area.inline.AbstractTextArea;
import org.apache.fop.area.inline.Image;
import org.apache.fop.area.inline.SpaceArea;
import org.apache.fop.area.inline.TextArea;
+import org.apache.fop.area.inline.Viewport;
import org.apache.fop.area.inline.WordArea;
import org.apache.fop.fo.extensions.ExtensionAttachment;
import org.apache.fop.fo.extensions.xmp.XMPMetadata;
@@ -85,7 +87,8 @@ public class IFRenderer extends AbstractPathOrientedRenderer {
private boolean inPageSequence = false;
private Stack graphicContextStack = new Stack();
- private GraphicContext graphicContext = new GraphicContext();
+ private Stack viewportDimensionStack = new Stack();
+ private IFGraphicContext graphicContext = new IFGraphicContext();
private Metadata documentMetadata;
@@ -285,12 +288,20 @@ public class IFRenderer extends AbstractPathOrientedRenderer {
/** {@inheritDoc} */
protected void saveGraphicsState() {
graphicContextStack.push(graphicContext);
- graphicContext = (GraphicContext)graphicContext.clone();
+ graphicContext = (IFGraphicContext)graphicContext.clone();
}
/** {@inheritDoc} */
protected void restoreGraphicsState() {
- graphicContext = (GraphicContext)graphicContextStack.pop();
+ while (graphicContext.getGroupDepth() > 0) {
+ try {
+ painter.endGroup();
+ } catch (IFException e) {
+ handleIFException(e);
+ }
+ graphicContext.endGroup();
+ }
+ graphicContext = (IFGraphicContext)graphicContextStack.pop();
}
/** {@inheritDoc} */
@@ -309,39 +320,78 @@ public class IFRenderer extends AbstractPathOrientedRenderer {
log.debug("Block.FIXED --> restoring context after break-out");
for (int i = 0, c = breakOutList.size(); i < c; i++) {
saveGraphicsState();
- this.graphicContext = (GraphicContext)breakOutList.get(i);
+ this.graphicContext = (IFGraphicContext)breakOutList.get(i);
}
}
/** {@inheritDoc} */
protected void concatenateTransformationMatrix(AffineTransform at) {
if (!at.isIdentity()) {
- graphicContext.transform(ptToMpt(at));
+ if (log.isDebugEnabled()) {
+ log.debug("-----concatenateTransformationMatrix: " + at);
+ }
+ AffineTransform atmpt = ptToMpt(at);
+ graphicContext.transform(atmpt);
+ graphicContext.startGroup();
+ try {
+ painter.startGroup(atmpt);
+ } catch (IFException e) {
+ handleIFException(e);
+ }
}
}
/** {@inheritDoc} */
protected void beginTextObject() {
- // TODO Auto-generated method stub
-
+ //nop - Ignore, handled by painter internally
}
/** {@inheritDoc} */
protected void endTextObject() {
- // TODO Auto-generated method stub
+ //nop - Ignore, handled by painter internally
+ }
+
+ /** {@inheritDoc} */
+ protected void renderRegionViewport(RegionViewport viewport) {
+ Dimension dim = new Dimension(viewport.getIPD(), viewport.getBPD());
+ viewportDimensionStack.push(dim);
+ super.renderRegionViewport(viewport);
+ viewportDimensionStack.pop();
+ }
+ /** {@inheritDoc} */
+ protected void renderBlockViewport(BlockViewport bv, List children) {
+ Dimension dim = new Dimension(bv.getIPD(), bv.getBPD());
+ viewportDimensionStack.push(dim);
+ super.renderBlockViewport(bv, children);
+ viewportDimensionStack.pop();
+ }
+
+ /** {@inheritDoc} */
+ public void renderViewport(Viewport viewport) {
+ Dimension dim = new Dimension(viewport.getIPD(), viewport.getBPD());
+ viewportDimensionStack.push(dim);
+ super.renderViewport(viewport);
+ viewportDimensionStack.pop();
}
/** {@inheritDoc} */
protected void startVParea(CTM ctm, Rectangle2D clippingRect) {
if (log.isDebugEnabled()) {
- log.debug("startVParea() ctm=" + ctm + ", rect=" + clippingRect);
+ log.debug("startVParea() ctm=" + ctm + ", clippingRect=" + clippingRect);
}
saveGraphicsState();
AffineTransform at = new AffineTransform(ctm.toArray());
graphicContext.transform(at);
try {
- painter.startBox(at, null, false);
+ Rectangle clipRect = null;
+ if (clippingRect != null) {
+ clipRect = new Rectangle(
+ (int)clippingRect.getMinX() - currentIPPosition,
+ (int)clippingRect.getMinY() - currentBPPosition,
+ (int)clippingRect.getWidth(), (int)clippingRect.getHeight());
+ }
+ painter.startViewport(at, (Dimension)viewportDimensionStack.peek(), clipRect);
} catch (IFException e) {
handleIFException(e);
}
@@ -354,7 +404,7 @@ public class IFRenderer extends AbstractPathOrientedRenderer {
protected void endVParea() {
log.debug("endVParea()");
try {
- painter.endBox();
+ painter.endViewport();
} catch (IFException e) {
handleIFException(e);
}
@@ -364,9 +414,10 @@ public class IFRenderer extends AbstractPathOrientedRenderer {
}
}
+ /*
protected void renderReferenceArea(Block block) {
// TODO Auto-generated method stub
- }
+ }*/
/** {@inheritDoc} */
protected void renderBlock(Block block) {
@@ -502,28 +553,30 @@ public class IFRenderer extends AbstractPathOrientedRenderer {
protected void drawImage(String url, Rectangle2D pos, Map foreignAttributes) {
// TODO Auto-generated method stub
-
+ log.warn("drawImage() NYI");
}
protected void clip() {
// TODO Auto-generated method stub
-
+ log.warn("clip() NYI");
}
protected void clipRect(float x, float y, float width, float height) {
// TODO Auto-generated method stub
-
+ log.warn("clipRect() NYI");
}
protected void closePath() {
// TODO Auto-generated method stub
-
+ log.warn("closePath() NYI");
}
protected void drawBorderLine(float x1, float y1, float x2, float y2, boolean horz,
boolean startOrBefore, int style, Color col) {
// TODO Auto-generated method stub
-
+ //log.warn("drawBorderLine() NYI");
+ updateColor(col, true);
+ fillRect(x1, y1, x2 - x1, y2 - y1);
}
private Rectangle toMillipointRectangle(float x, float y, float width, float height) {
@@ -545,13 +598,13 @@ public class IFRenderer extends AbstractPathOrientedRenderer {
/** {@inheritDoc} */
protected void moveTo(float x, float y) {
// TODO Auto-generated method stub
-
+ log.warn("moveTo() NYI");
}
/** {@inheritDoc} */
protected void lineTo(float x, float y) {
// TODO Auto-generated method stub
-
+ log.warn("lineTo() NYI");
}
/** {@inheritDoc} */
diff --git a/src/java/org/apache/fop/render/intermediate/IFSerializer.java b/src/java/org/apache/fop/render/intermediate/IFSerializer.java
index 8cfbcad11..f05485a59 100644
--- a/src/java/org/apache/fop/render/intermediate/IFSerializer.java
+++ b/src/java/org/apache/fop/render/intermediate/IFSerializer.java
@@ -200,15 +200,15 @@ public class IFSerializer extends AbstractXMLWritingIFPainter implements IFConst
}
/** {@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)
+ 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++) {
@@ -217,32 +217,72 @@ public class IFSerializer extends AbstractXMLWritingIFPainter implements IFConst
}
toString(transforms[i], sb);
}
- startBox(sb.toString(), size, clip);
+ startViewport(sb.toString(), 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 {
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);
+ }
+ atts.addAttribute("", "width", "width", CDATA, Integer.toString(size.width));
+ atts.addAttribute("", "height", "height", CDATA, Integer.toString(size.height));
+ if (clipRect != null) {
+ atts.addAttribute("", "clip-rect", "clip-rect", CDATA, toString(clipRect));
}
- if (clip) {
- atts.addAttribute("", "clip", "clip", CDATA, "true");
+ startElement(EL_VIEWPORT, atts);
+ } catch (SAXException e) {
+ throw new IFException("SAX error in startViewport()", e);
+ }
+ }
+
+ /** {@inheritDoc} */
+ public void endViewport() throws IFException {
+ try {
+ endElement(EL_VIEWPORT);
+ } catch (SAXException e) {
+ throw new IFException("SAX error in endViewport()", e);
+ }
+ }
+
+ /** {@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());
+ }
+
+ /** {@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(EL_BOX, atts);
+ startElement(EL_GROUP, atts);
} catch (SAXException e) {
- throw new IFException("SAX error in startBox()", e);
+ throw new IFException("SAX error in startGroup()", e);
}
}
/** {@inheritDoc} */
- public void endBox() throws IFException {
+ public void endGroup() throws IFException {
try {
- endElement(EL_BOX);
+ endElement(EL_GROUP);
} catch (SAXException e) {
- throw new IFException("SAX error in endBox()", e);
+ throw new IFException("SAX error in endGroup()", e);
}
}
diff --git a/src/java/org/apache/fop/render/pdf/PDFPainter.java b/src/java/org/apache/fop/render/pdf/PDFPainter.java
index ec83db707..8bf5c8f58 100644
--- a/src/java/org/apache/fop/render/pdf/PDFPainter.java
+++ b/src/java/org/apache/fop/render/pdf/PDFPainter.java
@@ -294,24 +294,33 @@ public class PDFPainter extends AbstractBinaryWritingIFPainter {
}
/** {@inheritDoc} */
- public void startBox(AffineTransform transform, Dimension size, boolean clip)
+ public void startViewport(AffineTransform transform, Dimension size, Rectangle clipRect)
throws IFException {
saveGraphicsState();
currentStream.add(CTMHelper.toPDFString(transform, true) + " cm\n");
+ if (clipRect != null) {
+ StringBuffer sb = new StringBuffer();
+ sb.append(format(clipRect.x)).append(' ');
+ sb.append(format(clipRect.y)).append(' ');
+ sb.append(format(clipRect.width)).append(' ');
+ sb.append(format(clipRect.height)).append(" re W n\n");
+ currentStream.add(sb.toString());
+ }
}
/** {@inheritDoc} */
- public void startBox(AffineTransform[] transforms, Dimension size, boolean clip)
- throws IFException {
- AffineTransform at = new AffineTransform();
- for (int i = 0, c = transforms.length; i < c; i++) {
- at.concatenate(transforms[i]);
- }
- startBox(at, size, clip);
+ public void startGroup(AffineTransform transform) throws IFException {
+ saveGraphicsState();
+ currentStream.add(CTMHelper.toPDFString(transform, true) + " cm\n");
+ }
+
+ /** {@inheritDoc} */
+ public void endGroup() throws IFException {
+ restoreGraphicsState();
}
/** {@inheritDoc} */
- public void endBox() throws IFException {
+ public void endViewport() throws IFException {
restoreGraphicsState();
}
@@ -348,7 +357,7 @@ public class PDFPainter extends AbstractBinaryWritingIFPainter {
}
/**
- * Formats a int value (normally coordinates in millipoints) as Strings.
+ * Formats a integer value (normally coordinates in millipoints) to a String.
* @param value the value (in millipoints)
* @return the formatted value
*/
@@ -494,7 +503,7 @@ public class PDFPainter extends AbstractBinaryWritingIFPainter {
}
textutil.writeTJMappedChar(ch);
- if (dx != null && i < dxl) {
+ if (dx != null && i < dxl - 1) {
glyphAdjust += dx[i + 1];
}