Browse Source

Moved sources from src/org/** to src/java/org/**


git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@196061 13f79535-47bb-0310-9956-ffa450edef68
pull/30/head
Jeremias Maerki 21 years ago
parent
commit
df2923f9e5
100 changed files with 15701 additions and 0 deletions
  1. 152
    0
      src/java/org/apache/fop/apps/AWTStarter.java
  2. 725
    0
      src/java/org/apache/fop/apps/CommandLineOptions.java
  3. 122
    0
      src/java/org/apache/fop/apps/CommandLineStarter.java
  4. 748
    0
      src/java/org/apache/fop/apps/Driver.java
  5. 104
    0
      src/java/org/apache/fop/apps/FOInputHandler.java
  6. 150
    0
      src/java/org/apache/fop/apps/FOPException.java
  7. 91
    0
      src/java/org/apache/fop/apps/Fop.java
  8. 133
    0
      src/java/org/apache/fop/apps/InputHandler.java
  9. 312
    0
      src/java/org/apache/fop/apps/LayoutHandler.java
  10. 239
    0
      src/java/org/apache/fop/apps/PrintStarter.java
  11. 107
    0
      src/java/org/apache/fop/apps/Starter.java
  12. 295
    0
      src/java/org/apache/fop/apps/StructureHandler.java
  13. 152
    0
      src/java/org/apache/fop/apps/TraxInputHandler.java
  14. 67
    0
      src/java/org/apache/fop/apps/Version.java
  15. 182
    0
      src/java/org/apache/fop/apps/XSLTInputHandler.java
  16. 7
    0
      src/java/org/apache/fop/apps/package.html
  17. 265
    0
      src/java/org/apache/fop/area/Area.java
  18. 248
    0
      src/java/org/apache/fop/area/AreaTree.java
  19. 114
    0
      src/java/org/apache/fop/area/AreaTreeModel.java
  20. 97
    0
      src/java/org/apache/fop/area/BeforeFloat.java
  21. 135
    0
      src/java/org/apache/fop/area/Block.java
  22. 188
    0
      src/java/org/apache/fop/area/BlockParent.java
  23. 110
    0
      src/java/org/apache/fop/area/BlockViewport.java
  24. 173
    0
      src/java/org/apache/fop/area/BodyRegion.java
  25. 282
    0
      src/java/org/apache/fop/area/CTM.java
  26. 157
    0
      src/java/org/apache/fop/area/CachedRenderPagesModel.java
  27. 63
    0
      src/java/org/apache/fop/area/Flow.java
  28. 88
    0
      src/java/org/apache/fop/area/Footnote.java
  29. 147
    0
      src/java/org/apache/fop/area/LineArea.java
  30. 60
    0
      src/java/org/apache/fop/area/LineTrait.java
  31. 101
    0
      src/java/org/apache/fop/area/MainReference.java
  32. 166
    0
      src/java/org/apache/fop/area/Page.java
  33. 407
    0
      src/java/org/apache/fop/area/PageViewport.java
  34. 164
    0
      src/java/org/apache/fop/area/RegionReference.java
  35. 147
    0
      src/java/org/apache/fop/area/RegionViewport.java
  36. 223
    0
      src/java/org/apache/fop/area/RenderPagesModel.java
  37. 87
    0
      src/java/org/apache/fop/area/Resolveable.java
  38. 112
    0
      src/java/org/apache/fop/area/Span.java
  39. 179
    0
      src/java/org/apache/fop/area/StorePagesModel.java
  40. 60
    0
      src/java/org/apache/fop/area/Title.java
  41. 475
    0
      src/java/org/apache/fop/area/Trait.java
  42. 103
    0
      src/java/org/apache/fop/area/TreeExt.java
  43. 63
    0
      src/java/org/apache/fop/area/inline/Anchor.java
  44. 89
    0
      src/java/org/apache/fop/area/inline/Character.java
  45. 109
    0
      src/java/org/apache/fop/area/inline/Container.java
  46. 100
    0
      src/java/org/apache/fop/area/inline/FilledArea.java
  47. 96
    0
      src/java/org/apache/fop/area/inline/ForeignObject.java
  48. 82
    0
      src/java/org/apache/fop/area/inline/Image.java
  49. 205
    0
      src/java/org/apache/fop/area/inline/InlineArea.java
  50. 111
    0
      src/java/org/apache/fop/area/inline/InlineParent.java
  51. 121
    0
      src/java/org/apache/fop/area/inline/Leader.java
  52. 69
    0
      src/java/org/apache/fop/area/inline/Space.java
  53. 115
    0
      src/java/org/apache/fop/area/inline/UnresolvedPageNumber.java
  54. 164
    0
      src/java/org/apache/fop/area/inline/Viewport.java
  55. 118
    0
      src/java/org/apache/fop/area/inline/Word.java
  56. 77
    0
      src/java/org/apache/fop/datatypes/AutoLength.java
  57. 741
    0
      src/java/org/apache/fop/datatypes/ColorType.java
  58. 74
    0
      src/java/org/apache/fop/datatypes/CompoundDatatype.java
  59. 123
    0
      src/java/org/apache/fop/datatypes/CondLength.java
  60. 68
    0
      src/java/org/apache/fop/datatypes/FODimension.java
  61. 118
    0
      src/java/org/apache/fop/datatypes/FixedLength.java
  62. 123
    0
      src/java/org/apache/fop/datatypes/Keep.java
  63. 81
    0
      src/java/org/apache/fop/datatypes/KeepValue.java
  64. 148
    0
      src/java/org/apache/fop/datatypes/Length.java
  65. 136
    0
      src/java/org/apache/fop/datatypes/LengthBase.java
  66. 95
    0
      src/java/org/apache/fop/datatypes/LengthPair.java
  67. 211
    0
      src/java/org/apache/fop/datatypes/LengthRange.java
  68. 84
    0
      src/java/org/apache/fop/datatypes/LinearCombinationLength.java
  69. 134
    0
      src/java/org/apache/fop/datatypes/MixedLength.java
  70. 57
    0
      src/java/org/apache/fop/datatypes/PercentBase.java
  71. 107
    0
      src/java/org/apache/fop/datatypes/PercentLength.java
  72. 104
    0
      src/java/org/apache/fop/datatypes/Space.java
  73. 111
    0
      src/java/org/apache/fop/datatypes/TableColLength.java
  74. 62
    0
      src/java/org/apache/fop/datatypes/ToBeImplemented.java
  75. 87
    0
      src/java/org/apache/fop/datatypes/ToBeImplementedProperty.java
  76. 6
    0
      src/java/org/apache/fop/datatypes/package.html
  77. 271
    0
      src/java/org/apache/fop/extensions/BookmarkData.java
  78. 118
    0
      src/java/org/apache/fop/extensions/Bookmarks.java
  79. 111
    0
      src/java/org/apache/fop/extensions/ExtensionElementMapping.java
  80. 71
    0
      src/java/org/apache/fop/extensions/ExtensionObj.java
  81. 92
    0
      src/java/org/apache/fop/extensions/Label.java
  82. 144
    0
      src/java/org/apache/fop/extensions/Outline.java
  83. 102
    0
      src/java/org/apache/fop/fo/AbstractCharIterator.java
  84. 88
    0
      src/java/org/apache/fop/fo/BoxPropShorthandParser.java
  85. 62
    0
      src/java/org/apache/fop/fo/CharIterator.java
  86. 87
    0
      src/java/org/apache/fop/fo/CharacterProperty.java
  87. 120
    0
      src/java/org/apache/fop/fo/ColorProfile.java
  88. 93
    0
      src/java/org/apache/fop/fo/ColorTypeProperty.java
  89. 85
    0
      src/java/org/apache/fop/fo/CondLengthProperty.java
  90. 107
    0
      src/java/org/apache/fop/fo/Declarations.java
  91. 67
    0
      src/java/org/apache/fop/fo/ElementMapping.java
  92. 104
    0
      src/java/org/apache/fop/fo/EnumProperty.java
  93. 486
    0
      src/java/org/apache/fop/fo/FOElementMapping.java
  94. 203
    0
      src/java/org/apache/fop/fo/FONode.java
  95. 180
    0
      src/java/org/apache/fop/fo/FOText.java
  96. 275
    0
      src/java/org/apache/fop/fo/FOTreeBuilder.java
  97. 220
    0
      src/java/org/apache/fop/fo/FOUserAgent.java
  98. 376
    0
      src/java/org/apache/fop/fo/FObj.java
  99. 113
    0
      src/java/org/apache/fop/fo/FObjMixed.java
  100. 0
    0
      src/java/org/apache/fop/fo/GenericShorthandParser.java

+ 152
- 0
src/java/org/apache/fop/apps/AWTStarter.java View File

@@ -0,0 +1,152 @@
/*
* $Id: AWTStarter.java,v 1.18 2003/02/27 10:13:05 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.apps;

//FOP
import org.apache.fop.render.awt.AWTRenderer;
import org.apache.fop.viewer.PreviewDialog;
import org.apache.fop.viewer.Translator;

//Java
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Locale;

// SAX
import org.xml.sax.XMLReader;

/**
* AWT Viewer starter.
* Originally contributed by:
* Juergen Verwohlt: Juergen.Verwohlt@jCatalog.com,
* Rainer Steinkuhle: Rainer.Steinkuhle@jCatalog.com,
* Stanislav Gorkhover: Stanislav.Gorkhover@jCatalog.com
* Modified to use streaming API by Mark Lillywhite, mark-fop@inomial.com
*/
public class AWTStarter extends CommandLineStarter {
private PreviewDialog frame;
private Translator translator;
private Driver driver;
private XMLReader parser;

/**
* Construct an AWTStarter
* @param commandLineOptions the parsed command line options
* @throws FOPException if anything goes wrong during initialization.
*/
public AWTStarter(CommandLineOptions commandLineOptions)
throws FOPException {
super(commandLineOptions);
init();
}

private void init() throws FOPException {
//Creates Translator according to the language
String language = commandLineOptions.getLanguage();
if (language == null) {
translator = new Translator(Locale.getDefault());
} else {
translator = new Translator(new Locale(language, ""));
}
AWTRenderer renderer = new AWTRenderer(translator);
frame = createPreviewDialog(renderer, translator);
renderer.setComponent(frame);
driver = new Driver();
driver.setRenderer(renderer);
parser = inputHandler.getParser();
if (parser == null) {
throw new FOPException("Unable to create SAX parser");
}
}

/**
* Runs formatting.
* @throws FOPException FIXME should not happen.
*/
public void run() throws FOPException {
driver.reset();
try {
frame.setStatus(translator.getString("Status.Build.FO.tree"));
driver.render(parser, inputHandler.getInputSource());
frame.setStatus(translator.getString("Status.Show"));
frame.showPage();
} catch (Exception e) {
frame.reportException(e);
}
}

private PreviewDialog createPreviewDialog(AWTRenderer renderer,
Translator res) {
PreviewDialog frame = new PreviewDialog(this, renderer, res);
frame.addWindowListener(new WindowAdapter() {
public void windowClosed(WindowEvent we) {
System.exit(0);
}
});

//Centers the window
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = frame.getSize();
if (frameSize.height > screenSize.height) {
frameSize.height = screenSize.height;
}
if (frameSize.width > screenSize.width) {
frameSize.width = screenSize.width;
}
frame.setLocation((screenSize.width - frameSize.width) / 2,
(screenSize.height - frameSize.height) / 2);
frame.setVisible(true);
return frame;
}
}


+ 725
- 0
src/java/org/apache/fop/apps/CommandLineOptions.java View File

@@ -0,0 +1,725 @@
/*
* $Id: CommandLineOptions.java,v 1.22 2003/02/27 10:13:06 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.apps;

// java
import java.io.File;
import java.io.FileNotFoundException;

// Avalon
import org.apache.avalon.framework.logger.ConsoleLogger;
import org.apache.avalon.framework.logger.Logger;

/**
* Options parses the commandline arguments
*/
public class CommandLineOptions {

/* input / output not set */
private static final int NOT_SET = 0;
/* input: fo file */
private static final int FO_INPUT = 1;
/* input: xml+xsl file */
private static final int XSLT_INPUT = 2;
/* output: pdf file */
private static final int PDF_OUTPUT = 1;
/* output: screen using swing */
private static final int AWT_OUTPUT = 2;
/* output: mif file */
private static final int MIF_OUTPUT = 3;
/* output: sent swing rendered file to printer */
private static final int PRINT_OUTPUT = 4;
/* output: pcl file */
private static final int PCL_OUTPUT = 5;
/* output: postscript file */
private static final int PS_OUTPUT = 6;
/* output: text file */
private static final int TXT_OUTPUT = 7;
/* output: svg file */
private static final int SVG_OUTPUT = 8;
/* output: XML area tree */
private static final int AREA_OUTPUT = 9;
/* output: RTF file */
private static final int RTF_OUTPUT = 10;

/* show configuration information */
private Boolean dumpConfiguration = Boolean.FALSE;
/* suppress any progress information */
private Boolean quiet = Boolean.FALSE;
/* for area tree XML output, only down to block area level */
private Boolean suppressLowLevelAreas = Boolean.FALSE;
/* user configuration file */
private File userConfigFile = null;
/* input fo file */
private File fofile = null;
/* xsltfile (xslt transformation as input) */
private File xsltfile = null;
/* xml file (xslt transformation as input) */
private File xmlfile = null;
/* output file */
private File outfile = null;
/* input mode */
private int inputmode = NOT_SET;
/* output mode */
private int outputmode = NOT_SET;
/* language for user information */
private String language = null;

private java.util.HashMap rendererOptions;

private Logger log;

/**
* Construct a command line option object from command line arguments
* @param args command line parameters
* @throws FOPException for general errors
* @throws FileNotFoundException if an input file wasn't found.
*/
public CommandLineOptions(String[] args)
throws FOPException, FileNotFoundException {

log = new ConsoleLogger(ConsoleLogger.LEVEL_INFO);

boolean optionsParsed = true;
rendererOptions = new java.util.HashMap();
try {
optionsParsed = parseOptions(args);
if (optionsParsed) {
checkSettings();
}
} catch (FOPException e) {
printUsage();
throw e;
} catch (java.io.FileNotFoundException e) {
printUsage();
throw e;
}
}

/**
* Get the logger.
* @return the logger
*/
public Logger getLogger() {
return log;
}

/**
* parses the commandline arguments
* @return true if parse was successful and processing can continue, false
* if processing should stop
* @exception FOPException if there was an error in the format of the options
*/
private boolean parseOptions(String args[]) throws FOPException {
for (int i = 0; i < args.length; i++) {
if (args[i].equals("-d") || args[i].equals("--full-error-dump")) {
log = new ConsoleLogger(ConsoleLogger.LEVEL_DEBUG);
} else if (args[i].equals("-x")
|| args[i].equals("--dump-config")) {
dumpConfiguration = Boolean.TRUE;
} else if (args[i].equals("-q") || args[i].equals("--quiet")) {
quiet = Boolean.TRUE;
log = new ConsoleLogger(ConsoleLogger.LEVEL_ERROR);
} else if (args[i].equals("-c")) {
if ((i + 1 == args.length)
|| (args[i + 1].charAt(0) == '-')) {
throw new FOPException("if you use '-c', you must specify "
+ "the name of the configuration file");
} else {
userConfigFile = new File(args[i + 1]);
i++;
}
} else if (args[i].equals("-l")) {
if ((i + 1 == args.length)
|| (args[i + 1].charAt(0) == '-')) {
throw new FOPException("if you use '-l', you must specify a language");
} else {
language = args[i + 1];
i++;
}
} else if (args[i].equals("-s")) {
suppressLowLevelAreas = Boolean.TRUE;
} else if (args[i].equals("-fo")) {
inputmode = FO_INPUT;
if ((i + 1 == args.length)
|| (args[i + 1].charAt(0) == '-')) {
throw new FOPException("you must specify the fo file for the '-fo' option");
} else {
fofile = new File(args[i + 1]);
i++;
}
} else if (args[i].equals("-xsl")) {
inputmode = XSLT_INPUT;
if ((i + 1 == args.length)
|| (args[i + 1].charAt(0) == '-')) {
throw new FOPException("you must specify the stylesheet "
+ "file for the '-xsl' option");
} else {
xsltfile = new File(args[i + 1]);
i++;
}
} else if (args[i].equals("-xml")) {
inputmode = XSLT_INPUT;
if ((i + 1 == args.length)
|| (args[i + 1].charAt(0) == '-')) {
throw new FOPException("you must specify the input file "
+ "for the '-xml' option");
} else {
xmlfile = new File(args[i + 1]);
i++;
}
} else if (args[i].equals("-awt")) {
setOutputMode(AWT_OUTPUT);
} else if (args[i].equals("-pdf")) {
setOutputMode(PDF_OUTPUT);
if ((i + 1 == args.length)
|| (args[i + 1].charAt(0) == '-')) {
throw new FOPException("you must specify the pdf output file");
} else {
outfile = new File(args[i + 1]);
i++;
}
} else if (args[i].equals("-mif")) {
setOutputMode(MIF_OUTPUT);
if ((i + 1 == args.length)
|| (args[i + 1].charAt(0) == '-')) {
throw new FOPException("you must specify the mif output file");
} else {
outfile = new File(args[i + 1]);
i++;
}
} else if (args[i].equals("-rtf")) {
setOutputMode(RTF_OUTPUT);
if ((i + 1 == args.length)
|| (args[i + 1].charAt(0) == '-')) {
throw new FOPException("you must specify the rtf output file");
} else {
outfile = new File(args[i + 1]);
i++;
}
} else if (args[i].equals("-print")) {
setOutputMode(PRINT_OUTPUT);
// show print help
if (i + 1 < args.length) {
if (args[i + 1].equals("help")) {
printUsagePrintOutput();
return false;
}
}
} else if (args[i].equals("-pcl")) {
setOutputMode(PCL_OUTPUT);
if ((i + 1 == args.length)
|| (args[i + 1].charAt(0) == '-')) {
throw new FOPException("you must specify the pdf output file");
} else {
outfile = new File(args[i + 1]);
i++;
}
} else if (args[i].equals("-ps")) {
setOutputMode(PS_OUTPUT);
if ((i + 1 == args.length)
|| (args[i + 1].charAt(0) == '-')) {
throw new FOPException("you must specify the PostScript output file");
} else {
outfile = new File(args[i + 1]);
i++;
}
} else if (args[i].equals("-txt")) {
setOutputMode(TXT_OUTPUT);
if ((i + 1 == args.length)
|| (args[i + 1].charAt(0) == '-')) {
throw new FOPException("you must specify the text output file");
} else {
outfile = new File(args[i + 1]);
i++;
}
} else if (args[i].equals("-svg")) {
setOutputMode(SVG_OUTPUT);
if ((i + 1 == args.length)
|| (args[i + 1].charAt(0) == '-')) {
throw new FOPException("you must specify the svg output file");
} else {
outfile = new File(args[i + 1]);
i++;
}
} else if (args[i].charAt(0) != '-') {
if (inputmode == NOT_SET) {
inputmode = FO_INPUT;
fofile = new File(args[i]);
} else if (outputmode == NOT_SET) {
outputmode = PDF_OUTPUT;
outfile = new File(args[i]);
} else {
throw new FOPException("Don't know what to do with "
+ args[i]);
}
} else if (args[i].equals("-at")) {
setOutputMode(AREA_OUTPUT);
if ((i + 1 == args.length)
|| (args[i + 1].charAt(0) == '-')) {
throw new FOPException("you must specify the area-tree output file");
} else {
outfile = new File(args[i + 1]);
i++;
}
} else {
printUsage();
return false;
}
}
return true;
} // end parseOptions

private void setOutputMode(int mode) throws FOPException {
if (outputmode == NOT_SET) {
outputmode = mode;
} else {
throw new FOPException("you can only set one output method");
}
}

/**
* checks whether all necessary information has been given in a consistent way
*/
private void checkSettings() throws FOPException, FileNotFoundException {
if (inputmode == NOT_SET) {
throw new FOPException("No input file specified");
}

if (outputmode == NOT_SET) {
throw new FOPException("No output file specified");
}

if (inputmode == XSLT_INPUT) {
// check whether xml *and* xslt file have been set
if (xmlfile == null) {
throw new FOPException("XML file must be specified for the tranform mode");
}
if (xsltfile == null) {
throw new FOPException("XSLT file must be specified for the tranform mode");
}

// warning if fofile has been set in xslt mode
if (fofile != null) {
log.warn("Can't use fo file with transform mode! Ignoring.\n"
+ "Your input is " + "\n xmlfile: "
+ xmlfile.getAbsolutePath()
+ "\nxsltfile: "
+ xsltfile.getAbsolutePath()
+ "\n fofile: "
+ fofile.getAbsolutePath());
}
if (!xmlfile.exists()) {
throw new FileNotFoundException("xml file "
+ xmlfile.getAbsolutePath()
+ " not found ");
}
if (!xsltfile.exists()) {
throw new FileNotFoundException("xsl file "
+ xsltfile.getAbsolutePath()
+ " not found ");
}

} else if (inputmode == FO_INPUT) {
if (xmlfile != null || xsltfile != null) {
log.warn("fo input mode, but xmlfile or xslt file are set:");
log.error("xml file: " + xmlfile.toString());
log.error("xslt file: " + xsltfile.toString());
}
if (!fofile.exists()) {
throw new FileNotFoundException("fo file "
+ fofile.getAbsolutePath()
+ " not found ");
}

}
} // end checkSettings

/**
* @return the type chosen renderer
* @throws FOPException for invalid output modes
*/
public int getRenderer() throws FOPException {
switch (outputmode) {
case NOT_SET:
throw new FOPException("Renderer has not been set!");
case PDF_OUTPUT:
return Driver.RENDER_PDF;
case AWT_OUTPUT:
return Driver.RENDER_AWT;
case MIF_OUTPUT:
return Driver.RENDER_MIF;
case PRINT_OUTPUT:
return Driver.RENDER_PRINT;
case PCL_OUTPUT:
return Driver.RENDER_PCL;
case PS_OUTPUT:
return Driver.RENDER_PS;
case TXT_OUTPUT:
return Driver.RENDER_TXT;
case SVG_OUTPUT:
return Driver.RENDER_SVG;
case AREA_OUTPUT:
rendererOptions.put("fineDetail", isCoarseAreaXml());
return Driver.RENDER_XML;
case RTF_OUTPUT:
return Driver.RENDER_RTF;
default:
throw new FOPException("Invalid Renderer setting!");
}
}

/**
* Get the input handler.
* @return the input handler
*/
public InputHandler getInputHandler() {
switch (inputmode) {
case FO_INPUT:
return new FOInputHandler(fofile);
case XSLT_INPUT:
return new XSLTInputHandler(xmlfile, xsltfile);
default:
return new FOInputHandler(fofile);
}
}

/**
* Get the renderer specific options.
* @return hash map with option/value pairs.
*/
public java.util.HashMap getRendererOptions() {
return rendererOptions;
}

/**
* Get the starter for the process.
* @return the starter.
* @throws FOPException In case of failure while getting the starter
*/
public Starter getStarter() throws FOPException {
Starter starter = null;
switch (outputmode) {
case AWT_OUTPUT:
try {
starter = new AWTStarter(this);
} catch (FOPException e) {
throw e;
} catch (Exception e) {
throw new FOPException("AWTStarter could not be loaded.", e);
}
break;
case PRINT_OUTPUT:
try {
starter = new PrintStarter(this);
} catch (FOPException e) {
throw e;
} catch (Exception e) {
throw new FOPException("PrintStarter could not be loaded.", e);
}
break;
default:
starter = new CommandLineStarter(this);
}
starter.enableLogging(log);
return starter;
}

/**
* Returns the input mode (type of input data, ex. NOT_SET or FO_INPUT)
* @return the input mode
*/
public int getInputMode() {
return inputmode;
}

/**
* Returns the output mode (output format, ex. NOT_SET or PDF_OUTPUT)
* @return the output mode
*/
public int getOutputMode() {
return outputmode;
}

/**
* Returns the XSL-FO file if set.
* @return the XSL-FO file, null if not set
*/
public File getFOFile() {
return fofile;
}

/**
* Returns the input XML file if set.
* @return the input XML file, null if not set
*/
public File getXMLFile() {
return xmlfile;
}

/**
* Returns the stylesheet to be used for transformation to XSL-FO.
* @return stylesheet
*/
public File getXSLFile() {
return xsltfile;
}

/**
* Returns the output file
* @return the output file
*/
public File getOutputFile() {
return outfile;
}

/**
* Returns the user configuration file to be used.
* @return the userconfig.xml file
*/
public File getUserConfigFile() {
return userConfigFile;
}

/**
* Returns the default language
* @return the default language
*/
public String getLanguage() {
return language;
}

/**
* Indicates if FOP should be silent.
* @return true if should be silent
*/
public Boolean isQuiet() {
return quiet;
}

/**
* Indicates if FOP should dump its configuration during runtime.
* @return true if config dump is enabled
*/
public Boolean dumpConfiguration() {
return dumpConfiguration;
}

/**
* Indicates whether the XML renderer should generate course area XML
* @return true if coarse area XML is desired
*/
public Boolean isCoarseAreaXml() {
return suppressLowLevelAreas;
}

/**
* Returns the input file.
* @return either the fofile or the xmlfile
*/
public File getInputFile() {
switch (inputmode) {
case FO_INPUT:
return fofile;
case XSLT_INPUT:
return xmlfile;
default:
return fofile;
}
}

/**
* shows the commandline syntax including a summary of all available options and some examples
*/
public static void printUsage() {
System.err.println(
"\nUSAGE\nFop [options] [-fo|-xml] infile [-xsl file] "
+ "[-awt|-pdf|-mif|-rtf|-pcl|-ps|-txt|-at|-print] <outfile>\n"
+ " [OPTIONS] \n"
+ " -d debug mode \n"
+ " -x dump configuration settings \n"
+ " -q quiet mode \n"
+ " -c cfg.xml use additional configuration file cfg.xml\n"
+ " -l lang the language to use for user information \n"
+ " -s for area tree XML, down to block areas only\n\n"
+ " [INPUT] \n"
+ " infile xsl:fo input file (the same as the next) \n"
+ " -fo infile xsl:fo input file \n"
+ " -xml infile xml input file, must be used together with -xsl \n"
+ " -xsl stylesheet xslt stylesheet \n \n"
+ " [OUTPUT] \n"
+ " outfile input will be rendered as pdf file into outfile \n"
+ " -pdf outfile input will be rendered as pdf file (outfile req'd) \n"
+ " -awt input will be displayed on screen \n"
+ " -mif outfile input will be rendered as mif file (outfile req'd)\n"
+ " -rtf outfile input will be rendered as rtf file (outfile req'd)\n"
+ " -pcl outfile input will be rendered as pcl file (outfile req'd) \n"
+ " -ps outfile input will be rendered as PostScript file (outfile req'd) \n"
+ " -txt outfile input will be rendered as text file (outfile req'd) \n"
+ " -svg outfile input will be rendered as an svg slides file (outfile req'd) \n"
+ " -at outfile representation of area tree as XML (outfile req'd) \n"
+ " -print input file will be rendered and sent to the printer \n"
+ " see options with \"-print help\" \n\n"
+ " [Examples]\n" + " Fop foo.fo foo.pdf \n"
+ " Fop -fo foo.fo -pdf foo.pdf (does the same as the previous line)\n"
+ " Fop -xsl foo.xsl -xml foo.xml -pdf foo.pdf\n"
+ " Fop foo.fo -mif foo.mif\n"
+ " Fop foo.fo -rtf foo.rtf\n"
+ " Fop foo.fo -print or Fop -print foo.fo \n"
+ " Fop foo.fo -awt \n");
}
/**
* shows the options for print output
*/
public void printUsagePrintOutput() {
System.err.println("USAGE: -print [-Dstart=i] [-Dend=i] [-Dcopies=i] [-Deven=true|false] "
+ " org.apache.fop.apps.Fop (..) -print \n"
+ "Example:\n"
+ "java -Dstart=1 -Dend=2 org.apache.Fop.apps.Fop infile.fo -print ");
}


/**
* debug mode. outputs all commandline settings
*/
private void debug() {
log.debug("Input mode: ");
switch (inputmode) {
case NOT_SET:
log.debug("not set");
break;
case FO_INPUT:
log.debug("FO ");
log.debug("fo input file: " + fofile.toString());
break;
case XSLT_INPUT:
log.debug("xslt transformation");
log.debug("xml input file: " + xmlfile.toString());
log.debug("xslt stylesheet: " + xsltfile.toString());
break;
default:
log.debug("unknown input type");
}
log.debug("Output mode: ");
switch (outputmode) {
case NOT_SET:
log.debug("not set");
break;
case PDF_OUTPUT:
log.debug("pdf");
log.debug("output file: " + outfile.toString());
break;
case AWT_OUTPUT:
log.debug("awt on screen");
if (outfile != null) {
log.error("awt mode, but outfile is set:");
log.debug("out file: " + outfile.toString());
}
break;
case MIF_OUTPUT:
log.debug("mif");
log.debug("output file: " + outfile.toString());
break;
case RTF_OUTPUT:
log.debug("rtf");
log.debug("output file: " + outfile.toString());
break;
case PRINT_OUTPUT:
log.debug("print directly");
if (outfile != null) {
log.error("print mode, but outfile is set:");
log.error("out file: " + outfile.toString());
}
break;
case PCL_OUTPUT:
log.debug("pcl");
log.debug("output file: " + outfile.toString());
break;
case PS_OUTPUT:
log.debug("PostScript");
log.debug("output file: " + outfile.toString());
break;
case TXT_OUTPUT:
log.debug("txt");
log.debug("output file: " + outfile.toString());
break;
case SVG_OUTPUT:
log.debug("svg");
log.debug("output file: " + outfile.toString());
break;
default:
log.debug("unknown input type");
}


log.debug("OPTIONS");
if (userConfigFile != null) {
log.debug("user configuration file: "
+ userConfigFile.toString());
} else {
log.debug("no user configuration file is used [default]");
}
if (dumpConfiguration != null) {
log.debug("dump configuration");
} else {
log.debug("don't dump configuration [default]");
}
if (quiet != null) {
log.debug("quiet mode on");
} else {
log.debug("quiet mode off [default]");
}

}

}


+ 122
- 0
src/java/org/apache/fop/apps/CommandLineStarter.java View File

@@ -0,0 +1,122 @@
/*
* $Id$
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.apps;

// SAX
import org.xml.sax.XMLReader;

// Java
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;


/**
* super class for all classes which start Fop from the commandline
*
* Modified to use new streaming API by Mark Lillywhite, mark-fop@inomial.com
*/
public class CommandLineStarter extends Starter {

/** the command-line options associated with this starter */
protected CommandLineOptions commandLineOptions;

/**
* Main constructor
* @param commandLineOptions command-line options to use
* @throws FOPException In case of failure
*/
public CommandLineStarter(CommandLineOptions commandLineOptions)
throws FOPException {
this.commandLineOptions = commandLineOptions;
super.setInputHandler(commandLineOptions.getInputHandler());
}

/**
* Run the format.
* @exception FOPException if there is an error during processing
*/
public void run() throws FOPException {
String version = Version.getVersion();

getLogger().info(version);

XMLReader parser = inputHandler.getParser();
setParserFeatures(parser);

Driver driver = new Driver();
setupLogger(driver);
driver.initialize();

try {
driver.setRenderer(commandLineOptions.getRenderer());
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(
commandLineOptions.getOutputFile()));
try {
driver.setOutputStream(bos);
if (driver.getRenderer() != null) {
driver.getRenderer().setOptions(
commandLineOptions.getRendererOptions());
}
driver.render(parser, inputHandler.getInputSource());
} finally {
bos.close();
}
System.exit(0);
} catch (Exception e) {
if (e instanceof FOPException) {
throw (FOPException) e;
}
throw new FOPException(e);
}
}

}


+ 748
- 0
src/java/org/apache/fop/apps/Driver.java View File

