From: Adrian Cumiskey Date: Wed, 9 Jul 2008 15:58:32 +0000 (+0000) Subject: Merged revisions 674484,674486-674487,674489,674540,674561,674564,674599,674602,67523... X-Git-Tag: fop-1_0~376^2~147 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=b62fb99c71f5d16e0fc337a54dfc9c9edc880768;p=xmlgraphics-fop.git Merged revisions 674484,674486-674487,674489,674540,674561,674564,674599,674602,675231 via svnmerge from https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk ........ r674484 | acumiskey | 2008-07-07 14:28:26 +0100 (Mon, 07 Jul 2008) | 1 line Added new AbstractXMLRenderer base class. ........ r674486 | acumiskey | 2008-07-07 14:43:19 +0100 (Mon, 07 Jul 2008) | 1 line Cleaned up some javadocs. ........ r674487 | acumiskey | 2008-07-07 14:44:14 +0100 (Mon, 07 Jul 2008) | 2 lines Refactored this class, moving much of its behaviour to the base AbstractXMLRenderer class. ........ r674489 | lfurini | 2008-07-07 14:52:36 +0100 (Mon, 07 Jul 2008) | 1 line Fixing absolute positioning of block-containers: bottom and right distances were not taken into account ........ r674540 | adelmelle | 2008-07-07 17:24:54 +0100 (Mon, 07 Jul 2008) | 1 line Correct indentation ........ r674561 | adelmelle | 2008-07-07 18:31:12 +0100 (Mon, 07 Jul 2008) | 1 line Added the change to the FONode interface committed in r670341 ........ r674564 | adelmelle | 2008-07-07 18:46:09 +0100 (Mon, 07 Jul 2008) | 1 line Fixed typo ........ r674599 | clay | 2008-07-07 20:15:34 +0100 (Mon, 07 Jul 2008) | 1 line updated info. ........ r674602 | clay | 2008-07-07 20:19:00 +0100 (Mon, 07 Jul 2008) | 1 line One more minor update. ........ r675231 | acumiskey | 2008-07-09 16:34:01 +0100 (Wed, 09 Jul 2008) | 2 lines Minor javadoc cleanup. ........ git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_AFPGOCAResources@675239 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/documentation/content/xdocs/team.xml b/src/documentation/content/xdocs/team.xml index bd9f72fde..a65840270 100644 --- a/src/documentation/content/xdocs/team.xml +++ b/src/documentation/content/xdocs/team.xml @@ -54,7 +54,7 @@ is a web/WAP/Palm developer from Laguna Beach, California, USA. A recent XML/XSL-FO convert, he has been nit-picking FAQs & assorted web pages since his first webmaster position @brain.com in 1996. Most - important creation? His li'l Jeremy was born June 18, 2002. + important creation? He's got a couple of cool kids.
  • Manuel Mall (MM) is an independant software engineer resident in Perth, Australia. Born a long time ago in Germany he has been involved in Software Engineering (Informatik) since the diff --git a/src/java/org/apache/fop/fo/flow/table/TableFObj.java b/src/java/org/apache/fop/fo/flow/table/TableFObj.java index faf1f7aba..f459ecd65 100644 --- a/src/java/org/apache/fop/fo/flow/table/TableFObj.java +++ b/src/java/org/apache/fop/fo/flow/table/TableFObj.java @@ -256,19 +256,19 @@ public abstract class TableFObj extends FObj { BorderSpecification borderSpec = new BorderSpecification( getCommonBorderPaddingBackground().getBorderInfo(side), getNameId()); switch (side) { - case CommonBorderPaddingBackground.BEFORE: - borderBefore = new ConditionalBorder(borderSpec, collapsingBorderModel); - break; - case CommonBorderPaddingBackground.AFTER: - borderAfter = new ConditionalBorder(borderSpec, collapsingBorderModel); - break; - case CommonBorderPaddingBackground.START: - borderStart = borderSpec; - break; - case CommonBorderPaddingBackground.END: - borderEnd = borderSpec; - break; - default: assert false; + case CommonBorderPaddingBackground.BEFORE: + borderBefore = new ConditionalBorder(borderSpec, collapsingBorderModel); + break; + case CommonBorderPaddingBackground.AFTER: + borderAfter = new ConditionalBorder(borderSpec, collapsingBorderModel); + break; + case CommonBorderPaddingBackground.START: + borderStart = borderSpec; + break; + case CommonBorderPaddingBackground.END: + borderEnd = borderSpec; + break; + default: assert false; } } } diff --git a/src/java/org/apache/fop/layoutmgr/BlockContainerLayoutManager.java b/src/java/org/apache/fop/layoutmgr/BlockContainerLayoutManager.java index 732cb1ae7..022ba1d90 100644 --- a/src/java/org/apache/fop/layoutmgr/BlockContainerLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/BlockContainerLayoutManager.java @@ -694,9 +694,17 @@ public class BlockContainerLayoutManager extends BlockStackingLayoutManager int y = 0; if (abProps.left.getEnum() != EN_AUTO) { x = abProps.left.getValue(this); + } else if (abProps.right.getEnum() != EN_AUTO + && width.getEnum() != EN_AUTO) { + x = getReferenceAreaIPD() + - abProps.right.getValue(this) - width.getValue(this); } if (abProps.top.getEnum() != EN_AUTO) { y = abProps.top.getValue(this); + } else if (abProps.bottom.getEnum() != EN_AUTO + && height.getEnum() != EN_AUTO) { + y = getReferenceAreaBPD() + - abProps.bottom.getValue(this) - height.getValue(this); } return new Point(x, y); } @@ -1085,3 +1093,4 @@ public class BlockContainerLayoutManager extends BlockStackingLayoutManager } + diff --git a/src/java/org/apache/fop/render/ps/PSRenderer.java b/src/java/org/apache/fop/render/ps/PSRenderer.java index 3f1769295..f84f46bf9 100644 --- a/src/java/org/apache/fop/render/ps/PSRenderer.java +++ b/src/java/org/apache/fop/render/ps/PSRenderer.java @@ -734,8 +734,7 @@ public class PSRenderer extends AbstractPathOrientedRenderer gen.useColor(col); } - /** {@inheritDoc} - * Area, float, float, float, float) */ + /** {@inheritDoc} */ protected void drawBackAndBorders(Area area, float startx, float starty, float width, float height) { if (area.hasTrait(Trait.BACKGROUND) @@ -904,9 +903,7 @@ public class PSRenderer extends AbstractPathOrientedRenderer } } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ public void startRenderer(OutputStream outputStream) throws IOException { log.debug("Rendering areas to PostScript..."); @@ -980,9 +977,7 @@ public class PSRenderer extends AbstractPathOrientedRenderer gen.writeDSCComment(DSCConstants.END_SETUP); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ public void stopRenderer() throws IOException { //Notify resource usage for font which are not supplied /* done in useFont now @@ -1134,9 +1129,7 @@ public class PSRenderer extends AbstractPathOrientedRenderer } } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ public void renderPage(PageViewport page) throws IOException, FOPException { log.debug("renderPage(): " + page); @@ -1313,9 +1306,7 @@ public class PSRenderer extends AbstractPathOrientedRenderer } } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ public void renderText(TextArea area) { renderInlineAreaBackAndBorders(area); String fontkey = getInternalFontNameForArea(area); @@ -1346,17 +1337,13 @@ public class PSRenderer extends AbstractPathOrientedRenderer renderTextDecoration(tf, fontsize, area, bl, rx); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ protected void renderWord(WordArea word) { renderText((TextArea)word.getParentArea(), word.getWord(), word.getLetterAdjustArray()); super.renderWord(word); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ protected void renderSpace(SpaceArea space) { AbstractTextArea textArea = (AbstractTextArea)space.getParentArea(); String s = space.getSpace(); diff --git a/src/java/org/apache/fop/render/xml/AbstractXMLRenderer.java b/src/java/org/apache/fop/render/xml/AbstractXMLRenderer.java new file mode 100644 index 000000000..7aa22e080 --- /dev/null +++ b/src/java/org/apache/fop/render/xml/AbstractXMLRenderer.java @@ -0,0 +1,268 @@ +/* + * 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.xml; + +import java.awt.geom.Rectangle2D; +import java.io.IOException; +import java.io.OutputStream; +import java.util.List; + +import javax.xml.transform.TransformerConfigurationException; +import javax.xml.transform.sax.SAXTransformerFactory; +import javax.xml.transform.sax.TransformerHandler; +import javax.xml.transform.stream.StreamResult; + +import org.apache.fop.area.BookmarkData; +import org.apache.fop.area.OffDocumentExtensionAttachment; +import org.apache.fop.area.OffDocumentItem; +import org.apache.fop.area.PageViewport; +import org.apache.fop.fo.extensions.ExtensionAttachment; +import org.apache.fop.render.PrintRenderer; +import org.apache.fop.render.RendererContext; +import org.apache.xmlgraphics.util.QName; +import org.xml.sax.Attributes; +import org.xml.sax.ContentHandler; +import org.xml.sax.SAXException; +import org.xml.sax.ext.LexicalHandler; +import org.xml.sax.helpers.AttributesImpl; + +public abstract class AbstractXMLRenderer extends PrintRenderer { + /** Main namespace in use. */ + public static final String NS = ""; + + /** CDATA type */ + public static final String CDATA = "CDATA"; + + /** An empty Attributes object used when no attributes are needed. */ + public static final Attributes EMPTY_ATTS = new AttributesImpl(); + + /** AttributesImpl instance that can be used during XML generation. */ + protected AttributesImpl atts = new AttributesImpl(); + + /** ContentHandler that the generated XML is written to */ + protected ContentHandler handler; + + /** The OutputStream to write the generated XML to. */ + protected OutputStream out; + + protected RendererContext context; + + /** A list of ExtensionAttachements received through processOffDocumentItem() */ + protected List extensionAttachments; + + /** + * Handles SAXExceptions. + * @param saxe the SAXException to handle + */ + protected void handleSAXException(SAXException saxe) { + throw new RuntimeException(saxe.getMessage()); + } + + /** + * Handles page extension attachments + * @param page the page viewport + */ + protected void handlePageExtensionAttachments(PageViewport page) { + handleExtensionAttachments(page.getExtensionAttachments()); + } + + /** + * Writes a comment to the generated XML. + * @param comment the comment + */ + protected void comment(String comment) { + if (handler instanceof LexicalHandler) { + try { + ((LexicalHandler) handler).comment(comment.toCharArray(), 0, comment.length()); + } catch (SAXException saxe) { + handleSAXException(saxe); + } + } + } + + /** + * Starts a new element (without attributes). + * @param tagName tag name of the element + */ + protected void startElement(String tagName) { + startElement(tagName, EMPTY_ATTS); + } + + /** + * Starts a new element. + * @param tagName tag name of the element + * @param atts attributes to add + */ + protected void startElement(String tagName, Attributes atts) { + try { + handler.startElement(NS, tagName, tagName, atts); + } catch (SAXException saxe) { + handleSAXException(saxe); + } + } + + /** + * Ends an element. + * @param tagName tag name of the element + */ + protected void endElement(String tagName) { + try { + handler.endElement(NS, tagName, tagName); + } catch (SAXException saxe) { + handleSAXException(saxe); + } + } + + /** + * Sends plain text to the XML + * @param text the text + */ + protected void characters(String text) { + try { + char[] ca = text.toCharArray(); + handler.characters(ca, 0, ca.length); + } catch (SAXException saxe) { + handleSAXException(saxe); + } + } + + /** + * Adds a new attribute to the protected member variable "atts". + * @param name name of the attribute + * @param value value of the attribute + */ + protected void addAttribute(String name, String value) { + atts.addAttribute(NS, name, name, CDATA, value); + } + + /** + * Adds a new attribute to the protected member variable "atts". + * @param name name of the attribute + * @param value value of the attribute + */ + protected void addAttribute(QName name, String value) { + atts.addAttribute(name.getNamespaceURI(), name.getLocalName(), name.getQName(), + CDATA, value); + } + + /** + * Adds a new attribute to the protected member variable "atts". + * @param name name of the attribute + * @param value value of the attribute + */ + protected void addAttribute(String name, int value) { + addAttribute(name, Integer.toString(value)); + } + + private String createString(Rectangle2D rect) { + return "" + (int) rect.getX() + " " + (int) rect.getY() + " " + + (int) rect.getWidth() + " " + (int) rect.getHeight(); + } + + /** + * Adds a new attribute to the protected member variable "atts". + * @param name name of the attribute + * @param rect a Rectangle2D to format and use as attribute value + */ + protected void addAttribute(String name, Rectangle2D rect) { + addAttribute(name, createString(rect)); + } + + /** {@inheritDoc} */ + public void startRenderer(OutputStream outputStream) + throws IOException { + if (this.handler == null) { + SAXTransformerFactory factory + = (SAXTransformerFactory)SAXTransformerFactory.newInstance(); + try { + TransformerHandler transformerHandler = factory.newTransformerHandler(); + setContentHandler(transformerHandler); + StreamResult res = new StreamResult(outputStream); + transformerHandler.setResult(res); + } catch (TransformerConfigurationException tce) { + throw new RuntimeException(tce.getMessage()); + } + this.out = outputStream; + } + + try { + handler.startDocument(); + } catch (SAXException saxe) { + handleSAXException(saxe); + } + } + + /** {@inheritDoc} */ + public void stopRenderer() throws IOException { + try { + handler.endDocument(); + } catch (SAXException saxe) { + handleSAXException(saxe); + } + if (this.out != null) { + this.out.flush(); + } + } + + /** {@inheritDoc} */ + public void processOffDocumentItem(OffDocumentItem oDI) { + if (oDI instanceof BookmarkData) { + renderBookmarkTree((BookmarkData) oDI); + } else if (oDI instanceof OffDocumentExtensionAttachment) { + ExtensionAttachment attachment = ((OffDocumentExtensionAttachment)oDI).getAttachment(); + if (extensionAttachments == null) { + extensionAttachments = new java.util.ArrayList(); + } + extensionAttachments.add(attachment); + } else { + String warn = "Ignoring OffDocumentItem: " + oDI; + log.warn(warn); + } + } + + /** {@inheritDoc} */ + protected void handleDocumentExtensionAttachments() { + if (extensionAttachments != null && extensionAttachments.size() > 0) { + handleExtensionAttachments(extensionAttachments); + extensionAttachments.clear(); + } + } + + /** + * Sets an outside TransformerHandler to use instead of the default one + * create in this class in startRenderer(). + * @param handler Overriding TransformerHandler + */ + public void setContentHandler(ContentHandler handler) { + this.handler = handler; + } + + /** + * Handles a list of extension attachments + * @param attachments a list of extension attachments + */ + protected abstract void handleExtensionAttachments(List attachments); + + /** + * Renders a bookmark tree + * @param odi the bookmark data + */ + protected abstract void renderBookmarkTree(BookmarkData odi); +} diff --git a/src/java/org/apache/fop/render/xml/XMLRenderer.java b/src/java/org/apache/fop/render/xml/XMLRenderer.java index 94cd107c7..b41de7387 100644 --- a/src/java/org/apache/fop/render/xml/XMLRenderer.java +++ b/src/java/org/apache/fop/render/xml/XMLRenderer.java @@ -35,11 +35,7 @@ import javax.xml.transform.stream.StreamResult; import org.w3c.dom.Document; -import org.xml.sax.Attributes; -import org.xml.sax.ContentHandler; import org.xml.sax.SAXException; -import org.xml.sax.ext.LexicalHandler; -import org.xml.sax.helpers.AttributesImpl; import org.apache.xmlgraphics.util.QName; import org.apache.xmlgraphics.util.XMLizable; @@ -99,39 +95,17 @@ import org.apache.fop.util.ColorUtil; * The output can be used to build a new area tree which can be * rendered to any renderer. */ -public class XMLRenderer extends PrintRenderer { +public class XMLRenderer extends AbstractXMLRenderer { /** XML MIME type */ public static final String XML_MIME_TYPE = MimeConstants.MIME_FOP_AREA_TREE; - /** Main namespace in use. */ - public static final String NS = ""; - - /** CDATA type */ - public static final String CDATA = "CDATA"; - - /** An empty Attributes object used when no attributes are needed. */ - public static final Attributes EMPTY_ATTS = new AttributesImpl(); - private boolean startedSequence = false; - private RendererContext context; private boolean compactFormat = false; /** If not null, the XMLRenderer will mimic another renderer by using its font setup. */ protected Renderer mimic; - /** ContentHandler that the generated XML is written to */ - protected ContentHandler handler; - - /** AttributesImpl instance that can be used during XML generation. */ - protected AttributesImpl atts = new AttributesImpl(); - - /** The OutputStream to write the generated XML to. */ - protected OutputStream out; - - /** A list of ExtensionAttachements received through processOffDocumentItem() */ - protected List extensionAttachments; - /** * Creates a new XML renderer. */ @@ -171,15 +145,6 @@ public class XMLRenderer extends PrintRenderer { } } - /** - * Sets an outside TransformerHandler to use instead of the default one - * create in this class in startRenderer(). - * @param handler Overriding TransformerHandler - */ - public void setContentHandler(ContentHandler handler) { - this.handler = handler; - } - public void setCompactFormat(boolean compact) { this.compactFormat = compact; } @@ -188,111 +153,6 @@ public class XMLRenderer extends PrintRenderer { return !this.compactFormat; } - /** - * Handles SAXExceptions. - * @param saxe the SAXException to handle - */ - protected void handleSAXException(SAXException saxe) { - throw new RuntimeException(saxe.getMessage()); - } - - /** - * Writes a comment to the generated XML. - * @param comment the comment - */ - protected void comment(String comment) { - if (handler instanceof LexicalHandler) { - try { - ((LexicalHandler) handler).comment(comment.toCharArray(), 0, comment.length()); - } catch (SAXException saxe) { - handleSAXException(saxe); - } - } - } - - /** - * Starts a new element (without attributes). - * @param tagName tag name of the element - */ - protected void startElement(String tagName) { - startElement(tagName, EMPTY_ATTS); - } - - /** - * Starts a new element. - * @param tagName tag name of the element - * @param atts attributes to add - */ - protected void startElement(String tagName, Attributes atts) { - try { - handler.startElement(NS, tagName, tagName, atts); - } catch (SAXException saxe) { - handleSAXException(saxe); - } - } - - /** - * Ends an element. - * @param tagName tag name of the element - */ - protected void endElement(String tagName) { - try { - handler.endElement(NS, tagName, tagName); - } catch (SAXException saxe) { - handleSAXException(saxe); - } - } - - /** - * Sends plain text to the XML - * @param text the text - */ - protected void characters(String text) { - try { - char[] ca = text.toCharArray(); - handler.characters(ca, 0, ca.length); - } catch (SAXException saxe) { - handleSAXException(saxe); - } - } - - /** - * Adds a new attribute to the protected member variable "atts". - * @param name name of the attribute - * @param value value of the attribute - */ - protected void addAttribute(String name, String value) { - atts.addAttribute(NS, name, name, CDATA, value); - } - - /** - * Adds a new attribute to the protected member variable "atts". - * @param name name of the attribute - * @param value value of the attribute - */ - protected void addAttribute(QName name, String value) { - atts.addAttribute(name.getNamespaceURI(), name.getLocalName(), name.getQName(), - CDATA, value); - } - - /** - * Adds a new attribute to the protected member variable "atts". - * @param name name of the attribute - * @param value value of the attribute - */ - protected void addAttribute(String name, int value) { - addAttribute(name, Integer.toString(value)); - } - - /** - * Adds a new attribute to the protected member variable "atts". - * @param name name of the attribute - * @param rect a Rectangle2D to format and use as attribute value - */ - protected void addAttribute(String name, Rectangle2D rect) { - addAttribute(name, createString(rect)); - } - /** * Adds the general Area attributes. * @param area Area to extract attributes from @@ -406,18 +266,6 @@ public class XMLRenderer extends PrintRenderer { } } - private String createString(Rectangle2D rect) { - return "" + (int) rect.getX() + " " + (int) rect.getY() + " " - + (int) rect.getWidth() + " " + (int) rect.getHeight(); - } - - private void handleDocumentExtensionAttachments() { - if (extensionAttachments != null && extensionAttachments.size() > 0) { - handleExtensionAttachments(extensionAttachments); - extensionAttachments.clear(); - } - } - /** {@inheritDoc} */ public void processOffDocumentItem(OffDocumentItem oDI) { if (oDI instanceof BookmarkData) { @@ -518,9 +366,7 @@ public class XMLRenderer extends PrintRenderer { startElement("areaTree"); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ public void stopRenderer() throws IOException { endPageSequence(); endElement("areaTree"); @@ -535,9 +381,7 @@ public class XMLRenderer extends PrintRenderer { log.debug("Written out Area Tree XML"); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ public void renderPage(PageViewport page) throws IOException, FOPException { atts.clear(); addAttribute("bounds", page.getViewArea()); @@ -561,7 +405,8 @@ public class XMLRenderer extends PrintRenderer { endElement("pageViewport"); } - private void handleExtensionAttachments(List attachments) { + /** {@inheritDoc} */ + protected void handleExtensionAttachments(List attachments) { if (attachments != null && attachments.size() > 0) { startElement("extension-attachments"); Iterator i = attachments.iterator(); @@ -582,10 +427,6 @@ public class XMLRenderer extends PrintRenderer { } } - private void handlePageExtensionAttachments(PageViewport page) { - handleExtensionAttachments(page.getExtensionAttachments()); - } - /** {@inheritDoc} */ public void startPageSequence(PageSequence pageSequence) { handleDocumentExtensionAttachments(); diff --git a/status.xml b/status.xml index 6f22165c5..2a3b8937e 100644 --- a/status.xml +++ b/status.xml @@ -53,6 +53,10 @@ + + Fixed absolute positioning of block-containers when specified + using right and bottom instead of left and top. + Added PDF encryption parameter support in configuration. @@ -65,6 +69,13 @@ empty areas in pages whose last normal line contains footnotes when the page bpd is not the same for all pages. + + Changed FONode.addCharacters() parameter to closer match the signature of + the standard SAX characters() event (reduces confusion and computations). + !! Implementors of extensions that subclass FONode directly, and + offer an implementation for addCharacters() should take care to make + similar modifications in their code !! + + + + +

    + This test checks absolutely positioned block-containers using top, bottom, left and right distances +

    +
    + + + + + + + + + + position + NOT ok! + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +