Index: src/documentation/content/xdocs/trunk/running.xml =================================================================== --- src/documentation/content/xdocs/trunk/running.xml (revision 1348087) +++ src/documentation/content/xdocs/trunk/running.xml (working copy) @@ -109,7 +109,7 @@

+Fop [options] [-fo|-xml] infile [-xsl file] [-awt|-pdf|-mif|-odt|-rtf|-tiff|-png|-pcl|-ps|-txt|-at [mime]|-print] [OPTIONS] -version print FOP version and exit -d debug mode @@ -164,6 +164,7 @@ -pdfa1b outfile input will be rendered as PDF/A-1b compliant PDF (outfile req'd, same as "-pdf outfile -pdfprofile PDF/A-1b") -awt input will be displayed on screen + -odt outfile input will be rendered as ODT (outfile req'd) -rtf outfile input will be rendered as RTF (outfile req'd) -pcl outfile input will be rendered as PCL (outfile req'd) -ps outfile input will be rendered as PostScript (outfile req'd) @@ -197,6 +198,7 @@ fop -xml foo.xml -xsl foo.xsl -foout foo.fo fop -xml - -xsl foo.xsl -pdf - fop foo.fo -mif foo.mif + fop foo.fo -odt foo.odt fop foo.fo -rtf foo.rtf fop foo.fo -print fop foo.fo -awt]]> Index: src/documentation/content/xdocs/trunk/output.xml =================================================================== --- src/documentation/content/xdocs/trunk/output.xml (revision 1348087) +++ src/documentation/content/xdocs/trunk/output.xml (working copy) @@ -1112,6 +1112,15 @@ +
+ ODT +

+ An open source XSL-FO to ODT converter has been integrated into Apache FOP. + This will create an ODT (rich text format) document that will + attempt to contain as much information from the XSL-FO document as + possible. +

+
RTF

Index: src/java/org/apache/fop/render/odf/FopOdfConverter.java =================================================================== --- src/java/org/apache/fop/render/odf/FopOdfConverter.java (revision 0) +++ src/java/org/apache/fop/render/odf/FopOdfConverter.java (revision 0) @@ -0,0 +1,47 @@ +/* + * 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. + */ + +package org.apache.fop.render.odf; + +import java.io.OutputStream; + +import org.apache.fop.fo.FONode; + +/** + * Renderer that renders areas to odt. + */ +public interface FopOdfConverter { + + /** + * Initialisation of converter + * @throws OdfException + */ + void init() throws OdfException; + + /** + * Write created odf document to the output stream + * @param os output stream + */ + void writeToOutputStream(OutputStream os); + + /** + * Convert FONode with its children to odf document holden by converter + * @param foNode node of xslfo + */ + void convertRecursively(FONode foNode); + +} Index: src/java/org/apache/fop/render/odf/OdfException.java =================================================================== --- src/java/org/apache/fop/render/odf/OdfException.java (revision 0) +++ src/java/org/apache/fop/render/odf/OdfException.java (revision 0) @@ -0,0 +1,32 @@ +/* + * 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. + */ + +package org.apache.fop.render.odf; + +import org.apache.avalon.framework.CascadingException; + +public class OdfException extends CascadingException { + + /** + * + */ + private static final long serialVersionUID = 6464226563894799824L; + + public OdfException(String message, Throwable throwable) { + super(message, throwable); + } +} Index: src/java/org/apache/fop/render/odf/ODTHandler.java =================================================================== --- src/java/org/apache/fop/render/odf/ODTHandler.java (revision 0) +++ src/java/org/apache/fop/render/odf/ODTHandler.java (revision 0) @@ -0,0 +1,74 @@ +/* + * 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. + */ + +package org.apache.fop.render.odf; + +import java.io.OutputStream; + +import org.xml.sax.SAXException; + +import org.apache.fop.apps.FOUserAgent; +import org.apache.fop.fo.FOEventHandler; +import org.apache.fop.fo.pagination.PageSequence; + +import org.apache.fop.render.odf.odt.FopOdtConverter; + +/** + * ODT Handler: generates ODT output + */ +public class ODTHandler extends FOEventHandler { + + private FopOdfConverter converter = new FopOdtConverter(); + + private final OutputStream os; + + /** + * Constructor : keeping output stream + */ + public ODTHandler(FOUserAgent userAgent, OutputStream os) { + super(userAgent); + this.os = os; + } + + /** + * {@inheritDoc} + */ + @Override + public void startDocument() throws SAXException { + try { + converter.init(); + } catch (OdfException e) { + e.printStackTrace(); + } + } + + /** + * {@inheritDoc} + */ + @Override + public void endDocument() throws SAXException { + converter.writeToOutputStream(os); + } + + /** + * {@inheritDoc} + */ + @Override + public void endPageSequence(PageSequence pageSeq) { + converter.convertRecursively(pageSeq); + } +} Index: src/java/org/apache/fop/render/odf/FopTagType.java =================================================================== --- src/java/org/apache/fop/render/odf/FopTagType.java (revision 0) +++ src/java/org/apache/fop/render/odf/FopTagType.java (revision 0) @@ -0,0 +1,26 @@ +/* + * 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. + */ + +package org.apache.fop.render.odf; + +/** + * Defines START and END tags helping to detect hierachical structure of xslfo. + */ +public enum FopTagType { + START, + END; +} Index: src/java/org/apache/fop/render/odf/odt/Namespace.java =================================================================== --- src/java/org/apache/fop/render/odf/odt/Namespace.java (revision 0) +++ src/java/org/apache/fop/render/odf/odt/Namespace.java (revision 0) @@ -0,0 +1,40 @@ +/* + * 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. + */ + +package org.apache.fop.render.odf.odt; + +/** + * Defines namespeces used for odf attributes. + */ +public final class Namespace { + + public static final String OFFICE = "urn:oasis:names:tc:opendocument:xmlns:office:1.0"; + + public static final String FO = "urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0"; + + public static final String XLINK = "http://www.w3.org/1999/xlink"; + + public static final String SVG = "urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0"; + + public static final String TABLE = "urn:oasis:names:tc:opendocument:xmlns:table:1.0"; + + public static final String STYLE = "urn:oasis:names:tc:opendocument:xmlns:style:1.0"; + + public static final String TEXT = "urn:oasis:names:tc:opendocument:xmlns:text:1.0"; + + private Namespace() { } +} Index: src/java/org/apache/fop/render/odf/odt/FopOdtConverter.java =================================================================== --- src/java/org/apache/fop/render/odf/odt/FopOdtConverter.java (revision 0) +++ src/java/org/apache/fop/render/odf/odt/FopOdtConverter.java (revision 0) @@ -0,0 +1,115 @@ +/* + * 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. + */ + +package org.apache.fop.render.odf.odt; + +import java.io.OutputStream; +import java.util.Iterator; + +import org.odftoolkit.simple.TextDocument; + +import org.apache.fop.fo.FONode; + +import org.apache.fop.render.odf.FopOdfConverter; +import org.apache.fop.render.odf.FopTagType; +import org.apache.fop.render.odf.OdfException; +import org.apache.fop.render.odf.odt.tags.RootTag; +import org.apache.fop.render.odf.odt.tags.Tag; +import org.apache.fop.render.odf.odt.tags.TagFactory; + +/** + * Renderer that renders areas to odt. + */ +public class FopOdtConverter implements FopOdfConverter { + + TextDocument odt = null; + + private TagFactory factory = new TagFactory(); + + private Tag actualTag = null; + + /** + * {@inheritDoc} + * @throws OdfException + */ + public void init() throws OdfException { + + try { + odt = TextDocument.newTextDocument(); + } catch (Exception e) { + throw new OdfException("Can't initialize the document", e); + } + + actualTag = new RootTag(odt); + } + + /** + * {@inheritDoc} + */ + public void writeToOutputStream(OutputStream os) { + + try { + odt.save(os); + } catch (Exception e) { + System.err.println(e.getMessage()); + e.printStackTrace(); + } + } + + /** + * {@inheritDoc} + */ + public void convertRecursively(FONode foNode) { + this.convert(foNode, FopTagType.START); + + if (foNode.getChildNodes() != null) { + for (Iterator it = foNode.getChildNodes(); it.hasNext();) { + FONode fn = (FONode) it.next(); + convertRecursively(fn); + } + } + + this.convert(foNode, FopTagType.END); + } + + /** + * Convert one tag to the element of odt. + * @param image the image which will be painted + * @param context the renderer context for the current renderer + */ + private void convert(FONode foNode, FopTagType type) { + if (type == FopTagType.START) { + try { + actualTag = factory.getTag(this, foNode, actualTag); + } catch (OdfException e1) { + e1.printStackTrace(); + } + try { + actualTag.execute(); + } catch (OdfException e) { + e.printStackTrace(); + } + } else if (type == FopTagType.END) { + try { + actualTag.closeIntercept(); + } catch (OdfException e) { + e.printStackTrace(); + } + actualTag = actualTag.getParent(); + } + } +} Index: src/java/org/apache/fop/render/odf/odt/tags/TableCellTag.java =================================================================== --- src/java/org/apache/fop/render/odf/odt/tags/TableCellTag.java (revision 0) +++ src/java/org/apache/fop/render/odf/odt/tags/TableCellTag.java (revision 0) @@ -0,0 +1,138 @@ +/* + * 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. + */ + +package org.apache.fop.render.odf.odt.tags; + +import org.odftoolkit.odfdom.dom.element.style.StyleStyleElement; +import org.odftoolkit.odfdom.dom.element.style.StyleTableCellPropertiesElement; +import org.odftoolkit.odfdom.dom.element.table.TableTableCellElement; +import org.odftoolkit.odfdom.pkg.OdfXMLFactory; + +import org.apache.fop.fo.flow.table.TableCell; +import org.apache.fop.render.odf.OdfException; +import org.apache.fop.render.odf.odt.Namespace; + +/** + * TableCell converter + */ +public class TableCellTag extends Tag { + + private TableCell tblCell = null; + + private TableTableCellElement tce = null; + + TableCellTag(Tag parent, TableCell tblCell) { + super(parent); + this.tblCell = tblCell; + } + + public TableCell getTableCell() { + return tblCell; + } + + public TableTableCellElement getTableCellElement() { + return tce; + } + + /** + * {@inheritDoc} + * @throws OdfException + */ + @Override + public void execute() throws OdfException { + + try { + tce = (TableTableCellElement) OdfXMLFactory.newOdfElement(this.getOdt().getContentDom(), TableTableCellElement.ELEMENT_NAME); + } catch (Exception e) { + throw new OdfException("Can't create table cell", e); + } + + StyleStyleElement sse = null; + try { + sse = (StyleStyleElement) OdfXMLFactory.newOdfElement(this.getOdt().getContentDom(), StyleStyleElement.ELEMENT_NAME); + } catch (Exception e) { + throw new OdfException("Can't create the style for new table cell", e); + } + + sse.setAttributeNS(Namespace.STYLE, "style:family", "table-cell"); + + StyleTableCellPropertiesElement stcpe = null; + + try { + stcpe = (StyleTableCellPropertiesElement) OdfXMLFactory.newOdfElement(this.getOdt().getContentDom(), StyleTableCellPropertiesElement.ELEMENT_NAME); + } catch (Exception e) { + throw new OdfException("Can't create style fot table cell", e); + } + + float borderSize = Math.round(((float)tblCell.getCommonBorderPaddingBackground().getBorderStartWidth(false)) / 100); + borderSize = borderSize / 10; + stcpe.setAttributeNS(Namespace.FO, "fo:border-left", Float.toString(borderSize) + "pt solid #000000"); + + borderSize = Math.round((float)tblCell.getCommonBorderPaddingBackground().getBorderEndWidth(false) / 100); + borderSize = borderSize / 10; + stcpe.setAttributeNS(Namespace.FO, "fo:border-right", Float.toString(borderSize) + "pt solid #000000"); + + borderSize = Math.round((float)tblCell.getCommonBorderPaddingBackground().getBorderBeforeWidth(false) / 100); + borderSize = borderSize / 10; + stcpe.setAttributeNS(Namespace.FO, "fo:border-top", Float.toString(borderSize) + "pt solid #000000"); + + borderSize = Math.round((float)tblCell.getCommonBorderPaddingBackground().getBorderAfterWidth(false) / 100); + borderSize = borderSize / 10; + stcpe.setAttributeNS(Namespace.FO, "fo:border-bottom", Float.toString(borderSize) + "pt solid #000000"); + + float paddingSize = Math.round((float)tblCell.getCommonBorderPaddingBackground().getPaddingLengthProperty(0).getLengthValue() / 100); + paddingSize = paddingSize / 10; + stcpe.setAttributeNS(Namespace.FO, "fo:padding-left", Float.toString(paddingSize) + "pt"); + + paddingSize = Math.round((float)tblCell.getCommonBorderPaddingBackground().getPaddingLengthProperty(1).getLengthValue() / 100); + paddingSize = paddingSize / 10; + stcpe.setAttributeNS(Namespace.FO, "fo:padding-top", Float.toString(paddingSize) + "pt"); + + paddingSize = Math.round((float)tblCell.getCommonBorderPaddingBackground().getPaddingLengthProperty(2).getLengthValue() / 100); + paddingSize = paddingSize / 10; + stcpe.setAttributeNS(Namespace.FO, "fo:padding-right", Float.toString(paddingSize) + "pt"); + + paddingSize = Math.round((float)tblCell.getCommonBorderPaddingBackground().getPaddingLengthProperty(3).getLengthValue() / 100); + paddingSize = paddingSize / 10; + stcpe.setAttributeNS(Namespace.FO, "fo:padding-bottom", Float.toString(paddingSize) + "pt"); + + sse.appendChild(stcpe); + + tce.setAttributeNS(Namespace.TABLE, "table:number-columns-spanned", Integer.toString(tblCell.getNumberColumnsSpanned())); + tce.setAttributeNS(Namespace.TABLE, "table:number-rows-spanned", Integer.toString(tblCell.getNumberRowsSpanned())); + + tce.setStyleName(this.appendNewStyle(sse)); + + parent.executeFromParent(this); + } + + @Override + public void execute(TableRowTag tag) throws OdfException { + try { + tag.getTableRow().appendChild(tce); + } catch (Exception e) { + throw new OdfException("Can't create table cell", e); + } + } + + public void executeFromParent(TagExecutable child) throws OdfException { + if (this != child) { + child.execute(this); + } + } + +} Index: src/java/org/apache/fop/render/odf/odt/tags/TableBodyTag.java =================================================================== --- src/java/org/apache/fop/render/odf/odt/tags/TableBodyTag.java (revision 0) +++ src/java/org/apache/fop/render/odf/odt/tags/TableBodyTag.java (revision 0) @@ -0,0 +1,45 @@ +/* + * 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. + */ + +package org.apache.fop.render.odf.odt.tags; + +import org.apache.fop.fo.flow.table.TableBody; +import org.apache.fop.render.odf.OdfException; + +/** + * TableBody converter + */ +public class TableBodyTag extends Tag { + + TableBodyTag(Tag parent, TableBody tblBody) { + super(parent); + } + + /** + * {@inheritDoc} + */ + @Override + public void execute() { } + + /** + * {@inheritDoc} + * @throws OdfException + */ + public void executeFromParent(TagExecutable child) throws OdfException { + parent.executeFromParent(child); + } +} Index: src/java/org/apache/fop/render/odf/odt/tags/InstreamForeignObjectTag.java =================================================================== --- src/java/org/apache/fop/render/odf/odt/tags/InstreamForeignObjectTag.java (revision 0) +++ src/java/org/apache/fop/render/odf/odt/tags/InstreamForeignObjectTag.java (revision 0) @@ -0,0 +1,46 @@ +/* + * 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. + */ + +package org.apache.fop.render.odf.odt.tags; + +import org.apache.fop.fo.flow.InstreamForeignObject; +import org.apache.fop.render.odf.OdfException; + +/** + * InstreamForeignObject converter + */ +public class InstreamForeignObjectTag extends Tag { + + InstreamForeignObjectTag(Tag parent, InstreamForeignObject foNode) { + super(parent); + } + + /** + * {@inheritDoc} + */ + @Override + public void execute() { } + + /** + * {@inheritDoc} + * @throws OdfException + */ + public void executeFromParent(TagExecutable child) throws OdfException { + child.execute(this); + } + +} Index: src/java/org/apache/fop/render/odf/odt/tags/PageNumberCitationTag.java =================================================================== --- src/java/org/apache/fop/render/odf/odt/tags/PageNumberCitationTag.java (revision 0) +++ src/java/org/apache/fop/render/odf/odt/tags/PageNumberCitationTag.java (revision 0) @@ -0,0 +1,46 @@ +/* + * 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. + */ + +package org.apache.fop.render.odf.odt.tags; + +import org.apache.fop.fo.flow.PageNumberCitation; +import org.apache.fop.render.odf.OdfException; + +/** + * PageNumberCitation converter + */ +public class PageNumberCitationTag extends Tag { + + PageNumberCitationTag(Tag parent, PageNumberCitation foNode) { + super(parent); + } + + /** + * {@inheritDoc} + */ + @Override + public void execute() { } + + /** + * {@inheritDoc} + * @throws OdfException + */ + public void executeFromParent(TagExecutable child) throws OdfException { + child.execute(this); + } + +} Index: src/java/org/apache/fop/render/odf/odt/tags/LeaderTag.java =================================================================== --- src/java/org/apache/fop/render/odf/odt/tags/LeaderTag.java (revision 0) +++ src/java/org/apache/fop/render/odf/odt/tags/LeaderTag.java (revision 0) @@ -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. + */ + +package org.apache.fop.render.odf.odt.tags; + +import org.apache.fop.fo.flow.Leader; +import org.apache.fop.render.odf.OdfException; + +/** + * Leader converter + */ +public class LeaderTag extends Tag { + + protected LeaderTag(Tag parent, Leader foNode) { + super(parent); + } + + /** + * {@inheritDoc} + */ + @Override + public void execute() { + // TODO Auto-generated method stub + + } + + /** + * {@inheritDoc} + * @throws OdfException + */ + public void executeFromParent(TagExecutable child) throws OdfException { + child.execute(this); + } + +} Index: src/java/org/apache/fop/render/odf/odt/tags/TagFactory.java =================================================================== --- src/java/org/apache/fop/render/odf/odt/tags/TagFactory.java (revision 0) +++ src/java/org/apache/fop/render/odf/odt/tags/TagFactory.java (revision 0) @@ -0,0 +1,116 @@ +/* + * 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. + */ + +package org.apache.fop.render.odf.odt.tags; + +import org.apache.fop.fo.FONode; +import org.apache.fop.fo.FOText; +import org.apache.fop.fo.flow.BasicLink; +import org.apache.fop.fo.flow.Block; +import org.apache.fop.fo.flow.BlockContainer; +import org.apache.fop.fo.flow.Character; +import org.apache.fop.fo.flow.ExternalGraphic; +import org.apache.fop.fo.flow.Footnote; +import org.apache.fop.fo.flow.FootnoteBody; +import org.apache.fop.fo.flow.Inline; +import org.apache.fop.fo.flow.InstreamForeignObject; +import org.apache.fop.fo.flow.Leader; +import org.apache.fop.fo.flow.ListBlock; +import org.apache.fop.fo.flow.ListItem; +import org.apache.fop.fo.flow.ListItemBody; +import org.apache.fop.fo.flow.ListItemLabel; +import org.apache.fop.fo.flow.PageNumber; +import org.apache.fop.fo.flow.PageNumberCitation; +import org.apache.fop.fo.flow.table.Table; +import org.apache.fop.fo.flow.table.TableBody; +import org.apache.fop.fo.flow.table.TableCell; +import org.apache.fop.fo.flow.table.TableColumn; +import org.apache.fop.fo.flow.table.TableFooter; +import org.apache.fop.fo.flow.table.TableHeader; +import org.apache.fop.fo.flow.table.TableRow; +import org.apache.fop.fo.pagination.Flow; +import org.apache.fop.fo.pagination.PageSequence; +import org.apache.fop.fo.pagination.StaticContent; +import org.apache.fop.render.odf.OdfException; +import org.apache.fop.render.odf.odt.FopOdtConverter; + +/** + * Factory that creates tag converters + */ +public class TagFactory { + + public Tag getTag(FopOdtConverter converter, FONode foNode, Tag actualTag) throws OdfException { + if (foNode instanceof PageSequence) { + return new PageSequenceTag(actualTag, (PageSequence) foNode, converter); + } else if (foNode instanceof Flow) { + return new FlowTag(actualTag, (Flow) foNode); + } else if (foNode instanceof StaticContent) { + return new StaticContentTag(actualTag, (StaticContent) foNode); + } else if (foNode instanceof ExternalGraphic) { + return new ExternalGraphicTag(actualTag, (ExternalGraphic) foNode); + } else if (foNode instanceof InstreamForeignObject) { + return new InstreamForeignObjectTag(actualTag, (InstreamForeignObject) foNode); + } else if (foNode instanceof Block) { + return new BlockTag(actualTag, (Block) foNode); + } else if (foNode instanceof BlockContainer) { + return new BlockContainerTag(actualTag, (BlockContainer) foNode); + } else if (foNode instanceof BasicLink) { + return new BasicLinkTag(actualTag, (BasicLink) foNode); + } else if (foNode instanceof Inline) { + return new InlineTag(actualTag, (Inline) foNode); + } else if (foNode instanceof FOText) { + return new Text(actualTag, (FOText) foNode); + } else if (foNode instanceof Character) { + return new CharacterTag(actualTag, (Character) foNode); + } else if (foNode instanceof PageNumber) { + return new PageNumberTag(actualTag, (PageNumber) foNode); + } else if (foNode instanceof Footnote) { + return new FootnoteTag(actualTag, (Footnote) foNode); + } else if (foNode instanceof FootnoteBody) { + return new FootnoteBodyTag(actualTag, (FootnoteBody) foNode); + } else if (foNode instanceof ListBlock) { + return new ListBlockTag(actualTag, (ListBlock) foNode); + } else if (foNode instanceof ListItemBody) { + return new ListItemBodyTag(actualTag, (ListItemBody) foNode); + } else if (foNode instanceof ListItem) { + return new ListItemTag(actualTag, (ListItem) foNode, converter); + } else if (foNode instanceof ListItemLabel) { + return new ListItemLabelTag(actualTag, (ListItemLabel) foNode); + } else if (foNode instanceof Table) { + return new TableTag(actualTag, (Table) foNode); + } else if (foNode instanceof TableHeader) { + return new TableHeaderTag(actualTag, (TableHeader) foNode); + } else if (foNode instanceof TableFooter) { + return new TableFooterTag(actualTag, (TableFooter) foNode); + } else if (foNode instanceof TableBody) { + return new TableBodyTag(actualTag, (TableBody) foNode); + } else if (foNode instanceof TableColumn) { + return new TableColumnTag(actualTag, (TableColumn) foNode); + } else if (foNode instanceof TableRow) { + return new TableRowTag(actualTag, (TableRow) foNode); + } else if (foNode instanceof TableCell) { + return new TableCellTag(actualTag, (TableCell) foNode); + } else if (foNode instanceof Leader) { + return new LeaderTag(actualTag, (Leader) foNode); + } else if (foNode instanceof PageNumberCitation) { + return new PageNumberCitationTag(actualTag, (PageNumberCitation) foNode); + } else { + return new UnknownTag(actualTag); + } + } + +} Index: src/java/org/apache/fop/render/odf/odt/tags/ListItemTag.java =================================================================== --- src/java/org/apache/fop/render/odf/odt/tags/ListItemTag.java (revision 0) +++ src/java/org/apache/fop/render/odf/odt/tags/ListItemTag.java (revision 0) @@ -0,0 +1,90 @@ +/* + * 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. + */ + +package org.apache.fop.render.odf.odt.tags; + +import org.odftoolkit.odfdom.dom.element.text.TextListItemElement; +import org.odftoolkit.odfdom.pkg.OdfXMLFactory; + +import org.apache.fop.fo.flow.ListItem; +import org.apache.fop.render.odf.OdfException; +import org.apache.fop.render.odf.odt.FopOdtConverter; + +/** + * ListItem converter + */ +public class ListItemTag extends Tag { + + private ListItem xslfoListItem = null; + + private TextListItemElement tlie = null; + + private FopOdtConverter converter = null; + + ListItemTag(Tag parent, ListItem foNode, FopOdtConverter converter) { + super(parent); + this.xslfoListItem = foNode; + this.converter = converter; + } + + public ListItem getXslfoListItem() { + return xslfoListItem; + } + + public TextListItemElement getTextListItemElement() { + return tlie; + } + + /** + * {@inheritDoc} + * @throws OdfException + */ + @Override + public void execute() throws OdfException { + try { + tlie = (TextListItemElement) OdfXMLFactory.newOdfElement(this.getOdt().getContentDom(), TextListItemElement.ELEMENT_NAME); + } catch (Exception e) { + throw new OdfException("Can't create List Item", e); + } + + parent.executeFromParent(this); + + converter.convertRecursively(xslfoListItem.getBody()); + } + + /** + * {@inheritDoc} + * @throws OdfException + */ + @Override + public void execute(ListBlockTag tag) throws OdfException { + try { + tag.getTextListElement().appendChild(tlie); + } catch (Exception e) { + throw new OdfException("Can't create List Item", e); + } + } + + /** + * {@inheritDoc} + * @throws OdfException + */ + public void executeFromParent(TagExecutable child) throws OdfException { + child.execute(this); + } + +} Index: src/java/org/apache/fop/render/odf/odt/tags/Tag.java =================================================================== --- src/java/org/apache/fop/render/odf/odt/tags/Tag.java (revision 0) +++ src/java/org/apache/fop/render/odf/odt/tags/Tag.java (revision 0) @@ -0,0 +1,221 @@ +/* + * 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. + */ + +package org.apache.fop.render.odf.odt.tags; + +import java.util.Map; +import java.util.Random; +import java.util.Vector; + +import org.odftoolkit.odfdom.dom.OdfContentDom; +import org.odftoolkit.odfdom.dom.element.style.StyleFontFaceElement; +import org.odftoolkit.odfdom.dom.element.style.StyleStyleElement; +import org.odftoolkit.odfdom.dom.element.text.TextPElement; +import org.odftoolkit.odfdom.pkg.OdfElement; +import org.odftoolkit.odfdom.pkg.OdfXMLFactory; +import org.odftoolkit.simple.TextDocument; +import org.odftoolkit.simple.text.Paragraph; +import org.w3c.dom.DOMException; +import org.w3c.dom.Node; + +import org.apache.fop.fo.pagination.Flow; +import org.apache.fop.render.odf.FopTagType; +import org.apache.fop.render.odf.OdfException; +import org.apache.fop.render.odf.odt.Namespace; +import org.apache.fop.render.odf.odt.Style; + +/** + * Tag converter abstract class. + */ +public abstract class Tag implements TagExecutable, TagExecutor { + + protected Tag parent = null; + + protected Style currentStyle = null; + + private static Random rand = new Random(); + + protected Tag(Tag parent) { + this.parent = parent; + if (parent != null) { + currentStyle = new Style(parent.getStyle()); + } else { + currentStyle = new Style(); + } + } + + protected TextDocument getOdt() { + return parent != null ? parent.getOdt() : null; + } + + protected Map getUsedStyles() { + return parent.getUsedStyles(); + } + + protected Vector getUsedFonts() { + return parent.getUsedFonts(); + } + + protected void registerFont(String font) throws OdfException { + if (!this.getUsedFonts().contains(font)) { + StyleFontFaceElement sffe = null; + try { + sffe = (StyleFontFaceElement) OdfXMLFactory.newOdfElement(this.getOdt().getContentDom(), StyleFontFaceElement.ELEMENT_NAME); + } catch (Exception e) { + throw new OdfException("Can't create new style.", e); + } + + if (isOnlyOneParagraph(this.getOdt())) { + removeLastParagraph(this.getOdt()); + } + + sffe.setStyleNameAttribute(font); + sffe.setAttributeNS(Namespace.SVG, "svg:font-family", font); + try { + this.getOdt().getContentDom().getElementsByTagNameNS(Namespace.OFFICE, "font-face-decls").item(0).appendChild(sffe); + } catch (Exception e) { + throw new OdfException("Can't register new font", e); + } + this.getUsedFonts().add(font); + } + } + + private boolean isOnlyOneParagraph(TextDocument textDocument) { + int i = 0; + try { + i = textDocument.getContentDom().getElementsByTagNameNS(Namespace.TEXT, "p").getLength(); + } catch (Exception e) { + return false; + } + return i == 1 ? true : false; + } + + private void removeLastParagraph(TextDocument textDocument) { + try { + textDocument.getContentDom().getElementsByTagNameNS(Namespace.OFFICE, "text").item(0).removeChild(textDocument.getContentDom().getElementsByTagNameNS(Namespace.TEXT, "p").item(0)); + } catch (Exception e) { + e.printStackTrace(); + } + } + + protected Style getStyle() { + return this.currentStyle; + } + + public Tag getParent() { + return parent; + } + + protected Paragraph getParagraph() throws OdfException { + return parent != null ? parent.getParagraph() : null; + } + + protected OdfElement getParagraphContainer() { + return parent != null ? parent.getParagraphContainer() : null; + } + + protected Paragraph newParagraph(Node paragraphContainer) throws OdfException { + + TextPElement tpe = null; + + try { + tpe = (TextPElement) OdfXMLFactory.newOdfElement(this.getOdt().getContentDom(), TextPElement.ELEMENT_NAME); + } catch (Exception e1) { + throw new OdfException("Can't create new style.", e1); + } + + try { + paragraphContainer.appendChild(tpe); + } catch (DOMException e) { + throw new OdfException("Can't create new paragraph", e); + } + + return Paragraph.getInstanceof(tpe); + } + + protected String appendNewStyle(StyleStyleElement sse) throws OdfException { + + sse.setAttributeNS(Namespace.STYLE, "style:name", ""); + + String styleName = Style.getStyleName(this.getUsedStyles(), sse); + + if (styleName == null) { + styleName = generateName(); + sse.setAttributeNS(Namespace.STYLE, "style:name", styleName); + + try { + OdfContentDom odf = this.getOdt().getContentDom(); + Node odfstyles = odf.getElementsByTagNameNS(Namespace.OFFICE, "automatic-styles").item(0); + odfstyles.appendChild(sse); + } catch (Exception e) { + throw new OdfException("Can't create new style.", e); + } + + this.getUsedStyles().put(styleName, sse); + } + + return styleName; + } + + private String generateName() { + return Integer.toString(rand.nextInt()); + } + + public abstract void execute() throws OdfException; + + public Tag execute(Flow fl, FopTagType type) { + return this; + } + + public void closeIntercept() throws OdfException { } + + public void execute(Tag tag) throws OdfException { + } + + public void execute(BlockTag tag) throws OdfException { + this.execute((Tag) tag); + } + + public void execute(InlineTag tag) throws OdfException { + this.execute((Tag) tag); + } + + public void execute(BasicLinkTag tag) throws OdfException { + this.execute((Tag) tag); + } + + public void execute(TableTag tag) throws OdfException { + this.execute((Tag) tag); + } + + public void execute(TableRowTag tag) throws OdfException { + this.execute((Tag) tag); + } + + public void execute(TableCellTag tag) throws OdfException { + this.execute((Tag) tag); + } + + public void execute(ListBlockTag tag) throws OdfException { + this.execute((Tag) tag); + } + + public void execute(ListItemTag tag) throws OdfException { + this.execute((Tag) tag); + } + +} Index: src/java/org/apache/fop/render/odf/odt/tags/Text.java =================================================================== --- src/java/org/apache/fop/render/odf/odt/tags/Text.java (revision 0) +++ src/java/org/apache/fop/render/odf/odt/tags/Text.java (revision 0) @@ -0,0 +1,70 @@ +/* + * 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. + */ + +package org.apache.fop.render.odf.odt.tags; + +import org.apache.fop.fo.FOText; +import org.apache.fop.render.odf.OdfException; + +/** + * Text converter + */ +public class Text extends Tag { + + private String string = null; + + Text(Tag parent, FOText textFop) { + super(parent); + this.string = textFop.getCharSequence().toString(); + } + + @Override + public void execute() throws OdfException { + + if (string.length() == 0) { + return; + } + + parent.executeFromParent(this); + } + + @Override + public void execute(Tag parent) throws OdfException { + this.getParagraph().appendTextContent(string, false); + } + + @Override + public void execute(BlockTag parent) throws OdfException { + this.getParagraph().appendTextContent(string, false); + } + + @Override + public void execute(InlineTag parent) { + parent.getTextSpanElement().setTextContent(string); + } + + @Override + public void execute(BasicLinkTag parent) { + parent.getLinkElement().setTextContent(string); + } + + public void executeFromParent(TagExecutable child) throws OdfException { + if (this != child) { + child.execute(this); + } + } +} Index: src/java/org/apache/fop/render/odf/odt/tags/TableFooterTag.java =================================================================== --- src/java/org/apache/fop/render/odf/odt/tags/TableFooterTag.java (revision 0) +++ src/java/org/apache/fop/render/odf/odt/tags/TableFooterTag.java (revision 0) @@ -0,0 +1,39 @@ +/* + * 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. + */ + +package org.apache.fop.render.odf.odt.tags; + +import org.apache.fop.fo.flow.table.TableFooter; +import org.apache.fop.render.odf.OdfException; + +/** + * TableFooter converter + */ +public class TableFooterTag extends Tag { + + TableFooterTag(Tag parent, TableFooter tblFooter) { + super(parent); + } + + @Override + public void execute() { } + + public void executeFromParent(TagExecutable child) throws OdfException { + child.execute(this); + } + +} Index: src/java/org/apache/fop/render/odf/odt/tags/BasicLinkTag.java =================================================================== --- src/java/org/apache/fop/render/odf/odt/tags/BasicLinkTag.java (revision 0) +++ src/java/org/apache/fop/render/odf/odt/tags/BasicLinkTag.java (revision 0) @@ -0,0 +1,108 @@ +/* + * 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. + */ + +package org.apache.fop.render.odf.odt.tags; + +import org.odftoolkit.odfdom.dom.element.text.TextAElement; +import org.odftoolkit.odfdom.dom.element.text.TextBookmarkRefElement; +import org.odftoolkit.odfdom.pkg.OdfElement; +import org.odftoolkit.odfdom.pkg.OdfXMLFactory; + +import org.w3c.dom.DOMException; + +import org.apache.fop.fo.flow.BasicLink; +import org.apache.fop.render.odf.OdfException; +import org.apache.fop.render.odf.odt.Namespace; +import org.apache.fop.render.odf.odt.Style; +import org.apache.fop.render.odf.odt.Style.Params; + +/** + * VasicLink converter + */ +public class BasicLinkTag extends Tag { + + BasicLink basicLink = null; + + OdfElement oe = null; + + /** + * Constructor. + */ + public BasicLinkTag(Tag parent, BasicLink basicLink) { + super(parent); + this.basicLink = basicLink; + + this.currentStyle.getParameters().put(Params.FONT_NAME, basicLink.getCommonFont().getFirstFontFamily().split(",")[0]); + this.currentStyle.getParameters().put(Params.FONT_STYLE, Style.fopFontToOdfFontStyle( basicLink.getCommonFont())); + this.currentStyle.getParameters().put(Params.FONT_WEIGHT, Style.fopFontToOdfFontWeight( basicLink.getCommonFont())); + this.currentStyle.getParameters().put(Params.FONT_SIZE, Style.fopLengthToPt( basicLink.getCommonFont().getFontSize())); + this.currentStyle.getParameters().put(Params.COLOR, Style.awtColorToOdfColor( basicLink.getColor())); + } + + public OdfElement getLinkElement() { + return oe; + } + + /** + * {@inheritDoc} + */ + @Override + public void execute() { + if (basicLink.hasExternalDestination()) { + try { + oe = (TextAElement) OdfXMLFactory.newOdfElement(this.getOdt().getContentDom(), TextAElement.ELEMENT_NAME); + } catch (Exception e1) { + e1.printStackTrace(); + } + String url = basicLink.getExternalDestination(); + if (url.startsWith("url")) { + url = url.substring(5, url.length() - 2); + } + oe.setAttributeNS(Namespace.XLINK, "xlink:href", url); + oe.setAttributeNS(Namespace.XLINK, "xlink:type", "simple"); + } else if (basicLink.hasInternalDestination()) { + try { + oe = (TextBookmarkRefElement) OdfXMLFactory.newOdfElement(this.getOdt().getContentDom(), TextBookmarkRefElement.ELEMENT_NAME); + } catch (Exception e) { + e.printStackTrace(); + } + oe.setAttributeNS(Namespace.TEXT, "text:ref-name", basicLink.getInternalDestination()); + oe.setAttributeNS(Namespace.TEXT, "text:reference-format", "page"); + } + } + + /** + * {@inheritDoc} + * @throws OdfException + */ + @Override + public void closeIntercept() throws OdfException { + try { + this.getParagraph().getOdfElement().appendChild(oe); + } catch (DOMException e) { + e.printStackTrace(); + } + } + + /** + * {@inheritDoc} + * @throws OdfException + */ + public void executeFromParent(TagExecutable child) throws OdfException { + child.execute(this); + } +} Index: src/java/org/apache/fop/render/odf/odt/tags/StaticTag.java =================================================================== --- src/java/org/apache/fop/render/odf/odt/tags/StaticTag.java (revision 0) +++ src/java/org/apache/fop/render/odf/odt/tags/StaticTag.java (revision 0) @@ -0,0 +1,37 @@ +/* + * 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. + */ + +package org.apache.fop.render.odf.odt.tags; + +import org.apache.fop.render.odf.OdfException; + +/** + * + */ +public class StaticTag extends Tag { + + protected StaticTag(Tag parent) { + super(parent); + } + + @Override + public void execute() { } + + public void executeFromParent(TagExecutable child) throws OdfException { + child.execute(this); + } +} Index: src/java/org/apache/fop/render/odf/odt/tags/TableTag.java =================================================================== --- src/java/org/apache/fop/render/odf/odt/tags/TableTag.java (revision 0) +++ src/java/org/apache/fop/render/odf/odt/tags/TableTag.java (revision 0) @@ -0,0 +1,98 @@ +/* + * 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. + */ + +package org.apache.fop.render.odf.odt.tags; + +import org.odftoolkit.odfdom.dom.element.table.TableTableColumnElement; +import org.odftoolkit.odfdom.dom.element.table.TableTableElement; +import org.odftoolkit.odfdom.pkg.OdfXMLFactory; +import org.w3c.dom.DOMException; + + +import org.apache.fop.fo.flow.table.Table; +import org.apache.fop.render.odf.OdfException; +import org.apache.fop.render.odf.odt.Namespace; + +/** + * Table converter + */ +public class TableTag extends Tag { + + private Table table = null; + + private TableTableElement tte = null; + + TableTag(Tag parent, Table table) { + super(parent); + this.table = table; + } + + public TableTableElement getTable() { + return tte; + } + + /** + * {@inheritDoc} + * @throws OdfException + */ + @Override + public void execute() throws OdfException { + + try { + tte = (TableTableElement) OdfXMLFactory.newOdfElement(this.getOdt().getContentDom(), TableTableElement.ELEMENT_NAME); + } catch (Exception e) { + throw new OdfException("Can't create new table.", e); + } + tte.setAttributeNS(Namespace.TABLE, "table:align", "margins"); + + if (table.getColumns().size() > 1) { + TableTableColumnElement tcne = null; + try { + tcne = (TableTableColumnElement) OdfXMLFactory.newOdfElement(this.getOdt().getContentDom(), TableTableColumnElement.ELEMENT_NAME); + } catch (Exception e) { + throw new OdfException("Can't create new table column.", e); + } + tcne.setAttributeNS(Namespace.TABLE, + "table:number-columns-repeated", + Integer.toString(table.getColumns().size())); + + try { + tte.appendChild(tcne); + } catch (Exception e) { + throw new OdfException("Can't create table.", e); + } + } + } + + /** + * {@inheritDoc} + */ + @Override + public void closeIntercept() { + try { + this.getOdt().getTableContainerElement().appendChild(tte); + } catch (DOMException e) { + e.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public void executeFromParent(TagExecutable child) throws OdfException { + child.execute(this); + } +} Index: src/java/org/apache/fop/render/odf/odt/tags/UnknownTag.java =================================================================== --- src/java/org/apache/fop/render/odf/odt/tags/UnknownTag.java (revision 0) +++ src/java/org/apache/fop/render/odf/odt/tags/UnknownTag.java (revision 0) @@ -0,0 +1,38 @@ +/* + * 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. + */ + +package org.apache.fop.render.odf.odt.tags; + +import org.apache.fop.render.odf.OdfException; + +/** + * Unknown tag converter + */ +public class UnknownTag extends Tag { + + protected UnknownTag(Tag parent) { + super(parent); + } + + @Override + public void execute() { } + + public void executeFromParent(TagExecutable child) throws OdfException { + child.execute(this); + } + +} Index: src/java/org/apache/fop/render/odf/odt/tags/FootnoteBodyTag.java =================================================================== --- src/java/org/apache/fop/render/odf/odt/tags/FootnoteBodyTag.java (revision 0) +++ src/java/org/apache/fop/render/odf/odt/tags/FootnoteBodyTag.java (revision 0) @@ -0,0 +1,46 @@ +/* + * 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. + */ + +package org.apache.fop.render.odf.odt.tags; + +import org.apache.fop.fo.flow.FootnoteBody; +import org.apache.fop.render.odf.OdfException; + +/** + * FootnoteBodyConverter + */ +public class FootnoteBodyTag extends Tag { + + protected FootnoteBodyTag(Tag parent, FootnoteBody foNode) { + super(parent); + } + + /** + * {@inheritDoc} + */ + @Override + public void execute() { } + + /** + * {@inheritDoc} + * @throws OdfException + */ + public void executeFromParent(TagExecutable child) throws OdfException { + child.execute(this); + } + +} Index: src/java/org/apache/fop/render/odf/odt/tags/BlockContainerTag.java =================================================================== --- src/java/org/apache/fop/render/odf/odt/tags/BlockContainerTag.java (revision 0) +++ src/java/org/apache/fop/render/odf/odt/tags/BlockContainerTag.java (revision 0) @@ -0,0 +1,51 @@ +/* + * 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. + */ + +package org.apache.fop.render.odf.odt.tags; + +import org.apache.fop.fo.flow.BlockContainer; +import org.apache.fop.render.odf.OdfException; + +/** + * BlockContainer converter + */ +public class BlockContainerTag extends Tag { + + /** + * Constructor + */ + protected BlockContainerTag(Tag parent, BlockContainer foNode) { + super(parent); + } + + /** + * {@inheritDoc} + */ + @Override + public void execute() { + + } + + /** + * {@inheritDoc} + * @throws OdfException + */ + public void executeFromParent(TagExecutable child) throws OdfException { + child.execute(this); + } + +} Index: src/java/org/apache/fop/render/odf/odt/tags/PageSequenceTag.java =================================================================== --- src/java/org/apache/fop/render/odf/odt/tags/PageSequenceTag.java (revision 0) +++ src/java/org/apache/fop/render/odf/odt/tags/PageSequenceTag.java (revision 0) @@ -0,0 +1,113 @@ +/* + * 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. + */ + +package org.apache.fop.render.odf.odt.tags; + +import org.apache.fop.fo.pagination.PageSequence; +import org.apache.fop.fo.pagination.PageSequenceMaster; +import org.apache.fop.fo.pagination.SimplePageMaster; +import org.apache.fop.render.odf.OdfException; +import org.apache.fop.render.odf.odt.FopOdtConverter; + +/** + * Defines a number of standard constants (keys) for use by the RendererContext class. + */ +public class PageSequenceTag extends Tag { + + protected PageSequence pageSeq = null; + + protected FopOdtConverter converter = null; + + protected SimplePageMaster pagemaster = null; + + PageSequenceTag(Tag parent, PageSequence pageSeq, FopOdtConverter converter) { + super(parent); + this.pageSeq = pageSeq; + this.converter = converter; + + String reference = pageSeq.getMasterReference(); + this.pagemaster = pageSeq.getRoot().getLayoutMasterSet().getSimplePageMaster(reference); + if (pagemaster == null) { + PageSequenceMaster master = pageSeq.getRoot().getLayoutMasterSet().getPageSequenceMaster(reference); + this.pagemaster = master.getNextSimplePageMaster(false, false, false, false, ""); + } + + //if(!isFirstPageSequence()) this.getOdt().addPageBreak(); + + //read page size and margins, if specified + //only simple-page-master supported, so pagemaster may be null + + //builderContext.pushContainer(sect); + + //Calculate usable page width for this flow + //int useAblePageWidth = pagemaster.getPageWidth().getValue() + // - pagemaster.getCommonMarginBlock().marginLeft.getValue() + // - pagemaster.getCommonMarginBlock().marginRight.getValue() + //percentManager.setDimension(pageSeq, useAblePageWidth); + + //bHeaderSpecified = false; + //bFooterSpecified = false; + + /*Region regionBefore = pagemaster.getRegion(Constants.FO_REGION_BEFORE); + if (regionBefore != null) { + FONode staticBefore = (FONode) pageSequence.getFlowMap().get(regionBefore.getRegionName()); + if (staticBefore != null) recurseFONode(staticBefore); + } + + Region regionAfter = pagemaster.getRegion(Constants.FO_REGION_AFTER); + if (regionAfter != null) { + FONode staticAfter = (FONode) pageSequence.getFlowMap().get(regionAfter.getRegionName()); + if (staticAfter != null) recurseFONode(staticAfter); + }*/ + } + + //private boolean isFirstPageSequence() { + // TODO Auto-generated method stub + // return false; + //} + + /** + * {@inheritDoc} + */ + @Override + public void execute() { + setMargins(); + converter.convertRecursively(pageSeq.getMainFlow()); + } + + private void setMargins() { + //int a = this.pagemaster.getPageWidth().getValue(); + //int b = this.pagemaster.getPageHeight().getValue(); + //int c = this.pagemaster.getCommonMarginBlock().marginLeft.getValue(); + //int d = this.pagemaster.getCommonMarginBlock().marginRight.getValue(); + } + + /** + * {@inheritDoc} + */ + @Override + public void closeIntercept() { + } + + /** + * {@inheritDoc} + * @throws OdfException + */ + public void executeFromParent(TagExecutable child) throws OdfException { + child.execute(this); + } +} Index: src/java/org/apache/fop/render/odf/odt/tags/TableColumnTag.java =================================================================== --- src/java/org/apache/fop/render/odf/odt/tags/TableColumnTag.java (revision 0) +++ src/java/org/apache/fop/render/odf/odt/tags/TableColumnTag.java (revision 0) @@ -0,0 +1,46 @@ +/* + * 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. + */ + +package org.apache.fop.render.odf.odt.tags; + +import org.apache.fop.fo.flow.table.TableColumn; +import org.apache.fop.render.odf.OdfException; + +/** + * TableColumn converter + */ +public class TableColumnTag extends Tag { + + TableColumnTag(Tag parent, TableColumn tblColumn) { + super(parent); + } + + /** + * {@inheritDoc} + */ + @Override + public void execute() { } + + /** + * {@inheritDoc} + * @throws OdfException + */ + public void executeFromParent(TagExecutable child) throws OdfException { + child.execute(this); + } + +} Index: src/java/org/apache/fop/render/odf/odt/tags/ListItemBodyTag.java =================================================================== --- src/java/org/apache/fop/render/odf/odt/tags/ListItemBodyTag.java (revision 0) +++ src/java/org/apache/fop/render/odf/odt/tags/ListItemBodyTag.java (revision 0) @@ -0,0 +1,46 @@ +/* + * 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. + */ + +package org.apache.fop.render.odf.odt.tags; + +import org.apache.fop.fo.flow.ListItemBody; +import org.apache.fop.render.odf.OdfException; + +/** + * ListItemBody converter + */ +public class ListItemBodyTag extends Tag { + + protected ListItemBodyTag(Tag parent, ListItemBody foNode) { + super(parent); + } + + /** + * {@inheritDoc} + */ + @Override + public void execute() { } + + /** + * {@inheritDoc} + * @throws OdfException + */ + public void executeFromParent(TagExecutable child) throws OdfException { + parent.executeFromParent(child); + } + +} Index: src/java/org/apache/fop/render/odf/odt/tags/InlineTag.java =================================================================== --- src/java/org/apache/fop/render/odf/odt/tags/InlineTag.java (revision 0) +++ src/java/org/apache/fop/render/odf/odt/tags/InlineTag.java (revision 0) @@ -0,0 +1,121 @@ +/* + * 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. + */ + +package org.apache.fop.render.odf.odt.tags; + +import org.odftoolkit.odfdom.dom.OdfContentDom; +import org.odftoolkit.odfdom.dom.element.style.StyleStyleElement; +import org.odftoolkit.odfdom.dom.element.style.StyleTextPropertiesElement; +import org.odftoolkit.odfdom.dom.element.text.TextSpanElement; +import org.odftoolkit.odfdom.pkg.OdfXMLFactory; +import org.w3c.dom.Node; + +import org.apache.fop.fo.flow.Inline; +import org.apache.fop.render.odf.OdfException; +import org.apache.fop.render.odf.odt.Namespace; +import org.apache.fop.render.odf.odt.Style; +import org.apache.fop.render.odf.odt.Style.Params; + +/** + * Inline converter + */ +public class InlineTag extends Tag { + + protected TextSpanElement tse = null; + + InlineTag(Tag parent, Inline inl) throws OdfException { + super(parent); + + this.currentStyle.getParameters().put(Params.FONT_NAME, inl.getCommonFont().getFirstFontFamily().split(",")[0]); + this.currentStyle.getParameters().put(Params.FONT_STYLE, Style.fopFontToOdfFontStyle( inl.getCommonFont())); + this.currentStyle.getParameters().put(Params.FONT_WEIGHT, Style.fopFontToOdfFontWeight( inl.getCommonFont())); + this.currentStyle.getParameters().put(Params.FONT_SIZE, Style.fopLengthToPt( inl.getCommonFont().getFontSize())); + this.currentStyle.getParameters().put(Params.COLOR, Style.awtColorToOdfColor( inl.getColor())); + + registerFont(this.currentStyle.getParameters().get(Params.FONT_NAME)); + } + + public TextSpanElement getTextSpanElement() { + return tse; + } + + /** + * {@inheritDoc} + * @throws OdfException + */ + @Override + public void execute() throws OdfException { + try { + tse = (TextSpanElement) OdfXMLFactory.newOdfElement(this.getOdt().getContentDom(), TextSpanElement.ELEMENT_NAME); + } catch (Exception e) { + throw new OdfException("Can't create text span.", e); + } + + StyleStyleElement sse = null; + try { + sse = (StyleStyleElement) OdfXMLFactory.newOdfElement(this.getOdt().getContentDom(), StyleStyleElement.ELEMENT_NAME); + } catch (Exception e) { + throw new OdfException("Can't create new style for text span.", e); + } + + sse.setAttributeNS(Namespace.STYLE, "style:family", "text"); + + StyleTextPropertiesElement stpe = null; + + try { + stpe = (StyleTextPropertiesElement) OdfXMLFactory.newOdfElement(this.getOdt().getContentDom(), StyleTextPropertiesElement.ELEMENT_NAME); + } catch (Exception e) { + throw new OdfException("Can't create new style for text span.", e); + } + + stpe.setAttributeNS(Namespace.FO, "fo:font-size", this.currentStyle.get(Params.FONT_SIZE)); + stpe.setAttributeNS(Namespace.FO, "fo:font-weight", this.currentStyle.get(Params.FONT_WEIGHT)); + stpe.setAttributeNS(Namespace.FO, "fo:font-style", this.currentStyle.get(Params.FONT_STYLE)); + stpe.setAttributeNS(Namespace.FO, "fo:color", this.currentStyle.get(Params.COLOR)); + stpe.setAttributeNS(Namespace.STYLE, "style:font-name", this.currentStyle.get(Params.FONT_NAME)); + + sse.appendChild(stpe); + + try { + OdfContentDom odf = this.getOdt().getContentDom(); + Node odfstyles = odf.getElementsByTagNameNS(Namespace.OFFICE, "automatic-styles").item(0); + odfstyles.appendChild(sse); + } catch (Exception e) { + throw new OdfException("Can't create new style.", e); + } + + tse.setStyleName(this.appendNewStyle(sse)); + } + + /** + * {@inheritDoc} + * @throws OdfException + */ + @Override + public void closeIntercept() throws OdfException { + this.getParagraph().getOdfElement().appendChild(tse); + } + + /** + * {@inheritDoc} + * @throws OdfException + */ + public void executeFromParent(TagExecutable child) throws OdfException { + child.execute(this); + } + +} Index: src/java/org/apache/fop/render/odf/odt/tags/CharacterTag.java =================================================================== --- src/java/org/apache/fop/render/odf/odt/tags/CharacterTag.java (revision 0) +++ src/java/org/apache/fop/render/odf/odt/tags/CharacterTag.java (revision 0) @@ -0,0 +1,46 @@ +/* + * 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. + */ + +package org.apache.fop.render.odf.odt.tags; + +import org.apache.fop.fo.flow.Character; +import org.apache.fop.render.odf.OdfException; + +/** + * Character converter + */ +public class CharacterTag extends Tag { + + CharacterTag(Tag actualTag, Character foNode) { + super(actualTag); + } + + /** + * {@inheritDoc} + */ + @Override + public void execute() { } + + /** + * {@inheritDoc} + * @throws OdfException + */ + public void executeFromParent(TagExecutable child) throws OdfException { + child.execute(this); + } + +} Index: src/java/org/apache/fop/render/odf/odt/tags/FootnoteTag.java =================================================================== --- src/java/org/apache/fop/render/odf/odt/tags/FootnoteTag.java (revision 0) +++ src/java/org/apache/fop/render/odf/odt/tags/FootnoteTag.java (revision 0) @@ -0,0 +1,52 @@ +/* + * 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. + */ + +package org.apache.fop.render.odf.odt.tags; + +import org.apache.fop.fo.flow.Footnote; +import org.apache.fop.render.odf.OdfException; + +/** + * Footnote converter + */ +public class FootnoteTag extends Tag { + + FootnoteTag(Tag parent, Footnote foNode) { + super(parent); + } + + /** + * {@inheritDoc} + */ + @Override + public void execute() { + /*Footnote fn = (Footnote)foNode; + + recurseFONode(fn.getFootnoteCitation()); + recurseFONode(fn.getFootnoteBody()); */ + + } + + /** + * {@inheritDoc} + * @throws OdfException + */ + public void executeFromParent(TagExecutable child) throws OdfException { + child.execute(this); + } + +} Index: src/java/org/apache/fop/render/odf/odt/tags/FlowTag.java =================================================================== --- src/java/org/apache/fop/render/odf/odt/tags/FlowTag.java (revision 0) +++ src/java/org/apache/fop/render/odf/odt/tags/FlowTag.java (revision 0) @@ -0,0 +1,45 @@ +/* + * 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. + */ + +package org.apache.fop.render.odf.odt.tags; + +import org.apache.fop.fo.pagination.Flow; +import org.apache.fop.render.odf.OdfException; + +/** + * Flow converter. + */ +public class FlowTag extends Tag { + + FlowTag(Tag parent, Flow fl) { + super(parent); + } + + /** + * {@inheritDoc} + */ + @Override + public void execute() { } + + /** + * {@inheritDoc} + * @throws OdfException + */ + public void executeFromParent(TagExecutable child) throws OdfException { + child.execute(this); + } +} Index: src/java/org/apache/fop/render/odf/odt/tags/PageNumberTag.java =================================================================== --- src/java/org/apache/fop/render/odf/odt/tags/PageNumberTag.java (revision 0) +++ src/java/org/apache/fop/render/odf/odt/tags/PageNumberTag.java (revision 0) @@ -0,0 +1,46 @@ +/* + * 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. + */ + +package org.apache.fop.render.odf.odt.tags; + +import org.apache.fop.fo.flow.PageNumber; +import org.apache.fop.render.odf.OdfException; + +/** + * PageNumber converter + */ +public class PageNumberTag extends Tag { + + PageNumberTag(Tag parent, PageNumber foNode) { + super(parent); + } + + /** + * {@inheritDoc} + */ + @Override + public void execute() { } + + /** + * {@inheritDoc} + * @throws OdfException + */ + public void executeFromParent(TagExecutable child) throws OdfException { + child.execute(this); + } + +} Index: src/java/org/apache/fop/render/odf/odt/tags/BlockTag.java =================================================================== --- src/java/org/apache/fop/render/odf/odt/tags/BlockTag.java (revision 0) +++ src/java/org/apache/fop/render/odf/odt/tags/BlockTag.java (revision 0) @@ -0,0 +1,251 @@ +/* + * 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. + */ + +package org.apache.fop.render.odf.odt.tags; + +import java.util.Iterator; + +import org.odftoolkit.odfdom.dom.element.style.StyleParagraphPropertiesElement; +import org.odftoolkit.odfdom.dom.element.style.StyleStyleElement; +import org.odftoolkit.odfdom.dom.element.style.StyleTextPropertiesElement; +import org.odftoolkit.odfdom.dom.element.table.TableTableCellElement; +import org.odftoolkit.odfdom.dom.element.text.TextBookmarkElement; +import org.odftoolkit.odfdom.dom.element.text.TextLineBreakElement; +import org.odftoolkit.odfdom.dom.element.text.TextListItemElement; +import org.odftoolkit.odfdom.pkg.OdfElement; +import org.odftoolkit.odfdom.pkg.OdfXMLFactory; +import org.odftoolkit.simple.text.Paragraph; + +import org.apache.fop.fo.FONode; +import org.apache.fop.fo.FOText; +import org.apache.fop.fo.flow.Block; +import org.apache.fop.layoutmgr.BlockLayoutManager; +import org.apache.fop.render.odf.OdfException; +import org.apache.fop.render.odf.odt.Namespace; +import org.apache.fop.render.odf.odt.Style; +import org.apache.fop.render.odf.odt.Style.Params; +/** + * Block converter + */ +public class BlockTag extends Tag { + + private Block bl = null; + + private Paragraph paragraph = null; + + private OdfElement paragraphContainer = null; + + /** + * {@inheritDoc} + * @throws OdfException + */ + @Override + protected Paragraph getParagraph() throws OdfException { + if (this.paragraph != null) { + return this.paragraph; + } else { + return parent.getParagraph(); + } + } + + /** + * {@inheritDoc} + */ + @Override + protected OdfElement getParagraphContainer() { + if (paragraphContainer != null) { + return this.paragraphContainer; + } else { + return parent.getParagraphContainer(); + } + } + + /** + * Constructor + * @throws OdfException + */ + BlockTag(Tag parent, Block bl) throws OdfException { + super(parent); + this.bl = bl; + this.currentStyle.getParameters().put(Params.FONT_NAME, bl.getCommonFont().getFirstFontFamily().split(",")[0]); + this.currentStyle.getParameters().put(Params.FONT_STYLE, Style.fopFontToOdfFontStyle( bl.getCommonFont())); + this.currentStyle.getParameters().put(Params.FONT_WEIGHT, Style.fopFontToOdfFontWeight( bl.getCommonFont())); + this.currentStyle.getParameters().put(Params.FONT_SIZE, Style.fopLengthToPt( bl.getCommonFont().getFontSize())); + this.currentStyle.getParameters().put(Params.COLOR, Style.awtColorToOdfColor( bl.getColor())); + this.currentStyle.getParameters().put(Params.TEXT_ALIGN, Style.fopAlignToOdfAlign( bl.getTextAlign())); + this.currentStyle.getParameters().put(Params.SPACE_BEFORE, Style.fopSpaceBeforeToPt( bl.getCommonMarginBlock().spaceBefore, new BlockLayoutManager(bl))); + this.currentStyle.getParameters().put(Params.SPACE_AFTER, Style.fopSpaceAfterToPt( bl.getCommonMarginBlock().spaceAfter, new BlockLayoutManager(bl))); + this.currentStyle.getParameters().put(Params.MARGIN_LEFT, Style.fopLengthToPt( bl.getCommonMarginBlock().marginLeft)); + this.currentStyle.getParameters().put(Params.MARGIN_RIGHT, Style.fopLengthToPt( bl.getCommonMarginBlock().marginRight)); + this.currentStyle.getParameters().put(Params.BACKGROUND_COLOR, Style.awtColorToString( bl.getCommonBorderPaddingBackground().backgroundColor)); + + registerFont(this.currentStyle.getParameters().get(Params.FONT_NAME)); + } + + /** + * {@inheritDoc} + * @throws OdfException + */ + @Override + public void execute() throws OdfException { + parent.executeFromParent(this); + } + + /** + * {@inheritDoc} + * @throws OdfException + */ + @Override + public void execute(Tag tag) throws OdfException { + + if (!bl.hasChildren()) { + addLineBreak(); + } else { + if (!childrenAreOnlyBlocks(this.bl)) { + this.paragraph = this.newParagraph(parent.getParagraphContainer()); + + if (bl.getId() != null) { + insertBookmark(bl.getId()); + } + + StyleStyleElement sse = null; + try { + sse = (StyleStyleElement) OdfXMLFactory.newOdfElement(this.getOdt().getContentDom(), StyleStyleElement.ELEMENT_NAME); + } catch (Exception e) { + throw new OdfException("Can't create new pragraph.", e); + } + + sse.setAttributeNS(Namespace.STYLE, "style:family", "paragraph"); + + StyleParagraphPropertiesElement sppe = null; + try { + sppe = (StyleParagraphPropertiesElement) OdfXMLFactory.newOdfElement(this.getOdt().getContentDom(), StyleParagraphPropertiesElement.ELEMENT_NAME); + } catch (Exception e) { + throw new OdfException("Can't create new pragraph.", e); + } + + sppe.setAttributeNS(Namespace.FO, "fo:margin-top", this.currentStyle.get(Params.SPACE_BEFORE)); + sppe.setAttributeNS(Namespace.FO, "fo:margin-bottom", this.currentStyle.get(Params.SPACE_AFTER)); + sppe.setAttributeNS(Namespace.FO, "fo:margin-left", this.currentStyle.get(Params.MARGIN_LEFT)); + sppe.setAttributeNS(Namespace.FO, "fo:margin-right", this.currentStyle.get(Params.MARGIN_RIGHT)); + sppe.setAttributeNS(Namespace.FO, "fo:background-color", this.currentStyle.get(Params.BACKGROUND_COLOR)); + sppe.setAttributeNS(Namespace.FO, "fo:text-align", this.currentStyle.get(Params.TEXT_ALIGN)); + sse.appendChild(sppe); + + StyleTextPropertiesElement stpe = null; + + try { + stpe = (StyleTextPropertiesElement) OdfXMLFactory.newOdfElement(this.getOdt().getContentDom(), StyleTextPropertiesElement.ELEMENT_NAME); + } catch (Exception e) { + throw new OdfException("Can't create new pragraph.", e); + } + + stpe.setAttributeNS(Namespace.STYLE, "style:font-name", this.currentStyle.get(Params.FONT_NAME)); + stpe.setAttributeNS(Namespace.FO, "fo:color", this.currentStyle.get(Params.COLOR)); + stpe.setAttributeNS(Namespace.FO, "fo:font-size", this.currentStyle.get(Params.FONT_SIZE)); + stpe.setAttributeNS(Namespace.FO, "fo:font-style", this.currentStyle.get(Params.FONT_STYLE)); + stpe.setAttributeNS(Namespace.FO, "fo:font-weight", this.currentStyle.get(Params.FONT_WEIGHT)); + + sse.appendChild(stpe); + + this.paragraph.getOdfElement().setStyleName(this.appendNewStyle(sse)); + } + } + } + + private void insertBookmark(String id) throws OdfException { + TextBookmarkElement tbe = null; + try { + tbe = (TextBookmarkElement) OdfXMLFactory.newOdfElement(this.getOdt().getContentDom(), TextBookmarkElement.ELEMENT_NAME); + } catch (Exception e) { + throw new OdfException("Can't create link intern.", e); + } + tbe.setAttributeNS(Namespace.TEXT, "text:name", id); + this.paragraph.getOdfElement().appendChild(tbe); + } + + /** + * {@inheritDoc} + * @throws OdfException + */ + @Override + public void execute(TableCellTag tag) throws OdfException { + TableTableCellElement ttce = tag.getTableCellElement(); + + this.paragraphContainer = ttce; + + if (!childrenAreOnlyBlocks(this.bl)) { + this.paragraph = this.newParagraph(this.paragraphContainer); + } + } + + /** + * {@inheritDoc} + * @throws OdfException + */ + @Override + public void execute(ListItemTag tag) throws OdfException { + TextListItemElement tlie = tag.getTextListItemElement(); + + this.paragraphContainer = tlie; + + if (!childrenAreOnlyBlocks(this.bl)) { + this.paragraph = this.newParagraph(this.paragraphContainer); + } + } + + private void addLineBreak() throws OdfException { + TextLineBreakElement tlb = null; + try { + tlb = (TextLineBreakElement) OdfXMLFactory.newOdfElement(this.getOdt().getContentDom(), TextLineBreakElement.ELEMENT_NAME); + } catch (Exception e) { + e.printStackTrace(); + } + + this.getParagraph().getOdfElement().appendChild(tlb); + } + + private boolean childrenAreOnlyBlocks(Block bl) { + + if (bl.hasChildren()) { + for (Iterator it = bl.getChildNodes(); it.hasNext();) { + FONode next = (FONode) it.next(); + if (!(next instanceof Block) ) { + if (next instanceof FOText) { + if ( ((FOText) next).length() != 0) { + return false; + } + } else { + return false; + } + } + } + } else { + return false; + } + + return true; + } + + /** + * {@inheritDoc} + * @throws OdfException + */ + public void executeFromParent(TagExecutable child) throws OdfException { + child.execute(this); + } +} Index: src/java/org/apache/fop/render/odf/odt/tags/StaticContentTag.java =================================================================== --- src/java/org/apache/fop/render/odf/odt/tags/StaticContentTag.java (revision 0) +++ src/java/org/apache/fop/render/odf/odt/tags/StaticContentTag.java (revision 0) @@ -0,0 +1,46 @@ +/* + * 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. + */ + +package org.apache.fop.render.odf.odt.tags; + +import org.apache.fop.fo.pagination.StaticContent; +import org.apache.fop.render.odf.OdfException; + +/** + * + */ +public class StaticContentTag extends Tag { + + protected StaticContentTag(Tag parent, StaticContent foNode) { + super(parent); + } + + /** + * {@inheritDoc} + */ + @Override + public void execute() { } + + /** + * {@inheritDoc} + * @throws OdfException + */ + public void executeFromParent(TagExecutable child) throws OdfException { + child.execute(this); + } + +} Index: src/java/org/apache/fop/render/odf/odt/tags/ListItemLabelTag.java =================================================================== --- src/java/org/apache/fop/render/odf/odt/tags/ListItemLabelTag.java (revision 0) +++ src/java/org/apache/fop/render/odf/odt/tags/ListItemLabelTag.java (revision 0) @@ -0,0 +1,46 @@ +/* + * 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. + */ + +package org.apache.fop.render.odf.odt.tags; + +import org.apache.fop.fo.flow.ListItemLabel; +import org.apache.fop.render.odf.OdfException; + +/** + * ListItemLabel converter + */ +public class ListItemLabelTag extends Tag { + + ListItemLabelTag(Tag parent, ListItemLabel foNode) { + super(parent); + } + + /** + * {@inheritDoc} + */ + @Override + public void execute() { } + + /** + * {@inheritDoc} + * @throws OdfException + */ + public void executeFromParent(TagExecutable child) throws OdfException { + child.execute(this); + } + +} Index: src/java/org/apache/fop/render/odf/odt/tags/RootTag.java =================================================================== --- src/java/org/apache/fop/render/odf/odt/tags/RootTag.java (revision 0) +++ src/java/org/apache/fop/render/odf/odt/tags/RootTag.java (revision 0) @@ -0,0 +1,93 @@ +/* + * 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. + */ + +package org.apache.fop.render.odf.odt.tags; + +import java.util.HashMap; +import java.util.Map; +import java.util.Vector; + +import org.odftoolkit.odfdom.dom.element.style.StyleStyleElement; +import org.odftoolkit.odfdom.pkg.OdfElement; +import org.odftoolkit.simple.TextDocument; +import org.odftoolkit.simple.text.Paragraph; + +import org.apache.fop.render.odf.OdfException; + +/** + * + */ +public class RootTag extends Tag { + + private TextDocument outputOdt = null; + + private Map usedStyles = new HashMap(); + + private Vector usedFonts = new Vector(); + + private Paragraph paragraph = null; + + public RootTag(TextDocument outputOdt) { + super(null); + this.outputOdt = outputOdt; + } + + protected TextDocument getOdt() { + return outputOdt; + } + + @Override + public Map getUsedStyles() { + return usedStyles; + } + + @Override + public Vector getUsedFonts() { + return usedFonts; + } + + @Override + protected Paragraph getParagraph() throws OdfException { + this.paragraph = this.newParagraph(getParagraphContainer()); + return this.paragraph; + } + + @Override + protected OdfElement getParagraphContainer() { + try { + return outputOdt.getContentRoot(); + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + /** + * {@inheritDoc} + */ + @Override + public void execute() { } + + /** + * {@inheritDoc} + * @throws OdfException + */ + public void executeFromParent(TagExecutable child) throws OdfException { + child.execute(this); + } + +} Index: src/java/org/apache/fop/render/odf/odt/tags/TableHeaderTag.java =================================================================== --- src/java/org/apache/fop/render/odf/odt/tags/TableHeaderTag.java (revision 0) +++ src/java/org/apache/fop/render/odf/odt/tags/TableHeaderTag.java (revision 0) @@ -0,0 +1,46 @@ +/* + * 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. + */ + +package org.apache.fop.render.odf.odt.tags; + +import org.apache.fop.fo.flow.table.TableHeader; +import org.apache.fop.render.odf.OdfException; + +/** + * TableHeader converter + */ +public class TableHeaderTag extends Tag { + + TableHeaderTag(Tag parent, TableHeader tblHeader) { + super(parent); + } + + /** + * {@inheritDoc} + */ + @Override + public void execute() { } + + /** + * {@inheritDoc} + * @throws OdfException + */ + public void executeFromParent(TagExecutable child) throws OdfException { + child.execute(this); + } + +} Index: src/java/org/apache/fop/render/odf/odt/tags/ExternalGraphicTag.java =================================================================== --- src/java/org/apache/fop/render/odf/odt/tags/ExternalGraphicTag.java (revision 0) +++ src/java/org/apache/fop/render/odf/odt/tags/ExternalGraphicTag.java (revision 0) @@ -0,0 +1,251 @@ +/* + * 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. + */ + +package org.apache.fop.render.odf.odt.tags; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Map; +import java.util.Random; + +import org.odftoolkit.odfdom.dom.element.draw.DrawFrameElement; +import org.odftoolkit.odfdom.dom.element.draw.DrawImageElement; +import org.odftoolkit.odfdom.dom.element.text.TextParagraphElementBase; +import org.odftoolkit.odfdom.pkg.OdfXMLFactory; + +import org.apache.commons.io.IOUtils; + +import org.apache.xmlgraphics.image.loader.Image; +import org.apache.xmlgraphics.image.loader.ImageFlavor; +import org.apache.xmlgraphics.image.loader.ImageInfo; +import org.apache.xmlgraphics.image.loader.ImageManager; +import org.apache.xmlgraphics.image.loader.ImageSessionContext; +import org.apache.xmlgraphics.image.loader.impl.ImageRawStream; +import org.apache.xmlgraphics.image.loader.util.ImageUtil; + +import org.apache.fop.apps.FOUserAgent; + +import org.apache.fop.datatypes.LengthBase; +import org.apache.fop.fo.FObj; +import org.apache.fop.fo.flow.AbstractGraphics; +import org.apache.fop.fo.flow.ExternalGraphic; +import org.apache.fop.layoutmgr.inline.ImageLayout; +import org.apache.fop.render.odf.OdfException; +import org.apache.fop.render.odf.odt.Namespace; + +/** + * External Graphic converter + */ +public class ExternalGraphicTag extends Tag { + + public static class PercentBaseContext implements org.apache.fop.datatypes.PercentBaseContext { + + Image image = null; + + public PercentBaseContext(Image image) { + this.image = image; + } + + public int getBaseLength(int lengthBase, FObj fobj) { + + final ImageInfo info = image.getInfo(); + + switch (lengthBase) { + case LengthBase.IMAGE_INTRINSIC_WIDTH: + return info.getSize().getWidthMpt(); + case LengthBase.IMAGE_INTRINSIC_HEIGHT: + return info.getSize().getHeightMpt(); + default: + return info.getSize().getHeightMpt(); + } + } + } + + public static final String ODT_IMAGES_PATH = "Pictures/"; + + ExternalGraphic eg = null; + + ExternalGraphicTag(Tag parent, ExternalGraphic eg) { + super(parent); + this.eg = eg; + } + + /** + * {@inheritDoc} + * @throws OdfException + */ + @Override + public void execute() throws OdfException { + + ImageInfo info = null; + FOUserAgent userAgent = eg.getUserAgent(); + ImageManager manager = userAgent.getFactory().getImageManager(); + + try { + info = manager.getImageInfo(eg.getURL(), userAgent.getImageSessionContext()); + putGraphic(eg, info); + } catch (Exception e) { + throw new OdfException("Can't create an image.", e); + } + } + + private static final ImageFlavor[] FLAVORS = new ImageFlavor[] { + ImageFlavor.RAW_EMF, + ImageFlavor.RAW_PNG, + ImageFlavor.RAW_JPEG + }; + + private void putGraphic(AbstractGraphics abstractGraphic, ImageInfo info) + throws OdfException { + + FOUserAgent userAgent = abstractGraphic.getUserAgent(); + ImageManager manager = userAgent.getFactory().getImageManager(); + ImageSessionContext sessionContext = userAgent.getImageSessionContext(); + Map hints = ImageUtil.getDefaultHints(sessionContext); + Image image; + try { + image = manager.getImage(info, FLAVORS, hints, sessionContext); + } catch (Exception e) { + throw new OdfException("Can't create an image.", e); + } + + putGraphic(abstractGraphic, image); + } + + private void putGraphic(AbstractGraphics abstractGraphic, Image image) + throws OdfException { + + byte[] rawData; + try { + rawData = getRawData(image); + } catch (IOException e) { + throw new OdfException("Can't create an image.", e); + } + + if (rawData == null) { + return; + } + + ImageLayout layout = getImageLayout(abstractGraphic, image); + + String imageType = image.getInfo().getMimeType().split("/")[1]; + + String filename = createFilename(imageType); + + putImageFileIntoOdt(rawData, filename, imageType); + + DrawImageElement die = createImage(); + + die.setAttributeNS(Namespace.XLINK, "xlink:href", ODT_IMAGES_PATH + filename); + die.setAttributeNS(Namespace.XLINK, "xlink:type", "simple"); + die.setAttributeNS(Namespace.XLINK, "xlink:show", "embed"); + die.setAttributeNS(Namespace.XLINK, "xlink:actuate", "onLoad"); + + DrawFrameElement dfe = createImageFrame(); + + dfe.setAttributeNS(Namespace.SVG, "svg:width", Double.valueOf(layout.getViewportSize().getWidth() / 1000) + "pt"); + dfe.setAttributeNS(Namespace.SVG, "svg:height", Double.valueOf(layout.getViewportSize().getHeight() / 1000) + "pt"); + + addImageToImageFrame(die, dfe); + + addImageFrameToParagraph(dfe, this.getParagraph().getOdfElement()); + } + + private byte[] getRawData(Image image) throws IOException { + + byte[] rawData = null; + + if (image instanceof ImageRawStream) { + ImageRawStream rawImage = (ImageRawStream)image; + InputStream in = rawImage.createInputStream(); + try { + rawData = IOUtils.toByteArray(in); + } finally { + IOUtils.closeQuietly(in); + } + } + return rawData; + } + + private ImageLayout getImageLayout(AbstractGraphics abstractGraphic, Image image) { + + PercentBaseContext pContext = new ExternalGraphicTag.PercentBaseContext(image); + + return new ImageLayout( abstractGraphic, + pContext, + image.getInfo().getSize().getDimensionMpt()); + } + + private void putImageFileIntoOdt(byte[] rawData, String filename, String imageType) { + this.getOdt().getPackage().insert(rawData, ODT_IMAGES_PATH + filename, imageType); + } + + private String createFilename(String imageType) { + String filename = null; + + do { + Random randomGenerator = new Random(); + filename = randomGenerator.nextInt(100) + "." + imageType; + } while(this.getOdt().getPackage().contains(ODT_IMAGES_PATH + filename)); + + return filename; + } + + private DrawImageElement createImage() throws OdfException { + DrawImageElement die = null; + try { + die = (DrawImageElement) OdfXMLFactory.newOdfElement(this.getOdt().getContentDom(), DrawImageElement.ELEMENT_NAME); + } catch (Exception e) { + throw new OdfException("Can't create an image.", e); + } + return die; + } + + private DrawFrameElement createImageFrame() { + DrawFrameElement dfe = null; + try { + dfe = (DrawFrameElement) OdfXMLFactory.newOdfElement(this.getOdt().getContentDom(), DrawFrameElement.ELEMENT_NAME); + } catch (Exception e) { + e.printStackTrace(); + } + return dfe; + } + + private void addImageToImageFrame(DrawImageElement die, DrawFrameElement dfe) throws OdfException { + try { + dfe.appendChild(die); + } catch (Exception e) { + throw new OdfException("Can't create an image.", e); + } + } + + private void addImageFrameToParagraph(DrawFrameElement dfe, TextParagraphElementBase tpeb) { + try { + tpeb.appendChild(dfe); + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * {@inheritDoc} + * @throws OdfException + */ + public void executeFromParent(TagExecutable child) throws OdfException { + child.execute(this); + } +} Index: src/java/org/apache/fop/render/odf/odt/tags/ListBlockTag.java =================================================================== --- src/java/org/apache/fop/render/odf/odt/tags/ListBlockTag.java (revision 0) +++ src/java/org/apache/fop/render/odf/odt/tags/ListBlockTag.java (revision 0) @@ -0,0 +1,71 @@ +/* + * 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. + */ + +package org.apache.fop.render.odf.odt.tags; + +import org.odftoolkit.odfdom.dom.element.text.TextListElement; +import org.odftoolkit.odfdom.pkg.OdfXMLFactory; + +import org.apache.fop.fo.flow.ListBlock; +import org.apache.fop.render.odf.OdfException; + +/** + * ListBlock converter + */ +public class ListBlockTag extends Tag { + + protected TextListElement tle = null; + + ListBlockTag(Tag parent, ListBlock foNode) { + super(parent); + } + + public TextListElement getTextListElement() { + return tle; + } + + /** + * {@inheritDoc} + * @throws OdfException + */ + @Override + public void execute() throws OdfException { + try { + tle = (TextListElement) OdfXMLFactory.newOdfElement(this.getOdt().getContentDom(), TextListElement.ELEMENT_NAME); + } catch (Exception e) { + throw new OdfException("Can't create the list", e); + } + } + + @Override + public void closeIntercept() throws OdfException { + try { + this.getOdt().getListContainerElement().appendChild(tle); + } catch (Exception e) { + throw new OdfException("Can't create the list", e); + } + } + + /** + * {@inheritDoc} + * @throws OdfException + */ + public void executeFromParent(TagExecutable child) throws OdfException { + child.execute(this); + } + +} Index: src/java/org/apache/fop/render/odf/odt/tags/TagExecutor.java =================================================================== --- src/java/org/apache/fop/render/odf/odt/tags/TagExecutor.java (revision 0) +++ src/java/org/apache/fop/render/odf/odt/tags/TagExecutor.java (revision 0) @@ -0,0 +1,28 @@ +/* + * 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. + */ + +package org.apache.fop.render.odf.odt.tags; + +import org.apache.fop.render.odf.OdfException; + +/** + * Interface of the converter class that wants to execute in order to its parent converter + */ +public interface TagExecutor { + + void executeFromParent(TagExecutable child) throws OdfException; +} Index: src/java/org/apache/fop/render/odf/odt/tags/TagExecutable.java =================================================================== --- src/java/org/apache/fop/render/odf/odt/tags/TagExecutable.java (revision 0) +++ src/java/org/apache/fop/render/odf/odt/tags/TagExecutable.java (revision 0) @@ -0,0 +1,44 @@ +/* + * 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. + */ + +package org.apache.fop.render.odf.odt.tags; + +import org.apache.fop.render.odf.OdfException; + +/** + * Interface for the class that accept parent visitor. + */ +public interface TagExecutable { + + void execute(Tag tag) throws OdfException; + + void execute(BlockTag tag) throws OdfException; + + void execute(InlineTag tag) throws OdfException; + + void execute(BasicLinkTag tag) throws OdfException; + + void execute(TableTag tag) throws OdfException; + + void execute(TableRowTag tag) throws OdfException; + + void execute(TableCellTag tag) throws OdfException; + + void execute(ListBlockTag tag) throws OdfException; + + void execute(ListItemTag tag) throws OdfException; +} Index: src/java/org/apache/fop/render/odf/odt/tags/TableRowTag.java =================================================================== --- src/java/org/apache/fop/render/odf/odt/tags/TableRowTag.java (revision 0) +++ src/java/org/apache/fop/render/odf/odt/tags/TableRowTag.java (revision 0) @@ -0,0 +1,75 @@ +/* + * 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. + */ + +package org.apache.fop.render.odf.odt.tags; + +import org.odftoolkit.odfdom.dom.element.table.TableTableRowElement; +import org.odftoolkit.odfdom.pkg.OdfXMLFactory; + +import org.apache.fop.fo.flow.table.TableRow; +import org.apache.fop.render.odf.OdfException; + +/** + * TableRow converter + */ +public class TableRowTag extends Tag { + + private TableTableRowElement tre = null; + + TableRowTag(Tag parent, TableRow tblRow) { + super(parent); + } + + public TableTableRowElement getTableRow() { + return this.tre; + } + + /** + * {@inheritDoc} + * @throws OdfException + */ + @Override + public void execute() throws OdfException { + try { + tre = (TableTableRowElement) OdfXMLFactory.newOdfElement(this.getOdt().getContentDom(), TableTableRowElement.ELEMENT_NAME); + } catch (Exception e) { + throw new OdfException("Can't create table row.", e); + } + + parent.executeFromParent(this); + } + + /** + * {@inheritDoc} + */ + @Override + public void execute(TableTag tag) { + try { + tag.getTable().appendChild(tre); + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * {@inheritDoc} + * @throws OdfException + */ + public void executeFromParent(TagExecutable child) throws OdfException { + child.execute(this); + } +} Index: src/java/org/apache/fop/render/odf/odt/Style.java =================================================================== --- src/java/org/apache/fop/render/odf/odt/Style.java (revision 0) +++ src/java/org/apache/fop/render/odf/odt/Style.java (revision 0) @@ -0,0 +1,174 @@ +/* + * 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. + */ + +package org.apache.fop.render.odf.odt; + +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; + +import org.odftoolkit.odfdom.dom.element.style.StyleStyleElement; +import org.odftoolkit.odfdom.type.Color; +import org.odftoolkit.simple.style.StyleTypeDefinitions.HorizontalAlignmentType; + +import org.apache.fop.datatypes.Length; +import org.apache.fop.fo.Constants; +import org.apache.fop.fo.properties.CommonFont; +import org.apache.fop.fo.properties.SpaceProperty; +import org.apache.fop.layoutmgr.BlockLayoutManager; + +/** + * Main class for style management. + */ +public class Style { + + public enum Params { + FONT_NAME, + FONT_STYLE, + FONT_WEIGHT, + FONT_SIZE, + COLOR, + TEXT_ALIGN, + SPACE_BEFORE, + SPACE_AFTER, + MARGIN_LEFT, + MARGIN_RIGHT, + BACKGROUND_COLOR + } + + private Map parameters = new HashMap(); + + private Style parentStyle = null; + + /** + * Constructor + */ + public Style(Style parentStyle) { + this.parentStyle = parentStyle; + } + + /** + * Constructor Style for the root tag. Setting default style parameters + */ + public Style() { + parameters.put(Params.FONT_NAME, "Times New Roman"); + parameters.put(Params.FONT_SIZE, "12pt"); + parameters.put(Params.COLOR, "#000000"); + parameters.put(Params.TEXT_ALIGN, HorizontalAlignmentType.LEFT.toString()); + } + + /** + * Get all style parameters + */ + public Map getParameters() { + return parameters; + } + + /** + * get an object from parameters. + */ + public String get(Params param) { + String value = parameters.get(param); + + if (value == null && parentStyle != null) { + value = parentStyle.get(param); + } + + return value; + } + + public static String getStyleName(Map styles, StyleStyleElement sse) { + for (Entry entry : styles.entrySet()) { + StyleStyleElement style = entry.getValue(); + if (style.equals(sse)) { + return entry.getKey(); + } + } + return null; + } + + public static Double fopLengthToDouble(Length length) { + return Double.valueOf((double)length.getValue() / 1000); + } + + public static String awtColorToOdfColor(java.awt.Color color) { + if (color == null) { + return null; + } else { + return new Color(color.getRed(), + color.getGreen(), + color.getBlue()).toString(); + } + } + + public static String fopFontToOdfFontStyle(CommonFont commonFont) { + return commonFont.getFontStyle() == Constants.EN_ITALIC ? "italic" : null; + } + + public static String fopFontToOdfFontWeight(CommonFont commonFont) { + return commonFont.getFontWeight() >= Constants.EN_700 ? "bold" : null; + } + + public static String fopAlignToOdfAlign(int textAlign) { + + if (textAlign == Constants.EN_LEFT) { + return HorizontalAlignmentType.LEFT.toString(); + } else if (textAlign == Constants.EN_JUSTIFY) { + return HorizontalAlignmentType.JUSTIFY.toString(); + } else if (textAlign == Constants.EN_CENTER) { + return HorizontalAlignmentType.CENTER.toString(); + } else if (textAlign == 39) { + return HorizontalAlignmentType.RIGHT.toString(); + } else { + return HorizontalAlignmentType.LEFT.toString(); + } + + } + + public static String fopSpaceBeforeToPt(SpaceProperty spaceBefore, BlockLayoutManager context) { + if (spaceBefore == null) { + return null; + } + Double value = Double.valueOf((double) spaceBefore.getLengthRange().toMinOptMax(context).getOpt() / 1000); + return value + "pt"; + } + + public static String fopSpaceAfterToPt(SpaceProperty spaceAfter, BlockLayoutManager context) { + if (spaceAfter == null) { + return null; + } + Double value = Double.valueOf((double) spaceAfter.getLengthRange().toMinOptMax(context).getOpt() / 1000); + return value + "pt"; + } + + public static String fopLengthToPt(Length l) { + if (l == null) { + return null; + } + Double value = Double.valueOf((double)l.getValue() / 1000); + return value + "pt"; + } + + public static String awtColorToString(java.awt.Color color) { + if (color == null) { + return null; + } + return "#" + Integer.toHexString(color.getRed()) + + Integer.toHexString(color.getGreen()) + + Integer.toHexString(color.getBlue()); + } +} Index: src/java/org/apache/fop/render/odf/ODTFOEventHandlerMaker.java =================================================================== --- src/java/org/apache/fop/render/odf/ODTFOEventHandlerMaker.java (revision 0) +++ src/java/org/apache/fop/render/odf/ODTFOEventHandlerMaker.java (revision 0) @@ -0,0 +1,63 @@ +/* + * 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. + */ + +package org.apache.fop.render.odf; + +import java.io.OutputStream; + +import org.apache.fop.apps.FOUserAgent; +import org.apache.fop.apps.MimeConstants; +import org.apache.fop.fo.FOEventHandler; +import org.apache.fop.render.AbstractFOEventHandlerMaker; + +/** + * Maker class for ODT support. + */ +public class ODTFOEventHandlerMaker extends AbstractFOEventHandlerMaker { + + private static final String[] MIMES = new String[] { + MimeConstants.MIME_ODT + }; + + + /** + * {@inheritDoc} + * @param ua FOUserAgent + * @param out OutputStream + * @return created ODTHandler + */ + public FOEventHandler makeFOEventHandler(FOUserAgent ua, OutputStream out) { + return new ODTHandler(ua, out); + } + + /** + * {@inheritDoc} + * @return true, if an outputstream is needed + */ + public boolean needsOutputStream() { + return true; + } + + /** + * {@inheritDoc} + * @return array of MIME types + */ + public String[] getSupportedMimeTypes() { + return MIMES; + } + +} Index: src/java/org/apache/fop/cli/CommandLineOptions.java =================================================================== --- src/java/org/apache/fop/cli/CommandLineOptions.java (revision 1348087) +++ src/java/org/apache/fop/cli/CommandLineOptions.java (working copy) @@ -319,6 +319,8 @@ i = i + parsePDFOutputOption(args, i, "PDF/A-1b"); } else if (args[i].equals("-mif")) { i = i + parseMIFOutputOption(args, i); + } else if (args[i].equals("-odt")) { + i = i + parseODTOutputOption(args, i); } else if (args[i].equals("-rtf")) { i = i + parseRTFOutputOption(args, i); } else if (args[i].equals("-tiff")) { @@ -519,6 +521,17 @@ } } + private int parseODTOutputOption(String[] args, int i) throws FOPException { + setOutputMode(MimeConstants.MIME_ODT); + if ((i + 1 == args.length) + || (isOption(args[i + 1]))) { + throw new FOPException("you must specify the ODT output file"); + } else { + setOutputFile(args[i + 1]); + return 1; + } + } + private void setOutputFile(String filename) { if (isSystemInOutFile(filename)) { this.useStdOut = true; @@ -1177,7 +1190,7 @@ public static void printUsage(PrintStream out) { out.println( "\nUSAGE\nfop [options] [-fo|-xml] infile [-xsl file] " - + "[-awt|-pdf|-mif|-rtf|-tiff|-png|-pcl|-ps|-txt|-at [mime]|-print] \n" + + "[-awt|-pdf|-mif|-odt|-rtf|-tiff|-png|-pcl|-ps|-txt|-at [mime]|-print] \n" + " [OPTIONS] \n" + " -version print FOP version and exit\n" + " -d debug mode \n" @@ -1236,6 +1249,7 @@ + " -pdfa1b outfile input will be rendered as PDF/A-1b compliant PDF\n" + " (outfile req'd, same as \"-pdf outfile -pdfprofile PDF/A-1b\")\n" + " -awt input will be displayed on screen \n" + + " -odt outfile input will be rendered as ODT (outfile req'd)\n" + " -rtf outfile input will be rendered as RTF (outfile req'd)\n" + " -pcl outfile input will be rendered as PCL (outfile req'd) \n" + " -ps outfile input will be rendered as PostScript (outfile req'd) \n" @@ -1271,6 +1285,7 @@ + " fop -xml foo.xml -xsl foo.xsl -foout foo.fo\n" + " fop -xml - -xsl foo.xsl -pdf -\n" + " fop foo.fo -mif foo.mif\n" + + " fop foo.fo -odt foo.odt\n" + " fop foo.fo -rtf foo.rtf\n" + " fop foo.fo -print\n" + " fop foo.fo -awt\n"); Index: src/java/org/apache/fop/apps/MimeConstants.java =================================================================== --- src/java/org/apache/fop/apps/MimeConstants.java (revision 1348087) +++ src/java/org/apache/fop/apps/MimeConstants.java (working copy) @@ -32,4 +32,6 @@ String MIME_FOP_AREA_TREE = "application/X-fop-areatree"; /** Apache FOP's intermediate format XML */ String MIME_FOP_IF = "application/X-fop-intermediate-format"; + /** Apache FOP's ODT format */ + String MIME_ODT = "application/vnd.oasis.opendocument.text"; } Index: src/java/META-INF/services/org.apache.fop.fo.FOEventHandler =================================================================== --- src/java/META-INF/services/org.apache.fop.fo.FOEventHandler (revision 1348087) +++ src/java/META-INF/services/org.apache.fop.fo.FOEventHandler (working copy) @@ -1 +1,2 @@ -org.apache.fop.render.rtf.RTFFOEventHandlerMaker \ No newline at end of file +org.apache.fop.render.rtf.RTFFOEventHandlerMaker +org.apache.fop.render.odf.ODTFOEventHandlerMaker \ No newline at end of file Index: test/odf/odt/fo_inline/color_font_size_style_weight.fo =================================================================== --- test/odf/odt/fo_inline/color_font_size_style_weight.fo (revision 0) +++ test/odf/odt/fo_inline/color_font_size_style_weight.fo (revision 0) @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + Joad rolled the coat up more tightly. "An old turtle," he said. "Picked + him up on the + road. An old bulldozer. Thought I'd take 'im to my little brother. Kids + like turtles." + + + + + Index: test/odf/odt/basic/text.fo =================================================================== --- test/odf/odt/basic/text.fo (revision 0) +++ test/odf/odt/basic/text.fo (revision 0) @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + This is simple text. + + + Index: test/odf/odt/fo_block/font_size.fo =================================================================== --- test/odf/odt/fo_block/font_size.fo (revision 0) +++ test/odf/odt/fo_block/font_size.fo (revision 0) @@ -0,0 +1,164 @@ + + + + + + + + + + + + + + + + + Lokomotywa + + + Stoi na stacji lokomotywa, + + Ciężka, ogromna i pot z niej spływa - + + Tłusta oliwa. + + Stoi i sapie, dyszy i dmucha, + + Żar z rozgrzanego jej brzucha bucha: + + Buch - jak gorąco! + + Uch - jak gorąco! + + Puff - jak gorąco! + + Uff - jak gorąco! + + Już ledwo sapie, już ledwo zipie, + + A jeszcze palacz węgiel w nią sypie. + + Wagony do niej podoczepiali + + Wielkie i ciężkie, z żelaza, stali, + + I pełno ludzi w każdym wagonie, + + A w jednym krowy, a w drugim konie, + + A w trzecim siedzą same grubasy, + + Siedzą i jedzą tłuste kiełbasy. + + A czwarty wagon pełen bananów, + + A w piątym stoi sześć fortepianów, + + W szóstym armata, o! jaka wielka! + + Pod każdym kołem żelazna belka! + + W siódmym dębowe stoły i szafy, + + W ósmym słoń, niedźwiedź i dwie żyrafy, + + W dziewiątym - same tuczone świnie, + + W dziesiątym - kufry, paki i skrzynie, + + A tych wagonów jest ze czterdzieści, + + Sam nie wiem, co się w nich jeszcze mieści. + + + Lecz choćby przyszło tysiąc atletów + + I każdy zjadłby tysiąc kotletów, + + I każdy nie wiem jak się natężał, + + To nie udźwigną - taki to ciężar! + + + Nagle - gwizd! + + Nagle - świst! + + Para - buch! + + Koła - w ruch! + + + Najpierw + + powoli + + jak żółw + + ociężale + + Ruszyła + + maszyna + + po szynach + + ospale. + + Szarpnęła wagony i ciągnie z mozołem, + + I kręci się, kręci się koło za kołem, + + I biegu przyspiesza, i gna coraz prędzej, + + I dudni, i stuka, łomoce i pędzi. + + + A dokąd? A dokąd? A dokąd? Na wprost! + + Po torze, po torze, po torze, przez most, + + Przez góry, przez tunel, przez pola, przez las + + I spieszy się, spieszy, by zdążyć na czas, + + Do taktu turkoce i puka, i stuka to: + + Tak to to, tak to to, tak to to, tak to to, + + Gładko tak, lekko tak toczy się w dal, + + Jak gdyby to była piłeczka, nie stal, + + Nie ciężka maszyna zziajana, zdyszana, + + Lecz raszka, igraszka, zabawka blaszana. + + + A skądże to, jakże to, czemu tak gna? + + A co to to, co to to, kto to tak pcha? + + Że pędzi, że wali, że bucha, buch-buch? + + To para gorąca wprawiła to w ruch, + + To para, co z kotła rurami do tłoków, + + A tłoki kołami ruszają z dwóch boków + + I gnają, i pchają, i pociąg się toczy, + + Bo para te tłoki wciąż tłoczy i tłoczy,, + + I koła turkocą, i puka, i stuka to: + + Tak to to, tak to to, tak to to, tak to to!... + + + + + Index: test/odf/odt/fo_block/color.fo =================================================================== --- test/odf/odt/fo_block/color.fo (revision 0) +++ test/odf/odt/fo_block/color.fo (revision 0) @@ -0,0 +1,253 @@ + + + + + + + + + + + + + + Julian Tuwim - Rzepka + + + Zasadził dziadek rzepkę w ogrodzie, + + Chodził te rzepkę oglądać co dzień. + + Wyrosła rzepka jędrna i krzepka, + + Schrupać by rzepkę z kawałkiem chlebaka! + + Więc ciągnie rzepkę dziadek niebożę, + + Ciągnie i ciągnie, wyciągnąć nie może! + + + Zawołał dziadek na pomoc babcię: + + "Ja złapię rzepkę, ty za mnie złap się!" + + I biedny dziadek z babcią niebogą + + Ciągną i ciągną, wyciągnąć nie mogą! + + Babcia za dziadka, + + Dziadek za rzepkę, + + Oj, przydałby się ktoś na przyczepkę! + + + Przyleciał wnuczek, babci się złapał, + + Poci się, stęka, aż się zasapał! + + Wnuczek za babcię, + + Babcia za dziadka, + + Dziadek za rzepkę, + + Oj, przydałby się ktoś na przyczepkę! + + Pocą się, sapią, stękają srogo, + + Ciągną i ciągną, wyciągnąć nie mogą! + + + Zawołał wnuczek szczeniaczka Mruczka, + + Przyleciał Mruczek i ciągnie wnuczka! + + Mruczek za wnuczka, + + Wnuczek za babcię, + + Babcia za dziadka, + + Dziadek za rzepkę, + + Oj, przydałby się ktoś na przyczepkę! + + Pocą się, sapią, stękają srogo, + + Ciągną i ciągną, wyciągnąć nie mogą! + + + Na kurkę czyhał kotek w ukryciu, + + Zaszczekał Mruczek: "Pomóż nam, Kiciu!" + + Kicia za Mruczka, + + Mruczek za wnuczka, + + Wnuczek za babcię, + + Babcia za dziadka, + + Dziadek za rzepkę, + + Oj, przydałby się ktoś na przyczepkę! + + Pocą się, sapią, stękają srogo, + + Ciągną i ciągną, wyciągnąć nie mogą! + + + Więc woła Kicia kurkę z podwórka, + + Wnet przyleciała usłużna kurka. + + Kurka za Kicię, + + Kicia za Mruczka, + + Mruczek za wnuczka, + + Wnuczek za babcię, + + Babcia za dziadka, + + Dziadek za rzepkę, + + Oj, przydałby się ktoś na przyczepkę! + + Pocą się, sapią, stękają srogo, + + Ciągną i ciągną, wyciągnąć nie mogą! + + + Szła sobie gąska ścieżynką wąską, + + Krzyknęła kurka: "ChodĽ no tu gąsko!" + + Gąska za kurkę, + + Kurka za Kicię, + + Kicia za Mruczka, + + Mruczek za wnuczka, + + Wnuczek za babcię, + + Babcia za dziadka, + + Dziadek za rzepkę, + + Oj, przydałby się ktoś na przyczepkę! + + Pocą się, sapią, stękają srogo, + + Ciągną i ciągną, wyciągnąć nie mogą! + + + Leciał wysoko bocian-długonos, + + "Fruńże tu, boćku, do nas na pomoc!" + + Bociek za gąskę, + + Gąska za kurkę, + + Kurka za Kicię, + + Kicia za Mruczka, + + Mruczek za wnuczka, + + Wnuczek za babcię, + + Babcia za dziadka, + + Dziadek za rzepkę, + + Oj, przydałby się ktoś na przyczepkę! + + Pocą się, sapią, stękają srogo, + + Ciągną i ciągną, wyciągnąć nie mogą! + + + Skakała drogą zielona żabka, + + Złapała boćka - rzadka to gradka! + + Żabka za boćka, + + Bociek za gąskę, + + Gąska za kurkę, + + Kurka za Kicię, + + Kicia za Mruczka, + + Mruczek za wnuczka, + + Wnuczek za babcię, + + Babcia za dziadka, + + Dziadek za rzepkę, + + A na przyczepkę + + Kawka za żabkę + + Bo na tę rzepkę + + Też miała chrapkę. + + + Tak się zawzięli, + + Tak się nadęli, + + Ze nagle rzepkę + + Trrrach!! - wyciągnęli! + + Aż wstyd powiedzieć, + + Co było dalej! + + Wszyscy na siebie + + Poupadali: + + Rzepka na dziadka, + + Dziadek na babcię, + + Babcia na wnuczka, + + Wnuczek na Mruczka, + + Mruczek na Kicię, + + Kicia na kurkę, + + Kurka na gąskę, + + Gąska na boćka, + + Bociek na żabkę, + + Żabka na kawkę + + I na ostatku + + Kawka na trawkę. + + + + + Index: test/odf/odt/fo_block/font_family.fo =================================================================== --- test/odf/odt/fo_block/font_family.fo (revision 0) +++ test/odf/odt/fo_block/font_family.fo (revision 0) @@ -0,0 +1,169 @@ + + + + + + + + + + + + + + + + + Lokomotywa + + + Stoi na stacji lokomotywa, + + Ciężka, ogromna i pot z niej spływa - + + Tłusta oliwa. + + Stoi i sapie, dyszy i dmucha, + + Żar z rozgrzanego jej brzucha bucha: + + Buch - jak gorąco! + + Uch - jak gorąco! + + Puff - jak gorąco! + + Uff - jak gorąco! + + Już ledwo sapie, już ledwo zipie, + + A jeszcze palacz węgiel w nią sypie. + + Wagony do niej podoczepiali + + Wielkie i ciężkie, z żelaza, stali, + + I pełno ludzi w każdym wagonie, + + A w jednym krowy, a w drugim konie, + + A w trzecim siedzą same grubasy, + + Siedzą i jedzą tłuste kiełbasy. + + A czwarty wagon pełen bananów, + + A w piątym stoi sześć fortepianów, + + W szóstym armata, o! jaka wielka! + + Pod każdym kołem żelazna belka! + + W siódmym dębowe stoły i szafy, + + W ósmym słoń, niedźwiedź i dwie żyrafy, + + W dziewiątym - same tuczone świnie, + + W dziesiątym - kufry, paki i skrzynie, + + A tych wagonów jest ze czterdzieści, + + Sam nie wiem, co się w nich jeszcze mieści. + + + Lecz choćby przyszło tysiąc atletów + + I każdy zjadłby tysiąc kotletów, + + I każdy nie wiem jak się natężał, + + To nie udźwigną - taki to ciężar! + + + Nagle - gwizd! + + Nagle - świst! + + Para - buch! + + Koła - w ruch! + + + Najpierw + + powoli + + jak żółw + + ociężale + + Ruszyła + + maszyna + + po szynach + + ospale. + + Szarpnęła wagony i ciągnie z mozołem, + + I kręci się, kręci się koło za kołem, + + I biegu przyspiesza, i gna coraz prędzej, + + I dudni, i stuka, łomoce i pędzi. + + + A dokąd? A dokąd? A dokąd? Na wprost! + + Po torze, po torze, po torze, przez most, + + Przez góry, przez tunel, przez pola, przez las + + I spieszy się, spieszy, by zdążyć na czas, + + Do taktu turkoce i puka, i stuka to: + + Tak to to, tak to to, tak to to, tak to to, + + Gładko tak, lekko tak toczy się w dal, + + Jak gdyby to była piłeczka, nie stal, + + Nie ciężka maszyna zziajana, zdyszana, + + Lecz raszka, igraszka, zabawka blaszana. + + + A skądże to, jakże to, czemu tak gna? + + A co to to, co to to, kto to tak pcha? + + Że pędzi, że wali, że bucha, buch-buch? + + To para gorąca wprawiła to w ruch, + + To para, co z kotła rurami do tłoków, + + A tłoki kołami ruszają z dwóch boków + + I gnają, i pchają, i pociąg się toczy, + + Bo para te tłoki wciąż tłoczy i tłoczy,, + + I koła turkocą, i puka, i stuka to: + + Tak to to, tak to to, tak to to, tak to to!... + + + + + Index: test/odf/odt/fo_block/text_align.fo =================================================================== --- test/odf/odt/fo_block/text_align.fo (revision 0) +++ test/odf/odt/fo_block/text_align.fo (revision 0) @@ -0,0 +1,77 @@ + + + + + + + + + + + + + + Joad rolled the coat up more tightly. "An old turtle," he said. "Picked + him up on the + road. An old bulldozer. Thought I'd take 'im to my little brother. Kids + like turtles." + + + The preacher nodded his head slowly. "Every kid got a turtle some time + or other. + Nobody can't keep a turtle though. They work at it and work at it, and at + last one day + they get out and away they go—off somewheres. It's like me. I wouldn't + take the good + ol' gospel that was just layin' there to my hand. I got to be pickin' + at it an' workin' at it + until I got it all tore down. Here I got the sperit sometimes an' + nothin' to preach about. I + got the call to lead people, an' no place to lead 'em." + + + "Lead 'em around and around," said Joad. "Sling 'em in the irrigation + ditch. Tell 'em + they'll burn in hell if they don't think like you. What the hell you want + to lead 'em + someplace for? Jus' lead 'em." + + + The straight trunk shade had stretched out along the ground. Joad + moved gratefully + into it and squatted on his hams and made a new smooth place on which + to draw his + thoughts with a stick. A thick-furred yellow shepherd dog came trotting + down the road, + head low, tongue lolling and dripping. Its tail hung limply curled, and + it panted loudly. + Joad whistled at it, but it only dropped its head an inch and trotted + fast toward some + definite destination. "Goin' someplace," Joad explained, a little piqued. + "Goin' for + home maybe." + + + The preacher could not be thrown from his subject. "Goin' someplace," + he repeated. + "That's right, he's goin' someplace. Me—I don't know where I'm goin'. Tell + you what— + I used ta get the people jumpin' an' talkin' in tongues and + glory-shoutin' till they just + fell down an' passed out. An' some I'd baptize to bring 'em to. An' + then—you know + what I'd do? I'd take one of them girls out in the grass, an' I'd lay + with her. Done it + ever' time. Then I'd feel bad, an' I'd pray an' pray, but it didn't do + no good. Come the + next time, them an' me was full of the sperit, I'd do it again. I + figgered there just wasn't + no hope for me, an' I was a damned ol' hypocrite. But I didn't mean + to be." + + + + + Index: test/odf/odt/fo_block/space_before_after.fo =================================================================== --- test/odf/odt/fo_block/space_before_after.fo (revision 0) +++ test/odf/odt/fo_block/space_before_after.fo (revision 0) @@ -0,0 +1,64 @@ + + + + + + + + + + + + + + Joad had moved + into the imperfect shade of the molting leaves before + the man heard + him coming, stopped his song, and turned his head. It was a long + head, + bony; tight of + skin, and set on a neck as stringy and muscular + as a celery stalk. His + eyeballs were + heavy and protruding; the lids + stretched to cover them, and the lids + were raw and red. + His cheeks + were brown and shiny and hairless and his mouth + full—humorous or + sensual. The nose, beaked and hard, stretched the skin so tightly + that the + bridge showed + white. There was no perspiration on the face, + not even on the tall pale + forehead. It was + an abnormally high + forehead, lined with delicate blue veins at the + temples. Fully half + of the face was above the eyes. His stiff gray hair was mussed back + from his brow as + though he had combed it back with his fingers. For + clothes he wore + overalls and a blue + shirt. A denim coat with brass + buttons and a spotted brown hat creased + like a pork pie + lay on the + ground beside him. Canvas sneakers, gray with dust, lay + near by + where they + had fallen when they were kicked off. + + + The man looked long at Joad. The light seemed to go far into his brown + eyes, and it + picked out little golden specks deep in the irises. The strained bundle + of neck muscles + stood out. + + + + + Index: test/odf/odt/fo_block/font_style.fo =================================================================== --- test/odf/odt/fo_block/font_style.fo (revision 0) +++ test/odf/odt/fo_block/font_style.fo (revision 0) @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + O KOCIE + + + Słyszał kto kiedy jako ciągą kota? + + Nie zawżdy szuka wody ta robota, + + Ciągnie go drugi nadobnie na suszy, + + Sukniej nie zmacza, ale wżdy mdło duszy. + + + + + Index: test/odf/odt/fo_block/font_weight.fo =================================================================== --- test/odf/odt/fo_block/font_weight.fo (revision 0) +++ test/odf/odt/fo_block/font_weight.fo (revision 0) @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + DO PANIEJ + + + Co usty mówisz byś w sercu myśliła, + + Barzo byś mię tym, Pani, zniewoliła. + + Ale kiedy mię swym miłym mianujesz, + + Podobno dawnym zwyczajom folgujesz. + + + + + Index: test/odf/odt/fo_external_graphic/simple.fo =================================================================== --- test/odf/odt/fo_external_graphic/simple.fo (revision 0) +++ test/odf/odt/fo_external_graphic/simple.fo (revision 0) @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + Joad rolled the coat up more tightly. "An old turtle," he said. "Picked + him up on the + road. An old bulldozer. Thought I'd take 'im to my little brother. Kids + like turtles." + + + + + + + + Index: test/odf/odt/fo_table/simple.fo =================================================================== --- test/odf/odt/fo_table/simple.fo (revision 0) +++ test/odf/odt/fo_table/simple.fo (revision 0) @@ -0,0 +1,128 @@ + + + + + + + + + + + + + + Joad rolled the coat up more tightly. + "An old turtle," he said. "Picked + him up on the + road. An old + bulldozer. Thought I'd take 'im to my little brother. Kids + like + turtles." + + + + + + + + aa + + + + + bb + + + + + cc + + + + + dd + + + + + + + ff + + + + + gg + + + + + hh + + + + + ii + + + + + + + jj + + + + + kk + + + + + + + + + + + + + + + + + + + + + + + + Index: test/odf/odt/fo_list_block/simple.fo =================================================================== --- test/odf/odt/fo_list_block/simple.fo (revision 0) +++ test/odf/odt/fo_list_block/simple.fo (revision 0) @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + Joad rolled the coat up more tightly. + "An old turtle," he said. "Picked + him up on the + road. An old + bulldozer. Thought I'd take 'im to my little brother. Kids + like + turtles." + + + + + + + + item1 + + + + + + + + item2 + + + + + + + + item3 + + + + + + +