diff options
author | Dirk-Willem van Gulik <dirkx@apache.org> | 1999-11-08 19:12:49 +0000 |
---|---|---|
committer | Dirk-Willem van Gulik <dirkx@apache.org> | 1999-11-08 19:12:49 +0000 |
commit | 10070e8383ff94f3f256e346b8c4a2a493533cfb (patch) | |
tree | 59080d7faae7c0bd9ff4e5a48f4df4394d468a02 /src/org/apache/fop/render/xml | |
parent | b510e7f15a798e944bb138993f2b586413adecbe (diff) | |
download | xmlgraphics-fop-10070e8383ff94f3f256e346b8c4a2a493533cfb.tar.gz xmlgraphics-fop-10070e8383ff94f3f256e346b8c4a2a493533cfb.zip |
Initial revision
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@193213 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/org/apache/fop/render/xml')
-rw-r--r-- | src/org/apache/fop/render/xml/Makefile | 23 | ||||
-rw-r--r-- | src/org/apache/fop/render/xml/XMLRenderer.java | 276 | ||||
-rw-r--r-- | src/org/apache/fop/render/xml/package.html | 6 |
3 files changed, 305 insertions, 0 deletions
diff --git a/src/org/apache/fop/render/xml/Makefile b/src/org/apache/fop/render/xml/Makefile new file mode 100644 index 000000000..75c36869e --- /dev/null +++ b/src/org/apache/fop/render/xml/Makefile @@ -0,0 +1,23 @@ + + +BASEDIR:=../../../../../.. +include $(BASEDIR)/Makefile.rules + +SUBDIRS= + +SOURCES=XMLRenderer.java + +CLASSES=$(SOURCES:.java=.class) + +all: $(CLASSES) allsubs + +clean: cleanme cleansubs + +cleanme: + rm -f *.class + +$(TARGETS:%=%subs): %subs : + for dir in $(SUBDIRS) ; do \ + (cd $$dir && pwd && $(MAKE) $(MFLAGS) $*) || exit 1 ; \ + done + diff --git a/src/org/apache/fop/render/xml/XMLRenderer.java b/src/org/apache/fop/render/xml/XMLRenderer.java new file mode 100644 index 000000000..9efc436dd --- /dev/null +++ b/src/org/apache/fop/render/xml/XMLRenderer.java @@ -0,0 +1,276 @@ +package org.apache.xml.fop.render.xml; + +// FOP +import org.apache.xml.fop.svg.*; +import org.apache.xml.fop.render.Renderer; +import org.apache.xml.fop.image.ImageArea; +import org.apache.xml.fop.layout.*; +import org.apache.xml.fop.pdf.*; + +// Java +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Enumeration; + +/** + * Renderer that renders areas to XML for debugging purposes. + */ +public class XMLRenderer implements Renderer { + + /** indentation to use for pretty-printing the XML */ + protected int indent = 0; + + /** the application producing the XML */ + protected String producer; + + /** the writer used to output the XML */ + protected PrintWriter writer; + + /** + * set the document's producer + * + * @param producer string indicating application producing the XML + */ + public void setProducer(String producer) { + this.producer = producer; + } + + /** + * render the areas into XML + * + * @param areaTree the laid-out area tree + * @param writer the PrintWriter to give the XML to + */ + public void render(AreaTree areaTree, PrintWriter writer) + throws IOException { + System.err.println("rendering areas to XML"); + this.writer = writer; + this.writer.write("<?xml version=\"1.0\"?>\n<!-- produced by " + + this.producer + " -->\n"); + writeStartTag("<AreaTree>"); + Enumeration e = areaTree.getPages().elements(); + while (e.hasMoreElements()) { + this.renderPage((Page) e.nextElement()); + } + writeEndTag("</AreaTree>"); + this.writer.flush(); + System.err.println("written out XML"); + } + + /** + * write out spaces to make indent + */ + protected void writeIndent() { + StringBuffer s = new StringBuffer(); + for (int i= 0; i<this.indent; i++) { + s = s.append(" "); + } + this.writer.write(s.toString()); + } + + /** + * write out an element + * + * @param element the full text of the element including tags + */ + protected void writeElement(String element) { + writeIndent(); + this.writer.write(element+"\n"); + } + + /** + * write out an empty-element-tag + * + * @param tag the text of the tag + */ + protected void writeEmptyElementTag(String tag) { + writeIndent(); + this.writer.write(tag + "\n"); + } + + /** + * write out an end tag + * + * @param tag the text of the tag + */ + protected void writeEndTag(String tag) { + this.indent--; + writeIndent(); + this.writer.write(tag + "\n"); + } + + /** + * write out a start tag + * + * @param tag the text of the tag + */ + protected void writeStartTag(String tag) { + writeIndent(); + this.writer.write(tag + "\n"); + this.indent++; + } + + /** + * set up the font info + * + * @param fontInfo the font info object to set up + */ + public void setupFontInfo(FontInfo fontInfo) { + + /* use PDF's font setup to get PDF metrics */ + org.apache.xml.fop.render.pdf.FontSetup.setup(fontInfo); + } + + /** + * render an area container to XML + * + * @param area the area container to render + */ + public void renderAreaContainer(AreaContainer area) { + writeStartTag("<AreaContainer>"); + Enumeration e = area.getChildren().elements(); + while (e.hasMoreElements()) { + Box b = (Box) e.nextElement(); + b.render(this); + } + writeEndTag("</AreaContainer>"); + } + + /** + * render a block area to XML + * + * @param area the block area to render + */ + public void renderBlockArea(BlockArea area) { + writeStartTag("<BlockArea start-indent=\"" + + area.getStartIndent() + + "\" end-indent=\"" + + area.getEndIndent() + "\">"); + Enumeration e = area.getChildren().elements(); + while (e.hasMoreElements()) { + Box b = (Box) e.nextElement(); + b.render(this); + } + writeEndTag("</BlockArea>"); + } + + /** + * render a display space to XML + * + * @param space the space to render + */ + public void renderDisplaySpace(DisplaySpace space) { + writeEmptyElementTag("<DisplaySpace size=\"" + + space.getSize() +"\"/>"); + } + + /** + * render an SVG area to XML + * + * @param area the area to render + */ + public void renderSVGArea(SVGArea area) { + writeEmptyElementTag("<SVG/>"); + } + + /** + * render an image area to XML + * + * @param area the area to render + */ + public void renderImageArea(ImageArea area) { + writeEmptyElementTag("<ImageArea/>"); + } + + /** + * render an inline area to XML + * + * @param area the area to render + */ + public void renderInlineArea(InlineArea area) { + String fontWeight = area.getFontState().getFontWeight(); + StringBuffer sb = new StringBuffer(); + String s = area.getText(); + int l = s.length(); + for (int i=0; i < l; i++) { + char ch = s.charAt(i); + if (ch>127) + sb = sb.append("&#"+(int)ch+";"); + else + sb = sb.append(ch); + } + writeElement("<InlineArea font-weight=\"" + + fontWeight + "\" red=\"" + + area.getRed() + "\" green=\"" + + area.getGreen() + "\" blue = \"" + + area.getBlue() + " width = \"" + + area.getContentWidth() + "\">" + sb.toString() + + "</InlineArea>"); + } + + /** + * render an inline space to XML + * + * @param space the space to render + */ + public void renderInlineSpace(InlineSpace space) { + writeEmptyElementTag("<InlineSpace size=\"" + + space.getSize() +"\"/>"); + } + + /** + * render a line area to XML + * + * @param area the area to render + */ + public void renderLineArea(LineArea area) { + String fontWeight = area.getFontState().getFontWeight(); + writeStartTag("<LineArea font-weight=\"" + + fontWeight + "\">"); + Enumeration e = area.getChildren().elements(); + while (e.hasMoreElements()) { + Box b = (Box)e.nextElement(); + b.render(this); + } + writeEndTag("</LineArea>"); + } + + /** + * render a page to XML + * + * @param page the page to render + */ + public void renderPage(Page page) { + AreaContainer body, before, after; + writeStartTag("<Page>"); + body = page.getBody(); + before = page.getBefore(); + after = page.getAfter(); + if (before != null) { + renderAreaContainer(before); + } + renderAreaContainer(body); + if (after != null) { + renderAreaContainer(after); + } + writeEndTag("</Page>"); + } + + /** + * render a rule area to XML + * + * @param area the area to render + */ + public void renderRuleArea(RuleArea area) { + writeEmptyElementTag("<Rule start-indent=\"" + + area.getStartIndent() + + "\" end-indent=\"" + + area.getEndIndent() + + "\" rule-thickness=\"" + + area.getRuleThickness() + + "\" red=\"" + area.getRed() + + "\" green=\"" + area.getGreen() + + "\" blue = \"" + area.getBlue() + + "\"/>"); + } +} diff --git a/src/org/apache/fop/render/xml/package.html b/src/org/apache/fop/render/xml/package.html new file mode 100644 index 000000000..4459f9e94 --- /dev/null +++ b/src/org/apache/fop/render/xml/package.html @@ -0,0 +1,6 @@ +<HTML> +<TITLE>org.apache.xml.fop.render.xml Package</TITLE> +<BODY> +<P>classes for rendering to XML for debugging</P> +</BODY> +</HTML>
\ No newline at end of file |