@@ -0,0 +1,748 @@
/*
* $Id$
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.apps;

// FOP
import org.apache.fop.fo.ElementMapping;
import org.apache.fop.fo.FOTreeBuilder;
import org.apache.fop.fo.FOUserAgent;
import org.apache.fop.render.Renderer;
import org.apache.fop.tools.DocumentInputSource;
import org.apache.fop.tools.DocumentReader;


// Avalon
import org.apache.avalon.framework.logger.ConsoleLogger;
import org.apache.avalon.framework.logger.LogEnabled;
import org.apache.avalon.framework.logger.Logger;

// DOM
import org.w3c.dom.Document;

// SAX
import org.xml.sax.ContentHandler;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import javax.xml.parsers.ParserConfigurationException;

// Java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.Reader;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

/**
* Primary class that drives overall FOP process.
* <P>
* The simplest way to use this is to instantiate it with the
* InputSource and OutputStream, then set the renderer desired, and
* calling run();
* <P>
* Here is an example use of Driver which outputs PDF:
*
* <PRE>
* Driver driver = new Driver(new InputSource (args[0]),
* new FileOutputStream(args[1]));
* driver.enableLogging(myLogger); //optional
* driver.setRenderer(RENDER_PDF);
* driver.run();
* </PRE>
* If neccessary, calling classes can call into the lower level
* methods to setup and
* render. Methods can be called to set the
* Renderer to use, the (possibly multiple) ElementMapping(s) to
* use and the OutputStream to use to output the results of the
* rendering (where applicable). In the case of the Renderer and
* ElementMapping(s), the Driver may be supplied either with the
* object itself, or the name of the class, in which case Driver will
* instantiate the class itself. The advantage of the latter is it
* enables runtime determination of Renderer and ElementMapping(s).
* <P>
* Once the Driver is set up, the render method
* is called. Depending on whether DOM or SAX is being used, the
* invocation of the method is either render(Document) or
* buildFOTree(Parser, InputSource) respectively.
* <P>
* A third possibility may be used to build the FO Tree, namely
* calling getContentHandler() and firing the SAX events yourself.
* <P>
* Once the FO Tree is built, the format() and render() methods may be
* called in that order.
* <P>
* Here is an example use of Driver which outputs to AWT:
*
* <PRE>
* Driver driver = new Driver();
* driver.enableLogging(myLogger); //optional
* driver.setRenderer(new org.apache.fop.render.awt.AWTRenderer(translator));
* driver.render(parser, fileInputSource(args[0]));
* </PRE>
*/
public class Driver implements LogEnabled {

/**
* Render to PDF. OutputStream must be set
*/
public static final int RENDER_PDF = 1;

/**
* Render to a GUI window. No OutputStream neccessary
*/
public static final int RENDER_AWT = 2;

/**
* Render to MIF. OutputStream must be set
*/
public static final int RENDER_MIF = 3;

/**
* Render to XML. OutputStream must be set
*/
public static final int RENDER_XML = 4;

/**
* Render to PRINT. No OutputStream neccessary
*/
public static final int RENDER_PRINT = 5;

/**
* Render to PCL. OutputStream must be set
*/
public static final int RENDER_PCL = 6;

/**
* Render to Postscript. OutputStream must be set
*/
public static final int RENDER_PS = 7;

/**
* Render to Text. OutputStream must be set
*/
public static final int RENDER_TXT = 8;

/**
* Render to SVG. OutputStream must be set
*/
public static final int RENDER_SVG = 9;

/**
* Render to RTF. OutputStream must be set
*/
public static final int RENDER_RTF = 10;

/**
* the FO tree builder
*/
private FOTreeBuilder treeBuilder;

/**
* the renderer type code given by setRenderer
*/
private int rendererType;

/**
* the renderer to use to output the area tree
*/
private Renderer renderer;

/**
* the structure handler
*/
private StructureHandler structHandler;

/**
* the source of the FO file
*/
private InputSource source;

/**
* the stream to use to output the results of the renderer
*/
private OutputStream stream;

/**
* The XML parser to use when building the FO tree
*/
private XMLReader reader;

/**
* the system resources that FOP will use
*/
private Logger log = null;
private FOUserAgent userAgent = null;

/**
* Returns the fully qualified classname of the standard XML parser for FOP
* to use.
* @return the XML parser classname
*/
public static final String getParserClassName() {
try {
return javax.xml.parsers.SAXParserFactory.newInstance()
.newSAXParser().getXMLReader().getClass().getName();
} catch (javax.xml.parsers.ParserConfigurationException e) {
return null;
} catch (org.xml.sax.SAXException e) {
return null;
}
}

/**
* Main constructor for the Driver class.
*/
public Driver() {
stream = null;
}

/**
* Convenience constructor for directly setting input and output.
* @param source InputSource to take the XSL-FO input from
* @param stream Target output stream
*/
public Driver(InputSource source, OutputStream stream) {
this();
this.source = source;
this.stream = stream;
}

/**
* Initializes the Driver object.
*/
public void initialize() {
stream = null;
treeBuilder = new FOTreeBuilder();
treeBuilder.setUserAgent(getUserAgent());
setupDefaultMappings();
}

/**
* Optionally sets the FOUserAgent instance for FOP to use. The Driver
* class sets up its own FOUserAgent if none is set through this method.
* @param agent FOUserAgent to use
*/
public void setUserAgent(FOUserAgent agent) {
userAgent = agent;
}

private FOUserAgent getUserAgent() {
if (userAgent == null) {
userAgent = new FOUserAgent();
userAgent.enableLogging(getLogger());
userAgent.setBaseURL("");
}
return userAgent;
}

/**
* Provide the Driver instance with a logger. More information on Avalon
* logging can be found at the
* <a href="http://avalon.apache.org">Avalon site</a>.
*
* @param log the logger. Must not be <code>null</code>.
* @see org.apache.avalon.framework.logger.LogEnabled#enableLogging(Logger)
*/
public void enableLogging(Logger log) {
if (this.log == null) {
this.log = log;
} else {
getLogger().warn("Logger is already set! Won't use the new logger.");
}
}


/**
* Returns the logger for use by FOP.
* @return the logger
* @see #enableLogging(Logger)
*/
protected Logger getLogger() {
if (this.log == null) {
this.log = new ConsoleLogger(ConsoleLogger.LEVEL_INFO);
this.log.error("Logger not set. Using ConsoleLogger as default.");
}

return this.log;
}

/**
* Resets the Driver so it can be reused. Property and element
* mappings are reset to defaults.
* The output stream is cleared. The renderer is cleared.
*/
public synchronized void reset() {
source = null;
stream = null;
reader = null;
treeBuilder.reset();
}

/**
* Indicates whether FOP has already received input data.
* @return true, if input data was received
*/
public boolean hasData() {
return (treeBuilder.hasData());
}

/**
* Set the OutputStream to use to output the result of the Renderer
* (if applicable)
* @param stream the stream to output the result of rendering to
*/
public void setOutputStream(OutputStream stream) {
this.stream = stream;
}

/**
* Set the source for the FO document. This can be a normal SAX
* InputSource, or an DocumentInputSource containing a DOM document.
* @see DocumentInputSource
*/
public void setInputSource(InputSource source) {
this.source = source;
}

/**
* Sets the reader used when reading in the source. If not set,
* this defaults to a basic SAX parser.
* @param reader the reader to use.
*/
public void setXMLReader(XMLReader reader) {
this.reader = reader;
}

/**
* Sets all the element and property list mappings to their default values.
*
*/
public void setupDefaultMappings() {
addElementMapping("org.apache.fop.fo.FOElementMapping");
addElementMapping("org.apache.fop.svg.SVGElementMapping");
addElementMapping("org.apache.fop.extensions.ExtensionElementMapping");

// add mappings from available services
Iterator providers =
Service.providers(org.apache.fop.fo.ElementMapping.class);
if (providers != null) {
while (providers.hasNext()) {
String str = (String)providers.next();
try {
addElementMapping(str);
} catch (IllegalArgumentException e) {
getLogger().warn("Error while adding element mapping", e);
}

}
}
}

/**
* Shortcut to set the rendering type to use. Must be one of
* <ul>
* <li>RENDER_PDF</li>
* <li>RENDER_AWT</li>
* <li>RENDER_MIF</li>
* <li>RENDER_XML</li>
* <li>RENDER_PCL</li>
* <li>RENDER_PS</li>
* <li>RENDER_TXT</li>
* <li>RENDER_SVG</li>
* <li>RENDER_RTF</li>
* </ul>
* @param renderer the type of renderer to use
* @throws IllegalArgumentException if an unsupported renderer type was required.
*/
public void setRenderer(int renderer) throws IllegalArgumentException {
rendererType = renderer;
switch (renderer) {
case RENDER_PDF:
setRenderer("org.apache.fop.render.pdf.PDFRenderer");
break;
case RENDER_AWT:
throw new IllegalArgumentException("Use renderer form of setRenderer() for AWT");
case RENDER_PRINT:
throw new IllegalArgumentException("Use renderer form of setRenderer() for PRINT");
case RENDER_PCL:
setRenderer("org.apache.fop.render.pcl.PCLRenderer");
break;
case RENDER_PS:
setRenderer("org.apache.fop.render.ps.PSRenderer");
break;
case RENDER_TXT:
setRenderer("org.apache.fop.render.txt.TXTRenderer()");
break;
case RENDER_MIF:
//structHandler will be set later
break;
case RENDER_XML:
setRenderer("org.apache.fop.render.xml.XMLRenderer");
break;
case RENDER_SVG:
setRenderer("org.apache.fop.render.svg.SVGRenderer");
break;
case RENDER_RTF:
//structHandler will be set later
break;
default:
throw new IllegalArgumentException("Unknown renderer type");
}
}

/**
* Set the Renderer to use.
* @param renderer the renderer instance to use (Note: Logger must be set at this point)
*/
public void setRenderer(Renderer renderer) {
renderer.setUserAgent(getUserAgent());
this.renderer = renderer;
}

/**
* Returns the currently active renderer.
* @return the renderer
*/
public Renderer getRenderer() {
return renderer;
}

/**
* Sets the renderer.
* @param rendererClassName the fully qualified classname of the renderer
* class to use.
* @param version version number
* @deprecated use renderer.setProducer(version) + setRenderer(renderer) or
* just setRenderer(rendererType) which will use the default producer string.
* @see #setRenderer(int)
* @see #setRenderer(Renderer)
*/
public void setRenderer(String rendererClassName, String version) {
setRenderer(rendererClassName);
}

/**
* Set the class name of the Renderer to use as well as the
* producer string for those renderers that can make use of it.
* @param rendererClassName classname of the renderer to use such as
* "org.apache.fop.render.pdf.PDFRenderer"
* @exception IllegalArgumentException if the classname was invalid.
* @see #setRenderer(int)
*/
public void setRenderer(String rendererClassName)
throws IllegalArgumentException {
try {
renderer =
(Renderer)Class.forName(rendererClassName).newInstance();
if (renderer instanceof LogEnabled) {
((LogEnabled)renderer).enableLogging(getLogger());
}
renderer.setProducer(Version.getVersion());
renderer.setUserAgent(getUserAgent());
} catch (ClassNotFoundException e) {
throw new IllegalArgumentException("Could not find "
+ rendererClassName);
} catch (InstantiationException e) {
throw new IllegalArgumentException("Could not instantiate "
+ rendererClassName);
} catch (IllegalAccessException e) {
throw new IllegalArgumentException("Could not access "
+ rendererClassName);
} catch (ClassCastException e) {
throw new IllegalArgumentException(rendererClassName
+ " is not a renderer");
}
}

/**
* Add the given element mapping.
* An element mapping maps element names to Java classes.
*
* @param mapping the element mappingto add
*/
public void addElementMapping(ElementMapping mapping) {
mapping.addToBuilder(treeBuilder);
}

/**
* Add the element mapping with the given class name.
* @param mappingClassName the class name representing the element mapping.
* @throws IllegalArgumentException if there was not such element mapping.
*/
public void addElementMapping(String mappingClassName)
throws IllegalArgumentException {
try {
ElementMapping mapping =
(ElementMapping)Class.forName(mappingClassName).newInstance();
addElementMapping(mapping);
} catch (ClassNotFoundException e) {
throw new IllegalArgumentException("Could not find "
+ mappingClassName);
} catch (InstantiationException e) {
throw new IllegalArgumentException("Could not instantiate "
+ mappingClassName);
} catch (IllegalAccessException e) {
throw new IllegalArgumentException("Could not access "
+ mappingClassName);
} catch (ClassCastException e) {
throw new IllegalArgumentException(mappingClassName
+ " is not an ElementMapping");
}
}

/**
* Returns the tree builder (a SAX ContentHandler).
*
* Used in situations where SAX is used but not via a FOP-invoked
* SAX parser. A good example is an XSLT engine that fires SAX
* events but isn't a SAX Parser itself.
* @return a content handler for handling the SAX events.
*/
public ContentHandler getContentHandler() {
// TODO: - do this stuff in a better way
// PIJ: I guess the structure handler should be created by the renderer.
if (rendererType == RENDER_MIF) {
structHandler = new org.apache.fop.mif.MIFHandler(stream);
} else if (rendererType == RENDER_RTF) {
structHandler = new org.apache.fop.rtf.renderer.RTFHandler(stream);
} else {
if (renderer == null) {
throw new IllegalStateException(
"Renderer not set when using standard structHandler");
}
structHandler = new LayoutHandler(stream, renderer, true);
}

structHandler.enableLogging(getLogger());

treeBuilder.setUserAgent(getUserAgent());
treeBuilder.setStructHandler(structHandler);

return treeBuilder;
}

/**
* Render the FO document read by a SAX Parser from an InputSource.
* @param parser the SAX parser.
* @param source the input source the parser reads from.
* @throws FOPException if anything goes wrong.
*/
public synchronized void render(XMLReader parser, InputSource source)
throws FOPException {
parser.setContentHandler(getContentHandler());
try {
parser.parse(source);
} catch (SAXException e) {
if (e.getException() instanceof FOPException) {
// Undo exception tunneling.
throw (FOPException)e.getException();
} else {
throw new FOPException(e);
}
} catch (IOException e) {
throw new FOPException(e);
}
}

/**
* Render the FO ducument represented by a DOM Document.
* @param document the DOM document to read from
* @throws FOPException if anything goes wrong.
*/
public synchronized void render(Document document)
throws FOPException {
try {
DocumentInputSource source = new DocumentInputSource(document);
DocumentReader reader = new DocumentReader();
reader.setContentHandler(getContentHandler());
reader.parse(source);
} catch (SAXException e) {
if (e.getException() instanceof FOPException) {
// Undo exception tunneling.
throw (FOPException)e.getException();
} else {
throw new FOPException(e);
}
} catch (IOException e) {
throw new FOPException(e);
}

}

/**
* Runs the formatting and renderering process using the previously set
* parser, input source, renderer and output stream.
* If the renderer was not set, default to PDF.
* If no parser was set, and the input source is not a dom document,
* get a default SAX parser.
* @throws IOException in case of IO errors.
* @throws FOPException if anything else goes wrong.
*/
public synchronized void run() throws IOException, FOPException {
if (renderer == null) {
setRenderer(RENDER_PDF);
}

if (source == null) {
throw new FOPException("InputSource is not set.");
}

if (reader == null) {
if (!(source instanceof DocumentInputSource)) {
try {
reader = javax.xml.parsers.SAXParserFactory.newInstance()
.newSAXParser().getXMLReader();
} catch (SAXException e) {
throw new FOPException(e);
} catch (ParserConfigurationException e) {
throw new FOPException(e);
}
}
}

if (source instanceof DocumentInputSource) {
render(((DocumentInputSource)source).getDocument());
} else {
render(reader, source);
}
}

}

// code stolen from org.apache.batik.util and modified slightly
// does what sun.misc.Service probably does, but it cannot be relied on.
// hopefully will be part of standard jdk sometime.

/**
* This class loads services present in the class path.
*/
class Service {

private static Map providerMap = new java.util.Hashtable();

public static synchronized Iterator providers(Class cls) {
ClassLoader cl = cls.getClassLoader();
// null if loaded by bootstrap class loader
if (cl == null) {
cl = ClassLoader.getSystemClassLoader();
}
String serviceFile = "META-INF/services/" + cls.getName();

// getLogger().debug("File: " + serviceFile);

List lst = (List)providerMap.get(serviceFile);
if (lst != null) {
return lst.iterator();
}

lst = new java.util.Vector();
providerMap.put(serviceFile, lst);

Enumeration e;
try {
e = cl.getResources(serviceFile);
} catch (IOException ioe) {
return lst.iterator();
}

while (e.hasMoreElements()) {
try {
java.net.URL u = (java.net.URL)e.nextElement();
//getLogger().debug("URL: " + u);

InputStream is = u.openStream();
Reader r = new InputStreamReader(is, "UTF-8");
BufferedReader br = new BufferedReader(r);

String line = br.readLine();
while (line != null) {
try {
// First strip any comment...
int idx = line.indexOf('#');
if (idx != -1) {
line = line.substring(0, idx);
}

// Trim whitespace.
line = line.trim();

// If nothing left then loop around...
if (line.length() == 0) {
line = br.readLine();
continue;
}
// getLogger().debug("Line: " + line);

// Try and load the class
// Object obj = cl.loadClass(line).newInstance();
// stick it into our vector...
lst.add(line);
} catch (Exception ex) {
// Just try the next line
}

line = br.readLine();
}
} catch (Exception ex) {
// Just try the next file...
}

}
return lst.iterator();
}

}


+ 104
- 0
src/java/org/apache/fop/apps/FOInputHandler.java View File

@@ -0,0 +1,104 @@
/*
* $Id$
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.apps;

// Imported SAX classes
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;

// java
import java.io.File;
import java.net.URL;

/**
* Manages input if it is an XSL-FO file.
*/
public class FOInputHandler extends InputHandler {
private File fofile = null;
private URL foURL = null;

/**
* Create a FOInputHandler for a file.
* @param fofile the file to read the FO document.
*/
public FOInputHandler(File fofile) {
this.fofile = fofile;
}

/**
* Create a FOInputHandler for an URL.
* @param url the URL to read the FO document.
*/
public FOInputHandler(URL url) {
this.foURL = url;
}

/**
* @see org.apache.fop.apps.InputHandler#getInputSource()
*/
public InputSource getInputSource () {
if (fofile != null) {
return super.fileInputSource(fofile);
}
return super.urlInputSource(foURL);
}

/**
* @see org.apache.fop.apps.InputHandler#getParser()
*/
public XMLReader getParser() throws FOPException {
return super.createParser();
}

}


+ 150
- 0
src/java/org/apache/fop/apps/FOPException.java View File

@@ -0,0 +1,150 @@
/*
* $Id$
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.apps;

import org.xml.sax.SAXException;

/**
* Exception thrown when FOP has a problem.
*/
public class FOPException extends Exception {

private static final String EXCEPTION_SEPARATOR = "\n---------\n";

private Throwable exception;

/**
* create a new FOP Exception
*
* @param message descriptive message
*/
public FOPException(String message) {
super(message);
}

public FOPException(Throwable e) {
super(e.getMessage());
setException(e);
}

public FOPException(String message, Throwable e) {
super(message);
setException(e);
}

protected void setException(Throwable t) {
exception = t;
}

public Throwable getException() {
return exception;
}

protected Throwable getRootException() {
Throwable result = exception;

if (result instanceof SAXException) {
result = ((SAXException)result).getException();
}
if (result instanceof java.lang.reflect.InvocationTargetException) {
result =
((java.lang.reflect.InvocationTargetException)result).getTargetException();
}
if (result != exception) {
return result;
}
return null;
}


public void printStackTrace() {
synchronized (System.err) {
super.printStackTrace();
if (exception != null) {
System.err.println(EXCEPTION_SEPARATOR);
exception.printStackTrace();
}
if (getRootException() != null) {
System.err.println(EXCEPTION_SEPARATOR);
getRootException().printStackTrace();
}
}
}

public void printStackTrace(java.io.PrintStream stream) {
synchronized (stream) {
super.printStackTrace(stream);
if (exception != null) {
stream.println(EXCEPTION_SEPARATOR);
exception.printStackTrace(stream);
}
if (getRootException() != null) {
stream.println(EXCEPTION_SEPARATOR);
getRootException().printStackTrace(stream);
}
}
}

public void printStackTrace(java.io.PrintWriter writer) {
synchronized (writer) {
super.printStackTrace(writer);
if (exception != null) {
writer.println(EXCEPTION_SEPARATOR);
exception.printStackTrace(writer);
}
if (getRootException() != null) {
writer.println(EXCEPTION_SEPARATOR);
getRootException().printStackTrace(writer);
}
}
}

}

+ 91
- 0
src/java/org/apache/fop/apps/Fop.java View File

@@ -0,0 +1,91 @@
/*
* $Id$
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.apps;

/**
* The main application class for the FOP command line interface (CLI).
*/
public class Fop {

/**
* The main routine for the command line interface
* @param args the command line parameters
*/
public static void main(String[] args) {
CommandLineOptions options = null;

try {
options = new CommandLineOptions(args);
Starter starter = options.getStarter();
starter.run();
} catch (FOPException e) {
if (e.getMessage() == null) {
System.err.println("Exception occured with a null error message");
} else {
System.err.println("" + e.getMessage());
}
if (options != null && options.getLogger().isDebugEnabled()) {
e.printStackTrace();
} else {
System.err.println("Turn on debugging for more information");
}
} catch (java.io.FileNotFoundException e) {
System.err.println("" + e.getMessage());
if (options != null && options.getLogger().isDebugEnabled()) {
e.printStackTrace();
} else {
System.err.println("Turn on debugging for more information");
}
}
}

}


+ 133
- 0
src/java/org/apache/fop/apps/InputHandler.java View File

@@ -0,0 +1,133 @@
/*
* $Id$
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.apps;

// SAX
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
import org.xml.sax.SAXException;

// Java
import javax.xml.parsers.SAXParserFactory;
import javax.xml.parsers.ParserConfigurationException;
import java.net.URL;
import java.io.File;

/**
* Abstract super class for input handlers.
* Should be used to abstract the various possibilities on how input
* can be provided to FOP (but actually isn't).
*/
public abstract class InputHandler {

/**
* Get the input source associated with this input handler.
* @return the input source
*/
public abstract InputSource getInputSource();

/**
* Get the SAX parser associated with this input handler.
* @return the SAX parser
* @throws FOPException in case of an error determining the SAX parser
*/
public abstract XMLReader getParser() throws FOPException;

/**
* Creates an InputSource from a URL.
* @param url URL to use
* @return the newly created InputSource
*/
public static InputSource urlInputSource(URL url) {
return new InputSource(url.toString());
}

/**
* Creates an <code>InputSource</code> from a <code>File</code>
* @param file the <code>File</code>
* @return the <code>InputSource</code> created
*/
public static InputSource fileInputSource(File file) {
/* this code adapted from James Clark's in XT */
String path = file.getAbsolutePath();
String fSep = System.getProperty("file.separator");
if (fSep != null && fSep.length() == 1) {
path = path.replace(fSep.charAt(0), '/');
}
if (path.length() > 0 && path.charAt(0) != '/') {
path = '/' + path;
}
try {
return new InputSource(new URL("file", null, path).toString());
} catch (java.net.MalformedURLException e) {
throw new Error("unexpected MalformedURLException");
}
}

/**
* Creates <code>XMLReader</code> object using default
* <code>SAXParserFactory</code>
* @return the created <code>XMLReader</code>
* @throws FOPException if the parser couldn't be created or configured for proper operation.
*/
protected static XMLReader createParser() throws FOPException {
try {
SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setNamespaceAware(true);
return factory.newSAXParser().getXMLReader();
} catch (SAXException se) {
throw new FOPException("Coudn't create XMLReader", se);
} catch (ParserConfigurationException pce) {
throw new FOPException("Coudn't create XMLReader", pce);
}
}
}


+ 312
- 0
src/java/org/apache/fop/apps/LayoutHandler.java View File

@@ -0,0 +1,312 @@
/*
* $Id: LayoutHandler.java,v 1.12 2003/02/27 10:13:06 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.apps;

// Java
import java.io.IOException;
import java.io.OutputStream;
import java.util.List;

// SAX
import org.xml.sax.SAXException;

// FOP
import org.apache.fop.area.AreaTree;
import org.apache.fop.area.AreaTreeModel;
import org.apache.fop.area.StorePagesModel;
import org.apache.fop.area.Title;
import org.apache.fop.area.TreeExt;
import org.apache.fop.fo.pagination.LayoutMasterSet;
import org.apache.fop.fo.pagination.PageSequence;
import org.apache.fop.layout.FontInfo;
import org.apache.fop.render.Renderer;

/**
* Layout handler that receives the structure events.
* This initiates layout processes and corresponding
* rendering processes such as start/end.
*/
public class LayoutHandler extends StructureHandler {

// TODO: Collecting of statistics should be configurable
private final boolean collectStatistics = true;
private static final boolean MEM_PROFILE_WITH_GC = false;

/**
* Somewhere to get our stats from.
*/
private Runtime runtime;

/**
* Keep track of the number of pages rendered.
*/
private int pageCount;

/**
* 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 current AreaTree for the PageSequence being rendered.
*/
private AreaTree areaTree;
private AreaTreeModel atModel;

/**
* Main constructor
* @param outputStream the stream that the result is rendered to
* @param renderer the renderer to call
* @param store if true then use the store pages model and keep the
* area tree in memory
*/
public LayoutHandler(OutputStream outputStream, Renderer renderer,
boolean store) {
if (collectStatistics) {
runtime = Runtime.getRuntime();
}
this.outputStream = outputStream;
this.renderer = renderer;

this.areaTree = new AreaTree();
this.atModel = AreaTree.createRenderPagesModel(renderer);
//this.atModel = new CachedRenderPagesModel(renderer);
areaTree.setTreeModel(atModel);
}

/**
* Get the area tree for this layout handler.
*
* @return the area tree for this document
*/
public AreaTree getAreaTree() {
return areaTree;
}

/**
* Start the document.
* This starts the document in the renderer.
*
* @throws SAXException if there is an error
*/
public void startDocument() throws SAXException {
//Initialize statistics
if (collectStatistics) {
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);
// check that the "any,normal,400" font exists
if (!fontInfo.isSetupValid()) {
throw new SAXException(new FOPException(
"No default font defined by OutputConverter"));
}
renderer.startRenderer(outputStream);
} catch (IOException e) {
throw new SAXException(e);
}
}

/**
* End the document.
*
* @throws SAXException if there is some error
*/
public void endDocument() throws SAXException {
try {
//processAreaTree(atModel);
areaTree.endDocument();
renderer.stopRenderer();
} catch (Exception e) {
throw new SAXException(e);
}

if (collectStatistics) {
if (MEM_PROFILE_WITH_GC) {
// This takes time but gives better results
System.gc();
}
long memoryNow = runtime.totalMemory() - runtime.freeMemory();
long memoryUsed = (memoryNow - initialMemory) / 1024L;
long timeUsed = System.currentTimeMillis() - startTime;
if (getLogger().isDebugEnabled()) {
getLogger().debug("Initial heap size: " + (initialMemory / 1024L) + "Kb");
getLogger().debug("Current heap size: " + (memoryNow / 1024L) + "Kb");
getLogger().debug("Total memory used: " + memoryUsed + "Kb");
if (!MEM_PROFILE_WITH_GC) {
getLogger().debug(" Memory use is indicative; no GC was performed");
getLogger().debug(" These figures should not be used comparatively");
}
getLogger().debug("Total time used: " + timeUsed + "ms");
getLogger().debug("Pages rendered: " + pageCount);
if (pageCount > 0) {
getLogger().debug("Avg render time: " + (timeUsed / pageCount) + "ms/page");
}
}
}
}

/**
* Start a page sequence.
* At the start of a page sequence it can start the page sequence
* on the area tree with the page sequence title.
*
* @param pageSeq the page sequence starting
* @param seqTitle the title of the page sequence
* @param lms the layout master set
*/
public void startPageSequence(PageSequence pageSeq,
org.apache.fop.fo.Title seqTitle,
LayoutMasterSet lms) {
Title title = null;
if (seqTitle != null) {
title = seqTitle.getTitleArea();
}
areaTree.startPageSequence(title);
}

/**
* End the PageSequence.
* The PageSequence formats Pages and adds them to the AreaTree.
* The area tree then handles what happens with the pages.
*
* @param pageSequence the page sequence ending
* @throws FOPException if there is an error formatting the pages
*/
public void endPageSequence(PageSequence pageSequence)
throws FOPException {
//areaTree.setFontInfo(fontInfo);

if (collectStatistics) {
if (MEM_PROFILE_WITH_GC) {
// This takes time but gives better results
System.gc();
}
long memoryNow = runtime.totalMemory() - runtime.freeMemory();
if (getLogger().isDebugEnabled()) {
getLogger().debug("Current heap size: " + (memoryNow / 1024L) + "Kb");
}
}
pageSequence.format(areaTree);
}

/**
* Process an area tree.
* If a store pages model is used this can read and send all the
* pages to the renderer.
*
* @param model the store pages model
* @throws FOPException if there is an error
*/
private void processAreaTree(StorePagesModel model) throws FOPException {
int count = 0;
int seqc = model.getPageSequenceCount();
while (count < seqc) {
Title title = model.getTitle(count);
renderer.startPageSequence(title);
int pagec = model.getPageCount(count);
for (int c = 0; c < pagec; c++) {
try {
renderer.renderPage(model.getPage(count, c));
} catch (IOException ioex) {
throw new FOPException("I/O Error rendering page",
ioex);
}
}
count++;
}
List list = model.getEndExtensions();
for (count = 0; count < list.size(); count++) {
TreeExt ext = (TreeExt)list.get(count);
renderer.renderExtension(ext);
}
}

/**
* Get the font information for the layout handler.
*
* @return the font information
*/
public FontInfo getFontInfo() {
return this.fontInfo;
}
}


+ 239
- 0
src/java/org/apache/fop/apps/PrintStarter.java View File

@@ -0,0 +1,239 @@
/*
* $Id: PrintStarter.java,v 1.14 2003/02/27 10:13:06 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.apps;

/*
* originally contributed by
* Stanislav Gorkhover: stanislav.gorkhover@jcatalog.com
* jCatalog Software AG
*
* Updated by Mark Lillywhite, mark-fop@inomial.com. Modified to
* handle the print job better, added -Ddialog option, removed
* (apparently) redundant copies code, generally cleaned up, and
* added interfaces to the new Render API.
*/


import org.xml.sax.XMLReader;

import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;
import java.io.OutputStream;
import java.io.IOException;
import java.util.Vector;

import org.apache.fop.render.awt.AWTRenderer;

/**
* This class prints a XSL-FO dokument without interaction.
* At the moment java has not the possibility to configure the printer and it's
* options without interaction (30.03.2000).
* This class allows to print a set of pages (from-to), even/odd pages and many copies.
* - Print from page xxx: property name - start, value int
* - Print to page xxx: property name - end, value int
* - Print even/odd pages: property name - even, value boolean
* - Print xxx copies: property name - copies, value int
*/
public class PrintStarter extends CommandLineStarter {

/**
* @see org.apache.fop.apps.CommandLineStarter#CommandLineStarter(CommandLineOptions)
*/
public PrintStarter(CommandLineOptions options) throws FOPException {
super(options);
}

/**
* @see org.apache.fop.apps.Starter#run()
*/
public void run() throws FOPException {
Driver driver = new Driver();

String version = Version.getVersion();
//log.debug(version);

XMLReader parser = inputHandler.getParser();

setParserFeatures(parser);

PrinterJob pj = PrinterJob.getPrinterJob();
if (System.getProperty("dialog") != null) {
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());
} catch (Exception e) {
if (e instanceof FOPException) {
throw (FOPException)e;
}
throw new FOPException(e);
}

System.exit(0);
}
int getIntProperty(String name, int def) {
String propValue = System.getProperty(name);
if (propValue != null) {
try {
return Integer.parseInt(propValue);
} catch (Exception e) {
return def;
}
} else {
return def;
}
}

class PrintRenderer extends AWTRenderer {

private static final int EVEN_AND_ALL = 0;
private static final int EVEN = 1;
private static final int ODD = 2;

private int startNumber;
private int endNumber;
private int mode = EVEN_AND_ALL;
private int copies = 1;
private PrinterJob printerJob;

PrintRenderer(PrinterJob printerJob) {
super(null);

this.printerJob = printerJob;
startNumber = getIntProperty("start", 1) - 1;
endNumber = getIntProperty("end", -1);

printerJob.setPageable(this);

mode = EVEN_AND_ALL;
String str = System.getProperty("even");
if (str != null) {
mode = Boolean.valueOf(str).booleanValue() ? EVEN : ODD;
}

}

public void stopRenderer(OutputStream outputStream)
throws IOException {
super.stopRenderer();

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());
}
}

/*public void renderPage(Page page) {
pageWidth = (int)((float)page.getWidth() / 1000f);
pageHeight = (int)((float)page.getHeight() / 1000f);
}*/

private Vector getInvalidPageNumbers() {

Vector vec = new Vector();
int max = getPageCount();
boolean isValid;
for (int i = 0; i < max; i++) {
isValid = true;
if (i < startNumber || i > endNumber) {
isValid = false;
} else if (mode != EVEN_AND_ALL) {
if (mode == EVEN && ((i + 1) % 2 != 0)) {
isValid = false;
} else if (mode == ODD && ((i + 1) % 2 != 1)) {
isValid = false;
}
}

if (!isValid) {
vec.add(i + "");
}
}

return vec;
}

/* TODO: I'm totally not sure that this is necessary -Mark
void setCopies(int val) {
copies = val;
Vector copie = tree.getPages();
for (int i = 1; i < copies; i++) {
tree.getPages().addAll(copie);
}

}
*/
} // class PrintRenderer
} // class PrintCommandLine


+ 107
- 0
src/java/org/apache/fop/apps/Starter.java View File

@@ -0,0 +1,107 @@
/*
* $Id: Starter.java,v 1.12 2003/02/27 10:13:07 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.apps;

// Avalon
import org.apache.avalon.framework.logger.AbstractLogEnabled;

// SAX
import org.xml.sax.XMLReader;
import org.xml.sax.SAXException;

/**
* Abstract super class.
* Creates a SAX Parser (defaulting to Xerces).
*/
public abstract class Starter extends AbstractLogEnabled {

/** InputHandler associated with this Starter */
protected InputHandler inputHandler;

/**
* Main constructor
* @throws FOPException In case of a problem constructing the Starter
*/
public Starter() throws FOPException {
}

/**
* Sets the InputHandler to use.
* @param inputHandler input handler
*/
public void setInputHandler(InputHandler inputHandler) {
this.inputHandler = inputHandler;
}

/**
* Runs the current setup.
* @throws FOPException In case of a problem during the FOP run
*/
public abstract void run() throws FOPException;

/**
* Sets the parser features on an XMLReader
* @param parser XMLReader to set features on
* @throws FOPException if the XMLReader doesn't support the feature that
* need to be set
*/
public void setParserFeatures(XMLReader parser) throws FOPException {
try {
parser.setFeature("http://xml.org/sax/features/namespace-prefixes",
true);
} catch (SAXException e) {
throw new FOPException("Error: You need a parser which allows the"
+ " http://xml.org/sax/features/namespace-prefixes"
+ " feature to be set to true to support namespaces", e);
}
}

}

