diff options
author | Steve Coffman <gears@apache.org> | 2001-08-01 23:08:55 +0000 |
---|---|---|
committer | Steve Coffman <gears@apache.org> | 2001-08-01 23:08:55 +0000 |
commit | 1f8404ea3f3676a23a7eced8e6558efefd2e03e0 (patch) | |
tree | a0526f9360fe9f29175ded93566407068377ca06 /src | |
parent | eeb2adff569057e2b6deb089ba9dffb21fb3a00b (diff) | |
download | xmlgraphics-fop-1f8404ea3f3676a23a7eced8e6558efefd2e03e0.tar.gz xmlgraphics-fop-1f8404ea3f3676a23a7eced8e6558efefd2e03e0.zip |
Code formatting. Still builds ok, but I didn't test it otherwise since last.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@194386 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src')
26 files changed, 720 insertions, 718 deletions
diff --git a/src/org/apache/fop/apps/AWTStarter.java b/src/org/apache/fop/apps/AWTStarter.java index 1bf2b4c86..c956da97f 100644 --- a/src/org/apache/fop/apps/AWTStarter.java +++ b/src/org/apache/fop/apps/AWTStarter.java @@ -57,7 +57,7 @@ public class AWTStarter extends CommandLineStarter { private Translator resource; public AWTStarter(CommandLineOptions commandLineOptions) - throws FOPException { + throws FOPException { super(commandLineOptions); init(); } @@ -78,8 +78,8 @@ public class AWTStarter extends CommandLineStarter { + language); UserMessage.setTranslator(getResourceBundle(TRANSLATION_PATH - + "messages." - + language)); + + "messages." + + language)); resource.setMissingEmphasized(false); renderer = new AWTRenderer(resource); @@ -127,7 +127,7 @@ public class AWTStarter extends CommandLineStarter { } protected PreviewDialog createPreviewDialog(AWTRenderer renderer, - Translator res) { + Translator res) { PreviewDialog frame = new PreviewDialog(renderer, res); frame.validate(); diff --git a/src/org/apache/fop/apps/CommandLineStarter.java b/src/org/apache/fop/apps/CommandLineStarter.java index 1f56c738e..556be58ce 100644 --- a/src/org/apache/fop/apps/CommandLineStarter.java +++ b/src/org/apache/fop/apps/CommandLineStarter.java @@ -34,7 +34,7 @@ public class CommandLineStarter extends Starter { boolean errorDump; public CommandLineStarter(CommandLineOptions commandLineOptions) - throws FOPException { + throws FOPException { this.commandLineOptions = commandLineOptions; options.setCommandLineOptions(commandLineOptions); errorDump = Configuration.getBooleanValue("debugMode").booleanValue(); diff --git a/src/org/apache/fop/apps/Driver.java b/src/org/apache/fop/apps/Driver.java index 4af65b07e..0b593a56c 100644 --- a/src/org/apache/fop/apps/Driver.java +++ b/src/org/apache/fop/apps/Driver.java @@ -171,6 +171,7 @@ public class Driver { try { parserClassName = System.getProperty("org.xml.sax.parser"); } catch (SecurityException se) {} + if (parserClassName == null) { parserClassName = "org.apache.xerces.parsers.SAXParser"; } @@ -261,6 +262,7 @@ public class Driver { try { addElementMapping(str); } catch (IllegalArgumentException e) {} + } } } @@ -338,7 +340,7 @@ public class Driver { * @see #setRenderer(int) */ public void setRenderer(String rendererClassName) - throws IllegalArgumentException { + throws IllegalArgumentException { try { _renderer = (Renderer)Class.forName(rendererClassName).newInstance(); @@ -346,13 +348,16 @@ public class Driver { } catch (ClassNotFoundException e) { throw new IllegalArgumentException("Could not find " + rendererClassName); - } catch (InstantiationException e) { + } + catch (InstantiationException e) { throw new IllegalArgumentException("Could not instantiate " + rendererClassName); - } catch (IllegalAccessException e) { + } + catch (IllegalAccessException e) { throw new IllegalArgumentException("Could not access " + rendererClassName); - } catch (ClassCastException e) { + } + catch (ClassCastException e) { throw new IllegalArgumentException(rendererClassName + " is not a renderer"); } @@ -372,7 +377,7 @@ public class Driver { * add the element mapping with the given class name */ public void addElementMapping(String mappingClassName) - throws IllegalArgumentException { + throws IllegalArgumentException { try { ElementMapping mapping = (ElementMapping)Class.forName(mappingClassName).newInstance(); @@ -380,13 +385,16 @@ public class Driver { } catch (ClassNotFoundException e) { throw new IllegalArgumentException("Could not find " + mappingClassName); - } catch (InstantiationException e) { + } + catch (InstantiationException e) { throw new IllegalArgumentException("Could not instantiate " + mappingClassName); - } catch (IllegalAccessException e) { + } + catch (IllegalAccessException e) { throw new IllegalArgumentException("Could not access " + mappingClassName); - } catch (ClassCastException e) { + } + catch (ClassCastException e) { throw new IllegalArgumentException(mappingClassName + " is not an ElementMapping"); } @@ -408,7 +416,7 @@ public class Driver { * SAX InputSource */ public synchronized void render(XMLReader parser, InputSource source) - throws FOPException { + throws FOPException { StreamRenderer streamRenderer = new StreamRenderer(_stream, _renderer); _treeBuilder.setStreamRenderer(streamRenderer); parser.setContentHandler(_treeBuilder); @@ -420,7 +428,8 @@ public class Driver { } else { throw new FOPException(e); } - } catch (IOException e) { + } + catch (IOException e) { throw new FOPException(e); } } @@ -429,10 +438,10 @@ public class Driver { * Build the formatting object tree using the given DOM Document */ public synchronized void render(Document document) - throws FOPException { + throws FOPException { StreamRenderer streamRenderer = new StreamRenderer(_stream, _renderer); _treeBuilder.setStreamRenderer(streamRenderer); - + try { DocumentInputSource source = new DocumentInputSource(document); DocumentReader reader = new DocumentReader(); @@ -440,7 +449,8 @@ public class Driver { reader.parse(source); } catch (SAXException e) { throw new FOPException(e); - } catch (IOException e) { + } + catch (IOException e) { throw new FOPException(e); } @@ -473,7 +483,7 @@ public class Driver { this._bufferManager.addBufferFile(bufferFile); } - /** + /** * Runs the formatting and renderering process using the previously set * inputsource and outputstream */ @@ -481,17 +491,17 @@ public class Driver { if (_renderer == null) { setRenderer(RENDER_PDF); } - + if (_source == null) { throw new FOPException("InputSource is not set."); } - + if (_reader == null) { if (!(_source instanceof DocumentInputSource)) { _reader = ConfigurationReader.createParser(); } } - + if (_source instanceof DocumentInputSource) { render(((DocumentInputSource)_source).getDocument()); } else { @@ -549,7 +559,7 @@ class Service { if (idx != -1) line = line.substring(0, idx); - // Trim whitespace. + // Trim whitespace. line = line.trim(); // If nothing left then loop around... @@ -566,11 +576,13 @@ class Service { } catch (Exception ex) { // Just try the next line } + line = br.readLine(); } } catch (Exception ex) { // Just try the next file... } + } return v.elements(); } diff --git a/src/org/apache/fop/apps/PrintStarter.java b/src/org/apache/fop/apps/PrintStarter.java index 7cf2636e2..f3c039f64 100644 --- a/src/org/apache/fop/apps/PrintStarter.java +++ b/src/org/apache/fop/apps/PrintStarter.java @@ -68,15 +68,15 @@ public class PrintStarter extends CommandLineStarter { PrinterJob pj = PrinterJob.getPrinterJob(); if(System.getProperty("dialog") != null) - if(!pj.printDialog()) - throw new FOPException("Printing cancelled by operator"); - + if(!pj.printDialog()) + throw new FOPException("Printing cancelled by operator"); + PrintRenderer renderer = new PrintRenderer(pj); int copies = getIntProperty("copies", 1); pj.setCopies(copies); - + //renderer.setCopies(copies); - + try { driver.setRenderer(renderer); driver.render(parser, inputHandler.getInputSource()); @@ -88,16 +88,16 @@ public class PrintStarter extends CommandLineStarter { } System.exit(0); - } - int getIntProperty(String name, int def) { - String propValue = System.getProperty(name); - if(propValue != null) { + } + int getIntProperty(String name, int def) { + String propValue = System.getProperty(name); + if(propValue != null) { try { - return Integer.parseInt(propValue); + return Integer.parseInt(propValue); } catch (Exception e) { - return def; + return def; } - } else { + } else { return def; } } @@ -113,7 +113,7 @@ public class PrintStarter extends CommandLineStarter { private int mode = EVEN_AND_ALL; private int copies = 1; private PrinterJob printerJob; - + PrintRenderer(PrinterJob printerJob) { super(null); @@ -129,33 +129,31 @@ public class PrintStarter extends CommandLineStarter { try { mode = Boolean.valueOf(str).booleanValue() ? EVEN : ODD; } catch (Exception e) {} + } } - public void stopRenderer(OutputStream outputStream) - throws IOException - { - super.stopRenderer(outputStream); - - if(endNumber == -1) - endNumber = getPageCount(); - + public void stopRenderer(OutputStream outputStream) + throws IOException { + super.stopRenderer(outputStream); + + if(endNumber == -1) + endNumber = getPageCount(); + Vector numbers = getInvalidPageNumbers(); for (int i = numbers.size() - 1; i > -1; i--) removePage(Integer.parseInt((String)numbers.elementAt(i))); try { - printerJob.print(); - } - catch (PrinterException e) - { - e.printStackTrace(); - throw new IOException( - "Unable to print: " + e.getClass().getName() + - ": " + e.getMessage()); + printerJob.print(); + } catch (PrinterException e) { + e.printStackTrace(); + throw new IOException( + "Unable to print: " + e.getClass().getName() + + ": " + e.getMessage()); } } @@ -197,8 +195,8 @@ public class PrintStarter extends CommandLineStarter { tree.getPages().addAll(copie); } - } - */ + } + */ } // class PrintRenderer } // class PrintCommandLine diff --git a/src/org/apache/fop/apps/StreamRenderer.java b/src/org/apache/fop/apps/StreamRenderer.java index e36b6e599..899e874b8 100644 --- a/src/org/apache/fop/apps/StreamRenderer.java +++ b/src/org/apache/fop/apps/StreamRenderer.java @@ -22,275 +22,253 @@ import org.apache.fop.messaging.MessageHandler; PageSequences up until all the IDs required by them are satisfied, at which time it will render the pages.<P> - + StreamRenderer is created by Driver and called from FOTreeBuilder when a PageSequence is created, and AreaTree when a Page is formatted.<P> */ -public class StreamRenderer extends Object -{ - private static final boolean MEM_PROFILE_WITH_GC = false; - - /** - Somewhere to get our stats from. - */ - private Runtime runtime = Runtime.getRuntime(); - - /** - Keep track of the number of pages rendered. - */ - int pageCount = 0; - - /** - Keep track of heap memory allocated, - for statistical purposes. - */ - private long initialMemory; - - /** - Keep track of time used by renderer. - */ - private long startTime; - - /** - The stream to which this rendering is to be - written to. <B>Note</B> that some renderers - do not render to a stream, and that this - member can therefore be null. - */ - private OutputStream outputStream; - - /** - The renderer being used. - */ - private Renderer renderer; - - /** - The FontInfo for this renderer. - */ - private FontInfo fontInfo = new FontInfo(); - - /** - The list of pages waiting to be renderered. - */ - private Vector renderQueue = new Vector(); - - /** - The current set of IDReferences, passed to the - areatrees and pages. This is used by the AreaTree - as a single map of all IDs. - */ - private IDReferences idReferences = new IDReferences(); - - public StreamRenderer(OutputStream outputStream, Renderer renderer) - { - this.outputStream = outputStream; - this.renderer = renderer; - } - - public IDReferences getIDReferences() - { - return idReferences; - } - - public void startRenderer() - throws SAXException - { - pageCount = 0; - - if (MEM_PROFILE_WITH_GC) - System.gc(); // This takes time but gives better results - - initialMemory = runtime.totalMemory() - runtime.freeMemory(); - startTime = System.currentTimeMillis(); - - try { - renderer.setupFontInfo(fontInfo); - renderer.startRenderer(outputStream); - } - catch (IOException e) - { - throw new SAXException(e); - } - } - - public void stopRenderer() - throws SAXException - { - /* - Force the processing of any more queue elements, - even if they are not resolved. +public class StreamRenderer extends Object { + private static final boolean MEM_PROFILE_WITH_GC = false; + + /** + Somewhere to get our stats from. */ - try { - processQueue(true); - renderer.stopRenderer(outputStream); - } - catch (FOPException e) - { - throw new SAXException(e); - } - catch (IOException e) - { - throw new SAXException(e); - } + private Runtime runtime = Runtime.getRuntime(); + + /** + Keep track of the number of pages rendered. + */ + int pageCount = 0; + + /** + Keep track of heap memory allocated, + for statistical purposes. + */ + private long initialMemory; + + /** + Keep track of time used by renderer. + */ + private long startTime; + + /** + The stream to which this rendering is to be + written to. <B>Note</B> that some renderers + do not render to a stream, and that this + member can therefore be null. + */ + private OutputStream outputStream; + + /** + The renderer being used. + */ + private Renderer renderer; - if (MEM_PROFILE_WITH_GC) - System.gc(); // This takes time but gives better results + /** + The FontInfo for this renderer. + */ + private FontInfo fontInfo = new FontInfo(); - long memoryNow = runtime.totalMemory() - runtime.freeMemory(); - long memoryUsed = (memoryNow - initialMemory) / 1024L; + /** + The list of pages waiting to be renderered. + */ + private Vector renderQueue = new Vector(); - MessageHandler.logln("Initial heap size: " + (initialMemory/1024L) + "Kb"); - MessageHandler.logln("Current heap size: " + (memoryNow/1024L) + "Kb"); - MessageHandler.logln("Total memory used: " + memoryUsed + "Kb"); + /** + The current set of IDReferences, passed to the + areatrees and pages. This is used by the AreaTree + as a single map of all IDs. + */ + private IDReferences idReferences = new IDReferences(); - if (!MEM_PROFILE_WITH_GC) - { - MessageHandler.logln(" Memory use is indicative; no GC was performed"); - MessageHandler.logln(" These figures should not be used comparatively"); + public StreamRenderer(OutputStream outputStream, Renderer renderer) { + this.outputStream = outputStream; + this.renderer = renderer; } - long timeUsed = System.currentTimeMillis() - startTime; - - MessageHandler.logln("Total time used: " + timeUsed + "ms"); - MessageHandler.logln("Pages rendererd: " + pageCount); - MessageHandler.logln("Avg render time: " + (timeUsed / pageCount) + "ms/page"); - } - - /** - Format the PageSequence. The PageSequence - formats Pages and adds them to the AreaTree, - which subsequently calls the StreamRenderer - instance (this) again to render the page. - At this time the page might be printed - or it might be queued. A page might not - be renderable immediately if the IDReferences - are not all valid. In this case we defer - the rendering until they are all valid. - */ - public void render(PageSequence pageSequence) - throws SAXException - { - AreaTree a = new AreaTree(this); - a.setFontInfo(fontInfo); - - try { - pageSequence.format(a); + public IDReferences getIDReferences() { + return idReferences; } - catch (FOPException e) - { - throw new SAXException(e); + + public void startRenderer() + throws SAXException { + pageCount = 0; + + if (MEM_PROFILE_WITH_GC) + System.gc(); // This takes time but gives better results + + initialMemory = runtime.totalMemory() - runtime.freeMemory(); + startTime = System.currentTimeMillis(); + + try { + renderer.setupFontInfo(fontInfo); + renderer.startRenderer(outputStream); + } catch (IOException e) { + throw new SAXException(e); + } } - } - - public synchronized void queuePage(Page page) - throws FOPException, IOException - { - /* - Try to optimise on the common case that there are - no pages pending and that all ID references are - valid on the current pages. This short-cuts the - pipeline and renders the area immediately. - */ - if ((renderQueue.size() == 0) && idReferences.isEveryIdValid()) - renderer.render(page, outputStream); - else - addToRenderQueue(page); - - pageCount++; - } - - private synchronized void addToRenderQueue(Page page) - throws FOPException, IOException - { - RenderQueueEntry entry = new RenderQueueEntry(page); - renderQueue.addElement(entry); - - /* - The just-added entry could (possibly) resolve the - waiting entries, so we try to process the queue - now to see. - */ - processQueue(false); - } - - /** - Try to process the queue from the first entry forward. - If an entry can't be processed, then the queue can't - move forward, so return. - */ - private synchronized void processQueue(boolean force) - throws FOPException, IOException - { - while (renderQueue.size() > 0) - { - RenderQueueEntry entry = (RenderQueueEntry) renderQueue.elementAt(0); - if ((!force) && (!entry.isResolved())) - break; - - renderer.render(entry.getPage(), outputStream); - - /* TODO - Enumeration rootEnumeration = - entry.getAreaTree().getExtensions().elements(); - while (rootEnumeration.hasMoreElements()) - renderTree.addExtension((ExtensionObj) rootEnumeration.nextElement()); - */ - - renderQueue.removeElementAt(0); + + public void stopRenderer() + throws SAXException { + /* + Force the processing of any more queue elements, + even if they are not resolved. + */ + try { + processQueue(true); + renderer.stopRenderer(outputStream); + } catch (FOPException e) { + throw new SAXException(e); + } + catch (IOException e) { + throw new SAXException(e); + } + + if (MEM_PROFILE_WITH_GC) + System.gc(); // This takes time but gives better results + + long memoryNow = runtime.totalMemory() - runtime.freeMemory(); + long memoryUsed = (memoryNow - initialMemory) / 1024L; + + MessageHandler.logln("Initial heap size: " + (initialMemory/1024L) + "Kb"); + MessageHandler.logln("Current heap size: " + (memoryNow/1024L) + "Kb"); + MessageHandler.logln("Total memory used: " + memoryUsed + "Kb"); + + if (!MEM_PROFILE_WITH_GC) { + MessageHandler.logln(" Memory use is indicative; no GC was performed"); + MessageHandler.logln(" These figures should not be used comparatively"); + } + + long timeUsed = System.currentTimeMillis() - startTime; + + MessageHandler.logln("Total time used: " + timeUsed + "ms"); + MessageHandler.logln("Pages rendererd: " + pageCount); + MessageHandler.logln("Avg render time: " + (timeUsed / pageCount) + "ms/page"); } - } - - /** - A RenderQueueEntry consists of the Page to be queued, - plus a list of outstanding ID references that need to be - resolved before the Page can be renderered.<P> - */ - class RenderQueueEntry extends Object - { - /* - The Page that has outstanding ID references. - */ - private Page page; - /* - A list of ID references (names). + /** + Format the PageSequence. The PageSequence + formats Pages and adds them to the AreaTree, + which subsequently calls the StreamRenderer + instance (this) again to render the page. + At this time the page might be printed + or it might be queued. A page might not + be renderable immediately if the IDReferences + are not all valid. In this case we defer + the rendering until they are all valid. */ - private Vector unresolvedIdReferences = new Vector(); + public void render(PageSequence pageSequence) + throws SAXException { + AreaTree a = new AreaTree(this); + a.setFontInfo(fontInfo); + + try { + pageSequence.format(a); + } catch (FOPException e) { + throw new SAXException(e); + } + } - public RenderQueueEntry(Page page) - { - this.page = page; + public synchronized void queuePage(Page page) + throws FOPException, IOException { + /* + Try to optimise on the common case that there are + no pages pending and that all ID references are + valid on the current pages. This short-cuts the + pipeline and renders the area immediately. + */ + if ((renderQueue.size() == 0) && idReferences.isEveryIdValid()) + renderer.render(page, outputStream); + else + addToRenderQueue(page); + + pageCount++; + } - Enumeration e = idReferences.getInvalidElements(); - while (e.hasMoreElements()) - unresolvedIdReferences.addElement(e.nextElement()); + private synchronized void addToRenderQueue(Page page) + throws FOPException, IOException { + RenderQueueEntry entry = new RenderQueueEntry(page); + renderQueue.addElement(entry); + + /* + The just-added entry could (possibly) resolve the + waiting entries, so we try to process the queue + now to see. + */ + processQueue(false); } - public Page getPage() - { - return page; + /** + Try to process the queue from the first entry forward. + If an entry can't be processed, then the queue can't + move forward, so return. + */ + private synchronized void processQueue(boolean force) + throws FOPException, IOException { + while (renderQueue.size() > 0) { + RenderQueueEntry entry = (RenderQueueEntry) renderQueue.elementAt(0); + if ((!force) && (!entry.isResolved())) + break; + + renderer.render(entry.getPage(), outputStream); + + /* TODO + Enumeration rootEnumeration = + entry.getAreaTree().getExtensions().elements(); + while (rootEnumeration.hasMoreElements()) + renderTree.addExtension((ExtensionObj) rootEnumeration.nextElement()); + */ + + renderQueue.removeElementAt(0); + } } /** - See if the outstanding references are resolved - in the current copy of IDReferences. + A RenderQueueEntry consists of the Page to be queued, + plus a list of outstanding ID references that need to be + resolved before the Page can be renderered.<P> */ - public boolean isResolved() - { - if ((unresolvedIdReferences.size() == 0) || idReferences.isEveryIdValid()) - return true; - - // - // See if any of the unresolved references are still unresolved. - // - Enumeration e = unresolvedIdReferences.elements(); - while (e.hasMoreElements()) - if (!idReferences.doesIDExist((String) e.nextElement())) - return false; - - unresolvedIdReferences.removeAllElements(); - return true; + class RenderQueueEntry extends Object { + /* + The Page that has outstanding ID references. + */ + private Page page; + + /* + A list of ID references (names). + */ + private Vector unresolvedIdReferences = new Vector(); + + public RenderQueueEntry(Page page) { + this.page = page; + + Enumeration e = idReferences.getInvalidElements(); + while (e.hasMoreElements()) + unresolvedIdReferences.addElement(e.nextElement()); + } + + public Page getPage() { + return page; + } + + /** + See if the outstanding references are resolved + in the current copy of IDReferences. + */ + public boolean isResolved() { + if ((unresolvedIdReferences.size() == 0) || idReferences.isEveryIdValid()) + return true; + + // + // See if any of the unresolved references are still unresolved. + // + Enumeration e = unresolvedIdReferences.elements(); + while (e.hasMoreElements()) + if (!idReferences.doesIDExist((String) e.nextElement())) + return false; + + unresolvedIdReferences.removeAllElements(); + return true; + } } - } } diff --git a/src/org/apache/fop/datatypes/IDReferences.java b/src/org/apache/fop/datatypes/IDReferences.java index 139cd4858..a27408794 100644 --- a/src/org/apache/fop/datatypes/IDReferences.java +++ b/src/org/apache/fop/datatypes/IDReferences.java @@ -237,7 +237,7 @@ public class IDReferences { * ex. 23 0 R */ public void setInternalGoToPageReference(String id, - String pageReference) { + String pageReference) { IDNode node = (IDNode)idReferences.get(id); if (node != null) { node.setInternalLinkGoToPageReference(pageReference); @@ -286,8 +286,7 @@ public class IDReferences { node.setPosition(x, y); } - public Enumeration getInvalidElements() - { - return idValidation.keys(); + public Enumeration getInvalidElements() { + return idValidation.keys(); } } diff --git a/src/org/apache/fop/fo/FONode.java b/src/org/apache/fop/fo/FONode.java index 6c6875899..2467ee076 100644 --- a/src/org/apache/fop/fo/FONode.java +++ b/src/org/apache/fop/fo/FONode.java @@ -132,6 +132,7 @@ abstract public class FONode { // still to do } + protected void addChild(FONode child) { children.addElement(child); } diff --git a/src/org/apache/fop/fo/FOText.java b/src/org/apache/fop/fo/FOText.java index 05e5a660a..4a4be3cc6 100644 --- a/src/org/apache/fop/fo/FOText.java +++ b/src/org/apache/fop/fo/FOText.java @@ -56,15 +56,15 @@ public class FOText extends FONode { for (int i = s; i < e; i++) ca[i - s] = chars[i]; this.length = e - s; - + /* ML - remove refs to BufferManager this.bufferManager = parent.bufferManager; if (this.bufferManager != null) { bufferManager.writeBuffer((Object)this, ca); - } else { + } else { System.out.println("abnormal exit"); System.exit(0); - } + } */ } @@ -84,7 +84,7 @@ public class FOText extends FONode { public boolean willCreateArea() { // ML - remove refs to BufferManager //char ca[] = this.bufferManager.readBuffer((Object)this); - + this.whiteSpaceCollapse = this.parent.properties.get("white-space-collapse").getEnum(); if (this.whiteSpaceCollapse == WhiteSpaceCollapse.FALSE @@ -208,8 +208,8 @@ public class FOText extends FONode { isLowerCase = (java.lang.Character.isLetter(c) && java.lang.Character.isLowerCase(c)); while (isLowerCase - == (java.lang.Character.isLetter(c) - && java.lang.Character.isLowerCase(c))) { + == (java.lang.Character.isLetter(c) + && java.lang.Character.isLowerCase(c))) { if (isLowerCase) { data[i] = java.lang.Character.toUpperCase(c); } diff --git a/src/org/apache/fop/fo/FOTreeBuilder.java b/src/org/apache/fop/fo/FOTreeBuilder.java index 75ac802f0..4c137658f 100644 --- a/src/org/apache/fop/fo/FOTreeBuilder.java +++ b/src/org/apache/fop/fo/FOTreeBuilder.java @@ -73,17 +73,15 @@ public class FOTreeBuilder extends DefaultHandler implements TreeBuilder { * The class that handles formatting and rendering to a stream * (mark-fop@inomial.com) */ - private StreamRenderer streamRenderer; - - public FOTreeBuilder() - { - } - - public void setStreamRenderer(StreamRenderer streamRenderer) - { - this.streamRenderer = streamRenderer; - } - + private StreamRenderer streamRenderer; + + public FOTreeBuilder() {} + + + public void setStreamRenderer(StreamRenderer streamRenderer) { + this.streamRenderer = streamRenderer; + } + /** * add a mapping from element name to maker. * @@ -146,38 +144,35 @@ public class FOTreeBuilder extends DefaultHandler implements TreeBuilder { * SAX Handler for the end of an element */ public void endElement(String uri, String localName, String rawName) - throws SAXException - { + throws SAXException { currentFObj.end(); - + // // mark-fop@inomial.com - tell the stream renderer to render // this page-sequence // if(currentFObj instanceof PageSequence) - streamRenderer.render((PageSequence) currentFObj); - - currentFObj = (FObj)currentFObj.getParent(); + streamRenderer.render((PageSequence) currentFObj); + + currentFObj = (FObj)currentFObj.getParent(); } /** * SAX Handler for the start of the document */ public void startDocument() - throws SAXException - { + throws SAXException { rootFObj = null; // allows FOTreeBuilder to be reused MessageHandler.logln("building formatting object tree"); streamRenderer.startRenderer(); } public void endDocument() - throws SAXException - { - MessageHandler.logln("Parsing of document complete, stopping renderer"); - streamRenderer.stopRenderer(); + throws SAXException { + MessageHandler.logln("Parsing of document complete, stopping renderer"); + streamRenderer.stopRenderer(); } - + /** * SAX Handler for the start of an element */ @@ -204,6 +199,7 @@ public class FOTreeBuilder extends DefaultHandler implements TreeBuilder { fobjMaker = new FObjMixed.Maker(); // fall back } + try { PropertyList list = null; if (currentListBuilder != null) { @@ -227,7 +223,7 @@ public class FOTreeBuilder extends DefaultHandler implements TreeBuilder { + " be root, not " + fobj.getName())); } - } else if(!(fobj instanceof org.apache.fop.fo.pagination.PageSequence)){ + } else if(!(fobj instanceof org.apache.fop.fo.pagination.PageSequence)) { currentFObj.addChild(fobj); } diff --git a/src/org/apache/fop/fo/flow/Block.java b/src/org/apache/fop/fo/flow/Block.java index 9830d1665..8b8de35b3 100644 --- a/src/org/apache/fop/fo/flow/Block.java +++ b/src/org/apache/fop/fo/flow/Block.java @@ -15,21 +15,21 @@ import org.apache.fop.layout.*; import org.apache.fop.datatypes.*; import org.apache.fop.apps.FOPException; - /* - Modified by Mark Lillywhite mark-fop@inomial.com. The changes - here are based on memory profiling and do not change functionality. - Essentially, the Block object had a pointer to a BlockArea object - that it created. The BlockArea was not referenced after the Block - was finished except to determine the size of the BlockArea, however - a reference to the BlockArea was maintained and this caused a lot of - GC problems, and was a major reason for FOP memory leaks. So, - the reference to BlockArea was made local, the required information - is now stored (instead of a reference to the complex BlockArea object) - and it appears that there are a lot of changes in this file, in fact - there are only a few sematic changes; mostly I just got rid of - "this." from blockArea since BlockArea is now local. - */ - +/* + Modified by Mark Lillywhite mark-fop@inomial.com. The changes + here are based on memory profiling and do not change functionality. + Essentially, the Block object had a pointer to a BlockArea object + that it created. The BlockArea was not referenced after the Block + was finished except to determine the size of the BlockArea, however + a reference to the BlockArea was maintained and this caused a lot of + GC problems, and was a major reason for FOP memory leaks. So, + the reference to BlockArea was made local, the required information + is now stored (instead of a reference to the complex BlockArea object) + and it appears that there are a lot of changes in this file, in fact + there are only a few sematic changes; mostly I just got rid of + "this." from blockArea since BlockArea is now local. + */ + public class Block extends FObjMixed { public static class Maker extends FObj.Maker { @@ -60,7 +60,7 @@ public class Block extends FObjMixed { int areaHeight = 0; int contentWidth = 0; - + String id; int span; @@ -184,7 +184,7 @@ public class Block extends FObjMixed { this.areasGenerated++; if (this.areasGenerated == 1) blockArea.isFirst(true); - // for normal areas this should be the only pair + // for normal areas this should be the only pair blockArea.addLineagePair(this, this.areasGenerated); // markers @@ -231,7 +231,7 @@ public class Block extends FObjMixed { return status; } else // i == 0 nothing was laid out.. - { + { anythingLaidOut = false; return status; } @@ -272,7 +272,7 @@ public class Block extends FObjMixed { // of memory. So we release it for the GC. areaHeight= blockArea.getHeight(); contentWidth= blockArea.getContentWidth(); - + // no break if last in area tree, or trailing in context // area int breakAfterStatus = propMgr.checkBreakAfter(area); @@ -283,7 +283,7 @@ public class Block extends FObjMixed { } if (keepWithNext != 0) { - blockArea = null; // Faster GC - BlockArea is big + blockArea = null; // Faster GC - BlockArea is big return new Status(Status.KEEP_WITH_NEXT); } @@ -301,10 +301,11 @@ public class Block extends FObjMixed { /** * Return the content width of the boxes generated by this FO. */ - public int getContentWidth() { + public int getContentWidth() { return contentWidth; // getAllocationWidth()?? } + public int getSpan() { return this.span; } diff --git a/src/org/apache/fop/fo/pagination/PageSequence.java b/src/org/apache/fop/fo/pagination/PageSequence.java index 0020836e8..6b3bf6e6c 100644 --- a/src/org/apache/fop/fo/pagination/PageSequence.java +++ b/src/org/apache/fop/fo/pagination/PageSequence.java @@ -143,7 +143,8 @@ public class PageSequence extends FObj { if (parent.getName().equals("fo:root")) { this.root = (Root)parent; // this.root.addPageSequence(this); - } else { + } + else { throw new FOPException("page-sequence must be child of root, not " + parent.getName()); } @@ -193,6 +194,7 @@ public class PageSequence extends FObj { // this.properties.get("id"); } + public void addFlow(Flow flow) throws FOPException { if (_flowMap.containsKey(flow.getFlowName())) { throw new FOPException("flow-names must be unique within an fo:page-sequence"); @@ -274,9 +276,9 @@ public class PageSequence extends FObj { MessageHandler.log(" [" + currentPageNumber); if ((status.getCode() == Status.FORCE_PAGE_BREAK_EVEN) - && ((currentPageNumber % 2) == 1)) {} + && ((currentPageNumber % 2) == 1)) {} else if ((status.getCode() == Status.FORCE_PAGE_BREAK_ODD) - && ((currentPageNumber % 2) == 0)) {} + && ((currentPageNumber % 2) == 0)) {} else { BodyAreaContainer bodyArea = currentPage.getBody(); bodyArea.setIDReferences(areaTree.getIDReferences()); @@ -303,12 +305,13 @@ public class PageSequence extends FObj { MessageHandler.log("]"); areaTree.addPage(currentPage); this.pageCount++; // used for 'force-page-count' calculations - } while (flowsAreIncomplete()); + } + while (flowsAreIncomplete()); // handle the 'force-page-count' forcePage(areaTree, firstAvailPageNumber); currentPage = null; - + MessageHandler.logln(""); } @@ -330,8 +333,8 @@ public class PageSequence extends FObj { // page number is 0-indexed PageMaster pageMaster = getNextPageMaster(masterName, - firstAvailPageNumber, - isFirstPage, isEmptyPage); + firstAvailPageNumber, + isFirstPage, isEmptyPage); // a legal alternative is to use the last sub-sequence // specification which should be handled in getNextSubsequence. That's not done here. @@ -447,11 +450,11 @@ public class PageSequence extends FObj { // handle forcing if (isForcing) { String nextPageMaster = getNextPageMasterName(sequenceMaster, - currentPageNumber, false, true); + currentPageNumber, false, true); return this.layoutMasterSet.getSimplePageMaster(nextPageMaster); } String nextPageMaster = getNextPageMasterName(sequenceMaster, - currentPageNumber, thisIsFirstPage, isEmptyPage); + currentPageNumber, thisIsFirstPage, isEmptyPage); return this.layoutMasterSet.getSimplePageMaster(nextPageMaster); } @@ -482,7 +485,8 @@ public class PageSequence extends FObj { currentSubsequence.reset(); // we leave currentSubsequence alone - } else { + } + else { currentSubsequence = nextSubsequence; } @@ -621,7 +625,8 @@ public class PageSequence extends FObj { if (nextSequence != null) { if (nextSequence.getIpnValue().equals("auto")) { // do nothing special - } else if (nextSequence.getIpnValue().equals("auto-odd")) { + } + else if (nextSequence.getIpnValue().equals("auto-odd")) { if (firstAvailPageNumber % 2 == 0) { makePage = true; } @@ -656,6 +661,7 @@ public class PageSequence extends FObj { } else if (this.forcePageCount == ForcePageCount.NO_FORCE) { // do nothing } + if (makePage) { try { this.isForcing = true; diff --git a/src/org/apache/fop/layout/AreaTree.java b/src/org/apache/fop/layout/AreaTree.java index d5a290124..0f4d3ea56 100644 --- a/src/org/apache/fop/layout/AreaTree.java +++ b/src/org/apache/fop/layout/AreaTree.java @@ -35,7 +35,7 @@ import java.util.Vector; Any extensions added to the AreaTree while generating a page are given to the Page for the renderer to deal with. */ - + public class AreaTree { /** @@ -48,14 +48,13 @@ public class AreaTree { * List of root extension objects */ Vector rootExtensions = null; - + private StreamRenderer streamRenderer; - - public AreaTree(StreamRenderer streamRenderer) - { - this.streamRenderer = streamRenderer; + + public AreaTree(StreamRenderer streamRenderer) { + this.streamRenderer = streamRenderer; } - + public void setFontInfo(FontInfo fontInfo) { this.fontInfo = fontInfo; } @@ -70,21 +69,18 @@ public class AreaTree { } public Page getPreviousPage(Page current, boolean isWithinPageSequence, - boolean isFirstCall) { + boolean isFirstCall) { return current; } public void addPage(Page page) - throws FOPException - { + throws FOPException { try { - page.setExtensions(rootExtensions); - rootExtensions = null; - streamRenderer.queuePage(page); - } - catch (IOException e) - { - throw new FOPException(e); + page.setExtensions(rootExtensions); + rootExtensions = null; + streamRenderer.queuePage(page); + } catch (IOException e) { + throw new FOPException(e); } } @@ -92,11 +88,10 @@ public class AreaTree { return streamRenderer.getIDReferences(); } - public void addExtension(ExtensionObj obj) - { - if(rootExtensions ==null) - rootExtensions = new Vector(); - rootExtensions.addElement(obj); + public void addExtension(ExtensionObj obj) { + if(rootExtensions ==null) + rootExtensions = new Vector(); + rootExtensions.addElement(obj); } - + } diff --git a/src/org/apache/fop/layout/Page.java b/src/org/apache/fop/layout/Page.java index 61600a19a..f543c6a0b 100644 --- a/src/org/apache/fop/layout/Page.java +++ b/src/org/apache/fop/layout/Page.java @@ -36,9 +36,9 @@ public class Page { private AreaContainer end; private AreaTree areaTree; - + private Vector rootExtensions; - + private PageSequence pageSequence; protected int pageNumber = 0; @@ -59,11 +59,10 @@ public class Page { markers = new Vector(); } - public IDReferences getIDReferences() - { - return areaTree.getIDReferences(); + public IDReferences getIDReferences() { + return areaTree.getIDReferences(); } - + public void setPageSequence(PageSequence pageSequence) { this.pageSequence = pageSequence; } @@ -186,13 +185,13 @@ public class Page { } public Vector getExtensions() { - return rootExtensions; + return rootExtensions; } public void setExtensions(Vector extensions) { - this.rootExtensions = extensions; + this.rootExtensions = extensions; } - + public void setPendingFootnotes(Vector v) { footnotes = v; if (footnotes != null) { @@ -202,6 +201,7 @@ public class Page { if (!Footnote.layoutFootnote(this, fb, null)) { // footnotes are too large to fit on empty page } + } footnotes = null; } diff --git a/src/org/apache/fop/pdf/PDFDocument.java b/src/org/apache/fop/pdf/PDFDocument.java index a1a3515ff..f2701d530 100644 --- a/src/org/apache/fop/pdf/PDFDocument.java +++ b/src/org/apache/fop/pdf/PDFDocument.java @@ -69,7 +69,7 @@ public class PDFDocument { protected Vector location = new Vector(); /** List of objects to write in the trailer */ - private Vector trailerObjects = new Vector(); + private Vector trailerObjects = new Vector(); /** * the counter for object numbering @@ -93,10 +93,10 @@ public class PDFDocument { /** The root outline object */ private PDFOutline outlineRoot = null; - + /** The /Pages object (mark-fop@inomial.com) */ private PDFPages pages; - + /** * the /Info object */ @@ -160,13 +160,13 @@ public class PDFDocument { /* create the /Root, /Info and /Resources objects */ this.pages = makePages(); - + // Create the Root object this.root = makeRoot(pages); - + // Create the Resources object this.resources = makeResources(); - + // Make the /Info record this.info = makeInfo(); } @@ -184,37 +184,34 @@ public class PDFDocument { * Make a /Catalog (Root) object. This object is written in * the trailer. */ - public PDFRoot makeRoot(PDFPages pages) - { + public PDFRoot makeRoot(PDFPages pages) { + + /* + * Make a /Pages object. This object is written in the trailer. + */ + PDFRoot pdfRoot = new PDFRoot(++this.objectcount, pages); + addTrailerObject(pdfRoot); + return pdfRoot; + } - /* - * Make a /Pages object. This object is written in the trailer. - */ - PDFRoot pdfRoot = new PDFRoot(++this.objectcount, pages); - addTrailerObject(pdfRoot); - return pdfRoot; - } - /** * Make a /Pages object. This object is written in the trailer. */ - - public PDFPages makePages() - { + + public PDFPages makePages() { PDFPages pdfPages = new PDFPages(++this.objectcount); addTrailerObject(pdfPages); return pdfPages; - } + } /** * Make a /Resources object. This object is written in the trailer. */ - public PDFResources makeResources() - { - PDFResources pdfResources = new PDFResources(++this.objectcount); - addTrailerObject(pdfResources); - return pdfResources; - } + public PDFResources makeResources() { + PDFResources pdfResources = new PDFResources(++this.objectcount); + addTrailerObject(pdfResources); + return pdfResources; + } /** * make an /Info object @@ -601,9 +598,9 @@ public class PDFDocument { * @param thePatternDataStream The stream of pattern data to be tiled. */ public PDFPattern makePattern(int thePatternType, // 1 - PDFResources theResources, int thePaintType, int theTilingType, - Vector theBBox, double theXStep, double theYStep, Vector theMatrix, - Vector theXUID, StringBuffer thePatternDataStream) { + PDFResources theResources, int thePaintType, int theTilingType, + Vector theBBox, double theXStep, double theYStep, Vector theMatrix, + Vector theXUID, StringBuffer thePatternDataStream) { String thePatternName = new String("Pa" + (++this.patternCount)); // int theNumber, String thePatternName, // PDFResources theResources @@ -680,7 +677,7 @@ public class PDFDocument { PDFColor currentColor = (PDFColor)theColors.elementAt(currentPosition); PDFColor nextColor = (PDFColor)theColors.elementAt(currentPosition - + 1); + + 1); // colorspace must be consistant if (this.colorspace.getColorSpace() != currentColor.getColorSpace()) @@ -784,7 +781,7 @@ public class PDFDocument { ((org.apache.fop.render.pdf.Font)metrics).getSubType(); PDFFontDescriptor pdfdesc = makeFontDescriptor(descriptor, - subtype); + subtype); PDFFontNonBase14 font = null; if (subtype == PDFFont.TYPE0) { @@ -847,7 +844,7 @@ public class PDFDocument { * make a /FontDescriptor object */ public PDFFontDescriptor makeFontDescriptor(FontDescriptor desc, - byte subtype) { + byte subtype) { PDFFontDescriptor font = null; if (subtype == PDFFont.TYPE0) { @@ -856,12 +853,13 @@ public class PDFDocument { desc.fontName(), desc.getFontBBox(), // desc.getAscender(), - // desc.getDescender(), - desc.getCapHeight(), desc.getFlags(), - // new PDFRectangle(desc.getFontBBox()), - desc.getItalicAngle(), desc.getStemV(), null); // desc.getLang(), + // desc.getDescender(), + desc.getCapHeight(), desc.getFlags(), + // new PDFRectangle(desc.getFontBBox()), + desc.getItalicAngle(), desc.getStemV(), null); // desc.getLang(), // null);//desc.getPanose()); - } else { + } + else { // Create normal FontDescriptor font = new PDFFontDescriptor(++this.objectcount, desc.fontName(), desc.getAscender(), @@ -904,7 +902,7 @@ public class PDFDocument { PDFXObject xObject = (PDFXObject)this.xObjectsMap.get(url); if (xObject != null) return xObject.getXNumber(); - // else, create a new one + // else, create a new one xObject = new PDFXObject(++this.objectcount, ++this.xObjectCount, img); this.objects.addElement(xObject); @@ -938,7 +936,7 @@ public class PDFDocument { while (enum.hasMoreElements()) { String id = enum.nextElement().toString(); idReferences.setInternalGoToPageReference(id, - page.referencePDF()); + page.referencePDF()); } } @@ -1005,25 +1003,23 @@ public class PDFDocument { idReferences.createNewId(destination); idReferences.addToIdValidationList(destination); goToReference = idReferences.createInternalLinkGoTo(destination, - ++this.objectcount); + ++this.objectcount); addTrailerObject(idReferences.getPDFGoTo(destination)); } return goToReference; } - - public void addTrailerObject(PDFObject object) - { - this.trailerObjects.addElement(object); + + public void addTrailerObject(PDFObject object) { + this.trailerObjects.addElement(object); } - + /** Ensure there is room in the locations xref for the number of objects that have been created. */ - private void prepareLocations() - { - while(location.size() < objectcount) - location.addElement(locationPlaceholder); + private void prepareLocations() { + while(location.size() < objectcount) + location.addElement(locationPlaceholder); } /** @@ -1068,13 +1064,13 @@ public class PDFDocument { * reference for later. */ public PDFOutline getOutlineRoot() { - if(outlineRoot != null) + if(outlineRoot != null) + return outlineRoot; + + outlineRoot = new PDFOutline(++this.objectcount, null, null); + addTrailerObject(outlineRoot); + root.setRootOutline(outlineRoot); return outlineRoot; - - outlineRoot = new PDFOutline(++this.objectcount, null, null); - addTrailerObject(outlineRoot); - root.setRootOutline(outlineRoot); - return outlineRoot; } /** @@ -1112,8 +1108,7 @@ public class PDFDocument { * * @param writer the OutputStream to output the document to */ - public void output(OutputStream stream) throws IOException - { + public void output(OutputStream stream) throws IOException { prepareLocations(); @@ -1127,7 +1122,7 @@ public class PDFDocument { * locations */ location.setElementAt( - new Integer(this.position),object.getNumber() - 1); + new Integer(this.position),object.getNumber() - 1); /* * output the object and increment the character position @@ -1149,10 +1144,9 @@ public class PDFDocument { * @return the number of bytes written */ public void outputHeader(OutputStream stream) - throws IOException - { + throws IOException { this.position=0; - + byte[] pdf = ("%PDF-" + this.pdfVersion + "\n").getBytes(); stream.write(pdf); this.position += pdf.length; @@ -1174,32 +1168,30 @@ public class PDFDocument { * @param stream the OutputStream to write the trailer to */ public void outputTrailer(OutputStream stream) - throws IOException - { - output(stream); - Enumeration e = trailerObjects.elements(); - while(e.hasMoreElements()) - { - PDFObject o = (PDFObject) e.nextElement(); - this.location.setElementAt( - new Integer(this.position), o.getNumber() - 1); - this.position += o.output(stream); - } + throws IOException { + output(stream); + Enumeration e = trailerObjects.elements(); + while(e.hasMoreElements()) { + PDFObject o = (PDFObject) e.nextElement(); + this.location.setElementAt( + new Integer(this.position), o.getNumber() - 1); + this.position += o.output(stream); + } /* output the xref table and increment the character position by the table's length */ this.position += outputXref(stream); - + /* construct the trailer */ - String pdf = - "trailer\n" + - "<<\n" + - "/Size " + (this.objectcount + 1) + "\n" + - "/Root " + this.root.number + " " + this.root.generation + " R\n" + - "/Info " + this.info.number + " " + this.info.generation + " R\n" + - ">>\n" + - "startxref\n" + - this.xref + "\n" + - "%%EOF\n"; + String pdf = + "trailer\n" + + "<<\n" + + "/Size " + (this.objectcount + 1) + "\n" + + "/Root " + this.root.number + " " + this.root.generation + " R\n" + + "/Info " + this.info.number + " " + this.info.generation + " R\n" + + ">>\n" + + "startxref\n" + + this.xref + "\n" + + "%%EOF\n"; /* write the trailer */ stream.write(pdf.getBytes()); diff --git a/src/org/apache/fop/pdf/PDFPages.java b/src/org/apache/fop/pdf/PDFPages.java index a3b5b60aa..4035fc2eb 100644 --- a/src/org/apache/fop/pdf/PDFPages.java +++ b/src/org/apache/fop/pdf/PDFPages.java @@ -80,8 +80,7 @@ public class PDFPages extends PDFObject { * * @return the PDF string */ - public byte[] toPDF() - { + public byte[] toPDF() { StringBuffer p = new StringBuffer(this.number + " " + this.generation + " obj\n<< /Type /Pages\n/Count " + this.getCount() + "\n/Kids ["); diff --git a/src/org/apache/fop/pdf/PDFRoot.java b/src/org/apache/fop/pdf/PDFRoot.java index 2bae2b91b..8741bd519 100644 --- a/src/org/apache/fop/pdf/PDFRoot.java +++ b/src/org/apache/fop/pdf/PDFRoot.java @@ -39,14 +39,14 @@ public class PDFRoot extends PDFObject { super(number); setRootPages(pages); } - + /** * Before the root is written to the document stream, * make sure it's object number is set. Package-private access * only; outsiders should not be fiddling with this stuff. */ void setNumber(int number) { - this.number = number; + this.number = number; } /** @@ -71,10 +71,9 @@ public class PDFRoot extends PDFObject { _outline = outline; } - public PDFOutline getRootOutline() - { - return _outline; - } + public PDFOutline getRootOutline() { + return _outline; + } /** @@ -86,8 +85,7 @@ public class PDFRoot extends PDFObject { * @return the PDF string */ public byte[] toPDF() - throws IllegalStateException - { + throws IllegalStateException { StringBuffer p = new StringBuffer(this.number + " " + this.generation + " obj\n<< /Type /Catalog\n/Pages " + this.rootPages.referencePDF() diff --git a/src/org/apache/fop/render/PrintRenderer.java b/src/org/apache/fop/render/PrintRenderer.java index 6c67420e6..f1afcde91 100644 --- a/src/org/apache/fop/render/PrintRenderer.java +++ b/src/org/apache/fop/render/PrintRenderer.java @@ -140,7 +140,7 @@ public abstract class PrintRenderer implements Renderer { * @param g the green component * @param b the blue component */ - protected abstract void addLine(int x1, int y1, int x2, int y2, int th, + protected abstract void addLine(int x1, int y1, int x2, int y2, int th, PDFPathPaint stroke); /** @@ -156,7 +156,7 @@ public abstract class PrintRenderer implements Renderer { * @param g the green component * @param b the blue component */ - protected abstract void addLine(int x1, int y1, int x2, int y2, int th, + protected abstract void addLine(int x1, int y1, int x2, int y2, int th, int rs, PDFPathPaint stroke); /** @@ -168,7 +168,7 @@ public abstract class PrintRenderer implements Renderer { * @param h the height in millipoints * @param stroke the stroke color/gradient */ - protected abstract void addRect(int x, int y, int w, int h, + protected abstract void addRect(int x, int y, int w, int h, PDFPathPaint stroke); /** @@ -181,7 +181,7 @@ public abstract class PrintRenderer implements Renderer { * @param fill the fill color/gradient * @param stroke the stroke color/gradient */ - protected abstract void addRect(int x, int y, int w, int h, + protected abstract void addRect(int x, int y, int w, int h, PDFPathPaint stroke, PDFPathPaint fill); /** @@ -195,10 +195,10 @@ public abstract class PrintRenderer implements Renderer { * @param h the height in millipoints * @param fill the fill color/gradient */ - protected void addFilledRect(int x, int y, int w, int h, + protected void addFilledRect(int x, int y, int w, int h, PDFPathPaint fill) { addRect(x, y, w, h, fill, fill); - } + } /** * render area container @@ -218,13 +218,13 @@ public abstract class PrintRenderer implements Renderer { this.currentYPosition -= area.getYPosition(); this.currentAreaContainerXPosition += area.getXPosition(); } else if (area.getPosition() == Position.STATIC) { - this.currentYPosition -= area.getPaddingTop() + this.currentYPosition -= area.getPaddingTop() + area.getBorderTopWidth(); /* * this.currentAreaContainerXPosition += * area.getPaddingLeft() + area.getBorderLeftWidth(); */ - } + } this.currentXPosition = this.currentAreaContainerXPosition; doFrame(area); @@ -233,13 +233,13 @@ public abstract class PrintRenderer implements Renderer { while (e.hasMoreElements()) { Box b = (Box)e.nextElement(); b.render(this); - } + } // Restore previous origin this.currentYPosition = saveY; this.currentAreaContainerXPosition = saveX; if (area.getPosition() == Position.STATIC) { this.currentYPosition -= area.getHeight(); - } + } /** * ** @@ -250,7 +250,7 @@ public abstract class PrintRenderer implements Renderer { * this.currentYPosition -= area.getHeight(); * ** */ - } + } public void renderBodyAreaContainer(BodyAreaContainer area) { int saveY = this.currentYPosition; @@ -263,7 +263,7 @@ public abstract class PrintRenderer implements Renderer { } else if (area.getPosition() == Position.RELATIVE) { this.currentYPosition -= area.getYPosition(); this.currentAreaContainerXPosition += area.getXPosition(); - } + } this.currentXPosition = this.currentAreaContainerXPosition; int w, h; @@ -277,7 +277,7 @@ public abstract class PrintRenderer implements Renderer { // but I do if ((bg != null) && (bg.alpha() == 0)) { this.addRect(rx, ry, w, -h, new PDFColor(bg), new PDFColor(bg)); - } + } // floats & footnotes stuff renderAreaContainer(area.getBeforeFloatReferenceArea()); @@ -288,7 +288,8 @@ public abstract class PrintRenderer implements Renderer { while (e.hasMoreElements()) { Box b = (Box)e.nextElement(); b.render(this); // span areas - } + } + if (area.getPosition() != Position.STATIC) { this.currentYPosition = saveY; @@ -296,15 +297,16 @@ public abstract class PrintRenderer implements Renderer { } else this.currentYPosition -= area.getHeight(); - } + } public void renderSpanArea(SpanArea area) { Enumeration e = area.getChildren().elements(); while (e.hasMoreElements()) { Box b = (Box)e.nextElement(); b.render(this); // column areas - } - } + } + + } private void doFrame(Area area) { int w, h; @@ -325,7 +327,7 @@ public abstract class PrintRenderer implements Renderer { // but I do if ((bg != null) && (bg.alpha() == 0)) { this.addFilledRect(rx, ry, w, -h, new PDFColor(bg)); - } + } // rx = rx - area.getBorderLeftWidth(); // ry = ry + area.getBorderTopWidth(); @@ -359,18 +361,18 @@ public abstract class PrintRenderer implements Renderer { int bottom = area.getBorderBottomWidth(); // If style is solid, use filled rectangles if (top != 0) - addFilledRect(rx, ry, w, top, + addFilledRect(rx, ry, w, top, new PDFColor(bp.getBorderColor(BorderAndPadding.TOP))); if (left != 0) - addFilledRect(rx - left, ry - h - bottom, left, h + top + bottom, + addFilledRect(rx - left, ry - h - bottom, left, h + top + bottom, new PDFColor(bp.getBorderColor(BorderAndPadding.LEFT))); if (right != 0) - addFilledRect(rx + w, ry - h - bottom, right, h + top + bottom, + addFilledRect(rx + w, ry - h - bottom, right, h + top + bottom, new PDFColor(bp.getBorderColor(BorderAndPadding.RIGHT))); if (bottom != 0) - addFilledRect(rx, ry - h - bottom, w, bottom, + addFilledRect(rx, ry - h - bottom, w, bottom, new PDFColor(bp.getBorderColor(BorderAndPadding.BOTTOM))); - } + } /** @@ -381,17 +383,17 @@ public abstract class PrintRenderer implements Renderer { public void renderBlockArea(BlockArea area) { // KLease: Temporary test to fix block positioning // Offset ypos by padding and border widths - this.currentYPosition -= (area.getPaddingTop() + this.currentYPosition -= (area.getPaddingTop() + area.getBorderTopWidth()); doFrame(area); Enumeration e = area.getChildren().elements(); while (e.hasMoreElements()) { Box b = (Box)e.nextElement(); b.render(this); - } - this.currentYPosition -= (area.getPaddingBottom() + } + this.currentYPosition -= (area.getPaddingBottom() + area.getBorderBottomWidth()); - } + } /** * render display space @@ -401,7 +403,7 @@ public abstract class PrintRenderer implements Renderer { public void renderDisplaySpace(DisplaySpace space) { int d = space.getSize(); this.currentYPosition -= d; - } + } /** * render image area @@ -429,39 +431,39 @@ public abstract class PrintRenderer implements Renderer { */ public abstract void renderWordArea(WordArea area); - protected void addWordLines(WordArea area, int rx, int bl, int size, + protected void addWordLines(WordArea area, int rx, int bl, int size, PDFColor theAreaColor) { if (area.getUnderlined()) { int yPos = bl - size / 10; - addLine(rx, yPos, rx + area.getContentWidth(), yPos, size / 14, + addLine(rx, yPos, rx + area.getContentWidth(), yPos, size / 14, theAreaColor); // save position for underlining a following InlineSpace prevUnderlineXEndPos = rx + area.getContentWidth(); prevUnderlineYEndPos = yPos; prevUnderlineSize = size / 14; prevUnderlineColor = theAreaColor; - } + } if (area.getOverlined()) { int yPos = bl + area.getFontState().getAscender() + size / 10; - addLine(rx, yPos, rx + area.getContentWidth(), yPos, size / 14, + addLine(rx, yPos, rx + area.getContentWidth(), yPos, size / 14, theAreaColor); prevOverlineXEndPos = rx + area.getContentWidth(); prevOverlineYEndPos = yPos; prevOverlineSize = size / 14; prevOverlineColor = theAreaColor; - } + } if (area.getLineThrough()) { int yPos = bl + area.getFontState().getAscender() * 3 / 8; - addLine(rx, yPos, rx + area.getContentWidth(), yPos, size / 14, + addLine(rx, yPos, rx + area.getContentWidth(), yPos, size / 14, theAreaColor); prevLineThroughXEndPos = rx + area.getContentWidth(); prevLineThroughYEndPos = yPos; prevLineThroughSize = size / 14; prevLineThroughColor = theAreaColor; - } - } + } + } /** * render inline space @@ -472,29 +474,29 @@ public abstract class PrintRenderer implements Renderer { this.currentXPosition += space.getSize(); if (space.getUnderlined()) { if (prevUnderlineColor != null) { - addLine(prevUnderlineXEndPos, prevUnderlineYEndPos, - prevUnderlineXEndPos + space.getSize(), - prevUnderlineYEndPos, prevUnderlineSize, + addLine(prevUnderlineXEndPos, prevUnderlineYEndPos, + prevUnderlineXEndPos + space.getSize(), + prevUnderlineYEndPos, prevUnderlineSize, prevUnderlineColor); - } - } + } + } if (space.getOverlined()) { if (prevOverlineColor != null) { - addLine(prevOverlineXEndPos, prevOverlineYEndPos, - prevOverlineXEndPos + space.getSize(), - prevOverlineYEndPos, prevOverlineSize, + addLine(prevOverlineXEndPos, prevOverlineYEndPos, + prevOverlineXEndPos + space.getSize(), + prevOverlineYEndPos, prevOverlineSize, prevOverlineColor); - } - } + } + } if (space.getLineThrough()) { if (prevLineThroughColor != null) { - addLine(prevLineThroughXEndPos, prevLineThroughYEndPos, - prevLineThroughXEndPos + space.getSize(), - prevLineThroughYEndPos, prevLineThroughSize, + addLine(prevLineThroughXEndPos, prevLineThroughYEndPos, + prevLineThroughXEndPos + space.getSize(), + prevLineThroughYEndPos, prevLineThroughSize, prevLineThroughColor); - } - } - } + } + } + } /** * render line area @@ -520,13 +522,13 @@ public abstract class PrintRenderer implements Renderer { this.currentYPosition = ry - ia.getYOffset(); } else { this.currentYPosition = ry - area.getPlacementOffset(); - } + } b.render(this); - } + } this.currentYPosition = ry - h; this.currentXPosition = rx; - } + } /** * render page @@ -553,37 +555,37 @@ public abstract class PrintRenderer implements Renderer { if (th != 0) { switch (st) { case org.apache.fop.fo.properties.RuleStyle.DOUBLE: - addLine(rx, ry, rx + w, ry, th / 3, st, - new PDFColor(area.getRed(), area.getGreen(), + addLine(rx, ry, rx + w, ry, th / 3, st, + new PDFColor(area.getRed(), area.getGreen(), area.getBlue())); - addLine(rx, ry + (2 * th / 3), rx + w, ry + (2 * th / 3), - th / 3, st, - new PDFColor(area.getRed(), area.getGreen(), + addLine(rx, ry + (2 * th / 3), rx + w, ry + (2 * th / 3), + th / 3, st, + new PDFColor(area.getRed(), area.getGreen(), area.getBlue())); break; case org.apache.fop.fo.properties.RuleStyle.GROOVE: - addLine(rx, ry, rx + w, ry, th / 2, st, - new PDFColor(area.getRed(), area.getGreen(), + addLine(rx, ry, rx + w, ry, th / 2, st, + new PDFColor(area.getRed(), area.getGreen(), area.getBlue())); - addLine(rx, ry + (th / 2), rx + w, ry + (th / 2), th / 2, st, + addLine(rx, ry + (th / 2), rx + w, ry + (th / 2), th / 2, st, new PDFColor(255, 255, 255)); break; case org.apache.fop.fo.properties.RuleStyle.RIDGE: - addLine(rx, ry, rx + w, ry, th / 2, st, + addLine(rx, ry, rx + w, ry, th / 2, st, new PDFColor(255, 255, 255)); - addLine(rx, ry + (th / 2), rx + w, ry + (th / 2), th / 2, st, - new PDFColor(area.getRed(), area.getGreen(), + addLine(rx, ry + (th / 2), rx + w, ry + (th / 2), th / 2, st, + new PDFColor(area.getRed(), area.getGreen(), area.getBlue())); break; default: - addLine(rx, ry, rx + w, ry, th, st, - new PDFColor(area.getRed(), area.getGreen(), + addLine(rx, ry, rx + w, ry, th, st, + new PDFColor(area.getRed(), area.getGreen(), area.getBlue())); } this.currentXPosition += area.getContentWidth(); this.currentYPosition += th; - } - } + } + } /** * set up the font info @@ -593,16 +595,14 @@ public abstract class PrintRenderer implements Renderer { public void setupFontInfo(FontInfo fontInfo) { this.fontInfo = fontInfo; FontSetup.setup(fontInfo); - } - + } + /** Default start renderer method. This would normally be overridden. (mark-fop@inomial.com). */ public void startRenderer(OutputStream outputStream) - throws IOException - { - } + throws IOException {} /** Default stop renderer method. This would normally be overridden. (mark-fop@inomial.com). diff --git a/src/org/apache/fop/render/Renderer.java b/src/org/apache/fop/render/Renderer.java index c28ffc923..f9bc5946d 100644 --- a/src/org/apache/fop/render/Renderer.java +++ b/src/org/apache/fop/render/Renderer.java @@ -91,7 +91,7 @@ public interface Renderer { */ //public void render(AreaTree areaTree, OutputStream stream) throws IOException, FOPException; public void render(Page page, OutputStream stream) - throws IOException, FOPException; + throws IOException, FOPException; /** * render the given area container @@ -159,9 +159,9 @@ public interface Renderer { public void renderLeaderArea(LeaderArea area); public void startRenderer(OutputStream outputStream) - throws IOException; - + throws IOException; + public void stopRenderer(OutputStream outputStream) - throws IOException; + throws IOException; } diff --git a/src/org/apache/fop/render/awt/AWTRenderer.java b/src/org/apache/fop/render/awt/AWTRenderer.java index 57595eb47..29bef196b 100644 --- a/src/org/apache/fop/render/awt/AWTRenderer.java +++ b/src/org/apache/fop/render/awt/AWTRenderer.java @@ -74,7 +74,7 @@ public class AWTRenderer implements Renderer, Printable, Pageable { protected Color saveColor = null; protected IDReferences idReferences = null; - + /** * Image Object and Graphics Object. The Graphics Object is the Graphics * object that is contained withing the Image Object. @@ -189,10 +189,10 @@ public class AWTRenderer implements Renderer, Printable, Pageable { int y = y1; int height, width; if (x1 == x2) // vertical line - { + { height = y2 - y1; if (height > 0) // y coordinates are reversed between fo and AWT - { + { height = -height; y = y2; } @@ -202,7 +202,7 @@ public class AWTRenderer implements Renderer, Printable, Pageable { x -= width; } } else // horizontal line - { + { width = x2 - x1; if (width < 0) { width = -width; @@ -210,7 +210,7 @@ public class AWTRenderer implements Renderer, Printable, Pageable { } height = th; if (height > 0) // y coordinates are reversed between fo and AWT - { + { height = -height; y -= height; } @@ -239,6 +239,7 @@ public class AWTRenderer implements Renderer, Printable, Pageable { // changed by aml/rlc to use helper function that // corrects for integer roundoff, and to remove 3D effect + protected void addRect(int x, int y, int w, int h, float r, float g, float b) { graphics.setColor(new Color(r, g, b)); @@ -335,33 +336,31 @@ public class AWTRenderer implements Renderer, Printable, Pageable { } public void removePage(int page) { - pageList.removeElementAt(page); + pageList.removeElementAt(page); } - public void render(int aPageNumber) - { - if(aPageNumber >= pageList.size()) - return; - - try{ - render((Page) pageList.elementAt(aPageNumber)); - } catch(IOException e){ - e.printStackTrace(); - // This exception can't occur because we are not dealing with - // any files - } + public void render(int aPageNumber) { + if(aPageNumber >= pageList.size()) + return; + + try { + render((Page) pageList.elementAt(aPageNumber)); + } catch(IOException e) { + e.printStackTrace(); + // This exception can't occur because we are not dealing with + // any files + } + } public void render(Page page, OutputStream stream) - throws IOException - { - pageList.addElement(page); + throws IOException { + pageList.addElement(page); } public void render(Page page) - throws IOException - { - idReferences = page.getIDReferences(); + throws IOException { + idReferences = page.getIDReferences(); pageWidth = (int)((float)page.getWidth() / 1000f + .5); pageHeight = (int)((float)page.getHeight() / 1000f + .5); @@ -464,6 +463,7 @@ public class AWTRenderer implements Renderer, Printable, Pageable { (org.apache.fop.layout.Box)e.nextElement(); b.render(this); // span areas } + } // empty for now @@ -474,6 +474,7 @@ public class AWTRenderer implements Renderer, Printable, Pageable { (org.apache.fop.layout.Box)e.nextElement(); b.render(this); // column areas } + } private void doFrame(org.apache.fop.layout.Area area) { @@ -528,9 +529,9 @@ public class AWTRenderer implements Renderer, Printable, Pageable { borderColor = bp.getBorderColor(BorderAndPadding.RIGHT); addLine(rx + w, ry, rx + w, ry - h, // area.getBorderRightWidth(), borderColor.red(), // corrected aml/rlc - -area.getBorderRightWidth(), borderColor.red(), - borderColor.green(), - borderColor.blue()); + -area.getBorderRightWidth(), borderColor.red(), + borderColor.green(), + borderColor.blue()); } if (area.getBorderBottomWidth() != 0) { @@ -611,7 +612,7 @@ public class AWTRenderer implements Renderer, Printable, Pageable { java.awt.Font f = graphics.getFont(); java.awt.Font smallFont = new java.awt.Font(f.getFontName(), - f.getStyle(), 8); + f.getStyle(), 8); graphics.setFont(smallFont); @@ -630,6 +631,7 @@ public class AWTRenderer implements Renderer, Printable, Pageable { SVGDocument svg = ((SVGImage)img).getSVGDocument(); renderSVGDocument(svg, (int)x, (int)y); } catch (FopImageException e) {} + } else { String urlString = img.getURL(); @@ -657,6 +659,7 @@ public class AWTRenderer implements Renderer, Printable, Pageable { // cannot normally occur because, if URL is wrong, constructing FopImage // will already have failed earlier on } + } } @@ -881,6 +884,7 @@ public class AWTRenderer implements Renderer, Printable, Pageable { // defined in Renderer Interface } + public int print(Graphics g, PageFormat pageFormat, int pageIndex) throws PrinterException { if (pageIndex >= pageList.size()) @@ -902,7 +906,7 @@ public class AWTRenderer implements Renderer, Printable, Pageable { } public PageFormat getPageFormat(int pageIndex) - throws IndexOutOfBoundsException { + throws IndexOutOfBoundsException { if (pageIndex >= pageList.size()) return null; @@ -929,7 +933,7 @@ public class AWTRenderer implements Renderer, Printable, Pageable { } public Printable getPrintable(int pageIndex) - throws IndexOutOfBoundsException { + throws IndexOutOfBoundsException { return this; } @@ -1060,12 +1064,14 @@ public class AWTRenderer implements Renderer, Printable, Pageable { // application.openLink(uri); } + public Point getClientAreaLocationOnScreen() { return new Point(0, 0); } public void setSVGCursor(java.awt.Cursor cursor) {} + public AffineTransform getTransform() { return currentTransform; } @@ -1088,17 +1094,16 @@ public class AWTRenderer implements Renderer, Printable, Pageable { public void registerExtension(BridgeExtension be) {} + } - + public void startRenderer(OutputStream outputStream) - throws IOException - { - } - + throws IOException {} + + public void stopRenderer(OutputStream outputStream) - throws IOException - { - render(0); + throws IOException { + render(0); } - + } diff --git a/src/org/apache/fop/render/mif/MIFRenderer.java b/src/org/apache/fop/render/mif/MIFRenderer.java index 567d59359..154c73dc7 100644 --- a/src/org/apache/fop/render/mif/MIFRenderer.java +++ b/src/org/apache/fop/render/mif/MIFRenderer.java @@ -113,6 +113,7 @@ public class MIFRenderer implements Renderer { */ public void setProducer(String producer) {} + public void renderAreaContainer(AreaContainer area) { if (area.foCreator != null @@ -228,6 +229,7 @@ public class MIFRenderer implements Renderer { b.render(this); // span areas } + if (area.getPosition() != Position.STATIC) { this.currentYPosition = saveY; this.currentAreaContainerXPosition = saveX; @@ -302,6 +304,7 @@ public class MIFRenderer implements Renderer { Box b = (Box)e.nextElement(); b.render(this); // column areas } + } /** @@ -338,6 +341,7 @@ public class MIFRenderer implements Renderer { */ public void renderForeignObjectArea(ForeignObjectArea area) {} + public void renderWordArea(WordArea area) { String s; s = area.getText(); @@ -482,25 +486,23 @@ public class MIFRenderer implements Renderer { normally be overridden. (mark-fop@inomial.com). */ public void startRenderer(OutputStream outputStream) - throws IOException - { - MessageHandler.logln("rendering areas to MIF"); + throws IOException { + MessageHandler.logln("rendering areas to MIF"); } - + /** Default stop renderer method. This would normally be overridden. (mark-fop@inomial.com) */ public void stopRenderer(OutputStream outputStream) - throws IOException - { - MessageHandler.logln("writing out MIF"); - this.mifDoc.output(outputStream); - outputStream.flush(); + throws IOException { + MessageHandler.logln("writing out MIF"); + this.mifDoc.output(outputStream); + outputStream.flush(); } public void render(Page page, OutputStream outputStream) { - this.renderPage(page); + this.renderPage(page); } } diff --git a/src/org/apache/fop/render/pcl/PCLRenderer.java b/src/org/apache/fop/render/pcl/PCLRenderer.java index 9ccd4f39f..2b1dbbb1a 100755 --- a/src/org/apache/fop/render/pcl/PCLRenderer.java +++ b/src/org/apache/fop/render/pcl/PCLRenderer.java @@ -81,7 +81,7 @@ public class PCLRenderer extends PrintRenderer { * @param producer string indicating application producing PCL */ public void setProducer(String producer) {} - + /** * add a line to the current stream * @@ -286,7 +286,7 @@ public class PCLRenderer extends PrintRenderer { resolution = 75; if (debug) System.out.println("PCLRenderer.printBMP() iscolor = " + iscolor); - // Setup for graphics + // Setup for graphics currentStream.add("\033*t" + resolution + "R\033*r0F\033*r1A"); // Transfer graphics data @@ -300,7 +300,7 @@ public class PCLRenderer extends PrintRenderer { indx = iy * iw; if (iscolor) indx *= 3; - // currentStream.add("\033*b" + bytewidth + "W"); + // currentStream.add("\033*b" + bytewidth + "W"); for (ix = 0; ix < iw; ix++) { if (iscolor) { cr = imgmap[indx++] & 0xFF; @@ -477,6 +477,7 @@ public class PCLRenderer extends PrintRenderer { // currentStream.add("Q\n"); } + public void setFont(String name, float size) { int fontcode = 0; if (name.length() > 1 && name.charAt(0) == 'F') { @@ -490,61 +491,75 @@ public class PCLRenderer extends PrintRenderer { case 1: // F1 = Helvetica // currentStream.add("\033(8U\033(s1p" + (size / 1000) + "v0s0b24580T"); // Arial is more common among PCL5 printers than Helvetica - so use Arial + currentStream.add("\033(0N\033(s1p" + (size / 1000) + "v0s0b16602T"); break; case 2: // F2 = Helvetica Oblique + currentStream.add("\033(0N\033(s1p" + (size / 1000) + "v1s0b16602T"); break; case 3: // F3 = Helvetica Bold + currentStream.add("\033(0N\033(s1p" + (size / 1000) + "v0s3b16602T"); break; case 4: // F4 = Helvetica Bold Oblique + currentStream.add("\033(0N\033(s1p" + (size / 1000) + "v1s3b16602T"); break; case 5: // F5 = Times Roman // currentStream.add("\033(8U\033(s1p" + (size / 1000) + "v0s0b25093T"); // Times New is more common among PCL5 printers than Times - so use Times New + currentStream.add("\033(0N\033(s1p" + (size / 1000) + "v0s0b16901T"); break; case 6: // F6 = Times Italic + currentStream.add("\033(0N\033(s1p" + (size / 1000) + "v1s0b16901T"); break; case 7: // F7 = Times Bold + currentStream.add("\033(0N\033(s1p" + (size / 1000) + "v0s3b16901T"); break; case 8: // F8 = Times Bold Italic + currentStream.add("\033(0N\033(s1p" + (size / 1000) + "v1s3b16901T"); break; case 9: // F9 = Courier + currentStream.add("\033(0N\033(s0p" + (120.01f / (size / 1000.00f)) + "h0s0b4099T"); break; case 10: // F10 = Courier Oblique + currentStream.add("\033(0N\033(s0p" + (120.01f / (size / 1000.00f)) + "h1s0b4099T"); break; case 11: // F11 = Courier Bold + currentStream.add("\033(0N\033(s0p" + (120.01f / (size / 1000.00f)) + "h0s3b4099T"); break; case 12: // F12 = Courier Bold Oblique + currentStream.add("\033(0N\033(s0p" + (120.01f / (size / 1000.00f)) + "h1s3b4099T"); break; case 13: // F13 = Symbol + currentStream.add("\033(19M\033(s1p" + (size / 1000) + "v0s0b16686T"); // currentStream.add("\033(9U\033(s1p" + (size / 1000) + "v0s0b25093T"); // ECMA Latin 1 Symbol Set in Times Roman??? break; case 14: // F14 = Zapf Dingbats + currentStream.add("\033(14L\033(s1p" + (size / 1000) + "v0s0b45101T"); break; @@ -629,8 +644,8 @@ public class PCLRenderer extends PrintRenderer { System.out.println("PCLRenderer.renderPage() paperheight=" + paperheight + " divisions=" + divisions); - // Set top margin. - // float fullmargin = 0; + // Set top margin. + // float fullmargin = 0; if (divisions > 0) fullmargin = paperheight * curdiv / divisions; if (topmargin > 0) @@ -638,9 +653,9 @@ public class PCLRenderer extends PrintRenderer { if (debug) System.out.println("PCLRenderer.renderPage() curdiv=" + curdiv + " fullmargin=" + fullmargin); - // if ( fullmargin > 0 ) - // currentStream.add("\033&l" + (fullmargin / 15f) + "c1e8C"); - // this.currentYPosition = fullmargin * 100; + // if ( fullmargin > 0 ) + // currentStream.add("\033&l" + (fullmargin / 15f) + "c1e8C"); + // this.currentYPosition = fullmargin * 100; if (paperheight > 0) pageHeight = (paperheight / divisions) + fullmargin; @@ -676,7 +691,7 @@ public class PCLRenderer extends PrintRenderer { if (end != null) renderAreaContainer(end); - // End page. + // End page. if (++curdiv == divisions || divisions == -1) { curdiv = 0; currentStream.add("\f"); @@ -709,8 +724,8 @@ public class PCLRenderer extends PrintRenderer { */ } public void startRenderer(OutputStream outputStream) - throws IOException - { MessageHandler.logln("rendering areas to PCL"); + throws IOException { + MessageHandler.logln("rendering areas to PCL"); currentStream = new PCLStream(outputStream); // Set orientation. @@ -726,19 +741,17 @@ public class PCLRenderer extends PrintRenderer { // Reset the margins. currentStream.add("\033" + "9\033&l0E"); } - + public void stopRenderer(OutputStream outputStream) - throws IOException - { + throws IOException { MessageHandler.logln("writing out PCL"); outputStream.flush(); } public void render(Page page, OutputStream outputStream) - throws IOException - { + throws IOException { idReferences = page.getIDReferences(); - this.renderPage(page); + this.renderPage(page); } } diff --git a/src/org/apache/fop/render/pdf/PDFRenderer.java b/src/org/apache/fop/render/pdf/PDFRenderer.java index 4554ff7e5..70e74a0c6 100644 --- a/src/org/apache/fop/render/pdf/PDFRenderer.java +++ b/src/org/apache/fop/render/pdf/PDFRenderer.java @@ -146,17 +146,15 @@ public class PDFRenderer extends PrintRenderer { } public void startRenderer(OutputStream stream) - throws IOException - { - pdfDoc.outputHeader(stream); + throws IOException { + pdfDoc.outputHeader(stream); } public void stopRenderer(OutputStream stream) - throws IOException - { - pdfDoc.outputTrailer(stream); + throws IOException { + pdfDoc.outputTrailer(stream); } - + /** * add a line to the current stream * @@ -280,6 +278,7 @@ public class PDFRenderer extends PrintRenderer { renderSVGDocument(svg, (int)x, (int)y, area.getFontState()); currentStream.add("Q\nBT\n"); } catch (FopImageException e) {} + } else { int xObjectNum = this.pdfDoc.addImage(img); closeText(); @@ -410,10 +409,10 @@ public class PDFRenderer extends PrintRenderer { ctx.putBridge(aBridge); GraphicsNode root; PDFGraphics2D graphics = new PDFGraphics2D(true, fs, pdfDoc, - currentFontName, - currentFontSize, - currentXPosition, - currentYPosition); + currentFontName, + currentFontSize, + currentXPosition, + currentYPosition); graphics.setGraphicContext(new org.apache.batik.ext.awt.g2d.GraphicContext()); graphics.setRenderingHints(rc.getRenderingHints()); aBridge.setPDFGraphics2D(graphics); @@ -490,7 +489,7 @@ public class PDFRenderer extends PrintRenderer { (Font)area.getFontState().getFontInfo().getFonts().get(name); if (f instanceof CIDFont) useMultiByte = true; - // String startText = useMultiByte ? "<FEFF" : "("; + // String startText = useMultiByte ? "<FEFF" : "("; String startText = useMultiByte ? "<" : "("; String endText = useMultiByte ? "> " : ") "; @@ -628,6 +627,7 @@ public class PDFRenderer extends PrintRenderer { // This should never fail } + for (int i = 0; i < uniBytes.length; i++) { int b = (uniBytes[i] < 0) ? (int)(256 + uniBytes[i]) : (int)uniBytes[i]; @@ -671,21 +671,20 @@ public class PDFRenderer extends PrintRenderer { } public void render(Page page, OutputStream outputStream) - throws FOPException, IOException - { - // MessageHandler.logln("rendering single page to PDF"); - this.idReferences = page.getIDReferences(); - this.pdfResources = this.pdfDoc.getResources(); - this.pdfDoc.setIDReferences(idReferences); - this.renderPage(page); + throws FOPException, IOException { + // MessageHandler.logln("rendering single page to PDF"); + this.idReferences = page.getIDReferences(); + this.pdfResources = this.pdfDoc.getResources(); + this.pdfDoc.setIDReferences(idReferences); + this.renderPage(page); - FontSetup.addToResources(this.pdfDoc, fontInfo); + FontSetup.addToResources(this.pdfDoc, fontInfo); - // TODO: this needs to be implemented - renderRootExtensions(page); + // TODO: this needs to be implemented + renderRootExtensions(page); - // MessageHandler.logln("writing out PDF"); - this.pdfDoc.output(outputStream); + // MessageHandler.logln("writing out PDF"); + this.pdfDoc.output(outputStream); } /** @@ -749,7 +748,7 @@ public class PDFRenderer extends PrintRenderer { while (f.hasMoreElements()) { LinkedRectangle lrect = (LinkedRectangle)f.nextElement(); currentAnnotList.addLink(this.pdfDoc.makeLink(lrect.getRectangle(), - dest, linkType)); + dest, linkType)); } } } else { @@ -901,12 +900,14 @@ public class PDFRenderer extends PrintRenderer { // application.openLink(uri); } + public Point getClientAreaLocationOnScreen() { return new Point(0, 0); } public void setSVGCursor(java.awt.Cursor cursor) {} + public AffineTransform getTransform() { return currentTransform; } @@ -929,5 +930,6 @@ public class PDFRenderer extends PrintRenderer { public void registerExtension(BridgeExtension be) {} + } } diff --git a/src/org/apache/fop/render/ps/PSRenderer.java b/src/org/apache/fop/render/ps/PSRenderer.java index bbbe0e748..f0476bee8 100644 --- a/src/org/apache/fop/render/ps/PSRenderer.java +++ b/src/org/apache/fop/render/ps/PSRenderer.java @@ -437,10 +437,10 @@ public class PSRenderer implements Renderer { BridgeContext ctx = new BridgeContext(userAgent, rc); GraphicsNode root; PSGraphics2D graphics = new PSGraphics2D(false, area.getFontState(), - this, currentFontName, - currentFontSize, - currentXPosition, - currentYPosition); + this, currentFontName, + currentFontSize, + currentXPosition, + currentYPosition); graphics.setGraphicContext(new org.apache.batik.ext.awt.g2d.GraphicContext()); graphics.setRenderingHints(rc.getRenderingHints()); try { @@ -452,6 +452,7 @@ public class PSRenderer implements Renderer { // e.printStackTrace(); } + write("grestore"); comment("% --- SVG Area end"); @@ -747,6 +748,7 @@ public class PSRenderer implements Renderer { switch (area.getLeaderPattern()) { case LeaderPattern.SPACE: // NOP + break; case LeaderPattern.RULE: if (area.getRuleStyle() == RuleStyle.NONE) @@ -993,12 +995,14 @@ public class PSRenderer implements Renderer { // application.openLink(uri); } + public Point getClientAreaLocationOnScreen() { return new Point(0, 0); } public void setSVGCursor(java.awt.Cursor cursor) {} + public AffineTransform getTransform() { return currentTransform; } @@ -1021,17 +1025,17 @@ public class PSRenderer implements Renderer { public void registerExtension(BridgeExtension be) {} + } /** Default start renderer method. This would normally be overridden. (mark-fop@inomial.com). - */ + */ public void startRenderer(OutputStream outputStream) - throws IOException - { + throws IOException { MessageHandler.logln("rendering areas to PostScript"); - + this.out = new PSStream(outputStream); write("%!PS-Adobe-3.0"); write("%%Creator: "+this.producer); @@ -1047,14 +1051,13 @@ public class PSRenderer implements Renderer { write("%%EndSetup"); write("FOPFonts begin"); } - + /** Default stop renderer method. This would normally be overridden. (mark-fop@inomial.com). */ public void stopRenderer(OutputStream outputStream) - throws IOException - { + throws IOException { write("%%Trailer"); write("%%EOF"); this.out.flush(); @@ -1062,6 +1065,6 @@ public class PSRenderer implements Renderer { } public void render(Page page, OutputStream outputStream) { - this.renderPage(page); - } + this.renderPage(page); + } } diff --git a/src/org/apache/fop/render/txt/TXTRenderer.java b/src/org/apache/fop/render/txt/TXTRenderer.java index 11b9f31f9..b173ab03c 100755 --- a/src/org/apache/fop/render/txt/TXTRenderer.java +++ b/src/org/apache/fop/render/txt/TXTRenderer.java @@ -96,6 +96,7 @@ public class TXTRenderer extends PrintRenderer { */ public void setProducer(String producer) {} + void addStr(int row, int col, String str, boolean ischar) { if (debug) System.out.println("TXTRenderer.addStr(" + row + ", " + col @@ -734,6 +735,7 @@ public class TXTRenderer extends PrintRenderer { PDFColor fc, PDFColor sc, float sw, boolean close) {} + boolean printBMP(FopImage img, int x, int y, int w, int h) throws FopImageException { if (debug) @@ -750,13 +752,13 @@ public class TXTRenderer extends PrintRenderer { if (iname.length() >= namew) addStr((int)((pageHeight - (y / 100)) * 100 * yFactor) + nameh, (int)(x * xFactor), - iname.substring(iname.length() - namew), - true); + iname.substring(iname.length() - namew), + true); else addStr((int)((pageHeight - (y / 100)) * 100 * yFactor) + nameh, (int)(x * xFactor + (namew - iname.length()) - / 2), iname, true); + / 2), iname, true); } } @@ -868,6 +870,7 @@ public class TXTRenderer extends PrintRenderer { // this.currentYPosition -= area.getEffectiveHeight(); } + void renderSVG(FontState fontState, SVGSVGElement svg, int x, int y) { /* * SVG - Not yet implemented @@ -1607,7 +1610,7 @@ public class TXTRenderer extends PrintRenderer { if (end != null) renderAreaContainer(end); - // Write out the buffers. + // Write out the buffers. for (int row = 0; row <= maxY; row++) { StringBuffer cr = charData[row]; StringBuffer dr = decoData[row]; @@ -1673,35 +1676,32 @@ public class TXTRenderer extends PrintRenderer { */ } public void startRenderer(OutputStream outputStream) - throws IOException - { - MessageHandler.logln("rendering areas to TEXT"); - currentStream = new PCLStream(outputStream); - firstPage=true; + throws IOException { + MessageHandler.logln("rendering areas to TEXT"); + currentStream = new PCLStream(outputStream); + firstPage=true; } - - /** - * In Mark's patch, this is endRenderer - * However, I couldn't see how it builds that way, so - * i changed it. - Steve gears@apache.org - */ + + /** + * In Mark's patch, this is endRenderer + * However, I couldn't see how it builds that way, so + * i changed it. - Steve gears@apache.org + */ public void stopRenderer(OutputStream outputStream) - throws IOException - { + throws IOException { MessageHandler.logln("writing out TEXT"); outputStream.flush(); } - public void render(Page page, OutputStream outputStream) - { - idReferences = page.getIDReferences(); - - if ( firstPage ) - firstPage = false; - else - currentStream.add(pageEnding); - this.renderPage(page); - currentStream.add(lineEnding); - } + public void render(Page page, OutputStream outputStream) { + idReferences = page.getIDReferences(); + + if ( firstPage ) + firstPage = false; + else + currentStream.add(pageEnding); + this.renderPage(page); + currentStream.add(lineEnding); + } } diff --git a/src/org/apache/fop/render/xml/XMLRenderer.java b/src/org/apache/fop/render/xml/XMLRenderer.java index 6aeca10fd..487d2c59c 100644 --- a/src/org/apache/fop/render/xml/XMLRenderer.java +++ b/src/org/apache/fop/render/xml/XMLRenderer.java @@ -70,12 +70,11 @@ public class XMLRenderer implements Renderer { this.producer = producer; } - + public void render(Page page, OutputStream outputStream) - throws IOException - { - this.renderPage(page); - } + throws IOException { + this.renderPage(page); + } /** * write out spaces to make indent @@ -427,30 +426,28 @@ public class XMLRenderer implements Renderer { private boolean isCoarseXml() { return ((Boolean)options.get("fineDetail")).booleanValue(); } - + /** Default start renderer method. This would normally be overridden. (mark-fop@inomial.com). */ public void startRenderer(OutputStream outputStream) - throws IOException - { + throws IOException { MessageHandler.logln("rendering areas to XML"); this.writer = new PrintWriter(outputStream); this.writer.write( "<?xml version=\"1.0\"?>\n<!-- produced by " + this.producer + " -->\n"); writeStartTag("<AreaTree>"); } - + /** Default stop renderer method. This would normally be overridden. (mark-fop@inomial.com). */ public void stopRenderer(OutputStream outputStream) - throws IOException - { + throws IOException { writeEndTag("</AreaTree>"); this.writer.flush(); MessageHandler.errorln("written out XML"); - } + } } diff --git a/src/org/apache/fop/tools/TestConverter.java b/src/org/apache/fop/tools/TestConverter.java index 0e91530c3..f7e8c8e42 100644 --- a/src/org/apache/fop/tools/TestConverter.java +++ b/src/org/apache/fop/tools/TestConverter.java @@ -79,6 +79,7 @@ public class TestConverter { public TestConverter() {} + public void setOutputPDF(boolean pdf) { outputPDF = pdf; } @@ -123,6 +124,7 @@ public class TestConverter { testsuite.getAttributes().getNamedItem("profile").getNodeValue(); // System.out.println("testing test suite:" + profile); } + NodeList testcases = testsuite.getChildNodes(); for (int count = 0; count < testcases.getLength(); count++) { Node testcase = testcases.item(count); @@ -148,6 +150,7 @@ public class TestConverter { tcase.getAttributes().getNamedItem("profile").getNodeValue(); // System.out.println("testing profile:" + profile); } + NodeList cases = tcase.getChildNodes(); for (int count = 0; count < cases.getLength(); count++) { Node node = cases.item(count); @@ -157,6 +160,7 @@ public class TestConverter { } else if (nodename.equals("test")) { runTest(tcase, node); } else if (nodename.equals("result")) {} + } } @@ -207,7 +211,7 @@ public class TestConverter { } else { inputHandler = new XSLTInputHandler(xmlFile, new File(baseDir + "/" - + xsl)); + + xsl)); } XMLReader parser = inputHandler.getParser(); @@ -224,13 +228,13 @@ public class TestConverter { rendererOptions.put("fineDetail", new Boolean(false)); driver.getRenderer().setOptions(rendererOptions); driver.getRenderer().setProducer("Testsuite Converter"); - + String outname = xmlFile.getName(); if (outname.endsWith(".xml")) { outname = outname.substring(0, outname.length() - 4); } driver.setOutputStream(new FileOutputStream(new File(destdir, - outname + (outputPDF ? ".pdf" : ".at.xml")))); + outname + (outputPDF ? ".pdf" : ".at.xml")))); // System.out.println("ddir:" + destdir + " on:" + outname + ".pdf"); driver.render(parser, inputHandler.getInputSource()); @@ -266,6 +270,7 @@ public class TestConverter { } } } catch (Exception e) {} + return false; } |