"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-ffa450edef68tags/fop-1_0
<include name="org/apache/fop/render/pdf/**"/> | <include name="org/apache/fop/render/pdf/**"/> | ||||
<exclude name="org/apache/fop/render/pdf/PDFRenderer.class"/> | <exclude name="org/apache/fop/render/pdf/PDFRenderer.class"/> | ||||
<exclude name="org/apache/fop/render/pdf/PDFXMLHandler*"/> | <exclude name="org/apache/fop/render/pdf/PDFXMLHandler*"/> | ||||
<include name="org/apache/fop/render/intermediate/IFPainterConfigurator.class"/> | |||||
<include name="org/apache/fop/render/*RendererConfigurator**"/> | <include name="org/apache/fop/render/*RendererConfigurator**"/> | ||||
<include name="org/apache/fop/pdf/**"/> | <include name="org/apache/fop/pdf/**"/> | ||||
</patternset> | </patternset> |
* @param adjust the glyph adjust value in thousands of text unit space. | * @param adjust the glyph adjust value in thousands of text unit space. | ||||
*/ | */ | ||||
public void adjustGlyphTJ(double adjust) { | 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(PDFNumber.doubleOut(adjust, DEC - 4)); | ||||
bufTJ.append(" "); | bufTJ.append(" "); | ||||
bufTJ.append(startText); | bufTJ.append(startText); |
package org.apache.fop.render.intermediate; | 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; | import org.apache.fop.apps.FOUserAgent; | ||||
/** | /** | ||||
return this.userAgent; | 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)); | |||||
} | |||||
} | } |
package org.apache.fop.render.intermediate; | package org.apache.fop.render.intermediate; | ||||
import java.awt.Rectangle; | |||||
import java.awt.geom.AffineTransform; | import java.awt.geom.AffineTransform; | ||||
import java.text.DecimalFormat; | import java.text.DecimalFormat; | ||||
import java.text.DecimalFormatSymbols; | import java.text.DecimalFormatSymbols; | ||||
* @return the StringBuffer passed to this method | * @return the StringBuffer passed to this method | ||||
*/ | */ | ||||
protected StringBuffer toString(AffineTransform transform, StringBuffer sb) { | protected StringBuffer toString(AffineTransform transform, StringBuffer sb) { | ||||
if (transform.isIdentity()) { | |||||
return sb; | |||||
} | |||||
double[] matrix = new double[6]; | double[] matrix = new double[6]; | ||||
transform.getMatrix(matrix); | transform.getMatrix(matrix); | ||||
if (matrix[0] == 1 && matrix[3] == 1 && matrix[1] == 0 && matrix[2] == 0) { | if (matrix[0] == 1 && matrix[3] == 1 && matrix[1] == 0 && matrix[2] == 0) { | ||||
} | } | ||||
return sb.toString(); | 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(); | |||||
} | |||||
} | } |
*/ | */ | ||||
public class AffineTransformArrayParser implements TransformListHandler { | public class AffineTransformArrayParser implements TransformListHandler { | ||||
private static final AffineTransform[] EMPTY_ARRAY = new AffineTransform[0]; | |||||
private List transforms; | private List transforms; | ||||
/** | /** | ||||
*/ | */ | ||||
public static AffineTransform[] createAffineTransform(String s) | public static AffineTransform[] createAffineTransform(String s) | ||||
throws ParseException { | throws ParseException { | ||||
if (s == null) { | |||||
return EMPTY_ARRAY; | |||||
} | |||||
TransformListParser p = new TransformListParser(); | TransformListParser p = new TransformListParser(); | ||||
AffineTransformArrayParser th = new AffineTransformArrayParser(); | AffineTransformArrayParser th = new AffineTransformArrayParser(); | ||||
String EL_PAGE_HEADER = "page-header"; | String EL_PAGE_HEADER = "page-header"; | ||||
String EL_PAGE_TRAILER = "page-trailer"; | String EL_PAGE_TRAILER = "page-trailer"; | ||||
String EL_PAGE_CONTENT = "content"; | String EL_PAGE_CONTENT = "content"; | ||||
String EL_BOX = "box"; | |||||
String EL_VIEWPORT = "viewport"; | |||||
String EL_GROUP = "g"; | |||||
} | } |
/* | |||||
* 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; | |||||
} | |||||
} |
*/ | */ | ||||
void endPageTrailer() throws IFException; | 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 | //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. | * Updates the current font. |
this.painter = painter; | this.painter = painter; | ||||
this.userAgent = userAgent; | this.userAgent = userAgent; | ||||
this.elementMappingRegistry = elementMappingRegistry; | 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 | //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("font", new FontHandler()); | ||||
elementHandlers.put("text", new TextHandler()); | elementHandlers.put("text", new TextHandler()); | ||||
elementHandlers.put("rect", new RectHandler()); | elementHandlers.put("rect", new RectHandler()); | ||||
} | } | ||||
private class BoxHandler extends AbstractElementHandler { | |||||
private class ViewportHandler extends AbstractElementHandler { | |||||
public void startElement(Attributes attributes) throws IFException { | public void startElement(Attributes attributes) throws IFException { | ||||
String transform = attributes.getValue("transform"); | String transform = attributes.getValue("transform"); | ||||
AffineTransform[] transforms | AffineTransform[] transforms | ||||
= AffineTransformArrayParser.createAffineTransform(transform); | = 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 { | 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(); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
private static Rectangle getAttributeAsRectangle(Attributes attributes, String name) { | 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) { | if (values.length != 4) { | ||||
throw new IllegalArgumentException("Rectangle must consist of 4 int values!"); | throw new IllegalArgumentException("Rectangle must consist of 4 int values!"); | ||||
} | } |
import org.apache.commons.logging.Log; | import org.apache.commons.logging.Log; | ||||
import org.apache.commons.logging.LogFactory; | import org.apache.commons.logging.LogFactory; | ||||
import org.apache.xmlgraphics.java2d.GraphicContext; | |||||
import org.apache.xmlgraphics.xmp.Metadata; | import org.apache.xmlgraphics.xmp.Metadata; | ||||
import org.apache.xmlgraphics.xmp.schemas.DublinCoreAdapter; | import org.apache.xmlgraphics.xmp.schemas.DublinCoreAdapter; | ||||
import org.apache.xmlgraphics.xmp.schemas.DublinCoreSchema; | import org.apache.xmlgraphics.xmp.schemas.DublinCoreSchema; | ||||
import org.apache.fop.apps.FOPException; | import org.apache.fop.apps.FOPException; | ||||
import org.apache.fop.apps.MimeConstants; | import org.apache.fop.apps.MimeConstants; | ||||
import org.apache.fop.area.Block; | import org.apache.fop.area.Block; | ||||
import org.apache.fop.area.BlockViewport; | |||||
import org.apache.fop.area.CTM; | import org.apache.fop.area.CTM; | ||||
import org.apache.fop.area.OffDocumentExtensionAttachment; | import org.apache.fop.area.OffDocumentExtensionAttachment; | ||||
import org.apache.fop.area.OffDocumentItem; | import org.apache.fop.area.OffDocumentItem; | ||||
import org.apache.fop.area.PageSequence; | import org.apache.fop.area.PageSequence; | ||||
import org.apache.fop.area.PageViewport; | import org.apache.fop.area.PageViewport; | ||||
import org.apache.fop.area.RegionViewport; | |||||
import org.apache.fop.area.Trait; | import org.apache.fop.area.Trait; | ||||
import org.apache.fop.area.inline.AbstractTextArea; | import org.apache.fop.area.inline.AbstractTextArea; | ||||
import org.apache.fop.area.inline.Image; | import org.apache.fop.area.inline.Image; | ||||
import org.apache.fop.area.inline.SpaceArea; | import org.apache.fop.area.inline.SpaceArea; | ||||
import org.apache.fop.area.inline.TextArea; | 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.area.inline.WordArea; | ||||
import org.apache.fop.fo.extensions.ExtensionAttachment; | import org.apache.fop.fo.extensions.ExtensionAttachment; | ||||
import org.apache.fop.fo.extensions.xmp.XMPMetadata; | import org.apache.fop.fo.extensions.xmp.XMPMetadata; | ||||
private boolean inPageSequence = false; | private boolean inPageSequence = false; | ||||
private Stack graphicContextStack = new Stack(); | private Stack graphicContextStack = new Stack(); | ||||
private GraphicContext graphicContext = new GraphicContext(); | |||||
private Stack viewportDimensionStack = new Stack(); | |||||
private IFGraphicContext graphicContext = new IFGraphicContext(); | |||||
private Metadata documentMetadata; | private Metadata documentMetadata; | ||||
/** {@inheritDoc} */ | /** {@inheritDoc} */ | ||||
protected void saveGraphicsState() { | protected void saveGraphicsState() { | ||||
graphicContextStack.push(graphicContext); | graphicContextStack.push(graphicContext); | ||||
graphicContext = (GraphicContext)graphicContext.clone(); | |||||
graphicContext = (IFGraphicContext)graphicContext.clone(); | |||||
} | } | ||||
/** {@inheritDoc} */ | /** {@inheritDoc} */ | ||||
protected void restoreGraphicsState() { | 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} */ | /** {@inheritDoc} */ | ||||
log.debug("Block.FIXED --> restoring context after break-out"); | log.debug("Block.FIXED --> restoring context after break-out"); | ||||
for (int i = 0, c = breakOutList.size(); i < c; i++) { | for (int i = 0, c = breakOutList.size(); i < c; i++) { | ||||
saveGraphicsState(); | saveGraphicsState(); | ||||
this.graphicContext = (GraphicContext)breakOutList.get(i); | |||||
this.graphicContext = (IFGraphicContext)breakOutList.get(i); | |||||
} | } | ||||
} | } | ||||
/** {@inheritDoc} */ | /** {@inheritDoc} */ | ||||
protected void concatenateTransformationMatrix(AffineTransform at) { | protected void concatenateTransformationMatrix(AffineTransform at) { | ||||
if (!at.isIdentity()) { | 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} */ | /** {@inheritDoc} */ | ||||
protected void beginTextObject() { | protected void beginTextObject() { | ||||
// TODO Auto-generated method stub | |||||
//nop - Ignore, handled by painter internally | |||||
} | } | ||||
/** {@inheritDoc} */ | /** {@inheritDoc} */ | ||||
protected void endTextObject() { | 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} */ | /** {@inheritDoc} */ | ||||
protected void startVParea(CTM ctm, Rectangle2D clippingRect) { | protected void startVParea(CTM ctm, Rectangle2D clippingRect) { | ||||
if (log.isDebugEnabled()) { | if (log.isDebugEnabled()) { | ||||
log.debug("startVParea() ctm=" + ctm + ", rect=" + clippingRect); | |||||
log.debug("startVParea() ctm=" + ctm + ", clippingRect=" + clippingRect); | |||||
} | } | ||||
saveGraphicsState(); | saveGraphicsState(); | ||||
AffineTransform at = new AffineTransform(ctm.toArray()); | AffineTransform at = new AffineTransform(ctm.toArray()); | ||||
graphicContext.transform(at); | graphicContext.transform(at); | ||||
try { | 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) { | } catch (IFException e) { | ||||
handleIFException(e); | handleIFException(e); | ||||
} | } | ||||
protected void endVParea() { | protected void endVParea() { | ||||
log.debug("endVParea()"); | log.debug("endVParea()"); | ||||
try { | try { | ||||
painter.endBox(); | |||||
painter.endViewport(); | |||||
} catch (IFException e) { | } catch (IFException e) { | ||||
handleIFException(e); | handleIFException(e); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
/* | |||||
protected void renderReferenceArea(Block block) { | protected void renderReferenceArea(Block block) { | ||||
// TODO Auto-generated method stub | // TODO Auto-generated method stub | ||||
} | |||||
}*/ | |||||
/** {@inheritDoc} */ | /** {@inheritDoc} */ | ||||
protected void renderBlock(Block block) { | protected void renderBlock(Block block) { | ||||
protected void drawImage(String url, Rectangle2D pos, Map foreignAttributes) { | protected void drawImage(String url, Rectangle2D pos, Map foreignAttributes) { | ||||
// TODO Auto-generated method stub | // TODO Auto-generated method stub | ||||
log.warn("drawImage() NYI"); | |||||
} | } | ||||
protected void clip() { | protected void clip() { | ||||
// TODO Auto-generated method stub | // TODO Auto-generated method stub | ||||
log.warn("clip() NYI"); | |||||
} | } | ||||
protected void clipRect(float x, float y, float width, float height) { | protected void clipRect(float x, float y, float width, float height) { | ||||
// TODO Auto-generated method stub | // TODO Auto-generated method stub | ||||
log.warn("clipRect() NYI"); | |||||
} | } | ||||
protected void closePath() { | protected void closePath() { | ||||
// TODO Auto-generated method stub | // TODO Auto-generated method stub | ||||
log.warn("closePath() NYI"); | |||||
} | } | ||||
protected void drawBorderLine(float x1, float y1, float x2, float y2, boolean horz, | protected void drawBorderLine(float x1, float y1, float x2, float y2, boolean horz, | ||||
boolean startOrBefore, int style, Color col) { | boolean startOrBefore, int style, Color col) { | ||||
// TODO Auto-generated method stub | // 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) { | private Rectangle toMillipointRectangle(float x, float y, float width, float height) { | ||||
/** {@inheritDoc} */ | /** {@inheritDoc} */ | ||||
protected void moveTo(float x, float y) { | protected void moveTo(float x, float y) { | ||||
// TODO Auto-generated method stub | // TODO Auto-generated method stub | ||||
log.warn("moveTo() NYI"); | |||||
} | } | ||||
/** {@inheritDoc} */ | /** {@inheritDoc} */ | ||||
protected void lineTo(float x, float y) { | protected void lineTo(float x, float y) { | ||||
// TODO Auto-generated method stub | // TODO Auto-generated method stub | ||||
log.warn("lineTo() NYI"); | |||||
} | } | ||||
/** {@inheritDoc} */ | /** {@inheritDoc} */ |
} | } | ||||
/** {@inheritDoc} */ | /** {@inheritDoc} */ | ||||
public void startBox(AffineTransform transform, Dimension size, boolean clip) | |||||
public void startViewport(AffineTransform transform, Dimension size, Rectangle clipRect) | |||||
throws IFException { | throws IFException { | ||||
StringBuffer sb = new StringBuffer(); | StringBuffer sb = new StringBuffer(); | ||||
toString(transform, sb); | toString(transform, sb); | ||||
startBox(sb.toString(), size, clip); | |||||
startViewport(sb.toString(), size, clipRect); | |||||
} | } | ||||
/** {@inheritDoc} */ | /** {@inheritDoc} */ | ||||
public void startBox(AffineTransform[] transforms, Dimension size, boolean clip) | |||||
public void startViewport(AffineTransform[] transforms, Dimension size, Rectangle clipRect) | |||||
throws IFException { | throws IFException { | ||||
StringBuffer sb = new StringBuffer(); | StringBuffer sb = new StringBuffer(); | ||||
for (int i = 0, c = transforms.length; i < c; i++) { | for (int i = 0, c = transforms.length; i < c; i++) { | ||||
} | } | ||||
toString(transforms[i], sb); | 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 { | try { | ||||
AttributesImpl atts = new AttributesImpl(); | 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) { | } catch (SAXException e) { | ||||
throw new IFException("SAX error in startBox()", e); | |||||
throw new IFException("SAX error in startGroup()", e); | |||||
} | } | ||||
} | } | ||||
/** {@inheritDoc} */ | /** {@inheritDoc} */ | ||||
public void endBox() throws IFException { | |||||
public void endGroup() throws IFException { | |||||
try { | try { | ||||
endElement(EL_BOX); | |||||
endElement(EL_GROUP); | |||||
} catch (SAXException e) { | } catch (SAXException e) { | ||||
throw new IFException("SAX error in endBox()", e); | |||||
throw new IFException("SAX error in endGroup()", e); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
/** {@inheritDoc} */ | /** {@inheritDoc} */ | ||||
public void startBox(AffineTransform transform, Dimension size, boolean clip) | |||||
public void startViewport(AffineTransform transform, Dimension size, Rectangle clipRect) | |||||
throws IFException { | throws IFException { | ||||
saveGraphicsState(); | saveGraphicsState(); | ||||
currentStream.add(CTMHelper.toPDFString(transform, true) + " cm\n"); | 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} */ | /** {@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} */ | /** {@inheritDoc} */ | ||||
public void endBox() throws IFException { | |||||
public void endViewport() throws IFException { | |||||
restoreGraphicsState(); | restoreGraphicsState(); | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* 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) | * @param value the value (in millipoints) | ||||
* @return the formatted value | * @return the formatted value | ||||
*/ | */ | ||||
} | } | ||||
textutil.writeTJMappedChar(ch); | textutil.writeTJMappedChar(ch); | ||||
if (dx != null && i < dxl) { | |||||
if (dx != null && i < dxl - 1) { | |||||
glyphAdjust += dx[i + 1]; | glyphAdjust += dx[i + 1]; | ||||
} | } | ||||
} | } | ||||
/** {@inheritDoc} */ | /** {@inheritDoc} */ | ||||
public void startBox(AffineTransform transform, Dimension size, boolean clip) | |||||
public void startViewport(AffineTransform transform, Dimension size, Rectangle clipRect) | |||||
throws IFException { | throws IFException { | ||||
StringBuffer sb = new StringBuffer(); | StringBuffer sb = new StringBuffer(); | ||||
toString(transform, sb); | 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(); | StringBuffer sb = new StringBuffer(); | ||||
for (int i = 0, c = transforms.length; i < c; i++) { | for (int i = 0, c = transforms.length; i < c; i++) { | ||||
if (i > 0) { | if (i > 0) { | ||||
} | } | ||||
toString(transforms[i], sb); | 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 { | try { | ||||
establish(MODE_NORMAL); | establish(MODE_NORMAL); | ||||
AttributesImpl atts = new AttributesImpl(); | 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); | 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) { | } catch (SAXException e) { | ||||
throw new IFException("SAX error in startBox()", e); | throw new IFException("SAX error in startBox()", e); | ||||
} | } | ||||
} | } | ||||
/** {@inheritDoc} */ | /** {@inheritDoc} */ | ||||
public void endBox() throws IFException { | |||||
public void endViewport() throws IFException { | |||||
try { | try { | ||||
establish(MODE_NORMAL); | establish(MODE_NORMAL); | ||||
endElement("svg"); | |||||
endElement("g"); | endElement("g"); | ||||
} catch (SAXException e) { | } catch (SAXException e) { | ||||
throw new IFException("SAX error in endBox()", e); | throw new IFException("SAX error in endBox()", e); | ||||
} | } | ||||
} | } | ||||
/** {@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} */ | /** {@inheritDoc} */ | ||||
public void startImage(Rectangle rect) throws IFException { | public void startImage(Rectangle rect) throws IFException { | ||||
//establish(MODE_NORMAL); | //establish(MODE_NORMAL); |
public void startPage(int index, String name, Dimension size) throws IFException { | public void startPage(int index, String name, Dimension size) throws IFException { | ||||
OutputStream out; | OutputStream out; | ||||
try { | 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) { | } catch (IOException ioe) { | ||||
throw new IFException("I/O exception while setting up output file", ioe); | throw new IFException("I/O exception while setting up output file", ioe); | ||||
} | } |