+ 295
- 0
src/java/org/apache/fop/apps/StructureHandler.java View File

@@ -0,0 +1,295 @@
/*
* $Id: StructureHandler.java,v 1.7 2003/02/27 10:13:07 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.apps;

// Java
import java.util.Set;
import java.util.HashSet;

// Avalon
import org.apache.avalon.framework.logger.AbstractLogEnabled;

// FOP
import org.apache.fop.fo.Title;
import org.apache.fop.fo.flow.Block;
import org.apache.fop.fo.flow.ExternalGraphic;
import org.apache.fop.fo.flow.Flow;
import org.apache.fop.fo.flow.InstreamForeignObject;
import org.apache.fop.fo.flow.Leader;
import org.apache.fop.fo.flow.ListBlock;
import org.apache.fop.fo.flow.ListItem;
import org.apache.fop.fo.flow.Table;
import org.apache.fop.fo.flow.TableBody;
import org.apache.fop.fo.flow.TableCell;
import org.apache.fop.fo.flow.TableRow;
import org.apache.fop.fo.pagination.LayoutMasterSet;
import org.apache.fop.fo.pagination.PageSequence;
import org.apache.fop.layout.FontInfo;

import org.xml.sax.SAXException;

/**
* This class receives structure events from the FO Tree.
* Sub-classes can then implement various methods to handle
* the FO Tree when the SAX events occur.
*/
public class StructureHandler extends AbstractLogEnabled {
/**
* The current set of id's in the FO tree.
* This is used so we know if the FO tree contains duplicates.
*/
private Set idReferences = new HashSet();

/**
* Main constructor
*/
public StructureHandler() {
}

/**
* Retuns the set of ID references.
* @return the ID references
*/
public Set getIDReferences() {
return idReferences;
}

/**
* Returns the FontInfo object associated with this StructureHandler.
* @return the FontInof object
*/
public FontInfo getFontInfo() {
return null;
}

/**
* This method is called to indicate the start of a new document run.
* @throws SAXException In case of a problem
*/
public void startDocument() throws SAXException {
}

/**
* This method is called to indicate the end of a document run.
* @throws SAXException In case of a problem
*/
public void endDocument() throws SAXException {
}

public void startPageSequence(PageSequence pageSeq, Title seqTitle, LayoutMasterSet lms) {

}

public void endPageSequence(PageSequence pageSeq) throws FOPException {

}

public void startFlow(Flow fl) {

}

public void endFlow(Flow fl) {

}

public void startBlock(Block bl) {

}

public void endBlock(Block bl) {

}


// Tables
public void startTable(Table tbl) {

}

public void endTable(Table tbl) {

}

public void startHeader(TableBody th) {

}

public void endHeader(TableBody th) {

}

public void startFooter(TableBody tf) {

}

public void endFooter(TableBody tf) {

}

public void startBody(TableBody tb) {

}

public void endBody(TableBody tb) {

}

public void startRow(TableRow tr) {

}

public void endRow(TableRow tr) {

}

public void startCell(TableCell tc) {

}

public void endCell(TableCell tc) {

}


// Lists
public void startList(ListBlock lb) {

}

public void endList(ListBlock lb) {

}

public void startListItem(ListItem li) {

}

public void endListItem(ListItem li) {

}

public void startListLabel() {

}

public void endListLabel() {

}

public void startListBody() {

}

public void endListBody() {

}


// Static Regions
public void startStatic() {

}

public void endStatic() {

}


public void startMarkup() {

}

public void endMarkup() {

}


public void startLink() {

}

public void endLink() {

}


public void image(ExternalGraphic eg) {

}

public void pageRef() {

}

public void foreignObject(InstreamForeignObject ifo) {

}

public void footnote() {

}

public void leader(Leader l) {

}


public void characters(char data[], int start, int length) {

}

public void pageBreak() {

}


}


+ 152
- 0
src/java/org/apache/fop/apps/TraxInputHandler.java View File

@@ -0,0 +1,152 @@
/*
* $Id: TraxInputHandler.java,v 1.6 2003/02/27 10:13:04 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.apps;

// Imported java.io classes
import java.io.File;

// Imported TraX classes
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamSource;
import javax.xml.transform.sax.SAXResult;
import javax.xml.transform.sax.SAXSource;
import javax.xml.transform.sax.SAXTransformerFactory;

// Imported SAX classes
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
import org.xml.sax.XMLFilter;

/**
* XSLTInputHandler basically takes an XML file and transforms it with an
* XSLT file and the resulting XSL-FO document is input for FOP.
*/
public class TraxInputHandler extends InputHandler {

private File xmlfile, xsltfile;

/**
* Main constructor
* @param xmlfile XML file
* @param xsltfile XSLT file
*/
public TraxInputHandler(File xmlfile, File xsltfile) {
this.xmlfile = xmlfile;
this.xsltfile = xsltfile;
}

/**
* @see org.apache.fop.apps.InputHandler#getInputSource()
*/
public InputSource getInputSource() {
return fileInputSource(xmlfile);
}

/**
* Overwrites this method of the super class and returns an XMLFilter
* instead of a simple XMLReader which allows chaining of transformations.
* @see org.apache.fop.apps.InputHandler#getParser()
*/
public XMLReader getParser() throws FOPException {
return this.getXMLFilter(xmlfile, xsltfile);
}

/**
* Creates from the transformer an instance of an XMLFilter which
* then can be used in a chain with the XMLReader passed to Driver. This way
* during the conversion of the xml file + xslt stylesheet the resulting
* data is fed into Fop. This should help to avoid memory problems
* @param xmlfile The xmlfile containing the text data
* @param xsltfile An xslt stylesheet
* @return an XMLFilter which can be chained together with other
* XMLReaders or XMLFilters
* @throws FOPException if setting up the XMLFilter fails
*/
public static XMLFilter getXMLFilter(File xmlfile,
File xsltfile) throws FOPException {
try {
// Instantiate a TransformerFactory.
TransformerFactory tFactory = TransformerFactory.newInstance();
// Determine whether the TransformerFactory supports The use uf SAXSource
// and SAXResult
if (tFactory.getFeature(SAXSource.FEATURE)
&& tFactory.getFeature(SAXResult.FEATURE)) {
// Cast the TransformerFactory to SAXTransformerFactory.
SAXTransformerFactory saxTFactory =
((SAXTransformerFactory)tFactory);
// Create an XMLFilter for each stylesheet.
XMLFilter xmlfilter =
saxTFactory.newXMLFilter(new StreamSource(xsltfile));

// Create an XMLReader.
XMLReader parser = createParser();
if (parser == null) {
throw new FOPException("Unable to create SAX parser");
}

// xmlFilter1 uses the XMLReader as its reader.
xmlfilter.setParent(parser);
return xmlfilter;
} else {
throw new FOPException("Your parser doesn't support the "
+ "features SAXSource and SAXResult."
+ "\nMake sure you are using an XSLT engine which "
+ "supports TrAX");
}
} catch (FOPException fe) {
throw fe;
} catch (Exception ex) {
throw new FOPException(ex);
}
}

}


+ 67
- 0
src/java/org/apache/fop/apps/Version.java View File

@@ -0,0 +1,67 @@
/*
* $Id: Version.java,v 1.18 2003/02/27 10:13:06 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.apps;

/**
* Class representing the version of FOP.
*/
public class Version {

/**
* Get the version of FOP
*
* @return the version string
*/
public static String getVersion() {
return "1.0dev";
}

}

+ 182
- 0
src/java/org/apache/fop/apps/XSLTInputHandler.java View File

@@ -0,0 +1,182 @@
/*
* $Id: XSLTInputHandler.java,v 1.10 2003/02/27 10:13:05 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.apps;

// Imported java.io classes
import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

// Imported SAX classes
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;

// FOP
import org.apache.fop.tools.xslt.XSLTransform;

/**
* XSLTInputHandler basically takes an XML file and transforms it with an XSLT
* file and the resulting XSL-FO document is input for FOP.
* @todo add URL constructor
*/
public class XSLTInputHandler extends InputHandler {

private File xmlfile, xsltfile;
private boolean useOldTransform = false;
private boolean gotParser = false;

/**
* Main constructor
* @param xmlfile XML file
* @param xsltfile XSLT file
*/
public XSLTInputHandler(File xmlfile, File xsltfile) {
this.xmlfile = xmlfile;
this.xsltfile = xsltfile;
}

/**
* @see org.apache.fop.apps.InputHandler#getInputSource()
*/
public InputSource getInputSource() {
if (!gotParser) {
throw new IllegalStateException("The method getParser() must be "
+ "called and the parser used when using XSLTInputHandler");
}
if (useOldTransform) {
try {
java.io.Writer writer;
java.io.Reader reader;
File tmpFile = null;

// create a Writer
// the following is an ugly hack to allow processing of larger files
// if xml file size is larger than 500 kb write the fo:file to disk
if ((xmlfile.length()) > 500000) {
tmpFile = new File(xmlfile.getName() + ".fo.tmp");
writer = new java.io.FileWriter(tmpFile);
} else {
writer = new java.io.StringWriter();
}

XSLTransform.transform(xmlfile.getCanonicalPath(),
xsltfile.getCanonicalPath(), writer);

writer.flush();
writer.close();

if (tmpFile != null) {
reader = new java.io.FileReader(tmpFile);
} else {
// create a input source containing the xsl:fo file which can be fed to Fop
reader = new java.io.StringReader(writer.toString());
}
return new InputSource(reader);
} catch (Exception ex) {
ex.printStackTrace();
/**@todo do proper logging of exceptions */
return null;
}
} else {
return fileInputSource(xmlfile);
}

}

/**
* This looks to see if the Trax api is supported and uses that to
* get an XMLFilter. Otherwise, it falls back to using DOM documents
* @return the created <code>XMLReader</code>
* @throws FOPException if getting the parser fails
* @see org.apache.fop.apps.InputHandler#getParser()
*/
public XMLReader getParser() throws FOPException {
gotParser = true;

XMLReader result = null;
try {
// try trax first
Class transformer =
Class.forName("javax.xml.transform.Transformer");
transformer =
Class.forName("org.apache.fop.apps.TraxInputHandler");
Class[] argTypes = {
File.class, File.class
};
Method getFilterMethod = transformer.getMethod("getXMLFilter",
argTypes);
File[] args = {
xmlfile, xsltfile
};
Object obj = getFilterMethod.invoke(null, args);
if (obj instanceof XMLReader) {
result = (XMLReader)obj;
}
} catch (ClassNotFoundException ex) {
throw new FOPException(ex);
} catch (InvocationTargetException ex) {
throw new FOPException(ex);
} catch (IllegalAccessException ex) {
throw new FOPException(ex);
} catch (NoSuchMethodException ex) {
throw new FOPException(ex);
}
// otherwise, use DOM documents via our XSLTransform tool class old style
if (result == null) {
useOldTransform = true;
result = createParser();
}
return result;

}

}


+ 7
- 0
src/java/org/apache/fop/apps/package.html View File

@@ -0,0 +1,7 @@
<HTML>
<TITLE>org.apache.fop.apps Package</TITLE>
<BODY>
<P>Application classes used for running FOP both on the command line and
embedded in other applications.</P>
</BODY>
</HTML>

+ 265
- 0
src/java/org/apache/fop/area/Area.java View File

@@ -0,0 +1,265 @@
/*
* $Id: Area.java,v 1.16 2003/03/05 15:19:31 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.area;

import java.io.Serializable;

import java.util.Map;
import java.util.HashMap;

// If the area appears more than once in the output
// or if the area has external data it is cached
// to keep track of it and to minimize rendered output
// renderers can render the output once and display it
// for every occurence
// this should also extend to all outputs (including PDFGraphics2D)
// and all types of renderers

/**
* Base object for all areas.
*/
public class Area implements Serializable {
// stacking directions
/**
* Stacking left to right
*/
public static final int LR = 0;

/**
* Stacking right to left
*/
public static final int RL = 1;

/**
* Stacking top to bottom
*/
public static final int TB = 2;

/**
* Stacking bottom to top
*/
public static final int BT = 3;

// orientations for reference areas
/**
* Normal orientation
*/
public static final int ORIENT_0 = 0;

/**
* Rotated 90 degrees clockwise
*/
public static final int ORIENT_90 = 1;

/**
* Rotate 180 degrees
*/
public static final int ORIENT_180 = 2;

/**
* Rotated 270 degrees clockwise
*/
public static final int ORIENT_270 = 3;

// area class values

/**
* Normal class
*/
public static final int CLASS_NORMAL = 0;

/**
* Fixed position class
*/
public static final int CLASS_FIXED = 1;

/**
* Absolute position class
*/
public static final int CLASS_ABSOLUTE = 2;

/**
* Before float class
*/
public static final int CLASS_BEFORE_FLOAT = 3;

/**
* Footnote class
*/
public static final int CLASS_FOOTNOTE = 4;

/**
* Side float class
*/
public static final int CLASS_SIDE_FLOAT = 5;

// IMPORTANT: make sure this is the maximum + 1
/**
* Maximum class count
*/
public static final int CLASS_MAX = CLASS_SIDE_FLOAT + 1;

private int areaClass = CLASS_NORMAL;
private int ipd;

/**
* Traits for this area stored in a HashMap
*/
protected HashMap props = null;

/**
* Get the area class of this area.
*
* @return the area class
*/
public int getAreaClass() {
return areaClass;
}

/**
* Set the area class of this area.
*
* @param areaClass the area class
*/
public void setAreaClass(int areaClass) {
this.areaClass = areaClass;
}

/**
* Set the inline progression dimension of this area.
*
* @param i the new inline progression dimension
*/
public void setIPD(int i) {
ipd = i;
}

/**
* Get the inline progression dimension of this area.
*
* @return the inline progression dimension
*/
public int getIPD() {
return ipd;
}

/**
* Add a child to this area.
* The default is to do nothing. Subclasses must override
* to do something if they can have child areas.
*
* @param child the child area to add
*/
public void addChild(Area child) {
}

/**
* Add a trait property to this area.
*
* @param prop the Trait to add
*/
public void addTrait(Trait prop) {
if (props == null) {
props = new java.util.HashMap(20);
}
props.put(prop.getPropType(), prop.getData());
}

/**
* Add a trait to this area.
*
* @param traitCode the trait key
* @param prop the value of the trait
*/
public void addTrait(Object traitCode, Object prop) {
if (props == null) {
props = new java.util.HashMap(20);
}
props.put(traitCode, prop);
}

/**
* Get the map of all traits on this area.
*
* @return the map of traits
*/
public Map getTraits() {
return this.props;
}

/**
* Get a trait from this area.
*
* @param oTraitCode the trait key
* @return the trait value
*/
public Object getTrait(Object oTraitCode) {
return (props != null ? props.get(oTraitCode) : null);
}
/**
* Get a trait from this area as an integer.
*
* @param oTraitCode the trait key
* @return the trait value
*/
public int getTraitAsInteger(Object oTraitCode) {
final Object obj = getTrait(oTraitCode);
if (obj instanceof Integer) {
return ((Integer)obj).intValue();
} else {
throw new IllegalArgumentException("Trait "
+ oTraitCode.getClass().getName()
+ " could not be converted to an integer");
}
}
}


+ 248
- 0
src/java/org/apache/fop/area/AreaTree.java View File

@@ -0,0 +1,248 @@
/*
* $Id: AreaTree.java,v 1.16 2003/03/05 15:19:31 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.area;

import org.apache.fop.render.Renderer;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.util.Set;
import java.util.HashSet;
import java.util.Iterator;

/**
* Area tree for formatting objects.
*
* Concepts:
* The area tree is to be as small as possible. With minimal classes
* and data to fully represent an area tree for formatting objects.
* The area tree needs to be simple to render and follow the spec
* closely.
* This area tree has the concept of page sequences.
* Where ever possible information is discarded or optimised to
* keep memory use low. The data is also organised to make it
* possible for renderers to minimise their output.
* A page can be saved if not fully resolved and once rendered
* a page contains only size and id reference information.
* The area tree pages are organised in a model that depends on the
* type of renderer.
*/
public class AreaTree {
// allows for different models to deal with adding/rendering
// in different situations
private AreaTreeModel model;

// hashmap of arraylists containing pages with id area
private Map idLocations = new HashMap();
// list of id's yet to be resolved and arraylists of pages
private Map resolve = new HashMap();
private List treeExtensions = new ArrayList();

/**
* Create a render pages area tree model.
* @param rend the renderer that will be used
* @return RenderPagesModel the new area tree model
*/
public static RenderPagesModel createRenderPagesModel(Renderer rend) {
return new RenderPagesModel(rend);
}

/**
* Create a new store pages model.
* @return StorePagesModel the new model
*/
public static StorePagesModel createStorePagesModel() {
return new StorePagesModel();
}

/**
* Set the tree model to use for this area tree.
* The different models can have different behaviour
* when pages area added and other changes.
* @param m the area tree model
*/
public void setTreeModel(AreaTreeModel m) {
model = m;
}

/**
* Get the area tree model for this area tree.
*
* @return AreaTreeModel the model being used for this area tree
*/
public AreaTreeModel getAreaTreeModel() {
return model;
}

/**
* Start a new page sequence.
* This signals that a new page sequence has started in the document.
* @param title the title of the new page sequence or null if no title
*/
public void startPageSequence(Title title) {
model.startPageSequence(title);
}

/**
* Add a new page to the area tree.
* @param page the page to add
*/
public void addPage(PageViewport page) {
model.addPage(page);
}

/**
* Add an id reference pointing to a page viewport.
* @param id the id of the reference
* @param pv the page viewport that contains the id reference
*/
public void addIDRef(String id, PageViewport pv) {
List list = (List)idLocations.get(id);
if (list == null) {
list = new ArrayList();
idLocations.put(id, list);
}
list.add(pv);

Set todo = (Set)resolve.get(id);
if (todo != null) {
for (Iterator iter = todo.iterator(); iter.hasNext();) {
Resolveable res = (Resolveable)iter.next();
res.resolve(id, list);
}
resolve.remove(id);
}
}

/**
* Get the list of id references for an id.
* @param id the id to lookup
* @return the list of id references.
*/
public List getIDReferences(String id) {
return (List)idLocations.get(id);
}

/**
* Add an unresolved object with a given id.
* @param id the id reference that needs resolving
* @param res the Resolveable object to resolve
*/
public void addUnresolvedID(String id, Resolveable res) {
Set todo = (Set)resolve.get(id);
if (todo == null) {
todo = new HashSet();
resolve.put(id, todo);
}
todo.add(res);
}

/**
* Add a tree extension.
* This checks if the extension is resolveable and attempts
* to resolve or add the resolveable ids for later resolution.
* @param ext the tree extension to add.
*/
public void addTreeExtension(TreeExt ext) {
treeExtensions.add(ext);
if (ext.isResolveable()) {
Resolveable res = (Resolveable)ext;
String[] ids = res.getIDs();
for (int count = 0; count < ids.length; count++) {
if (idLocations.containsKey(ids[count])) {
res.resolve(ids[count], (List)idLocations.get(ids[count]));
} else {
Set todo = (Set)resolve.get(ids[count]);
if (todo == null) {
todo = new HashSet();
resolve.put(ids[count], todo);
}
todo.add(ext);
}
}
} else {
handleTreeExtension(ext, TreeExt.IMMEDIATELY);
}
}

/**
* Handle a tree extension.
* This sends the extension to the model for handling.
* @param ext the tree extension to handle
* @param when when the extension should be handled by the model
*/
public void handleTreeExtension(TreeExt ext, int when) {
// queue tree extension according to the when
model.addExtension(ext, when);
}

/**
* Signal end of document.
* This indicates that the document is complete and any unresolved
* reference can be dealt with.
*/
public void endDocument() {
for (Iterator iter = resolve.keySet().iterator(); iter.hasNext();) {
String id = (String)iter.next();
Set list = (Set)resolve.get(id);
for (Iterator resIter = list.iterator(); resIter.hasNext();) {
Resolveable res = (Resolveable)resIter.next();
if (!res.isResolved()) {
res.resolve(id, null);
}
}
}
model.endDocument();
}
}


+ 114
- 0
src/java/org/apache/fop/area/AreaTreeModel.java View File

@@ -0,0 +1,114 @@
/*
* $Id: AreaTreeModel.java,v 1.4 2003/03/05 15:19:31 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.area;

/**
* This is the model for the area tree object.
* The model implementation can handle the page sequence,
* page and extensions.
* The mathods to acces the page viewports can only
* assume the PageViewport is valid as it remains for
* the life of the area tree model.
*/
public abstract class AreaTreeModel {
/**
* Start a page sequence on this model.
* @param title the title of the new page sequence
*/
public abstract void startPageSequence(Title title);

/**
* Add a page to this moel.
* @param page the page to add to the model.
*/
public abstract void addPage(PageViewport page);

/**
* Add an extension to this model.
* @param ext the extension to add
* @param when when the extension should be handled
*/
public abstract void addExtension(TreeExt ext, int when);

/**
* Signal the end of the document for any processing.
*/
public abstract void endDocument();

/**
* Get the page sequence count.
* @return the number of page sequences in the document.
*/
public abstract int getPageSequenceCount();

/**
* Get the title for a page sequence.
* @param count the page sequence count
* @return the title of the page sequence
*/
public abstract Title getTitle(int count);

/**
* Get the page count.
* @param seq the page sequence to count.
* @return returns the number of pages in a page sequence
*/
public abstract int getPageCount(int seq);

/**
* Get the page for a position in the document.
* @param seq the page sequence number
* @param count the page count in the sequence
* @return the PageViewport for the particular page
*/
public abstract PageViewport getPage(int seq, int count);

}

+ 97
- 0
src/java/org/apache/fop/area/BeforeFloat.java View File

@@ -0,0 +1,97 @@
/*
* $Id: BeforeFloat.java,v 1.5 2003/03/05 15:19:31 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.area;

/**
* The before float area.
* This is used to place the before float areas.
* It has an optional separator and before float block children.
*/
public class BeforeFloat extends BlockParent {
// this is an optional block area that will be rendered
// as the separator only if there are float areas
private Block separator = null;

/**
* Set the separator area for this before float.
*
* @param sep the before float separator area
*/
public void setSeparator(Block sep) {
separator = sep;
}

/**
* Get the separator area for this before float.
*
* @return the before float separator area
*/
public Block getSeparator() {
return separator;
}

/**
* Get the height of this before float.
* It gets the height of the children and if there is a
* separator its height is also added.
*
* @return the height of the before float including separator
*/
public int getHeight() {
int h = super.getHeight();
if (separator != null) {
h += separator.getHeight();
}
return h;
}

}


+ 135
- 0
src/java/org/apache/fop/area/Block.java View File

@@ -0,0 +1,135 @@
/*
* $Id: Block.java,v 1.12 2003/03/05 15:19:31 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.area;

import java.util.ArrayList;

// block areas hold either more block areas or line
// areas can also be used as a block spacer
// a block area may have children positioned by stacking
// or by relative to the parent for floats, tables and lists
// cacheable object
// has id information

/**
* This is the block area class.
* It holds child block areas such as other blocks or lines.
*/
public class Block extends BlockParent {
/**
* Normally stacked with other blocks.
*/
public static final int STACK = 0;

/**
* Placed relative to the flow position.
* This effects the flow placement of stacking normally.
*/
public static final int RELATIVE = 1;

/**
* Relative to the block parent but not effecting the stacking
* Used for block-container, tables and lists.
*/
public static final int ABSOLUTE = 2;

private int stacking = TB;
private int positioning = STACK;

// a block with may contain the dominant styling info in
// terms of most lines or blocks with info

/**
* Add the block to this block area.
*
* @param block the block area to add
*/
public void addBlock(Block block) {
if (children == null) {
children = new ArrayList();
}
height += block.getHeight();
children.add(block);
}

/**
* Add the line area to this block area.
*
* @param line the line area to add
*/
public void addLineArea(LineArea line) {
if (children == null) {
children = new ArrayList();
}
height += line.getHeight();
children.add(line);
}

/**
* Set the positioning of this area.
*
* @param pos the positioning to use when rendering this area
*/
public void setPositioning(int pos) {
positioning = pos;
}

/**
* Get the positioning of this area.
*
* @return the positioning to use when rendering this area
*/
public int getPositioning() {
return positioning;
}

}


+ 188
- 0
src/java/org/apache/fop/area/BlockParent.java View File

@@ -0,0 +1,188 @@
/*
* $Id: BlockParent.java,v 1.7 2003/03/05 15:19:31 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.area;

import java.util.ArrayList;
import java.util.List;

/**
* A BlockParent holds block-level areas.
*/
public class BlockParent extends Area {

// this position is used for absolute position
// or as an indent
// this has the size in the block progression dimension

/**
* The x offset position of this block parent.
* Used for relative and absolute positioning.
*/
protected int xOffset = 0;

/**
* The y offset position of this block parent.
* Used for relative and absolute positioning.
*/
protected int yOffset = 0;

/**
* The width of this block parent.
*/
protected int width = 0;

/**
* The height of this block parent.
*/
protected int height = 0;

/**
* The children of this block parent area.
*/
protected List children = null;

// orientation if reference area
private int orientation = ORIENT_0;

/**
* Add the block area to this block parent.
*
* @param block the child block area to add
*/
public void addBlock(Block block) {
if (children == null) {
children = new ArrayList();
}
children.add(block);
}

/**
* Get the list of child areas for this block area.
*
* @return the list of child areas
*/
public List getChildAreas() {
return children;
}

/**
* Set the X offset of this block parent area.
*
* @param off the x offset of the block parent area
*/
public void setXOffset(int off) {
xOffset = off;
}

/**
* Set the Y offset of this block parent area.
*
* @param off the y offset of the block parent area
*/
public void setYOffset(int off) {
yOffset = off;
}

/**
* Set the width of this block parent area.
*
* @param w the width of the area
*/
public void setWidth(int w) {
width = w;
}

/**
* Set the height of this block parent area.
*
* @param h the height of the block parent area
*/
public void setHeight(int h) {
height = h;
}

/**
* Get the X offset of this block parent area.
*
* @return the x offset of the block parent area
*/
public int getXOffset() {
return xOffset;
}

/**
* Get the Y offset of this block parent area.
*
* @return the y offset of the block parent area
*/
public int getYOffset() {
return yOffset;
}

/**
* Get the width of this block parent area.
*
* @return the width of the area
*/
public int getWidth() {
return width;
}

/**
* Get the height of this block parent area.
*
* @return the height of the block parent area
*/
public int getHeight() {
return height;
}

}

+ 110
- 0
src/java/org/apache/fop/area/BlockViewport.java View File

@@ -0,0 +1,110 @@
/*
* $Id: BlockViewport.java,v 1.3 2003/03/05 15:19:31 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.area;

/**
* A BlockViewport.
* This is used for block level Viewport/reference pairs.
* The block-container creates this area.
*/
public class BlockViewport extends Block {
// clipping for this viewport
private boolean clip = false;
// transform if rotated or absolute
private CTM viewportCTM;

/**
* Create a new block viewport area.
*/
public BlockViewport() {
}

/**
* Set the transform of this viewport.
* If the viewport is rotated or has an absolute positioning
* this transform will do the work.
*
* @param ctm the transformation
*/
public void setCTM(CTM ctm) {
viewportCTM = ctm;
}

/**
* Get the transform of this block viewport.
*
* @return the transformation of this viewport
* or null if normally stacked without rotation
*/
public CTM getCTM() {
return viewportCTM;
}

/**
* Set the clipping for this viewport.
*
* @param cl the clipping for the viewport
*/
public void setClip(boolean cl) {
clip = cl;
}

/**
* Get the clipping for this viewport.
*
* @return the clipping for the viewport
* true if the contents should be clipped for this viewport
*/
public boolean getClip() {
return clip;
}
}


+ 173
- 0
src/java/org/apache/fop/area/BodyRegion.java View File

@@ -0,0 +1,173 @@
/*
* $Id: BodyRegion.java,v 1.9 2003/03/05 15:19:31 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.area;

/**
* The body region area.
* This area contains a main reference area and optionally a
* before float and footnote area.
*/
public class BodyRegion extends RegionReference {
private BeforeFloat beforeFloat;
private MainReference mainReference;
private Footnote footnote;
private int columnGap;
private int columnCount;

/** Reference inline progression dimension for the body. */
private int refIPD;

/**
* Create a new body region area.
* This sets the region reference area class to BODY.
*/
public BodyRegion() {
super(BODY);
}

/**
* Set the number of columns for blocks when not spanning
*
* @param colCount the number of columns
*/
public void setColumnCount(int colCount) {
this.columnCount = colCount;
}

/**
* Get the number of columns when not spanning
*
* @return the number of columns
*/
public int getColumnCount() {
return this.columnCount;
}

/**
* Set the column gap between columns
* The length is in millipoints.
*
* @param colGap the column gap in millipoints
*/
public void setColumnGap(int colGap) {
this.columnGap = colGap;
}

/**
* Set the before float area.
*
* @param bf the before float area
*/
public void setBeforeFloat(BeforeFloat bf) {
beforeFloat = bf;
}

/**
* Set the main reference area.
*
* @param mr the main reference area
*/
public void setMainReference(MainReference mr) {
mainReference = mr;
}

/**
* Set the footnote area.
*
* @param foot the footnote area
*/
public void setFootnote(Footnote foot) {
footnote = foot;
}

/**
* Get the before float area.
*
* @return the before float area
*/
public BeforeFloat getBeforeFloat() {
return beforeFloat;
}

/**
* Get the main reference area.
*
* @return the main reference area
*/
public MainReference getMainReference() {
return mainReference;
}

/**
* Get the footnote area.
*
* @return the footnote area
*/
public Footnote getFootnote() {
return footnote;
}

/**
* Clone this object.
* This is only used to clone the current object, the child areas
* are assumed to be null and are not cloned.
*
* @return a shallow copy of this object
*/
public Object clone() {
BodyRegion br = new BodyRegion();
br.setCTM(getCTM());
br.setIPD(getIPD());
br.columnGap = columnGap;
br.columnCount = columnCount;
return br;
}
}

+ 282
- 0
src/java/org/apache/fop/area/CTM.java View File

