You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by je...@apache.org on 2008/07/16 11:10:04 UTC
svn commit: r677204 [2/2] - in
/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src:
java/META-INF/services/ java/org/apache/fop/cli/
java/org/apache/fop/render/ java/org/apache/fop/render/iform/
java/org/apache/fop/render/intermediate/ java/org/apache...
Added: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFRendererMaker.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFRendererMaker.java?rev=677204&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFRendererMaker.java (added)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFRendererMaker.java Wed Jul 16 02:10:02 2008
@@ -0,0 +1,56 @@
+/*
+ * 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.fop.apps.FOUserAgent;
+import org.apache.fop.apps.MimeConstants;
+import org.apache.fop.render.AbstractRendererMaker;
+import org.apache.fop.render.PrintRendererConfigurator;
+import org.apache.fop.render.Renderer;
+import org.apache.fop.render.RendererConfigurator;
+
+/**
+ * RendererMaker for the Intermediate Format Renderer.
+ */
+public class IFRendererMaker extends AbstractRendererMaker {
+
+ private static final String[] MIMES = new String[] {MimeConstants.MIME_FOP_IF};
+
+ /**{@inheritDoc} */
+ public Renderer makeRenderer(FOUserAgent userAgent) {
+ return new IFRenderer();
+ }
+
+ /**{@inheritDoc} */
+ public RendererConfigurator getConfigurator(FOUserAgent userAgent) {
+ return new PrintRendererConfigurator(userAgent);
+ }
+
+ /** {@inheritDoc} */
+ public boolean needsOutputStream() {
+ return false;
+ }
+
+ /** {@inheritDoc} */
+ public String[] getSupportedMimeTypes() {
+ return MIMES;
+ }
+
+}
Propchange: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFRendererMaker.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFRendererMaker.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFSerializer.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFSerializer.java?rev=677204&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFSerializer.java (added)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFSerializer.java Wed Jul 16 02:10:02 2008
@@ -0,0 +1,363 @@
+/*
+ * 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 java.awt.Color;
+import java.awt.Dimension;
+import java.awt.Paint;
+import java.awt.Rectangle;
+import java.awt.geom.AffineTransform;
+
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.AttributesImpl;
+
+import org.apache.xmlgraphics.util.XMLizable;
+
+import org.apache.fop.util.ColorUtil;
+
+/**
+ * IFPainter implementation that serializes the intermediate format to XML.
+ */
+public class IFSerializer extends AbstractXMLWritingIFPainter implements IFConstants {
+
+ /**
+ * Default constructor.
+ */
+ public IFSerializer() {
+ }
+
+ /** {@inheritDoc} */
+ protected String getMainNamespace() {
+ return NAMESPACE;
+ }
+
+ /** {@inheritDoc} */
+ public boolean supportsPagesOutOfOrder() {
+ return false;
+ //Theoretically supported but disabled to improve performance when
+ //rendering the IF to the final format later on
+ }
+
+ /** {@inheritDoc} */
+ public void startDocument() throws IFException {
+ try {
+ handler.startDocument();
+ handler.startPrefixMapping("", NAMESPACE);
+ handler.startPrefixMapping(XLINK_PREFIX, XLINK_NAMESPACE);
+ startElement(EL_DOCUMENT);
+ } catch (SAXException e) {
+ throw new IFException("SAX error in startDocument()", e);
+ }
+ }
+
+ /** {@inheritDoc} */
+ public void startDocumentHeader() throws IFException {
+ try {
+ startElement(EL_HEADER);
+ } catch (SAXException e) {
+ throw new IFException("SAX error in startDocumentHeader()", e);
+ }
+ }
+
+ /** {@inheritDoc} */
+ public void endDocumentHeader() throws IFException {
+ try {
+ endElement(EL_HEADER);
+ } catch (SAXException e) {
+ throw new IFException("SAX error in startDocumentHeader()", e);
+ }
+ }
+
+ /** {@inheritDoc} */
+ public void endDocument() throws IFException {
+ try {
+ endElement(EL_DOCUMENT);
+ handler.endDocument();
+ } catch (SAXException e) {
+ throw new IFException("SAX error in endDocument()", e);
+ }
+ }
+
+ /** {@inheritDoc} */
+ public void startPageSequence(String id) throws IFException {
+ try {
+ AttributesImpl atts = new AttributesImpl();
+ if (id != null) {
+ atts.addAttribute(XML_NAMESPACE, "id", "xml:id", CDATA, id);
+ }
+ startElement(EL_PAGE_SEQUENCE, atts);
+ } catch (SAXException e) {
+ throw new IFException("SAX error in startPageSequence()", e);
+ }
+ }
+
+ /** {@inheritDoc} */
+ public void endPageSequence() throws IFException {
+ try {
+ endElement(EL_PAGE_SEQUENCE);
+ } catch (SAXException e) {
+ throw new IFException("SAX error in endPageSequence()", e);
+ }
+ }
+
+ /** {@inheritDoc} */
+ public void startPage(int index, String name, Dimension size) throws IFException {
+ try {
+ AttributesImpl atts = new AttributesImpl();
+ atts.addAttribute("", "index", "index", CDATA, Integer.toString(index));
+ atts.addAttribute("", "name", "name", CDATA, name);
+ atts.addAttribute("", "width", "width", CDATA, Integer.toString(size.width));
+ atts.addAttribute("", "height", "height", CDATA, Integer.toString(size.height));
+ startElement(EL_PAGE, atts);
+ } catch (SAXException e) {
+ throw new IFException("SAX error in startPage()", e);
+ }
+ }
+
+ /** {@inheritDoc} */
+ public void startPageHeader() throws IFException {
+ try {
+ startElement(EL_PAGE_HEADER);
+ } catch (SAXException e) {
+ throw new IFException("SAX error in startPageHeader()", e);
+ }
+ }
+
+ /** {@inheritDoc} */
+ public void endPageHeader() throws IFException {
+ try {
+ endElement(EL_PAGE_HEADER);
+ } catch (SAXException e) {
+ throw new IFException("SAX error in endPageHeader()", e);
+ }
+ }
+
+ /** {@inheritDoc} */
+ public void startPageContent() throws IFException {
+ try {
+ startElement(EL_PAGE_CONTENT);
+ } catch (SAXException e) {
+ throw new IFException("SAX error in startPageContent()", e);
+ }
+ }
+
+ /** {@inheritDoc} */
+ public void endPageContent() throws IFException {
+ try {
+ endElement(EL_PAGE_CONTENT);
+ } catch (SAXException e) {
+ throw new IFException("SAX error in endPageContent()", e);
+ }
+ }
+
+ /** {@inheritDoc} */
+ public void startPageTrailer() throws IFException {
+ try {
+ startElement(EL_PAGE_TRAILER);
+ } catch (SAXException e) {
+ throw new IFException("SAX error in startPageTrailer()", e);
+ }
+ }
+
+ /** {@inheritDoc} */
+ public void endPageTrailer() throws IFException {
+ try {
+ endElement(EL_PAGE_TRAILER);
+ } catch (SAXException e) {
+ throw new IFException("SAX error in endPageTrailer()", e);
+ }
+ }
+
+ /** {@inheritDoc} */
+ public void endPage() throws IFException {
+ try {
+ endElement(EL_PAGE);
+ } catch (SAXException e) {
+ throw new IFException("SAX error in endPage()", e);
+ }
+ }
+
+ /** {@inheritDoc} */
+ public void startBox(AffineTransform transform, Dimension size, boolean clip)
+ throws IFException {
+ StringBuffer sb = new StringBuffer();
+ toString(transform, sb);
+ startBox(sb.toString(), size, clip);
+ }
+
+ /** {@inheritDoc} */
+ public void startBox(AffineTransform[] transforms, Dimension size, boolean clip)
+ 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);
+ }
+ startBox(sb.toString(), size, clip);
+ }
+
+ private void startBox(String transform, Dimension size, boolean clip) 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 (clip) {
+ atts.addAttribute("", "clip", "clip", CDATA, "true");
+ }
+ startElement(EL_BOX, atts);
+ } catch (SAXException e) {
+ throw new IFException("SAX error in startBox()", e);
+ }
+ }
+
+ /** {@inheritDoc} */
+ public void endBox() throws IFException {
+ try {
+ endElement(EL_BOX);
+ } catch (SAXException e) {
+ throw new IFException("SAX error in endBox()", e);
+ }
+ }
+
+ /** {@inheritDoc} */
+ public void startImage(Rectangle rect) throws IFException {
+ // TODO Auto-generated method stub
+
+ }
+
+ /** {@inheritDoc} */
+ public void drawImage(String uri, Rectangle rect) throws IFException {
+ // TODO Auto-generated method stub
+
+ }
+
+ /** {@inheritDoc} */
+ public void endImage() throws IFException {
+ // TODO Auto-generated method stub
+
+ }
+
+ /** {@inheritDoc} */
+ public void addTarget(String name, int x, int y) throws IFException {
+ // TODO Auto-generated method stub
+
+ }
+
+ private static String toString(Paint paint) {
+ if (paint instanceof Color) {
+ return ColorUtil.colorToString((Color)paint);
+ } else {
+ throw new UnsupportedOperationException("Paint not supported: " + paint);
+ }
+ }
+
+ /** {@inheritDoc} */
+ public void drawRect(Rectangle rect, Paint fill, Color stroke) throws IFException {
+ if (fill == null && stroke == null) {
+ return;
+ }
+ try {
+ AttributesImpl atts = new AttributesImpl();
+ atts.addAttribute("", "x", "x", CDATA, Integer.toString(rect.x));
+ atts.addAttribute("", "y", "y", CDATA, Integer.toString(rect.y));
+ atts.addAttribute("", "width", "width", CDATA, Integer.toString(rect.width));
+ atts.addAttribute("", "height", "height", CDATA, Integer.toString(rect.height));
+ if (fill != null) {
+ atts.addAttribute("", "fill", "fill", CDATA, toString(fill));
+ }
+ if (stroke != null) {
+ atts.addAttribute("", "stroke", "sroke", CDATA, toString(stroke));
+ }
+ element("rect", atts);
+ } catch (SAXException e) {
+ throw new IFException("SAX error in drawRect()", e);
+ }
+ }
+
+ /** {@inheritDoc} */
+ public void drawText(int x, int y, int[] dx, int[] dy, String text) throws IFException {
+ try {
+ AttributesImpl atts = new AttributesImpl();
+ atts.addAttribute("", "x", "x", CDATA, Integer.toString(x));
+ atts.addAttribute("", "y", "y", CDATA, Integer.toString(y));
+ if (dx != null) {
+ atts.addAttribute("", "dx", "dx", CDATA, toString(dx));
+ }
+ if (dy != null) {
+ atts.addAttribute("", "dy", "dy", CDATA, toString(dy));
+ }
+ startElement("text", atts);
+ char[] chars = text.toCharArray();
+ handler.characters(chars, 0, chars.length);
+ endElement("text");
+ } catch (SAXException e) {
+ throw new IFException("SAX error in setFont()", e);
+ }
+ }
+
+ /** {@inheritDoc} */
+ public void setFont(String family, String style, Integer weight, String variant, Integer size,
+ Color color) throws IFException {
+ try {
+ AttributesImpl atts = new AttributesImpl();
+ if (family != null) {
+ atts.addAttribute("", "family", "family", CDATA, family);
+ }
+ if (style != null) {
+ atts.addAttribute("", "style", "style", CDATA, style);
+ }
+ if (weight != null) {
+ atts.addAttribute("", "weight", "weight", CDATA, weight.toString());
+ }
+ if (variant != null) {
+ atts.addAttribute("", "variant", "variant", CDATA, variant);
+ }
+ if (size != null) {
+ atts.addAttribute("", "size", "size", CDATA, size.toString());
+ }
+ if (color != null) {
+ atts.addAttribute("", "color", "color", CDATA, toString(color));
+ }
+ element("font", atts);
+ } catch (SAXException e) {
+ throw new IFException("SAX error in setFont()", e);
+ }
+ }
+
+ /** {@inheritDoc} */
+ public void handleExtensionObject(Object extension) throws IFException {
+ if (extension instanceof XMLizable) {
+ try {
+ ((XMLizable)extension).toSAX(this.handler);
+ } catch (SAXException e) {
+ throw new IFException("SAX error while handling extension object", e);
+ }
+ } else {
+ throw new UnsupportedOperationException(
+ "Don't know how to handle extension object: " + extension);
+ }
+ }
+
+}
Propchange: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFSerializer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFSerializer.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFState.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFState.java?rev=677204&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFState.java (added)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFState.java Wed Jul 16 02:10:02 2008
@@ -0,0 +1,188 @@
+/*
+ * 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 java.awt.Color;
+
+public class IFState {
+
+ private IFState parent;
+
+ private String fontFamily;
+ private int fontSize;
+ private String fontStyle;
+ private int fontWeight;
+ private String fontVariant;
+ private boolean fontChanged = true;
+
+ private Color textColor;
+
+ private IFState() {
+ //nop
+ }
+
+ private IFState(IFState parent) {
+ this.parent = parent;
+
+ this.fontFamily = parent.fontFamily;
+ this.fontSize = parent.fontSize;
+ this.fontStyle = parent.fontStyle;
+ this.fontWeight = parent.fontWeight;
+ this.fontVariant = parent.fontVariant;
+
+ this.textColor = parent.textColor;
+ }
+
+ public static IFState create() {
+ return new IFState();
+ }
+
+ public IFState push() {
+ return new IFState(this);
+ }
+
+ public IFState pop() {
+ return this.parent;
+ }
+
+ public boolean isFontChanged() {
+ return this.fontChanged;
+ }
+
+ public void resetFontChanged() {
+ this.fontChanged = false;
+ }
+
+ /**
+ * Returns the font family.
+ * @return the font family
+ */
+ public String getFontFamily() {
+ return fontFamily;
+ }
+
+ /**
+ * Sets the font family.
+ * @param family the new font family
+ */
+ public void setFontFamily(String family) {
+ if (!family.equals(this.fontFamily)) {
+ this.fontChanged = true;
+ }
+ this.fontFamily = family;
+ }
+
+ /**
+ * Returns the font size.
+ * @return the font size (in mpt)
+ */
+ public int getFontSize() {
+ return fontSize;
+ }
+
+ /**
+ * Sets the font size.
+ * @param size the new font size (in mpt)
+ */
+ public void setFontSize(int size) {
+ if (size != this.fontSize) {
+ this.fontChanged = true;
+ }
+ this.fontSize = size;
+ }
+
+ /**
+ * Returns the font style.
+ * @return the font style
+ */
+ public String getFontStyle() {
+ return fontStyle;
+ }
+
+ /**
+ * Set the font style
+ * @param style the new font style
+ */
+ public void setFontStyle(String style) {
+ if (!style.equals(this.fontStyle)) {
+ this.fontChanged = true;
+ }
+ this.fontStyle = style;
+ }
+
+ /**
+ * Returns the font weight.
+ * @return the font weight
+ */
+ public int getFontWeight() {
+ return fontWeight;
+ }
+
+ /**
+ * Sets the font weight
+ * @param weight the new font weight
+ */
+ public void setFontWeight(int weight) {
+ if (weight != this.fontWeight) {
+ this.fontChanged = true;
+ }
+ this.fontWeight = weight;
+ }
+
+ /**
+ * Returns the font variant.
+ * @return the font variant
+ */
+ public String getFontVariant() {
+ return fontVariant;
+ }
+
+ /**
+ * Sets the font variant.
+ * @param variant the new font variant
+ */
+ public void setFontVariant(String variant) {
+ if (!variant.equals(this.fontVariant)) {
+ this.fontChanged = true;
+ }
+ this.fontVariant = variant;
+ }
+
+ /**
+ * Returns the text color.
+ * @return the text color
+ */
+ public Color getTextColor() {
+ return textColor;
+ }
+
+ /**
+ * Sets the text color.
+ * @param color the new text color
+ */
+ public void setTextColor(Color color) {
+ if (!color.equals(this.textColor)) {
+ this.fontChanged = true;
+ }
+ this.textColor = color;
+ }
+
+
+}
Propchange: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFState.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFState.java
------------------------------------------------------------------------------
svn:keywords = Id
Modified: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/util/DelegatingContentHandler.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/util/DelegatingContentHandler.java?rev=677204&r1=677203&r2=677204&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/util/DelegatingContentHandler.java (original)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/util/DelegatingContentHandler.java Wed Jul 16 02:10:02 2008
@@ -38,9 +38,8 @@
* <p>
* The ContentHandler is the only instance that is required. All others (DTDHandler,
* EntityResolver, LexicalHandler and ErrorHandler) may be ignored.
- *
*/
-public class DelegatingContentHandler
+public class DelegatingContentHandler
implements EntityResolver, DTDHandler, ContentHandler, LexicalHandler, ErrorHandler {
private ContentHandler delegate;
@@ -48,7 +47,7 @@
private DTDHandler dtdHandler;
private LexicalHandler lexicalHandler;
private ErrorHandler errorHandler;
-
+
/**
* Main constructor.
*/
@@ -62,7 +61,7 @@
public ContentHandler getDelegateContentHandler() {
return this.delegate;
}
-
+
/**
* Sets the delegate ContentHandler that all events are forwarded to.
* @param handler the delegate instance
@@ -70,7 +69,7 @@
public void setDelegateContentHandler(ContentHandler handler) {
this.delegate = handler;
}
-
+
/**
* Sets the delegate EntityResolver.
* @param resolver the delegate instance
@@ -78,7 +77,7 @@
public void setDelegateEntityResolver(EntityResolver resolver) {
this.entityResolver = resolver;
}
-
+
/**
* Sets the delegate DTDHandler.
* @param handler the delegate instance
@@ -86,7 +85,7 @@
public void setDelegateDTDHandler(DTDHandler handler) {
this.dtdHandler = handler;
}
-
+
/**
* Sets the delegate LexicalHandler.
* @param handler the delegate instance
@@ -94,7 +93,7 @@
public void setDelegateLexicalHandler(LexicalHandler handler) {
this.lexicalHandler = handler;
}
-
+
/**
* Sets the delegate ErrorHandler.
* @param handler the delegate instance
@@ -102,13 +101,12 @@
public void setDelegateErrorHandler(ErrorHandler handler) {
this.errorHandler = handler;
}
-
+
// ==== EntityResolver
-
- /**
- * {@inheritDoc}
- */
- public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
+
+ /** {@inheritDoc} */
+ public InputSource resolveEntity(String publicId, String systemId)
+ throws SAXException, IOException {
if (entityResolver != null) {
return entityResolver.resolveEntity(publicId, systemId);
} else {
@@ -118,19 +116,15 @@
// ==== DTDHandler
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
public void notationDecl(String name, String publicId, String systemId) throws SAXException {
if (dtdHandler != null) {
dtdHandler.notationDecl(name, publicId, systemId);
}
}
- /**
- * {@inheritDoc}
- */
- public void unparsedEntityDecl(String name, String publicId, String systemId,
+ /** {@inheritDoc} */
+ public void unparsedEntityDecl(String name, String publicId, String systemId,
String notationName) throws SAXException {
if (dtdHandler != null) {
dtdHandler.unparsedEntityDecl(name, publicId, systemId, notationName);
@@ -138,174 +132,132 @@
}
// ==== ContentHandler
-
- /**
- * {@inheritDoc}
- */
+
+ /** {@inheritDoc} */
public void setDocumentLocator(Locator locator) {
delegate.setDocumentLocator(locator);
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
public void startDocument() throws SAXException {
delegate.startDocument();
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
public void endDocument() throws SAXException {
delegate.endDocument();
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
public void startPrefixMapping(String prefix, String uri) throws SAXException {
delegate.startPrefixMapping(prefix, uri);
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
public void endPrefixMapping(String prefix) throws SAXException {
delegate.endPrefixMapping(prefix);
}
- /**
- * {@inheritDoc}
- */
- public void startElement(String uri, String localName, String qName,
+ /** {@inheritDoc} */
+ public void startElement(String uri, String localName, String qName,
Attributes atts) throws SAXException {
delegate.startElement(uri, localName, qName, atts);
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
public void endElement(String uri, String localName, String qName) throws SAXException {
delegate.endElement(uri, localName, qName);
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
public void characters(char[] ch, int start, int length) throws SAXException {
delegate.characters(ch, start, length);
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException {
delegate.ignorableWhitespace(ch, start, length);
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
public void processingInstruction(String target, String data) throws SAXException {
delegate.processingInstruction(target, data);
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
public void skippedEntity(String name) throws SAXException {
delegate.skippedEntity(name);
}
// ==== LexicalHandler
-
- /**
- * {@inheritDoc}
- */
+
+ /** {@inheritDoc} */
public void startDTD(String name, String publicId, String systemId) throws SAXException {
if (lexicalHandler != null) {
lexicalHandler.startDTD(name, publicId, systemId);
}
-
+
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
public void endDTD() throws SAXException {
if (lexicalHandler != null) {
lexicalHandler.endDTD();
}
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
public void startEntity(String name) throws SAXException {
if (lexicalHandler != null) {
lexicalHandler.startEntity(name);
}
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
public void endEntity(String name) throws SAXException {
if (lexicalHandler != null) {
lexicalHandler.endEntity(name);
}
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
public void startCDATA() throws SAXException {
if (lexicalHandler != null) {
lexicalHandler.startCDATA();
}
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
public void endCDATA() throws SAXException {
if (lexicalHandler != null) {
lexicalHandler.endCDATA();
}
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
public void comment(char[] ch, int start, int length) throws SAXException {
if (lexicalHandler != null) {
lexicalHandler.comment(ch, start, length);
}
}
-
+
// ==== ErrorHandler
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
public void warning(SAXParseException exception) throws SAXException {
if (errorHandler != null) {
errorHandler.warning(exception);
}
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
public void error(SAXParseException exception) throws SAXException {
if (errorHandler != null) {
errorHandler.error(exception);
}
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
public void fatalError(SAXParseException exception) throws SAXException {
if (errorHandler != null) {
errorHandler.fatalError(exception);
Added: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/sandbox/META-INF/services/org.apache.fop.render.intermediate.IFPainter
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/sandbox/META-INF/services/org.apache.fop.render.intermediate.IFPainter?rev=677204&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/sandbox/META-INF/services/org.apache.fop.render.intermediate.IFPainter (added)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/sandbox/META-INF/services/org.apache.fop.render.intermediate.IFPainter Wed Jul 16 02:10:02 2008
@@ -0,0 +1,2 @@
+org.apache.fop.render.svg.SVGPainterMaker
+org.apache.fop.render.svg.SVGPrintPainterMaker
\ No newline at end of file
Added: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/sandbox/org/apache/fop/render/svg/AbstractSVGPainter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/sandbox/org/apache/fop/render/svg/AbstractSVGPainter.java?rev=677204&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/sandbox/org/apache/fop/render/svg/AbstractSVGPainter.java (added)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/sandbox/org/apache/fop/render/svg/AbstractSVGPainter.java Wed Jul 16 02:10:02 2008
@@ -0,0 +1,303 @@
+/*
+ * 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.svg;
+
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.Paint;
+import java.awt.Rectangle;
+import java.awt.geom.AffineTransform;
+
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.AttributesImpl;
+
+import org.apache.xmlgraphics.xmp.Metadata;
+
+import org.apache.fop.render.intermediate.AbstractXMLWritingIFPainter;
+import org.apache.fop.render.intermediate.IFException;
+import org.apache.fop.render.intermediate.IFState;
+import org.apache.fop.util.ColorUtil;
+
+/**
+ * Abstract base class for SVG Painter implementations.
+ */
+public abstract class AbstractSVGPainter extends AbstractXMLWritingIFPainter
+ implements SVGConstants {
+
+ /** Holds the intermediate format state */
+ protected IFState state;
+
+ private static final int MODE_NORMAL = 0;
+ private static final int MODE_TEXT = 1;
+
+ private int mode = MODE_NORMAL;
+
+ /** {@inheritDoc} */
+ protected String getMainNamespace() {
+ return NAMESPACE;
+ }
+
+ /** {@inheritDoc} */
+ public void startDocumentHeader() throws IFException {
+ try {
+ startElement("defs");
+ } catch (SAXException e) {
+ throw new IFException("SAX error in startDocumentHeader()", e);
+ }
+ }
+
+ /** {@inheritDoc} */
+ public void endDocumentHeader() throws IFException {
+ try {
+ endElement("defs");
+ } catch (SAXException e) {
+ throw new IFException("SAX error in startDocumentHeader()", e);
+ }
+ }
+
+ /** {@inheritDoc} */
+ public void startPageContent() throws IFException {
+ this.state = IFState.create();
+ }
+
+ /** {@inheritDoc} */
+ public void endPageContent() throws IFException {
+ assert this.state.pop() == null;
+ }
+
+ /** {@inheritDoc} */
+ public void startBox(AffineTransform transform, Dimension size, boolean clip)
+ throws IFException {
+ StringBuffer sb = new StringBuffer();
+ toString(transform, sb);
+ startBox(sb.toString(), size, clip);
+ }
+
+ /** {@inheritDoc} */
+ public void startBox(AffineTransform[] transforms, Dimension size, boolean clip)
+ 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);
+ }
+ startBox(sb.toString(), size, clip);
+ }
+
+ private void startBox(String transform, Dimension size, boolean clip) 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 (clip) {
+ atts.addAttribute("", "clip", "clip", CDATA, "true");
+ }*/
+ startElement("g", atts);
+ } catch (SAXException e) {
+ throw new IFException("SAX error in startBox()", e);
+ }
+ }
+
+ /** {@inheritDoc} */
+ public void endBox() throws IFException {
+ try {
+ establish(MODE_NORMAL);
+ endElement("g");
+ } catch (SAXException e) {
+ throw new IFException("SAX error in endBox()", e);
+ }
+ }
+
+ /** {@inheritDoc} */
+ public void startImage(Rectangle rect) throws IFException {
+ //establish(MODE_NORMAL);
+ // TODO Auto-generated method stub
+
+ }
+
+ /** {@inheritDoc} */
+ public void drawImage(String uri, Rectangle rect) throws IFException {
+ //establish(MODE_NORMAL);
+ // TODO Auto-generated method stub
+
+ }
+
+ /** {@inheritDoc} */
+ public void endImage() throws IFException {
+ // TODO Auto-generated method stub
+
+ }
+
+ /** {@inheritDoc} */
+ public void addTarget(String name, int x, int y) throws IFException {
+ //establish(MODE_NORMAL);
+ // TODO Auto-generated method stub
+
+ }
+
+ private static String toString(Paint paint) {
+ //TODO Paint serialization: Fine-tune and extend!
+ if (paint instanceof Color) {
+ return ColorUtil.colorToString((Color)paint);
+ } else {
+ throw new UnsupportedOperationException("Paint not supported: " + paint);
+ }
+ }
+
+ /** {@inheritDoc} */
+ public void drawRect(Rectangle rect, Paint fill, Color stroke) throws IFException {
+ if (fill == null && stroke == null) {
+ return;
+ }
+ try {
+ establish(MODE_NORMAL);
+ AttributesImpl atts = new AttributesImpl();
+ atts.addAttribute("", "x", "x", CDATA, Integer.toString(rect.x));
+ atts.addAttribute("", "y", "y", CDATA, Integer.toString(rect.y));
+ atts.addAttribute("", "width", "width", CDATA, Integer.toString(rect.width));
+ atts.addAttribute("", "height", "height", CDATA, Integer.toString(rect.height));
+ if (fill != null) {
+ atts.addAttribute("", "fill", "fill", CDATA, toString(fill));
+ }
+ if (stroke != null) {
+ atts.addAttribute("", "stroke", "sroke", CDATA, toString(stroke));
+ }
+ element("rect", atts);
+ } catch (SAXException e) {
+ throw new IFException("SAX error in drawRect()", e);
+ }
+ }
+
+ /** {@inheritDoc} */
+ public void drawText(int x, int y, int[] dx, int[] dy, String text) throws IFException {
+ try {
+ establish(MODE_TEXT);
+ AttributesImpl atts = new AttributesImpl();
+ atts.addAttribute("", "x", "x", CDATA, Integer.toString(x));
+ atts.addAttribute("", "y", "y", CDATA, Integer.toString(y));
+ if (dx != null) {
+ atts.addAttribute("", "dx", "dx", CDATA, toString(dx));
+ }
+ if (dy != null) {
+ atts.addAttribute("", "dy", "dy", CDATA, toString(dy));
+ }
+ startElement("text", atts);
+ char[] chars = text.toCharArray();
+ handler.characters(chars, 0, chars.length);
+ endElement("text");
+ } catch (SAXException e) {
+ throw new IFException("SAX error in setFont()", e);
+ }
+ }
+
+ /** {@inheritDoc} */
+ public void setFont(String family, String style, Integer weight, String variant, Integer size,
+ Color color) throws IFException {
+ if (family != null) {
+ state.setFontFamily(family);
+ }
+ if (style != null) {
+ state.setFontStyle(style);
+ }
+ if (weight != null) {
+ state.setFontWeight(weight.intValue());
+ }
+ if (variant != null) {
+ state.setFontVariant(variant);
+ }
+ if (size != null) {
+ state.setFontSize(size.intValue());
+ }
+ if (color != null) {
+ state.setTextColor(color);
+ }
+ }
+
+ private void leaveTextMode() throws SAXException {
+ assert this.mode == MODE_TEXT;
+ endElement("g");
+ this.mode = MODE_NORMAL;
+ }
+
+ private void establish(int newMode) throws SAXException {
+ switch (newMode) {
+ case MODE_TEXT:
+ enterTextMode();
+ break;
+ default:
+ if (this.mode == MODE_TEXT) {
+ leaveTextMode();
+ }
+ }
+ }
+
+ private void enterTextMode() throws SAXException {
+ if (state.isFontChanged() && this.mode == MODE_TEXT) {
+ leaveTextMode();
+ }
+ if (this.mode != MODE_TEXT) {
+ startTextGroup();
+ this.mode = MODE_TEXT;
+ }
+ }
+
+ private void startTextGroup() throws SAXException {
+ AttributesImpl atts = new AttributesImpl();
+ atts.addAttribute("", "font-family", "font-family",
+ CDATA, state.getFontFamily());
+ atts.addAttribute("", "font-style", "font-style",
+ CDATA, state.getFontStyle());
+ atts.addAttribute("", "font-weight", "font-weight",
+ CDATA, Integer.toString(state.getFontWeight()));
+ atts.addAttribute("", "font-variant", "font-variant",
+ CDATA, state.getFontVariant());
+ atts.addAttribute("", "font-size", "font-size",
+ CDATA, Integer.toString(state.getFontSize()));
+ atts.addAttribute("", "fill", "fill",
+ CDATA, toString(state.getTextColor()));
+ startElement("g", atts);
+ state.resetFontChanged();
+ }
+
+ /** {@inheritDoc} */
+ public void handleExtensionObject(Object extension) throws IFException {
+ if (extension instanceof Metadata) {
+ Metadata meta = (Metadata)extension;
+ try {
+ establish(MODE_NORMAL);
+ startElement("metadata");
+ meta.toSAX(this.handler);
+ endElement("metadata");
+ } catch (SAXException e) {
+ throw new IFException("SAX error while handling extension object", e);
+ }
+ } else {
+ throw new UnsupportedOperationException(
+ "Don't know how to handle extension object: " + extension);
+ }
+ }
+}
Propchange: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/sandbox/org/apache/fop/render/svg/AbstractSVGPainter.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/sandbox/org/apache/fop/render/svg/AbstractSVGPainter.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/sandbox/org/apache/fop/render/svg/SVGConstants.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/sandbox/org/apache/fop/render/svg/SVGConstants.java?rev=677204&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/sandbox/org/apache/fop/render/svg/SVGConstants.java (added)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/sandbox/org/apache/fop/render/svg/SVGConstants.java Wed Jul 16 02:10:02 2008
@@ -0,0 +1,49 @@
+/*
+ * 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.svg;
+
+import org.apache.fop.apps.MimeConstants;
+
+/**
+ * Constants for the intermediate format.
+ */
+public interface SVGConstants {
+
+ /** MIME type for SVG. */
+ String MIME_TYPE = MimeConstants.MIME_SVG;
+
+ /** MIME type for SVG Print. */
+ String MIME_SVG_PRINT = MimeConstants.MIME_SVG + ";profile=print";
+
+ /** File extension for SVG. */
+ String FILE_EXTENSION_SVG = "svg";
+
+ /** XML namespace for SVG. */
+ String NAMESPACE = "http://www.w3.org/2000/svg";
+
+ /** XML namespace. */
+ String XML_NAMESPACE = "http://www.w3.org/XML/1998/namespace";
+
+ /** Namespace prefix for XLink */
+ String XLINK_PREFIX = "xlink";
+ /** XML namespace for XLink */
+ String XLINK_NAMESPACE = "http://www.w3.org/1999/xlink";
+
+}
Propchange: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/sandbox/org/apache/fop/render/svg/SVGConstants.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/sandbox/org/apache/fop/render/svg/SVGConstants.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/sandbox/org/apache/fop/render/svg/SVGPainter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/sandbox/org/apache/fop/render/svg/SVGPainter.java?rev=677204&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/sandbox/org/apache/fop/render/svg/SVGPainter.java (added)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/sandbox/org/apache/fop/render/svg/SVGPainter.java Wed Jul 16 02:10:02 2008
@@ -0,0 +1,254 @@
+/*
+ * 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.svg;
+
+import java.awt.Dimension;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.Result;
+import javax.xml.transform.Source;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.dom.DOMResult;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.sax.SAXResult;
+import javax.xml.transform.sax.TransformerHandler;
+import javax.xml.transform.stream.StreamResult;
+
+import org.w3c.dom.Document;
+
+import org.xml.sax.ContentHandler;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.AttributesImpl;
+
+import org.apache.commons.io.IOUtils;
+
+import org.apache.fop.render.bitmap.MultiFileRenderingUtil;
+import org.apache.fop.render.intermediate.DelegatingFragmentContentHandler;
+import org.apache.fop.render.intermediate.IFException;
+
+/**
+ * IFPainter implementation that writes SVG.
+ */
+public class SVGPainter extends AbstractSVGPainter {
+
+ /** Helper class for generating multiple files */
+ private MultiFileRenderingUtil multiFileUtil;
+
+ private StreamResult firstStream;
+ private StreamResult currentStream;
+
+ private Document reusedParts;
+
+ /**
+ * Default constructor.
+ */
+ public SVGPainter() {
+ //nop
+ }
+
+ /** {@inheritDoc} */
+ public boolean supportsPagesOutOfOrder() {
+ return true;
+ }
+
+ /** {@inheritDoc} */
+ public void setResult(Result result) throws IFException {
+ if (result instanceof StreamResult) {
+ multiFileUtil = new MultiFileRenderingUtil(FILE_EXTENSION_SVG,
+ getUserAgent().getOutputFile());
+ this.firstStream = (StreamResult)result;
+ } else {
+ throw new UnsupportedOperationException("Result is not supported: " + result);
+ }
+ }
+
+ /** {@inheritDoc} */
+ public void startDocument() throws IFException {
+ DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
+ builderFactory.setNamespaceAware(true);
+ builderFactory.setValidating(false);
+ try {
+ DocumentBuilder builder = builderFactory.newDocumentBuilder();
+ this.reusedParts = builder.newDocument();
+ } catch (ParserConfigurationException e) {
+ throw new IFException("Error while setting up a DOM for SVG generation", e);
+ }
+
+ try {
+ TransformerHandler toDOMHandler = tFactory.newTransformerHandler();
+ toDOMHandler.setResult(new DOMResult(this.reusedParts));
+ this.handler = toDOMHandler;
+ } catch (TransformerConfigurationException e) {
+ throw new IFException(
+ "Error while setting up a TransformerHandler for SVG generation", e);
+ }
+ }
+
+ /** {@inheritDoc} */
+ public void endDocument() throws IFException {
+ }
+
+ /** {@inheritDoc} */
+ public void startPageSequence(String id) throws IFException {
+ //nop
+ }
+
+ /** {@inheritDoc} */
+ public void endPageSequence() throws IFException {
+ //nop
+ }
+
+ /** {@inheritDoc} */
+ public void startPage(int index, String name, Dimension size) throws IFException {
+ OutputStream out;
+ try {
+ out = this.multiFileUtil.createOutputStream(index);
+ } catch (IOException ioe) {
+ throw new IFException("I/O exception while setting up output file", ioe);
+ }
+ if (out == null) {
+ this.handler = createContentHandler(this.firstStream);
+ } else {
+ this.currentStream = new StreamResult(out);
+ this.handler = createContentHandler(this.currentStream);
+ }
+ if (false) {
+ final ContentHandler originalHandler = this.handler;
+ this.handler = (ContentHandler)Proxy.newProxyInstance(
+ ContentHandler.class.getClassLoader(),
+ new Class[] {ContentHandler.class},
+ new InvocationHandler() {
+ public Object invoke(Object proxy, Method method, Object[] args)
+ throws Throwable {
+ String methodName = method.getName();
+ System.out.println(methodName + ":");
+ if (args != null) {
+ for (int i = 0; i < args.length; i++) {
+ System.out.println(" " + args[i]);
+ }
+ }
+ return method.invoke(originalHandler, args);
+ }
+ });
+ }
+ try {
+ handler.startDocument();
+ handler.startPrefixMapping("", NAMESPACE);
+ handler.startPrefixMapping(XLINK_PREFIX, XLINK_NAMESPACE);
+ AttributesImpl atts = new AttributesImpl();
+ atts.addAttribute("", "version", "version", CDATA, "1.1"); //SVG 1.1
+ /*
+ atts.addAttribute("", "index", "index", CDATA, Integer.toString(index));
+ atts.addAttribute("", "name", "name", CDATA, name);
+ */
+ atts.addAttribute("", "width", "width", CDATA,
+ Float.toString(size.width / 1000f) + "pt");
+ atts.addAttribute("", "height", "height", CDATA,
+ Float.toString(size.height / 1000f) + "pt");
+ atts.addAttribute("", "viewBox", "viewBox", CDATA,
+ "0 0 " + Integer.toString(size.width) + " " + Integer.toString(size.height));
+ startElement("svg", atts);
+
+ try {
+ Transformer transformer = tFactory.newTransformer();
+ Source src = new DOMSource(this.reusedParts.getDocumentElement());
+ Result res = new SAXResult(new DelegatingFragmentContentHandler(this.handler));
+ transformer.transform(src, res);
+ } catch (TransformerConfigurationException tce) {
+ throw new IFException("Error setting up a Transformer", tce);
+ } catch (TransformerException te) {
+ if (te.getCause() instanceof SAXException) {
+ throw (SAXException)te.getCause();
+ } else {
+ throw new IFException("Error while serializing reused parts", te);
+ }
+ }
+ } catch (SAXException e) {
+ throw new IFException("SAX error in startPage()", e);
+ }
+ }
+
+ private void closeCurrentStream() {
+ if (this.currentStream != null) {
+ IOUtils.closeQuietly(currentStream.getOutputStream());
+ currentStream.setOutputStream(null);
+ IOUtils.closeQuietly(currentStream.getWriter());
+ currentStream.setWriter(null);
+ this.currentStream = null;
+ }
+ }
+
+ /** {@inheritDoc} */
+ public void startPageHeader() throws IFException {
+ }
+
+ /** {@inheritDoc} */
+ public void endPageHeader() throws IFException {
+ }
+
+ /** {@inheritDoc} */
+ public void startPageContent() throws IFException {
+ super.startPageContent();
+ try {
+ startElement("g");
+ } catch (SAXException e) {
+ throw new IFException("SAX error in startPageContent()", e);
+ }
+ }
+
+ /** {@inheritDoc} */
+ public void endPageContent() throws IFException {
+ try {
+ endElement("g");
+ } catch (SAXException e) {
+ throw new IFException("SAX error in endPageContent()", e);
+ }
+ super.endPageContent();
+ }
+
+ /** {@inheritDoc} */
+ public void startPageTrailer() throws IFException {
+ }
+
+ /** {@inheritDoc} */
+ public void endPageTrailer() throws IFException {
+ }
+
+ /** {@inheritDoc} */
+ public void endPage() throws IFException {
+ try {
+ endElement("svg");
+ this.handler.endDocument();
+ } catch (SAXException e) {
+ throw new IFException("SAX error in endPage()", e);
+ }
+ closeCurrentStream();
+ }
+
+}
Propchange: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/sandbox/org/apache/fop/render/svg/SVGPainter.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/sandbox/org/apache/fop/render/svg/SVGPainter.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/sandbox/org/apache/fop/render/svg/SVGPainterMaker.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/sandbox/org/apache/fop/render/svg/SVGPainterMaker.java?rev=677204&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/sandbox/org/apache/fop/render/svg/SVGPainterMaker.java (added)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/sandbox/org/apache/fop/render/svg/SVGPainterMaker.java Wed Jul 16 02:10:02 2008
@@ -0,0 +1,48 @@
+/*
+ * 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.svg;
+
+import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.render.intermediate.AbstractIFPainterMaker;
+import org.apache.fop.render.intermediate.IFPainter;
+
+/**
+ * Painter factory for SVG output.
+ */
+public class SVGPainterMaker extends AbstractIFPainterMaker {
+
+ private static final String[] MIMES = new String[] {SVGConstants.MIME_TYPE};
+
+ /** {@inheritDoc} */
+ public IFPainter makePainter(FOUserAgent ua) {
+ return new SVGPainter();
+ }
+
+ /** {@inheritDoc} */
+ public boolean needsOutputStream() {
+ return true;
+ }
+
+ /** {@inheritDoc} */
+ public String[] getSupportedMimeTypes() {
+ return MIMES;
+ }
+
+}
Propchange: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/sandbox/org/apache/fop/render/svg/SVGPainterMaker.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/sandbox/org/apache/fop/render/svg/SVGPainterMaker.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/sandbox/org/apache/fop/render/svg/SVGPrintPainter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/sandbox/org/apache/fop/render/svg/SVGPrintPainter.java?rev=677204&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/sandbox/org/apache/fop/render/svg/SVGPrintPainter.java (added)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/sandbox/org/apache/fop/render/svg/SVGPrintPainter.java Wed Jul 16 02:10:02 2008
@@ -0,0 +1,172 @@
+/*
+ * 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.svg;
+
+import java.awt.Dimension;
+
+import javax.xml.transform.Result;
+
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.AttributesImpl;
+
+import org.apache.fop.render.intermediate.IFConstants;
+import org.apache.fop.render.intermediate.IFException;
+
+/**
+ * IFPainter implementation that writes SVG Print.
+ */
+public class SVGPrintPainter extends AbstractSVGPainter {
+
+ /**
+ * Default constructor.
+ */
+ public SVGPrintPainter() {
+ //nop
+ }
+
+ /**
+ * Creates a new SVGPrintPainter that sends the XML content it generates to the given
+ * SAX ContentHandler.
+ * @param result the JAXP Result object to receive the generated content
+ * @throws IFException if an error occurs setting up the output
+ */
+ public SVGPrintPainter(Result result) throws IFException {
+ setResult(result);
+ }
+
+ /** {@inheritDoc} */
+ public boolean supportsPagesOutOfOrder() {
+ return false;
+ }
+
+ /** {@inheritDoc} */
+ public void startDocument() throws IFException {
+ try {
+ handler.startDocument();
+ handler.startPrefixMapping("", NAMESPACE);
+ handler.startPrefixMapping(XLINK_PREFIX, XLINK_NAMESPACE);
+ handler.startPrefixMapping("if", IFConstants.NAMESPACE);
+ AttributesImpl atts = new AttributesImpl();
+ atts.addAttribute("", "version", "version", CDATA, "1.2"); //SVG Print is SVG 1.2
+ startElement("svg", atts);
+ } catch (SAXException e) {
+ throw new IFException("SAX error in startDocument()", e);
+ }
+ }
+
+ /** {@inheritDoc} */
+ public void endDocument() throws IFException {
+ try {
+ endElement("svg");
+ handler.endDocument();
+ } catch (SAXException e) {
+ throw new IFException("SAX error in endDocument()", e);
+ }
+ }
+
+ /** {@inheritDoc} */
+ public void startPageSequence(String id) throws IFException {
+ try {
+ AttributesImpl atts = new AttributesImpl();
+ if (id != null) {
+ atts.addAttribute(XML_NAMESPACE, "id", "xml:id", CDATA, id);
+ }
+ startElement("pageSet", atts);
+ } catch (SAXException e) {
+ throw new IFException("SAX error in startPageSequence()", e);
+ }
+ }
+
+ /** {@inheritDoc} */
+ public void endPageSequence() throws IFException {
+ try {
+ endElement("pageSet");
+ } catch (SAXException e) {
+ throw new IFException("SAX error in endPageSequence()", e);
+ }
+ }
+
+ /** {@inheritDoc} */
+ public void startPage(int index, String name, Dimension size) throws IFException {
+ try {
+ AttributesImpl atts = new AttributesImpl();
+ /*
+ atts.addAttribute("", "index", "index", CDATA, Integer.toString(index));
+ atts.addAttribute("", "name", "name", CDATA, name);
+ */
+ //NOTE: SVG Print doesn't support individual page sizes for each page
+ atts.addAttribute(IFConstants.NAMESPACE, "width", "if:width",
+ CDATA, Integer.toString(size.width));
+ atts.addAttribute(IFConstants.NAMESPACE, "height", "if:height",
+ CDATA, Integer.toString(size.height));
+ atts.addAttribute(IFConstants.NAMESPACE, "viewBox", "if:viewBox", CDATA,
+ "0 0 " + Integer.toString(size.width) + " " + Integer.toString(size.height));
+ startElement("page", atts);
+ } catch (SAXException e) {
+ throw new IFException("SAX error in startPage()", e);
+ }
+ }
+
+ /** {@inheritDoc} */
+ public void startPageHeader() throws IFException {
+ }
+
+ /** {@inheritDoc} */
+ public void endPageHeader() throws IFException {
+ }
+
+ /** {@inheritDoc} */
+ public void startPageContent() throws IFException {
+ super.startPageContent();
+ try {
+ startElement("g");
+ } catch (SAXException e) {
+ throw new IFException("SAX error in startPageContent()", e);
+ }
+ }
+
+ /** {@inheritDoc} */
+ public void endPageContent() throws IFException {
+ try {
+ endElement("g");
+ } catch (SAXException e) {
+ throw new IFException("SAX error in endPageContent()", e);
+ }
+ super.endPageContent();
+ }
+
+ /** {@inheritDoc} */
+ public void startPageTrailer() throws IFException {
+ }
+
+ /** {@inheritDoc} */
+ public void endPageTrailer() throws IFException {
+ }
+
+ /** {@inheritDoc} */
+ public void endPage() throws IFException {
+ try {
+ endElement("page");
+ } catch (SAXException e) {
+ throw new IFException("SAX error in endPage()", e);
+ }
+ }
+
+}
Propchange: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/sandbox/org/apache/fop/render/svg/SVGPrintPainter.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/sandbox/org/apache/fop/render/svg/SVGPrintPainter.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/sandbox/org/apache/fop/render/svg/SVGPrintPainterMaker.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/sandbox/org/apache/fop/render/svg/SVGPrintPainterMaker.java?rev=677204&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/sandbox/org/apache/fop/render/svg/SVGPrintPainterMaker.java (added)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/sandbox/org/apache/fop/render/svg/SVGPrintPainterMaker.java Wed Jul 16 02:10:02 2008
@@ -0,0 +1,48 @@
+/*
+ * 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.svg;
+
+import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.render.intermediate.AbstractIFPainterMaker;
+import org.apache.fop.render.intermediate.IFPainter;
+
+/**
+ * Painter factory for SVG Print output.
+ */
+public class SVGPrintPainterMaker extends AbstractIFPainterMaker {
+
+ private static final String[] MIMES = new String[] {SVGConstants.MIME_SVG_PRINT};
+
+ /** {@inheritDoc} */
+ public IFPainter makePainter(FOUserAgent ua) {
+ return new SVGPrintPainter();
+ }
+
+ /** {@inheritDoc} */
+ public boolean needsOutputStream() {
+ return true;
+ }
+
+ /** {@inheritDoc} */
+ public String[] getSupportedMimeTypes() {
+ return MIMES;
+ }
+
+}
Propchange: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/sandbox/org/apache/fop/render/svg/SVGPrintPainterMaker.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/sandbox/org/apache/fop/render/svg/SVGPrintPainterMaker.java
------------------------------------------------------------------------------
svn:keywords = Id
---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org