@@ -0,0 +1,282 @@
/*
* $Id: CTM.java,v 1.8 2003/03/05 15:19:31 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.area;

import java.awt.geom.Rectangle2D;
import java.awt.Rectangle;
import java.io.Serializable;

import org.apache.fop.fo.properties.WritingMode;

/**
* Describe a PDF or PostScript style coordinate transformation matrix (CTM).
* The matrix encodes translations, scaling and rotations of the coordinate
* system used to render pages.
*/
public class CTM implements Serializable {
private double a, b, c, d, e, f;

private static final CTM CTM_LRTB = new CTM(1, 0, 0, 1, 0, 0);
private static final CTM CTM_RLTB = new CTM(-1, 0, 0, 1, 0, 0);
private static final CTM CTM_TBRL = new CTM(0, 1, -1, 0, 0, 0);

/**
* Create the identity matrix
*/
public CTM() {
a = 1;
b = 0;
c = 0;
d = 1;
e = 0;
f = 0;
}

/**
* Initialize a CTM from the passed arguments.
*
* @param a the x scale
* @param b the x shear
* @param c the y shear
* @param d the y scale
* @param e the x shift
* @param f the y shift
*/
public CTM(double a, double b, double c, double d, double e, double f) {
this.a = a;
this.b = b;
this.c = c;
this.d = d;
this.e = e;
this.f = f;
}

/**
* Initialize a CTM to the identity matrix with a translation
* specified by x and y
*
* @param x the x shift
* @param y the y shift.
*/
public CTM(double x, double y) {
this.a = 1;
this.b = 0;
this.c = 0;
this.d = 1;
this.e = x;
this.f = y;
}

/**
* Initialize a CTM with the values of another CTM.
*
* @param ctm another CTM
*/
protected CTM(CTM ctm) {
this.a = ctm.a;
this.b = ctm.b;
this.c = ctm.c;
this.d = ctm.d;
this.e = ctm.e;
this.f = ctm.f;
}

/**
* Return a CTM which will transform coordinates for a particular writing-mode
* into normalized first quandrant coordinates.
* @param wm A writing mode constant from fo.properties.WritingMode, ie.
* one of LR_TB, RL_TB, TB_RL.
* @param ipd The inline-progression dimension of the reference area whose
* CTM is being set..
* @param bpd The block-progression dimension of the reference area whose
* CTM is being set.
* @return a new CTM with the required transform
*/
public static CTM getWMctm(int wm, int ipd, int bpd) {
CTM wmctm;
switch (wm) {
case WritingMode.LR_TB:
return new CTM(CTM_LRTB);
case WritingMode.RL_TB:
{
wmctm = new CTM(CTM_RLTB);
wmctm.e = ipd;
return wmctm;
}
//return CTM_RLTB.translate(ipd, 0);
case WritingMode.TB_RL: // CJK
{
wmctm = new CTM(CTM_TBRL);
wmctm.e = bpd;
return wmctm;
}
//return CTM_TBRL.translate(0, ipd);
default:
return null;
}
}

/**
* Multiply new passed CTM with this one and generate a new result CTM.
* @param premult The CTM to multiply with this one. The new one will be
* the first multiplicand.
* @return CTM The result of multiplying premult * this.
*/
public CTM multiply(CTM premult) {
CTM rslt = new CTM ((premult.a * a) + (premult.b * c),
(premult.a * b) + (premult.b * d),
(premult.c * a) + (premult.d * c),
(premult.c * b) + (premult.d * d),
(premult.e * a) + (premult.f * c) + e,
(premult.e * b) + (premult.f * d) + f);
return rslt;
}

/**
* Rotate this CTM by "angle" radians and return a new result CTM.
* This is used to account for reference-orientation.
* @param angle The angle in radians. Positive angles are measured counter-
* clockwise.
* @return CTM The result of rotating this CTM.
*/
public CTM rotate(double angle) {
double cos, sin;
if (angle == 90.0) {
cos = 0.0;
sin = 1.0;
} else if (angle == 270.0) {
cos = 0.0;
sin = -1.0;
} else if (angle == 180.0) {
cos = -1.0;
sin = 0.0;
} else {
double rad = Math.toRadians(angle);
cos = Math.cos(rad);
sin = Math.sin(rad);
}
CTM rotate = new CTM(cos, -sin, sin, cos, 0, 0);
return multiply(rotate);
}

/**
* Translate this CTM by the passed x and y values and return a new result CTM.
* @param x The amount to translate along the x axis.
* @param y The amount to translate along the y axis.
* @return CTM The result of translating this CTM.
*/
public CTM translate(double x, double y) {
CTM translate = new CTM(1, 0, 0, 1, x, y);
return multiply(translate);
}

/**
* Scale this CTM by the passed x and y values and return a new result CTM.
* @param x The amount to scale along the x axis.
* @param y The amount to scale along the y axis.
* @return CTM The result of scaling this CTM.
*/
public CTM scale(double x, double y) {
CTM scale = new CTM(x, 0, 0, y, 0, 0);
return multiply(scale);
}

/**
* Transform a rectangle by the CTM to produce a rectangle in the transformed
* coordinate system.
* @param inRect The rectangle in the original coordinate system
* @return Rectangle2D The rectangle in the transformed coordinate system.
*/
public Rectangle2D transform(Rectangle2D inRect) {
// Store as 2 sets of 2 points and transform those, then
// recalculate the width and height
int x1t = (int)(inRect.getX() * a + inRect.getY() * c + e);
int y1t = (int)(inRect.getX() * b + inRect.getY() * d + f);
int x2t = (int)((inRect.getX() + inRect.getWidth()) * a
+ (inRect.getY() + inRect.getHeight()) * c + e);
int y2t = (int)((inRect.getX() + inRect.getWidth()) * b
+ (inRect.getY() + inRect.getHeight()) * d + f);
// Normalize with x1 < x2
if (x1t > x2t) {
int tmp = x2t;
x2t = x1t;
x1t = tmp;
}
if (y1t > y2t) {
int tmp = y2t;
y2t = y1t;
y1t = tmp;
}
return new Rectangle(x1t, y1t, x2t - x1t, y2t - y1t);
}

/**
* Get string for this transform.
*
* @return a string with the transform values
*/
public String toString() {
return "[" + a + " " + b + " " + c + " " + d + " " + e + " "
+ f + "]";
}

/**
* Get an array containing the values of this transform.
* This creates and returns a new transform with the values in it.
*
* @return an array containing the transform values
*/
public double[] toArray() {
return new double[]{a, b, c, d, e, f};
}
}


+ 157
- 0
src/java/org/apache/fop/area/CachedRenderPagesModel.java View File

@@ -0,0 +1,157 @@
/*
* $Id: CachedRenderPagesModel.java,v 1.7 2003/03/05 15:19:31 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.area;

import org.apache.fop.render.Renderer;

import java.util.Map;
import java.util.HashMap;
import java.util.Iterator;

import java.io.File;
import java.io.FileOutputStream;
import java.io.FileInputStream;
import java.io.ObjectOutputStream;
import java.io.ObjectInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedInputStream;

/**
* A simple cached render pages model.
* If the page is prepared for later rendering then this saves
* the page contents to a file and once the page is resolved
* the contents a reloaded.
*/
public class CachedRenderPagesModel extends RenderPagesModel {
private Map pageMap = new HashMap();

/**
* Create a new render pages model with the given renderer.
* @param rend the renderer to render pages to
*/
public CachedRenderPagesModel(Renderer rend) {
super(rend);
}

/**
* Check prepared pages
* If a page is resolved it loads the page contents from
* the file.
*
* @param newpage the new page being added
* @return true if the current page should be rendered
* false if the renderer doesn't support out of order
* rendering and there are pending pages
*/
protected boolean checkPreparedPages(PageViewport newpage) {
for (Iterator iter = prepared.iterator(); iter.hasNext();) {
PageViewport p = (PageViewport)iter.next();
if (p.isResolved()) {
if (p != newpage) {
try {
// load page from cache
String name = (String)pageMap.get(p);
File temp = new File(name);
System.out.println("page serialized to: " + temp.length());
ObjectInputStream in = new ObjectInputStream(
new BufferedInputStream(
new FileInputStream(temp)));
p.loadPage(in);
in.close();
temp.delete();
pageMap.remove(p);
} catch (Exception e) {
e.printStackTrace();
}
}

try {
renderer.renderPage(p);
} catch (Exception e) {
// use error handler to handle this FOP or IO Exception
e.printStackTrace();
}
p.clear();
iter.remove();
} else {
if (!renderer.supportsOutOfOrder()) {
break;
}
}
}
if (newpage != null && newpage.getPage() != null) {
savePage(newpage);
}
return renderer.supportsOutOfOrder() || prepared.isEmpty();
}

/**
* Save a page.
* It saves the contents of the page to a file.
*
* @param page the page to prepare
*/
protected void savePage(PageViewport page) {
try {
// save page to cache
ObjectOutputStream tempstream;
String fname = "page" + page.toString() + ".ser";
tempstream = new ObjectOutputStream(new BufferedOutputStream(
new FileOutputStream(fname)));
page.savePage(tempstream);
tempstream.close();
pageMap.put(page, fname);
} catch (Exception e) {
e.printStackTrace();
}
}
}


+ 63
- 0
src/java/org/apache/fop/area/Flow.java View File

@@ -0,0 +1,63 @@
/*
* $Id: Flow.java,v 1.5 2003/03/05 15:19:31 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.area;

/**
* The normal flow reference area class.
* This area contains a list of block areas from the flow.
*/
public class Flow extends BlockParent {
// the list of blocks created from the flow
private int stacking = TB;
private int width;

}


+ 88
- 0
src/java/org/apache/fop/area/Footnote.java View File

@@ -0,0 +1,88 @@
/*
* $Id: Footnote.java,v 1.6 2003/03/05 15:19:31 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.area;

// may combine with before float into a conditional area

/**
* Footnote reference area.
* This areas holds footnote areas and an optional separator area.
*/
public class Footnote extends BlockParent {
private Block separator = null;

// footnote has an optional separator
// and a list of sub block areas that can be added/removed

// this is the relative position of the footnote inside
// the body region
private int top;

/**
* Set the separator area for this footnote.
*
* @param sep the separator area
*/
public void setSeparator(Block sep) {
separator = sep;
}

/**
* Get the separator area for this footnote area.
*
* @return the separator area
*/
public Block getSeparator() {
return separator;
}

}


+ 147
- 0
src/java/org/apache/fop/area/LineArea.java View File

@@ -0,0 +1,147 @@
/*
* $Id: LineArea.java,v 1.12 2003/03/05 15:19:31 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.area;

import org.apache.fop.area.inline.InlineArea;

import java.util.ArrayList;
import java.util.List;

/**
* The line area.
* This is a line area that contains inline areas.
*/
public class LineArea extends Area {
private int stacking = LR;
// contains inline areas
// has start indent and length, dominant baseline, height
private int startIndent;
private int length;

private int lineHeight;
// this is the offset for the dominant baseline
private int baseLine;

// this class can contain the dominant char styling info
// this means that many renderers can optimise a bit

private List inlineAreas = new ArrayList();

/**
* Set the height of this line area.
*
* @param height the height of the line area
*/
public void setHeight(int height) {
lineHeight = height;
}

/**
* Get the height of this line area.
*
* @return the height of the line area
*/
public int getHeight() {
return lineHeight;
}

/**
* Add a child area to this line area.
*
* @param childArea the inline child area to add
*/
public void addChild(Area childArea) {
if (childArea instanceof InlineArea) {
addInlineArea((InlineArea)childArea);
}
}

/**
* Add an inline child area to this line area.
*
* @param area the inline child area to add
*/
public void addInlineArea(InlineArea area) {
inlineAreas.add(area);
}

/**
* Get the inline child areas of this line area.
*
* @return the list of inline areas
*/
public List getInlineAreas() {
return inlineAreas;
}

/**
* Set the start indent of this line area.
* The start indent is used for offsetting the start of
* the inline areas for alignment or other indents.
*
* @param si the start indent value
*/
public void setStartIndent(int si) {
startIndent = si;
}

/**
* Get the start indent of this line area.
* The start indent is used for offsetting the start of
* the inline areas for alignment or other indents.
*
* @return the start indent value
*/
public int getStartIndent() {
return startIndent;
}
}


+ 60
- 0
src/java/org/apache/fop/area/LineTrait.java View File

@@ -0,0 +1,60 @@
/*
* $Id: LineTrait.java,v 1.3 2003/03/05 15:19:31 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.area;

/**
* Traits for a range of areas in a line.
* Not sure if this is needed.
*/
public class LineTrait extends Trait {
private int[] range;
}


+ 101
- 0
src/java/org/apache/fop/area/MainReference.java View File

@@ -0,0 +1,101 @@
/*
* $Id: MainReference.java,v 1.6 2003/03/05 15:19:31 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.area;

import java.util.List;

/**
* The main body reference area.
* This area that contains the flow via the span areas.
*/
public class MainReference extends Area {
private List spanAreas = new java.util.ArrayList();
private int columnGap;
private int width;

/**
* Add a span area to this area.
*
* @param span the span area to add
*/
public void addSpan(Span span) {
spanAreas.add(span);
}

/**
* Get the span areas from this area.
*
* @return the list of span areas
*/
public List getSpans() {
return spanAreas;
}

/**
* Get the column gap in millipoints.
*
* @return the column gap in millioints
*/
public int getColumnGap() {
return columnGap;
}

/**
* Get the width of this reference area.
*
* @return the width
*/
public int getWidth() {
return width;
}

}


+ 166
- 0
src/java/org/apache/fop/area/Page.java View File

@@ -0,0 +1,166 @@
/*
* $Id: Page.java,v 1.10 2003/03/05 15:19:31 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.area;

import java.io.Serializable;
import java.util.Map;

/**
* The page.
* This holds the contents of the page. Each region is added.
* The unresolved references area added so that if the page is
* serialized then it will handle the resolving properly after
* being reloaded.
* This is serializable so it can be saved to cache to save
* memory if there are forward references.
* The page is cloneable so the page master can make copies of
* the top level page and regions.
*/
public class Page implements Serializable, Cloneable {
// contains before, start, body, end and after regions
private RegionViewport regionBefore = null;
private RegionViewport regionStart = null;
private RegionViewport regionBody = null;
private RegionViewport regionEnd = null;
private RegionViewport regionAfter = null;

// temporary map of unresolved objects used when serializing the page
private Map unresolved = null;

/**
* Set the region on this page.
*
* @param areaclass the area class of the region to set
* @param port the region viewport to set
*/
public void setRegion(int areaclass, RegionViewport port) {
if (areaclass == RegionReference.BEFORE) {
regionBefore = port;
} else if (areaclass == RegionReference.START) {
regionStart = port;
} else if (areaclass == RegionReference.BODY) {
regionBody = port;
} else if (areaclass == RegionReference.END) {
regionEnd = port;
} else if (areaclass == RegionReference.AFTER) {
regionAfter = port;
}
}

/**
* Get the region from this page.
*
* @param areaclass the region area class
* @return the region viewport or null if none
*/
public RegionViewport getRegion(int areaclass) {
if (areaclass == RegionReference.BEFORE) {
return regionBefore;
} else if (areaclass == RegionReference.START) {
return regionStart;
} else if (areaclass == RegionReference.BODY) {
return regionBody;
} else if (areaclass == RegionReference.END) {
return regionEnd;
} else if (areaclass == RegionReference.AFTER) {
return regionAfter;
}
return null;
}

/**
* Clone this page.
* This returns a new page with a clone of all the regions.
*
* @return a new clone of this page
*/
public Object clone() {
Page p = new Page();
if (regionBefore != null) {
p.regionBefore = (RegionViewport)regionBefore.clone();
}
if (regionStart != null) {
p.regionStart = (RegionViewport)regionStart.clone();
}
if (regionBody != null) {
p.regionBody = (RegionViewport)regionBody.clone();
}
if (regionEnd != null) {
p.regionEnd = (RegionViewport)regionEnd.clone();
}
if (regionAfter != null) {
p.regionAfter = (RegionViewport)regionAfter.clone();
}

return p;
}

/**
* Set the unresolved references on this page for serializing.
*
* @param unres the map of unresolved objects
*/
public void setUnresolvedReferences(Map unres) {
unresolved = unres;
}

/**
* Get the map unresolved references from this page.
* This should be called after deserializing to retrieve
* the map of unresolved references that were serialized.
*
* @return the de-serialized map of unresolved objects
*/
public Map getUnresolvedReferences() {
return unresolved;
}
}


+ 407
- 0
src/java/org/apache/fop/area/PageViewport.java View File

@@ -0,0 +1,407 @@
/*
* $Id: PageViewport.java,v 1.16 2003/03/05 15:19:31 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.area;

import java.awt.geom.Rectangle2D;
import java.io.ObjectOutputStream;
import java.io.ObjectInputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.util.Iterator;

import org.apache.fop.fo.properties.RetrievePosition;

/**
* Page viewport that specifies the viewport area and holds the page contents.
* This is the top level object for a page and remains valid for the life
* of the document and the area tree.
* This object may be used as a key to reference a page.
* This is the level that creates the page.
* The page (reference area) is then rendered inside the page object
*/
public class PageViewport implements Resolveable, Cloneable {
private Page page;
private Rectangle2D viewArea;
private boolean clip = false;
private String pageNumber = null;

// list of id references and the rectangle on the page
private Map idReferences = null;

// this keeps a list of currently unresolved areas or extensions
// once the thing is resolved it is removed
// when this is empty the page can be rendered
private Map unresolved = null;

private Map pendingResolved = null;

// hashmap of markers for this page
// start and end are added by the fo that contains the markers
private Map markerFirstStart = null;
private Map markerLastStart = null;
private Map markerFirstAny = null;
private Map markerLastEnd = null;
private Map markerLastAny = null;

/**
* Create a page viewport.
* @param p the page reference area that holds the contents
* @param bounds the bounds of this viewport
*/
public PageViewport(Page p, Rectangle2D bounds) {
page = p;
viewArea = bounds;
}

/**
* Set if this viewport should clip.
* @param c true if this viewport should clip
*/
public void setClip(boolean c) {
clip = c;
}

/**
* Get the view area rectangle of this viewport.
* @return the rectangle for this viewport
*/
public Rectangle2D getViewArea() {
return viewArea;
}

/**
* Get the page reference area with the contents.
* @return the page reference area
*/
public Page getPage() {
return page;
}

/**
* Set the page number for this page.
* @param num the string representing the page number
*/
public void setPageNumber(String num) {
pageNumber = num;
}

/**
* Get the page number of this page.
* @return the string that represents this page
*/
public String getPageNumber() {
return pageNumber;
}

/**
* Get the key for this page viewport.
* This is used so that a serializable key can be used to
* lookup the page or some other reference.
*
* @return a unique page viewport key for this area tree
*/
public String getKey() {
return toString();
}

/**
* Add an unresolved id to this page.
* All unresolved ids for the contents of this page are
* added to this page. This is so that the resolvers can be
* serialized with the page to preserve the proper function.
* @param id the id of the reference
* @param res the resolver of the reference
*/
public void addUnresolvedID(String id, Resolveable res) {
if (unresolved == null) {
unresolved = new HashMap();
}
List list = (List)unresolved.get(id);
if (list == null) {
list = new ArrayList();
unresolved.put(id, list);
}
list.add(res);
}

/**
* Check if this page has been fully resolved.
* @return true if the page is resolved and can be rendered
*/
public boolean isResolved() {
return unresolved == null;
}

/**
* Get the id references for this page.
* @return always null
*/
public String[] getIDs() {
return null;
}

/**
* This resolves reference with a list of pages.
* The pages (PageViewport) contain the rectangle of the area.
* @param id the id to resolve
* @param pages the list of pages with the id area
* may be null if not found
*/
public void resolve(String id, List pages) {
if (page == null) {
if (pendingResolved == null) {
pendingResolved = new HashMap();
}
pendingResolved.put(id, pages);
} else {
if (unresolved != null) {
List todo = (List)unresolved.get(id);
if (todo != null) {
for (int count = 0; count < todo.size(); count++) {
Resolveable res = (Resolveable)todo.get(count);
res.resolve(id, pages);
}
}
}
}
if (unresolved != null) {
unresolved.remove(id);
if (unresolved.isEmpty()) {
unresolved = null;
}
}
}

/**
* Add the markers for this page.
* Only the required markers are kept.
* For "first-starting-within-page" it adds the markers
* that are starting only if the marker class name is not
* already added.
* For "first-including-carryover" it adds any starting marker
* if the marker class name is not already added.
* For "last-starting-within-page" it adds all marks that
* are starting, replacing earlier markers.
* For "last-ending-within-page" it adds all markers that
* are ending, replacing earlier markers.
*
* Should this logic be placed in the Page layout manager.
*
* @param marks the map of markers to add
* @param start if the area being added is starting or ending
* @param isfirst isfirst or islast flag
*/
public void addMarkers(Map marks, boolean start, boolean isfirst) {
if (start) {
if (isfirst) {
if (markerFirstStart == null) {
markerFirstStart = new HashMap();
}
if (markerFirstAny == null) {
markerFirstAny = new HashMap();
}
// only put in new values, leave current
for (Iterator iter = marks.keySet().iterator(); iter.hasNext();) {
Object key = iter.next();
if (!markerFirstStart.containsKey(key)) {
markerFirstStart.put(key, marks.get(key));
}
if (!markerFirstAny.containsKey(key)) {
markerFirstAny.put(key, marks.get(key));
}
}
if (markerLastStart == null) {
markerLastStart = new HashMap();
}
// replace all
markerLastStart.putAll(marks);

} else {
if (markerFirstAny == null) {
markerFirstAny = new HashMap();
}
// only put in new values, leave current
for (Iterator iter = marks.keySet().iterator(); iter.hasNext();) {
Object key = iter.next();
if (!markerFirstAny.containsKey(key)) {
markerFirstAny.put(key, marks.get(key));
}
}
}
} else {
if (!isfirst) {
if (markerLastEnd == null) {
markerLastEnd = new HashMap();
}
// replace all
markerLastEnd.putAll(marks);
}
if (markerLastAny == null) {
markerLastAny = new HashMap();
}
// replace all
markerLastAny.putAll(marks);
}
}

/**
* Get a marker from this page.
* This will retrieve a marker with the class name
* and position.
*
* @param name The class name of the marker to retrieve
* @param pos the position to retrieve
* @return Object the marker found or null
*/
public Object getMarker(String name, int pos) {
Object mark = null;
switch (pos) {
case RetrievePosition.FSWP:
if (markerFirstStart != null) {
mark = markerFirstStart.get(name);
}
if (mark == null && markerFirstAny != null) {
mark = markerFirstAny.get(name);
}
break;
case RetrievePosition.FIC:
if (markerFirstAny != null) {
mark = markerFirstAny.get(name);
}
break;
case RetrievePosition.LSWP:
if (markerLastStart != null) {
mark = markerLastStart.get(name);
}
if (mark == null && markerLastAny != null) {
mark = markerLastAny.get(name);
}
break;
case RetrievePosition.LEWP:
if (markerLastEnd != null) {
mark = markerLastEnd.get(name);
}
if (mark == null && markerLastAny != null) {
mark = markerLastAny.get(name);
}
break;
}
return mark;
}

/**
* Save the page contents to an object stream.
* The map of unresolved references are set on the page so that
* the resolvers can be properly serialized and reloaded.
* @param out the object output stream to write the contents
* @throws Exception if there is a problem saving the page
*/
public void savePage(ObjectOutputStream out) throws Exception {
// set the unresolved references so they are serialized
page.setUnresolvedReferences(unresolved);
out.writeObject(page);
page = null;
}

/**
* Load the page contents from an object stream.
* This loads the page contents from the stream and
* if there are any unresolved references that were resolved
* while saved they will be resolved on the page contents.
* @param in the object input stream to read the page from
* @throws Exception if there is an error loading the page
*/
public void loadPage(ObjectInputStream in) throws Exception {
page = (Page) in.readObject();
unresolved = page.getUnresolvedReferences();
if (unresolved != null && pendingResolved != null) {
for (Iterator iter = pendingResolved.keySet().iterator();
iter.hasNext();) {
String id = (String) iter.next();
resolve(id, (List)pendingResolved.get(id));
}
pendingResolved = null;
}
}

/**
* Clone this page.
* Used by the page master to create a copy of an original page.
* @return a copy of this page and associated viewports
*/
public Object clone() {
Page p = (Page)page.clone();
PageViewport ret = new PageViewport(p, (Rectangle2D)viewArea.clone());
return ret;
}

/**
* Clear the page contents to save memory.
* This object is kept for the life of the area tree since
* it holds id and marker information and is used as a key.
*/
public void clear() {
page = null;
}
/**
* @see java.lang.Object#toString()
*/
public String toString() {
StringBuffer sb = new StringBuffer(64);
sb.append("PageViewport: page=");
sb.append(getPageNumber());
return sb.toString();
}
}

+ 164
- 0
src/java/org/apache/fop/area/RegionReference.java View File

@@ -0,0 +1,164 @@
/*
* $Id: RegionReference.java,v 1.10 2003/03/05 15:19:31 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.area;

import java.util.ArrayList;
import java.util.List;

/**
* This is a region reference area for the page regions.
* This area represents a region on the page. It is cloneable
* so the page master can make copies from the original page and regions.
*/
public class RegionReference extends Area implements Cloneable {
/**
* The before region.
*/
public static final int BEFORE = 0;

/**
* The start region.
*/
public static final int START = 1;

/**
* The body region.
*/
public static final int BODY = 2;

/**
* The end region.
*/
public static final int END = 3;

/**
* The after region.
*/
public static final int AFTER = 4;

private int regionClass = BEFORE;
private CTM ctm;
// the list of block areas from the static flow
private List blocks = new ArrayList();

/**
* Create a new region reference area.
*
* @param type the region class type
*/
public RegionReference(int type) {
regionClass = type;
}

/**
* Set the Coordinate Transformation Matrix which transforms content
* coordinates in this region reference area which are specified in
* terms of "start" and "before" into coordinates in a system which
* is positioned in "absolute" directions (with origin at lower left of
* the region reference area.
*
* @param ctm the current transform to position this region
*/
public void setCTM(CTM ctm) {
this.ctm = ctm;
}

/**
* Get the current transform of this region.
*
* @return ctm the current transform to position this region
*/
public CTM getCTM() {
return this.ctm;
}

/**
* Get the block in this region.
*
* @return the list of blocks in this region
*/
public List getBlocks() {
return blocks;
}

/**
* Get the region class of this region.
*
* @return the region class
*/
public int getRegionClass() {
return regionClass;
}

/**
* Add a block area to this region reference area.
*
* @param block the block area to add
*/
public void addBlock(Block block) {
blocks.add(block);
}

/**
* Clone this region.
* This is used when cloning the page by the page master.
* The blocks are not copied since the master will have no blocks.
*
* @return a copy of this region reference area
*/
public Object clone() {
RegionReference rr = new RegionReference(regionClass);
rr.ctm = ctm;
rr.setIPD(getIPD());
return rr;
}

}

+ 147
- 0
src/java/org/apache/fop/area/RegionViewport.java View File

@@ -0,0 +1,147 @@
/*
* $Id: RegionViewport.java,v 1.9 2003/03/05 15:19:31 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.area;

import java.awt.geom.Rectangle2D;
import java.io.IOException;
import java.util.HashMap;

/**
* Region Viewport reference area.
* This area is the viewport for a region and contains a region area.
*/
public class RegionViewport extends Area implements Cloneable {
// this rectangle is relative to the page
private RegionReference region;
private Rectangle2D viewArea;
private boolean clip = false;

/**
* Create a new region viewport.
*
* @param viewArea the view area of this viewport
*/
public RegionViewport(Rectangle2D viewArea) {
this.viewArea = viewArea;
}

/**
* Set the region for this region viewport.
*
* @param reg the child region inside this viewport
*/
public void setRegion(RegionReference reg) {
region = reg;
}

/**
* Get the region for this region viewport.
*
* @return the child region inside this viewport
*/
public RegionReference getRegion() {
return region;
}

/**
* Set the clipping for this region viewport.
*
* @param c the clipping value
*/
public void setClip(boolean c) {
clip = c;
}

/**
* Get the view area of this viewport.
*
* @return the viewport rectangle area
*/
public Rectangle2D getViewArea() {
return viewArea;
}

private void writeObject(java.io.ObjectOutputStream out)
throws IOException {
out.writeFloat((float) viewArea.getX());
out.writeFloat((float) viewArea.getY());
out.writeFloat((float) viewArea.getWidth());
out.writeFloat((float) viewArea.getHeight());
out.writeBoolean(clip);
out.writeObject(props);
out.writeObject(region);
}

private void readObject(java.io.ObjectInputStream in)
throws IOException, ClassNotFoundException {
viewArea = new Rectangle2D.Float(in.readFloat(), in.readFloat(),
in.readFloat(), in.readFloat());
clip = in.readBoolean();
props = (HashMap)in.readObject();
setRegion((RegionReference) in.readObject());
}

/**
* Clone this region viewport.
* Used when creating a copy from the page master.
*
* @return a new copy of this region viewport
*/
public Object clone() {
RegionViewport rv = new RegionViewport((Rectangle2D)viewArea.clone());
rv.region = (RegionReference)region.clone();
if (props != null) {
rv.props = (HashMap)props.clone();
}
return rv;
}
}


+ 223
- 0
src/java/org/apache/fop/area/RenderPagesModel.java View File

@@ -0,0 +1,223 @@
/*
* $Id: RenderPagesModel.java,v 1.3 2003/03/05 15:19:31 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.area;

// FOP
import org.apache.fop.render.Renderer;

// Java
import java.util.List;
import java.util.Iterator;

/**
* This uses the store pages model to store the pages
* each page is either rendered if ready or prepared
* for later rendering.
* Once a page is rendered it is cleared to release the
* contents but the PageViewport is retained. So even
* though the pages are stored the contents are discarded.
*/
public class RenderPagesModel extends StorePagesModel {
/**
* The renderer that will render the pages.
*/
protected Renderer renderer;
/**
* Pages that have been prepared but not rendered yet.
*/
protected List prepared = new java.util.ArrayList();
private List pendingExt = new java.util.ArrayList();
private List endDocExt = new java.util.ArrayList();

/**
* Create a new render pages model with the given renderer.
* @param rend the renderer to render pages to
*/
public RenderPagesModel(Renderer rend) {
renderer = rend;
}

/**
* Start a new page sequence.
* This tells the renderer that a new page sequence has
* started with the given title.
* @param title the title of the new page sequence
*/
public void startPageSequence(Title title) {
super.startPageSequence(title);
renderer.startPageSequence(title);
}

/**
* Add a page to the render page model.
* If the page is finished it can be rendered immediately.
* If the page needs resolving then if the renderer supports
* out of order rendering it can prepare the page. Otherwise
* the page is added to a queue.
* @param page the page to add to the model
*/
public void addPage(PageViewport page) {
super.addPage(page);

// for links the renderer needs to prepare the page
// it is more appropriate to do this after queued pages but
// it will mean that the renderer has not prepared a page that
// could be referenced
boolean done = renderer.supportsOutOfOrder() && page.isResolved();
if (done) {
try {
renderer.renderPage(page);
} catch (Exception e) {
// use error handler to handle this FOP or IO Exception
e.printStackTrace();
}
page.clear();
} else {
preparePage(page);
}


// check prepared pages
boolean cont = checkPreparedPages(page);

if (cont) {
renderExtensions(pendingExt);
pendingExt.clear();
}
}

/**
* Check prepared pages
*
* @param newpage the new page being added
* @return true if the current page should be rendered
* false if the renderer doesn't support out of order
* rendering and there are pending pages
*/
protected boolean checkPreparedPages(PageViewport newpage) {
for (Iterator iter = prepared.iterator(); iter.hasNext();) {
PageViewport p = (PageViewport)iter.next();
if (p.isResolved()) {
try {
renderer.renderPage(p);
} catch (Exception e) {
// use error handler to handle this FOP or IO Exception
e.printStackTrace();
}
p.clear();
iter.remove();
} else {
// if keeping order then stop at first page not resolved
if (!renderer.supportsOutOfOrder()) {
break;
}
}
}
return renderer.supportsOutOfOrder() || prepared.isEmpty();
}

/**
* Prepare a page.
* An unresolved page can be prepared if the renderer supports
* it and the page will be rendered later.
* @param page the page to prepare
*/
protected void preparePage(PageViewport page) {
if (renderer.supportsOutOfOrder()) {
renderer.preparePage(page);
}
prepared.add(page);
}

/**
* Add an extension to this model.
* If handle immediately then send directly to the renderer.
* The after page ones are handled after the next page is added.
* End of document extensions are added to a list to be
* handled at the end.
* @param ext the extension
* @param when when to render the extension
*/
public void addExtension(TreeExt ext, int when) {
switch(when) {
case TreeExt.IMMEDIATELY:
renderer.renderExtension(ext);
break;
case TreeExt.AFTER_PAGE:
pendingExt.add(ext);
break;
case TreeExt.END_OF_DOC:
endDocExt.add(ext);
break;
}
}

private void renderExtensions(List list) {
for (int count = 0; count < list.size(); count++) {
TreeExt ext = (TreeExt)list.get(count);
renderer.renderExtension(ext);
}
}

/**
* End the document. Render any end document extensions.
*/
public void endDocument() {
// render any pages that had unresolved ids
checkPreparedPages(null);

renderExtensions(pendingExt);
pendingExt.clear();

renderExtensions(endDocExt);
}
}


+ 87
- 0
src/java/org/apache/fop/area/Resolveable.java View File

@@ -0,0 +1,87 @@
/*
* $Id: Resolveable.java,v 1.5 2003/03/05 15:19:31 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.area;

import java.util.List;

/**
* Resolveable Interface.
* Classes that implement this can be resolved when
* an id is added to the area tree.
*/
public interface Resolveable {

/**
* Check if this area has been resolved.
*
* @return true once this area is resolved
*/
boolean isResolved();

/**
* Get the array of id references of this resolveable object.
* If this object contains child resolveables that are
* resolved through this then it should return the id's of
* the child also.
*
* @return the id references for resolving this object
*/
String[] getIDs();

/**
* This resolves reference with a list of pages.
* The pages (PageViewport) contain the rectangle of the area.
* @param id the id to resolve
* @param pages the list of pages with the id area
* may be null if not found
*/
void resolve(String id, List pages);
}

+ 112
- 0
src/java/org/apache/fop/area/Span.java View File

@@ -0,0 +1,112 @@
/*
* $Id: Span.java,v 1.8 2003/03/05 15:19:31 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.area;

import java.util.List;

/**
* The span reference area.
* This is a reference area block area with 0 border and padding
* The span reference areas are stacked inside the main reference area.
*/
public class Span extends Area {
// the list of flow reference areas in this span area
private List flowAreas;
private int height;

/**
* Create a span area with the number of columns for this span area.
*
* @param cols the number of columns in the span
*/
public Span(int cols) {
flowAreas = new java.util.ArrayList(cols);
}

/**
* Add the flow area to this span area.
*
* @param flow the flow area to add
*/
public void addFlow(Flow flow) {
flowAreas.add(flow);
}

/**
* Get the column count for this span area.
*
* @return the number of columns in this span area
*/
public int getColumnCount() {
return flowAreas.size();
}

/**
* Get the height of this span area.
*
* @return the height of this span area
*/
public int getHeight() {
return height;
}

/**
* Get the flow area for a particular column.
*
* @param count the column number for the flow
* @return the flow area for the requested column
*/
public Flow getFlow(int count) {
return (Flow) flowAreas.get(count);
}

}


+ 179
- 0
src/java/org/apache/fop/area/StorePagesModel.java View File

@@ -0,0 +1,179 @@
/*
* $Id: StorePagesModel.java,v 1.3 2003/03/05 15:19:31 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.area;

// Java
import java.util.List;

/**
* This class stores all the pages in the document
* for interactive agents.
* The pages are stored and can be retrieved in any order.
*/
public class StorePagesModel extends AreaTreeModel {
private List pageSequence = null;
private List titles = new java.util.ArrayList();
private List currSequence;
private List extensions = new java.util.ArrayList();

/**
* Create a new store pages model
*/
public StorePagesModel() {
}

/**
* Start a new page sequence.
* This creates a new list for the pages in the new page sequence.
* @param title the title of the page sequence.
*/
public void startPageSequence(Title title) {
titles.add(title);
if (pageSequence == null) {
pageSequence = new java.util.ArrayList();
}
currSequence = new java.util.ArrayList();
pageSequence.add(currSequence);
}

/**
* Add a page.
* @param page the page to add to the current page sequence
*/
public void addPage(PageViewport page) {
currSequence.add(page);
}

/**
* Get the page sequence count.
* @return the number of page sequences in the document.
*/
public int getPageSequenceCount() {
return pageSequence.size();
}

/**
* Get the title for a page sequence.
* @param count the page sequence count
* @return the title of the page sequence
*/
public Title getTitle(int count) {
return (Title) titles.get(count);
}

/**
* Get the page count.
* @param seq the page sequence to count.
* @return returns the number of pages in a page sequence
*/
public int getPageCount(int seq) {
List sequence = (List) pageSequence.get(seq);
return sequence.size();
}

/**
* Get the page for a position in the document.
* @param seq the page sequence number
* @param count the page count in the sequence
* @return the PageViewport for the particular page
*/
public PageViewport getPage(int seq, int count) {
List sequence = (List) pageSequence.get(seq);
return (PageViewport) sequence.get(count);
}

/**
* Add an extension to the store page model.
* The extension is stored so that it can be retrieved in the
* appropriate position.
* @param ext the extension to add
* @param when when the extension should be handled
*/
public void addExtension(TreeExt ext, int when) {
int seq, page;
switch(when) {
case TreeExt.IMMEDIATELY:
seq = pageSequence == null ? 0 : pageSequence.size();
page = currSequence == null ? 0 : currSequence.size();
break;
case TreeExt.AFTER_PAGE:
break;
case TreeExt.END_OF_DOC:
break;
}
extensions.add(ext);
}

/**
* Get the list of extensions that apply at a particular
* position in the document.
* @param seq the page sequence number
* @param count the page count in the sequence
* @return the list of extensions
*/
public List getExtensions(int seq, int count) {
return null;
}

/**
* Get the end of document extensions for this stroe pages model.
* @return the list of end extensions
*/
public List getEndExtensions() {
return extensions;
}

/**
* End document, do nothing.
*/
public void endDocument() {
}
}

+ 60
- 0
src/java/org/apache/fop/area/Title.java View File

@@ -0,0 +1,60 @@
/*
* $Id: Title.java,v 1.4 2003/03/05 15:19:31 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.area;

/**
* The title area.
* This area holds the inline areas from the page-sequence
* title element.
*/
public class Title extends LineArea {
}


+ 475
- 0
src/java/org/apache/fop/area/Trait.java View File

@@ -0,0 +1,475 @@
/*
* $Id: Trait.java,v 1.13 2003/03/05 15:19:31 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.area;

import org.apache.fop.datatypes.ColorType;
import org.apache.fop.traits.BorderProps;

import java.io.Serializable;
import java.util.Map;
import java.util.HashMap;
import java.util.Iterator;

// properties should be serialized by the holder
/**
* Area traits used for rendering.
* This class represents an area trait that specifies a value for rendering.
*/
public class Trait implements Serializable {
/**
* Id reference line, not resolved.
* not sure if this is needed.
*/
public static final Integer ID_LINK = new Integer(0);

/**
* Internal link trait.
* This is resolved and provides a link to an internal area.
*/
public static final Integer INTERNAL_LINK = new Integer(1); //resolved

/**
* External link. A URL link to an external resource.
*/
public static final Integer EXTERNAL_LINK = new Integer(2);

/**
* The font name from the font setup.
*/
public static final Integer FONT_NAME = new Integer(3);

/**
* Font size for the current font.
*/
public static final Integer FONT_SIZE = new Integer(4);

/**
* The current colour.
*/
public static final Integer COLOR = new Integer(7);

/**
* Don't think this is necessary.
*/
public static final Integer ID_AREA = new Integer(8);

/**
* Background trait for an area.
*/
public static final Integer BACKGROUND = new Integer(9);

/**
* Underline trait used when rendering inline parent.
*/
public static final Integer UNDERLINE = new Integer(10);

/**
* Overline trait used when rendering inline parent.
*/
public static final Integer OVERLINE = new Integer(11);

/**
* Linethrough trait used when rendering inline parent.
*/
public static final Integer LINETHROUGH = new Integer(12);

/**
* Shadow offset.
*/
public static final Integer OFFSET = new Integer(13);

/**
* The shadow for text.
*/
public static final Integer SHADOW = new Integer(14);

/**
* The border start.
*/
public static final Integer BORDER_START = new Integer(15);

/**
* The border end.
*/
public static final Integer BORDER_END = new Integer(16);

/**
* The border before.
*/
public static final Integer BORDER_BEFORE = new Integer(17);

/**
* The border after.
*/
public static final Integer BORDER_AFTER = new Integer(18);

/**
* The padding start.
*/
public static final Integer PADDING_START = new Integer(19);

/**
* The padding end.
*/
public static final Integer PADDING_END = new Integer(20);

/**
* The padding before.
*/
public static final Integer PADDING_BEFORE = new Integer(21);

/**
* The padding after.
*/
public static final Integer PADDING_AFTER = new Integer(22);

private static final Map TRAIT_INFO = new HashMap();

private static class TraitInfo {
private String name;
private Class clazz; // Class of trait data
public TraitInfo(String name, Class clazz) {
this.name = name;
this.clazz = clazz;
}
public String getName() {
return this.name;
}
public Class getClazz() {
return this.clazz;
}
}

static {
// Create a hashmap mapping trait code to name for external representation
TRAIT_INFO.put(ID_LINK, new TraitInfo("id-link", String.class));
TRAIT_INFO.put(INTERNAL_LINK,
new TraitInfo("internal-link", String.class));
TRAIT_INFO.put(EXTERNAL_LINK,
new TraitInfo("external-link", String.class));
TRAIT_INFO.put(FONT_NAME,
new TraitInfo("font-family", String.class));
TRAIT_INFO.put(FONT_SIZE,
new TraitInfo("font-size", Integer.class));
TRAIT_INFO.put(COLOR, new TraitInfo("color", String.class));
TRAIT_INFO.put(ID_AREA, new TraitInfo("id-area", String.class));
TRAIT_INFO.put(BACKGROUND,
new TraitInfo("background", Background.class));
TRAIT_INFO.put(UNDERLINE,
new TraitInfo("underline", Boolean.class));
TRAIT_INFO.put(OVERLINE,
new TraitInfo("overline", Boolean.class));
TRAIT_INFO.put(LINETHROUGH,
new TraitInfo("linethrough", Boolean.class));
TRAIT_INFO.put(OFFSET, new TraitInfo("offset", Integer.class));
TRAIT_INFO.put(SHADOW, new TraitInfo("shadow", Integer.class));
TRAIT_INFO.put(BORDER_START,
new TraitInfo("border-start", BorderProps.class));
TRAIT_INFO.put(BORDER_END,
new TraitInfo("border-end", BorderProps.class));
TRAIT_INFO.put(BORDER_BEFORE,
new TraitInfo("border-before", BorderProps.class));
TRAIT_INFO.put(BORDER_AFTER,
new TraitInfo("border-after", BorderProps.class));
TRAIT_INFO.put(PADDING_START,
new TraitInfo("padding-start", Integer.class));
TRAIT_INFO.put(PADDING_END,
new TraitInfo("padding-end", Integer.class));
TRAIT_INFO.put(PADDING_BEFORE,
new TraitInfo("padding-before", Integer.class));
TRAIT_INFO.put(PADDING_AFTER,
new TraitInfo("padding-after", Integer.class));
}

/**
* Get the trait name for a trait code.
*
* @param traitCode the trait code to get the name for
* @return the trait name
*/
public static String getTraitName(Object traitCode) {
Object obj = TRAIT_INFO.get(traitCode);
if (obj != null) {
return ((TraitInfo) obj).getName();
} else {
return "unknown-trait-" + traitCode.toString();
}
}

/**
* Get the trait code for a trait name.
*
* @param sTraitName the name of the trait to find
* @return the trait code object
*/
public static Object getTraitCode(String sTraitName) {
Iterator iter = TRAIT_INFO.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry entry = (Map.Entry) iter.next();
TraitInfo ti = (TraitInfo) entry.getValue();
if (ti != null && ti.getName().equals(sTraitName)) {
return entry.getKey();
}
}
return null;
}

/**
* Get the data storage class for the trait.
*
* @param oTraitCode the trait code to lookup
* @return the class type for the trait
*/
private static Class getTraitClass(Object oTraitCode) {
TraitInfo ti = (TraitInfo) TRAIT_INFO.get(oTraitCode);
return (ti != null ? ti.getClazz() : null);
}

/**
* The type of trait for an area.
*/
private Object propType;

/**
* The data value of the trait.
*/
private Object data;

/**
* Create a new empty trait.
*/
public Trait() {
this.propType = null;
this.data = null;
}

/**
* Create a trait with the value and type.
*
* @param propType the type of trait
* @param data the data value
*/
public Trait(Object propType, Object data) {
this.propType = propType;
this.data = data;
}

/**
* Returns the trait data value.
* @return the trait data value
*/
public Object getData() {
return this.data;
}

/**
* Returns the property type.
* @return the property type
*/
public Object getPropType() {
return this.propType;
}

/**
* Return the string for debugging.
* @see java.lang.Object#toString()
*/
public String toString() {
return data.toString();
}

/**
* Make a trait value.
*
* @param oCode trait code
* @param sTraitValue trait value as String
* @return the trait value as object
*/
public static Object makeTraitValue(Object oCode, String sTraitValue) {
// Get the code from the name
// See what type of object it is
// Convert string value to an object of that type
Class tclass = getTraitClass(oCode);
if (tclass == null) {
return null;
}
if (tclass.equals(String.class)) {
return sTraitValue;
}
if (tclass.equals(Integer.class)) {
return new Integer(sTraitValue);
}
// See if the class has a constructor from string or can read from a string
try {
Object o = tclass.newInstance();
//return o.fromString(sTraitValue);
} catch (IllegalAccessException e1) {
System.err.println("Can't create instance of "
+ tclass.getName());
return null;
} catch (InstantiationException e2) {
System.err.println("Can't create instance of "
+ tclass.getName());
return null;
}


return null;
}

/**
* Background trait structure.
* Used for storing back trait information which are related.
*/
public static class Background implements Serializable {
/** The background color if any. */
private ColorType color = null;

/** The background image url if any. */
private String url = null;

/** Background repeat enum for images. */
private int repeat;

/** Background horizontal offset for images. */
private int horiz;

/** Background vertical offset for images. */
private int vertical;
/**
* Returns the background color.
* @return background color, null if n/a
*/
public ColorType getColor() {
return color;
}

/**
* Returns the horizontal offset for images.
* @return the horizontal offset
*/
public int getHoriz() {
return horiz;
}

/**
* Returns the image repetition behaviour for images.
* @return the image repetition behaviour
*/
public int getRepeat() {
return repeat;
}

/**
* Returns the URL to the background image
* @return URL to the background image, null if n/a
*/
public String getURL() {
return url;
}

/**
* Returns the vertical offset for images.
* @return the vertical offset
*/
public int getVertical() {
return vertical;
}

/**
* Sets the color.
* @param color The color to set
*/
public void setColor(ColorType color) {
this.color = color;
}

/**
* Sets the horizontal offset.
* @param horiz The horizontal offset to set
*/
public void setHoriz(int horiz) {
this.horiz = horiz;
}

/**
* Sets the image repetition behaviour for images.
* @param repeat The image repetition behaviour to set
*/
public void setRepeat(int repeat) {
this.repeat = repeat;
}

/**
* Sets the URL to the background image.
* @param url The URL to set
*/
public void setURL(String url) {
this.url = url;
}

/**
* Sets the vertical offset for images.
* @param vertical The vertical offset to set
*/
public void setVertical(int vertical) {
this.vertical = vertical;
}

}

}


+ 103
- 0
src/java/org/apache/fop/area/TreeExt.java View File

@@ -0,0 +1,103 @@
/*
* $Id: TreeExt.java,v 1.4 2003/03/05 15:19:31 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.area;

/**
* Area tree extension interface.
* This interface is used by area tree extensions that are handled
* by the renderer.
* When this extension is handled by the area tree it is rendered
* according to the three possibilities, IMMEDIATELY, AFTER_PAGE
* or END_OF_DOC.
*/
public interface TreeExt {
/**
* Render this extension immediately when
* being handled by the area tree.
*/
public static final int IMMEDIATELY = 0;

/**
* Render this extension after the next page is rendered
* or prepared when being handled by the area tree.
*/
public static final int AFTER_PAGE = 1;

/**
* Render this extension at the end of the document once
* all pages have been fully rendered.
*/
public static final int END_OF_DOC = 2;

/**
* Check if this tree extension is also resolveable so that
* the area tree can do id reference resolution when the
* extension is added to the area tree.
*
* @return true if this also implements resolveable
*/
boolean isResolveable();

/**
* Get the mime type for the document that this area tree
* extension applies.
*
* @return the mime type of the document where this applies
*/
String getMimeType();

/**
* Get the name of this extension.
*
* @return the name of this extension
*/
String getName();
}

+ 63
- 0
src/java/org/apache/fop/area/inline/Anchor.java View File

@@ -0,0 +1,63 @@
/*
* $Id: Anchor.java,v 1.4 2003/03/05 16:45:43 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.area.inline;

/**
* Anchor area for footnote or float.
* Not sure if this is needed.
*/
public class Anchor extends InlineArea {

// has a keep with adjacent area
// has reference to associated footnote or float out-of-line area

}


+ 89
- 0
src/java/org/apache/fop/area/inline/Character.java View File

@@ -0,0 +1,89 @@
/*
* $Id: Character.java,v 1.4 2003/03/05 16:45:43 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.area.inline;

import org.apache.fop.render.Renderer;

/**
* Single character inline area.
* This inline area holds a single character.
*/
public class Character extends InlineArea {
private char character;

/**
* Create a new characater inline area with the given character.
*
* @param ch the character for this inline area
*/
public Character(char ch) {
character = ch;
}

/**
* Render this inline area.
*
* @param renderer the renderer to render this character area
*/
public void render(Renderer renderer) {
renderer.renderCharacter(this);
}

/**
* Get the character for this inline character area.
*
* @return the character
*/
public char getChar() {
return character;
}
}


+ 109
- 0
src/java/org/apache/fop/area/inline/Container.java View File

@@ -0,0 +1,109 @@
/*
* $Id: Container.java,v 1.7 2003/03/05 16:45:42 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.area.inline;

import org.apache.fop.area.Area;
import org.apache.fop.area.Block;

import java.util.List;
import java.util.ArrayList;

/**
* Container area for inline container.
* This area should be placed in a viewport as a result of the
* inline container formatting object.
* This allows an inline area to have blocks as children.
*/
public class Container extends Area {
/**
* The list of block areas stacked inside this container
*/
protected List blocks = new ArrayList();

/**
* The width of this container
*/
protected int width;

/**
* Create a new container area
*/
public Container() {
}

/**
* Add the block to this area.
*
* @param block the block area to add
*/
public void addBlock(Block block) {
blocks.add(block);
}

/**
* Get the block areas stacked inside this container area.
*
* @return the list of block areas
*/
public List getBlocks() {
return blocks;
}

/**
* Get the width of this container area.
*
* @return the width
*/
public int getWidth() {
return width;
}
}


+ 100
- 0
src/java/org/apache/fop/area/inline/FilledArea.java View File

@@ -0,0 +1,100 @@
/*
* $Id: FilledArea.java,v 1.5 2003/03/05 16:45:43 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.area.inline;

import java.util.List;
import java.util.ArrayList;

/**
* Filled area.
* This inline area contains some inline areas.
* When the renderer gets the child areas to render
* the inline areas are repeated to fill the ipd of
* this inline parent.
* This extends InlineParent so that the renderer will render
* this as a normal inline parent.
*/
public class FilledArea extends InlineParent {
private int unitWidth;

/**
* Create a new filled area.
*/
public FilledArea() {
}

/**
* Set the unit width for the areas to fill the full width.
*
* @param w the unit width
*/
public void setUnitWidth(int w) {
unitWidth = w;
}

/**
* Get the child areas for this filed area.
* This copies the references of the inline areas so that
* it fills the total width of the area a whole number of times
* for the unit width.
*
* @return the list of child areas copied to fill the width
*/
public List getChildAreas() {
int units = (int)(getWidth() / unitWidth);
List newList = new ArrayList();
for (int count = 0; count < units; count++) {
newList.addAll(inlines);
}
return newList;
}
}


+ 96
- 0
src/java/org/apache/fop/area/inline/ForeignObject.java View File

@@ -0,0 +1,96 @@
/*
* $Id: ForeignObject.java,v 1.4 2003/03/05 16:45:43 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.area.inline;

import org.apache.fop.area.Area;

import org.w3c.dom.Document;

// cacheable object
/**
* Foreign object inline area.
* This inline area represents an instream-foreign object.
* This holds an xml document and the associated namespace.
*/
public class ForeignObject extends Area {
private Document doc;
private String namespace;

/**
* Create a new foreign object with the given dom and namespace.
*
* @param d the xml document
* @param ns the namespace of the document
*/
public ForeignObject(Document d, String ns) {
doc = d;
namespace = ns;
}

/**
* Get the document for this foreign object.
*
* @return the xml document
*/
public Document getDocument() {
return doc;
}

/**
* Get the namespace of this foreign object.
*
* @return the namespace of this document
*/
public String getNameSpace() {
return namespace;
}
}


+ 82
- 0
src/java/org/apache/fop/area/inline/Image.java View File

@@ -0,0 +1,82 @@
/*
* $Id: Image.java,v 1.6 2003/03/05 16:45:43 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.area.inline;

import org.apache.fop.area.Area;

/**
* Image area for external-graphic.
* This area holds information for rendering an image.
* The url of the image is used as a key to reference the image cache.
*/
public class Image extends Area {
private String url;

/**
* Create a new image with the given url.
*
* @param u the url of the image
*/
public Image(String u) {
url = u;
}

/**
* Get the url of this image.
* This url is used as a key to locate the actual image data.
*
* @return the url of this image
*/
public String getURL() {
return url;
}
}


+ 205
- 0
src/java/org/apache/fop/area/inline/InlineArea.java View File

@@ -0,0 +1,205 @@
/*
* $Id: InlineArea.java,v 1.15 2003/03/05 16:45:43 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.area.inline;

import org.apache.fop.area.Area;
import org.apache.fop.area.Trait;
import org.apache.fop.render.Renderer;
import org.apache.fop.traits.BorderProps;

/**
* Inline Area
* This area is for all inline areas that can be placed
* in a line area.
* Extensions of this class should render themselves with the
* requested renderer.
*/
public class InlineArea extends Area {
// int width;
private int height;
/**
* The content ipd of this inline area
*/
protected int contentIPD = 0;

/**
* offset position from top of parent area
*/
protected int verticalPosition = 0;

/**
* Render this inline area.
* Inline areas that extend this class are expected
* to implement this method to render themselves in
* the renderer.
*
* @param renderer the renderer to render this inline area
*/
public void render(Renderer renderer) {
}

/**
* Set the width of this inline area.
* Currently sets the ipd.
*
* @param w the width
*/
public void setWidth(int w) {
contentIPD = w;
}

/**
* Get the width of this inline area.
* Currently gets the ipd.
*
* @return the width
*/
public int getWidth() {
return contentIPD;
}

/**
* Set the inline progression dimension of this inline area.
*
* @param ipd the inline progression dimension
*/
public void setIPD(int ipd) {
this.contentIPD = ipd;
}

/**
* Get the inline progression dimension
*
* @return the inline progression dimension of this area
*/
public int getIPD() {
return this.contentIPD;
}

/**
* Increase the inline progression dimensions of this area.
* This is used for inline parent areas that contain mulitple child areas.
*
* @param ipd the inline progression to increase by
*/
public void increaseIPD(int ipd) {
this.contentIPD += ipd;
}

/**
* Set the height of this inline area.
*
* @param h the height value to set
*/
public void setHeight(int h) {
height = h;
}

/**
* Get the height of this inline area.
*
* @return the height of the inline area
*/
public int getHeight() {
return height;
}

/**
* Get the allocation inline progression dimension of this area.
* This adds the content, borders and the padding to find the
* total allocated IPD.
*
* @return the total IPD allocation for this area
*/
public int getAllocIPD() {
// If start or end border or padding is non-zero, add to content IPD
int iBP = contentIPD;
Object t;
if ((t = getTrait(Trait.PADDING_START)) != null) {
iBP += ((Integer) t).intValue();
}
if ((t = getTrait(Trait.PADDING_END)) != null) {
iBP += ((Integer) t).intValue();
}
if ((t = getTrait(Trait.BORDER_START)) != null) {
iBP += ((BorderProps) t).width;
}
if ((t = getTrait(Trait.BORDER_END)) != null) {
iBP += ((BorderProps) t).width;
}
return iBP;
}

/**
* Set the offset of this inline area.
* This is used to set the offset of the inline area
* which is normally relative to the top of the line
* or the baseline.
*
* @param v the offset
*/
public void setOffset(int v) {
verticalPosition = v;
}

/**
* Get the offset of this inline area.
* This returns the offset of the inline area
* which is normally relative to the top of the line
* or the baseline.
*
* @return the offset
*/
public int getOffset() {
return verticalPosition;
}
}


+ 111
- 0
src/java/org/apache/fop/area/inline/InlineParent.java View File

@@ -0,0 +1,111 @@
/*
* $Id: InlineParent.java,v 1.9 2003/03/05 16:45:42 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.area.inline;

import org.apache.fop.area.Area;
import org.apache.fop.render.Renderer;

import java.util.List;
import java.util.ArrayList;

/**
* Inline parent area.
* This is an inline area that can have other inlines as children.
*/
public class InlineParent extends InlineArea {
/**
* The list of inline areas added to this inline parent.
*/
protected List inlines = new ArrayList();

/**
* An inline parent is a reference area somay have clipping
*/
protected boolean clip = false;

/**
* Create a new inline parent to add areas to.
*/
public InlineParent() {
}

/**
* Render this area.
*
* @param renderer the renderer to render this area in
*/
public void render(Renderer renderer) {
renderer.renderInlineParent(this);
}

/**
* Override generic Area method.
*
* @param childArea the child area to add
*/
public void addChild(Area childArea) {
if (childArea instanceof InlineArea) {
inlines.add(childArea);
increaseIPD(((InlineArea) childArea).getAllocIPD());
}
}

/**
* Get the child areas for this inline parent.
*
* @return the list of child areas
*/
public List getChildAreas() {
return inlines;
}

}


+ 121
- 0
src/java/org/apache/fop/area/inline/Leader.java View File

@@ -0,0 +1,121 @@
/*
* $Id: Leader.java,v 1.6 2003/03/05 16:45:43 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.area.inline;

import org.apache.fop.render.Renderer;
import org.apache.fop.fo.properties.RuleStyle;

/**
* This is a leader inline area.
* This class is only used for leader with leader-pattern of rule.
*/
public class Leader extends InlineArea {

// in the case of use content or dots this is replaced
// with the set of inline areas
// if space replaced with a space
// otherwise this is a holder for a line

private int ruleStyle = RuleStyle.SOLID;
private int ruleThickness = 1000;

/**
* Create a new leader area.
*/
public Leader() {
}

/**
* Set the rule style of this leader area.
*
* @param style the rule style for the leader line
*/
public void setRuleStyle(int style) {
ruleStyle = style;
}

/**
* Set the rule thickness of the rule in miilipoints.
*
* @param rt the rule thickness in millipoints
*/
public void setRuleThickness(int rt) {
ruleThickness = rt;
}

/**
* Get the rule style of this leader.
*
* @return the rule style
*/
public int getRuleStyle() {
return ruleStyle;
}

/**
* Get the rule thickness of the rule in miilipoints.
*
* @return the rule thickness in millipoints
*/
public int getRuleThickness() {
return ruleThickness;
}

/**
* Render this leader in the current renderer.
*
* @param renderer the renderer to render this inline area
*/
public void render(Renderer renderer) {
renderer.renderLeader(this);
}
}


+ 69
- 0
src/java/org/apache/fop/area/inline/Space.java View File

@@ -0,0 +1,69 @@
/*
* $Id: Space.java,v 1.5 2003/03/05 16:45:43 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.area.inline;

import org.apache.fop.render.Renderer;

/**
* Inline space area.
* This is used for adding a inline space to the output.
*/
public class Space extends InlineArea {

/**
* Render this inlien space area.
*
* @param renderer the renderer to render this inline area
*/
public void render(Renderer renderer) {
renderer.renderInlineSpace(this);
}
}

+ 115
- 0
src/java/org/apache/fop/area/inline/UnresolvedPageNumber.java View File

@@ -0,0 +1,115 @@
/*
* $Id: UnresolvedPageNumber.java,v 1.7 2003/03/05 16:45:43 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.area.inline;

import org.apache.fop.area.PageViewport;
import org.apache.fop.area.Resolveable;

import java.util.List;

/**
* Unresolveable page number area.
* This is a word area that resolves itself to a page number
* from an id reference.
*/
public class UnresolvedPageNumber extends Word implements Resolveable {
private boolean resolved = false;
private String pageRefId;

/**
* Create a new unresolveable page number.
*
* @param id the id reference for resolving this
*/
public UnresolvedPageNumber(String id) {
pageRefId = id;
word = "?";
}

/**
* Get the id references for this area.
*
* @return the id reference for this unresolved page number
*/
public String[] getIDs() {
return new String[] {pageRefId};
}

/**
* Resolve this page number reference.
* This resolves the reference by getting the page number
* string from the first page in the list of pages that apply
* for the id reference. The word string is then set to the
* page number string.
*
* @param id the id reference being resolved
* @param pages the list of pages for the id reference
*/
public void resolve(String id, List pages) {
resolved = true;
if (pages != null) {
PageViewport page = (PageViewport)pages.get(0);
String str = page.getPageNumber();
word = str;

/**@todo Update IPD ??? */
}
}

/**
* Check if this is resolved.
*
* @return true when this has been resolved
*/
public boolean isResolved() {
return resolved;
}
}

+ 164
- 0
src/java/org/apache/fop/area/inline/Viewport.java View File

@@ -0,0 +1,164 @@
/*
* $Id: Viewport.java,v 1.7 2003/03/05 16:45:42 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.area.inline;

import org.apache.fop.area.Area;
import org.apache.fop.render.Renderer;

import java.io.IOException;
import java.awt.geom.Rectangle2D;
import java.util.HashMap;

/**
* Inline viewport area.
* This is an inline-level viewport area for inline container,
* external graphic and instream foreign object. This viewport
* holds the area and positions it.
*/
public class Viewport extends InlineArea {
// contents could be container, foreign object or image
private Area content;
// clipping for the viewport
private boolean clip = false;
// position of the cild area relative to this area
private Rectangle2D contentPosition;

/**
* Create a new viewport area with the content area.
*
* @param child the child content area of this viewport
*/
public Viewport(Area child) {
content = child;
}

/**
* Set the clip of this viewport.
*
* @param c true if this viewport should clip
*/
public void setClip(boolean c) {
clip = c;
}

/**
* Get the clip of this viewport.
*
* @return true if this viewport should clip
*/
public boolean getClip() {
return clip;
}

/**
* Set the position and size of the content of this viewport.
*
* @param cp the position and size to place the content
*/
public void setContentPosition(Rectangle2D cp) {
contentPosition = cp;
}

/**
* Get the position and size of the content of this viewport.
*
* @return the position and size to place the content
*/
public Rectangle2D getContentPosition() {
return contentPosition;
}

/**
* Get the content area for this viewport.
*
* @return the content area
*/
public Area getContent() {
return content;
}

/**
* Render this inline area.
*
* @param renderer the renderer to render this inline area
*/
public void render(Renderer renderer) {
renderer.renderViewport(this);
}

private void writeObject(java.io.ObjectOutputStream out)
throws IOException {
out.writeBoolean(contentPosition != null);
if (contentPosition != null) {
out.writeFloat((float) contentPosition.getX());
out.writeFloat((float) contentPosition.getY());
out.writeFloat((float) contentPosition.getWidth());
out.writeFloat((float) contentPosition.getHeight());
}
out.writeBoolean(clip);
out.writeObject(props);
out.writeObject(content);
}

private void readObject(java.io.ObjectInputStream in)
throws IOException, ClassNotFoundException {
if (in.readBoolean()) {
contentPosition = new Rectangle2D.Float(in.readFloat(),
in.readFloat(),
in.readFloat(),
in.readFloat());
}
clip = in.readBoolean();
props = (HashMap) in.readObject();
content = (Area) in.readObject();
}

}

+ 118
- 0
src/java/org/apache/fop/area/inline/Word.java View File

@@ -0,0 +1,118 @@
/*
* $Id: Word.java,v 1.10 2003/03/05 16:45:42 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.area.inline;

import org.apache.fop.render.Renderer;

/**
* A word inline area.
* This is really a collection character inline areas collected together
* into a single word.
*/
public class Word extends InlineArea {
/**
* The word for this word area.
*/
protected String word;
private int iWSadjust = 0;

/**
* Create a word area.
*/
public Word() {
}

/**
* Render the word to the renderer.
*
* @param renderer the renderer to render this word
*/
public void render(Renderer renderer) {
renderer.renderWord(this);
}

/**
* Set the word.
*
* @param w the word string
*/
public void setWord(String w) {
word = w;
}

/**
* Get the word string.
*
* @return the word string
*/
public String getWord() {
return word;
}

/**
* Get word space adjust.
*
* @return the word space adjustment
*/
public int getWSadjust() {
return iWSadjust;
}

/**
* Set word space adjust.
*
* @param iWSadjust the word space adjustment
*/
public void setWSadjust(int iWSadjust) {
this.iWSadjust = iWSadjust;
}
}


+ 77
- 0
src/java/org/apache/fop/datatypes/AutoLength.java View File

@@ -0,0 +1,77 @@
/*
* $Id: AutoLength.java,v 1.3 2003/03/05 20:38:23 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.datatypes;

/**
* A length quantity in XSL which is specified as "auto".
*/
public class AutoLength extends Length {

/**
* @see org.apache.fop.datatypes.Length#isAuto()
*/
public boolean isAuto() {
return true;
}

// Should we do something intelligent here to set the actual size?
// Would need a reference object!
// protected void computeValue() {
// }

/**
* @see java.lang.Object#toString()
*/
public String toString() {
return "auto";
}

}

+ 741
- 0
src/java/org/apache/fop/datatypes/ColorType.java View File

@@ -0,0 +1,741 @@
/*
* $Id: ColorType.java,v 1.21 2003/03/05 20:38:23 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.datatypes;

import java.io.Serializable;
import java.util.StringTokenizer;

/**
* A colour quantity in XSL.
*/
public class ColorType implements Serializable {

/**
* the red component
*/
protected float red;

/**
* the green component
*/
protected float green;

/**
* the blue component
*/
protected float blue;

/**
* the alpha component
*/
protected float alpha = 0;

/**
* Main constructor
* @param red red component
* @param green green component
* @param blue blue component
*/
public ColorType(float red, float green, float blue) {
this.red = red;
this.green = green;
this.blue = blue;
}

/**
* Set the colour given a particular String specifying either a
* colour name or #RGB or #RRGGBB
* @param value RGB value as String to be parsed
*/
public ColorType(String value) {
if (value.startsWith("#")) {
try {
if (value.length() == 4) {
// note: divide by 15 so F = FF = 1 and so on
this.red = Integer.parseInt(value.substring(1, 2), 16)
/ 15f;
this.green = Integer.parseInt(value.substring(2, 3), 16)
/ 15f;
this.blue = Integer.parseInt(value.substring(3), 16)
/ 15f;
} else if (value.length() == 7) {
// note: divide by 255 so FF = 1
this.red = Integer.parseInt(value.substring(1, 3), 16)
/ 255f;
this.green = Integer.parseInt(value.substring(3, 5), 16)
/ 255f;
this.blue = Integer.parseInt(value.substring(5), 16)
/ 255f;
} else {
this.red = 0;
this.green = 0;
this.blue = 0;
//log.error("unknown colour format. Must be #RGB or #RRGGBB");
}
} catch (Exception e) {
this.red = 0;
this.green = 0;
this.blue = 0;
//log.error("unknown colour format. Must be #RGB or #RRGGBB");
}
} else if (value.startsWith("rgb(")) {
int poss = value.indexOf("(");
int pose = value.indexOf(")");
if (poss != -1 && pose != -1) {
value = value.substring(poss + 1, pose);
StringTokenizer st = new StringTokenizer(value, ",");
try {
if (st.hasMoreTokens()) {
String str = st.nextToken().trim();
if (str.endsWith("%")) {
this.red =
Integer.parseInt(str.substring(0, str.length() - 1))
* 2.55f;
} else {
this.red = Integer.parseInt(str) / 255f;
}
}
if (st.hasMoreTokens()) {
String str = st.nextToken().trim();
if (str.endsWith("%")) {
this.green =
Integer.parseInt(str.substring(0, str.length() - 1))
* 2.55f;
} else {
this.green = Integer.parseInt(str) / 255f;
}
}
if (st.hasMoreTokens()) {
String str = st.nextToken().trim();
if (str.endsWith("%")) {
this.blue =
Integer.parseInt(str.substring(0, str.length() - 1))
* 2.55f;
} else {
this.blue = Integer.parseInt(str) / 255f;
}
}
} catch (Exception e) {
this.red = 0;
this.green = 0;
this.blue = 0;
//log.error("unknown colour format. Must be #RGB or #RRGGBB");
}
}
} else if (value.startsWith("url(")) {
// refers to a gradient
} else {
if (value.toLowerCase().equals("transparent")) {
this.red = 0;
this.green = 0;
this.blue = 0;
this.alpha = 1;
} else {
boolean found = false;
for (int count = 0; count < NAMES.length; count++) {
if (value.toLowerCase().equals(NAMES[count])) {
this.red = VALUES[count][0] / 255f;
this.green = VALUES[count][1] / 255f;
this.blue = VALUES[count][2] / 255f;
found = true;
break;
}
}
if (!found) {
this.red = 0;
this.green = 0;
this.blue = 0;
//log.error("unknown colour name: "
// + value);
}
}
}
}

/**
* Returns the blue component of the color.
* @return float a value between 0.0 and 1.0
*/
public float getBlue() {
return this.blue;
}

/**
* Returns the green component of the color.
* @return float a value between 0.0 and 1.0
*/
public float getGreen() {
return this.green;
}

/**
* Returns the red component of the color.
* @return float a value between 0.0 and 1.0
*/
public float getRed() {
return this.red;
}

/**
* Returns the alpha (transparency) component of the color.
* @return float a value between 0.0 and 1.0
*/
public float alpha() {
return this.alpha;
}

/**
* @see java.lang.Object#toString()
*/
public String toString() {
StringBuffer sbuf = new StringBuffer(8);
sbuf.append('#');
String s = Integer.toHexString((int)(red * 255.0));
if (s.length() == 1) {
sbuf.append('0');
}
sbuf.append(s);
s = Integer.toHexString((int)(green * 255.0));
if (s.length() == 1) {
sbuf.append('0');
}
sbuf.append(s);
s = Integer.toHexString((int)(blue * 255.0));
if (s.length() == 1) {
sbuf.append('0');
}
sbuf.append(s);
return sbuf.toString();
}

/** The names of the predefined colors */
protected static final String[] NAMES = {
"aliceblue", "antiquewhite", "aqua", "aquamarine", "azure", "beige",
"bisque", "black", "blanchedalmond", "blue", "blueviolet", "brown",
"burlywood", "cadetblue", "chartreuse", "chocolate", "coral",
"cornflowerblue", "cornsilk", "crimson", "cyan", "darkblue",
"darkcyan", "darkgoldenrod", "darkgray", "darkgreen", "darkgrey",
"darkkhaki", "darkmagenta", "darkolivegreen", "darkorange",
"darkorchid", "darkred", "darksalmon", "darkseagreen",
"darkslateblue", "darkslategray", "darkslategrey", "darkturquoise",
"darkviolet", "deeppink", "deepskyblue", "dimgray", "dimgrey",
"dodgerblue", "firebrick", "floralwhite", "forestgreen", "fuchsia",
"gainsboro", "lightpink", "lightsalmon", "lightseagreen",
"lightskyblue", "lightslategray", "lightslategrey", "lightsteelblue",
"lightyellow", "lime", "limegreen", "linen", "magenta", "maroon",
"mediumaquamarine", "mediumblue", "mediumorchid", "mediumpurple",
"mediumseagreen", "mediumslateblue", "mediumspringgreen",
"mediumturquoise", "mediumvioletred", "midnightblue", "mintcream",
"mistyrose", "moccasin", "navajowhite", "navy", "oldlace", "olive",
"olivedrab", "orange", "orangered", "orchid", "palegoldenrod",
"palegreen", "paleturquoise", "palevioletred", "papayawhip",
"peachpuff", "peru", "pink", "plum", "powderblue", "purple", "red",
"rosybrown", "royalblue", "saddlebrown", "salmon", "ghostwhite",
"gold", "goldenrod", "gray", "grey", "green", "greenyellow",
"honeydew", "hotpink", "indianred", "indigo", "ivory", "khaki",
"lavender", "lavenderblush", "lawngreen", "lemonchiffon",
"lightblue", "lightcoral", "lightcyan", "lightgoldenrodyellow",
"lightgray", "lightgreen", "lightgrey", "sandybrown", "seagreen",
"seashell", "sienna", "silver", "skyblue", "slateblue", "slategray",
"slategrey", "snow", "springgreen", "steelblue", "tan", "teal",
"thistle", "tomato", "turquoise", "violet", "wheat", "white",
"whitesmoke", "yellow", "yellowgreen"
};

/** The color values for the predefined colors */
protected static final int[][] VALUES = {
{
240, 248, 255
}, {
250, 235, 215
}, {
0, 255, 255
}, {
127, 255, 212
}, {
240, 255, 255
}, {
245, 245, 220
}, {
255, 228, 196
}, {
0, 0, 0
}, {
255, 235, 205
}, {
0, 0, 255
}, {
138, 43, 226
}, {
165, 42, 42
}, {
222, 184, 135
}, {
95, 158, 160
}, {
127, 255, 0
}, {
210, 105, 30
}, {
255, 127, 80
}, {
100, 149, 237
}, {
255, 248, 220
}, {
220, 20, 60
}, {
0, 255, 255
}, {
0, 0, 139
}, {
0, 139, 139
}, {
184, 134, 11
}, {
169, 169, 169
}, {
0, 100, 0
}, {
169, 169, 169
}, {
189, 183, 107
}, {
139, 0, 139
}, {
85, 107, 47
}, {
255, 140, 0
}, {
153, 50, 204
}, {
139, 0, 0
}, {
233, 150, 122
}, {
143, 188, 143
}, {
72, 61, 139
}, {
47, 79, 79
}, {
47, 79, 79
}, {
0, 206, 209
}, {
148, 0, 211
}, {
255, 20, 147
}, {
0, 191, 255
}, {
105, 105, 105
}, {
105, 105, 105
}, {
30, 144, 255
}, {
178, 34, 34
}, {
255, 250, 240
}, {
34, 139, 34
}, {
255, 0, 255
}, {
220, 220, 220
}, {
255, 182, 193
}, {
255, 160, 122
}, {
32, 178, 170
}, {
135, 206, 250
}, {
119, 136, 153
}, {
119, 136, 153
}, {
176, 196, 222
}, {
255, 255, 224
}, {
0, 255, 0
}, {
50, 205, 50
}, {
250, 240, 230
}, {
255, 0, 255
}, {
128, 0, 0
}, {
102, 205, 170
}, {
0, 0, 205
}, {
186, 85, 211
}, {
147, 112, 219
}, {
60, 179, 113
}, {
123, 104, 238
}, {
0, 250, 154
}, {
72, 209, 204
}, {
199, 21, 133
}, {
25, 25, 112
}, {
245, 255, 250
}, {
255, 228, 225
}, {
255, 228, 181
}, {
255, 222, 173
}, {
0, 0, 128
}, {
253, 245, 230
}, {
128, 128, 0
}, {
107, 142, 35
}, {
255, 165, 0
}, {
255, 69, 0
}, {
218, 112, 214
}, {
238, 232, 170
}, {
152, 251, 152
}, {
175, 238, 238
}, {
219, 112, 147
}, {
255, 239, 213
}, {
255, 218, 185
}, {
205, 133, 63
}, {
255, 192, 203
}, {
221, 160, 221
}, {
176, 224, 230
}, {
128, 0, 128
}, {
255, 0, 0
}, {
188, 143, 143
}, {
65, 105, 225
}, {
139, 69, 19
}, {
250, 128, 114
}, {
248, 248, 255
}, {
255, 215, 0
}, {
218, 165, 32
}, {
128, 128, 128
}, {
128, 128, 128
}, {
0, 128, 0
}, {
173, 255, 47
}, {
240, 255, 240
}, {
255, 105, 180
}, {
205, 92, 92
}, {
75, 0, 130
}, {
255, 255, 240
}, {
240, 230, 140
}, {
230, 230, 250
}, {
255, 240, 245
}, {
124, 252, 0
}, {
255, 250, 205
}, {
173, 216, 230
}, {
240, 128, 128
}, {
224, 255, 255
}, {
250, 250, 210
}, {
211, 211, 211
}, {
144, 238, 144
}, {
211, 211, 211
}, {
244, 164, 96
}, {
46, 139, 87
}, {
255, 245, 238
}, {
160, 82, 45
}, {
192, 192, 192
}, {
135, 206, 235
}, {
106, 90, 205
}, {
112, 128, 144
}, {
112, 128, 144
}, {
255, 250, 250
}, {
0, 255, 127
}, {
70, 130, 180
}, {
210, 180, 140
}, {
0, 128, 128
}, {
216, 191, 216
}, {
255, 99, 71
}, {
64, 224, 208
}, {
238, 130, 238
}, {
245, 222, 179
}, {
255, 255, 255
}, {
245, 245, 245
}, {
255, 255, 0
}, {
154, 205, 50
}
};
}

/*
* aliceblue rgb(240, 248, 255)
* antiquewhite rgb(250, 235, 215)
* aqua rgb( 0, 255, 255)
* aquamarine rgb(127, 255, 212)
* azure rgb(240, 255, 255)
* beige rgb(245, 245, 220)
* bisque rgb(255, 228, 196)
* black rgb( 0, 0, 0)
* blanchedalmond rgb(255, 235, 205)
* blue rgb( 0, 0, 255)
* blueviolet rgb(138, 43, 226)
* brown rgb(165, 42, 42)
* burlywood rgb(222, 184, 135)
* cadetblue rgb( 95, 158, 160)
* chartreuse rgb(127, 255, 0)
* chocolate rgb(210, 105, 30)
* coral rgb(255, 127, 80)
* cornflowerblue rgb(100, 149, 237)
* cornsilk rgb(255, 248, 220)
* crimson rgb(220, 20, 60)
* cyan rgb( 0, 255, 255)
* darkblue rgb( 0, 0, 139)
* darkcyan rgb( 0, 139, 139)
* darkgoldenrod rgb(184, 134, 11)
* darkgray rgb(169, 169, 169)
* darkgreen rgb( 0, 100, 0)
* darkgrey rgb(169, 169, 169)
* darkkhaki rgb(189, 183, 107)
* darkmagenta rgb(139, 0, 139)
* darkolivegreen rgb( 85, 107, 47)
* darkorange rgb(255, 140, 0)
* darkorchid rgb(153, 50, 204)
* darkred rgb(139, 0, 0)
* darksalmon rgb(233, 150, 122)
* darkseagreen rgb(143, 188, 143)
* darkslateblue rgb( 72, 61, 139)
* darkslategray rgb( 47, 79, 79)
* darkslategrey rgb( 47, 79, 79)
* darkturquoise rgb( 0, 206, 209)
* darkviolet rgb(148, 0, 211)
* deeppink rgb(255, 20, 147)
* deepskyblue rgb( 0, 191, 255)
* dimgray rgb(105, 105, 105)
* dimgrey rgb(105, 105, 105)
* dodgerblue rgb( 30, 144, 255)
* firebrick rgb(178, 34, 34)
* floralwhite rgb(255, 250, 240)
* forestgreen rgb( 34, 139, 34)
* fuchsia rgb(255, 0, 255)
* gainsboro rgb(220, 220, 220)
* lightpink rgb(255, 182, 193)
* lightsalmon rgb(255, 160, 122)
* lightseagreen rgb( 32, 178, 170)
* lightskyblue rgb(135, 206, 250)
* lightslategray rgb(119, 136, 153)
* lightslategrey rgb(119, 136, 153)
* lightsteelblue rgb(176, 196, 222)
* lightyellow rgb(255, 255, 224)
* lime rgb( 0, 255, 0)
* limegreen rgb( 50, 205, 50)
* linen rgb(250, 240, 230)
* magenta rgb(255, 0, 255)
* maroon rgb(128, 0, 0)
* mediumaquamarine rgb(102, 205, 170)
* mediumblue rgb( 0, 0, 205)
* mediumorchid rgb(186, 85, 211)
* mediumpurple rgb(147, 112, 219)
* mediumseagreen rgb( 60, 179, 113)
* mediumslateblue rgb(123, 104, 238)
* mediumspringgreen rgb( 0, 250, 154)
* mediumturquoise rgb( 72, 209, 204)
* mediumvioletred rgb(199, 21, 133)
* midnightblue rgb( 25, 25, 112)
* mintcream rgb(245, 255, 250)
* mistyrose rgb(255, 228, 225)
* moccasin rgb(255, 228, 181)
* navajowhite rgb(255, 222, 173)
* navy rgb( 0, 0, 128)
* oldlace rgb(253, 245, 230)
* olive rgb(128, 128, 0)
* olivedrab rgb(107, 142, 35)
* orange rgb(255, 165, 0)
* orangered rgb(255, 69, 0)
* orchid rgb(218, 112, 214)
* palegoldenrod rgb(238, 232, 170)
* palegreen rgb(152, 251, 152)
* paleturquoise rgb(175, 238, 238)
* palevioletred rgb(219, 112, 147)
* papayawhip rgb(255, 239, 213)
* peachpuff rgb(255, 218, 185)
* peru rgb(205, 133, 63)
* pink rgb(255, 192, 203)
* plum rgb(221, 160, 221)
* powderblue rgb(176, 224, 230)
* purple rgb(128, 0, 128)
* red rgb(255, 0, 0)
* rosybrown rgb(188, 143, 143)
* royalblue rgb( 65, 105, 225)
* saddlebrown rgb(139, 69, 19)
* salmon rgb(250, 128, 114)
* ghostwhite rgb(248, 248, 255)
* gold rgb(255, 215, 0)
* goldenrod rgb(218, 165, 32)
* gray rgb(128, 128, 128)
* grey rgb(128, 128, 128)
* green rgb( 0, 128, 0)
* greenyellow rgb(173, 255, 47)
* honeydew rgb(240, 255, 240)
* hotpink rgb(255, 105, 180)
* indianred rgb(205, 92, 92)
* indigo rgb( 75, 0, 130)
* ivory rgb(255, 255, 240)
* khaki rgb(240, 230, 140)
* lavender rgb(230, 230, 250)
* lavenderblush rgb(255, 240, 245)
* lawngreen rgb(124, 252, 0)
* lemonchiffon rgb(255, 250, 205)
* lightblue rgb(173, 216, 230)
* lightcoral rgb(240, 128, 128)
* lightcyan rgb(224, 255, 255)
* lightgoldenrodyellow rgb(250, 250, 210)
* lightgray rgb(211, 211, 211)
* lightgreen rgb(144, 238, 144)
* lightgrey rgb(211, 211, 211)
* sandybrown rgb(244, 164, 96)
* seagreen rgb( 46, 139, 87)
* seashell rgb(255, 245, 238)
* sienna rgb(160, 82, 45)
* silver rgb(192, 192, 192)
* skyblue rgb(135, 206, 235)
* slateblue rgb(106, 90, 205)
* slategray rgb(112, 128, 144)
* slategrey rgb(112, 128, 144)
* snow rgb(255, 250, 250)
* springgreen rgb( 0, 255, 127)
* steelblue rgb( 70, 130, 180)
* tan rgb(210, 180, 140)
* teal rgb( 0, 128, 128)
* thistle rgb(216, 191, 216)
* tomato rgb(255, 99, 71)
* turquoise rgb( 64, 224, 208)
* violet rgb(238, 130, 238)
* wheat rgb(245, 222, 179)
* white rgb(255, 255, 255)
* whitesmoke rgb(245, 245, 245)
* yellow rgb(255, 255, 0)
* yellowgreen rgb(154, 205, 50)
*/

+ 74
- 0
src/java/org/apache/fop/datatypes/CompoundDatatype.java View File

@@ -0,0 +1,74 @@
/*
* $Id: CompoundDatatype.java,v 1.3 2003/03/05 20:38:23 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.datatypes;

import org.apache.fop.fo.Property;

/**
* This interface is used as a base for compound datatypes.
*/
public interface CompoundDatatype {
/**
* Sets a component of the compound datatype.
* @param sCmpnName name of the component
* @param cmpnValue value of the component
* @param bIsDefault Indicates if it's the default value
*/
void setComponent(String sCmpnName, Property cmpnValue, boolean bIsDefault);

/**
* Returns a component of the compound datatype.
* @param sCmpnName name of the component
* @return the value of the component
*/
Property getComponent(String sCmpnName);
}

+ 123
- 0
src/java/org/apache/fop/datatypes/CondLength.java View File

@@ -0,0 +1,123 @@
/*
* $Id: CondLength.java,v 1.7 2003/03/05 20:38:23 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.datatypes;

import org.apache.fop.fo.Property;
import org.apache.fop.fo.properties.Constants;

/**
* A space quantity in XSL (space-before, space-after).
* See length-conditional datatype in the specs.
*/
public class CondLength implements CompoundDatatype {

private Property length;
private Property conditionality;

/**
* @see org.apache.fop.datatypes.CompoundDatatype#setComponent(String, Property, boolean)
*/
public void setComponent(String sCmpnName, Property cmpnValue,
boolean bIsDefault) {
if (sCmpnName.equals("length")) {
length = cmpnValue;
} else if (sCmpnName.equals("conditionality")) {
conditionality = cmpnValue;
}
}

/**
* @see org.apache.fop.datatypes.CompoundDatatype#getComponent(String)
*/
public Property getComponent(String sCmpnName) {
if (sCmpnName.equals("length")) {
return length;
} else if (sCmpnName.equals("conditionality")) {
return conditionality;
} else {
return null;
}
}

/**
* Returns the conditionality.
* @return the conditionality
*/
public Property getConditionality() {
return this.conditionality;
}

/**
* Returns the length.
* @return the length
*/
public Property getLength() {
return this.length;
}

/**
* Indicates if the length can be discarded on certain conditions.
* @return true if the length can be discarded.
*/
public boolean isDiscard() {
return this.conditionality.getEnum() == Constants.DISCARD;
}

/**
* Returns the computed length value.
* @return the length in millipoints
*/
public int getLengthValue() {
return this.length.getLength().getValue();
}

}


+ 68
- 0
src/java/org/apache/fop/datatypes/FODimension.java View File

@@ -0,0 +1,68 @@
/*
* $Id: FODimension.java,v 1.3 2003/03/05 20:38:23 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.datatypes;

/**
* This datatype hold a pair of resolved lengths,
* specifiying the dimensions in
* both inline and block-progression-directions.
*/
public class FODimension {

public int ipd;
public int bpd;


public FODimension(int ipd, int bpd) {
this.ipd = ipd;
this.bpd = bpd;
}
}

+ 118
- 0
src/java/org/apache/fop/datatypes/FixedLength.java View File

@@ -0,0 +1,118 @@
/*
* $Id: FixedLength.java,v 1.4 2003/03/05 20:38:23 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.datatypes;

import org.apache.fop.fo.expr.Numeric;

/**
* a length quantity in XSL
*/
public class FixedLength extends Length {

/**
* Set the length given a number of relative units and the current
* font size in base units.
*/
public FixedLength(double numRelUnits, int iCurFontSize) {
setComputedValue((int)(numRelUnits * (double)iCurFontSize));
}

/**
* Set the length given a number of units and a unit name.
*/
public FixedLength(double numUnits, String units) {
convert(numUnits, units);
}

/**
* set the length as a number of base units
*/
public FixedLength(int baseUnits) {
setComputedValue(baseUnits);
}

/**
* Convert the given length to a dimensionless integer representing
* a whole number of base units (milli-points).
*/
protected void convert(double dvalue, String unit) {

int assumedResolution = 1; // points/pixel

if (unit.equals("in")) {
dvalue = dvalue * 72;
} else if (unit.equals("cm")) {
dvalue = dvalue * 28.3464567;
} else if (unit.equals("mm")) {
dvalue = dvalue * 2.83464567;
} else if (unit.equals("pt")) {
dvalue = dvalue;
} else if (unit.equals("pc")) {
dvalue = dvalue * 12;
/*
* } else if (unit.equals("em")) {
* dvalue = dvalue * fontsize;
*/
} else if (unit.equals("px")) {
dvalue = dvalue * assumedResolution;
} else {
dvalue = 0;
//log.error("unknown length unit '" + unit
// + "'");
}
setComputedValue((int)(dvalue * 1000));
}

public Numeric asNumeric() {
return new Numeric(this);
}
}


+ 123
- 0
src/java/org/apache/fop/datatypes/Keep.java View File

@@ -0,0 +1,123 @@
/*
* $Id: Keep.java,v 1.5 2003/03/05 20:38:23 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.datatypes;

import org.apache.fop.fo.Property;

/**
* XSL FO Keep Property datatype (keep-together, etc)
*/
public class Keep implements CompoundDatatype {
private Property withinLine;
private Property withinColumn;
private Property withinPage;

public Keep() {
}

// From CompoundDatatype
public void setComponent(String sCmpnName, Property cmpnValue,
boolean bIsDefault) {
if (sCmpnName.equals("within-line")) {
setWithinLine(cmpnValue, bIsDefault);
} else if (sCmpnName.equals("within-column")) {
setWithinColumn(cmpnValue, bIsDefault);
} else if (sCmpnName.equals("within-page")) {
setWithinPage(cmpnValue, bIsDefault);
}
}

// From CompoundDatatype
public Property getComponent(String sCmpnName) {
if (sCmpnName.equals("within-line")) {
return getWithinLine();
} else if (sCmpnName.equals("within-column")) {
return getWithinColumn();
} else if (sCmpnName.equals("within-page")) {
return getWithinPage();
} else {
return null;
}
}

public void setWithinLine(Property withinLine, boolean bIsDefault) {
this.withinLine = withinLine;
}

protected void setWithinColumn(Property withinColumn,
boolean bIsDefault) {
this.withinColumn = withinColumn;
}

public void setWithinPage(Property withinPage, boolean bIsDefault) {
this.withinPage = withinPage;
}

public Property getWithinLine() {
return this.withinLine;
}

public Property getWithinColumn() {
return this.withinColumn;
}

public Property getWithinPage() {
return this.withinPage;
}

/**
* What to do here?? There isn't really a meaningful single value.
*/
public String toString() {
return "Keep";
}

}

+ 81
- 0
src/java/org/apache/fop/datatypes/KeepValue.java View File

@@ -0,0 +1,81 @@
/*
* $Id: KeepValue.java,v 1.5 2003/03/05 20:38:23 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.datatypes;

/**
* Keep Value
* Stores the different types of keeps in a single convenient format.
*/
public class KeepValue {
public static final String KEEP_WITH_ALWAYS = "KEEP_WITH_ALWAYS";
public static final String KEEP_WITH_AUTO = "KEEP_WITH_AUTO";
public static final String KEEP_WITH_VALUE = "KEEP_WITH_VALUE";
private String type = KEEP_WITH_AUTO;
private int value = 0;

public KeepValue(String type, int val) {
this.type = type;
this.value = val;
}

public int getValue() {
return value;
}

public String getType() {
return type;
}

public String toString() {
return type;
}

}

+ 148
- 0
src/java/org/apache/fop/datatypes/Length.java View File

@@ -0,0 +1,148 @@
/*
* $Id: Length.java,v 1.17 2003/03/05 20:38:23 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.datatypes;

import org.apache.fop.fo.expr.Numeric;

/**
* A length quantity in XSL
*/
public class Length {

/** Holds the length in millipoints. */
protected int millipoints = 0;
/** Indicates if the value has been computed, or not. */
protected boolean bIsComputed = false;

/**
* Returns the length in 1/1000ths of a point (millipoints)
* @return the length in millipoints
*/
public int getValue() {
if (!bIsComputed) {
computeValue();
}
return millipoints;
}

/**
* Computes the value.
*/
protected void computeValue() {
}


/**
* Sets the computed value.
* @param millipoints the length in millipoints
*/
protected void setComputedValue(int millipoints) {
setComputedValue(millipoints, true);
}

/**
* Sets the computed value.
* @param millipoints the length in millipoints
* @param bSetComputed True if the isComputed flag should be set.
*/
protected void setComputedValue(int millipoints, boolean bSetComputed) {
this.millipoints = millipoints;
this.bIsComputed = bSetComputed;
}

/**
* Indicates if the length has the "auto" value.
* @return True if the length is set to "auto"
*/
public boolean isAuto() {
return false;
}

/**
* Indicates if the length has been computed.
* @return True if the length has been computed
*/
public boolean isComputed() {
return this.bIsComputed;
}

/**
* Return the number of table units which are included in this
* length specification.
* This will always be 0 unless the property specification used
* the proportional-column-width() function (only only table
* column FOs).
* <p>If this value is not 0, the actual value of the Length cannot
* be known without looking at all of the columns in the table to
* determine the value of a "table-unit".
* @return The number of table units which are included in this
* length specification.
*/
public double getTableUnits() {
return 0.0;
}

public void resolveTableUnit(double dTableUnit) {
}

public Numeric asNumeric() {
return null;
}

/**
* @see java.lang.Object#toString()
*/
public String toString() {
String s = millipoints + "mpt";
return s;
}

}

+ 136
- 0
src/java/org/apache/fop/datatypes/LengthBase.java View File

@@ -0,0 +1,136 @@
/*
* $Id: LengthBase.java,v 1.9 2003/03/05 20:38:23 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.datatypes;

import org.apache.fop.fo.FObj;
import org.apache.fop.fo.PropertyList;

public class LengthBase implements PercentBase {
// Standard kinds of percent-based length
public static final int CUSTOM_BASE = 0;
public static final int FONTSIZE = 1;
public static final int INH_FONTSIZE = 2;
public static final int CONTAINING_BOX = 3;
public static final int CONTAINING_REFAREA = 4;

/**
* FO parent of the FO for which this property is to be calculated.
*/
protected /* final */ FObj parentFO;

/**
* PropertyList for the FO where this property is calculated.
*/
private /* final */ PropertyList propertyList;

/**
* One of the defined types of LengthBase
*/
private /* final */ int iBaseType;

public LengthBase(FObj parentFO, PropertyList plist, int iBaseType) {
this.parentFO = parentFO;
this.propertyList = plist;
this.iBaseType = iBaseType;
}

/**
* Accessor for parentFO object from subclasses which define
* custom kinds of LengthBase calculations.
*/
protected FObj getParentFO() {
return parentFO;
}

/**
* Accessor for propertyList object from subclasses which define
* custom kinds of LengthBase calculations.
*/
protected PropertyList getPropertyList() {
return propertyList;
}

public int getDimension() {
return 1;
}

public double getBaseValue() {
return 1.0;
}

public int getBaseLength() {
switch (iBaseType) {
case FONTSIZE:
return propertyList.get("font-size").getLength().getValue();
case INH_FONTSIZE:
return propertyList.getInherited("font-size").getLength().getValue();
//case CONTAINING_BOX:
// depends on property?? inline-progression vs block-progression
//return parentFO.getContentWidth();
case CONTAINING_REFAREA: // example: start-indent, end-indent
{
//FONode fo;
//for (fo = parentFO; fo != null && !fo.generatesReferenceAreas();
// fo = fo.getParent());
//return (((fo != null) && (fo instanceof FObj)) ? ((FObj)fo).getContentWidth() : 0);
return 0;
}
case CUSTOM_BASE:
//log.debug("!!! LengthBase.getBaseLength() called on CUSTOM_BASE type !!!");
return 0;
default:
//log.error("Unknown base type for LengthBase.");
return 0;
}
}

}


+ 95
- 0
src/java/org/apache/fop/datatypes/LengthPair.java View File

@@ -0,0 +1,95 @@
/*
* $Id: LengthPair.java,v 1.6 2003/03/05 20:38:24 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.datatypes;

import org.apache.fop.fo.Property;

/**
* This datatype hold a pair of lengths, specifiying the dimensions in
* both inline and block-progression-directions.
* It is currently only used to specify border-separation in tables.
*/
public class LengthPair implements CompoundDatatype {

private Property ipd;
private Property bpd;

// From CompoundDatatype
public void setComponent(String sCmpnName, Property cmpnValue,
boolean bIsDefault) {
if (sCmpnName.equals("block-progression-direction")) {
bpd = cmpnValue;
} else if (sCmpnName.equals("inline-progression-direction")) {
ipd = cmpnValue;
}
}

// From CompoundDatatype
public Property getComponent(String sCmpnName) {
if (sCmpnName.equals("block-progression-direction")) {
return getBPD();
} else if (sCmpnName.equals("inline-progression-direction")) {
return getIPD();
} else {
return null; // SHOULDN'T HAPPEN
}
}

public Property getIPD() {
return this.ipd;
}

public Property getBPD() {
return this.bpd;
}

}


+ 211
- 0
src/java/org/apache/fop/datatypes/LengthRange.java View File

@@ -0,0 +1,211 @@
/*
* $Id: LengthRange.java,v 1.10 2003/03/05 20:38:23 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.datatypes;

import org.apache.fop.fo.Property;

/**
* a "progression-dimension" quantity
* ex. block-progression-dimension, inline-progression-dimension
* corresponds to the triplet min-height, height, max-height (or width)
*/
public class LengthRange implements CompoundDatatype {

private Property minimum;
private Property optimum;
private Property maximum;
private static final int MINSET = 1;
private static final int OPTSET = 2;
private static final int MAXSET = 4;
private int bfSet = 0; // bit field
private boolean bChecked = false;

// From CompoundDatatype
public void setComponent(String sCmpnName, Property cmpnValue,
boolean bIsDefault) {
if (sCmpnName.equals("minimum")) {
setMinimum(cmpnValue, bIsDefault);
} else if (sCmpnName.equals("optimum")) {
setOptimum(cmpnValue, bIsDefault);
} else if (sCmpnName.equals("maximum")) {
setMaximum(cmpnValue, bIsDefault);
}
}

// From CompoundDatatype
public Property getComponent(String sCmpnName) {
if (sCmpnName.equals("minimum")) {
return getMinimum();
} else if (sCmpnName.equals("optimum")) {
return getOptimum();
} else if (sCmpnName.equals("maximum")) {
return getMaximum();
} else {
return null; // SHOULDN'T HAPPEN
}
}

/**
* Set minimum value to min.
* @param minimum A Length value specifying the minimum value for this
* LengthRange.
* @param bIsDefault If true, this is set as a "default" value
* and not a user-specified explicit value.
*/
protected void setMinimum(Property minimum, boolean bIsDefault) {
this.minimum = minimum;
if (!bIsDefault) {
bfSet |= MINSET;
}
}


/**
* Set maximum value to max if it is >= optimum or optimum isn't set.
* @param max A Length value specifying the maximum value for this
* @param bIsDefault If true, this is set as a "default" value
* and not a user-specified explicit value.
*/
protected void setMaximum(Property max, boolean bIsDefault) {
maximum = max;
if (!bIsDefault) {
bfSet |= MAXSET;
}
}


/**
* Set the optimum value.
* @param opt A Length value specifying the optimum value for this
* @param bIsDefault If true, this is set as a "default" value
* and not a user-specified explicit value.
*/
protected void setOptimum(Property opt, boolean bIsDefault) {
optimum = opt;
if (!bIsDefault) {
bfSet |= OPTSET;
}
}

// Minimum is prioritaire, if explicit
private void checkConsistency() {
if (bChecked) {
return;
}
// Make sure max >= min
// Must also control if have any allowed enum values!

/**
* *******************
* if (minimum.mvalue() > maximum.mvalue()) {
* if ((bfSet&MINSET)!=0) {
* // if minimum is explicit, force max to min
* if ((bfSet&MAXSET)!=0) {
* // Warning: min>max, resetting max to min
* log.error("forcing max to min in LengthRange");
* }
* maximum = minimum ;
* }
* else {
* minimum = maximum; // minimum was default value
* }
* }
* // Now make sure opt <= max and opt >= min
* if (optimum.mvalue() > maximum.mvalue()) {
* if ((bfSet&OPTSET)!=0) {
* if ((bfSet&MAXSET)!=0) {
* // Warning: opt > max, resetting opt to max
* log.error("forcing opt to max in LengthRange");
* optimum = maximum ;
* }
* else {
* maximum = optimum; // maximum was default value
* }
* }
* else {
* // opt is default and max is explicit or default
* optimum = maximum ;
* }
* }
* else if (optimum.mvalue() < minimum.mvalue()) {
* if ((bfSet&MINSET)!=0) {
* // if minimum is explicit, force opt to min
* if ((bfSet&OPTSET)!=0) {
* log.error("forcing opt to min in LengthRange");
* }
* optimum = minimum ;
* }
* else {
* minimum = optimum; // minimum was default value
* }
* }
* *******$*******
*/
bChecked = true;
}

public Property getMinimum() {
checkConsistency();
return this.minimum;
}

public Property getMaximum() {
checkConsistency();
return this.maximum;
}

public Property getOptimum() {
checkConsistency();
return this.optimum;
}

}


+ 84
- 0
src/java/org/apache/fop/datatypes/LinearCombinationLength.java View File

@@ -0,0 +1,84 @@
/*
* $Id: LinearCombinationLength.java,v 1.4 2003/03/05 20:38:24 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.datatypes;

import java.util.Vector;

public class LinearCombinationLength extends Length {

protected Vector factors;
protected Vector lengths;

public LinearCombinationLength() {
factors = new Vector();
lengths = new Vector();
}

public void addTerm(double factor, Length length) {
factors.addElement(new Double(factor));
lengths.addElement(length);
}

/**
* Return the computed value in millipoints.
*/
protected void computeValue() {
int result = 0;
int numFactors = factors.size();
for (int i = 0; i < numFactors; ++i) {
result +=
(int)(((Double)factors.elementAt(i)).doubleValue()
* (double)((Length)lengths.elementAt(i)).getValue());
}
setComputedValue(result);
}

}

+ 134
- 0
src/java/org/apache/fop/datatypes/MixedLength.java View File

@@ -0,0 +1,134 @@
/*
* $Id: MixedLength.java,v 1.6 2003/03/05 20:38:23 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.datatypes;

import java.util.Vector;
import java.util.Enumeration;

import org.apache.fop.fo.expr.Numeric;
import org.apache.fop.fo.expr.PropertyException;

/**
* A length quantity in XSL which is specified with a mixture
* of absolute and relative and/or percent components.
* The actual value may not be computable before layout is done.
*/
public class MixedLength extends Length {

private Vector lengths ;

public MixedLength(Vector lengths) {
this.lengths = lengths;
}

protected void computeValue() {
int computedValue = 0;
boolean bAllComputed = true;
Enumeration e = lengths.elements();
while (e.hasMoreElements()) {
Length l = (Length) e.nextElement();
computedValue += l.getValue();
if (!l.isComputed()) {
bAllComputed = false;
}
}
setComputedValue(computedValue, bAllComputed);
}


public double getTableUnits() {
double tableUnits = 0.0;
Enumeration e = lengths.elements();
while (e.hasMoreElements()) {
tableUnits += ((Length) e.nextElement()).getTableUnits();
}
return tableUnits;
}

public void resolveTableUnit(double dTableUnit) {
Enumeration e = lengths.elements();
while (e.hasMoreElements()) {
((Length) e.nextElement()).resolveTableUnit(dTableUnit);
}
}

public String toString() {
StringBuffer sbuf = new StringBuffer();
Enumeration e = lengths.elements();
while (e.hasMoreElements()) {
if (sbuf.length() > 0) {
sbuf.append('+');
}
sbuf.append(e.nextElement().toString());
}
return sbuf.toString();
}

public Numeric asNumeric() {
Numeric numeric = null;
for (Enumeration e = lengths.elements(); e.hasMoreElements();) {
Length l = (Length) e.nextElement();
if (numeric == null) {
numeric = l.asNumeric();
} else {
try {
Numeric sum = numeric.add(l.asNumeric());
numeric = sum;
} catch (PropertyException pe) {
System.err.println(
"Can't convert MixedLength to Numeric: " + pe);
}
}
}
return numeric;
}
}


+ 57
- 0
src/java/org/apache/fop/datatypes/PercentBase.java View File

@@ -0,0 +1,57 @@
/*
* $Id: PercentBase.java,v 1.3 2003/03/05 20:38:23 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.datatypes;

public interface PercentBase {
int getDimension();
double getBaseValue();
int getBaseLength();
}

+ 107
- 0
src/java/org/apache/fop/datatypes/PercentLength.java View File

@@ -0,0 +1,107 @@
/*
* $Id: PercentLength.java,v 1.6 2003/03/05 20:38:23 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.datatypes;

import org.apache.fop.fo.expr.Numeric;

/**
* a percent specified length quantity in XSL
*/
public class PercentLength extends Length {

private double factor;
private PercentBase lbase = null;

/**
* construct an object based on a factor (the percent, as a
* a factor) and an object which has a method to return the
* Length which provides the "base" for this calculation.
*/
public PercentLength(double factor) {
this(factor, null);
}

public PercentLength(double factor, PercentBase lbase) {
this.factor = factor;
this.lbase = lbase;
}

public void setBaseLength(PercentBase lbase) {
this.lbase = lbase;
}

public PercentBase getBaseLength() {
return this.lbase;
}

/**
* Return the computed value in millipoints. This assumes that the
* base length has been resolved to an absolute length value.
*/
protected void computeValue() {
setComputedValue((int)(factor * (double)lbase.getBaseLength()));
}

public double value() {
return factor;
}

public String toString() {
// return the factor as a percent
// What about the base value?
return (new Double(factor * 100.0).toString()) + "%";
}

public Numeric asNumeric() {
return new Numeric(this);
}

}

+ 104
- 0
src/java/org/apache/fop/datatypes/Space.java View File

@@ -0,0 +1,104 @@
/*
* $Id: Space.java,v 1.8 2003/03/05 20:38:23 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.datatypes;

import org.apache.fop.fo.Property;

/**
* a space quantity in XSL (space-before, space-after)
*/
public class Space extends LengthRange {

private Property precedence;
private Property conditionality;

// From CompoundDatatype
public void setComponent(String sCmpnName, Property cmpnValue,
boolean bIsDefault) {
if (sCmpnName.equals("precedence")) {
setPrecedence(cmpnValue, bIsDefault);
} else if (sCmpnName.equals("conditionality")) {
setConditionality(cmpnValue, bIsDefault);
} else {
super.setComponent(sCmpnName, cmpnValue, bIsDefault);
}
}

// From CompoundDatatype
public Property getComponent(String sCmpnName) {
if (sCmpnName.equals("precedence")) {
return getPrecedence();
} else if (sCmpnName.equals("conditionality")) {
return getConditionality();
} else {
return super.getComponent(sCmpnName);
}
}

protected void setPrecedence(Property precedence, boolean bIsDefault) {
this.precedence = precedence;
}

protected void setConditionality(Property conditionality,
boolean bIsDefault) {
this.conditionality = conditionality;
}

public Property getPrecedence() {
return this.precedence;
}

public Property getConditionality() {
return this.conditionality;
}

}


+ 111
- 0
src/java/org/apache/fop/datatypes/TableColLength.java View File

@@ -0,0 +1,111 @@
/*
* $Id: TableColLength.java,v 1.6 2003/03/05 20:38:24 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.datatypes;

import org.apache.fop.fo.expr.Numeric;

/**
* A table-column width specification, possibly including some
* number of proportional "column-units". The absolute size of a
* column-unit depends on the fixed and proportional sizes of all
* columns in the table, and on the overall size of the table.
* It can't be calculated until all columns have been specified and until
* the actual width of the table is known. Since this can be specified
* as a percent of its parent containing width, the calculation is done
* during layout.
* NOTE: this is only supposed to be allowed if table-layout=fixed.
*/
public class TableColLength extends Length {

/**
* Number of table-column proportional units
*/
private double tcolUnits;

/**
* Construct an object with tcolUnits of proportional measure.
*/
public TableColLength(double tcolUnits) {
this.tcolUnits = tcolUnits;
}

/**
* Override the method in Length to return the number of specified
* proportional table-column units.
*/
public double getTableUnits() {
return tcolUnits;
}

/**
* Calculate the number of millipoints and set it.
*/
public void resolveTableUnit(double mpointsPerUnit) {
setComputedValue((int)(tcolUnits * mpointsPerUnit));
}

//If the table-unit can be resolved, set the computed value
/*protected void computeValue() {
if (tblUnitBase.canResolveUnit()) {
rslt += (int)(tcolUnits * (double)tblUnitBase.getUnitValue());
setComputedValue(rslt);
}
}*/

public String toString() {
return (Double.toString(tcolUnits) + " table-column-units");
}

public Numeric asNumeric() {
return new Numeric(this);
}
}


+ 62
- 0
src/java/org/apache/fop/datatypes/ToBeImplemented.java View File

@@ -0,0 +1,62 @@
/*
* $Id: ToBeImplemented.java,v 1.3 2003/03/05 20:38:23 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.datatypes;

/**
* a not as yet implemented value
*/
public class ToBeImplemented {

public ToBeImplemented(String value) {
}

}


+ 87
- 0
src/java/org/apache/fop/datatypes/ToBeImplementedProperty.java View File

@@ -0,0 +1,87 @@
/*
* $Id: ToBeImplementedProperty.java,v 1.6 2003/03/05 20:38:23 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.datatypes;

import org.apache.fop.fo.FObj;
import org.apache.fop.fo.Property;
import org.apache.fop.fo.PropertyList;

public class ToBeImplementedProperty extends Property {

public static class Maker extends Property.Maker {

public Maker(String propName) {
super(propName);
}

public Property convertProperty(Property p,
PropertyList propertyList, FObj fo) {
if (p instanceof ToBeImplementedProperty) {
return p;
}
ToBeImplementedProperty val =
new ToBeImplementedProperty(getPropName());
return val;
}
}

public ToBeImplementedProperty(String propName) {

//XXX: (mjg@recalldesign.com) This is a bit of a kluge, perhaps an
//UnimplementedPropertyException or something similar should
//get thrown here instead.

// Logger log = Hierarchy.getDefaultHierarchy().getLoggerFor("fop");
// log.warn("property - \"" + propName
// + "\" is not implemented yet.");
}
}


+ 6
- 0
src/java/org/apache/fop/datatypes/package.html View File

@@ -0,0 +1,6 @@
<HTML>
<TITLE>org.apache.fop.datatypes Package</TITLE>
<BODY>
<P>XSL Datatypes</P>
</BODY>
</HTML>

+ 271
- 0
src/java/org/apache/fop/extensions/BookmarkData.java View File

@@ -0,0 +1,271 @@
/*
* $Id: BookmarkData.java,v 1.5 2003/03/05 20:40:18 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.extensions;

import org.apache.fop.area.PageViewport;
import org.apache.fop.area.Resolveable;
import org.apache.fop.area.TreeExt;
import org.apache.fop.area.AreaTree;

import java.util.ArrayList;
import java.util.List;
import java.util.HashMap;

/**
* This class holds the PDF bookmark extension data.
* This implements Resolveable and TreeExt so that it can be
* added to the area tree as a resolveable tree extension.
*/
public class BookmarkData implements Resolveable, TreeExt {
private ArrayList subData = new ArrayList();
private HashMap idRefs = new HashMap();

// area tree for the top level object to notify when resolved
private AreaTree areaTree = null;

private String idRef;
private PageViewport pageRef = null;
private String label = null;

/**
* Create a new bookmark data object.
* This should only be call by the top level element as the
* id reference will be null.
*/
public BookmarkData() {
idRef = null;
}

/**
* Create a new pdf bookmark data object.
* This is used by the outlines to create a data object
* with a id reference. The id reference is to be resolved.
*
* @param id the id reference
*/
public BookmarkData(String id) {
idRef = id;
idRefs.put(idRef, this);
}

/**
* Set the area tree.
* This should only be called for the top level element.
* The area tree is used once resolving is complete.
*
* @param at the area tree for the current document
*/
public void setAreaTree(AreaTree at) {
areaTree = at;
}

/**
* Get the id reference for this data.
*
* @return the id reference
*/
public String getID() {
return idRef;
}

/**
* Add the child bookmark data object.
* This adds a child bookmark in the bookmark hierarchy.
*
* @param sub the child bookmark data
*/
public void addSubData(BookmarkData sub) {
subData.add(sub);
idRefs.put(sub.getID(), sub);
String[] ids = sub.getIDs();
for (int count = 0; count < ids.length; count++) {
idRefs.put(ids[count], sub);
}
}

/**
* Set the label for this bookmark.
*
* @param l the string label
*/
public void setLabel(String l) {
label = l;
}

/**
* Get the label for this bookmark object.
*
* @return the label string
*/
public String getLabel() {
return label;
}

/**
* Get the size of child data objects.
*
* @return the number of child bookmark data
*/
public int getCount() {
return subData.size();
}

/**
* Get the child data object.
*
* @param count the index to get
* @return the child bookmark data
*/
public BookmarkData getSubData(int count) {
return (BookmarkData)subData.get(count);
}

/**
* Get the page that this resolves to.
*
* @return the PageViewport that this extension resolves to
*/
public PageViewport getPage() {
return pageRef;
}

/**
* Check if this tree extension is resolveable.
*
* @return true since this also implements Resolveable
*/
public boolean isResolveable() {
return true;
}

/**
* Get the mime type of this area tree extension.
*
* @return this tree extension applies to pdf
*/
public String getMimeType() {
return "application/pdf";
}

/**
* Get the name of this area tree extension.
*
* @return the name of the PDF bookmark extension is "Bookmark"
*/
public String getName() {
return "Bookmark";
}

/**
* Check if this resolveable object has been resolved.
* Once the id reference is null then it has been resolved.
*
* @return true if this has been resolved
*/
public boolean isResolved() {
return idRefs == null;
}

/**
* Get the id references held by this object.
* Also includes all id references of all children.
*
* @return the array of id references
*/
public String[] getIDs() {
return (String[])idRefs.keySet().toArray(new String[] {});
}

/**
* Resolve this resolveable object.
* This resolves the id reference and if possible also
* resolves id references of child elements that have the same
* id reference.
*
* @param id the id reference being resolved
* @param pages the list of pages the the id reference resolves to
*/
public void resolve(String id, List pages) {
// this method is buggy

if (!id.equals(idRef)) {
BookmarkData bd = (BookmarkData)idRefs.get(id);
idRefs.remove(id);
if (bd != null) {
bd.resolve(id, pages);
if (bd.isResolved()) {
checkFinish();
}
} else if (idRef == null) {
checkFinish();
}
} else {
if (pages != null) {
pageRef = (PageViewport)pages.get(0);
}
// TODO
// get rect area of id on page

idRefs.remove(idRef);
checkFinish();
}
}

private void checkFinish() {
if (idRefs.size() == 0) {
idRefs = null;
if (areaTree != null) {
areaTree.handleTreeExtension(this, TreeExt.AFTER_PAGE);
}
}
}
}


+ 118
- 0
src/java/org/apache/fop/extensions/Bookmarks.java View File

@@ -0,0 +1,118 @@
/*
* $Id: Bookmarks.java,v 1.7 2003/03/05 20:40:18 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.extensions;

import org.apache.fop.apps.LayoutHandler;
import org.apache.fop.fo.FONode;
import org.apache.fop.area.AreaTree;

import java.util.ArrayList;

/**
* Bookmarks data is the top level element of the pdf bookmark extension.
* This handles the adding of outlines. When the element is ended it
* creates the bookmark data and adds to the area tree.
*/
public class Bookmarks extends ExtensionObj {
private ArrayList outlines = new ArrayList();
private BookmarkData data;

/**
* Create a new Bookmarks object.
*
* @param parent the parent fo node
*/
public Bookmarks(FONode parent) {
super(parent);
}

/**
* Add the child to the top level.
* This handles all Outline objects added and ignores others.
*
* @param obj the child to add
*/
protected void addChild(FONode obj) {
if (obj instanceof Outline) {
outlines.add(obj);
}
}

/**
* Get the data created for this bookmark.
*
* @return the bookmark data
*/
public BookmarkData getData() {
return data;
}

/**
* When this element is finished then it can create
* the bookmark data from the child elements and add
* the extension to the area tree.
*/
public void end() {
getLogger().debug("adding bookmarks to area tree");
data = new BookmarkData();
for (int count = 0; count < outlines.size(); count++) {
Outline out = (Outline)outlines.get(count);
data.addSubData(out.getData());
}
// add data to area tree for resolving and handling
if (structHandler instanceof LayoutHandler) {
AreaTree at = ((LayoutHandler)structHandler).getAreaTree();
at.addTreeExtension(data);
data.setAreaTree(at);
}
}
}


+ 111
- 0
src/java/org/apache/fop/extensions/ExtensionElementMapping.java View File

@@ -0,0 +1,111 @@
/*
* $Id: ExtensionElementMapping.java,v 1.10 2003/03/05 20:40:18 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.extensions;

import org.apache.fop.fo.FONode;
import org.apache.fop.fo.ElementMapping;
import org.apache.fop.fo.FOTreeBuilder;

import java.util.HashMap;

/**
* Element mapping for the pdf bookmark extension.
* This sets up the mapping for the classes that handle the
* pdf bookmark extension.
*/
public class ExtensionElementMapping implements ElementMapping {
/**
* The pdf bookmark extension uri
*/
public static final String URI = "http://xml.apache.org/fop/extensions";

// the mappings are only setup once and resued after that
private static HashMap foObjs = null;

private static synchronized void setupExt() {
if (foObjs == null) {
foObjs = new HashMap();
foObjs.put("bookmarks", new B());
foObjs.put("outline", new O());
foObjs.put("label", new L());
}
}

/**
* Add the mappings to the fo tree builder.
*
* @param builder the fo tree builder to add the mappings
*/
public void addToBuilder(FOTreeBuilder builder) {
if (foObjs == null) {
setupExt();
}
builder.addMapping(URI, foObjs);
}

static class B extends ElementMapping.Maker {
public FONode make(FONode parent) {
return new Bookmarks(parent);
}
}

static class O extends ElementMapping.Maker {
public FONode make(FONode parent) {
return new Outline(parent);
}
}

static class L extends ElementMapping.Maker {
public FONode make(FONode parent) {
return new Label(parent);
}
}
}

+ 71
- 0
src/java/org/apache/fop/extensions/ExtensionObj.java View File

@@ -0,0 +1,71 @@
/*
* $Id: ExtensionObj.java,v 1.7 2003/03/05 20:40:18 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.extensions;

import org.apache.fop.fo.FONode;
import org.apache.fop.fo.FObj;

/**
* Base class for pdf bookmark extension objects.
*/
public abstract class ExtensionObj extends FObj {

/**
* Create a new extension object.
*
* @param parent the parent formatting object
*/
public ExtensionObj(FONode parent) {
super(parent);
}

}


+ 92
- 0
src/java/org/apache/fop/extensions/Label.java View File

@@ -0,0 +1,92 @@
/*
* $Id: Label.java,v 1.7 2003/03/05 20:40:18 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.extensions;

import org.apache.fop.fo.FONode;

/**
* Labal for PDF bookmark extension.
* This element contains the label for the bookmark object.
*/
public class Label extends ExtensionObj {
private String label = "";

/**
* Create a new label object.
*
* @param parent the fo node parent
*/
public Label(FONode parent) {
super(parent);
}

/**
* Add the characters to this label.
* The text data inside the label xml element is used for the label string.
*
* @param data the character data
* @param start the start position in the data array
* @param end the end position in the character array
*/
protected void addCharacters(char data[], int start, int end) {
label += new String(data, start, end - start);
}

/**
* Get the string for this label.
*
* @return the label string
*/
public String toString() {
return label;
}

}

+ 144
- 0
src/java/org/apache/fop/extensions/Outline.java View File

@@ -0,0 +1,144 @@
/*
* $Id: Outline.java,v 1.10 2003/03/05 20:40:18 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.extensions;

import org.apache.fop.fo.FONode;
import org.apache.fop.apps.FOPException;

import java.util.ArrayList;

import org.xml.sax.Attributes;

/**
* The outline object for the pdf bookmark extension.
* The outline element contains a label and optionally more outlines.
*/
public class Outline extends ExtensionObj {
private Label label;
private ArrayList outlines = new ArrayList();

private String internalDestination;
private String externalDestination;

/**
* Create a new outline object.
*
* @param parent the parent fo node
*/
public Outline(FONode parent) {
super(parent);
}

/**
* The attribues on the outline object are the internal and external
* destination. One of these is required.
*
* @param attlist the attribute list
* @throws FOPException a fop exception if there is an error
*/
public void handleAttrs(Attributes attlist) throws FOPException {
internalDestination =
attlist.getValue("internal-destination");
externalDestination =
attlist.getValue("external-destination");
if (externalDestination != null && !externalDestination.equals("")) {
getLogger().warn("fox:outline external-destination not supported currently.");
}

if (internalDestination == null || internalDestination.equals("")) {
getLogger().warn("fox:outline requires an internal-destination.");
}

}

/**
* Add the child to this outline.
* This checks for the type, label or outline and handles appropriately.
*
* @param obj the child object
*/
protected void addChild(FONode obj) {
if (obj instanceof Label) {
label = (Label)obj;
} else if (obj instanceof Outline) {
outlines.add(obj);
}
}

/**
* Get the bookmark data for this outline.
* This creates a bookmark data with the destination
* and adds all the data from child outlines.
*
* @return the new bookmark data
*/
public BookmarkData getData() {
BookmarkData data = new BookmarkData(internalDestination);
data.setLabel(getLabel());
for (int count = 0; count < outlines.size(); count++) {
Outline out = (Outline)outlines.get(count);
data.addSubData(out.getData());
}
return data;
}

/**
* Get the label string.
* This gets the label string from the child label element.
*
* @return the label string or empty if not found
*/
public String getLabel() {
return label == null ? "" : label.toString();
}

}


+ 102
- 0
src/java/org/apache/fop/fo/AbstractCharIterator.java View File

@@ -0,0 +1,102 @@
/*
* $Id: AbstractCharIterator.java,v 1.4 2003/03/05 21:48:01 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.fo;

import java.util.NoSuchElementException;

/**
* Abstract base class for character iterators.
*/
public abstract class AbstractCharIterator implements CharIterator, Cloneable {

/**
* @see java.util.Iterator#hasNext()
*/
public abstract boolean hasNext();

/**
* @see org.apache.fop.fo.CharIterator#nextChar()
*/
public abstract char nextChar() throws NoSuchElementException ;

/**
* @see java.util.Iterator#next()
*/
public Object next() throws NoSuchElementException {
return new Character(nextChar());
}

/**
* @see java.util.Iterator#remove()
*/
public void remove() {
throw new UnsupportedOperationException();
}


/**
* @see org.apache.fop.fo.CharIterator#replaceChar(char)
*/
public void replaceChar(char c) {
}

/**
* @see java.lang.Object#clone()
*/
public Object clone() {
try {
return super.clone();
} catch (CloneNotSupportedException ex) {
return null;
}
}
}


+ 88
- 0
src/java/org/apache/fop/fo/BoxPropShorthandParser.java View File

@@ -0,0 +1,88 @@
/*
* $Id: BoxPropShorthandParser.java,v 1.3 2003/03/05 21:48:01 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.fo;

public class BoxPropShorthandParser extends GenericShorthandParser {

/**
* @see org.apache.fop.fo.GenericShorthandParser#GenericShorthandParser(ListProperty)
*/
public BoxPropShorthandParser(ListProperty listprop) {
super(listprop);
}

/**
* Stores 1 to 4 values of same type.
* Set the given property based on the number of values set.
* Example: padding, border-width, border-color, border-style, margin
* @see org.apache.fop.fo.GenericShorthandParser#convertValueForProperty(String, Maker, PropertyList)
*/
protected Property convertValueForProperty(String propName,
Property.Maker maker,
PropertyList propertyList) {
Property p = null;
if (propName.indexOf("-top") >= 0) {
p = getElement(0);
} else if (propName.indexOf("-right") >= 0) {
p = getElement(count() > 1 ? 1 : 0);
} else if (propName.indexOf("-bottom") >= 0) {
p = getElement(count() > 2 ? 2 : 0);
} else if (propName.indexOf("-left") >= 0) {
p = getElement(count() > 3 ? 3 : (count() > 1 ? 1 : 0));
}
// if p not null, try to convert it to a value of the correct type
if (p != null) {
return maker.convertShorthandProperty(propertyList, p, null);
}
return p;
}

}

+ 62
- 0
src/java/org/apache/fop/fo/CharIterator.java View File

@@ -0,0 +1,62 @@
/*
* $Id: CharIterator.java,v 1.2 2003/03/05 21:48:01 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.fo;

import java.util.Iterator;
import java.util.NoSuchElementException;


public interface CharIterator extends Iterator {

char nextChar() throws NoSuchElementException ;
void replaceChar(char c);
Object clone();
}

+ 87
- 0
src/java/org/apache/fop/fo/CharacterProperty.java View File

@@ -0,0 +1,87 @@
/*
* $Id: CharacterProperty.java,v 1.3 2003/03/05 21:48:02 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.fo;

public class CharacterProperty extends Property {

public static class Maker extends Property.Maker {

public Maker(String propName) {
super(propName);
}

public Property make(PropertyList propertyList, String value,
FObj fo) {
char c = value.charAt(0);
return new CharacterProperty(c);
}

} // end Charakter.Maker

private char character;

public CharacterProperty(char character) {
this.character = character;
}

public Object getObject() {
return new Character(character);
}

public char getCharacter() {
return this.character;
}

public String getString() {
return new Character(character).toString();
}

}

+ 120
- 0
src/java/org/apache/fop/fo/ColorProfile.java View File

@@ -0,0 +1,120 @@
/*
* $Id: ColorProfile.java,v 1.10 2003/03/05 21:48:01 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.fo;

// Java
import java.awt.color.ICC_Profile;
import java.awt.color.ICC_ColorSpace;
import java.net.URL;
import java.io.IOException;
import java.io.InputStream;

// FOP
import org.apache.fop.datatypes.ColorType;

/**
* The fo:color-profile formatting object.
* This loads the color profile when needed and resolves a requested color.
*/
public class ColorProfile extends FObj {
private int intent;
private String src;
private String profileName;
private ICC_ColorSpace colorSpace = null;

/**
* @see org.apache.fop.fo.FONode#FONode(FONode)
*/
protected ColorProfile(FONode parent) {
super(parent);
}

public void end() {
src = this.properties.get("src").getString();
profileName = this.properties.get("color-profile-name").getString();
intent = this.properties.get("rendering-intent").getEnum();
this.properties = null;
}

/**
* Get the name of this color profile.
*/
public String getProfileName() {
return profileName;
}

/**
* Get the color specified with the color values from the color profile.
* The default values are used if the profile could not be loaded
* or the value is not found.
*/
public ColorType getColor(int[] colorVals, int defR, int defG, int defB) {
// float[] rgbvals = colorSpace.toRGB(colorVals);
// return new ColorType(rgbvals);
return null;
}

/**
* Load the color profile.
*/
private void load() {
try {
URL url = new URL(src);
InputStream is = url.openStream();
ICC_Profile iccProfile = ICC_Profile.getInstance(is);
colorSpace = new ICC_ColorSpace(iccProfile);
} catch (IOException ioe) {
getLogger().error("Could not read Color Profile src", ioe);
} catch (IllegalArgumentException iae) {
getLogger().error("Color Profile src not an ICC Profile", iae);
}
}
}

+ 93
- 0
src/java/org/apache/fop/fo/ColorTypeProperty.java View File

@@ -0,0 +1,93 @@
/*
* $Id: ColorTypeProperty.java,v 1.5 2003/03/05 21:48:02 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.fo;

import org.apache.fop.datatypes.ColorType;

public class ColorTypeProperty extends Property {

public static class Maker extends Property.Maker {

public Maker(String propName) {
super(propName);
}

public Property convertProperty(Property p,
PropertyList propertyList, FObj fo) {
if (p instanceof ColorTypeProperty) {
return p;
}
ColorType val = p.getColorType();
if (val != null) {
return new ColorTypeProperty(val);
}
return convertPropertyDatatype(p, propertyList, fo);
}

}

private ColorType colorType;

public ColorTypeProperty(ColorType colorType) {
this.colorType = colorType;
}

// Can't convert to any other types
public ColorType getColorType() {
return this.colorType;
}

public Object getObject() {
return this.colorType;
}

}


+ 85
- 0
src/java/org/apache/fop/fo/CondLengthProperty.java View File

@@ -0,0 +1,85 @@
/*
* $Id: CondLengthProperty.java,v 1.5 2003/03/05 21:48:01 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.fo;

import org.apache.fop.datatypes.Length;
import org.apache.fop.datatypes.CondLength;

public class CondLengthProperty extends Property {

public static class Maker extends Property.Maker {

public Maker(String name) {
super(name);
}

}

private CondLength condLength = null;

public CondLengthProperty(CondLength condLength) {
this.condLength = condLength;
}

public CondLength getCondLength() {
return this.condLength;
}

/* Question, should we allow this? */
public Length getLength() {
return this.condLength.getLength().getLength();
}

public Object getObject() {
return this.condLength;
}

}

+ 107
- 0
src/java/org/apache/fop/fo/Declarations.java View File

@@ -0,0 +1,107 @@
/*
* $Id: Declarations.java,v 1.8 2003/03/05 21:48:01 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.fo;

// Java
import java.util.List;
import java.util.Map;
import java.util.Iterator;

/**
* Declarations formatting object.
* A declarations formatting object holds a set of color-profiles
* and optionally additional non-XSL namespace elements.
* The color-profiles are held in a hashmap for use with color-profile
* references.
*/
public class Declarations extends FObj {
private Map colorProfiles = null;
private List external = null;

protected Declarations(FONode parent) {
super(parent);
}

/**
* At then end of this element sort out the child into
* a hashmap of color profiles and a list of external xml.
*/
public void end() {
for (Iterator iter = children.iterator(); iter.hasNext();) {
FONode node = (FONode)iter.next();
if (node.getName().equals("fo:color-profile")) {
ColorProfile cp = (ColorProfile)node;
if (!"".equals(cp.getProfileName())) {
if (colorProfiles == null) {
colorProfiles = new java.util.HashMap();
}
if (colorProfiles.get(cp.getProfileName()) != null) {
// duplicate names
getLogger().warn("Duplicate fo:color-profile profile name : "
+ cp.getProfileName());
}
colorProfiles.put(cp.getProfileName(), cp);
} else {
getLogger().warn("color-profile-name required for color profile");
}
} else if (node instanceof XMLObj) {
if (external == null) {
external = new java.util.ArrayList();
}
external.add(node);
} else {
getLogger().warn("invalid element " + node.getName() + "inside declarations");
}
}
children = null;
}
}

+ 67
- 0
src/java/org/apache/fop/fo/ElementMapping.java View File

@@ -0,0 +1,67 @@
/*
* $Id: ElementMapping.java,v 1.11 2003/03/05 21:48:02 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.fo;

/**
* Interface for adding supported element and property mappings to
* the given builder.
*/
public interface ElementMapping {
final String DEFAULT = "<default>";

void addToBuilder(FOTreeBuilder builder);

public static class Maker {
public FONode make(FONode parent) {
return null;
}
}
}

+ 104
- 0
src/java/org/apache/fop/fo/EnumProperty.java View File

@@ -0,0 +1,104 @@
/*
* $Id: EnumProperty.java,v 1.8 2003/03/05 21:48:01 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.fo;

import org.apache.fop.apps.FOPException;

public class EnumProperty extends Property {

public static class Maker extends Property.Maker {

protected Maker(String propName) {
super(propName);
}

/**
* Called by subclass if no match found.
*/
public Property checkEnumValues(String value) {
//log.error("Unknown enumerated value for property '"
// + getPropName() + "': " + value);
return null;
}

protected Property findConstant(String value) {
return null;
}

public Property convertProperty(Property p,
PropertyList propertyList,
FObj fo) throws FOPException {
if (p instanceof EnumProperty) {
return p;
} else {
return null;
}
}
}

private int value;

public EnumProperty(int explicitValue) {
this.value = explicitValue;
}

public int getEnum() {
return this.value;
}

public Object getObject() {
// FIXME: return String value: property must reference maker
// return maker.getEnumValue(this.value);
return new Integer(this.value);
}

}


+ 486
- 0
src/java/org/apache/fop/fo/FOElementMapping.java View File

@@ -0,0 +1,486 @@
/*
* $Id: FOElementMapping.java,v 1.5 2003/03/05 21:48:02 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.fo;

// Java
import java.util.HashMap;

/**
* Element mapping class for all XSL-FO elements.
*/
public class FOElementMapping implements ElementMapping {
private static HashMap foObjs = null;

private static synchronized void setupFO() {
if (foObjs == null) {
foObjs = new HashMap();

// Declarations and Pagination and Layout Formatting Objects
foObjs.put("root", new R());
foObjs.put("declarations", new Dec());
foObjs.put("color-profile", new CP());
foObjs.put("page-sequence", new PS());
foObjs.put("layout-master-set", new LMS());
foObjs.put("page-sequence-master",
new PSM());
foObjs.put("single-page-master-reference",
new SPMR());
foObjs.put("repeatable-page-master-reference",
new RPMR());
foObjs.put("repeatable-page-master-alternatives",
new RPMA());
foObjs.put("conditional-page-master-reference",
new CPMR());
foObjs.put("simple-page-master",
new SPM());
foObjs.put("region-body", new RB());
foObjs.put("region-before", new RBefore());
foObjs.put("region-after", new RA());
foObjs.put("region-start", new RS());
foObjs.put("region-end", new RE());
foObjs.put("flow", new Fl());
foObjs.put("static-content", new SC());
foObjs.put("title", new T());

// Block-level Formatting Objects
foObjs.put("block", new B());
foObjs.put("block-container", new BC());

// Inline-level Formatting Objects
foObjs.put("bidi-override", new BO());
foObjs.put("character",
new Ch());
foObjs.put("initial-property-set",
new IPS());
foObjs.put("external-graphic", new EG());
foObjs.put("instream-foreign-object",
new IFO());
foObjs.put("inline", new In());
foObjs.put("inline-container", new IC());
foObjs.put("leader", new L());
foObjs.put("page-number", new PN());
foObjs.put("page-number-citation",
new PNC());

// Formatting Objects for Tables
foObjs.put("table-and-caption", new TAC());
foObjs.put("table", new Ta());
foObjs.put("table-column", new TC());
foObjs.put("table-caption", new TCaption());
foObjs.put("table-header", new TB());
foObjs.put("table-footer", new TB());
foObjs.put("table-body", new TB());
foObjs.put("table-row", new TR());
foObjs.put("table-cell", new TCell());

// Formatting Objects for Lists
foObjs.put("list-block", new LB());
foObjs.put("list-item", new LI());
foObjs.put("list-item-body", new LIB());
foObjs.put("list-item-label", new LIL());

// Dynamic Effects: Link and Multi Formatting Objects
foObjs.put("basic-link", new BL());
foObjs.put("multi-switch", new MS());
foObjs.put("multi-case", new MC());
foObjs.put("multi-toggle", new MT());
foObjs.put("multi-properties", new MP());
foObjs.put("multi-property-set",
new MPS());

// Out-of-Line Formatting Objects
foObjs.put("float",
new F());
foObjs.put("footnote", new Foot());
foObjs.put("footnote-body", new FB());

// Other Formatting Objects
foObjs.put("wrapper", new W());
foObjs.put("marker", new M());
foObjs.put("retrieve-marker", new RM());
}

}

/**
* @see org.apache.fop.fo.ElementMapping#addToBuilder(FOTreeBuilder)
*/
public void addToBuilder(FOTreeBuilder builder) {
setupFO();
String uri = "http://www.w3.org/1999/XSL/Format";
builder.addMapping(uri, foObjs);
}

static class R extends ElementMapping.Maker {
public FONode make(FONode parent) {
return new org.apache.fop.fo.pagination.Root(parent);
}
}

static class Dec extends ElementMapping.Maker {
public FONode make(FONode parent) {
return new Declarations(parent);
}
}

static class CP extends ElementMapping.Maker {
public FONode make(FONode parent) {
return new ColorProfile(parent);
}
}

static class PS extends ElementMapping.Maker {
public FONode make(FONode parent) {
return new org.apache.fop.fo.pagination.PageSequence(parent);
}
}

static class LMS extends ElementMapping.Maker {
public FONode make(FONode parent) {
return new org.apache.fop.fo.pagination.LayoutMasterSet(parent);
}
}

static class PSM extends ElementMapping.Maker {
public FONode make(FONode parent) {
return new org.apache.fop.fo.pagination.PageSequenceMaster(parent);
}
}

static class SPMR extends ElementMapping.Maker {
public FONode make(FONode parent) {
return new org.apache.fop.fo.pagination.SinglePageMasterReference(parent);
}
}

static class RPMR extends ElementMapping.Maker {
public FONode make(FONode parent) {
return new org.apache.fop.fo.pagination.RepeatablePageMasterReference(parent);
}
}

static class RPMA extends ElementMapping.Maker {
public FONode make(FONode parent) {
return new org.apache.fop.fo.pagination.RepeatablePageMasterAlternatives(parent);
}
}

static class CPMR extends ElementMapping.Maker {
public FONode make(FONode parent) {
return new org.apache.fop.fo.pagination.ConditionalPageMasterReference(parent);
}
}

static class SPM extends ElementMapping.Maker {
public FONode make(FONode parent) {
return new org.apache.fop.fo.pagination.SimplePageMaster(parent);
}
}

static class RB extends ElementMapping.Maker {
public FONode make(FONode parent) {
return new org.apache.fop.fo.pagination.RegionBody(parent);
}
}

static class RBefore extends ElementMapping.Maker {
public FONode make(FONode parent) {
return new org.apache.fop.fo.pagination.RegionBefore(parent);
}
}

static class RA extends ElementMapping.Maker {
public FONode make(FONode parent) {
return new org.apache.fop.fo.pagination.RegionAfter(parent);
}
}

static class RS extends ElementMapping.Maker {
public FONode make(FONode parent) {
return new org.apache.fop.fo.pagination.RegionStart(parent);
}
}

static class RE extends ElementMapping.Maker {
public FONode make(FONode parent) {
return new org.apache.fop.fo.pagination.RegionEnd(parent);
}
}

static class Fl extends ElementMapping.Maker {
public FONode make(FONode parent) {
return new org.apache.fop.fo.flow.Flow(parent);
}
}

static class SC extends ElementMapping.Maker {
public FONode make(FONode parent) {
return new org.apache.fop.fo.flow.StaticContent(parent);
}
}

static class T extends ElementMapping.Maker {
public FONode make(FONode parent) {
return new Title(parent);
}
}

static class B extends ElementMapping.Maker {
public FONode make(FONode parent) {
return new org.apache.fop.fo.flow.Block(parent);
}
}

static class BC extends ElementMapping.Maker {
public FONode make(FONode parent) {
return new org.apache.fop.fo.flow.BlockContainer(parent);
}
}

static class BO extends ElementMapping.Maker {
public FONode make(FONode parent) {
return new org.apache.fop.fo.flow.BidiOverride(parent);
}
}

static class Ch extends ElementMapping.Maker {
public FONode make(FONode parent) {
return new org.apache.fop.fo.flow.Character(parent);
}
}

static class IPS extends ElementMapping.Maker {
public FONode make(FONode parent) {
return new org.apache.fop.fo.flow.InitialPropertySet(parent);
}
}

static class EG extends ElementMapping.Maker {
public FONode make(FONode parent) {
return new org.apache.fop.fo.flow.ExternalGraphic(parent);
}
}

static class IFO extends ElementMapping.Maker {
public FONode make(FONode parent) {
return new org.apache.fop.fo.flow.InstreamForeignObject(parent);
}
}

static class In extends ElementMapping.Maker {
public FONode make(FONode parent) {
return new org.apache.fop.fo.flow.Inline(parent);
}
}

static class IC extends ElementMapping.Maker {
public FONode make(FONode parent) {
return new org.apache.fop.fo.flow.InlineContainer(parent);
}
}

static class L extends ElementMapping.Maker {
public FONode make(FONode parent) {
return new org.apache.fop.fo.flow.Leader(parent);
}
}

static class PN extends ElementMapping.Maker {
public FONode make(FONode parent) {
return new org.apache.fop.fo.flow.PageNumber(parent);
}
}

static class PNC extends ElementMapping.Maker {
public FONode make(FONode parent) {
return new org.apache.fop.fo.flow.PageNumberCitation(parent);
}
}

static class TAC extends ElementMapping.Maker {
public FONode make(FONode parent) {
return new org.apache.fop.fo.flow.TableAndCaption(parent);
}
}

static class Ta extends ElementMapping.Maker {
public FONode make(FONode parent) {
return new org.apache.fop.fo.flow.Table(parent);
}
}

static class TC extends ElementMapping.Maker {
public FONode make(FONode parent) {
return new org.apache.fop.fo.flow.TableColumn(parent);
}
}

static class TCaption extends ElementMapping.Maker {
public FONode make(FONode parent) {
return new org.apache.fop.fo.flow.TableCaption(parent);
}
}

static class TB extends ElementMapping.Maker {
public FONode make(FONode parent) {
return new org.apache.fop.fo.flow.TableBody(parent);
}
}

static class TR extends ElementMapping.Maker {
public FONode make(FONode parent) {
return new org.apache.fop.fo.flow.TableRow(parent);
}
}

static class TCell extends ElementMapping.Maker {
public FONode make(FONode parent) {
return new org.apache.fop.fo.flow.TableCell(parent);
}
}

static class LB extends ElementMapping.Maker {
public FONode make(FONode parent) {
return new org.apache.fop.fo.flow.ListBlock(parent);
}
}

static class LI extends ElementMapping.Maker {
public FONode make(FONode parent) {
return new org.apache.fop.fo.flow.ListItem(parent);
}
}

static class LIB extends ElementMapping.Maker {
public FONode make(FONode parent) {
return new org.apache.fop.fo.flow.ListItemBody(parent);
}
}

static class LIL extends ElementMapping.Maker {
public FONode make(FONode parent) {
return new org.apache.fop.fo.flow.ListItemLabel(parent);
}
}

static class BL extends ElementMapping.Maker {
public FONode make(FONode parent) {
return new org.apache.fop.fo.flow.BasicLink(parent);
}
}

static class MS extends ElementMapping.Maker {
public FONode make(FONode parent) {
return new org.apache.fop.fo.flow.MultiSwitch(parent);
}
}

static class MC extends ElementMapping.Maker {
public FONode make(FONode parent) {
return new org.apache.fop.fo.flow.MultiCase(parent);
}
}

static class MT extends ElementMapping.Maker {
public FONode make(FONode parent) {
return new org.apache.fop.fo.flow.MultiToggle(parent);
}
}

static class MP extends ElementMapping.Maker {
public FONode make(FONode parent) {
return new org.apache.fop.fo.flow.MultiProperties(parent);
}
}

static class MPS extends ElementMapping.Maker {
public FONode make(FONode parent) {
return new org.apache.fop.fo.flow.MultiPropertySet(parent);
}
}

static class F extends ElementMapping.Maker {
public FONode make(FONode parent) {
return new org.apache.fop.fo.flow.Float(parent);
}
}

static class Foot extends ElementMapping.Maker {
public FONode make(FONode parent) {
return new org.apache.fop.fo.flow.Footnote(parent);
}
}

static class FB extends ElementMapping.Maker {
public FONode make(FONode parent) {
return new org.apache.fop.fo.flow.FootnoteBody(parent);
}
}

static class W extends ElementMapping.Maker {
public FONode make(FONode parent) {
return new org.apache.fop.fo.flow.Wrapper(parent);
}
}

static class M extends ElementMapping.Maker {
public FONode make(FONode parent) {
return new org.apache.fop.fo.flow.Marker(parent);
}
}

static class RM extends ElementMapping.Maker {
public FONode make(FONode parent) {
return new org.apache.fop.fo.flow.RetrieveMarker(parent);
}
}
}

+ 203
- 0
src/java/org/apache/fop/fo/FONode.java View File

@@ -0,0 +1,203 @@
/*
* $Id: FONode.java,v 1.34 2003/03/05 21:48:02 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.fo;

// Java
import java.util.ListIterator;

// XML
import org.xml.sax.Attributes;

// Avalon
import org.apache.avalon.framework.logger.Logger;

// FOP
import org.apache.fop.apps.FOPException;
import org.apache.fop.apps.StructureHandler;
import org.apache.fop.util.CharUtilities;

/**
* base class for nodes in the XML tree
*
*/
public abstract class FONode {
/** FO User Agent for this node (for logger etc.)*/
protected FOUserAgent userAgent;
/** Parent FO node */
protected FONode parent;
/** Name of the node */
protected String name;

/**
* Main constructor.
* @param parent parent of this node
*/
protected FONode(FONode parent) {
this.parent = parent;
}

/**
* Sets the name of the node.
* @param str the name
*/
public void setName(String str) {
name = str;
}

/**
* Returns the logger for the node.
* @return the logger
*/
protected Logger getLogger() {
return userAgent.getLogger();
}

/**
* Sets the user agent for the node.
* @param ua the user agent
*/
public void setUserAgent(FOUserAgent ua) {
userAgent = ua;
}

/**
* Returns the user agent for the node.
* @return FOUserAgent
*/
protected FOUserAgent getUserAgent() {
return userAgent;
}

/**
* Sets the structure handler to send events to.
* @param st StructureHandler instance
*/
public void setStructHandler(StructureHandler st) {
}

public void handleAttrs(Attributes attlist) throws FOPException {
}

/**
* Returns the name of the object
* @return the name of this object
*/
public String getName() {
return this.name;
}

/**
* Adds characters (does nothing here)
* @param data text
* @param start start position
* @param length length of the text
*/
protected void addCharacters(char data[], int start, int length) {
// ignore
}

/**
*
*/
protected void start() {
// do nothing by default
}

/**
*
*/
protected void end() {
// do nothing by default
}

protected void addChild(FONode child) {
}

public FONode getParent() {
return this.parent;
}

/**
* Return an iterator over all the children of this FObj.
* @return A ListIterator.
*/
public ListIterator getChildren() {
return null;
}

/**
* Return an iterator over the object's children starting
* at the pased node.
* @param childNode First node in the iterator
* @return A ListIterator or null if childNode isn't a child of
* this FObj.
*/
public ListIterator getChildren(FONode childNode) {
return null;
}

public CharIterator charIterator() {
return new OneCharIterator(CharUtilities.CODE_EOT);
}

/**
* This is a quick check to see if it is a marker.
* This is needed since there is no other quick way of checking
* for a marker and not adding to the child list.
*
* @return true if this is a marker
*/
protected boolean isMarker() {
return false;
}
}


+ 180
- 0
src/java/org/apache/fop/fo/FOText.java View File

@@ -0,0 +1,180 @@
/*
* $Id: FOText.java,v 1.43 2003/03/05 21:48:01 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.fo;

// Java
import java.util.NoSuchElementException;
import java.util.List;

// FOP
import org.apache.fop.layout.TextState;
import org.apache.fop.layoutmgr.LayoutManager;
import org.apache.fop.layoutmgr.TextLayoutManager;
import org.apache.fop.apps.StructureHandler;
import org.apache.fop.fo.properties.WhiteSpaceCollapse;

/**
* A text node in the formatting object tree.
*
* Modified by Mark Lillywhite, mark-fop@inomial.com.
* Unfortunately the BufferManager implementatation holds
* onto references to the character data in this object
* longer than the lifetime of the object itself, causing
* excessive memory consumption and OOM errors.
*/
public class FOText extends FObj {

protected char[] ca;
protected int start;
protected int length;
TextInfo textInfo;
TextState ts;

public FOText(char[] chars, int s, int e, TextInfo ti) {
super(null);
this.start = 0;
this.ca = new char[e - s];
System.arraycopy(chars, s, ca, 0, e - s);
this.length = e - s;
textInfo = ti;
}

public void setStructHandler(StructureHandler st) {
super.setStructHandler(st);
structHandler.characters(ca, start, length);
}

/**
* Check if this text node will create an area.
* This means either there is non-whitespace or it is
* preserved whitespace.
* Maybe this just needs to check length > 0, since char iterators
* handle whitespace.
*
* @return true if this will create an area in the output
*/
public boolean willCreateArea() {
if (textInfo.whiteSpaceCollapse == WhiteSpaceCollapse.FALSE
&& length > 0) {
return true;
}

for (int i = start; i < start + length; i++) {
char ch = ca[i];
if (!((ch == ' ')
|| (ch == '\n')
|| (ch == '\r')
|| (ch == '\t'))) { // whitespace
return true;
}
}
return false;
}

public void addLayoutManager(List list) {
// if nothing left (length=0)?
if (length == 0) {
return;
}

if (length < ca.length) {
char[] tmp = ca;
ca = new char[length];
System.arraycopy(tmp, 0, ca, 0, length);
}
LayoutManager lm = new TextLayoutManager(ca, textInfo);
lm.setFObj(this);
list.add(lm);
}

public CharIterator charIterator() {
return new TextCharIterator();
}

private class TextCharIterator extends AbstractCharIterator {
private int curIndex = 0;
public boolean hasNext() {
return (curIndex < length);
}

public char nextChar() {
if (curIndex < length) {
// Just a char class? Don't actually care about the value!
return ca[curIndex++];
} else {
throw new NoSuchElementException();
}
}

public void remove() {
if (curIndex > 0 && curIndex < length) {
// copy from curIndex to end to curIndex-1
System.arraycopy(ca, curIndex, ca, curIndex - 1,
length - curIndex);
length--;
curIndex--;
} else if (curIndex == length) {
curIndex = --length;
}
}


public void replaceChar(char c) {
if (curIndex > 0 && curIndex <= length) {
ca[curIndex - 1] = c;
}
}


}
}


+ 275
- 0
src/java/org/apache/fop/fo/FOTreeBuilder.java View File

@@ -0,0 +1,275 @@
/*
* $Id: FOTreeBuilder.java,v 1.43 2003/03/05 21:48:01 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.fo;

// FOP
import org.apache.fop.apps.FOPException;
import org.apache.fop.apps.StructureHandler;

// Java
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

// SAX
import org.xml.sax.helpers.DefaultHandler;
import org.xml.sax.SAXException;
import org.xml.sax.Attributes;

// Avalon
import org.apache.avalon.framework.logger.Logger;

/**
* SAX Handler that builds the formatting object tree.
*
* Modified by Mark Lillywhite mark-fop@inomial.com. Now uses
* StreamRenderer to automagically render the document as
* soon as it receives a page-sequence end-tag. Also,
* calls methods to set up and shut down the renderer at
* the beginning and end of the FO document. Finally,
* supresses adding the PageSequence object to the Root,
* since it is parsed immediately.
*/
public class FOTreeBuilder extends DefaultHandler {

/**
* Table mapping element names to the makers of objects
* representing formatting objects.
*/
protected Map fobjTable = new java.util.HashMap();

/**
* Set of mapped namespaces.
*/
protected Set namespaces = new java.util.HashSet();

/**
* Current formatting object being handled
*/
protected FONode currentFObj = null;

/**
* The root of the formatting object tree
*/
protected FONode rootFObj = null;

/**
* The class that handles formatting and rendering to a stream
* (mark-fop@inomial.com)
*/
private StructureHandler structHandler;

private FOUserAgent userAgent;

/**
* Default constructor
*/
public FOTreeBuilder() {
}

private Logger getLogger() {
return userAgent.getLogger();
}

/**
* Sets the user agent
* @param ua the user agent
*/
public void setUserAgent(FOUserAgent ua) {
userAgent = ua;
}

private FOUserAgent getUserAgent() {
return userAgent;
}

/**
* Sets the structure handler to receive events.
* @param sh StructureHandler instance
*/
public void setStructHandler(StructureHandler sh) {
this.structHandler = sh;
}

/**
* Adds a mapping from a namespace to a table of makers.
*
* @param namespaceURI namespace URI of formatting object elements
* @param table table of makers
*/
public void addMapping(String namespaceURI, HashMap table) {
this.fobjTable.put(namespaceURI, table);
this.namespaces.add(namespaceURI.intern());
}

/**
* SAX Handler for characters
* @see org.xml.sax.ContentHandler#characters(char[], int, int)
*/
public void characters(char data[], int start, int length) {
if (currentFObj != null) {
currentFObj.addCharacters(data, start, start + length);
}
}

/**
* SAX Handler for the end of an element
* @see org.xml.sax.ContentHandler#endElement(String, String, String)
*/
public void endElement(String uri, String localName, String rawName)
throws SAXException {
currentFObj.end();
currentFObj = currentFObj.getParent();
}

/**
* SAX Handler for the start of the document
* @see org.xml.sax.ContentHandler#startDocument()
*/
public void startDocument() throws SAXException {
rootFObj = null; // allows FOTreeBuilder to be reused
if (getLogger().isDebugEnabled()) {
getLogger().debug("Building formatting object tree");
}
structHandler.startDocument();
}

/**
* SAX Handler for the end of the document
* @see org.xml.sax.ContentHandler#endDocument()
*/
public void endDocument() throws SAXException {
rootFObj = null;
currentFObj = null;
if (getLogger().isDebugEnabled()) {
getLogger().debug("Parsing of document complete");
}
structHandler.endDocument();
}

/**
* SAX Handler for the start of an element
* @see org.xml.sax.ContentHandler#startElement(String, String, String, Attributes)
*/
public void startElement(String uri, String localName, String rawName,
Attributes attlist) throws SAXException {
/* the formatting object started */
FONode fobj;

/* the maker for the formatting object started */
ElementMapping.Maker fobjMaker = null;

Map table = (Map)fobjTable.get(uri);
if (table != null) {
fobjMaker = (ElementMapping.Maker)table.get(localName);
// try default
if (fobjMaker == null) {
fobjMaker = (ElementMapping.Maker)table.get(ElementMapping.DEFAULT);
}
}

if (fobjMaker == null) {
if (getLogger().isWarnEnabled()) {
getLogger().warn("Unknown formatting object " + uri + "^" + localName);
}
if (namespaces.contains(uri.intern())) {
// fall back
fobjMaker = new Unknown.Maker();
} else {
fobjMaker = new UnknownXMLObj.Maker(uri);
}
}

try {
fobj = fobjMaker.make(currentFObj);
fobj.setName(localName);
// set the user agent for resolving user agent values
fobj.setUserAgent(userAgent);
// set the structure handler so that appropriate
// elements can signal structure events
fobj.setStructHandler(structHandler);

fobj.handleAttrs(attlist);
} catch (FOPException e) {
throw new SAXException(e);
}

if (rootFObj == null) {
if (!fobj.getName().equals("fo:root")) {
throw new SAXException(new FOPException("Root element must"
+ " be fo:root, not "
+ fobj.getName()));
}
rootFObj = fobj;
} else {
currentFObj.addChild(fobj);
}

currentFObj = fobj;
}

/**
* Resets this object for another run.
*/
public void reset() {
currentFObj = null;
rootFObj = null;
structHandler = null;
}

/**
* Indicates if data has been processed.
* @return True if data has been processed
*/
public boolean hasData() {
return (rootFObj != null);
}
}

+ 220
- 0
src/java/org/apache/fop/fo/FOUserAgent.java View File

@@ -0,0 +1,220 @@
/*
* $Id: FOUserAgent.java,v 1.15 2003/03/05 21:48:02 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.fo;

// Java
import java.util.Map;
import java.io.IOException;
import java.io.InputStream;

// XML
import org.w3c.dom.Document;

// Avalon
import org.apache.avalon.framework.logger.LogEnabled;
import org.apache.avalon.framework.logger.Logger;

// FOP
import org.apache.fop.render.XMLHandler;
import org.apache.fop.render.RendererContext;

/**
* The User Agent for fo.
* This user agent is used by the processing to obtain user configurable
* options.
* <p>
* Renderer specific extensions (that do not produce normal areas on
* the output) will be done like so:
* <br>
* The extension will create an area, custom if necessary
* <br>
* this area will be added to the user agent with a key
* <br>
* the renderer will know keys for particular extensions
* <br>
* eg. bookmarks will be held in a special hierarchical area representing
* the title and bookmark structure
* <br>
* These areas may contain resolveable areas that will be processed
* with other resolveable areas
*/
public class FOUserAgent implements LogEnabled {
private Logger log;
private Map defaults = new java.util.HashMap();
private Map handlers = new java.util.HashMap();
private String baseURL;

/**
* Sets the logger.
* @param log Logger to use
* @see org.apache.avalon.framework.logger.LogEnabled#enableLogging(Logger)
*/
public void enableLogging(Logger log) {
this.log = log;
}

/**
* Returns the logger to use.
* @see org.apache.avalon.framework.logger.AbstractLogEnabled#getLogger()
* @todo This breaks IoC/SoC. Should be improved.
*/
public Logger getLogger() {
return this.log;
}

/**
* Sets the base URL.
* @param baseURL base URL
*/
public void setBaseURL(String baseURL) {
this.baseURL = baseURL;
}

/**
* Returns the base URL.
* @return the base URL
*/
public String getBaseURL() {
if ((this.baseURL == null) || (this.baseURL.trim().equals(""))) {
return "file:.";
} else {
return this.baseURL;
}
}

/**
* Get an input stream for a reference.
* Temporary solution until API better.
* @param uri URI to access
* @return InputStream for accessing the resource.
* @throws IOException in case of an I/O problem
*/
public InputStream getStream(String uri) throws IOException {
return null;
}

/**
* Returns the conversion factor from pixel units to millimeters. This
* depends on the desired reolution.
* @return float conversion factor
*/
public float getPixelUnitToMillimeter() {
return 0.35277777777777777778f;
}

/**
* If to create hot links to footnotes and before floats.
* @return True if hot links dhould be created
*/
public boolean linkToFootnotes() {
return true;
}

/**
* Set the default xml handler for the given mime type.
* @param mime MIME type
* @param handler XMLHandler to use
*/
public void setDefaultXMLHandler(String mime, XMLHandler handler) {
defaults.put(mime, handler);
}

/**
* Add an xml handler for the given mime type and xml namespace.
* @param mime MIME type
* @param ns Namespace URI
* @param handler XMLHandler to use
*/
public void addXMLHandler(String mime, String ns, XMLHandler handler) {
Map mh = (Map) handlers.get(mime);
if (mh == null) {
mh = new java.util.HashMap();
handlers.put(mime, mh);
}
mh.put(ns, handler);
}

/**
* Render the xml document with the given xml namespace.
* The Render Context is by the handle to render into the current
* rendering target.
* @param ctx rendering context
* @param doc DOM Document containing the source document
* @param namespace Namespace URI of the document
*/
public void renderXML(RendererContext ctx, Document doc,
String namespace) {
String mime = ctx.getMimeType();
Map mh = (Map) handlers.get(mime);
XMLHandler handler = null;
if (mh != null) {
handler = (XMLHandler) mh.get(namespace);
}
if (handler == null) {
handler = (XMLHandler) defaults.get(mime);
}
if (handler != null) {
try {
handler.handleXML(ctx, doc, namespace);
} catch (Throwable t) {
// could not handle document
getLogger().error("Some XML content will be ignored. "
+ "Could not render XML", t);
}
} else {
// no handler found for document
getLogger().warn("Some XML content will be ignored. "
+ "No handler defined for XML: " + namespace);
}
}
}


+ 376
- 0
src/java/org/apache/fop/fo/FObj.java View File

@@ -0,0 +1,376 @@
/*
* $Id: FObj.java,v 1.40 2003/03/05 21:48:02 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.fo;

// Java
import java.util.Iterator;
import java.util.ListIterator;
import java.util.ArrayList;
import java.util.List;
import java.util.HashMap;
import java.util.Set;
import java.util.Map;
import org.xml.sax.Attributes;

// FOP
import org.apache.fop.apps.FOPException;
import org.apache.fop.apps.StructureHandler;
import org.apache.fop.fo.properties.FOPropertyMapping;
import org.apache.fop.fo.flow.Marker;

/**
* base class for representation of formatting objects and their processing
*/
public class FObj extends FONode {
private static final String FO_URI = "http://www.w3.org/1999/XSL/Format";

/**
* Static property list builder that converts xml attributes
* into fo properties. This is static since the underlying
* property mappings for fo are also static.
*/
protected static PropertyListBuilder plb = null;

/**
* Structure handler used to notify structure events
* such as start end element.
*/
protected StructureHandler structHandler;

/**
* Formatting properties for this fo element.
*/
public PropertyList properties;

/**
* Property manager for handler some common properties.
*/
protected PropertyManager propMgr;

/**
* Id of this fo element of null if no id.
*/
protected String id = null;

/**
* The children of this node.
*/
protected ArrayList children = null;

/**
* Markers added to this element.
*/
protected Map markers = null;

/**
* Create a new formatting object.
* All formatting object classes extend this class.
*
* @param parent the parent node
*/
public FObj(FONode parent) {
super(parent);
}

/**
* Set the name of this element.
* The prepends "fo:" to the name to indicate it is in the fo namespace.
*
* @param str the xml element name
*/
public void setName(String str) {
name = "fo:" + str;
}

protected PropertyListBuilder getListBuilder() {
if (plb == null) {
plb = new PropertyListBuilder();
plb.addList(FOPropertyMapping.getGenericMappings());

for (Iterator iter =
FOPropertyMapping.getElementMappings().iterator();
iter.hasNext();) {
String elem = (String) iter.next();
plb.addElementList(elem,
FOPropertyMapping.getElementMapping(elem));
}
}
return plb;
}

/**
* Handle the attributes for this element.
* The attributes must be used immediately as the sax attributes
* will be altered for the next element.
*/
public void handleAttrs(Attributes attlist) throws FOPException {
FONode par = parent;
while (par != null && !(par instanceof FObj)) {
par = par.parent;
}
PropertyList props = null;
if (par != null) {
props = ((FObj) par).properties;
}
properties = getListBuilder().makeList(FO_URI, name, attlist, props,
(FObj) par);
properties.setFObj(this);
this.propMgr = makePropertyManager(properties);
setWritingMode();
}

protected PropertyManager makePropertyManager(
PropertyList propertyList) {
return new PropertyManager(propertyList);
}

/**
* Add the child to this object.
*
* @param child the child node to add
*/
protected void addChild(FONode child) {
if (containsMarkers() && child.isMarker()) {
addMarker((Marker)child);
} else {
if (children == null) {
children = new ArrayList();
}
children.add(child);
}
}

/**
* Set the structure handler for handling structure events.
*
* @param st the structure handler
*/
public void setStructHandler(StructureHandler st) {
structHandler = st;
}

/**
* lets outside sources access the property list
* first used by PageNumberCitation to find the "id" property
* @param name - the name of the desired property to obtain
* @return the property
*/
public Property getProperty(String name) {
return (properties.get(name));
}

/**
* Setup the id for this formatting object.
* Most formatting objects can have an id that can be referenced.
* This methods checks that the id isn't already used by another
* fo and sets the id attribute of this object.
*/
protected void setupID() {
Property prop = this.properties.get("id");
if (prop != null) {
String str = prop.getString();
if (str != null && !str.equals("")) {
Set idrefs = structHandler.getIDReferences();
if (!idrefs.contains(str)) {
id = str;
idrefs.add(id);
} else {
getLogger().warn("duplicate id:" + str + " ignored");
}
}
}
}

/**
* Get the id string for this formatting object.
* This will be unique for the fo document.
*
* @return the id string or null if not set
*/
public String getID() {
return id;
}

/**
* Check if this formatting object generates reference areas.
*
* @return true if generates reference areas
*/
public boolean generatesReferenceAreas() {
return false;
}

/**
* Check if this formatting object generates inline areas.
*
* @return true if generates inline areas
*/
public boolean generatesInlineAreas() {
return true;
}

/**
* Check if this formatting object may contain markers.
*
* @return true if this can contian markers
*/
protected boolean containsMarkers() {
return false;
}

/**
* Set writing mode for this FO.
* Find nearest ancestor, including self, which generates
* reference areas and use the value of its writing-mode property.
* If no such ancestor is found, use the value on the root FO.
*/
protected void setWritingMode() {
FObj p;
FONode parent;
for (p = this; !p.generatesReferenceAreas()
&& (parent = p.getParent()) != null
&& (parent instanceof FObj); p = (FObj) parent) {
}
this.properties.setWritingMode(
p.getProperty("writing-mode").getEnum());
}

/**
* Return a LayoutManager responsible for laying out this FObj's content.
* Must override in subclasses if their content can be laid out.
* @param list the list to add the layout manager(s) to
*/
public void addLayoutManager(List list) {
}

/**
* Return an iterator over all the children of this FObj.
* @return A ListIterator.
*/
public ListIterator getChildren() {
if (children != null) {
return children.listIterator();
}
return null;
}

/**
* Return an iterator over the object's children starting
* at the pased node.
* @param childNode First node in the iterator
* @return A ListIterator or null if childNode isn't a child of
* this FObj.
*/
public ListIterator getChildren(FONode childNode) {
if (children != null) {
int i = children.indexOf(childNode);
if (i >= 0) {
return children.listIterator(i);
}
}
return null;
}

/**
* Add the marker to this formatting object.
* If this object can contain markers it checks that the marker
* has a unique class-name for this object and that it is
* the first child.
*/
public void addMarker(Marker marker) {
String mcname = marker.getMarkerClassName();
if (children != null) {
// check for empty children
for (Iterator iter = children.iterator(); iter.hasNext();) {
FONode node = (FONode)iter.next();
if (node instanceof FOText) {
FOText text = (FOText)node;
if (text.willCreateArea()) {
getLogger().error("fo:marker must be an initial child: " + mcname);
return;
} else {
iter.remove();
}
} else {
getLogger().error("fo:marker must be an initial child: " + mcname);
return;
}
}
}
if (markers == null) {
markers = new HashMap();
}
if (!markers.containsKey(mcname)) {
markers.put(mcname, marker);
} else {
getLogger().error("fo:marker 'marker-class-name' "
+ "must be unique for same parent: " + mcname);
}
}

public boolean hasMarkers() {
return markers != null && !markers.isEmpty();
}

public Map getMarkers() {
return markers;
}

/**
* lets layout managers access FO properties via PropertyManager
* @return the property manager for this FO
*/
public PropertyManager getPropertyManager() {
return this.propMgr;
}

}


+ 113
- 0
src/java/org/apache/fop/fo/FObjMixed.java View File

@@ -0,0 +1,113 @@
/*
* $Id: FObjMixed.java,v 1.33 2003/03/05 21:48:01 jeremias Exp $
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.fo;

import org.apache.fop.layout.FontInfo;
import org.apache.fop.apps.StructureHandler;
import org.apache.fop.layoutmgr.InlineStackingLayoutManager;
import org.apache.fop.layoutmgr.LMiter;

import java.util.List;

/**
* base class for representation of mixed content formatting objects
* and their processing
*/
public class FObjMixed extends FObj {
protected TextInfo textInfo = null;
protected FontInfo fontInfo = null;

public FObjMixed(FONode parent) {
super(parent);
}

public void setStructHandler(StructureHandler st) {
super.setStructHandler(st);
fontInfo = st.getFontInfo();
}

public void addLayoutManager(List lms) {
if (children != null) {
InlineStackingLayoutManager lm;
lm = new InlineStackingLayoutManager();
lm.setUserAgent(getUserAgent());
lm.setFObj(this);
lm.setLMiter(new LMiter(children.listIterator()));
lms.add(lm);
}
}

protected void addCharacters(char data[], int start, int length) {
if (textInfo == null) {
// Really only need one of these, but need to get fontInfo
// stored in propMgr for later use.
propMgr.setFontInfo(fontInfo);
textInfo = propMgr.getTextLayoutProps(fontInfo);
}

FOText ft = new FOText(data, start, length, textInfo);
ft.setUserAgent(userAgent);
ft.setStructHandler(structHandler);
addChild(ft);
}

public void setup() {
if (this.properties != null) {
setupID();
}
}

public CharIterator charIterator() {
return new RecursiveCharIterator(this);
}

}


+ 0
- 0
src/java/org/apache/fop/fo/GenericShorthandParser.java View File


Some files were not shown because too many files changed in this diff

Loading…
Cancel
Save