diff options
author | jtauber <jtauber@unknown> | 1999-11-22 02:32:21 +0000 |
---|---|---|
committer | jtauber <jtauber@unknown> | 1999-11-22 02:32:21 +0000 |
commit | 8db42fcc7af041a77223683e11e053ffb82c4847 (patch) | |
tree | 81748e94daccc781c60ee1d2bcf5a6105ab3070f /src/org/apache | |
parent | abd622447e632998a8c9a5fbf40aec5e0ce73315 (diff) | |
download | xmlgraphics-fop-8db42fcc7af041a77223683e11e053ffb82c4847.tar.gz xmlgraphics-fop-8db42fcc7af041a77223683e11e053ffb82c4847.zip |
removed multiple CRs at end of lines
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@193230 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/org/apache')
100 files changed, 0 insertions, 8258 deletions
diff --git a/src/org/apache/fop/apps/CommandLine.java b/src/org/apache/fop/apps/CommandLine.java index ffba2f695..67101ccb3 100644 --- a/src/org/apache/fop/apps/CommandLine.java +++ b/src/org/apache/fop/apps/CommandLine.java @@ -50,245 +50,123 @@ */ package org.apache.fop.apps; - - // SAX - import org.xml.sax.Parser; - import org.xml.sax.InputSource; - import org.xml.sax.SAXException; - import org.xml.sax.SAXParseException; - - // Java - import java.io.FileReader; - import java.io.File; - import java.io.FileWriter; - import java.io.PrintWriter; - import java.io.IOException; - import java.io.FileNotFoundException; - import java.net.URL; - - /** - * mainline class. - * - * Gets input and output filenames from the command line. - * Creates a SAX Parser (defaulting to XP). - * - */ - public class CommandLine { - - /** - * creates a SAX parser, using the value of org.xml.sax.parser - * defaulting to com.jclark.xml.sax.Driver - * - * @return the created SAX parser - */ - static Parser createParser() { - String parserClassName = - System.getProperty("org.xml.sax.parser"); - if (parserClassName == null) { - parserClassName = "com.jclark.xml.sax.Driver"; - } - System.err.println("using SAX parser " + parserClassName); - - try { - return (Parser) - Class.forName(parserClassName).newInstance(); - } catch (ClassNotFoundException e) { - System.err.println("Could not find " + parserClassName); - } catch (InstantiationException e) { - System.err.println("Could not instantiate " - + parserClassName); - } catch (IllegalAccessException e) { - System.err.println("Could not access " + parserClassName); - } catch (ClassCastException e) { - System.err.println(parserClassName + " is not a SAX driver"); - } - return null; - } - - /** - * create an InputSource from a file name - * - * @param filename the name of the file - * @return the InputSource created - */ - protected static InputSource fileInputSource(String filename) { - - /* this code adapted from James Clark's in XT */ - File file = new File(filename); - 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"); - } - } - - /** - * mainline method - * - * first command line argument is input file - * second command line argument is output file - * - * @param command line arguments - */ - public static void main(String[] args) { - String version = Version.getVersion(); - System.err.println(version); - - if (args.length != 2) { - System.err.println("usage: java " - + "org.apache.fop.apps.CommandLine " - + "formatting-object-file pdf-file"); - System.exit(1); - } - - Parser parser = createParser(); - - if (parser == null) { - System.err.println("ERROR: Unable to create SAX parser"); - System.exit(1); - } - - try { - Driver driver = new Driver(); - driver.setRenderer("org.apache.fop.render.pdf.PDFRenderer", version); - driver.addElementMapping("org.apache.fop.fo.StandardElementMapping"); - driver.addElementMapping("org.apache.fop.svg.SVGElementMapping"); - driver.setWriter(new PrintWriter(new FileWriter(args[1]))); - driver.buildFOTree(parser, fileInputSource(args[0])); - driver.format(); - driver.render(); - } catch (Exception e) { - System.err.println("FATAL ERROR: " + e.getMessage()); - System.exit(1); - } - } - } - diff --git a/src/org/apache/fop/apps/Driver.java b/src/org/apache/fop/apps/Driver.java index e163405fb..bee187fed 100644 --- a/src/org/apache/fop/apps/Driver.java +++ b/src/org/apache/fop/apps/Driver.java @@ -50,431 +50,216 @@ */ package org.apache.fop.apps; - - // FOP - import org.apache.fop.fo.FOTreeBuilder; - import org.apache.fop.fo.ElementMapping; - import org.apache.fop.layout.AreaTree; - import org.apache.fop.layout.FontInfo; - import org.apache.fop.render.Renderer; - - // DOM - import org.w3c.dom.Document; - import org.w3c.dom.Node; - import org.w3c.dom.NamedNodeMap; - import org.w3c.dom.Attr; - - // SAX - import org.xml.sax.DocumentHandler; - import org.xml.sax.InputSource; - import org.xml.sax.Parser; - import org.xml.sax.SAXException; - import org.xml.sax.helpers.AttributeListImpl; - - // Java - import java.io.PrintWriter; - import java.io.IOException; - - public class Driver { - - protected FOTreeBuilder treeBuilder; - protected AreaTree areaTree; - protected Renderer renderer; - protected PrintWriter writer; - - public Driver() { - this.treeBuilder = new FOTreeBuilder(); - } - - public void setRenderer(Renderer renderer) { - this.renderer = renderer; - } - - public void setRenderer(String rendererClassName, String producer) { - this.renderer = createRenderer(rendererClassName); - this.renderer.setProducer(producer); - } - - protected Renderer createRenderer(String rendererClassName) { - System.err.println("using renderer " + rendererClassName); - - try { - return (Renderer) - Class.forName(rendererClassName).newInstance(); - } catch (ClassNotFoundException e) { - System.err.println("Could not find " + rendererClassName); - } catch (InstantiationException e) { - System.err.println("Could not instantiate " - + rendererClassName); - } catch (IllegalAccessException e) { - System.err.println("Could not access " + rendererClassName); - } catch (ClassCastException e) { - System.err.println(rendererClassName + " is not a renderer"); - } - return null; - } - - public void addElementMapping(ElementMapping mapping) { - mapping.addToBuilder(this.treeBuilder); - } - - public void addElementMapping(String mappingClassName) { - createElementMapping(mappingClassName).addToBuilder(this.treeBuilder); - } - - protected ElementMapping createElementMapping(String mappingClassName) { - System.err.println("using element mapping " + mappingClassName); - - try { - return (ElementMapping) - Class.forName(mappingClassName).newInstance(); - } catch (ClassNotFoundException e) { - System.err.println("Could not find " + mappingClassName); - } catch (InstantiationException e) { - System.err.println("Could not instantiate " - + mappingClassName); - } catch (IllegalAccessException e) { - System.err.println("Could not access " + mappingClassName); - } catch (ClassCastException e) { - System.err.println(mappingClassName + " is not an element mapping"); - } - return null; - } - - public DocumentHandler getDocumentHandler() { - return this.treeBuilder; - } - - public void buildFOTree(Parser parser, InputSource source) - throws FOPException { - parser.setDocumentHandler(this.treeBuilder); - try { - parser.parse(source); - } catch (SAXException e) { - if (e.getException() instanceof FOPException) - throw (FOPException) e.getException(); - else - throw new FOPException(e.getMessage()); - } catch (IOException e) { - throw new FOPException(e.getMessage()); - } - } - - public void buildFOTree(Document document) - throws FOPException { - - /* most of this code is modified from John Cowan's */ - - Node currentNode; - AttributeListImpl currentAtts; - - /* temporary array for making Strings into character arrays */ - char[] array = null; - - currentAtts = new AttributeListImpl(); - - /* start at the document element */ - currentNode = document; - - try { - while (currentNode != null) { - switch (currentNode.getNodeType()) { - case Node.DOCUMENT_NODE: - this.treeBuilder.startDocument(); - break; - case Node.CDATA_SECTION_NODE: - case Node.TEXT_NODE: - String data = currentNode.getNodeValue(); - int datalen = data.length(); - if (array == null || array.length < datalen) { - /* if the array isn't big enough, make a new - one */ - array = new char[datalen]; - } - data.getChars(0, datalen, array, 0); - this.treeBuilder.characters(array, 0, datalen); - break; - case Node.PROCESSING_INSTRUCTION_NODE: - this.treeBuilder.processingInstruction( - currentNode.getNodeName(), - currentNode.getNodeValue()); - break; - case Node.ELEMENT_NODE: - NamedNodeMap map = currentNode.getAttributes(); - currentAtts.clear(); - for (int i = map.getLength() - 1; i >= 0; i--) { - Attr att = (Attr)(map.item(i)); - currentAtts.addAttribute(att.getName(), - "CDATA", - att.getValue()); - } - this.treeBuilder.startElement( - currentNode.getNodeName(), currentAtts); - break; - } - - Node nextNode = currentNode.getFirstChild(); - if (nextNode != null) { - currentNode = nextNode; - continue; - } - - while (currentNode != null) { - switch (currentNode.getNodeType()) { - case Node.DOCUMENT_NODE: - this.treeBuilder.endDocument(); - break; - case Node.ELEMENT_NODE: - this.treeBuilder.endElement( - currentNode.getNodeName()); - break; - } - - nextNode = currentNode.getNextSibling(); - if (nextNode != null) { - currentNode = nextNode; - break; - } - - currentNode = currentNode.getParentNode(); - } - } - } catch (SAXException e) { - throw new FOPException(e.getMessage()); - } - } - - public void setWriter(PrintWriter writer) { - this.writer = writer; - } - - public void format() - throws FOPException { - FontInfo fontInfo = new FontInfo(); - this.renderer.setupFontInfo(fontInfo); - - this.areaTree = new AreaTree(); - this.areaTree.setFontInfo(fontInfo); - - this.treeBuilder.format(areaTree); - } - - public void render() - throws IOException { - this.renderer.render(areaTree, this.writer); - } - } - diff --git a/src/org/apache/fop/apps/ErrorHandler.java b/src/org/apache/fop/apps/ErrorHandler.java index ea9d1e400..79c889897 100644 --- a/src/org/apache/fop/apps/ErrorHandler.java +++ b/src/org/apache/fop/apps/ErrorHandler.java @@ -50,9 +50,5 @@ */ package org.apache.fop.apps; - - /** not implemented yet */ - public interface ErrorHandler {} - diff --git a/src/org/apache/fop/apps/FOPException.java b/src/org/apache/fop/apps/FOPException.java index 07347278e..6b64166de 100644 --- a/src/org/apache/fop/apps/FOPException.java +++ b/src/org/apache/fop/apps/FOPException.java @@ -50,33 +50,17 @@ */ package org.apache.fop.apps; - - /** - * Exception thrown when FOP has a problem - */ - public class FOPException extends Exception { - - /** - * create a new FOP Exception - * - * @param message descriptive message - */ - public FOPException(String message) { - super(message); - } - } - diff --git a/src/org/apache/fop/apps/Version.java b/src/org/apache/fop/apps/Version.java index 7222db46d..a97e23501 100644 --- a/src/org/apache/fop/apps/Version.java +++ b/src/org/apache/fop/apps/Version.java @@ -50,37 +50,19 @@ */ package org.apache.fop.apps; - - /** - * class representing the version of FOP. - * - * added at the request of Stefano Mazzocchi for use by Fop. - */ - public class Version { - - /** - * get the version of FOP - * - * @return the version string - */ - public static String getVersion() { - return "FOP 0.12.0pre5"; - } - } - diff --git a/src/org/apache/fop/apps/XTCommandLine.java b/src/org/apache/fop/apps/XTCommandLine.java index db3ab2927..21fa398de 100644 --- a/src/org/apache/fop/apps/XTCommandLine.java +++ b/src/org/apache/fop/apps/XTCommandLine.java @@ -50,157 +50,79 @@ */ package org.apache.fop.apps; - - import org.apache.fop.render.pdf.PDFRenderer; - import org.apache.fop.fo.StandardElementMapping; - import org.apache.fop.svg.SVGElementMapping; - - // James Clark - import com.jclark.xsl.sax.XSLProcessor; - import com.jclark.xsl.sax.XSLProcessorImpl; - - // SAX - import org.xml.sax.Parser; - import org.xml.sax.InputSource; - import org.xml.sax.SAXException; - import org.xml.sax.SAXParseException; - - // Java - import java.io.FileReader; - import java.io.FileWriter; - import java.io.PrintWriter; - import java.io.IOException; - import java.io.FileNotFoundException; - import java.net.URL; - - /** - * mainline class for full transformation (via XT) + formatting/rendering. - * - * gets input, stylesheet and output filenames from the command line - * creates an implementation of XSLProcessor, passing it the stylesheet - * treats XSLProcessor as SAXParser - * - */ - public class XTCommandLine extends CommandLine { - - /** - * mainline method. - * - * first command line argument is XML input file - * second command line argument is XSL stylesheet file - * third command line argument is outputfile - */ - public static void main(String[] args) { - String version = Version.getVersion(); - System.err.println(version); - - if (args.length != 3) { - System.err.println("usage: java org.apache.fop.apps.XTCommandLine xml-file xsl-stylesheet pdf-file"); - System.exit(1); - } - - Parser parser = createParser(); - - if (parser == null) { - System.err.println("ERROR: Unable to create SAX parser"); - System.exit(1); - } - - XSLProcessor xslProcessor = new XSLProcessorImpl(); - xslProcessor.setParser(parser); - - try { - xslProcessor.loadStylesheet(fileInputSource(args[1])); - - Driver driver = new Driver(); - driver.setRenderer("org.apache.fop.render.pdf.PDFRenderer", - version); - driver.addElementMapping("org.apache.fop.fo.StandardElementMapping"); - driver.addElementMapping("org.apache.fop.svg.SVGElementMapping"); - driver.setWriter(new PrintWriter(new FileWriter(args[2]))); - driver.buildFOTree(parser, fileInputSource(args[0])); - driver.format(); - driver.render(); - } catch (Exception e) { - System.err.println("FATAL ERROR: " + e.getMessage()); - System.exit(1); - } - } - } - diff --git a/src/org/apache/fop/datatypes/ColorType.java b/src/org/apache/fop/datatypes/ColorType.java index cbd7f03c6..2049a8f7c 100644 --- a/src/org/apache/fop/datatypes/ColorType.java +++ b/src/org/apache/fop/datatypes/ColorType.java @@ -50,273 +50,137 @@ */ package org.apache.fop.datatypes; - - /** - * a colour quantity in XSL - */ - public class ColorType { - - /** the red component */ - protected float red; - - /** the green component */ - protected float green; - - /** the blue component */ - protected float blue; - - /** - * set the colour given a particular String specifying either a - * colour name or #RGB or #RRGGBB - */ - 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; - System.err.println("ERROR: unknown colour format. Must be #RGB or #RRGGBB"); - } - } catch (Exception e) { - this.red = 0; - this.green = 0; - this.blue = 0; - System.err.println("ERROR: unknown colour format. Must be #RGB or #RRGGBB"); - } - } else { - if (value.toLowerCase().equals("black")) { - this.red = 0; - this.green = 0; - this.blue = 0; - } else if (value.toLowerCase().equals("green")) { - this.red = 0; - this.green = 0.5f; - this.blue = 0; - } else if (value.toLowerCase().equals("silver")) { - this.red = 0.75f; - this.green = 0.75f; - this.blue = 0.75f; - } else if (value.toLowerCase().equals("lime")) { - this.red = 0; - this.green = 1; - this.blue = 0; - } else if (value.toLowerCase().equals("gray")) { - this.red = 0.5f; - this.green = 0.5f; - this.blue = 0.5f; - } else if (value.toLowerCase().equals("olive")) { - this.red = 0.5f; - this.green = 0.5f; - this.blue = 0; - } else if (value.toLowerCase().equals("white")) { - this.red = 1; - this.green = 1; - this.blue = 1; - } else if (value.toLowerCase().equals("yellow")) { - this.red = 1; - this.green = 1; - this.blue = 0; - } else if (value.toLowerCase().equals("maroon")) { - this.red = 0.5f; - this.green = 0; - this.blue = 0; - } else if (value.toLowerCase().equals("navy")) { - this.red = 0; - this.green = 0; - this.blue = 0.5f; - } else if (value.toLowerCase().equals("red")) { - this.red = 1; - this.green = 0; - this.blue = 0; - } else if (value.toLowerCase().equals("blue")) { - this.red = 0; - this.green = 0; - this.blue = 1; - } else if (value.toLowerCase().equals("purple")) { - this.red = 0.5f; - this.green = 0; - this.blue = 0.5f; - } else if (value.toLowerCase().equals("teal")) { - this.red = 0; - this.green = 0.5f; - this.blue = 0.5f; - } else if (value.toLowerCase().equals("fuchsia")) { - this.red = 1; - this.green = 0; - this.blue = 1; - } else if (value.toLowerCase().equals("aqua")) { - this.red = 0; - this.green = 1; - this.blue = 1; - } else if (value.toLowerCase().equals("orange")) { - // for compatibility with passiveTex - this.red = 0.7f; - this.green = 0.5f; - this.blue = 0; - } else { - this.red = 0; - this.green = 0; - this.blue = 0; - System.err.println("ERROR: unknown colour name: " + value); - } - } - } - - public float blue() { - return this.blue; - } - - public float green() { - return this.green; - } - - public float red() { - return this.red; - } - } - diff --git a/src/org/apache/fop/datatypes/Length.java b/src/org/apache/fop/datatypes/Length.java index cfb3db774..15b95edf2 100644 --- a/src/org/apache/fop/datatypes/Length.java +++ b/src/org/apache/fop/datatypes/Length.java @@ -50,177 +50,89 @@ */ package org.apache.fop.datatypes; - - import org.apache.fop.fo.Property; - - /** - * a length quantity in XSL - */ - public class Length { - - protected int millipoints = 0; - - protected double fontsize = 12; - - /** - * set the length given a particular String specifying length and units - */ - public Length (String len) { - convert(len); - } - - /** - * set the length given a particular String specifying length and units, - * and the font-size (necessary for an em) - */ - public Length (String len, int fontsize) { - this.fontsize = fontsize; - convert(len); - } - - /** - * set the length given a particular multiplier and a length property - */ - public Length (double multiplier, Property property) { - this.millipoints = (int)(multiplier * property.getLength().mvalue()); - } - - protected void convert(String len) { - /* convert the given length to a dimensionless integer representing - points. */ - - int assumed_resolution = 1; // points/pixel - - int l = len.length(); - - if (l == 0) { - System.err.println("WARNING: empty length"); - this.millipoints = 0; - } else { - String unit = len.substring(l-2); - double dvalue = - Double.valueOf(len.substring(0,(l-2))).doubleValue(); - - if (unit.equals("in")) - dvalue = dvalue * 72; - else if (unit.equals("cm")) - dvalue = dvalue * 28.35; - else if (unit.equals("mm")) - dvalue = dvalue * 2.84; - 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 * assumed_resolution; - else { - dvalue = 0; - System.err.println("ERROR: unknown length units in " - + len); - } - - this.millipoints = (int) (dvalue * 1000); - } - } - - /** - * return the length in 1/1000ths of a point - */ - public int mvalue() { - return millipoints; - } - - public String toString() { - String s = millipoints + "mpt"; - return s; - } - } - diff --git a/src/org/apache/fop/fo/ElementMapping.java b/src/org/apache/fop/fo/ElementMapping.java index e59cc61fe..d7289536e 100644 --- a/src/org/apache/fop/fo/ElementMapping.java +++ b/src/org/apache/fop/fo/ElementMapping.java @@ -50,13 +50,7 @@ */ package org.apache.fop.fo; - - public interface ElementMapping { - - public void addToBuilder(FOTreeBuilder builder); - } - diff --git a/src/org/apache/fop/fo/FONode.java b/src/org/apache/fop/fo/FONode.java index 04b60601e..bad4bfbf2 100644 --- a/src/org/apache/fop/fo/FONode.java +++ b/src/org/apache/fop/fo/FONode.java @@ -50,221 +50,111 @@ */ package org.apache.fop.fo; - - // FOP - import org.apache.fop.apps.FOPException; - import org.apache.fop.layout.Area; - - // Java - import java.util.Vector; - - /** - * base class for nodes in the formatting object tree - */ - abstract public class FONode { - - protected FObj parent; - protected Vector children = new Vector(); - - /** value of marker before layout begins */ - public final static int START = -1000; - - /** value of marker after break-after */ - public final static int BREAK_AFTER = -1001; - - /** - * where the layout was up to. - * for FObjs it is the child number - * for FOText it is the character number - */ - protected int marker = START; - - protected boolean isInLabel = false; - protected boolean isInListBody = false; - protected boolean isInTableCell = false; - - protected int bodyIndent; - protected int distanceBetweenStarts; - protected int labelSeparation; - - protected int forcedStartOffset = 0; - protected int forcedWidth = 0; - - protected FONode(FObj parent) { - this.parent = parent; - } - - public void setIsInLabel() { - this.isInLabel = true; - } - - public void setIsInListBody() { - this.isInListBody = true; - } - - public void setIsInTableCell() { - this.isInTableCell = true; - } - - public void setDistanceBetweenStarts(int distance) { - this.distanceBetweenStarts = distance; - } - - public void setLabelSeparation(int separation) { - this.labelSeparation = separation; - } - - public void setBodyIndent(int indent) { - this.bodyIndent = indent; - } - - public void forceStartOffset(int offset) { - this.forcedStartOffset = offset; - } - - public void forceWidth(int width) { - this.forcedWidth = width; - } - - public void resetMarker() { - this.marker = START; - int numChildren = this.children.size(); - for (int i = 0; i < numChildren; i++) { - ((FONode) children.elementAt(i)).resetMarker(); - } - } - - protected void addChild(FONode child) { - children.addElement(child); - } - - public FObj getParent() { - return this.parent; - } - - /* status */ - /* layout was fully completed */ - public final static int OK = 1; - /* none of the formatting object could be laid out because the - containing area was full (end of page) */ - public final static int AREA_FULL_NONE = 2; - /* some of the formatting object could not be laid out because the - containing area was full (end of page) */ - public final static int AREA_FULL_SOME = 3; - /* force page break */ - public final static int FORCE_PAGE_BREAK = 4; - public final static int FORCE_PAGE_BREAK_EVEN = 5; - public final static int FORCE_PAGE_BREAK_ODD = 6; - - abstract public int layout(Area area) - throws FOPException; - } - diff --git a/src/org/apache/fop/fo/FOText.java b/src/org/apache/fop/fo/FOText.java index 1fe2fb1a0..6da9163a7 100644 --- a/src/org/apache/fop/fo/FOText.java +++ b/src/org/apache/fop/fo/FOText.java @@ -50,161 +50,81 @@ */ package org.apache.fop.fo; - - // FOP - import org.apache.fop.layout.Area; - import org.apache.fop.layout.BlockArea; - import org.apache.fop.layout.FontState; - import org.apache.fop.datatypes.*; - import org.apache.fop.fo.properties.*; - import org.apache.fop.apps.FOPException; - - /** - * a text node in the formatting object tree - */ - public class FOText extends FONode { - - protected char[] ca; - protected int start; - protected int length; - - FontState fs; - float red; - float green; - float blue; - int wrapOption; - int whiteSpaceTreatment; - - protected FOText(char[] chars, int s, int e, FObj parent) { - super(parent); - this.start = 0; - this.ca = new char[e - s]; - for (int i = s; i < e; i++) - this.ca[i - s] = chars[i]; - this.length = e - s; - } - - public int layout(Area area) throws FOPException { - if (!(area instanceof BlockArea)) { - System.err.println("WARNING: text outside block area" + new String(ca, start, length)); - return OK; - } - if (this.marker == START) { - String fontFamily = - this.parent.properties.get("font-family").getString(); - String fontStyle = - this.parent.properties.get("font-style").getString(); - String fontWeight = - this.parent.properties.get("font-weight").getString(); - int fontSize = - this.parent.properties.get("font-size").getLength().mvalue(); - - this.fs = new FontState(area.getFontInfo(), fontFamily, fontStyle, - fontWeight, fontSize); - - ColorType c = - this.parent.properties.get("color").getColorType(); - this.red = c.red(); - this.green = c.green(); - this.blue = c.blue(); - - this.wrapOption = - this.parent.properties.get("wrap-option").getEnum(); - this.whiteSpaceTreatment = - this.parent.properties.get("white-space-treatment").getEnum(); - - this.marker = this.start; - } - int orig_start = this.marker; - this.marker = ((BlockArea) area).addText(fs, red, green, blue, - wrapOption, - whiteSpaceTreatment, - ca, this.marker, length); - if (this.marker == -1) { - return OK; - } else if (this.marker != orig_start) { - return AREA_FULL_SOME; - } else { - return AREA_FULL_NONE; - } - } - } - diff --git a/src/org/apache/fop/fo/FOTreeBuilder.java b/src/org/apache/fop/fo/FOTreeBuilder.java index bd8c87d77..0d3bc52ea 100644 --- a/src/org/apache/fop/fo/FOTreeBuilder.java +++ b/src/org/apache/fop/fo/FOTreeBuilder.java @@ -50,409 +50,205 @@ */ package org.apache.fop.fo; - - // FOP - import org.apache.fop.layout.AreaTree; - import org.apache.fop.apps.FOPException; - import org.apache.fop.fo.pagination.Root; - - // SAX - import org.xml.sax.HandlerBase; - import org.xml.sax.SAXException; - import org.xml.sax.InputSource; - import org.xml.sax.AttributeList; - - // Java - import java.util.Hashtable; - import java.util.Stack; - import java.io.IOException; - - /** - * SAX Handler that builds the formatting object tree. - */ - public class FOTreeBuilder extends HandlerBase { - - /** - * table mapping element names to the makers of objects - * representing formatting objects - */ - protected Hashtable fobjTable = new Hashtable(); - - /** - * class that builds a property list for each formatting object - */ - protected PropertyListBuilder propertyListBuilder = new - PropertyListBuilder(); - - /** - * current formatting object being handled - */ - protected FObj currentFObj = null; - - /** - * the root of the formatting object tree - */ - protected FObj rootFObj = null; - - /** - * set of names of formatting objects encountered but unknown - */ - protected Hashtable unknownFOs = new Hashtable(); - - // namespace implementation ideas pinched from John Cowan - protected static class NSMap { - String prefix; - String uri; - int level; - - NSMap(String prefix, String uri, int level) { - this.prefix = prefix; - this.uri = uri; - this.level = level; - } - } - - protected int level = 0; - protected Stack namespaceStack = new Stack(); - - { - namespaceStack.push(new NSMap("xml", - "http://www.w3.org/XML/1998/namespace", - -1)); - namespaceStack.push(new NSMap("", "", -1)); - } - - protected String findURI(String prefix) { - for (int i = namespaceStack.size() - 1; i >= 0; i--) { - NSMap nsMap = (NSMap) (namespaceStack.elementAt(i)); - if (prefix.equals(nsMap.prefix)) return nsMap.uri; - } - return null; - } - - protected String mapName(String name) - throws SAXException { - int colon = name.indexOf(':'); - String prefix = ""; - String localPart = name; - if (colon != -1) { - prefix = name.substring(0, colon); - localPart = name.substring(colon + 1); - } - String uri = findURI(prefix); - if (uri == null) { - if (prefix.equals("")) { - return name; - } else { - throw new SAXException(new FOPException("Unknown namespace prefix " + prefix)); - } - } - return uri + "^" + localPart; - } - - /** - * add a mapping from element name to maker. - * - * @param namespaceURI namespace URI of formatting object element - * @param localName local name of formatting object element - * @param maker Maker for class representing formatting object - */ - public void addMapping(String namespaceURI, String localName, - FObj.Maker maker) { - this.fobjTable.put(namespaceURI + "^" + localName, maker); - } - - /** SAX Handler for characters */ - public void characters(char data[], int start, int length) { - currentFObj.addCharacters(data, start, start + length); - } - - /** SAX Handler for the end of an element */ - public void endElement(String name) { - currentFObj.end(); - currentFObj = (FObj) currentFObj.getParent(); - level--; - while (((NSMap) namespaceStack.peek()).level > level) { - namespaceStack.pop(); - } - } - - /** SAX Handler for the start of the document */ - public void startDocument() { - System.err.println("building formatting object tree"); - } - - /** SAX Handler for the start of an element */ - public void startElement(String name, AttributeList attlist) - throws SAXException { - - /* the formatting object started */ - FObj fobj; - - /* the maker for the formatting object started */ - FObj.Maker fobjMaker; - - level++; - int length = attlist.getLength(); - for (int i = 0; i < length; i++) { - String att = attlist.getName(i); - if (att.equals("xmlns")) { - namespaceStack.push( new NSMap("", - attlist.getValue(i), - level)); - } else if (att.startsWith("xmlns:")) { - String value = attlist.getValue(i); - namespaceStack.push(new NSMap(att.substring(6), value, - level)); - } - } - String fullName = mapName(name); - - fobjMaker = (FObj.Maker) fobjTable.get(fullName); - - if (fobjMaker == null) { - if (!this.unknownFOs.containsKey(fullName)) { - this.unknownFOs.put(fullName, ""); - System.err.println("WARNING: Unknown formatting object " - + fullName); - } - fobjMaker = new FObjMixed.Maker(); // fall back - } - - try { - fobj = - fobjMaker.make(currentFObj, - this.propertyListBuilder.makeList(attlist, - (currentFObj == null) ? null : currentFObj.properties)); - } catch (FOPException e) { - throw new SAXException(e); - } - - if (rootFObj == null) { - rootFObj = fobj; - if (!fobj.getName().equals("fo:root")) { - throw new SAXException(new FOPException("Root element must" - + " be root, not " - + fobj.getName())); - } - } else { - currentFObj.addChild(fobj); - } - - currentFObj = fobj; - } - - /** - * format this formatting object tree - * - * @param areaTree the area tree to format into - */ - public void format(AreaTree areaTree) - throws FOPException { - System.err.println("formatting FOs into areas"); - ((Root) this.rootFObj).format(areaTree); - } - } - diff --git a/src/org/apache/fop/fo/FObj.java b/src/org/apache/fop/fo/FObj.java index 73aaddaae..9e48e969d 100644 --- a/src/org/apache/fop/fo/FObj.java +++ b/src/org/apache/fop/fo/FObj.java @@ -50,115 +50,58 @@ */ package org.apache.fop.fo; - - // FOP - import org.apache.fop.layout.Area; - import org.apache.fop.apps.FOPException; - - // Java - import java.util.Hashtable; - import java.util.Enumeration; - - /** - * base class for representation of formatting objects and their processing - */ - public class FObj extends FONode { - - public static class Maker { - public FObj make(FObj parent, PropertyList propertyList) - throws FOPException { - return new FObj(parent, propertyList); - } - } - - public static Maker maker() { - return new Maker(); - } - - protected PropertyList properties; - protected String name; - - protected FObj(FObj parent, PropertyList propertyList) { - super(parent); - this.properties = propertyList; - this.name = "default FO"; - } - - protected void addCharacters(char data[], int start, int length) { - // ignore - } - - public int layout(Area area) throws FOPException { - // should always be overridden - return OK; - } - - public String getName() { - return this.name; - } - - protected void start() { - // do nothing by default - } - - protected void end() { - // do nothing by default - } - } - - diff --git a/src/org/apache/fop/fo/FObjMixed.java b/src/org/apache/fop/fo/FObjMixed.java index 53d74a6e2..a005991ec 100644 --- a/src/org/apache/fop/fo/FObjMixed.java +++ b/src/org/apache/fop/fo/FObjMixed.java @@ -50,99 +50,50 @@ */ package org.apache.fop.fo; - - import org.apache.fop.layout.Area; - import org.apache.fop.apps.FOPException; - - /** - * base class for representation of mixed content formatting objects - * and their processing - */ - public class FObjMixed extends FObj { - - public static class Maker extends FObj.Maker { - public FObj make(FObj parent, PropertyList propertyList) - throws FOPException { - return new FObjMixed(parent, propertyList); - } - } - - public static FObj.Maker maker() { - return new FObjMixed.Maker(); - } - - protected FObjMixed(FObj parent, PropertyList propertyList) { - super(parent, propertyList); - } - - protected void addCharacters(char data[], int start, int length) { - children.addElement(new FOText(data,start,length,this)); - } - - public int layout(Area area) throws FOPException { - - if (this.marker == START) { - this.marker = 0; - } - - int numChildren = this.children.size(); - for (int i = this.marker; i < numChildren; i++) { - FONode fo = (FONode) children.elementAt(i); - int status; - if ((status = fo.layout(area)) != OK) { - this.marker = i; - return status; - } - } - return OK; - } - } - - diff --git a/src/org/apache/fop/fo/Property.java b/src/org/apache/fop/fo/Property.java index 65851aa2d..5645b2df4 100644 --- a/src/org/apache/fop/fo/Property.java +++ b/src/org/apache/fop/fo/Property.java @@ -50,83 +50,42 @@ */ package org.apache.fop.fo; - - import org.apache.fop.datatypes.*; - import org.apache.fop.apps.FOPException; - - public class Property { - - public static class Maker { - - public boolean isInherited() { return false; } - - public Property make(PropertyList propertyList, String value) throws FOPException { - return null; - } - - public Property make(PropertyList propertyList) throws FOPException { // default - return null; - } - - public Property compute(PropertyList propertyList) { // compute - return null; - } - } - protected PropertyList propertyList; - - public Length getLength() { return null; } - public String getString() { return null; } - public ColorType getColorType() { return null; } - public int getEnum() { return 0; } - - public static double toDouble(String s) { - double d; - try { - d = Double.valueOf(s).doubleValue(); - } catch (NumberFormatException e) { - d = Double.NaN; - } - return d; - } - - } - diff --git a/src/org/apache/fop/fo/PropertyList.java b/src/org/apache/fop/fo/PropertyList.java index d34ed50cc..ca53e2b0b 100644 --- a/src/org/apache/fop/fo/PropertyList.java +++ b/src/org/apache/fop/fo/PropertyList.java @@ -50,83 +50,42 @@ */ package org.apache.fop.fo; - - import java.util.Hashtable; - - import org.apache.fop.apps.FOPException; - - public class PropertyList extends Hashtable { - private PropertyListBuilder builder; - private PropertyList parentPropertyList = null; - - public PropertyList(PropertyList parentPropertyList) { - this.parentPropertyList = parentPropertyList; - } - - public Property get(String propertyName) { - - if (builder == null) - System.err.println("OH OH, builder has not been set"); - Property p = (Property)super.get(propertyName); - - if (p == null) { // if not explicit - p = this.builder.computeProperty(this,propertyName); - if (p == null) { // else inherit - if ((this.parentPropertyList != null)&&(this.builder.isInherited(propertyName))) { // check for parent - p = this.parentPropertyList.get(propertyName); // retrieve parent's value - } else { // default - try { - p = this.builder.makeProperty(this,propertyName); - } catch (FOPException e) { - // don't know what to do here - } - } - } - } - return p; - } - - public void setBuilder(PropertyListBuilder builder) { - this.builder = builder; - } - } - diff --git a/src/org/apache/fop/fo/PropertyListBuilder.java b/src/org/apache/fop/fo/PropertyListBuilder.java index c9c898f7d..9465cdc53 100644 --- a/src/org/apache/fop/fo/PropertyListBuilder.java +++ b/src/org/apache/fop/fo/PropertyListBuilder.java @@ -50,241 +50,121 @@ */ package org.apache.fop.fo; - - import org.apache.fop.fo.properties.*; - import org.apache.fop.svg.*; - - import org.apache.fop.apps.FOPException; - - import org.xml.sax.AttributeList; - - import java.util.Hashtable; - - public class PropertyListBuilder { - private Hashtable propertyTable; - - public PropertyListBuilder() { - this.propertyTable = new Hashtable(); - - propertyTable.put("end-indent",EndIndent.maker()); - propertyTable.put("page-master-name",PageMasterName.maker()); - propertyTable.put("page-master-first",PageMasterFirst.maker()); - propertyTable.put("page-master-repeating",PageMasterRepeating.maker()); - propertyTable.put("page-master-odd",PageMasterOdd.maker()); - propertyTable.put("page-master-even",PageMasterEven.maker()); - propertyTable.put("margin-top",MarginTop.maker()); - propertyTable.put("margin-bottom",MarginBottom.maker()); - propertyTable.put("margin-left",MarginLeft.maker()); - propertyTable.put("margin-right",MarginRight.maker()); - propertyTable.put("extent",Extent.maker()); - propertyTable.put("page-width",PageWidth.maker()); - propertyTable.put("page-height",PageHeight.maker()); - propertyTable.put("flow-name",FlowName.maker()); - propertyTable.put("font-family",FontFamily.maker()); - propertyTable.put("font-style",FontStyle.maker()); - propertyTable.put("font-weight",FontWeight.maker()); - propertyTable.put("font-size",FontSize.maker()); - propertyTable.put("line-height",LineHeight.maker()); - propertyTable.put("text-align",TextAlign.maker()); - propertyTable.put("text-align-last",TextAlignLast.maker()); - propertyTable.put("space-before.optimum",SpaceBeforeOptimum.maker()); - propertyTable.put("space-after.optimum",SpaceAfterOptimum.maker()); - propertyTable.put("start-indent",StartIndent.maker()); - propertyTable.put("end-indent",EndIndent.maker()); - propertyTable.put("provisional-distance-between-starts",ProvisionalDistanceBetweenStarts.maker()); - propertyTable.put("provisional-label-separation",ProvisionalLabelSeparation.maker()); - propertyTable.put("rule-thickness",RuleThickness.maker()); - propertyTable.put("color",Color.maker()); - propertyTable.put("wrap-option",WrapOption.maker()); - propertyTable.put("white-space-treatment",WhiteSpaceTreatment.maker()); - propertyTable.put("break-before",BreakBefore.maker()); - propertyTable.put("break-after",BreakAfter.maker()); - propertyTable.put("text-indent",TextIndent.maker()); - propertyTable.put("href",HRef.maker()); - propertyTable.put("column-width",ColumnWidth.maker()); - propertyTable.put("height",SVGLength.maker()); - propertyTable.put("width",SVGLength.maker()); - propertyTable.put("x",SVGLength.maker()); - propertyTable.put("y",SVGLength.maker()); - propertyTable.put("x1",SVGLength.maker()); - propertyTable.put("x2",SVGLength.maker()); - propertyTable.put("y1",SVGLength.maker()); - propertyTable.put("y2",SVGLength.maker()); - } - - public Property computeProperty(PropertyList propertyList, String propertyName) { - - Property p = null; - - Property.Maker propertyMaker = (Property.Maker)propertyTable.get(propertyName); - if (propertyMaker != null) { - p = propertyMaker.compute(propertyList); - } else { - //System.err.println("WARNING: property " + propertyName + " ignored"); - } - return p; - } - - public boolean isInherited(String propertyName) { - boolean b; - - Property.Maker propertyMaker = (Property.Maker)propertyTable.get(propertyName); - if (propertyMaker != null) { - b = propertyMaker.isInherited(); - } else { - //System.err.println("WARNING: Unknown property " + propertyName); - b = true; - } - return b; - } - - public PropertyList makeList(AttributeList attributes, PropertyList parentPropertyList) throws FOPException { - - PropertyList p = new PropertyList(parentPropertyList); - p.setBuilder(this); - - for (int i = 0; i < attributes.getLength(); i++) { - String attributeName = attributes.getName(i); - Property.Maker propertyMaker = (Property.Maker)propertyTable.get(attributeName); - if (propertyMaker != null) { - p.put(attributeName,propertyMaker.make(p,attributes.getValue(i))); - } else { - //System.err.println("WARNING: property " + attributeName + " ignored"); - } - } - - return p; - } - - public Property makeProperty(PropertyList propertyList, String propertyName) throws FOPException { - - Property p = null; - - Property.Maker propertyMaker = (Property.Maker)propertyTable.get(propertyName); - if (propertyMaker != null) { - p = propertyMaker.make(propertyList); - } else { - //System.err.println("WARNING: property " + propertyName + " ignored"); - } - return p; - } - } - diff --git a/src/org/apache/fop/fo/StandardElementMapping.java b/src/org/apache/fop/fo/StandardElementMapping.java index 16e7f47d4..006c3bd4e 100644 --- a/src/org/apache/fop/fo/StandardElementMapping.java +++ b/src/org/apache/fop/fo/StandardElementMapping.java @@ -50,105 +50,53 @@ */ package org.apache.fop.fo; - - import org.apache.fop.fo.flow.*; - import org.apache.fop.fo.pagination.*; - - public class StandardElementMapping implements ElementMapping { - - public void addToBuilder(FOTreeBuilder builder) { - - String uri = "http://www.w3.org/1999/XSL/Format"; - - builder.addMapping(uri, "root", Root.maker()); - builder.addMapping(uri, "layout-master-set", - LayoutMasterSet.maker()); - builder.addMapping(uri, "simple-page-master", - SimplePageMaster.maker()); - builder.addMapping(uri, "region-body", RegionBody.maker()); - builder.addMapping(uri, "region-before", RegionBefore.maker()); - builder.addMapping(uri, "region-after", RegionAfter.maker()); - builder.addMapping(uri, "page-sequence", PageSequence.maker()); - builder.addMapping(uri, "sequence-specification", - SequenceSpecification.maker()); - builder.addMapping(uri, "sequence-specifier-single", - SequenceSpecifierSingle.maker()); - builder.addMapping(uri, "sequence-specifier-repeating", - SequenceSpecifierRepeating.maker()); - builder.addMapping(uri, "sequence-specifier-alternating", - SequenceSpecifierAlternating.maker()); - builder.addMapping(uri, "flow", Flow.maker()); - builder.addMapping(uri, "static-content", - StaticContent.maker()); - builder.addMapping(uri, "block", Block.maker()); - builder.addMapping(uri, "list-block", ListBlock.maker()); - builder.addMapping(uri, "list-item", ListItem.maker()); - builder.addMapping(uri, "list-item-label", - ListItemLabel.maker()); - builder.addMapping(uri, "list-item-body", ListItemBody.maker()); - builder.addMapping(uri, "page-number", PageNumber.maker()); - builder.addMapping(uri, "display-sequence", - DisplaySequence.maker()); - builder.addMapping(uri, "inline-sequence", - InlineSequence.maker()); - builder.addMapping(uri, "display-rule", DisplayRule.maker()); - builder.addMapping(uri, "display-graphic", - DisplayGraphic.maker()); - builder.addMapping(uri, "table", Table.maker()); - builder.addMapping(uri, "table-column", TableColumn.maker()); - builder.addMapping(uri, "table-body", TableBody.maker()); - builder.addMapping(uri, "table-row", TableRow.maker()); - builder.addMapping(uri, "table-cell", TableCell.maker()); - } - } - diff --git a/src/org/apache/fop/fo/flow/Block.java b/src/org/apache/fop/fo/flow/Block.java index 55e115c35..113b9eeb3 100644 --- a/src/org/apache/fop/fo/flow/Block.java +++ b/src/org/apache/fop/fo/flow/Block.java @@ -50,385 +50,193 @@ */ package org.apache.fop.fo.flow; - - // FOP - import org.apache.fop.fo.*; - import org.apache.fop.fo.properties.*; - import org.apache.fop.layout.*; - import org.apache.fop.apps.FOPException; - - public class Block extends FObjMixed { - - public static class Maker extends FObj.Maker { - public FObj make(FObj parent, PropertyList propertyList) - throws FOPException { - return new Block(parent, propertyList); - } - } - - public static FObj.Maker maker() { - return new Block.Maker(); - } - - FontState fs; - int align; - int alignLast; - int breakBefore; - int breakAfter; - int lineHeight; - int startIndent; - int endIndent; - int spaceBefore; - int spaceAfter; - int textIndent; - - BlockArea blockArea; - - // this may be helpful on other FOs too - boolean anythingLaidOut = false; - - public Block(FObj parent, PropertyList propertyList) { - super(parent, propertyList); - this.name = "fo:block"; - } - - public int layout(Area area) throws FOPException { - // System.err.print(" b:LAY[" + marker + "] "); - - if (this.marker == BREAK_AFTER) { - return OK; - } - - if (this.marker == START) { - String fontFamily = - this.properties.get("font-family").getString(); - String fontStyle = - this.properties.get("font-style").getString(); - String fontWeight = - this.properties.get("font-weight").getString(); - int fontSize = - this.properties.get("font-size").getLength().mvalue(); - - this.fs = new FontState(area.getFontInfo(), fontFamily, - fontStyle, fontWeight, fontSize); - this.align = this.properties.get("text-align").getEnum(); - this.alignLast = - this.properties.get("text-align-last").getEnum(); - this.breakBefore = - this.properties.get("break-before").getEnum(); - this.breakAfter = - this.properties.get("break-after").getEnum(); - this.lineHeight = - this.properties.get("line-height").getLength().mvalue(); - this.startIndent = - this.properties.get("start-indent").getLength().mvalue(); - this.endIndent = - this.properties.get("end-indent").getLength().mvalue(); - this.spaceBefore = - this.properties.get("space-before.optimum").getLength().mvalue(); - this.spaceAfter = - this.properties.get("space-after.optimum").getLength().mvalue(); - this.textIndent = - this.properties.get("text-indent").getLength().mvalue(); - - if (area instanceof BlockArea) { - area.end(); - } - if (this.isInLabel) { - startIndent += bodyIndent; - endIndent += (area.getAllocationWidth() - - distanceBetweenStarts - startIndent) - + labelSeparation; - } - - if (this.isInListBody) { - startIndent += bodyIndent + distanceBetweenStarts; - } - - if (this.isInTableCell) { - startIndent += forcedStartOffset; - endIndent = area.getAllocationWidth() - startIndent - - forcedWidth; - } - - this.marker = 0; - - if (breakBefore == BreakBefore.PAGE) { - return FORCE_PAGE_BREAK; - } - - if (breakBefore == BreakBefore.ODD_PAGE) { - return FORCE_PAGE_BREAK_ODD; - } - - if (breakBefore == BreakBefore.EVEN_PAGE) { - return FORCE_PAGE_BREAK_EVEN; - } - } - - if ((spaceBefore != 0) && (this.marker ==0)) { - area.addDisplaySpace(spaceBefore); - } - - if (anythingLaidOut) { - this.textIndent = 0; - } - - this.blockArea = - new BlockArea(fs, area.getAllocationWidth(), - area.spaceLeft(), startIndent, endIndent, - textIndent, align, alignLast, lineHeight); - blockArea.setPage(area.getPage()); - blockArea.start(); - - int numChildren = this.children.size(); - for (int i = this.marker; i < numChildren; i++) { - FONode fo = (FONode) children.elementAt(i); - if (this.isInListBody) { - fo.setIsInListBody(); - fo.setDistanceBetweenStarts(this.distanceBetweenStarts); - fo.setBodyIndent(this.bodyIndent); - } - int status; - if ((status = fo.layout(blockArea)) != OK) { - this.marker = i; - if ((i != 0) && (status == AREA_FULL_NONE)) { - status = AREA_FULL_SOME; - } - //blockArea.end(); - area.addChild(blockArea); - area.increaseHeight(blockArea.getHeight()); - anythingLaidOut = true; - return status; - } - anythingLaidOut = true; - } - - blockArea.end(); - area.addChild(blockArea); - - /* should this be combined into above? */ - area.increaseHeight(blockArea.getHeight()); - - if (spaceAfter != 0) { - area.addDisplaySpace(spaceAfter); - } - - if (area instanceof BlockArea) { - area.start(); - } - - if (breakAfter == BreakAfter.PAGE) { - this.marker = BREAK_AFTER; - return FORCE_PAGE_BREAK; - } - - if (breakAfter == BreakAfter.ODD_PAGE) { - this.marker = BREAK_AFTER; - return FORCE_PAGE_BREAK_ODD; - } - - if (breakAfter == BreakAfter.EVEN_PAGE) { - this.marker = BREAK_AFTER; - return FORCE_PAGE_BREAK_EVEN; - } - - //System.err.print(" b:OK" + marker + " "); - return OK; - } - - public int getAreaHeight() { - return blockArea.getHeight(); - } - } - diff --git a/src/org/apache/fop/fo/flow/DisplayGraphic.java b/src/org/apache/fop/fo/flow/DisplayGraphic.java index a424a9b71..47e360fae 100644 --- a/src/org/apache/fop/fo/flow/DisplayGraphic.java +++ b/src/org/apache/fop/fo/flow/DisplayGraphic.java @@ -50,265 +50,133 @@ */ package org.apache.fop.fo.flow; - - // FOP - import org.apache.fop.fo.*; - import org.apache.fop.fo.properties.*; - import org.apache.fop.layout.Area; - import org.apache.fop.layout.BlockArea; - import org.apache.fop.layout.FontState; - import org.apache.fop.apps.FOPException; - import org.apache.fop.image.*; - - // Java - import java.util.Enumeration; - import java.util.Hashtable; - - public class DisplayGraphic extends FObj { - public static class Maker extends FObj.Maker { - public FObj make(FObj parent, PropertyList propertyList) - throws FOPException { - return new DisplayGraphic(parent, propertyList); - } - } - - public static FObj.Maker maker() { - return new DisplayGraphic.Maker(); - } - - FontState fs; - int align; - int startIndent; - int endIndent; - int spaceBefore; - int spaceAfter; - String href; - int height; - int width; - - ImageArea imageArea; - - public DisplayGraphic(FObj parent, PropertyList propertyList) { - super(parent, propertyList); - this.name = "fo:display-graphic"; - } - - public int layout(Area area) throws FOPException { - - if (this.marker == START) { - String fontFamily = - this.properties.get("font-family").getString(); - String fontStyle = - this.properties.get("font-style").getString(); - String fontWeight = - this.properties.get("font-weight").getString(); - int fontSize = - this.properties.get("font-size").getLength().mvalue(); - - this.fs = new FontState(area.getFontInfo(), fontFamily, - fontStyle, fontWeight, fontSize); - - // FIXME - this.align = this.properties.get("text-align").getEnum(); - - this.startIndent = - this.properties.get("start-indent").getLength().mvalue(); - this.endIndent = - this.properties.get("end-indent").getLength().mvalue(); - - this.spaceBefore = - this.properties.get("space-before.optimum").getLength().mvalue(); - this.spaceAfter = - this.properties.get("space-after.optimum").getLength().mvalue(); - - this.href = this.properties.get("href").getString(); - this.width = - this.properties.get("width").getLength().mvalue(); - this.height = - this.properties.get("height").getLength().mvalue(); - - if (area instanceof BlockArea) { - area.end(); - } - - if (this.isInLabel) { - startIndent += bodyIndent; - endIndent += (area.getAllocationWidth() - - distanceBetweenStarts - startIndent) - + labelSeparation; - } - - if (this.isInListBody) { - startIndent += bodyIndent + distanceBetweenStarts; - } - - if (this.isInTableCell) { - startIndent += forcedStartOffset; - endIndent = area.getAllocationWidth() - startIndent - - forcedWidth; - } - - this.marker = 0; - } - - if ((spaceBefore != 0) && (this.marker == 0)) { - area.addDisplaySpace(spaceBefore); - } - - FopImage img = FopImageFactory.Make(href, 0, 0, width, height); - - this.imageArea = new ImageArea(fs, - img, - area.getAllocationWidth(), - img.getWidth(), - img.getHeight(), - startIndent, endIndent, - align); - - imageArea.start(); - imageArea.end(); - area.addChild(imageArea); - area.increaseHeight(imageArea.getHeight()); - - if (spaceAfter != 0) { - area.addDisplaySpace(spaceAfter); - } - - if (area instanceof BlockArea) { - area.start(); - } - - return OK; - } - } - diff --git a/src/org/apache/fop/fo/flow/DisplayRule.java b/src/org/apache/fop/fo/flow/DisplayRule.java index 4e988fb03..855ec6d8d 100644 --- a/src/org/apache/fop/fo/flow/DisplayRule.java +++ b/src/org/apache/fop/fo/flow/DisplayRule.java @@ -50,177 +50,89 @@ */ package org.apache.fop.fo.flow; - - // FOP - import org.apache.fop.fo.*; - import org.apache.fop.fo.properties.*; - import org.apache.fop.datatypes.*; - import org.apache.fop.layout.Area; - import org.apache.fop.layout.BlockArea; - import org.apache.fop.layout.RuleArea; - import org.apache.fop.layout.FontState; - import org.apache.fop.apps.FOPException; - - public class DisplayRule extends FObj { - - public static class Maker extends FObj.Maker { - public FObj make(FObj parent, PropertyList propertyList) - throws FOPException { - return new DisplayRule(parent, propertyList); - } - } - - public static FObj.Maker maker() { - return new DisplayRule.Maker(); - } - - public DisplayRule(FObj parent, PropertyList propertyList) { - super(parent, propertyList); - this.name = "fo:display-rule"; - } - - public int layout(Area area) throws FOPException { - // FIXME: doesn't check to see if it will fit - - String fontFamily = this.properties.get("font-family").getString(); - String fontStyle = this.properties.get("font-style").getString(); - String fontWeight = this.properties.get("font-weight").getString(); - int fontSize = this.properties.get("font-size").getLength().mvalue(); - - FontState fs = new FontState(area.getFontInfo(), fontFamily, - fontStyle, fontWeight, fontSize); - - int align = this.properties.get("text-align").getEnum(); - int startIndent = - this.properties.get("start-indent").getLength().mvalue(); - int endIndent = - this.properties.get("end-indent").getLength().mvalue(); - int spaceBefore = - this.properties.get("space-before.optimum").getLength().mvalue(); - int spaceAfter = - this.properties.get("space-after.optimum").getLength().mvalue(); - int ruleThickness = - this.properties.get("rule-thickness").getLength().mvalue(); - int ruleLength = 0; // not used; - - ColorType c = this.properties.get("color").getColorType(); - float red = c.red(); - float green = c.green(); - float blue = c.blue(); - - if (area instanceof BlockArea) { - area.end(); - } - - if (spaceBefore != 0) { - area.addDisplaySpace(spaceBefore); - } - - RuleArea ruleArea = new RuleArea(fs, - area.getAllocationWidth(), - area.spaceLeft(), - startIndent, endIndent, - align, ruleThickness, - ruleLength, red, green, - blue); - area.addChild(ruleArea); - area.increaseHeight(ruleArea.getHeight()); - - if (spaceAfter != 0) { - area.addDisplaySpace(spaceAfter); - } - - if (area instanceof BlockArea) { - area.start(); - } - - return OK; - } - } - diff --git a/src/org/apache/fop/fo/flow/DisplaySequence.java b/src/org/apache/fop/fo/flow/DisplaySequence.java index c83807140..35189ebff 100644 --- a/src/org/apache/fop/fo/flow/DisplaySequence.java +++ b/src/org/apache/fop/fo/flow/DisplaySequence.java @@ -50,105 +50,53 @@ */ package org.apache.fop.fo.flow; - - // FOP - import org.apache.fop.fo.*; - import org.apache.fop.layout.Area; - import org.apache.fop.apps.FOPException; - - // Java - import java.util.Enumeration; - - public class DisplaySequence extends FObj { - - public static class Maker extends FObj.Maker { - public FObj make(FObj parent, PropertyList propertyList) - throws FOPException { - return new DisplaySequence(parent, propertyList); - } - } - - public static FObj.Maker maker() { - return new DisplaySequence.Maker(); - } - - public DisplaySequence(FObj parent, PropertyList propertyList) { - super(parent, propertyList); - this.name = "fo:display-sequence"; - } - - public int layout(Area area) throws FOPException { - if (this.marker == START) { - this.marker = 0; - } - // this is such common code, perhaps it should be in the super class - int numChildren = this.children.size(); - for (int i = this.marker; i < numChildren; i++) { - FObj fo = (FObj) children.elementAt(i); - int status; - if ((status = fo.layout(area)) != OK) { - /* message from child */ - if (status > OK) { - /* child still successful */ - this.marker = i+1; - } else { - /* child unsucessful */ - this.marker = i; - } - return status; - } - } - return OK; - } - } - diff --git a/src/org/apache/fop/fo/flow/Flow.java b/src/org/apache/fop/fo/flow/Flow.java index 66d7e4781..380af416c 100644 --- a/src/org/apache/fop/fo/flow/Flow.java +++ b/src/org/apache/fop/fo/flow/Flow.java @@ -50,119 +50,60 @@ */ package org.apache.fop.fo.flow; - - // FOP - import org.apache.fop.fo.*; - import org.apache.fop.fo.properties.*; - import org.apache.fop.fo.pagination.PageSequence; - import org.apache.fop.layout.Area; - import org.apache.fop.apps.FOPException; - - // Java - import java.util.Hashtable; - import java.util.Enumeration; - - public class Flow extends FObj { - - public static class Maker extends FObj.Maker { - public FObj make(FObj parent, PropertyList propertyList) - throws FOPException { - return new Flow(parent, propertyList); - } - } - - public static FObj.Maker maker() { - return new Flow.Maker(); - } - - PageSequence pageSequence; - - protected Flow(FObj parent, PropertyList propertyList) - throws FOPException { - super(parent, propertyList); - this.name = "fo:flow"; - - if (parent.getName().equals("fo:page-sequence")) { - this.pageSequence = (PageSequence) parent; - } else { - throw new FOPException("flow must be child of " - + "page-sequence, not " - + parent.getName()); - } - pageSequence.setFlow(this); - } - - public int layout(Area area) throws FOPException { - if (this.marker == START) { - this.marker = 0; - } - int numChildren = this.children.size(); - for (int i = this.marker; i < numChildren; i++) { - FObj fo = (FObj) children.elementAt(i); - int status; - if ((status = fo.layout(area)) != OK) { - this.marker = i; - return status; - } - } - return OK; - } - } - diff --git a/src/org/apache/fop/fo/flow/InlineSequence.java b/src/org/apache/fop/fo/flow/InlineSequence.java index 04aeb2be5..c7965636a 100644 --- a/src/org/apache/fop/fo/flow/InlineSequence.java +++ b/src/org/apache/fop/fo/flow/InlineSequence.java @@ -50,71 +50,36 @@ */ package org.apache.fop.fo.flow; - - // FOP - import org.apache.fop.fo.*; - import org.apache.fop.layout.Area; - import org.apache.fop.apps.FOPException; - - // Java - import java.util.Enumeration; - - public class InlineSequence extends FObjMixed { - - public static class Maker extends FObj.Maker { - public FObj make(FObj parent, PropertyList propertyList) - throws FOPException { - return new InlineSequence(parent, propertyList); - } - } - - public static FObj.Maker maker() { - return new InlineSequence.Maker(); - } - - public InlineSequence(FObj parent, PropertyList propertyList) - throws FOPException { - super(parent, propertyList); - this.name = "fo:inline-sequence"; - - if (parent.getName().equals("fo:flow")) { - throw new FOPException("inline-sequence can't be directly" - + " under flow"); - } - } - - } - diff --git a/src/org/apache/fop/fo/flow/ListBlock.java b/src/org/apache/fop/fo/flow/ListBlock.java index 99f351c5a..a3a649719 100644 --- a/src/org/apache/fop/fo/flow/ListBlock.java +++ b/src/org/apache/fop/fo/flow/ListBlock.java @@ -50,287 +50,144 @@ */ package org.apache.fop.fo.flow; - - // FOP - import org.apache.fop.fo.*; - import org.apache.fop.fo.properties.*; - import org.apache.fop.layout.Area; - import org.apache.fop.layout.BlockArea; - import org.apache.fop.layout.FontState; - import org.apache.fop.apps.FOPException; - - // Java - import java.util.Enumeration; - - public class ListBlock extends FObj { - - public static class Maker extends FObj.Maker { - public FObj make(FObj parent, PropertyList propertyList) - throws FOPException { - return new ListBlock(parent, propertyList); - } - } - - public static FObj.Maker maker() { - return new ListBlock.Maker(); - } - - FontState fs; - int align; - int alignLast; - int breakBefore; - int breakAfter; - int lineHeight; - int startIndent; - int endIndent; - int spaceBefore; - int spaceAfter; - int provisionalDistanceBetweenStarts; - int provisionalLabelSeparation; - int spaceBetweenListRows = 0; - - public ListBlock(FObj parent, PropertyList propertyList) { - super(parent, propertyList); - this.name = "fo:list-block"; - } - - public int layout(Area area) throws FOPException { - if (this.marker == START) { - String fontFamily = - this.properties.get("font-family").getString(); - String fontStyle = - this.properties.get("font-style").getString(); - String fontWeight = - this.properties.get("font-weight").getString(); - int fontSize = - this.properties.get("font-size").getLength().mvalue(); - - this.fs = new FontState(area.getFontInfo(), fontFamily, - fontStyle, fontWeight, fontSize); - - this.align = this.properties.get("text-align").getEnum(); - this.alignLast = - this.properties.get("text-align-last").getEnum(); - this.lineHeight = - this.properties.get("line-height").getLength().mvalue(); - this.startIndent = - this.properties.get("start-indent").getLength().mvalue(); - this.endIndent = - this.properties.get("end-indent").getLength().mvalue(); - this.spaceBefore = - this.properties.get("space-before.optimum").getLength().mvalue(); - this.spaceAfter = - this.properties.get("space-after.optimum").getLength().mvalue(); - this.provisionalDistanceBetweenStarts = - this.properties.get("provisional-distance-between-starts").getLength().mvalue(); - this.provisionalLabelSeparation = - this.properties.get("provisional-label-separation").getLength().mvalue(); - this.spaceBetweenListRows = 0; // not used at present - - this.marker = 0; - - if (area instanceof BlockArea) { - area.end(); - } - - if (spaceBefore != 0) { - area.addDisplaySpace(spaceBefore); - } - - if (this.isInListBody) { - startIndent += bodyIndent + distanceBetweenStarts; - bodyIndent = startIndent; - } - } - - BlockArea blockArea = - new BlockArea(fs, area.getAllocationWidth(), - area.spaceLeft(), startIndent, endIndent, 0, - align, alignLast, lineHeight); - blockArea.setPage(area.getPage()); - blockArea.start(); - - int numChildren = this.children.size(); - for (int i = this.marker; i < numChildren; i++) { - if (!(children.elementAt(i) instanceof ListItem)) { - System.err.println("WARNING: This version of FOP requires list-items inside list-blocks"); - return OK; - } - ListItem listItem = (ListItem) children.elementAt(i); - listItem.setDistanceBetweenStarts(this.provisionalDistanceBetweenStarts); - listItem.setLabelSeparation(this.provisionalLabelSeparation); - listItem.setBodyIndent(this.bodyIndent); - int status; - if ((status = listItem.layout(blockArea)) != OK) { - /* message from child */ - if (status > OK) { - /* child still successful */ - this.marker = i+1; - } else { - /* child unsucessful */ - this.marker = i; - } - blockArea.end(); - area.addChild(blockArea); - area.increaseHeight(blockArea.getHeight()); - return status; - } - } - - blockArea.end(); - area.addChild(blockArea); - area.increaseHeight(blockArea.getHeight()); - - if (spaceAfter != 0) { - area.addDisplaySpace(spaceAfter); - } - - if (area instanceof BlockArea) { - area.start(); - } - - return OK; - } - } - diff --git a/src/org/apache/fop/fo/flow/ListItem.java b/src/org/apache/fop/fo/flow/ListItem.java index cf43f72a3..4ab9a8290 100644 --- a/src/org/apache/fop/fo/flow/ListItem.java +++ b/src/org/apache/fop/fo/flow/ListItem.java @@ -50,289 +50,145 @@ */ package org.apache.fop.fo.flow; - - // FOP - import org.apache.fop.fo.*; - import org.apache.fop.fo.properties.*; - import org.apache.fop.layout.Area; - import org.apache.fop.layout.BlockArea; - import org.apache.fop.layout.FontState; - import org.apache.fop.apps.FOPException; - - // Java - import java.util.Enumeration; - - public class ListItem extends FObj { - - public static class Maker extends FObj.Maker { - public FObj make(FObj parent, PropertyList propertyList) - throws FOPException { - return new ListItem(parent, propertyList); - } - } - - public static FObj.Maker maker() { - return new ListItem.Maker(); - } - - FontState fs; - int align; - int alignLast; - int breakBefore; - int breakAfter; - int lineHeight; - int startIndent; - int endIndent; - int spaceBefore; - int spaceAfter; - - public ListItem(FObj parent, PropertyList propertyList) { - super(parent, propertyList); - this.name = "fo:list-item"; - } - - public int layout(Area area) throws FOPException { - if (this.marker == START) { - String fontFamily = - this.properties.get("font-family").getString(); - String fontStyle = - this.properties.get("font-style").getString(); - String fontWeight = - this.properties.get("font-weight").getString(); - int fontSize = - this.properties.get("font-size").getLength().mvalue(); - - this.fs = new FontState(area.getFontInfo(), fontFamily, - fontStyle, fontWeight, fontSize); - - this.align = this.properties.get("text-align").getEnum(); - this.alignLast = - this.properties.get("text-align-last").getEnum(); - this.lineHeight = - this.properties.get("line-height").getLength().mvalue(); - this.startIndent = - this.properties.get("start-indent").getLength().mvalue(); - this.endIndent = - this.properties.get("end-indent").getLength().mvalue(); - this.spaceBefore = - this.properties.get("space-before.optimum").getLength().mvalue(); - this.spaceAfter = - this.properties.get("space-after.optimum").getLength().mvalue(); - - this.marker = 0; - } - - /* not sure this is needed given we know area is from list block */ - if (area instanceof BlockArea) { - area.end(); - } - - if (spaceBefore != 0) { - area.addDisplaySpace(spaceBefore); - } - - startIndent += this.bodyIndent; - - BlockArea blockArea = - new BlockArea(fs, area.getAllocationWidth(), - area.spaceLeft(), startIndent, endIndent, - 0, align, alignLast, lineHeight); - blockArea.setPage(area.getPage()); - blockArea.start(); - - int numChildren = this.children.size(); - if (numChildren != 2) { - throw new FOPException("list-item must have exactly two children"); - } - ListItemLabel label = (ListItemLabel) children.elementAt(0); - ListItemBody body = (ListItemBody) children.elementAt(1); - - label.setDistanceBetweenStarts(this.distanceBetweenStarts); - label.setLabelSeparation(this.labelSeparation); - label.setBodyIndent(this.bodyIndent); - - body.setDistanceBetweenStarts(this.distanceBetweenStarts); - body.setBodyIndent(this.bodyIndent); - - /* this doesn't actually do anything */ - body.setLabelSeparation(this.labelSeparation); - - int status; - - // what follows doesn't yet take into account whether the - // body failed completely or only got some text in - - if (this.marker == 0) { - status = label.layout(blockArea); - if (status != OK) { - return status; - } - } - - status = body.layout(blockArea); - if (status != OK) { - blockArea.end(); - area.addChild(blockArea); - area.increaseHeight(blockArea.getHeight()); - this.marker = 1; - return status; - } - - blockArea.end(); - area.addChild(blockArea); - area.increaseHeight(blockArea.getHeight()); - - if (spaceAfter != 0) { - area.addDisplaySpace(spaceAfter); - } - - /* not sure this is needed given we know area is from list block */ - if (area instanceof BlockArea) { - area.start(); - } - return OK; - } - } - diff --git a/src/org/apache/fop/fo/flow/ListItemBody.java b/src/org/apache/fop/fo/flow/ListItemBody.java index f62962889..c3799860e 100644 --- a/src/org/apache/fop/fo/flow/ListItemBody.java +++ b/src/org/apache/fop/fo/flow/ListItemBody.java @@ -50,109 +50,55 @@ */ package org.apache.fop.fo.flow; - - // FOP - import org.apache.fop.fo.*; - import org.apache.fop.fo.properties.*; - import org.apache.fop.layout.Area; - import org.apache.fop.layout.FontState; - import org.apache.fop.apps.FOPException; - - // Java - import java.util.Enumeration; - - public class ListItemBody extends FObj { - - public static class Maker extends FObj.Maker { - public FObj make(FObj parent, PropertyList propertyList) - throws FOPException { - return new ListItemBody(parent, propertyList); - } - } - - public static FObj.Maker maker() { - return new ListItemBody.Maker(); - } - - public ListItemBody(FObj parent, PropertyList propertyList) { - super(parent, propertyList); - this.name = "fo:list-item-body"; - } - - public int layout(Area area) throws FOPException { - if (this.marker == START) { - this.marker = 0; - } - int numChildren = this.children.size(); - for (int i = this.marker; i < numChildren; i++) { - FObj fo = (FObj) children.elementAt(i); - fo.setIsInListBody(); - fo.setDistanceBetweenStarts(this.distanceBetweenStarts); - fo.setLabelSeparation(this.labelSeparation); - fo.setBodyIndent(this.bodyIndent); - int status; - if ((status = fo.layout(area)) != OK) { - this.marker = i; - if ((i == 0) && (status == AREA_FULL_NONE)) { - return AREA_FULL_NONE; - } else { - return AREA_FULL_SOME; - } - } - } - return OK; - } - } - diff --git a/src/org/apache/fop/fo/flow/ListItemLabel.java b/src/org/apache/fop/fo/flow/ListItemLabel.java index b2ecb6eb7..07278de8b 100644 --- a/src/org/apache/fop/fo/flow/ListItemLabel.java +++ b/src/org/apache/fop/fo/flow/ListItemLabel.java @@ -50,99 +50,50 @@ */ package org.apache.fop.fo.flow; - - // FOP - import org.apache.fop.fo.*; - import org.apache.fop.fo.properties.*; - import org.apache.fop.layout.Area; - import org.apache.fop.layout.FontState; - import org.apache.fop.apps.FOPException; - - // Java - import java.util.Enumeration; - - public class ListItemLabel extends FObj { - - public static class Maker extends FObj.Maker { - public FObj make(FObj parent, PropertyList propertyList) - throws FOPException { - return new ListItemLabel(parent, propertyList); - } - } - - public static FObj.Maker maker() { - return new ListItemLabel.Maker(); - } - - public ListItemLabel(FObj parent, PropertyList propertyList) { - super(parent, propertyList); - this.name = "fo:list-item-label"; - } - - public int layout(Area area) throws FOPException { - int numChildren = this.children.size(); - - if (numChildren != 1) { - throw new FOPException("list-item-label must have exactly one block in this version of FOP"); - } - Block block = (Block) children.elementAt(0); - - block.setIsInLabel(); - block.setDistanceBetweenStarts(this.distanceBetweenStarts); - block.setLabelSeparation(this.labelSeparation); - block.setBodyIndent(this.bodyIndent); - - int status; - status = block.layout(area); - area.addDisplaySpace(-block.getAreaHeight()); - return status; - } - } - diff --git a/src/org/apache/fop/fo/flow/PageNumber.java b/src/org/apache/fop/fo/flow/PageNumber.java index 338929aff..e31d7ab62 100644 --- a/src/org/apache/fop/fo/flow/PageNumber.java +++ b/src/org/apache/fop/fo/flow/PageNumber.java @@ -50,133 +50,67 @@ */ package org.apache.fop.fo.flow; - - // FOP - import org.apache.fop.fo.*; - import org.apache.fop.datatypes.*; - import org.apache.fop.fo.properties.*; - import org.apache.fop.layout.*; - import org.apache.fop.apps.FOPException; - - // Java - import java.util.Enumeration; - - public class PageNumber extends FObj { - - public static class Maker extends FObj.Maker { - public FObj make(FObj parent, PropertyList propertyList) - throws FOPException { - return new PageNumber(parent, propertyList); - } - } - - public static FObj.Maker maker() { - return new PageNumber.Maker(); - } - - FontState fs; - float red; - float green; - float blue; - int wrapOption; - int whiteSpaceTreatment; - - public PageNumber(FObj parent, PropertyList propertyList) { - super(parent, propertyList); - this.name = "fo:page-number"; - } - - public int layout(Area area) throws FOPException { - if (!(area instanceof BlockArea)) { - System.err.println("WARNING: page-number outside block area"); - return OK; - } - if (this.marker == START) { - String fontFamily = this.properties.get("font-family").getString(); - String fontStyle = this.properties.get("font-style").getString(); - String fontWeight = this.properties.get("font-weight").getString(); - int fontSize = this.properties.get("font-size").getLength().mvalue(); - - this.fs = new FontState(area.getFontInfo(), fontFamily, - fontStyle, fontWeight, fontSize); - - ColorType c = this.properties.get("color").getColorType(); - this.red = c.red(); - this.green = c.green(); - this.blue = c.blue(); - - this.wrapOption = this.properties.get("wrap-option").getEnum(); - this.whiteSpaceTreatment = this.properties.get("white-space-treatment").getEnum(); - - this.marker = 0; - } - String p = Integer.toString(area.getPage().getNumber()); - this.marker = ((BlockArea) area).addText(fs, red, green, blue, wrapOption, whiteSpaceTreatment, p.toCharArray(), 0, p.length()); - return OK; - } - } - diff --git a/src/org/apache/fop/fo/flow/StaticContent.java b/src/org/apache/fop/fo/flow/StaticContent.java index 22a983ce9..e62185a4b 100644 --- a/src/org/apache/fop/fo/flow/StaticContent.java +++ b/src/org/apache/fop/fo/flow/StaticContent.java @@ -50,109 +50,55 @@ */ package org.apache.fop.fo.flow; - - // FOP - import org.apache.fop.fo.*; - import org.apache.fop.fo.properties.*; - import org.apache.fop.fo.pagination.PageSequence; - import org.apache.fop.layout.Area; - import org.apache.fop.apps.FOPException; - - // Java - import java.util.Enumeration; - - public class StaticContent extends FObj { - - public static class Maker extends FObj.Maker { - public FObj make(FObj parent, PropertyList propertyList) - throws FOPException { - return new StaticContent(parent, propertyList); - } - } - - public static FObj.Maker maker() { - return new StaticContent.Maker(); - } - - PageSequence pageSequence; - - protected StaticContent(FObj parent, PropertyList propertyList) - throws FOPException { - super(parent, propertyList); - this.name = "fo:static-content"; - - if (parent.getName().equals("fo:page-sequence")) { - this.pageSequence = (PageSequence) parent; - } else { - throw new FOPException("static-content must be child of " - + "fo:page-sequence, not " - + parent.getName()); - } - String flowName = this.properties.get("flow-name").getString(); - - pageSequence.setStaticContent(flowName, this); - } - - public int layout(Area area) throws FOPException { - int numChildren = this.children.size(); - for (int i = 0; i < numChildren; i++) { - FObj fo = (FObj) children.elementAt(i); - fo.layout(area); - } - resetMarker(); - return OK; - } - } - diff --git a/src/org/apache/fop/fo/flow/Table.java b/src/org/apache/fop/fo/flow/Table.java index 61e6fd530..eff120aa5 100644 --- a/src/org/apache/fop/fo/flow/Table.java +++ b/src/org/apache/fop/fo/flow/Table.java @@ -50,367 +50,184 @@ */ package org.apache.fop.fo.flow; - - // FOP - import org.apache.fop.fo.*; - import org.apache.fop.fo.properties.*; - import org.apache.fop.layout.*; - import org.apache.fop.apps.FOPException; - - // Java - import java.util.Vector; - - public class Table extends FObj { - - public static class Maker extends FObj.Maker { - public FObj make(FObj parent, PropertyList propertyList) - throws FOPException { - return new Table(parent, propertyList); - } - } - - public static FObj.Maker maker() { - return new Table.Maker(); - } - - FontState fs; - int breakBefore; - int breakAfter; - int startIndent; - int endIndent; - int spaceBefore; - int spaceAfter; - - Vector columns = new Vector(); - int currentColumnNumber = 0; - - BlockArea blockArea; - - public Table(FObj parent, PropertyList propertyList) { - super(parent, propertyList); - this.name = "fo:table"; - } - - public int layout(Area area) throws FOPException { - if (this.marker == BREAK_AFTER) { - return OK; - } - - if (this.marker == START) { - String fontFamily = - this.properties.get("font-family").getString(); - String fontStyle = - this.properties.get("font-style").getString(); - String fontWeight = - this.properties.get("font-weight").getString(); - int fontSize = - this.properties.get("font-size").getLength().mvalue(); - - this.fs = new FontState(area.getFontInfo(), fontFamily, - fontStyle, fontWeight, fontSize); - this.breakBefore = - this.properties.get("break-before").getEnum(); - this.breakAfter = - this.properties.get("break-after").getEnum(); - this.startIndent = - this.properties.get("start-indent").getLength().mvalue(); - this.endIndent = - this.properties.get("end-indent").getLength().mvalue(); - this.spaceBefore = - this.properties.get("space-before.optimum").getLength().mvalue(); - this.spaceAfter = - this.properties.get("space-after.optimum").getLength().mvalue(); - if (area instanceof BlockArea) { - area.end(); - } - - if (this.isInListBody) { - startIndent += bodyIndent + distanceBetweenStarts; - } - - this.marker = 0; - - if (breakBefore == BreakBefore.PAGE) { - return FORCE_PAGE_BREAK; - } - - if (breakBefore == BreakBefore.ODD_PAGE) { - return FORCE_PAGE_BREAK_ODD; - } - - if (breakBefore == BreakBefore.EVEN_PAGE) { - return FORCE_PAGE_BREAK_EVEN; - } - } - - if ((spaceBefore != 0) && (this.marker ==0)) { - area.addDisplaySpace(spaceBefore); - } - - this.blockArea = - new BlockArea(fs, area.getAllocationWidth(), - area.spaceLeft(), startIndent, endIndent, 0, - 0, 0, 0); - blockArea.setPage(area.getPage()); - blockArea.start(); - - int numChildren = this.children.size(); - for (int i = this.marker; i < numChildren; i++) { - FONode fo = (FONode) children.elementAt(i); - if (fo instanceof TableColumn) { - TableColumn c = (TableColumn) fo; - int num = c.getColumnNumber(); - if (num == 0) { - num = currentColumnNumber + 1; - } - currentColumnNumber = num; - if (num > columns.size()) { - columns.setSize(num); - } - columns.setElementAt(c, num-1); - } else if (fo instanceof TableBody) { - if (columns.size() == 0) { - System.err.println("WARNING: current implementation of tables requires a table-column for each column, indicating column-width"); - return OK; - } - - //if (this.isInListBody) { - //fo.setIsInListBody(); - //fo.setDistanceBetweenStarts(this.distanceBetweenStarts); - //fo.setBodyIndent(this.bodyIndent); - //} - - ((TableBody) fo).setColumns(columns); - - int status; - if ((status = fo.layout(blockArea)) != OK) { - this.marker = i; - if ((i != 0) && (status == AREA_FULL_NONE)) { - status = AREA_FULL_SOME; - } - //blockArea.end(); - area.addChild(blockArea); - area.increaseHeight(blockArea.getHeight()); - return status; - } - } - } - - blockArea.end(); - area.addChild(blockArea); - - /* should this be combined into above? */ - area.increaseHeight(blockArea.getHeight()); - - if (spaceAfter != 0) { - area.addDisplaySpace(spaceAfter); - } - - if (area instanceof BlockArea) { - area.start(); - } - - if (breakAfter == BreakAfter.PAGE) { - this.marker = BREAK_AFTER; - return FORCE_PAGE_BREAK; - } - - if (breakAfter == BreakAfter.ODD_PAGE) { - this.marker = BREAK_AFTER; - return FORCE_PAGE_BREAK_ODD; - } - - if (breakAfter == BreakAfter.EVEN_PAGE) { - this.marker = BREAK_AFTER; - return FORCE_PAGE_BREAK_EVEN; - } - - return OK; - } - - public int getAreaHeight() { - return blockArea.getHeight(); - } - } - diff --git a/src/org/apache/fop/fo/flow/TableBody.java b/src/org/apache/fop/fo/flow/TableBody.java index c87546ed2..c3d5a8c5d 100644 --- a/src/org/apache/fop/fo/flow/TableBody.java +++ b/src/org/apache/fop/fo/flow/TableBody.java @@ -50,275 +50,138 @@ */ package org.apache.fop.fo.flow; - - // FOP - import org.apache.fop.fo.*; - import org.apache.fop.fo.properties.*; - import org.apache.fop.layout.*; - import org.apache.fop.apps.FOPException; - - // Java - import java.util.Vector; - - public class TableBody extends FObj { - - public static class Maker extends FObj.Maker { - public FObj make(FObj parent, PropertyList propertyList) - throws FOPException { - return new TableBody(parent, propertyList); - } - } - - public static FObj.Maker maker() { - return new TableBody.Maker(); - } - - FontState fs; - int startIndent; - int endIndent; - int spaceBefore; - int spaceAfter; - - Vector columns; - - BlockArea blockArea; - - public TableBody(FObj parent, PropertyList propertyList) { - super(parent, propertyList); - this.name = "fo:table-body"; - } - - public void setColumns(Vector columns) { - this.columns = columns; - } - - public int layout(Area area) throws FOPException { - if (this.marker == BREAK_AFTER) { - return OK; - } - - if (this.marker == START) { - String fontFamily = - this.properties.get("font-family").getString(); - String fontStyle = - this.properties.get("font-style").getString(); - String fontWeight = - this.properties.get("font-weight").getString(); - int fontSize = - this.properties.get("font-size").getLength().mvalue(); - - this.fs = new FontState(area.getFontInfo(), fontFamily, - fontStyle, fontWeight, fontSize); - this.startIndent = - this.properties.get("start-indent").getLength().mvalue(); - this.endIndent = - this.properties.get("end-indent").getLength().mvalue(); - this.spaceBefore = - this.properties.get("space-before.optimum").getLength().mvalue(); - this.spaceAfter = - this.properties.get("space-after.optimum").getLength().mvalue(); - if (area instanceof BlockArea) { - area.end(); - } - - //if (this.isInListBody) { - //startIndent += bodyIndent + distanceBetweenStarts; - //} - - this.marker = 0; - - } - - if ((spaceBefore != 0) && (this.marker ==0)) { - area.addDisplaySpace(spaceBefore); - } - - this.blockArea = - new BlockArea(fs, area.getAllocationWidth(), - area.spaceLeft(), startIndent, endIndent, 0, - 0, 0, 0); - blockArea.setPage(area.getPage()); - blockArea.start(); - - int numChildren = this.children.size(); - for (int i = this.marker; i < numChildren; i++) { - TableRow row = (TableRow) children.elementAt(i); - - //if (this.isInListBody) { - //fo.setIsInListBody(); - //fo.setDistanceBetweenStarts(this.distanceBetweenStarts); - //fo.setBodyIndent(this.bodyIndent); - //} - - row.setColumns(columns); - - int status; - if ((status = row.layout(blockArea)) != OK) { - this.marker = i; - if ((i != 0) && (status == AREA_FULL_NONE)) { - status = AREA_FULL_SOME; - } - //blockArea.end(); - area.addChild(blockArea); - area.increaseHeight(blockArea.getHeight()); - return status; - } - } - - blockArea.end(); - area.addChild(blockArea); - - /* should this be combined into above? */ - area.increaseHeight(blockArea.getHeight()); - - if (spaceAfter != 0) { - area.addDisplaySpace(spaceAfter); - } - - if (area instanceof BlockArea) { - area.start(); - } - - return OK; - } - - public int getAreaHeight() { - return blockArea.getHeight(); - } - } - diff --git a/src/org/apache/fop/fo/flow/TableCell.java b/src/org/apache/fop/fo/flow/TableCell.java index 694364a7d..5abe8c578 100644 --- a/src/org/apache/fop/fo/flow/TableCell.java +++ b/src/org/apache/fop/fo/flow/TableCell.java @@ -50,245 +50,123 @@ */ package org.apache.fop.fo.flow; - - // FOP - import org.apache.fop.fo.*; - import org.apache.fop.fo.properties.*; - import org.apache.fop.layout.*; - import org.apache.fop.apps.FOPException; - - public class TableCell extends FObj { - - public static class Maker extends FObj.Maker { - public FObj make(FObj parent, PropertyList propertyList) - throws FOPException { - return new TableCell(parent, propertyList); - } - } - - public static FObj.Maker maker() { - return new TableCell.Maker(); - } - - FontState fs; - int startIndent; - int endIndent; - int spaceBefore; - int spaceAfter; - - protected int startOffset; - protected int width; - protected int height = 0; - - BlockArea blockArea; - - public TableCell(FObj parent, PropertyList propertyList) { - super(parent, propertyList); - this.name = "fo:table-cell"; - } - - public void setStartOffset(int offset) { - startOffset = offset; - } - - public void setWidth(int width) { - this.width = width; - } - - public int layout(Area area) throws FOPException { - if (this.marker == BREAK_AFTER) { - return OK; - } - - if (this.marker == START) { - String fontFamily = - this.properties.get("font-family").getString(); - String fontStyle = - this.properties.get("font-style").getString(); - String fontWeight = - this.properties.get("font-weight").getString(); - int fontSize = - this.properties.get("font-size").getLength().mvalue(); - - this.fs = new FontState(area.getFontInfo(), fontFamily, - fontStyle, fontWeight, fontSize); - this.startIndent = - this.properties.get("start-indent").getLength().mvalue(); - this.endIndent = - this.properties.get("end-indent").getLength().mvalue(); - this.spaceBefore = - this.properties.get("space-before.optimum").getLength().mvalue(); - this.spaceAfter = - this.properties.get("space-after.optimum").getLength().mvalue(); - if (area instanceof BlockArea) { - area.end(); - } - - //if (this.isInListBody) { - //startIndent += bodyIndent + distanceBetweenStarts; - //} - - this.marker = 0; - - } - - if ((spaceBefore != 0) && (this.marker ==0)) { - area.addDisplaySpace(spaceBefore); - } - - this.blockArea = - new BlockArea(fs, area.getAllocationWidth(), - area.spaceLeft(), startIndent, endIndent, 0, - 0, 0, 0); - blockArea.setPage(area.getPage()); - blockArea.start(); - - int numChildren = this.children.size(); - for (int i = this.marker; i < numChildren; i++) { - FObj fo = (FObj) children.elementAt(i); - fo.setIsInTableCell(); - fo.forceStartOffset(startOffset); - fo.forceWidth(width); - int status; - if ((status = fo.layout(blockArea)) != OK) { - this.marker = i; - if ((i == 0) && (status == AREA_FULL_NONE)) { - return AREA_FULL_NONE; - } else { - return AREA_FULL_SOME; - } - } - height += blockArea.getHeight(); - - } - blockArea.end(); - area.addChild(blockArea); - - return OK; - } - - public int getHeight() { - return height; - } - } - diff --git a/src/org/apache/fop/fo/flow/TableColumn.java b/src/org/apache/fop/fo/flow/TableColumn.java index 1fa05aab6..4a1b23bcc 100644 --- a/src/org/apache/fop/fo/flow/TableColumn.java +++ b/src/org/apache/fop/fo/flow/TableColumn.java @@ -50,69 +50,35 @@ */ package org.apache.fop.fo.flow; - - // FOP - import org.apache.fop.fo.*; - import org.apache.fop.fo.properties.*; - import org.apache.fop.layout.*; - import org.apache.fop.apps.FOPException; - - public class TableColumn extends FObj { - - public static class Maker extends FObj.Maker { - public FObj make(FObj parent, PropertyList propertyList) - throws FOPException { - return new TableColumn(parent, propertyList); - } - } - - public static FObj.Maker maker() { - return new TableColumn.Maker(); - } - - public TableColumn(FObj parent, PropertyList propertyList) { - super(parent, propertyList); - this.name = "fo:table-column"; - } - - public int getColumnWidth() { - return this.properties.get("column-width").getLength().mvalue(); - } - - public int getColumnNumber() { - return 0; // not implemented yet - } - } - diff --git a/src/org/apache/fop/fo/flow/TableRow.java b/src/org/apache/fop/fo/flow/TableRow.java index 3f80f0c00..9578f0ea3 100644 --- a/src/org/apache/fop/fo/flow/TableRow.java +++ b/src/org/apache/fop/fo/flow/TableRow.java @@ -50,311 +50,156 @@ */ package org.apache.fop.fo.flow; - - // FOP - import org.apache.fop.fo.*; - import org.apache.fop.fo.properties.*; - import org.apache.fop.layout.*; - import org.apache.fop.apps.FOPException; - - // Java - import java.util.Vector; - - public class TableRow extends FObj { - - public static class Maker extends FObj.Maker { - public FObj make(FObj parent, PropertyList propertyList) - throws FOPException { - return new TableRow(parent, propertyList); - } - } - - public static FObj.Maker maker() { - return new TableRow.Maker(); - } - - FontState fs; - int startIndent; - int endIndent; - int spaceBefore; - int spaceAfter; - - int widthOfCellsSoFar = 0; - int largestCellHeight = 0; - - Vector columns; - - BlockArea blockArea; - - public TableRow(FObj parent, PropertyList propertyList) { - super(parent, propertyList); - this.name = "fo:table-row"; - } - - public void setColumns(Vector columns) { - this.columns = columns; - } - - public int layout(Area area) throws FOPException { - if (this.marker == BREAK_AFTER) { - return OK; - } - - if (this.marker == START) { - String fontFamily = - this.properties.get("font-family").getString(); - String fontStyle = - this.properties.get("font-style").getString(); - String fontWeight = - this.properties.get("font-weight").getString(); - int fontSize = - this.properties.get("font-size").getLength().mvalue(); - - this.fs = new FontState(area.getFontInfo(), fontFamily, - fontStyle, fontWeight, fontSize); - this.startIndent = - this.properties.get("start-indent").getLength().mvalue(); - this.endIndent = - this.properties.get("end-indent").getLength().mvalue(); - this.spaceBefore = - this.properties.get("space-before.optimum").getLength().mvalue(); - this.spaceAfter = - this.properties.get("space-after.optimum").getLength().mvalue(); - if (area instanceof BlockArea) { - area.end(); - } - - //if (this.isInListBody) { - //startIndent += bodyIndent + distanceBetweenStarts; - //} - - this.marker = 0; - - } - - if ((spaceBefore != 0) && (this.marker ==0)) { - area.addDisplaySpace(spaceBefore); - } - - this.blockArea = - new BlockArea(fs, area.getAllocationWidth(), - area.spaceLeft(), startIndent, endIndent, 0, - 0, 0, 0); - blockArea.setPage(area.getPage()); - blockArea.start(); - - int numChildren = this.children.size(); - if (numChildren != columns.size()) { - System.err.println("WARNING: Number of children under table-row not equal to number of table-columns"); - return OK; - } - - for (int i = this.marker; i < numChildren; i++) { - TableCell cell = (TableCell) children.elementAt(i); - - //if (this.isInListBody) { - //fo.setIsInListBody(); - //fo.setDistanceBetweenStarts(this.distanceBetweenStarts); - //fo.setBodyIndent(this.bodyIndent); - //} - - cell.setStartOffset(widthOfCellsSoFar); - int width = ((TableColumn) columns.elementAt(i)).getColumnWidth(); - - cell.setWidth(width); - widthOfCellsSoFar += width; - - int status; - if ((status = cell.layout(blockArea)) != OK) { - this.marker = i; - if ((i != 0) && (status == AREA_FULL_NONE)) { - status = AREA_FULL_SOME; - } - //blockArea.end(); - area.addChild(blockArea); - area.increaseHeight(blockArea.getHeight()); - return status; - } - - int h = cell.getHeight(); - blockArea.addDisplaySpace(-h); - if (h > largestCellHeight) { - largestCellHeight = h; - } - - } - - blockArea.end(); - area.addChild(blockArea); - area.addDisplaySpace(largestCellHeight); - area.increaseHeight(largestCellHeight); - - if (spaceAfter != 0) { - area.addDisplaySpace(spaceAfter); - } - - if (area instanceof BlockArea) { - area.start(); - } - - return OK; - } - - public int getAreaHeight() { - return blockArea.getHeight(); - } - } - diff --git a/src/org/apache/fop/fo/pagination/LayoutMasterSet.java b/src/org/apache/fop/fo/pagination/LayoutMasterSet.java index 05d5836db..ba38263a4 100644 --- a/src/org/apache/fop/fo/pagination/LayoutMasterSet.java +++ b/src/org/apache/fop/fo/pagination/LayoutMasterSet.java @@ -50,101 +50,51 @@ */ package org.apache.fop.fo.pagination; - - // FOP - import org.apache.fop.fo.*; - import org.apache.fop.fo.properties.*; - import org.apache.fop.apps.FOPException; - - // Java - import java.util.Hashtable; - - public class LayoutMasterSet extends FObj { - - public static class Maker extends FObj.Maker { - public FObj make(FObj parent, PropertyList propertyList) - throws FOPException { - return new LayoutMasterSet(parent,propertyList); - } - } - - public static FObj.Maker maker() { - return new LayoutMasterSet.Maker(); - } - - private Hashtable layoutMasters; - private Root root; - - protected LayoutMasterSet(FObj parent, PropertyList propertyList) - throws FOPException { - super(parent, propertyList); - this.name = "fo:layout-master-set"; - - this.layoutMasters = new Hashtable(); - if (parent.getName().equals("fo:root")) { - this.root = (Root)parent; - root.setLayoutMasterSet(this); - } else { - throw - new FOPException("fo:layout-master-set must be child of fo:root, not " - + parent.getName()); - } - } - - protected void addLayoutMaster(String masterName, SimplePageMaster layoutMaster) { - this.layoutMasters.put(masterName, layoutMaster); - } - - protected SimplePageMaster getLayoutMaster(String masterName) { - return (SimplePageMaster)this.layoutMasters.get(masterName); - } - } - diff --git a/src/org/apache/fop/fo/pagination/PageSequence.java b/src/org/apache/fop/fo/pagination/PageSequence.java index 0e6f454d8..47260026d 100644 --- a/src/org/apache/fop/fo/pagination/PageSequence.java +++ b/src/org/apache/fop/fo/pagination/PageSequence.java @@ -50,277 +50,139 @@ */ package org.apache.fop.fo.pagination; - - // FOP - import org.apache.fop.fo.*; - import org.apache.fop.fo.properties.*; - import org.apache.fop.fo.flow.Flow; - import org.apache.fop.fo.flow.StaticContent; - import org.apache.fop.layout.Area; - import org.apache.fop.layout.AreaContainer; - import org.apache.fop.layout.AreaTree; - import org.apache.fop.layout.Page; - import org.apache.fop.layout.PageMaster; - import org.apache.fop.layout.PageMasterFactory; - import org.apache.fop.apps.FOPException; - - // Java - import java.util.Hashtable; - import java.util.Vector; - - public class PageSequence extends FObj { - - public static class Maker extends FObj.Maker { - public FObj make(FObj parent, PropertyList propertyList) - throws FOPException { - return new PageSequence(parent, propertyList); - } - } - - public static FObj.Maker maker() { - return new PageSequence.Maker(); - } - - protected Root root; - protected SequenceSpecification sequenceSpecification; - protected Flow flow; - protected StaticContent staticBefore; - protected StaticContent staticAfter; - protected LayoutMasterSet layoutMasterSet; - - protected Page currentPage; - protected int currentPageNumber = 0; - - protected PageSequence(FObj parent, PropertyList propertyList) - throws FOPException { - super(parent, propertyList); - this.name = "fo:page-sequence"; - - if (parent.getName().equals("fo:root")) { - this.root = (Root) parent; - this.root.addPageSequence(this); - } else { - throw - new FOPException("page-sequence must be child of root, not " - + parent.getName()); - } - layoutMasterSet = root.getLayoutMasterSet(); - } - - protected Page makePage(AreaTree areaTree) throws FOPException { - PageMaster pageMaster; - // layout this page sequence - - // while there is still stuff in the flow, ask the - // sequence-specification for a new page - - if (this.sequenceSpecification == null) { - throw new FOPException("page-sequence is missing an" - + " sequence-specification"); - } - - PageMasterFactory pmf = - this.sequenceSpecification.getFirstPageMasterFactory(); - - pageMaster = pmf.getNextPageMaster(); - - while (pageMaster == null) { - /* move on to next sequence specifier */ - pmf = pmf.getNext(); - if (pmf == null) { - throw new FOPException("out of sequence specifiers" - + " (FOP will eventually allow this)"); - } - pageMaster = pmf.getNextPageMaster(); - } - return pageMaster.makePage(areaTree); - } - - public void format(AreaTree areaTree) throws FOPException { - int status = OK; - - do { - currentPage = makePage(areaTree); - currentPage.setNumber(++this.currentPageNumber); - System.err.print(" [" + currentPageNumber); - if ((this.staticBefore != null) && - (currentPage.getBefore() != null)) { - AreaContainer beforeArea = currentPage.getBefore(); - this.staticBefore.layout(beforeArea); - } - if ((this.staticAfter != null) && - (currentPage.getAfter() != null)) { - AreaContainer afterArea = currentPage.getAfter(); - this.staticAfter.layout(afterArea); - } - if ((status == FORCE_PAGE_BREAK_EVEN) && - ((currentPageNumber % 2) == 1)) { - } else if ((status == FORCE_PAGE_BREAK_ODD) && - ((currentPageNumber % 2) == 0)) { - } else { - AreaContainer bodyArea = currentPage.getBody(); - status = this.flow.layout(bodyArea); - } - System.err.print("]"); - areaTree.addPage(currentPage); - } while (status != OK); - System.err.println(); - } - - public void setFlow(Flow flow) { - this.flow = flow; - } - - protected void setSequenceSpecification(SequenceSpecification sequenceSpecification) { - this.sequenceSpecification = sequenceSpecification; - sequenceSpecification.setLayoutMasterSet(this.layoutMasterSet); - } - - public void setStaticContent(String name, StaticContent staticContent) { - if (name.equals("xsl-before")) { - this.staticBefore = staticContent; - } else if (name.equals("xsl-after")) { - this.staticAfter = staticContent; - } else { - System.err.println("WARNING: this version of FOP only supports " - + "static-content in region-before and region-after"); - } - } - } - diff --git a/src/org/apache/fop/fo/pagination/RegionAfter.java b/src/org/apache/fop/fo/pagination/RegionAfter.java index 78dcecc93..9b8872e1f 100644 --- a/src/org/apache/fop/fo/pagination/RegionAfter.java +++ b/src/org/apache/fop/fo/pagination/RegionAfter.java @@ -50,109 +50,55 @@ */ package org.apache.fop.fo.pagination; - - // FOP - import org.apache.fop.fo.*; - import org.apache.fop.fo.properties.*; - import org.apache.fop.layout.Region; - import org.apache.fop.apps.FOPException; - - public class RegionAfter extends FObj { - - public static class Maker extends FObj.Maker { - public FObj make(FObj parent, PropertyList propertyList) throws FOPException { - return new RegionAfter(parent,propertyList); - } - } - - public static FObj.Maker maker() { - return new RegionAfter.Maker(); - } - - SimplePageMaster layoutMaster; - - protected RegionAfter(FObj parent, PropertyList propertyList) - throws FOPException { - super(parent, propertyList); - this.name = "fo:region-after"; - - if (parent.getName().equals("fo:simple-page-master")) { - this.layoutMaster = (SimplePageMaster) parent; - this.layoutMaster.setRegionAfter(this); - } else { - throw new FOPException("region-after must be child " - + "of simple-page-master, not " - + parent.getName()); - } - } - - Region makeRegion(int allocationRectangleXPosition, - int allocationRectangleYPosition, - int allocationRectangleWidth, - int allocationRectangleHeight) { - int marginTop = this.properties.get("margin-top").getLength().mvalue(); - int marginBottom = this.properties.get("margin-bottom").getLength().mvalue(); - int marginLeft = this.properties.get("margin-left").getLength().mvalue(); - int marginRight = this.properties.get("margin-right").getLength().mvalue(); - int extent = this.properties.get("extent").getLength().mvalue(); - - return new Region(allocationRectangleXPosition + marginLeft, - allocationRectangleYPosition - - allocationRectangleHeight + extent, - allocationRectangleWidth - marginLeft - - marginRight,extent); - } - } - diff --git a/src/org/apache/fop/fo/pagination/RegionBefore.java b/src/org/apache/fop/fo/pagination/RegionBefore.java index 258ec88dc..55747c196 100644 --- a/src/org/apache/fop/fo/pagination/RegionBefore.java +++ b/src/org/apache/fop/fo/pagination/RegionBefore.java @@ -50,107 +50,54 @@ */ package org.apache.fop.fo.pagination; - - // FOP - import org.apache.fop.fo.*; - import org.apache.fop.fo.properties.*; - import org.apache.fop.layout.Region; - import org.apache.fop.apps.FOPException; - - public class RegionBefore extends FObj { - - public static class Maker extends FObj.Maker { - public FObj make(FObj parent, PropertyList propertyList) throws FOPException { - return new RegionBefore(parent, propertyList); - } - } - - public static FObj.Maker maker() { - return new RegionBefore.Maker(); - } - - SimplePageMaster layoutMaster; - - protected RegionBefore(FObj parent, PropertyList propertyList) - throws FOPException { - super(parent, propertyList); - this.name = "fo:region-before"; - - if (parent.getName().equals("fo:simple-page-master")) { - this.layoutMaster = (SimplePageMaster) parent; - this.layoutMaster.setRegionBefore(this); - } else { - throw new FOPException("region-before must be child of " - + "simple-page-master, not " - + parent.getName()); - } - } - - Region makeRegion(int allocationRectangleXPosition, - int allocationRectangleYPosition, - int allocationRectangleWidth, - int allocationRectangleHeight) { - int marginTop = this.properties.get("margin-top").getLength().mvalue(); - int marginBottom = this.properties.get("margin-bottom").getLength().mvalue(); - int marginLeft = this.properties.get("margin-left").getLength().mvalue(); - int marginRight = this.properties.get("margin-right").getLength().mvalue(); - int extent = this.properties.get("extent").getLength().mvalue(); - - return new Region(allocationRectangleXPosition + marginLeft, - allocationRectangleYPosition - marginTop, - allocationRectangleWidth - marginLeft - - marginRight, extent); - } - } - diff --git a/src/org/apache/fop/fo/pagination/RegionBody.java b/src/org/apache/fop/fo/pagination/RegionBody.java index 314be56c7..72a86819b 100644 --- a/src/org/apache/fop/fo/pagination/RegionBody.java +++ b/src/org/apache/fop/fo/pagination/RegionBody.java @@ -50,101 +50,51 @@ */ package org.apache.fop.fo.pagination; - - // FOP - import org.apache.fop.fo.*; - import org.apache.fop.fo.properties.*; - import org.apache.fop.layout.Region; - import org.apache.fop.apps.FOPException; - - public class RegionBody extends FObj { - - public static class Maker extends FObj.Maker { - public FObj make(FObj parent, PropertyList propertyList) throws FOPException { - return new RegionBody(parent, propertyList); - } - } - - public static FObj.Maker maker() { - return new RegionBody.Maker(); - } - - protected RegionBody(FObj parent, PropertyList propertyList) - throws FOPException { - super(parent, propertyList); - this.name = "fo:region-body"; - - if (parent.getName().equals("fo:simple-page-master")) { - ((SimplePageMaster) parent).setRegionBody(this); - } else { - throw new FOPException("region-body must be child of " - + "simple-page-master, not " - + parent.getName()); - } - } - - Region makeRegion(int allocationRectangleXPosition, - int allocationRectangleYPosition, - int allocationRectangleWidth, - int allocationRectangleHeight) { - int marginTop = this.properties.get("margin-top").getLength().mvalue(); - int marginBottom = this.properties.get("margin-bottom").getLength().mvalue(); - int marginLeft = this.properties.get("margin-left").getLength().mvalue(); - int marginRight = this.properties.get("margin-right").getLength().mvalue(); - - return new Region(allocationRectangleXPosition + marginLeft, - allocationRectangleYPosition - marginTop, - allocationRectangleWidth - marginLeft - - marginRight, allocationRectangleHeight - - marginTop - marginBottom); - } - } - diff --git a/src/org/apache/fop/fo/pagination/Root.java b/src/org/apache/fop/fo/pagination/Root.java index 91cb00994..f7f8bbbd6 100644 --- a/src/org/apache/fop/fo/pagination/Root.java +++ b/src/org/apache/fop/fo/pagination/Root.java @@ -50,123 +50,62 @@ */ package org.apache.fop.fo.pagination; - - // FOP - import org.apache.fop.fo.*; - import org.apache.fop.fo.properties.*; - import org.apache.fop.layout.AreaTree; - import org.apache.fop.apps.FOPException; - - // Java - import java.util.Vector; - import java.util.Enumeration; - - public class Root extends FObj { - - public static class Maker extends FObj.Maker { - public FObj make(FObj parent, PropertyList propertyList) - throws FOPException { - return new Root(parent, propertyList); - } - } - - public static FObj.Maker maker() { - return new Root.Maker(); - } - - LayoutMasterSet layoutMasterSet; - Vector pageSequences; - - protected Root(FObj parent, PropertyList propertyList) - throws FOPException { - super(parent, propertyList); - this.name = "fo:root"; - - pageSequences = new Vector(); - if (parent != null) { - throw new FOPException("root must be root element"); - } - } - - public void addPageSequence(PageSequence pageSequence) { - this.pageSequences.addElement(pageSequence); - } - - public LayoutMasterSet getLayoutMasterSet() { - return this.layoutMasterSet; - } - - public void format(AreaTree areaTree) throws FOPException { - if (layoutMasterSet == null) { - throw new FOPException("No layout master set."); - } - Enumeration e = pageSequences.elements(); - while (e.hasMoreElements()) { - ((PageSequence) e.nextElement()).format(areaTree); - } - } - - public void setLayoutMasterSet(LayoutMasterSet layoutMasterSet) { - this.layoutMasterSet = layoutMasterSet; - } - } - diff --git a/src/org/apache/fop/fo/pagination/SequenceSpecification.java b/src/org/apache/fop/fo/pagination/SequenceSpecification.java index a620ff5f4..6113624c1 100644 --- a/src/org/apache/fop/fo/pagination/SequenceSpecification.java +++ b/src/org/apache/fop/fo/pagination/SequenceSpecification.java @@ -50,133 +50,67 @@ */ package org.apache.fop.fo.pagination; - - // FOP - import org.apache.fop.fo.*; - import org.apache.fop.fo.properties.*; - import org.apache.fop.layout.PageMasterFactory; - import org.apache.fop.apps.FOPException; - - public class SequenceSpecification extends FObj { - - public static class Maker extends FObj.Maker { - public FObj make(FObj parent, PropertyList propertyList) - throws FOPException { - return new SequenceSpecification(parent, propertyList); - } - } - - public static FObj.Maker maker() { - return new SequenceSpecification.Maker(); - } - - private PageSequence pageSequence; - private LayoutMasterSet layoutMasterSet; - private PageMasterFactory firstPMF; - private PageMasterFactory currentPMF; - - protected SequenceSpecification(FObj parent, - PropertyList propertyList) - throws FOPException { - super(parent, propertyList); - this.name = "fo:sequence-specification"; - - if (parent.getName().equals("fo:page-sequence")) { - this.pageSequence = (PageSequence) parent; - this.pageSequence.setSequenceSpecification(this); - } else { - throw new FOPException("sequence-specification must be child" - + " of page-sequence, not " - + parent.getName()); - } - this.firstPMF = null; - this.currentPMF = null; - - } - - protected void addSequenceSpecifier(SequenceSpecifier sequenceSpecifier) { - if (this.firstPMF == null) { - this.firstPMF = sequenceSpecifier.getPageMasterFactory(); - } else { - this.currentPMF.setNext(sequenceSpecifier.getPageMasterFactory()); - } - this.currentPMF = sequenceSpecifier.getPageMasterFactory(); - } - - protected PageMasterFactory getFirstPageMasterFactory() { - return this.firstPMF; - } - - LayoutMasterSet getLayoutMasterSet() { - return this.layoutMasterSet; - } - - protected void setLayoutMasterSet(LayoutMasterSet layoutMasterSet) { - this.layoutMasterSet = layoutMasterSet; - } - } - diff --git a/src/org/apache/fop/fo/pagination/SequenceSpecifier.java b/src/org/apache/fop/fo/pagination/SequenceSpecifier.java index 9e977efc9..b2f2bec0a 100644 --- a/src/org/apache/fop/fo/pagination/SequenceSpecifier.java +++ b/src/org/apache/fop/fo/pagination/SequenceSpecifier.java @@ -50,27 +50,14 @@ */ package org.apache.fop.fo.pagination; - - import org.apache.fop.fo.*; - import org.apache.fop.layout.PageMasterFactory; - - abstract public class SequenceSpecifier extends FObj { - - protected SequenceSpecifier(FObj parent, PropertyList propertyList) { - super(parent, propertyList); - } - - public abstract PageMasterFactory getPageMasterFactory(); - } - diff --git a/src/org/apache/fop/fo/pagination/SequenceSpecifierAlternating.java b/src/org/apache/fop/fo/pagination/SequenceSpecifierAlternating.java index 51b8a88c7..39db4482c 100644 --- a/src/org/apache/fop/fo/pagination/SequenceSpecifierAlternating.java +++ b/src/org/apache/fop/fo/pagination/SequenceSpecifierAlternating.java @@ -50,131 +50,66 @@ */ package org.apache.fop.fo.pagination; - - // FOP - import org.apache.fop.fo.*; - import org.apache.fop.fo.properties.*; - import org.apache.fop.layout.PageMasterFactory; - import org.apache.fop.layout.AlternatingPageMasterFactory; - import org.apache.fop.layout.PageMaster; - import org.apache.fop.apps.FOPException; - - public class SequenceSpecifierAlternating extends SequenceSpecifier { - - public static class Maker extends FObj.Maker { - public FObj make(FObj parent, PropertyList propertyList) - throws FOPException { - return new SequenceSpecifierAlternating(parent, propertyList); - } - } - - public static FObj.Maker maker() { - return new SequenceSpecifierAlternating.Maker(); - } - - private SequenceSpecification sequenceSpecification; - private LayoutMasterSet layoutMasterSet; - private AlternatingPageMasterFactory pageMasterFactory; - - protected SequenceSpecifierAlternating(FObj parent, - PropertyList propertyList) - throws FOPException { - super(parent, propertyList); - PageMaster pf, pe, po; - - this.name = "fo:sequence-specifer-alternating"; - - if (parent.getName().equals("fo:sequence-specification")) { - this.sequenceSpecification = (SequenceSpecification) parent; - this.layoutMasterSet = this.sequenceSpecification.getLayoutMasterSet(); - } else { - throw new FOPException("fo:sequence-specifier-alternating must be " - + " child of fo:sequence-specification, not " - + parent.getName()); - } - - String pageMasterFirst = this.properties.get("page-master-first").getString(); - String pageMasterOdd = this.properties.get("page-master-odd").getString(); - String pageMasterEven = this.properties.get("page-master-even").getString(); - - try { - pf = this.layoutMasterSet.getLayoutMaster(pageMasterFirst).getPageMaster(); - pe = this.layoutMasterSet.getLayoutMaster(pageMasterEven).getPageMaster(); - po = this.layoutMasterSet.getLayoutMaster(pageMasterOdd).getPageMaster(); - this.pageMasterFactory = new AlternatingPageMasterFactory(pf,pe,po); - } catch (java.lang.NullPointerException e) { - throw new FOPException("at least one of the page-master names in" - + " sequence-specifier-alternating is not in" - + " layout-master-set"); - } - this.sequenceSpecification.addSequenceSpecifier(this); - } - - public PageMasterFactory getPageMasterFactory() { - return this.pageMasterFactory; - } - } - diff --git a/src/org/apache/fop/fo/pagination/SequenceSpecifierRepeating.java b/src/org/apache/fop/fo/pagination/SequenceSpecifierRepeating.java index bddbac7c3..683c05670 100644 --- a/src/org/apache/fop/fo/pagination/SequenceSpecifierRepeating.java +++ b/src/org/apache/fop/fo/pagination/SequenceSpecifierRepeating.java @@ -50,123 +50,62 @@ */ package org.apache.fop.fo.pagination; - - // FOP - import org.apache.fop.fo.*; - import org.apache.fop.fo.properties.*; - import org.apache.fop.layout.PageMasterFactory; - import org.apache.fop.layout.RepeatingPageMasterFactory; - import org.apache.fop.layout.PageMaster; - import org.apache.fop.apps.FOPException; - - public class SequenceSpecifierRepeating extends SequenceSpecifier { - - public static class Maker extends FObj.Maker { - public FObj make(FObj parent, PropertyList propertyList) - throws FOPException { - return new SequenceSpecifierRepeating(parent, propertyList); - } - } - - public static FObj.Maker maker() { - return new SequenceSpecifierRepeating.Maker(); - } - - private SequenceSpecification sequenceSpecification; - private LayoutMasterSet layoutMasterSet; - private RepeatingPageMasterFactory pageMasterFactory; - - protected SequenceSpecifierRepeating(FObj parent, PropertyList propertyList) - throws FOPException { - super(parent, propertyList); - PageMaster pf, pr; - - this.name = "fo:sequence-specifer-repeating"; - - if (parent.getName().equals("fo:sequence-specification")) { - this.sequenceSpecification = (SequenceSpecification) parent; - this.layoutMasterSet = this.sequenceSpecification.getLayoutMasterSet(); - } else { - throw new FOPException("sequence-specifier-repeating must be " - + "child of fo:sequence-specification, " - + "not " + parent.getName()); - } - - String pageMasterFirst = this.properties.get("page-master-first").getString(); - String pageMasterRepeating = this.properties.get("page-master-repeating").getString(); - try { - pf = this.layoutMasterSet.getLayoutMaster(pageMasterFirst).getPageMaster(); - pr = this.layoutMasterSet.getLayoutMaster(pageMasterRepeating).getPageMaster(); - this.pageMasterFactory = new RepeatingPageMasterFactory(pf, pr); - } catch (java.lang.NullPointerException e) { - throw new FOPException("at least one of the page-master names in " - + "sequence-specifier-repeating is not in " - + "layout-master-set"); - } - this.sequenceSpecification.addSequenceSpecifier(this); - } - - public PageMasterFactory getPageMasterFactory() { - return this.pageMasterFactory; - } - } - diff --git a/src/org/apache/fop/fo/pagination/SequenceSpecifierSingle.java b/src/org/apache/fop/fo/pagination/SequenceSpecifierSingle.java index a062f0315..d6f0129c9 100644 --- a/src/org/apache/fop/fo/pagination/SequenceSpecifierSingle.java +++ b/src/org/apache/fop/fo/pagination/SequenceSpecifierSingle.java @@ -50,119 +50,60 @@ */ package org.apache.fop.fo.pagination; - - // FOP - import org.apache.fop.fo.*; - import org.apache.fop.fo.properties.*; - import org.apache.fop.layout.PageMasterFactory; - import org.apache.fop.layout.SinglePageMasterFactory; - import org.apache.fop.layout.PageMaster; - import org.apache.fop.apps.FOPException; - - public class SequenceSpecifierSingle extends SequenceSpecifier { - - public static class Maker extends FObj.Maker { - public FObj make(FObj parent, PropertyList propertyList) - throws FOPException { - return new SequenceSpecifierSingle(parent, propertyList); - } - } - - public static FObj.Maker maker() { - return new SequenceSpecifierSingle.Maker(); - } - - private SequenceSpecification sequenceSpecification; - private LayoutMasterSet layoutMasterSet; - private SinglePageMasterFactory pageMasterFactory; - - protected SequenceSpecifierSingle(FObj parent, PropertyList propertyList) - throws FOPException { - super(parent, propertyList); - this.name = "fo:sequence-specifer-single"; - - if (parent.getName().equals("fo:sequence-specification")) { - this.sequenceSpecification = (SequenceSpecification) parent; - this.layoutMasterSet = this.sequenceSpecification.getLayoutMasterSet(); - } else { - throw new FOPException("sequence-specifier-single must be " - + "child of fo:sequence-specification, " - + "not " + parent.getName()); - } - - String pageMasterName = this.properties.get("page-master-name").getString(); - try { - this.pageMasterFactory = new SinglePageMasterFactory(this.layoutMasterSet.getLayoutMaster(pageMasterName).getPageMaster()); - } catch (java.lang.NullPointerException e) { - throw new FOPException("page-master-name " + - pageMasterName + " must be in layout-master-set"); - } - this.sequenceSpecification.addSequenceSpecifier(this); - } - - public PageMasterFactory getPageMasterFactory() { - return this.pageMasterFactory; - } - - public String getPageMasterName() { - return this.properties.get("page-master-name").getString(); - } - } - diff --git a/src/org/apache/fop/fo/pagination/SimplePageMaster.java b/src/org/apache/fop/fo/pagination/SimplePageMaster.java index 11fcffd2c..8ccfc38d0 100644 --- a/src/org/apache/fop/fo/pagination/SimplePageMaster.java +++ b/src/org/apache/fop/fo/pagination/SimplePageMaster.java @@ -50,179 +50,90 @@ */ package org.apache.fop.fo.pagination; - - // FOP - import org.apache.fop.fo.*; - import org.apache.fop.fo.properties.*; - import org.apache.fop.layout.PageMaster; - import org.apache.fop.layout.Region; - import org.apache.fop.apps.FOPException; - - public class SimplePageMaster extends FObj { - - public static class Maker extends FObj.Maker { - public FObj make(FObj parent, PropertyList propertyList) - throws FOPException { - return new SimplePageMaster(parent, propertyList); - } - } - - public static FObj.Maker maker() { - return new SimplePageMaster.Maker(); - } - - RegionBody regionBody; - RegionBefore regionBefore; - RegionAfter regionAfter; - - LayoutMasterSet layoutMasterSet; - PageMaster pageMaster; - - protected SimplePageMaster(FObj parent, PropertyList propertyList) - throws FOPException { - super(parent, propertyList); - this.name = "fo:simple-page-master"; - - if (parent.getName().equals("fo:layout-master-set")) { - this.layoutMasterSet = (LayoutMasterSet) parent; - String pm = this.properties.get("page-master-name").getString(); - if (pm == null) { - System.err.println("WARNING: simple-page-master does not have " - + "a page-master-name and so is being ignored"); - } else { - this.layoutMasterSet.addLayoutMaster(pm, this); - } - } else { - throw new FOPException("fo:simple-page-master must be child " - + "of fo:layout-master-set, not " - + parent.getName()); - } - } - - protected void end() { - int pageWidth = this.properties.get("page-width").getLength().mvalue(); - int pageHeight = this.properties.get("page-height").getLength().mvalue(); - - int marginTop = this.properties.get("margin-top").getLength().mvalue(); - int marginBottom = this.properties.get("margin-bottom").getLength().mvalue(); - int marginLeft = this.properties.get("margin-left").getLength().mvalue(); - int marginRight = this.properties.get("margin-right").getLength().mvalue(); - - int contentRectangleXPosition = marginLeft; - int contentRectangleYPosition = pageHeight - marginTop; - int contentRectangleWidth = pageWidth - marginLeft - marginRight; - int contentRectangleHeight = pageHeight - marginTop - marginBottom; - - this.pageMaster = new PageMaster(pageWidth, pageHeight); - this.pageMaster.addBody(this.regionBody.makeRegion(contentRectangleXPosition,contentRectangleYPosition,contentRectangleWidth,contentRectangleHeight)); - - if (this.regionBefore != null) - this.pageMaster.addBefore(this.regionBefore.makeRegion(contentRectangleXPosition,contentRectangleYPosition,contentRectangleWidth,contentRectangleHeight)); - if (this.regionAfter != null) - this.pageMaster.addAfter(this.regionAfter.makeRegion(contentRectangleXPosition,contentRectangleYPosition,contentRectangleWidth,contentRectangleHeight)); - } - - PageMaster getPageMaster() { - return this.pageMaster; - } - - protected void setRegionAfter(RegionAfter region) { - this.regionAfter = region; - } - - protected void setRegionBefore(RegionBefore region) { - this.regionBefore = region; - } - - protected void setRegionBody(RegionBody region) { - this.regionBody = region; - } - } - diff --git a/src/org/apache/fop/image/BmpBwImage.java b/src/org/apache/fop/image/BmpBwImage.java index 3885ad2a7..18830bfdd 100644 --- a/src/org/apache/fop/image/BmpBwImage.java +++ b/src/org/apache/fop/image/BmpBwImage.java @@ -50,217 +50,109 @@ */ /* modified by JKT to integrate into 0.12.0 */ - - //Title: BoBoGi FOP - //Version: - //Copyright: Copyright (c) 1999 - //Author: Sergio Botti - //Company: Dibe Elsag - //Description: xml to pdf converter - - package org.apache.fop.image; - import java.io.FileInputStream; - import java.io.IOException; - import java.io.PrintWriter; - - public class BmpBwImage implements FopImage { - int X; - int Y; - int width; - int height; - int pixelwidth; - int pixelheight; - String ref; - boolean color; - int bitperpixel; - int[] imagemap; - int imagestart; - /* - Costructor read the header of the bmp file to get the size - and the other data - SB - */ - public BmpBwImage(String href,int x,int y,int w,int h) - { - this.ref=href; - this.X=x; - this.Y=y; - - int wpos=18; - int hpos=22; //offset positioning for w and height in bmp files - int [] headermap = new int[54]; - try{ - FileInputStream file=new FileInputStream(ref); - boolean eof=false; - int count=0; - while ((!eof) && (count<54) ) { - int input =file.read(); - if (input==-1) - eof=true; - else - headermap[count++]=input; - } - file.close(); - }catch (IOException e) {System.err.println("Image not found");} - // gets h & w from headermap - this.pixelwidth = headermap[wpos]+headermap[wpos+1]*256+headermap[wpos+2]*256*256+headermap[wpos+3]*256*256*256; - this.pixelheight = headermap[hpos]+headermap[hpos+1]*256+headermap[hpos+2]*256*256+headermap[hpos+3]*256*256*256; - if (w==0) - this.width=this.pixelwidth*1000; - else - this.width=w; - if (h==0) - this.height=this.pixelheight*1000; - else - this.height=h; - - this.imagestart =headermap[10]+headermap[11]*256+headermap[12]*256*256+headermap[13]*256*256*256; - this.bitperpixel=headermap[28]; - } - - public String gethref() { return this.ref; } - public int getWidth() { return this.width; } - public int getHeight() { return this.height; } - public int getpixelwidth() { return this.pixelwidth; } - public int getpixelheight() { return this.pixelheight; } - public int getX(){ return this.X; } - public int getY(){ return this.Y; } - - public int[] getimagemap(){ - int input; - int[] temp = new int[nextfourdiv(this.pixelwidth)*(this.pixelheight)]; - try { - FileInputStream file = new FileInputStream(this.ref); - int count = 0; - file.skip((long) this.imagestart); - while ((input = file.read()) != -1) { - temp[count++] = input; - } - file.close(); - } catch (IOException e) { - System.err.println("Image not found"); - } - int[] map = new int[this.pixelheight * this.pixelwidth]; - int k = 0; - for (int y = 0; y < this.pixelheight; y++) { - for (int x = 0; x < this.pixelwidth; x++) - map[k++] = temp[y * nextfourdiv(this.pixelwidth) + x]; - } - return map; - } - - public boolean getcolor(){return false;} - public int getbitperpixel() {return this.bitperpixel;} - - private int nextfourdiv(int number) { - return ((number/4)+1)*4; - } - - } - diff --git a/src/org/apache/fop/image/BmpColImage.java b/src/org/apache/fop/image/BmpColImage.java index b8c21d9f0..88688cad5 100644 --- a/src/org/apache/fop/image/BmpColImage.java +++ b/src/org/apache/fop/image/BmpColImage.java @@ -50,253 +50,127 @@ */ /* modified by JKT to integrate into 0.12.0 */ - - //Title: BoBoGi FOP - //Version: - //Copyright: Copyright (c) 1999 - //Author: Sergio Botti - //Company: Dibe Elsag - //Description: xml to pdf converter - - package org.apache.fop.image; - import java.io.FileInputStream; - import java.io.IOException; - import java.io.PrintWriter; - - public class BmpColImage implements FopImage { - int X; - int Y; - int width; - int height; - int pixelwidth; - int pixelheight; - String ref; - boolean color=true; - int bitperpixel; - int[] imagemap; - int imagestart; - /* - Costructor read the header of the bmp file to get the size - and the other data - SB - */ - public BmpColImage(String href,int x,int y,int w,int h) - { - this.ref=href; - this.X=x; - this.Y=y; - - int wpos=18; - int hpos=22; //offset positioning for w and height in bmp files - int [] headermap = new int[54]; - try{ - FileInputStream file=new FileInputStream(ref); - boolean eof=false; - int count=0; - while ((!eof) && (count<54) ) { - int input =file.read(); - if (input==-1) - eof=true; - else - headermap[count++]=input; - } - file.close(); - }catch (IOException e) {System.err.println("Image not found");} - // gets h & w from headermap - this.pixelwidth = headermap[wpos]+headermap[wpos+1]*256+headermap[wpos+2]*256*256+headermap[wpos+3]*256*256*256; - this.pixelheight = headermap[hpos]+headermap[hpos+1]*256+headermap[hpos+2]*256*256+headermap[hpos+3]*256*256*256; - if (w==0) - this.width=this.pixelwidth*1000; - else - this.width=w; - if (h==0) - this.height=this.pixelheight*1000; - else - this.height=h; - - this.imagestart =headermap[10]+headermap[11]*256+headermap[12]*256*256+headermap[13]*256*256*256; - this.bitperpixel=headermap[28]; - } - - public String gethref() { return this.ref; } - public int getWidth() { return this.width; } - public int getHeight() { return this.height; } - public int getpixelwidth() { return this.pixelwidth; } - public int getpixelheight() { return this.pixelheight; } - public int getX(){ return this.X; } - public int getY(){ return this.Y; } - - public int[] getimagemap(){ - int[] temp = new int[nextfourdiv(this.pixelwidth*3)*(this.pixelheight)]; - try{ - FileInputStream file=new FileInputStream(this.ref); - boolean eof=false; - int count=0; - file.skip((long)this.imagestart); - while (!eof) { - int input = file.read(); - if (input==-1) { - eof=true; - } else { - temp[count++]=input; - } - } - file.close(); - } catch (IOException e) { - System.err.println("Image not found"); - } - - int[] map =new int[this.pixelheight*this.pixelwidth*3]; - int k=0; - - for (int y=0;y<this.pixelheight;y++) { - for (int x=0;x<(this.pixelwidth);x++) { - map[k++]=temp[y*nextfourdiv(this.pixelwidth*3)+x*3+2]; - map[k++]=temp[y*nextfourdiv(this.pixelwidth*3)+x*3+1]; - map[k++]=temp[y*nextfourdiv(this.pixelwidth*3)+x*3]; - - //map[k++]=temp[y*nextfourdiv(this.pixelwidth*3)+x]; - } - } - return map; - } - - - public boolean getcolor(){return true;} - public int getbitperpixel() {return this.bitperpixel;} - - // - private int nextfourdiv(int number) { - int n = number; - while((n%4)!=0) { - n++; - } - return n; - } - - } - diff --git a/src/org/apache/fop/image/FopImage.java b/src/org/apache/fop/image/FopImage.java index e46286aad..c4c2f88b5 100644 --- a/src/org/apache/fop/image/FopImage.java +++ b/src/org/apache/fop/image/FopImage.java @@ -50,49 +50,25 @@ */ /* modified by JKT to integrate into 0.12.0 */ - - //Title: BoBoGi FOP - //Version: - //Copyright: Copyright (c) 1999 - //Author: Sergio Botti - //Company: Dibe Elsag - //Description: Part in xml to pdf converter - - - package org.apache.fop.image; - - public interface FopImage { - public int getpixelwidth(); - public int getpixelheight(); - public int getWidth(); - public int getHeight(); - public int getX(); - public int getY(); - public String gethref(); - public int[] getimagemap(); - public boolean getcolor(); - public int getbitperpixel(); - } - diff --git a/src/org/apache/fop/image/FopImageFactory.java b/src/org/apache/fop/image/FopImageFactory.java index 06b9c95ef..fe77d2277 100644 --- a/src/org/apache/fop/image/FopImageFactory.java +++ b/src/org/apache/fop/image/FopImageFactory.java @@ -50,95 +50,48 @@ */ /* modified by JKT to integrate into 0.12.0 */ - - //Title: BoBoGi FOP - //Version: x - //Copyright: Copyright (c) 1999 - //Author: Sergio Botti - //Company: Dibe Elsag - //Description: xml to pdf converter - - - package org.apache.fop.image; - - import java.io.FileInputStream; - import java.io.IOException; - - public class FopImageFactory { - - public static FopImage Make(String ref,int x,int y, int width, int height) { - - - int colorpos=28; //offset positioning for w and height in bmp files - int [] headermap = new int[54]; - try{ - FileInputStream file=new FileInputStream(ref); - boolean eof=false; - int count=0; - while ((!eof) && (count<54) ) { - int input =file.read(); - if (input==-1) - eof=true; - else - headermap[count++]=input; - } - file.close(); - } catch (IOException e) {System.err.println("Image not found");} - int bpp=headermap[28]; - if (bpp==8) { - return (new BmpBwImage(ref,x,y,width,height)); - } else if (bpp==24) { - return (new BmpColImage(ref,x,y,width,height)); - } - System.err.println("Unsupported bmp format"); - - return null; - - } - } - diff --git a/src/org/apache/fop/image/GifJpegImage.java b/src/org/apache/fop/image/GifJpegImage.java index 4d5d66e65..4928ee304 100644 --- a/src/org/apache/fop/image/GifJpegImage.java +++ b/src/org/apache/fop/image/GifJpegImage.java @@ -50,241 +50,121 @@ */ /* modified by JKT to integrate into 0.12.0 */ - - //Title: BoBoGi FOP - //Version: - //Copyright: Copyright (c) 1999 - //Author: Sergio Botti - //Company: Dibe Elsag - //Description: xml to pdf converter - - - package org.apache.fop.image; - - import java.util.Hashtable; - import java.net.URL; - import java.io.IOException; - import java.io.PrintWriter; - import java.awt.image.*; - import java.awt.Image; - import java.awt.Toolkit; - - public class GifJpegImage implements FopImage { - int X; - int Y; - int width; - int height; - int pixelwidth; - int pixelheight; - String ref; - boolean color=true; - int bitperpixel=8; - int[] imagemap; - int[] tempmap; - /* - Costructor read the header of the bmp file to get the size - and the other data - SB - */ - - public GifJpegImage(String href,int x,int y,int w,int h) - { - this.ref=href; - this.X=x; - this.Y=y; - this.pixelheight=-1; - this.pixelwidth=-1; - try { - URL url = new URL(href); - ImageProducer ip = (ImageProducer)url.getContent(); - FopImageConsumer consumer = new FopImageConsumer(); - ip.startProduction(consumer); - while ((this.pixelheight = consumer.getHeight())==-1) {} - while ((this.pixelwidth = consumer.getWidth())==-1) {} - this.tempmap = new int[this.pixelwidth*this.pixelheight]; - //Image img=Toolkit.getDefaultToolkit().getImage("prova.gif"); - // Image img=Toolkit.getDefaultToolkit().getImage(url); - PixelGrabber pg = new PixelGrabber(ip,0,0,this.pixelwidth,this.pixelheight,this.tempmap,0,w); - try { - pg.grabPixels(); - }catch (InterruptedException e) {System.err.println("Image grabbing interrupted");} - } catch (ClassCastException e) {System.err.println("Image format not supported: " + href); - } catch (Exception e) {System.err.println("Error loading image " + href + " : " +e); - } - if (w==0) - this.width=this.pixelwidth*1000; - else - this.width=w; - if (h==0) - this.height=this.pixelheight*1000; - else - this.height=h; - } - // - public static class FopImageConsumer implements ImageConsumer { - int width = -1; - int height = -1; - public void imageComplete(int status) {} - public void setColorModel(ColorModel model) {} - public void setDimensions(int width, int height) { - this.width = width; - this.height = height; - } - public void setHints(int hintflags) {} - public void setPixels(int x, int y, int w, int h,ColorModel model, byte[] pixels,int off, int scansize) {} - public void setPixels(int x, int y, int w, int h,ColorModel model, int[] pixels,int off, int scansize) {} - public void setProperties(Hashtable props) {} - public int getWidth() { return this.width; } - public int getHeight() { return this.height; } - } - - // - public String gethref() { return this.ref; } - public int getWidth() { return this.width; } - public int getHeight() { return this.height; } - public int getpixelwidth() { return this.pixelwidth; } - public int getpixelheight() { return this.pixelheight; } - public int getX(){ return this.X; } - public int getY(){ return this.Y; } - - public int[] getimagemap(){ - this.imagemap=new int[this.pixelheight*this.pixelwidth*3]; - int count=0; - int i; - for(i=0;i<(this.pixelheight*this.pixelwidth);i++) - { - int red = ((this.tempmap[i]>>16) & 0xff); - int green = ((this.tempmap[i]>> 8) & 0xff); - int blue = ((this.tempmap[i] ) & 0xff); - this.imagemap[count++]=red; - this.imagemap[count++]=green; - this.imagemap[count++]=blue; - } - return imagemap; - } - - - public boolean getcolor(){return true;} - public int getbitperpixel() {return this.bitperpixel;} - } - - - diff --git a/src/org/apache/fop/image/ImageArea.java b/src/org/apache/fop/image/ImageArea.java index b8edcdf0b..9ff0698e2 100644 --- a/src/org/apache/fop/image/ImageArea.java +++ b/src/org/apache/fop/image/ImageArea.java @@ -50,115 +50,58 @@ */ /* modified by JKT to integrate into 0.12.0 */ - - package org.apache.fop.image; - - import org.apache.fop.layout.*; - import org.apache.fop.render.Renderer; - - import java.util.Vector; - import java.util.Enumeration; - - public class ImageArea extends Area { - - protected int xOffset = 0; - protected FopImage image; - - public ImageArea(FontState fontState, FopImage img, - int AllocationWidth, int width, int height, - int startIndent, int endIndent, int align) { - super(fontState,width,height); - this.currentHeight = height; - this.contentRectangleWidth = width; - this.image = img; - - switch (align) { - case 1: - xOffset = startIndent; - break; - case 2: - if (endIndent == 0) - endIndent = AllocationWidth; - xOffset = (endIndent - width); - break; - case 3: - case 4: - if (endIndent == 0) - endIndent = AllocationWidth; - xOffset = startIndent + ((endIndent - startIndent) - width)/2; - break; - } - } - - public int getXOffset() { - return this.xOffset; - } - - public FopImage getImage() { - return this.image; - } - - public void render(Renderer renderer) { - renderer.renderImageArea(this); - } - - public int getImageHeight() { - return currentHeight; - } - } - diff --git a/src/org/apache/fop/layout/AlternatingPageMasterFactory.java b/src/org/apache/fop/layout/AlternatingPageMasterFactory.java index 23e1739b4..d08bbdf20 100644 --- a/src/org/apache/fop/layout/AlternatingPageMasterFactory.java +++ b/src/org/apache/fop/layout/AlternatingPageMasterFactory.java @@ -50,83 +50,42 @@ */ package org.apache.fop.layout; - - public class AlternatingPageMasterFactory extends PageMasterFactory { - - private PageMaster pageMasterFirst; - private PageMaster pageMasterEven; - private PageMaster pageMasterOdd; - - private static final int FIRST = 0; - private static final int EVEN = 1; - private static final int ODD = 2; - - private int state; - - public AlternatingPageMasterFactory(PageMaster first, PageMaster even, PageMaster odd) { - this.pageMasterFirst = first; - this.pageMasterEven = even; - this.pageMasterOdd = odd; - this.state = FIRST; - } - - public int getHeight() { - return this.pageMasterFirst.getHeight(); - } - - public PageMaster getNextPageMaster() { - PageMaster pm; - - switch (this.state) { - case EVEN: pm = this.pageMasterEven; this.state = ODD; break; - case ODD: pm = this.pageMasterOdd; this.state = EVEN; break; - default: pm = this.pageMasterFirst; this.state = EVEN; - } - - return pm; - } - - public int getWidth() { - return this.pageMasterFirst.getWidth(); - } - } - diff --git a/src/org/apache/fop/layout/Area.java b/src/org/apache/fop/layout/Area.java index a0b4281a6..0849b2ba4 100644 --- a/src/org/apache/fop/layout/Area.java +++ b/src/org/apache/fop/layout/Area.java @@ -50,207 +50,104 @@ */ package org.apache.fop.layout; - - // Java - import java.util.Vector; - - abstract public class Area extends Box { - - /* nominal font size and nominal font family incorporated in - fontState */ - protected FontState fontState; - - protected Vector children = new Vector(); - - /* max size in line-progression-direction */ - protected int maxHeight; - - protected int currentHeight = 0; - - protected int contentRectangleWidth; - - protected int allocationWidth; - - /* the inner-most area container the area is in */ - protected AreaContainer areaContainer; - - /* the page this area is on */ - protected Page page; - - public Area (FontState fontState) { - this.fontState = fontState; - } - - public Area (FontState fontState, int allocationWidth, int maxHeight) { - this.fontState = fontState; - this.allocationWidth = allocationWidth; - this.maxHeight = maxHeight; - } - - public void addChild(Box child) { - this.children.addElement(child); - child.parent = this; - } - - public void addChildAtStart(Box child) { - this.children.insertElementAt(child,0); - child.parent = this; - } - - public void addDisplaySpace(int size) { - this.addChild(new DisplaySpace(size)); - this.currentHeight += size; - } - - public FontInfo getFontInfo() { - return this.page.getFontInfo(); - } - - public void end() { - } - - public int getAllocationWidth() { - return this.allocationWidth; - } - - public Vector getChildren() { - return this.children; - } - - public int getContentWidth() { - return this.contentRectangleWidth; - } - - public FontState getFontState() { - return this.fontState; - } - - public int getHeight() { - return this.currentHeight; - } - - public int getMaxHeight() { - return this.maxHeight; - } - - public Page getPage() { - return this.page; - } - - public void increaseHeight(int amount) { - this.currentHeight += amount; - } - - public void setPage(Page page) { - this.page = page; - } - - public int spaceLeft() { - return maxHeight - currentHeight; - } - - public void start() { - } - } - diff --git a/src/org/apache/fop/layout/AreaContainer.java b/src/org/apache/fop/layout/AreaContainer.java index 30182f4d6..af39677cf 100644 --- a/src/org/apache/fop/layout/AreaContainer.java +++ b/src/org/apache/fop/layout/AreaContainer.java @@ -50,65 +50,33 @@ */ package org.apache.fop.layout; - - // FOP - import org.apache.fop.render.Renderer; - - // Java - import java.util.Vector; - import java.util.Enumeration; - - public class AreaContainer extends Area { - - private int xPosition; // should be able to take value 'left' and 'right' too - private int yPosition; // should be able to take value 'top' and 'bottom' too - - AreaContainer(int xPosition, int yPosition, int allocationWidth, int maxHeight) { - super(null, allocationWidth, maxHeight); - this.xPosition = xPosition; - this.yPosition = yPosition; - } - - public void render(Renderer renderer) { - renderer.renderAreaContainer(this); - } - - public int getXPosition() { - return xPosition; - } - - public int getYPosition() { - return yPosition; - } - } - diff --git a/src/org/apache/fop/layout/AreaTree.java b/src/org/apache/fop/layout/AreaTree.java index 6f0ba0bdd..b0bc7159e 100644 --- a/src/org/apache/fop/layout/AreaTree.java +++ b/src/org/apache/fop/layout/AreaTree.java @@ -50,81 +50,41 @@ */ package org.apache.fop.layout; - - // FOP - import org.apache.fop.apps.FOPException; - import org.apache.fop.fo.flow.StaticContent; - import org.apache.fop.svg.*; - import org.apache.fop.render.Renderer; - - // Java - import java.io.IOException; - import java.io.PrintWriter; - import java.util.Enumeration; - import java.util.Stack; - import java.util.Vector; - - public class AreaTree { - - /** object containing information on available fonts, including - metrics */ - FontInfo fontInfo; - - /* list of all the pages */ - Vector pageList = new Vector(); - - public void setFontInfo(FontInfo fontInfo) { - this.fontInfo = fontInfo; - } - - public FontInfo getFontInfo() { - return this.fontInfo; - } - - public void addPage(Page page) { - this.pageList.addElement(page); - } - - public Vector getPages() { - return this.pageList; - } - } - diff --git a/src/org/apache/fop/layout/BlockArea.java b/src/org/apache/fop/layout/BlockArea.java index ded113146..a9242bbbb 100644 --- a/src/org/apache/fop/layout/BlockArea.java +++ b/src/org/apache/fop/layout/BlockArea.java @@ -50,265 +50,133 @@ */ package org.apache.fop.layout; - - // FOP - import org.apache.fop.render.Renderer; - - // Java - import java.util.Vector; - import java.util.Enumeration; - - public class BlockArea extends Area { - - /* relative to area container */ - protected int startIndent; - protected int endIndent; - - /* first line startIndent modifier */ - protected int textIndent; - - protected int lineHeight; - - protected int halfLeading; - - /* text-align of all but the last line */ - protected int align; - - /* text-align of the last line */ - protected int alignLastLine; - - protected LineArea currentLineArea; - - /* have any line areas been used? */ - protected boolean hasLines = false; - - public BlockArea(FontState fontState, int allocationWidth, - int maxHeight, int startIndent, int endIndent, - int textIndent, int align, int alignLastLine, - int lineHeight) { - super(fontState, allocationWidth, maxHeight); - - this.startIndent = startIndent; - this.endIndent = endIndent; - this.textIndent = textIndent; - this.contentRectangleWidth = allocationWidth - startIndent - endIndent; - this.align = align; - this.alignLastLine = alignLastLine; - this.lineHeight = lineHeight; - - this.halfLeading = (lineHeight - fontState.getFontSize())/2; - } - - public void render(Renderer renderer) { - renderer.renderBlockArea(this); - } - - public void addLineArea(LineArea la) { - if (!la.isEmpty()) { - this.addDisplaySpace(this.halfLeading); - int size = la.getHeight(); - this.addChild(la); - this.increaseHeight(size); - this.addDisplaySpace(this.halfLeading); - } - } - - public int addText(FontState fontState, float red, float green, - float blue, int wrapOption, - int whiteSpaceTreatment, char data[], - int start, int end) { - int ts, te; - char[] ca; - - ts = start; - te = end; - ca = data; - - if (currentHeight + currentLineArea.getHeight() > maxHeight) { - return start; - } - - this.currentLineArea.changeFont(fontState); - this.currentLineArea.changeColor(red, green, blue); - this.currentLineArea.changeWrapOption(wrapOption); - this.currentLineArea.changeWhiteSpaceTreatment(whiteSpaceTreatment); - ts = this.currentLineArea.addText(ca, ts, te); - this.hasLines = true; - - while (ts != -1) { - this.currentLineArea.align(this.align); - this.addLineArea(this.currentLineArea); - this.currentLineArea = new - LineArea(fontState, lineHeight, halfLeading, - allocationWidth, startIndent, endIndent); - if (currentHeight + currentLineArea.getHeight() > - this.maxHeight) { - return ts; - } - this.currentLineArea.changeFont(fontState); - this.currentLineArea.changeColor(red, green, blue); - this.currentLineArea.changeWrapOption(wrapOption); - this.currentLineArea.changeWhiteSpaceTreatment(whiteSpaceTreatment); - ts = this.currentLineArea.addText(ca, ts, te); - } - return -1; - } - - public void end() { - if (this.hasLines) { - this.currentLineArea.addPending(); - this.currentLineArea.align(this.alignLastLine); - this.addLineArea(this.currentLineArea); - } - } - - public void start() { - currentLineArea = new LineArea(fontState, lineHeight, - halfLeading, allocationWidth, - startIndent + textIndent, - endIndent); - } - - public int getEndIndent() { - return endIndent; - } - - public int getStartIndent() { - return startIndent; - } - - public int spaceLeft() { - return maxHeight - currentHeight; - } - } - diff --git a/src/org/apache/fop/layout/Box.java b/src/org/apache/fop/layout/Box.java index e02193bef..c71724247 100644 --- a/src/org/apache/fop/layout/Box.java +++ b/src/org/apache/fop/layout/Box.java @@ -50,19 +50,10 @@ */ package org.apache.fop.layout; - - import org.apache.fop.render.Renderer; - - abstract public class Box { - protected Area parent; - protected AreaTree areaTree; - abstract public void render(Renderer renderer); - } - diff --git a/src/org/apache/fop/layout/DisplaySpace.java b/src/org/apache/fop/layout/DisplaySpace.java index 5cc50fbf4..abb439573 100644 --- a/src/org/apache/fop/layout/DisplaySpace.java +++ b/src/org/apache/fop/layout/DisplaySpace.java @@ -50,37 +50,19 @@ */ package org.apache.fop.layout; - - import org.apache.fop.render.Renderer; - - public class DisplaySpace extends Space { - private int size; - - public DisplaySpace(int size) { - this.size = size; - } - public int getSize() { - return size; - } - - public void render(Renderer renderer) { - renderer.renderDisplaySpace(this); - } - } - diff --git a/src/org/apache/fop/layout/FontInfo.java b/src/org/apache/fop/layout/FontInfo.java index dc6d778fb..e651baa2a 100644 --- a/src/org/apache/fop/layout/FontInfo.java +++ b/src/org/apache/fop/layout/FontInfo.java @@ -50,155 +50,78 @@ */ package org.apache.fop.layout; - - import java.util.Hashtable; - import java.util.Enumeration; - - import org.apache.fop.apps.FOPException; - - public class FontInfo { - - Hashtable triplets; // look up a font-triplet to find a font-name - Hashtable fonts; // look up a font-name to get a font (that implements FontMetric at least) - - public FontInfo() { - this.triplets = new Hashtable(); - this.fonts = new Hashtable(); - } - - public void addFontProperties(String name, String family, String style, String weight) { - /* add the given family, style and weight as a lookup for the font - with the given name */ - - String key = family + "," + style + "," + weight; - this.triplets.put(key,name); - } - - public void addMetrics(String name, FontMetric metrics) { - // add the given metrics as a font with the given name - - this.fonts.put(name,metrics); - } - - public String fontLookup(String family, String style, String weight) throws FOPException { - // given a family, style and weight, return the font name - int i; - - try { - i = Integer.parseInt(weight); - } catch (NumberFormatException e) { - i = 0; - } - - if (i > 600) - weight = "bold"; - else if (i > 0) - weight = "normal"; - - String key = family + "," + style + "," + weight; - - String f = (String)this.triplets.get(key); - if (f == null) { - f = (String)this.triplets.get("any," + style + "," + weight); - if (f == null) { - f = (String)this.triplets.get("any,normal,normal"); - if (f == null) { - throw new FOPException("no default font defined by OutputConverter"); - } - System.err.println("WARNING: defaulted font to any,normal,normal"); - } - System.err.println("WARNING: unknown font "+family+" so defaulted font to any"); - } - return f; - } - - public Hashtable getFonts() { - return this.fonts; - } - - public FontMetric getMetricsFor(String fontName) throws FOPException { - return (FontMetric)fonts.get(fontName); - } - - public FontMetric getMetricsFor(String family, String style, String weight) throws FOPException { - // given a family, style and weight, return the metric - - return (FontMetric)fonts.get(fontLookup(family,style,weight)); - } - } - diff --git a/src/org/apache/fop/layout/FontMetric.java b/src/org/apache/fop/layout/FontMetric.java index 3ef8f6436..68398b0a9 100644 --- a/src/org/apache/fop/layout/FontMetric.java +++ b/src/org/apache/fop/layout/FontMetric.java @@ -50,35 +50,18 @@ */ package org.apache.fop.layout; - - /** - * interface for font metric classes - */ - public interface FontMetric { - int getAscender(); - int getCapHeight(); - int getDescender(); - int getXHeight(); - - /** - * return width (in 1/1000ths of point size) of character at - * code point i - */ - public int width(int i); - } - diff --git a/src/org/apache/fop/layout/FontState.java b/src/org/apache/fop/layout/FontState.java index 4dbdaa7b1..12abcea13 100644 --- a/src/org/apache/fop/layout/FontState.java +++ b/src/org/apache/fop/layout/FontState.java @@ -50,123 +50,62 @@ */ package org.apache.fop.layout; - - import org.apache.fop.apps.FOPException; - - public class FontState { - - protected FontInfo fontInfo; - private String fontName; - private int fontSize; - private String fontFamily; - private String fontStyle; - private String fontWeight; - private FontMetric metric; - - public FontState(FontInfo fontInfo, String fontFamily, String fontStyle, String fontWeight, int fontSize) throws FOPException { - this.fontInfo = fontInfo; - this.fontFamily = fontFamily; - this.fontStyle = fontStyle; - this.fontWeight = fontWeight; - this.fontSize = fontSize; - this.fontName = fontInfo.fontLookup(fontFamily,fontStyle,fontWeight); - this.metric = fontInfo.getMetricsFor(fontName); - } - - public int getAscender() { - return fontSize * metric.getAscender() / 1000; - } - - public int getCapHeight() { - return fontSize * metric.getCapHeight() / 1000; - } - - public int getDescender() { - return fontSize * metric.getDescender() / 1000; - } - - public String getFontName() { - return this.fontName; - } - - public int getFontSize() { - return this.fontSize; - } - - public String getFontWeight() { - return this.fontWeight; - } - - public FontInfo getFontInfo() { - return this.fontInfo; - } - - public int getXHeight() { - return fontSize * metric.getXHeight() / 1000; - } - - public int width(int charnum) { - // returns width of given character number in millipoints - return (fontSize * metric.width(charnum) / 1000); - } - } - diff --git a/src/org/apache/fop/layout/InlineArea.java b/src/org/apache/fop/layout/InlineArea.java index 37bff3339..239270a7a 100644 --- a/src/org/apache/fop/layout/InlineArea.java +++ b/src/org/apache/fop/layout/InlineArea.java @@ -50,77 +50,39 @@ */ package org.apache.fop.layout; - - import org.apache.fop.render.Renderer; - - public class InlineArea extends Area { - - private String text; - private float red, green, blue; - - public InlineArea(FontState fontState, float red, float green, float blue, String text, int width) { - super(fontState); - this.red = red; - this.green = green; - this.blue = blue; - this.text = text; - this.contentRectangleWidth = width; - } - - public void render(Renderer renderer) { - renderer.renderInlineArea(this); - } - - public float getBlue() { - return this.blue; - } - - public float getGreen() { - return this.green; - } - - public float getRed() { - return this.red; - } - - public String getText() { - return this.text; - } - } - diff --git a/src/org/apache/fop/layout/InlineSpace.java b/src/org/apache/fop/layout/InlineSpace.java index 2fc059832..4ff64cd43 100644 --- a/src/org/apache/fop/layout/InlineSpace.java +++ b/src/org/apache/fop/layout/InlineSpace.java @@ -50,47 +50,24 @@ */ package org.apache.fop.layout; - - import org.apache.fop.render.Renderer; - - public class InlineSpace extends Space { - private int size; // in millipoints - - public InlineSpace(int amount) { - this.size = amount; - } - - public int getSize() { - return size; - } - - public void setSize(int amount) { - this.size = amount; - } - - public void render(Renderer renderer) { - renderer.renderInlineSpace(this); - } - } - diff --git a/src/org/apache/fop/layout/LineArea.java b/src/org/apache/fop/layout/LineArea.java index ff2b4e2f9..c2993f38e 100644 --- a/src/org/apache/fop/layout/LineArea.java +++ b/src/org/apache/fop/layout/LineArea.java @@ -50,803 +50,402 @@ */ package org.apache.fop.layout; - - import org.apache.fop.render.Renderer; - - import java.util.Vector; - import java.util.Enumeration; - - import org.apache.fop.fo.properties.WrapOption; // for enumerated - // values - import org.apache.fop.fo.properties.WhiteSpaceTreatment; // for - // enumerated values - import org.apache.fop.fo.properties.TextAlign; // for enumerated - // values - import org.apache.fop.fo.properties.TextAlignLast; // for enumerated - // values - - public class LineArea extends Area { - - protected int lineHeight; - protected int halfLeading; - protected int nominalFontSize; - protected int nominalGlyphHeight; - - protected int allocationHeight; - protected int startIndent; - protected int endIndent; - - private int placementOffset; - - private FontState currentFontState; // not the nominal, which is - // in this.fontState - private float red, green, blue; - private int wrapOption; - private int whiteSpaceTreatment; - - /* the width of text that has definitely made it into the line - area */ - protected int finalWidth = 0; - - /* the width of the current word so far */ - protected int wordWidth = 0; - - /* values that prev (below) may take */ - protected static final int NOTHING = 0; - protected static final int WHITESPACE = 1; - protected static final int TEXT = 2; - - /* the character type of the previous character */ - protected int prev = NOTHING; - - /* the position in data[] of the start of the current word */ - protected int wordStart; - - /* the length (in characters) of the current word */ - protected int wordLength = 0; - - /* width of spaces before current word */ - protected int spaceWidth = 0; - - /* the inline areas that have not yet been added to the line - because subsequent characters to come (in a different addText) - may be part of the same word */ - protected Vector pendingAreas = new Vector(); - - /* the width of the pendingAreas */ - protected int pendingWidth = 0; - - public LineArea(FontState fontState, int lineHeight, int - halfLeading, int allocationWidth, int startIndent, - int endIndent) { - super(fontState); - - this.currentFontState = fontState; - this.lineHeight = lineHeight; - this.nominalFontSize = fontState.getFontSize(); - this.nominalGlyphHeight = fontState.getAscender() - - fontState.getDescender(); - - this.placementOffset = fontState.getAscender(); - this.contentRectangleWidth = allocationWidth - startIndent - - endIndent; - this.fontState = fontState; - - this.allocationHeight = this.nominalGlyphHeight; - this.halfLeading = this.lineHeight - this.allocationHeight; - - this.startIndent = startIndent; - this.endIndent = endIndent; - - } - - public void render(Renderer renderer) { - renderer.renderLineArea(this); - } - - public int addText(char data[], int start, int end) { - boolean overrun = false; - - wordStart = start; - wordLength = 0; - wordWidth = 0; - - /* iterate over each character */ - for (int i = start; i < end; i++) { - int charWidth; - /* get the character */ - char c = data[i]; - - if (c > 127) { - /* this class shouldn't be hard coded */ - char d = - org.apache.fop.render.pdf.CodePointMapping.map[c]; - if (d != 0) { - c = data[i] = d; - } else { - System.err.print("ch" - + (int)c + "?"); - c = data[i] = '#'; - } - } - - charWidth = currentFontState.width(c); - - if ((c == ' ') || - (c == '\n') || - (c == '\r') || - (c == '\t')) { // whitespace - - if (prev == WHITESPACE) { - - // if current & previous are WHITESPACE - - if (this.whiteSpaceTreatment == - WhiteSpaceTreatment.PRESERVE) { - if (c == ' ') { - spaceWidth += currentFontState.width(32); - } else if (c == '\n') { - // force line break - return i; - } else if (c == '\t') { - spaceWidth += 8 * currentFontState.width(32); - } - } // else ignore it - - } else if (prev == TEXT) { - - // if current is WHITESPACE and previous TEXT - - // the current word made it, so - - // add the space before the current word (if there - // was some) - - if (spaceWidth > 0) { - addChild(new InlineSpace(spaceWidth)); - finalWidth += spaceWidth; - spaceWidth = 0; - } - - // add any pending areas - - Enumeration e = pendingAreas.elements(); - while (e.hasMoreElements()) { - InlineArea inlineArea = (InlineArea) e.nextElement(); - addChild(inlineArea); - } - finalWidth += pendingWidth; - - // reset pending areas array - pendingWidth = 0; - pendingAreas = new Vector(); - - // add the current word - - if (wordLength > 0) { - addChild(new InlineArea(currentFontState, - this.red, this.green, - this.blue, new - String(data, wordStart, - wordLength), - wordWidth)); - finalWidth += wordWidth; - - // reset word width - wordWidth = 0; - } - - // deal with this new whitespace following the - // word we just added - - prev = WHITESPACE; - - if (this.whiteSpaceTreatment == - WhiteSpaceTreatment.IGNORE) { - // do nothing - } else { - spaceWidth = currentFontState.width(32); - } - if (this.whiteSpaceTreatment == - WhiteSpaceTreatment.PRESERVE) { - if (c == '\n') { - // force a line break - return i; - } else if (c == '\t') { - spaceWidth = currentFontState.width(32); - } - } - - } else { - - // if current is WHITESPACE and no previous - - if (this.whiteSpaceTreatment == - WhiteSpaceTreatment.PRESERVE) { - prev = WHITESPACE; - spaceWidth = currentFontState.width(32); - } else { - // skip over it - start++; - } - } - - } else { // current is TEXT - - if (prev == WHITESPACE) { - - // if current is TEXT and previous WHITESPACE - - wordWidth = charWidth; - if ((finalWidth + spaceWidth + wordWidth) > - this.contentRectangleWidth) { - if (overrun) - System.err.print(">"); - if (this.wrapOption == WrapOption.WRAP) - return i; - } - prev = TEXT; - wordStart = i; - wordLength = 1; - } else if (prev == TEXT) { - wordLength++; - wordWidth += charWidth; - } else { // nothing previous - prev = TEXT; - wordStart = i; - wordLength = 1; - wordWidth = charWidth; - } - - if ((finalWidth + spaceWidth + pendingWidth + wordWidth) > - this.contentRectangleWidth) { - - // BREAK MID WORD - if (wordStart == start) { // if couldn't even fit - // first word - overrun = true; - // if not at start of line, return word start - // to try again on a new line - if (finalWidth > 0) { - return wordStart; - } - } else if (this.wrapOption == WrapOption.WRAP) { - return wordStart; - } - } - - } - } // end of iteration over text - - if (prev == TEXT) { - pendingAreas.addElement(new InlineArea(currentFontState, this.red, - this.green, this.blue, new - String(data, wordStart, - wordLength), wordWidth)); - pendingWidth += wordWidth; - wordWidth = 0; - } - - if (overrun) - System.err.print(">"); - return -1; - } - - public void addPending() { - if (spaceWidth > 0) { - addChild(new InlineSpace(spaceWidth)); - finalWidth += spaceWidth; - spaceWidth = 0; - } - - Enumeration e = pendingAreas.elements(); - while (e.hasMoreElements()) { - InlineArea inlineArea = (InlineArea) e.nextElement(); - addChild(inlineArea); - } - finalWidth += pendingWidth; - - // reset pending areas array - pendingWidth = 0; - pendingAreas = new Vector(); - } - - public void align(int type) { - int padding; - - switch (type) { - case TextAlign.START: // left - padding = this.contentRectangleWidth - finalWidth; - endIndent += padding; - break; - case TextAlign.END: // right - padding = this.contentRectangleWidth - finalWidth; - startIndent += padding; - break; - case TextAlign.CENTERED: // center - padding = (this.contentRectangleWidth - finalWidth)/2; - startIndent += padding; - endIndent += padding; - break; - case TextAlign.JUSTIFIED: // justify - Vector spaceList = new Vector(); - - int spaceCount = 0; - Enumeration e = children.elements(); - while (e.hasMoreElements()) { - Box b = (Box)e.nextElement(); - if (b instanceof InlineSpace) { - InlineSpace space = (InlineSpace)b; - spaceList.addElement(space); - spaceCount++; - } - } - if (spaceCount > 0) { - padding = (this.contentRectangleWidth - finalWidth) / - spaceCount; - } else { // no spaces - padding = 0; - } - Enumeration f = spaceList.elements(); - while (f.hasMoreElements()) { - InlineSpace space2 = (InlineSpace)f.nextElement(); - int i = space2.getSize(); - space2.setSize(i + padding); - } - } - } - - public void changeColor(float red, float green, float blue) { - this.red = red; - this.green = green; - this.blue = blue; - } - - public void changeFont(FontState fontState) { - this.currentFontState = fontState; - } - - public void changeWhiteSpaceTreatment(int whiteSpaceTreatment) { - this.whiteSpaceTreatment = whiteSpaceTreatment; - } - - public void changeWrapOption(int wrapOption) { - this.wrapOption = wrapOption; - } - - public int getEndIndent() { - return endIndent; - } - - public int getHeight() { - return this.allocationHeight; - } - - public int getPlacementOffset() { - return this.placementOffset; - } - - public int getStartIndent() { - return startIndent; - } - - public boolean isEmpty() { - return (prev==0); - } - - public Vector getPendingAreas() { - return pendingAreas; - } - - public int getPendingWidth() { - return pendingWidth; - } - - public void setPendingAreas(Vector areas) { - pendingAreas = areas; - } - - public void setPendingWidth(int width) { - pendingWidth = width; - } - } - diff --git a/src/org/apache/fop/layout/Page.java b/src/org/apache/fop/layout/Page.java index beedcda4f..c283b0d5c 100644 --- a/src/org/apache/fop/layout/Page.java +++ b/src/org/apache/fop/layout/Page.java @@ -50,183 +50,92 @@ */ package org.apache.fop.layout; - - // FOP - import org.apache.fop.render.Renderer; - - // Java - import java.util.Vector; - import java.util.Enumeration; - - public class Page { - - private int height; - private int width; - - private AreaContainer body; - private AreaContainer before; - private AreaContainer after; - private AreaContainer start; - private AreaContainer end; - - private AreaTree areaTree; - - protected int pageNumber = 0; - - Page(AreaTree areaTree, int height, int width) { - this.areaTree = areaTree; - this.height = height; - this.width = width; - } - - public void setNumber(int number) { - this.pageNumber = number; - } - - public int getNumber() { - return this.pageNumber; - } - - void addAfter(AreaContainer area) { - this.after = area; - area.setPage(this); - } - - void addBefore(AreaContainer area) { - this.before = area; - area.setPage(this); - } - - void addBody(AreaContainer area) { - this.body = area; - area.setPage(this); - } - - void addEnd(AreaContainer area) { - this.end = area; - area.setPage(this); - } - - void addStart(AreaContainer area) { - this.start = area; - area.setPage(this); - } - - public void render(Renderer renderer) { - renderer.renderPage(this); - } - - public AreaContainer getAfter() { - return this.after; - } - - public AreaContainer getBefore() { - return this.before; - } - - public AreaContainer getBody() { - return this.body; - } - - public int getHeight() { - return this.height; - } - - public int getWidth() { - return this.width; - } - - public FontInfo getFontInfo() { - return this.areaTree.getFontInfo(); - } - } - diff --git a/src/org/apache/fop/layout/PageMaster.java b/src/org/apache/fop/layout/PageMaster.java index 3b44785ae..67ca59b5a 100644 --- a/src/org/apache/fop/layout/PageMaster.java +++ b/src/org/apache/fop/layout/PageMaster.java @@ -50,133 +50,67 @@ */ package org.apache.fop.layout; - - public class PageMaster { - - private int width; - private int height; - - private Region body; - private Region before; - private Region after; - private Region start; - private Region end; - - public PageMaster(int pageWidth, int pageHeight) { - this.width = pageWidth; - this.height = pageHeight; - } - - public void addAfter(Region region) { - this.after = region; - } - - public void addBefore(Region region) { - this.before = region; - } - - public void addBody(Region region) { - this.body = region; - } - - public void addEnd(Region region) { - this.end = region; - } - - public void addStart(Region region) { - this.start = region; - } - - public int getHeight() { - return this.height; - } - - public int getWidth() { - return this.width; - } - - public Page makePage(AreaTree areaTree) { - Page p = new Page(areaTree, this.height, this.width); - if (this.body != null) { - p.addBody(body.makeAreaContainer()); - } - if (this.before != null) { - p.addBefore(before.makeAreaContainer()); - } - if (this.after != null) { - p.addAfter(after.makeAreaContainer()); - } - if (this.start != null) { - p.addStart(start.makeAreaContainer()); - } - if (this.end != null) { - p.addEnd(end.makeAreaContainer()); - } - return p; - } - } - diff --git a/src/org/apache/fop/layout/PageMasterFactory.java b/src/org/apache/fop/layout/PageMasterFactory.java index e7499f78a..1339d9645 100644 --- a/src/org/apache/fop/layout/PageMasterFactory.java +++ b/src/org/apache/fop/layout/PageMasterFactory.java @@ -50,41 +50,21 @@ */ package org.apache.fop.layout; - - abstract public class PageMasterFactory { - - private PageMasterFactory next; - - abstract public int getHeight(); - - abstract public int getWidth(); - - public PageMasterFactory getNext() { - return this.next; - } - - abstract public PageMaster getNextPageMaster(); - - public void setNext(PageMasterFactory pmf) { - this.next = pmf; - } - } - diff --git a/src/org/apache/fop/layout/Region.java b/src/org/apache/fop/layout/Region.java index e40891e06..0e4ed529a 100644 --- a/src/org/apache/fop/layout/Region.java +++ b/src/org/apache/fop/layout/Region.java @@ -50,41 +50,21 @@ */ package org.apache.fop.layout; - - public class Region { - - private int xPosition; - private int yPosition; - private int width; - private int height; - - public Region(int xPosition, int yPosition, int width, int height) { - this.xPosition = xPosition; - this.yPosition = yPosition; - this.width = width; - this.height = height; - } - - public AreaContainer makeAreaContainer() { - return new AreaContainer(xPosition, yPosition, width, height); - } - } - diff --git a/src/org/apache/fop/layout/RepeatingPageMasterFactory.java b/src/org/apache/fop/layout/RepeatingPageMasterFactory.java index 51a38ec6e..a0f84ccf6 100644 --- a/src/org/apache/fop/layout/RepeatingPageMasterFactory.java +++ b/src/org/apache/fop/layout/RepeatingPageMasterFactory.java @@ -50,75 +50,38 @@ */ package org.apache.fop.layout; - - public class RepeatingPageMasterFactory extends PageMasterFactory { - - private PageMaster pageMasterFirst; - private PageMaster pageMasterRepeating; - - private static final int FIRST = 0; - private static final int REST = 1; - - private int state; - - public RepeatingPageMasterFactory(PageMaster first, PageMaster repeating) { - this.pageMasterFirst = first; - this.pageMasterRepeating = repeating; - this.state = FIRST; - } - - public int getHeight() { - return this.pageMasterFirst.getHeight(); - } - - public PageMaster getNextPageMaster() { - PageMaster pm; - - switch (this.state) { - case REST: pm = this.pageMasterRepeating; this.state = REST; break; - default: pm = this.pageMasterFirst; this.state = REST; - } - - return pm; - } - - public int getWidth() { - return this.pageMasterFirst.getWidth(); - } - } - diff --git a/src/org/apache/fop/layout/RuleArea.java b/src/org/apache/fop/layout/RuleArea.java index 26c8fee0b..5c8c19d26 100644 --- a/src/org/apache/fop/layout/RuleArea.java +++ b/src/org/apache/fop/layout/RuleArea.java @@ -50,119 +50,60 @@ */ package org.apache.fop.layout; - - import org.apache.fop.render.Renderer; - - import java.util.Vector; - import java.util.Enumeration; - - public class RuleArea extends Area { - - int align; // text-align - int length; // length in millipoints - int ruleThickness; - - int startIndent; - int endIndent; - - float red, green, blue; - public RuleArea(FontState fontState, int allocationWidth, int maxHeight, int startIndent, int endIndent, int align, int ruleThickness, int length, float red, float green, float blue) { - super(fontState,allocationWidth,maxHeight); - - this.contentRectangleWidth = allocationWidth - startIndent - endIndent; - this.align = align; - - this.startIndent = startIndent; - this.endIndent = endIndent; - this.ruleThickness = ruleThickness; - this.length = length; - this.currentHeight = maxHeight; - - this.red = red; - this.green = green; - this.blue = blue; - } - - public void render(Renderer renderer) { - renderer.renderRuleArea(this); - } - public float getBlue() { - return this.blue; - } - public int getEndIndent() { - return endIndent; - } - public float getGreen() { - return this.green; - } - public int getHeight() { - return this.ruleThickness; - } - public float getRed() { - return this.red; - } - public int getRuleThickness() { - return this.ruleThickness; - } - public int getStartIndent() { - return startIndent; - } - } - diff --git a/src/org/apache/fop/layout/SinglePageMasterFactory.java b/src/org/apache/fop/layout/SinglePageMasterFactory.java index a26bfae02..3b5e19bf3 100644 --- a/src/org/apache/fop/layout/SinglePageMasterFactory.java +++ b/src/org/apache/fop/layout/SinglePageMasterFactory.java @@ -50,69 +50,35 @@ */ package org.apache.fop.layout; - - public class SinglePageMasterFactory extends PageMasterFactory { - - private PageMaster pageMaster; - - private static final int FIRST = 0; - private static final int DONE = 1; - - private int state; - - public SinglePageMasterFactory(PageMaster pageMaster) { - this.pageMaster = pageMaster; - this.state = FIRST; - } - - public int getHeight() { - return this.pageMaster.getHeight(); - } - - public PageMaster getNextPageMaster() { - PageMaster pm; - - switch (this.state) { - case FIRST: pm = this.pageMaster; this.state = DONE; break; - default: pm = null; - } - - return pm; - } - public int getWidth() { - return this.pageMaster.getWidth(); - } - } - diff --git a/src/org/apache/fop/layout/Space.java b/src/org/apache/fop/layout/Space.java index bbc2f138a..5a6e16228 100644 --- a/src/org/apache/fop/layout/Space.java +++ b/src/org/apache/fop/layout/Space.java @@ -50,9 +50,5 @@ */ package org.apache.fop.layout; - - abstract public class Space extends Box { - } - diff --git a/src/org/apache/fop/pdf/PDFDocument.java b/src/org/apache/fop/pdf/PDFDocument.java index 7cbf8bd3f..042f8b1a8 100644 --- a/src/org/apache/fop/pdf/PDFDocument.java +++ b/src/org/apache/fop/pdf/PDFDocument.java @@ -50,611 +50,306 @@ */ /* image support modified from work of BoBoGi */ - - package org.apache.fop.pdf; - - // images are the one place that FOP classes outside this package get - // referenced and I'd rather not do it - import org.apache.fop.image.FopImage; - - // Java - import java.io.IOException; - import java.io.PrintWriter; - import java.util.Vector; - - /** - * class representing a PDF document. - * - * The document is built up by calling various methods and then finally - * output to given filehandle using output method. - * - * A PDF document consists of a series of numbered objects preceded by a - * header and followed by an xref table and trailer. The xref table - * allows for quick access to objects by listing their character - * positions within the document. For this reason the PDF document must - * keep track of the character position of each object. The document - * also keeps direct track of the /Root, /Info and /Resources objects. - */ - public class PDFDocument { - - /** the version of PDF supported */ - protected static final String pdfVersion = "1.2"; - - /** the current character position */ - protected int position = 0; - - /** the character position of each object */ - protected Vector location = new Vector(); - - /** the counter for object numbering */ - protected int objectcount = 0; - - /** the objects themselves */ - protected Vector objects = new Vector(); - - /** character position of xref table */ - protected int xref; - - /** the /Root object */ - protected PDFRoot root; - - /** the /Info object */ - protected PDFInfo info; - - /** the /Resources object */ - protected PDFResources resources; - - protected int xObjectCount = 0; - protected Vector xObjects = new Vector(); - - /** - * creates an empty PDF document - */ - public PDFDocument() { - - /* create the /Root, /Info and /Resources objects */ - this.root = makeRoot(); - this.info = makeInfo(); - this.resources = makeResources(); - } - - /** - * set the producer of the document - * - * @param producer string indicating application producing the PDF - */ - public void setProducer(String producer) { - this.info.setProducer(producer); - } - - /** - * make /Root object as next object - * - * @return the created /Root object - */ - protected PDFRoot makeRoot() { - - /* create a PDFRoot with the next object number and add to - list of objects */ - PDFRoot pdfRoot = new PDFRoot(++this.objectcount); - this.objects.addElement(pdfRoot); - - /* create a new /Pages object to be root of Pages hierarchy - and add to list of objects */ - PDFPages rootPages = new PDFPages(++this.objectcount); - this.objects.addElement(rootPages); - - /* inform the /Root object of the /Pages root */ - pdfRoot.setRootPages(rootPages); - return pdfRoot; - } - - /** - * make an /Info object - * - * @param producer string indicating application producing the PDF - * @return the created /Info object - */ - protected PDFInfo makeInfo() { - - /* create a PDFInfo with the next object number and add to - list of objects */ - PDFInfo pdfInfo = new PDFInfo(++this.objectcount); - this.objects.addElement(pdfInfo); - return pdfInfo; - } - - /** - * make a /Resources object - * - * @return the created /Resources object - */ - private PDFResources makeResources() { - - /* create a PDFResources with the next object number and add - to list of objects */ - PDFResources pdfResources = new PDFResources(++this.objectcount); - this.objects.addElement(pdfResources); - return pdfResources; - } - - /** - * make a Type1 /Font object - * - * @param fontname internal name to use for this font (eg "F1") - * @param basefont name of the base font (eg "Helvetica") - * @param encoding character encoding scheme used by the font - * @return the created /Font object - */ - public PDFFont makeFont(String fontname, String basefont, - String encoding) { - - /* create a PDFFont with the next object number and add to the - list of objects */ - PDFFont font = new PDFFont(++this.objectcount, fontname, - basefont, encoding); - this.objects.addElement(font); - return font; - } - - public int addImage(FopImage img) { - PDFXObject xObject = new PDFXObject(++this.objectcount, - ++this.xObjectCount, img); - this.objects.addElement(xObject); - this.xObjects.addElement(xObject); - return xObjectCount; - } - - /** - * make a /Page object - * - * @param resources resources object to use - * @param contents stream object with content - * @param pagewidth width of the page in points - * @param pageheight height of the page in points - * @return the created /Page object - */ - public PDFPage makePage(PDFResources resources, - PDFStream contents, int pagewidth, - int pageheight) { - - /* create a PDFPage with the next object number, the given - resources, contents and dimensions */ - PDFPage page = new PDFPage(++this.objectcount, resources, - contents, pagewidth, pageheight); - - /* add it to the list of objects */ - this.objects.addElement(page); - - /* add the page to the Root */ - this.root.addPage(page); - - return page; - } - - /** - * make a stream object - * - * @return the stream object created - */ - public PDFStream makeStream() { - - /* create a PDFStream with the next object number and add it - to the list of objects */ - PDFStream obj = new PDFStream(++this.objectcount); - this.objects.addElement(obj); - return obj; - } - - /** - * get the /Resources object for the document - * - * @return the /Resources object - */ - public PDFResources getResources() { - return this.resources; - } - - /** - * write the entire document out - * - * @param writer the PrinterWriter to output the document to - */ - public void output(PrintWriter writer) throws IOException { - - /* output the header and increment the character position by - the header's length */ - this.position += outputHeader(writer); - - this.resources.setXObjects(xObjects); - - /* loop through the object numbers */ - for (int i=1; i <= this.objectcount; i++) { - - /* add the position of this object to the list of object - locations */ - this.location.addElement(new Integer(this.position)); - - /* retrieve the object with the current number */ - PDFObject object = (PDFObject)this.objects.elementAt(i-1); - - /* output the object and increment the character position - by the object's length */ - this.position += object.output(writer); - } - - /* output the xref table and increment the character position - by the table's length */ - this.position += outputXref(writer); - - /* output the trailer and flush the Writer */ - outputTrailer(writer); - writer.flush(); - } - - /** - * write the PDF header - * - * @param writer the PrintWriter to write the header to - * @return the number of characters written - */ - protected int outputHeader(PrintWriter writer) throws IOException { - String pdf = "%PDF-" + this.pdfVersion + "\n"; - writer.write(pdf); - return pdf.length(); - } - - /** - * write the trailer - * - * @param writer the PrintWriter to write the trailer to - */ - protected void outputTrailer(PrintWriter writer) throws IOException { - - /* construct the trailer */ - String pdf = "trailer\n<<\n/Size " + (this.objectcount+1) - + "\n/Root " + this.root.number + " " + this.root.generation - + " R\n/Info " + this.info.number + " " - + this.info.generation + " R\n>>\nstartxref\n" + this.xref - + "\n%%EOF\n"; - - /* write the trailer */ - writer.write(pdf); - } - - /** - * write the xref table - * - * @param writer the PrintWriter to write the xref table to - * @return the number of characters written - */ - private int outputXref(PrintWriter writer) throws IOException { - - /* remember position of xref table */ - this.xref = this.position; - - /* construct initial part of xref */ - StringBuffer pdf = new StringBuffer("xref\n0 " + (this.objectcount+1) - + "\n0000000000 65535 f \n"); - - /* loop through object numbers */ - for (int i=1; i < this.objectcount+1; i++) { - - /* contruct xref entry for object */ - String padding = "0000000000"; - String x = this.location.elementAt(i-1).toString(); - String loc = padding.substring(x.length()) + x; - - /* append to xref table */ - pdf = pdf.append(loc + " 00000 n \n"); - } - - /* write the xref table and return the character length */ - writer.write(pdf.toString()); - return pdf.length(); - } - } - diff --git a/src/org/apache/fop/pdf/PDFFont.java b/src/org/apache/fop/pdf/PDFFont.java index 562bddf2e..49a6c4791 100644 --- a/src/org/apache/fop/pdf/PDFFont.java +++ b/src/org/apache/fop/pdf/PDFFont.java @@ -50,135 +50,68 @@ */ package org.apache.fop.pdf; - - // Java - import java.io.IOException; - import java.io.PrintWriter; - - /** - * class representing a /Font object. - * - * A small object expressing the base font name and encoding of a - * Type 1 font along with an internal name for the font used within - * streams of content - */ - public class PDFFont extends PDFObject { - - /** the internal name for the font (eg "F1") */ - protected String fontname; - - /** the base font name (eg "Helvetica") */ - protected String basefont; - - /** the character encoding scheme used by the font (eg - "WinAnsiEncoding") */ - protected String encoding; - - /** - * create the /Font object - * - * @param the object's number - * @param fontname the internal name for the font - * @param basefont the base font name - * @param encoding the character encoding schema used by the font - */ - public PDFFont(int number, String fontname, String basefont, - String encoding) { - - /* generic creation of PDF object */ - super(number); - - /* set fields using paramaters */ - this.fontname = fontname; - this.basefont = basefont; - this.encoding = encoding; - } - - /** - * get the internal name used for this font - * - * @return the internal name - */ - public String getName() { - return this.fontname; - } - - /** - * produce the PDF representation for the object - * - * @return the PDF - */ - public String toPDF() { - String p = this.number + " " + this.generation - + " obj\n<< /Type /Font\n/Subtype /Type1\n/Name /" - + this.fontname + "\n/BaseFont /" + this.basefont - + "\n/Encoding /"+ this.encoding + " >>\nendobj\n"; - return p; - } - } - diff --git a/src/org/apache/fop/pdf/PDFInfo.java b/src/org/apache/fop/pdf/PDFInfo.java index e469546e1..89f8b3ec7 100644 --- a/src/org/apache/fop/pdf/PDFInfo.java +++ b/src/org/apache/fop/pdf/PDFInfo.java @@ -50,89 +50,45 @@ */ package org.apache.fop.pdf; - - // Java - import java.io.IOException; - import java.io.PrintWriter; - - /** - * class representing an /Info object - */ - public class PDFInfo extends PDFObject { - - /** the application producing the PDF */ - protected String producer; - - /** - * create an Info object - * - * @param number the object's number - */ - public PDFInfo(int number) { - super(number); - } - - /** - * set the producer string - * - * @param producer the producer string - */ - public void setProducer(String producer) { - this.producer = producer; - } - - /** - * produce the PDF representation of the object - * - * @return the PDF - */ - public String toPDF() { - String p = this.number + " " + this.generation - + " obj\n<< /Type /Info\n/Producer (" + this.producer - + ") >>\nendobj\n"; - return p; - } - } - diff --git a/src/org/apache/fop/pdf/PDFObject.java b/src/org/apache/fop/pdf/PDFObject.java index 9c283ec74..656377519 100644 --- a/src/org/apache/fop/pdf/PDFObject.java +++ b/src/org/apache/fop/pdf/PDFObject.java @@ -50,119 +50,60 @@ */ package org.apache.fop.pdf; - - // Java - import java.io.IOException; - import java.io.PrintWriter; - - /** - * generic PDF object. - * - * A PDF Document is essentially a collection of these objects. A PDF - * Object has a number and a generation (although the generation will always - * be 0 in new documents). - */ - public abstract class PDFObject { - - /** the object's number */ - protected int number; - - /** the object's generation (0 in new documents) */ - protected int generation = 0; - - /** - * create an empty object - * - * @param number the object's number - */ - public PDFObject(int number) { - this.number = number; - } - - /** - * write the PDF represention of this object - * - * @param writer the PrintWriter to write the PDF to - * @return the number of characters written - */ - protected int output(PrintWriter writer) throws IOException { - String pdf = this.toPDF(); - writer.write(pdf); - return pdf.length(); - } - - /** - * the PDF representation of a reference to this object - * - * @return the reference string - */ - protected String referencePDF() { - String p = this.number + " " + this.generation + " R"; - return p; - } - - /** - * represent object as PDF - * - * @return PDF string - */ - abstract String toPDF(); - } - diff --git a/src/org/apache/fop/pdf/PDFPage.java b/src/org/apache/fop/pdf/PDFPage.java index e96a2211c..9242da03e 100644 --- a/src/org/apache/fop/pdf/PDFPage.java +++ b/src/org/apache/fop/pdf/PDFPage.java @@ -50,157 +50,79 @@ */ package org.apache.fop.pdf; - - // Java - import java.io.PrintWriter; - import java.util.Vector; - - /** - * class representing a /Page object. - * - * There is one of these for every page in a PDF document. The object - * specifies the dimensions of the page and references a /Resources - * object, a contents stream and the page's parent in the page - * hierarchy. - */ - public class PDFPage extends PDFObject { - - /** the page's parent, a /Pages object */ - protected PDFPages parent; - - /** the page's /Resource object */ - protected PDFResources resources; - - /** the contents stream */ - protected PDFStream contents; - - /** the width of the page in points */ - protected int pagewidth; - - /** the height of the page in points */ - protected int pageheight; - - /** - * create a /Page object - * - * @param number the object's number - * @param resources the /Resources object - * @param contents the content stream - * @param pagewidth the page's width in points - * @param pageheight the page's height in points - */ - public PDFPage(int number, PDFResources resources, - PDFStream contents, int pagewidth, - int pageheight) { - - /* generic creation of object */ - super(number); - - /* set fields using parameters */ - this.resources = resources; - this.contents = contents; - this.pagewidth = pagewidth; - this.pageheight = pageheight; - } - - /** - * set this page's parent - * - * @param parent the /Pages object that is this page's parent - */ - public void setParent(PDFPages parent) { - this.parent = parent; - } - - /** - * represent this object as PDF - * - * @return the PDF string - */ - public String toPDF() { - String p = this.number + " " + this.generation - + " obj\n<< /Type /Page\n/Parent " - + this.parent.referencePDF() + "\n/MediaBox [ 0 0 " - + this.pagewidth + " " + this.pageheight + " ]\n/Resources " - + this.resources.referencePDF() + "\n/Contents " - + this.contents.referencePDF() + " >>\nendobj\n"; - return p; - } - } - diff --git a/src/org/apache/fop/pdf/PDFPages.java b/src/org/apache/fop/pdf/PDFPages.java index c4dcf1f4d..4e4b29c67 100644 --- a/src/org/apache/fop/pdf/PDFPages.java +++ b/src/org/apache/fop/pdf/PDFPages.java @@ -50,141 +50,71 @@ */ package org.apache.fop.pdf; - - // Java - import java.io.PrintWriter; - import java.util.Vector; - - /** - * class representing a /Pages object. - * - * A /Pages object is an ordered collection of pages (/Page objects) - * (Actually, /Pages can contain further /Pages as well but this - * implementation doesn't allow this) - */ - public class PDFPages extends PDFObject { - - /** the /Page objects */ - protected Vector kids = new Vector(); - - /** the number of /Page objects */ - protected int count = 0; - - // private PDFPages parent; - - /** - * create a /Pages object. - * - * @param number the object's number - */ - public PDFPages(int number) { - - /* generic creation of object */ - super(number); - } - - /** - * add a /Page object. - * - * @param page the PDFPage to add. - */ - public void addPage(PDFPage page) { - this.kids.addElement(page); - page.setParent(this); - } - - /** - * get the count of /Page objects - * - * @return the number of pages - */ - public int getCount() { - return this.count; - } - - /** - * represent the object in PDF - * - * @return the PDF string - */ - public String toPDF() { - StringBuffer p = new StringBuffer(this.number + " " - + this.generation - + " obj\n<< /Type /Pages\n/Count " - + this.getCount() + "\n/Kids ["); - for (int i = 0; i < kids.size(); i++) { - p = p.append(((PDFObject)kids.elementAt(i)).referencePDF() + " "); - } - p = p.append("] >>\nendobj\n"); - return p.toString(); - } - } - diff --git a/src/org/apache/fop/pdf/PDFResources.java b/src/org/apache/fop/pdf/PDFResources.java index 64b54dea7..32e39b068 100644 --- a/src/org/apache/fop/pdf/PDFResources.java +++ b/src/org/apache/fop/pdf/PDFResources.java @@ -50,167 +50,84 @@ */ package org.apache.fop.pdf; - - // Java - import java.io.PrintWriter; - import java.util.Enumeration; - import java.util.Vector; - import java.util.Hashtable; - - /** - * class representing a /Resources object. - * - * /Resources object contain a list of references to the fonts for the - * document - */ - public class PDFResources extends PDFObject { - - /** /Font objects keyed by their internal name */ - protected Hashtable fonts = new Hashtable(); - - protected Vector xObjects; - - /** - * create a /Resources object. - * - * @param number the object's number - */ - public PDFResources(int number) { - - /* generic creation of object */ - super(number); - } - - /** - * add font object to resources list. - * - * @param font the PDFFont to add - */ - public void addFont(PDFFont font) { - this.fonts.put(font.getName(),font); - } - - public void setXObjects(Vector xObjects) { - this.xObjects = xObjects; - } - - /** - * represent the object in PDF - * - * @return the PDF - */ - public String toPDF() { - StringBuffer p = new StringBuffer(this.number + " " - + this.generation - + " obj\n<< /Font << "); - - /* construct PDF dictionary of font object references */ - Enumeration fontEnumeration = fonts.keys(); - while (fontEnumeration.hasMoreElements()) { - String fontName = (String) fontEnumeration.nextElement(); - p = p.append("/" + fontName + " " - + ((PDFFont) fonts.get(fontName)).referencePDF() - + "\n"); - } - - p = p.append(">>\n/ProcSet [ /PDF /ImageC /Text ] "); - - if (!this.xObjects.isEmpty()) { - p = p.append("/XObject <<"); - for (int i = 1; i < this.xObjects.size(); i++) { - p = p.append("/Im" + i + " " + - ((PDFXObject) - this.xObjects.elementAt(i - - 1)).referencePDF() - + - " \n"); - } - } - - p = p.append(">>\nendobj\n"); - - return p.toString(); - } - } - diff --git a/src/org/apache/fop/pdf/PDFRoot.java b/src/org/apache/fop/pdf/PDFRoot.java index 67f5e45fb..a1f309a31 100644 --- a/src/org/apache/fop/pdf/PDFRoot.java +++ b/src/org/apache/fop/pdf/PDFRoot.java @@ -50,107 +50,54 @@ */ package org.apache.fop.pdf; - - // Java - import java.io.IOException; - import java.io.PrintWriter; - - /** - * class representing a Root (/Catalog) object - */ - public class PDFRoot extends PDFObject { - - /** the /Pages object that is root of the Pages hierarchy */ - protected PDFPages rootPages; - - /** - * create a Root (/Catalog) object - * - * @param number the object's number - */ - public PDFRoot(int number) { - super(number); - } - - /** - * add a /Page object to the root /Pages object - * - * @param page the /Page object to add - */ - public void addPage(PDFPage page) { - this.rootPages.addPage(page); - } - - /** - * set the root /Pages object - * - * @param pages the /Pages object to set as root - */ - public void setRootPages(PDFPages pages) { - this.rootPages = pages; - } - - /** - * represent the object as PDF - * - * @return the PDF string - */ - public String toPDF() { - String p = this.number + " " + this.generation - + " obj\n<< /Type /Catalog\n/Pages " - + this.rootPages.referencePDF() + " >>\nendobj\n"; - return p; - } - } - diff --git a/src/org/apache/fop/pdf/PDFStream.java b/src/org/apache/fop/pdf/PDFStream.java index a8d163a40..f1e1ca76f 100644 --- a/src/org/apache/fop/pdf/PDFStream.java +++ b/src/org/apache/fop/pdf/PDFStream.java @@ -50,155 +50,78 @@ */ package org.apache.fop.pdf; - - /** - * class representing a PDF stream. - * - * A derivative of the PDF Object, a PDF Stream has not only a dictionary - * but a stream of PDF commands. The stream of commands is where the real - * work is done, the dictionary just provides information like the stream - * length. - */ - public class PDFStream extends PDFObject { - - /** the stream of PDF commands */ - protected StringBuffer data = new StringBuffer(); - - /** - * create an empty stream object - * - * @param number the object's number - */ - public PDFStream(int number) { - super(number); - } - - /** - * append data to the stream - * - * @param s the string of PDF to add - */ - public void add(String s) { - this.data = this.data.append(s); - } - - /** - * append an array of xRGB pixels, ASCII Hex Encoding it first - * - * @param pixels the area of pixels - * @param width the width of the image in pixels - * @param height the height of the image in pixels - */ - public void addImageArray(int[] pixels, int width, int height) { - for (int i = 0; i < height; i++) { - for (int j = 0; j < width; j++) { - int p = pixels[i * width + j]; - int r = (p >> 16) & 0xFF; - int g = (p >> 8) & 0xFF; - int b = (p ) & 0xFF; - if (r < 16) { - this.data = this.data.append(0); - } - this.data = this.data.append(Integer.toHexString(r)); - if (g < 16) { - this.data = this.data.append(0); - } - this.data = this.data.append(Integer.toHexString(g)); - if (b < 16) { - this.data = this.data.append(0); - } - this.data = this.data.append(Integer.toHexString(b)); - this.data = this.data.append(" "); - } - } - this.data = this.data.append(">\n"); - } - - /** - * represent as PDF. - * - * @return the PDF string. - */ - public String toPDF() { - String p = this.number + " " + this.generation - + " obj\n<< /Length " + (this.data.length()+1) - + " >>\nstream\n" + this.data + "\nendstream\nendobj\n"; - return p; - } - } - diff --git a/src/org/apache/fop/pdf/PDFXObject.java b/src/org/apache/fop/pdf/PDFXObject.java index 279cb37a5..f915be811 100644 --- a/src/org/apache/fop/pdf/PDFXObject.java +++ b/src/org/apache/fop/pdf/PDFXObject.java @@ -50,201 +50,101 @@ */ /* modified by JKT to integrate with 0.12.0 */ - - package org.apache.fop.pdf; - - import java.io.IOException; - import java.io.PrintWriter; - - // shouldn't have to do this - import org.apache.fop.image.*; - - /** - * PDF XObject - * - * A derivative of the PDF Object, is a PDF Stream that has not only a - * dictionary but a stream of image data. - * the dictionary just provides information like the stream length - */ - public class PDFXObject extends PDFObject { - - FopImage fopimage; - int[] map; - int Xnum; - - - /** - * create an Xobject with the given number and name and load the - * image in the object - */ - public PDFXObject(int number,int Xnumber,FopImage img) { - super(number); - this.Xnum=Xnumber; - if (img == null) - System.err.println("FISH"); - this.map = img.getimagemap(); - fopimage=img; - } - - /** - * represent as PDF - */ - protected int output(PrintWriter writer) throws IOException { - int length=0; - int i=0; - int x,y; - int ncc=(fopimage.getcolor()? 3 : 1);//Number of Color Channels - int size=(fopimage.getpixelwidth())*(fopimage.getpixelheight()*ncc); - String p; - String pdf = this.toPDF(); - // push the pdf dictionary on the writer - writer.write(pdf); - length +=pdf.length(); - p = (size*2+1) + " >>\n"; - p = p + "stream\n"; - writer.write(p); - length +=p.length(); - // push all the image data on the writer and takes care of length for trailer - for (y=fopimage.getpixelheight()-1;y>=0;y--) - { - for (x=0;x<fopimage.getpixelwidth()*ncc;x++) - { - i=y*fopimage.getpixelwidth()*ncc+x; - if (this.map[i]<16) - { - writer.write("0"); - writer.write(Integer.toHexString(this.map[i])); - length++; - length++; - }else - { - writer.write(Integer.toHexString(this.map[i])); - length++; - length++; - } - } - } - // close the object - p = ">"; - p += "\nendstream\nendobj\n"; - writer.write(p); - length +=p.length(); - return length; - } - - String toPDF() { - String p = this.number + " " + this.generation + " obj\n"; - p = p + "<</Type /XObject\n"; - p = p + "/Subtype /Image\n"; - p = p + "/Name /Im"+Xnum+"\n"; - p = p + "/Width "+fopimage.getpixelwidth()+"\n"; - p = p + "/Height "+fopimage.getpixelheight()+"\n"; - p = p + "/BitsPerComponent 8\n"; - if (fopimage.getcolor()) - p = p + "/ColorSpace /DeviceRGB\n"; - else - p = p + "/ColorSpace /DeviceGray\n"; - p = p + "/Filter /ASCIIHexDecode\n"; - p = p + "/Length "; - return p; - } - } - diff --git a/src/org/apache/fop/render/Renderer.java b/src/org/apache/fop/render/Renderer.java index 30780169a..0f1ab587a 100644 --- a/src/org/apache/fop/render/Renderer.java +++ b/src/org/apache/fop/render/Renderer.java @@ -50,117 +50,59 @@ */ package org.apache.fop.render; - - // FOP - import org.apache.fop.svg.SVGArea; - import org.apache.fop.image.ImageArea; - import org.apache.fop.layout.*; - - // Java - import java.io.PrintWriter; - import java.io.IOException; - - /** - * interface implement by all renderers. - * - * a Renderer implementation takes areas/spaces and produces output in - * some format. - */ - public interface Renderer { - - /** set up the given FontInfo */ - public void setupFontInfo(FontInfo fontInfo); - - /** set the producer of the rendering */ - public void setProducer(String producer); - - /** render the given area tree to the given writer */ - public void render(AreaTree areaTree, PrintWriter writer) throws IOException; - - /** render the given area container */ - public void renderAreaContainer(AreaContainer area); - - /** render the given block area */ - public void renderBlockArea(BlockArea area); - - /** render the given display space */ - public void renderDisplaySpace(DisplaySpace space); - - /** render the given SVG area */ - public void renderSVGArea(SVGArea area); - - /** render the given image area */ - public void renderImageArea(ImageArea area); - - /** render the given inline area */ - public void renderInlineArea(InlineArea area); - - /** render the given inline space */ - public void renderInlineSpace(InlineSpace space); - - /** render the given line area */ - public void renderLineArea(LineArea area); - - /** render the given page */ - public void renderPage(Page page); - - /** render the given rule area */ - public void renderRuleArea(RuleArea area); - } - diff --git a/src/org/apache/fop/render/pdf/Font.java b/src/org/apache/fop/render/pdf/Font.java index 49a752703..5717a62ad 100644 --- a/src/org/apache/fop/render/pdf/Font.java +++ b/src/org/apache/fop/render/pdf/Font.java @@ -50,41 +50,21 @@ */ package org.apache.fop.render.pdf; - - // FOP - import org.apache.fop.layout.FontMetric; - - /** - * base class for PDF font classes - */ - public abstract class Font implements FontMetric { - - /** - * get the encoding of the font - */ - public abstract String encoding(); - - /** - * get the base font name - */ - public abstract String fontName(); - } - diff --git a/src/org/apache/fop/render/pdf/FontSetup.java b/src/org/apache/fop/render/pdf/FontSetup.java index d9750da30..d3228fa60 100644 --- a/src/org/apache/fop/render/pdf/FontSetup.java +++ b/src/org/apache/fop/render/pdf/FontSetup.java @@ -50,335 +50,168 @@ */ package org.apache.fop.render.pdf; - - // FOP - import org.apache.fop.render.pdf.fonts.*; - import org.apache.fop.layout.FontInfo; - import org.apache.fop.pdf.PDFDocument; - import org.apache.fop.pdf.PDFResources; - - // Java - import java.util.Enumeration; - import java.util.Hashtable; - - /** - * sets up the PDF fonts. - * - * Assigns the font (with metrics) to internal names like "F1" and - * assigns family-style-weight triplets to the fonts - */ - public class FontSetup { - - /** - * sets up the font info object. - * - * adds metrics for basic fonts and useful family-style-weight - * triplets for lookup - * - * @param fontInfo the font info object to set up - */ - public static void setup(FontInfo fontInfo) { - System.err.println("setting up fonts"); - - fontInfo.addMetrics("F1", new Helvetica()); - fontInfo.addMetrics("F2", new HelveticaOblique()); - fontInfo.addMetrics("F3", new HelveticaBold()); - fontInfo.addMetrics("F4", new HelveticaBoldOblique()); - fontInfo.addMetrics("F5", new TimesRoman()); - fontInfo.addMetrics("F6", new TimesItalic()); - fontInfo.addMetrics("F7", new TimesBold()); - fontInfo.addMetrics("F8", new TimesBoldItalic()); - fontInfo.addMetrics("F9", new Courier()); - fontInfo.addMetrics("F10", new CourierOblique()); - fontInfo.addMetrics("F11", new CourierBold()); - fontInfo.addMetrics("F12", new CourierBoldOblique()); - - /* any is treated as serif */ - fontInfo.addFontProperties("F5", "any", "normal", "normal"); - fontInfo.addFontProperties("F6", "any", "italic", "normal"); - fontInfo.addFontProperties("F6", "any", "oblique", "normal"); - fontInfo.addFontProperties("F7", "any", "normal", "bold"); - fontInfo.addFontProperties("F8", "any", "italic", "bold"); - fontInfo.addFontProperties("F8", "any", "oblique", "bold"); - - fontInfo.addFontProperties("F1", "sans-serif", "normal", - "normal"); - fontInfo.addFontProperties("F2", "sans-serif", "oblique", - "normal"); - fontInfo.addFontProperties("F2", "sans-serif", "italic", - "normal"); - fontInfo.addFontProperties("F3", "sans-serif", "normal", - "bold"); - fontInfo.addFontProperties("F4", "sans-serif", "oblique", - "bold"); - fontInfo.addFontProperties("F4", "sans-serif", "italic", - "bold"); - fontInfo.addFontProperties("F5", "serif", "normal", "normal"); - fontInfo.addFontProperties("F6", "serif", "oblique", - "normal"); - fontInfo.addFontProperties("F6", "serif", "italic", "normal"); - fontInfo.addFontProperties("F7", "serif", "normal", "bold"); - fontInfo.addFontProperties("F8", "serif", "oblique", "bold"); - fontInfo.addFontProperties("F8", "serif", "italic", "bold"); - fontInfo.addFontProperties("F9", "monospace", "normal", - "normal"); - fontInfo.addFontProperties("F10", "monospace", "oblique", - "normal"); - fontInfo.addFontProperties("F10", "monospace", "italic", - "normal"); - fontInfo.addFontProperties("F11", "monospace", "normal", - "bold"); - fontInfo.addFontProperties("F12", "monospace", "oblique", - "bold"); - fontInfo.addFontProperties("F12", "monospace", "italic", - "bold"); - - fontInfo.addFontProperties("F1", "Helvetica", "normal", - "normal"); - fontInfo.addFontProperties("F2", "Helvetica", "oblique", - "normal"); - fontInfo.addFontProperties("F2", "Helvetica", "italic", - "normal"); - fontInfo.addFontProperties("F3", "Helvetica", "normal", - "bold"); - fontInfo.addFontProperties("F4", "Helvetica", "oblique", - "bold"); - fontInfo.addFontProperties("F4", "Helvetica", "italic", - "bold"); - fontInfo.addFontProperties("F5", "Times", "normal", "normal"); - fontInfo.addFontProperties("F6", "Times", "oblique", - "normal"); - fontInfo.addFontProperties("F6", "Times", "italic", "normal"); - fontInfo.addFontProperties("F7", "Times", "normal", "bold"); - fontInfo.addFontProperties("F8", "Times", "oblique", "bold"); - fontInfo.addFontProperties("F8", "Times", "italic", "bold"); - fontInfo.addFontProperties("F9", "Courier", "normal", - "normal"); - fontInfo.addFontProperties("F10", "Courier", "oblique", - "normal"); - fontInfo.addFontProperties("F10", "Courier", "italic", - "normal"); - fontInfo.addFontProperties("F11", "Courier", "normal", - "bold"); - fontInfo.addFontProperties("F12", "Courier", "oblique", - "bold"); - fontInfo.addFontProperties("F12", "Courier", "italic", - "bold"); - - /* for compatibility with PassiveTex */ - fontInfo.addFontProperties("F5", "Times-Roman", "normal", - "normal"); - fontInfo.addFontProperties("F6", "Times-Roman", "oblique", - "normal"); - fontInfo.addFontProperties("F6", "Times-Roman", "italic", - "normal"); - fontInfo.addFontProperties("F7", "Times-Roman", "normal", - "bold"); - fontInfo.addFontProperties("F8", "Times-Roman", "oblique", - "bold"); - fontInfo.addFontProperties("F8", "Times-Roman", "italic", - "bold"); - fontInfo.addFontProperties("F5", "Times Roman", "normal", - "normal"); - fontInfo.addFontProperties("F6", "Times Roman", "oblique", - "normal"); - fontInfo.addFontProperties("F6", "Times Roman", "italic", - "normal"); - fontInfo.addFontProperties("F7", "Times Roman", "normal", - "bold"); - fontInfo.addFontProperties("F8", "Times Roman", "oblique", - "bold"); - fontInfo.addFontProperties("F8", "Times Roman", "italic", - "bold"); - fontInfo.addFontProperties("F9", "Computer-Modern-Typewriter", - "normal", "normal"); - } - - /** - * add the fonts in the font info to the PDF document - * - * @param doc PDF document to add fonts to - * @param fontInfo font info object to get font information from - */ - public static void addToResources(PDFDocument doc, FontInfo fontInfo) { - Hashtable fonts = fontInfo.getFonts(); - Enumeration e = fonts.keys(); - PDFResources resources = doc.getResources(); - while (e.hasMoreElements()) { - String f = (String) e.nextElement(); - resources.addFont(doc.makeFont(f, - ((Font) - fonts.get(f)).fontName(), - ((Font) - fonts.get(f)).encoding() - ) - ); - } - } - } - diff --git a/src/org/apache/fop/render/pdf/PDFRenderer.java b/src/org/apache/fop/render/pdf/PDFRenderer.java index 32498cfd8..b6976fba3 100644 --- a/src/org/apache/fop/render/pdf/PDFRenderer.java +++ b/src/org/apache/fop/render/pdf/PDFRenderer.java @@ -50,853 +50,427 @@ */ package org.apache.fop.render.pdf; - - // FOP - import org.apache.fop.render.Renderer; - import org.apache.fop.image.ImageArea; - import org.apache.fop.image.FopImage; - import org.apache.fop.layout.*; - import org.apache.fop.svg.*; - import org.apache.fop.pdf.*; - - // Java - import java.io.IOException; - import java.io.PrintWriter; - import java.util.Enumeration; - - /** - * Renderer that renders areas to PDF - */ - public class PDFRenderer implements Renderer { - - /** the PDF Document being created */ - protected PDFDocument pdfDoc; - - /** the /Resources object of the PDF document being created */ - protected PDFResources pdfResources; - - /** the current stream to add PDF commands to */ - PDFStream currentStream; - - /** the current (internal) font name */ - protected String currentFontName; - - /** the current font size in millipoints */ - protected int currentFontSize; - - /** the current colour's red component */ - protected float currentRed = 0; - - /** the current colour's green component */ - protected float currentGreen = 0; - - /** the current colour's blue component */ - protected float currentBlue = 0; - - /** the current vertical position in millipoints from bottom */ - protected int currentYPosition = 0; - - /** the current horizontal position in millipoints from left */ - protected int currentXPosition = 0; - - /** the horizontal position of the current area container */ - private int currentAreaContainerXPosition = 0; - - /** - * create the PDF renderer - */ - public PDFRenderer() { - this.pdfDoc = new PDFDocument(); - } - - /** - * set the PDF document's producer - * - * @param producer string indicating application producing PDF - */ - public void setProducer(String producer) { - this.pdfDoc.setProducer(producer); - } - - /** - * render the areas into PDF - * - * @param areaTree the laid-out area tree - * @param writer the PrintWriter to write the PDF with - */ - public void render(AreaTree areaTree, PrintWriter writer) throws IOException { - System.err.println("rendering areas to PDF"); - this.pdfResources = this.pdfDoc.getResources(); - Enumeration e = areaTree.getPages().elements(); - while (e.hasMoreElements()) { - this.renderPage((Page) e.nextElement()); - } - System.err.println("writing out PDF"); - this.pdfDoc.output(writer); - } - - /** - * add a line to the current stream - * - * @param x1 the start x location in millipoints - * @param y1 the start y location in millipoints - * @param x2 the end x location in millipoints - * @param y2 the end y location in millipoints - * @param th the thickness in millipoints - * @param r the red component - * @param g the green component - * @param b the blue component - */ - protected void addLine(int x1, int y1, int x2, int y2, int th, - float r, float g, float b) { - currentStream.add(r + " " + g + " " + b + " RG\n" - + (x1/1000f) + " " + (y1/1000f) + " m " - + (x2/1000f) + " " + (y2/1000f) + " l " - + (th/1000f) + " w S\n" - + "0 0 0 RG\n"); - } - - /** - * add a rectangle to the current stream - * - * @param x the x position of left edge in millipoints - * @param y the y position of top edge in millipoints - * @param w the width in millipoints - * @param h the height in millipoints - * @param r the red component - * @param g the green component - * @param b the blue component - */ - protected void addRect(int x, int y, int w, int h, - float r, float g, float b) { - currentStream.add(r + " " + g + " " + b + " RG\n" - + (x/1000f) + " " + (y/1000f) + " " - + (w/1000f) + " " + (h/1000f) + " re S\n" - + "0 0 0 RG\n"); - } - - /** - * add a filled rectangle to the current stream - * - * @param x the x position of left edge in millipoints - * @param y the y position of top edge in millipoints - * @param w the width in millipoints - * @param h the height in millipoints - * @param r the red component of edges - * @param g the green component of edges - * @param b the blue component of edges - * @param fr the red component of the fill - * @param fg the green component of the fill - * @param fb the blue component of the fill - */ - protected void addRect(int x, int y, int w, int h, - float r, float g, float b, - float fr, float fg, float fb) { - currentStream.add(fr + " " + fg + " " + fb + " rg\n" - + r + " " + g + " " + b + " RG\n" - + (x/1000f) + " " + (y/1000f) + " " - + (w/1000f) + " " + (h/1000f) + " re S\n" - + (x/1000f) + " " + (y/1000f) + " " - + (w/1000f) + " " + (h/1000f) + " re f\n" - + "0 0 0 RG 0 0 0 rg\n"); - } - - /** - * render area container to PDF - * - * @param area the area container to render - */ - public void renderAreaContainer(AreaContainer area) { - - /* move into position */ - currentStream.add("1 0 0 1 " - + (area.getXPosition()/1000f) + " " - + (area.getYPosition()/1000f) + " Tm\n"); - - this.currentYPosition = area.getYPosition(); - this.currentAreaContainerXPosition = area.getXPosition(); - - Enumeration e = area.getChildren().elements(); - while (e.hasMoreElements()) { - Box b = (Box) e.nextElement(); - b.render(this); - } - } - - /** - * render block area to PDF - * - * @param area the block area to render - */ - public void renderBlockArea(BlockArea area) { - int rx = this.currentAreaContainerXPosition - + area.getStartIndent(); - int ry = this.currentYPosition; - int w = area.getContentWidth(); - int h = area.getHeight(); - Enumeration e = area.getChildren().elements(); - while (e.hasMoreElements()) { - Box b = (Box) e.nextElement(); - b.render(this); - } - } - - /** - * render display space to PDF - * - * @param space the display space to render - */ - public void renderDisplaySpace(DisplaySpace space) { - int d = space.getSize(); - this.currentYPosition -= d; - } - - /** - * render image area to PDF - * - * @param area the image area to render - */ - public void renderImageArea(ImageArea area) { - // adapted from contribution by BoBoGi - int x = this.currentAreaContainerXPosition + - area.getXOffset(); - int y = this.currentYPosition; - int w = area.getContentWidth(); - int h = area.getHeight(); - - this.currentYPosition -= h*1000; - - FopImage img = area.getImage(); - - int xObjectNum = this.pdfDoc.addImage(img); - - currentStream.add("ET\nq\n" + (img.getWidth()/1000f) + " 0 0 " + - (img.getHeight()/1000f) + " " + - ((x + img.getX())/1000f) + " " + - (((y - h) - img.getY())/1000f) + " cm\n" + - "/Im" + xObjectNum + " Do\nQ\nBT\n"); - } - - /** - * render SVG area to PDF - * - * @param area the SVG area to render - */ - public void renderSVGArea(SVGArea area) { - int x = this.currentAreaContainerXPosition; - int y = this.currentYPosition; - int w = area.getContentWidth(); - int h = area.getHeight(); - this.currentYPosition -= h; - Enumeration e = area.getChildren().elements(); - while (e.hasMoreElements()) { - Object o = e.nextElement(); - if (o instanceof RectGraphic) { - int rx = ((RectGraphic)o).x; - int ry = ((RectGraphic)o).y; - int rw = ((RectGraphic)o).width; - int rh = ((RectGraphic)o).height; - addRect(x+rx,y-ry,rw,-rh,0,0,0); - } else if (o instanceof LineGraphic) { - int x1 = ((LineGraphic)o).x1; - int y1 = ((LineGraphic)o).y1; - int x2 = ((LineGraphic)o).x2; - int y2 = ((LineGraphic)o).y2; - addLine(x+x1,y-y1,x+x2,y-y2,0,0,0,0); - } else if (o instanceof TextGraphic) { - int tx = ((TextGraphic)o).x; - int ty = ((TextGraphic)o).y; - String s = ((TextGraphic)o).s; - currentStream.add("1 0 0 1 " - + ((x+tx)/1000f) + " " - + ((y-ty)/1000f) + " Tm " - + "(" + s + ") Tj\n"); - } - } - } - - /** - * render inline area to PDF - * - * @param area inline area to render - */ - public void renderInlineArea(InlineArea area) { - char ch; - StringBuffer pdf = new StringBuffer(); - - String name = area.getFontState().getFontName(); - int size = area.getFontState().getFontSize(); - - float red = area.getRed(); - float green = area.getGreen(); - float blue = area.getBlue(); - - if ((!name.equals(this.currentFontName)) - || (size != this.currentFontSize)) { - this.currentFontName = name; - this.currentFontSize = size; - pdf = pdf.append("/" + name + " " + (size/1000) + " Tf\n"); - } - - if ((red != this.currentRed) - || (green != this.currentGreen) - || (blue != this.currentBlue)) { - this.currentRed = red; - this.currentGreen = green; - this.currentBlue = blue; - pdf = pdf.append(red + " " + green + " " + blue + " rg\n"); - } - - int rx = this.currentXPosition; - int bl = this.currentYPosition; - - pdf = pdf.append("1 0 0 1 " - +(rx/1000f) + " " + (bl/1000f) - + " Tm ("); - - String s = area.getText(); - int l = s.length(); - - for (int i=0; i < l; i++) { - ch = s.charAt(i); - if (ch > 127) { - pdf = pdf.append("\\"); - pdf = pdf.append(Integer.toOctalString((int)ch)); - } else { - switch (ch) { - case '(' : pdf = pdf.append("\\("); break; - case ')' : pdf = pdf.append("\\)"); break; - case '\\' : pdf = pdf.append("\\\\"); break; - default : pdf = pdf.append(ch); break; - } - } - } - pdf = pdf.append(") Tj\n"); - - currentStream.add(pdf.toString()); - - this.currentXPosition += area.getContentWidth(); - } - - /** - * render inline space to PDF - * - * @param space space to render - */ - public void renderInlineSpace(InlineSpace space) { - this.currentXPosition += space.getSize(); - } - - /** - * render line area to PDF - * - * @param area area to render - */ - public void renderLineArea(LineArea area) { - int rx = this.currentAreaContainerXPosition - + area.getStartIndent(); - int ry = this.currentYPosition; - int w = area.getContentWidth(); - int h = area.getHeight(); - - this.currentYPosition -= area.getPlacementOffset(); - this.currentXPosition = rx; - - int bl = this.currentYPosition; - - Enumeration e = area.getChildren().elements(); - while (e.hasMoreElements()) { - Box b = (Box) e.nextElement(); - b.render(this); - } - - this.currentYPosition = ry-h; - } - - /** - * render page into PDF - * - * @param page page to render - */ - public void renderPage(Page page) { - AreaContainer body, before, after; - - currentStream = this.pdfDoc.makeStream(); - body = page.getBody(); - before = page.getBefore(); - after = page.getAfter(); - - this.currentFontName = ""; - this.currentFontSize = 0; - - currentStream.add("BT\n"); - renderAreaContainer(body); - - if (before != null) { - renderAreaContainer(before); - } - - if (after != null) { - renderAreaContainer(after); - } - - currentStream.add("ET\n"); - - this.pdfDoc.makePage(this.pdfResources, currentStream, - page.getWidth()/1000, page.getHeight()/1000); - } - - /** - * render rule area into PDF - * - * @param area area to render - */ - public void renderRuleArea(RuleArea area) { - int rx = this.currentAreaContainerXPosition - + area.getStartIndent(); - int ry = this.currentYPosition; - int w = area.getContentWidth(); - int h = area.getHeight(); - int th = area.getRuleThickness(); - float r = area.getRed(); - float g = area.getGreen(); - float b = area.getBlue(); - - addLine(rx, ry, rx+w, ry, th, r, g, b); - } - - /** - * set up the font info - * - * @param fontInfo font info to set up - */ - public void setupFontInfo(FontInfo fontInfo) { - FontSetup.setup(fontInfo); - FontSetup.addToResources(this.pdfDoc, fontInfo); - } - } - diff --git a/src/org/apache/fop/render/xml/XMLRenderer.java b/src/org/apache/fop/render/xml/XMLRenderer.java index 2cfcee908..9bc8fa702 100644 --- a/src/org/apache/fop/render/xml/XMLRenderer.java +++ b/src/org/apache/fop/render/xml/XMLRenderer.java @@ -50,553 +50,277 @@ */ package org.apache.fop.render.xml; - - // FOP - import org.apache.fop.svg.*; - import org.apache.fop.render.Renderer; - import org.apache.fop.image.ImageArea; - import org.apache.fop.layout.*; - import org.apache.fop.pdf.*; - - // Java - import java.io.IOException; - import java.io.PrintWriter; - import java.util.Enumeration; - - /** - * Renderer that renders areas to XML for debugging purposes. - */ - public class XMLRenderer implements Renderer { - - /** indentation to use for pretty-printing the XML */ - protected int indent = 0; - - /** the application producing the XML */ - protected String producer; - - /** the writer used to output the XML */ - protected PrintWriter writer; - - /** - * set the document's producer - * - * @param producer string indicating application producing the XML - */ - public void setProducer(String producer) { - this.producer = producer; - } - - /** - * render the areas into XML - * - * @param areaTree the laid-out area tree - * @param writer the PrintWriter to give the XML to - */ - public void render(AreaTree areaTree, PrintWriter writer) - throws IOException { - System.err.println("rendering areas to XML"); - this.writer = writer; - this.writer.write("<?xml version=\"1.0\"?>\n<!-- produced by " - + this.producer + " -->\n"); - writeStartTag("<AreaTree>"); - Enumeration e = areaTree.getPages().elements(); - while (e.hasMoreElements()) { - this.renderPage((Page) e.nextElement()); - } - writeEndTag("</AreaTree>"); - this.writer.flush(); - System.err.println("written out XML"); - } - - /** - * write out spaces to make indent - */ - protected void writeIndent() { - StringBuffer s = new StringBuffer(); - for (int i= 0; i<this.indent; i++) { - s = s.append(" "); - } - this.writer.write(s.toString()); - } - - /** - * write out an element - * - * @param element the full text of the element including tags - */ - protected void writeElement(String element) { - writeIndent(); - this.writer.write(element+"\n"); - } - - /** - * write out an empty-element-tag - * - * @param tag the text of the tag - */ - protected void writeEmptyElementTag(String tag) { - writeIndent(); - this.writer.write(tag + "\n"); - } - - /** - * write out an end tag - * - * @param tag the text of the tag - */ - protected void writeEndTag(String tag) { - this.indent--; - writeIndent(); - this.writer.write(tag + "\n"); - } - - /** - * write out a start tag - * - * @param tag the text of the tag - */ - protected void writeStartTag(String tag) { - writeIndent(); - this.writer.write(tag + "\n"); - this.indent++; - } - - /** - * set up the font info - * - * @param fontInfo the font info object to set up - */ - public void setupFontInfo(FontInfo fontInfo) { - - /* use PDF's font setup to get PDF metrics */ - org.apache.fop.render.pdf.FontSetup.setup(fontInfo); - } - - /** - * render an area container to XML - * - * @param area the area container to render - */ - public void renderAreaContainer(AreaContainer area) { - writeStartTag("<AreaContainer>"); - Enumeration e = area.getChildren().elements(); - while (e.hasMoreElements()) { - Box b = (Box) e.nextElement(); - b.render(this); - } - writeEndTag("</AreaContainer>"); - } - - /** - * render a block area to XML - * - * @param area the block area to render - */ - public void renderBlockArea(BlockArea area) { - writeStartTag("<BlockArea start-indent=\"" - + area.getStartIndent() - + "\" end-indent=\"" - + area.getEndIndent() + "\">"); - Enumeration e = area.getChildren().elements(); - while (e.hasMoreElements()) { - Box b = (Box) e.nextElement(); - b.render(this); - } - writeEndTag("</BlockArea>"); - } - - /** - * render a display space to XML - * - * @param space the space to render - */ - public void renderDisplaySpace(DisplaySpace space) { - writeEmptyElementTag("<DisplaySpace size=\"" - + space.getSize() +"\"/>"); - } - - /** - * render an SVG area to XML - * - * @param area the area to render - */ - public void renderSVGArea(SVGArea area) { - writeEmptyElementTag("<SVG/>"); - } - - /** - * render an image area to XML - * - * @param area the area to render - */ - public void renderImageArea(ImageArea area) { - writeEmptyElementTag("<ImageArea/>"); - } - - /** - * render an inline area to XML - * - * @param area the area to render - */ - public void renderInlineArea(InlineArea area) { - String fontWeight = area.getFontState().getFontWeight(); - StringBuffer sb = new StringBuffer(); - String s = area.getText(); - int l = s.length(); - for (int i=0; i < l; i++) { - char ch = s.charAt(i); - if (ch>127) - sb = sb.append("&#"+(int)ch+";"); - else - sb = sb.append(ch); - } - writeElement("<InlineArea font-weight=\"" - + fontWeight + "\" red=\"" - + area.getRed() + "\" green=\"" - + area.getGreen() + "\" blue = \"" - + area.getBlue() + " width = \"" - + area.getContentWidth() + "\">" + sb.toString() - + "</InlineArea>"); - } - - /** - * render an inline space to XML - * - * @param space the space to render - */ - public void renderInlineSpace(InlineSpace space) { - writeEmptyElementTag("<InlineSpace size=\"" - + space.getSize() +"\"/>"); - } - - /** - * render a line area to XML - * - * @param area the area to render - */ - public void renderLineArea(LineArea area) { - String fontWeight = area.getFontState().getFontWeight(); - writeStartTag("<LineArea font-weight=\"" - + fontWeight + "\">"); - Enumeration e = area.getChildren().elements(); - while (e.hasMoreElements()) { - Box b = (Box)e.nextElement(); - b.render(this); - } - writeEndTag("</LineArea>"); - } - - /** - * render a page to XML - * - * @param page the page to render - */ - public void renderPage(Page page) { - AreaContainer body, before, after; - writeStartTag("<Page>"); - body = page.getBody(); - before = page.getBefore(); - after = page.getAfter(); - if (before != null) { - renderAreaContainer(before); - } - renderAreaContainer(body); - if (after != null) { - renderAreaContainer(after); - } - writeEndTag("</Page>"); - } - - /** - * render a rule area to XML - * - * @param area the area to render - */ - public void renderRuleArea(RuleArea area) { - writeEmptyElementTag("<Rule start-indent=\"" - + area.getStartIndent() - + "\" end-indent=\"" - + area.getEndIndent() - + "\" rule-thickness=\"" - + area.getRuleThickness() - + "\" red=\"" + area.getRed() - + "\" green=\"" + area.getGreen() - + "\" blue = \"" + area.getBlue() - + "\"/>"); - } - } - diff --git a/src/org/apache/fop/svg/Graphic.java b/src/org/apache/fop/svg/Graphic.java index 28fa409ff..cd223a417 100644 --- a/src/org/apache/fop/svg/Graphic.java +++ b/src/org/apache/fop/svg/Graphic.java @@ -50,17 +50,9 @@ */ package org.apache.fop.svg; - - /** - * base class for SVG graphic objects. - * - * Graphic objects include rectangles, lines and text - */ - public abstract class Graphic {} - diff --git a/src/org/apache/fop/svg/Line.java b/src/org/apache/fop/svg/Line.java index d2a6c191f..27d8f76f8 100644 --- a/src/org/apache/fop/svg/Line.java +++ b/src/org/apache/fop/svg/Line.java @@ -50,163 +50,82 @@ */ package org.apache.fop.svg; - - // FOP - import org.apache.fop.fo.*; - import org.apache.fop.fo.properties.*; - import org.apache.fop.layout.Area; - import org.apache.fop.layout.FontState; - import org.apache.fop.apps.FOPException; - - /** - * class representing svg:line pseudo flow object. - */ - public class Line extends FObj { - - /** - * inner class for making Line objects. - */ - public static class Maker extends FObj.Maker { - - /** - * make a Line object. - * - * @param parent the parent formatting object - * @param propertyList the explicit properties of this object - * - * @return the Line object - */ - public FObj make(FObj parent, PropertyList propertyList) - throws FOPException { - return new Line(parent, propertyList); - } - } - - /** - * returns the maker for this object. - * - * @return the maker for Line objects - */ - public static FObj.Maker maker() { - return new Line.Maker(); - } - - /** - * constructs a Line object (called by Maker). - * - * @param parent the parent formatting object - * @param propertyList the explicit properties of this object - */ - protected Line(FObj parent, PropertyList propertyList) { - super(parent, propertyList); - this.name = "svg:line"; - } - - /** - * layout this formatting object. - * - * @param area the area to layout the object into - * - * @return the status of the layout - */ - public int layout(Area area) throws FOPException { - - /* retrieve properties */ - int x1 = this.properties.get("x1").getLength().mvalue(); - int x2 = this.properties.get("x2").getLength().mvalue(); - int y1 = this.properties.get("y1").getLength().mvalue(); - int y2 = this.properties.get("y2").getLength().mvalue(); - - /* if the area this is being put into is an SVGArea */ - if (area instanceof SVGArea) { - /* add a line to the SVGArea */ - ((SVGArea) area).addGraphic(new LineGraphic(x1, y1, x2, y2)); - } else { - /* otherwise generate a warning */ - System.err.println("WARNING: svg:line outside svg:svg"); - } - - /* return status */ - return OK; - } - } - diff --git a/src/org/apache/fop/svg/LineGraphic.java b/src/org/apache/fop/svg/LineGraphic.java index 6e9dd52eb..59ed032d7 100644 --- a/src/org/apache/fop/svg/LineGraphic.java +++ b/src/org/apache/fop/svg/LineGraphic.java @@ -50,69 +50,35 @@ */ package org.apache.fop.svg; - - /** - * class representing a line in an SVG Area - */ - public class LineGraphic extends Graphic { - - /** x-coordinate of start */ - public int x1; - - /** y-coordinate of start */ - public int y1; - - /** x-coordinate of end */ - public int x2; - - /** y-coordinate of end */ - public int y2; - - /** - * construct a line graphic - * - * @param x1 x-coordinate of start - * @param y1 y-coordinate of start - * @param x2 x-coordinate of end - * @param y2 y-coordinate of end - */ - public LineGraphic(int x1, int y1, int x2, int y2) { - this.x1 = x1; - this.y1 = y1; - this.x2 = x2; - this.y2 = y2; - } - } - diff --git a/src/org/apache/fop/svg/Rect.java b/src/org/apache/fop/svg/Rect.java index ac2e58e41..722b87e28 100644 --- a/src/org/apache/fop/svg/Rect.java +++ b/src/org/apache/fop/svg/Rect.java @@ -50,163 +50,82 @@ */ package org.apache.fop.svg; - - // FOP - import org.apache.fop.fo.*; - import org.apache.fop.fo.properties.*; - import org.apache.fop.layout.Area; - import org.apache.fop.layout.FontState; - import org.apache.fop.apps.FOPException; - - /** - * class representing svg:rect pseudo flow object. - */ - public class Rect extends FObj { - - /** - * inner class for making Rect objects. - */ - public static class Maker extends FObj.Maker { - - /** - * make a Rect object. - * - * @param parent the parent formatting object - * @param propertyList the explicit properties of this object - * - * @return the Rect object - */ - public FObj make(FObj parent, PropertyList propertyList) - throws FOPException { - return new Rect(parent, propertyList); - } - } - - /** - * returns the maker for this object. - * - * @return the maker for Rect objects - */ - public static FObj.Maker maker() { - return new Rect.Maker(); - } - - /** - * constructs a Rect object (called by Maker). - * - * @param parent the parent formatting object - * @param propertyList the explicit properties of this object - */ - protected Rect(FObj parent, PropertyList propertyList) { - super(parent, propertyList); - this.name = "svg:rect"; - } - - /** - * layout this formatting object. - * - * @param area the area to layout the object into - * - * @return the status of the layout - */ - public int layout(Area area) throws FOPException { - - /* retrieve properties */ - int width = this.properties.get("width").getLength().mvalue(); - int height = this.properties.get("height").getLength().mvalue(); - int x = this.properties.get("x").getLength().mvalue(); - int y = this.properties.get("y").getLength().mvalue(); - - /* if the area this is being put into is an SVGArea */ - if (area instanceof SVGArea) { - /* add a rectangle to the SVGArea */ - ((SVGArea) area).addGraphic(new RectGraphic(x, y, width, height)); - } else { - /* otherwise generate a warning */ - System.err.println("WARNING: svg:rect outside svg:svg"); - } - - /* return status */ - return OK; - } - } - diff --git a/src/org/apache/fop/svg/RectGraphic.java b/src/org/apache/fop/svg/RectGraphic.java index 0f6106d85..72b3fc740 100644 --- a/src/org/apache/fop/svg/RectGraphic.java +++ b/src/org/apache/fop/svg/RectGraphic.java @@ -50,69 +50,35 @@ */ package org.apache.fop.svg; - - /** - * class representing a rectangle in an SVG Area - */ - public class RectGraphic extends Graphic { - - /** x-coordinate of corner */ - public int x; - - /** y-coordinate of corner */ - public int y; - - /** width of rectangle */ - public int width; - - /** height of rectangle */ - public int height; - - /** - * construct a rectangle graphic. - * - * @param x x-coordinate of corner - * @param y y-coordinate of corner - * @param width width of rectangle - * @param height height of rectangle - */ - public RectGraphic(int x, int y, int width, int height) { - this.x = x; - this.y = y; - this.width = width; - this.height = height; - } - } - diff --git a/src/org/apache/fop/svg/SVG.java b/src/org/apache/fop/svg/SVG.java index 61596262d..27042e2b3 100644 --- a/src/org/apache/fop/svg/SVG.java +++ b/src/org/apache/fop/svg/SVG.java @@ -50,353 +50,177 @@ */ package org.apache.fop.svg; - - // FOP - import org.apache.fop.fo.*; - import org.apache.fop.fo.properties.*; - import org.apache.fop.layout.Area; - import org.apache.fop.layout.BlockArea; - import org.apache.fop.layout.FontState; - import org.apache.fop.apps.FOPException; - - /** - * class representing svg:svg pseudo flow object. - */ - public class SVG extends FObj { - - /** - * inner class for making SVG objects. - */ - public static class Maker extends FObj.Maker { - - /** - * make an SVG object. - * - * @param parent the parent formatting object - * @param propertyList the explicit properties of this object - * - * @return the SVG object - */ - public FObj make(FObj parent, PropertyList propertyList) - throws FOPException { - return new SVG(parent, propertyList); - } - } - - /** - * returns the maker for this object. - * - * @return the maker for SVG objects - */ - public static FObj.Maker maker() { - return new SVG.Maker(); - } - - FontState fs; - int breakBefore; - int breakAfter; - int width; - int height; - int spaceBefore; - int spaceAfter; - - /** - * constructs an SVG object (called by Maker). - * - * @param parent the parent formatting object - * @param propertyList the explicit properties of this object - */ - public SVG(FObj parent, PropertyList propertyList) { - super(parent, propertyList); - this.name = "svg:svg"; - } - - /** - * layout this formatting object. - * - * @param area the area to layout the object into - * - * @return the status of the layout - */ - public int layout(Area area) throws FOPException { - - if (this.marker == BREAK_AFTER) { - return OK; - } - - if (this.marker == START) { - /* retrieve properties */ - String fontFamily = this.properties.get("font-family").getString(); - String fontStyle = this.properties.get("font-style").getString(); - String fontWeight = this.properties.get("font-weight").getString(); - int fontSize = this.properties.get("font-size").getLength().mvalue(); - - this.fs = new FontState(area.getFontInfo(), fontFamily, - fontStyle, fontWeight, fontSize); - - this.breakBefore = this.properties.get("break-before").getEnum(); - this.breakAfter = this.properties.get("break-after").getEnum(); - this.width = this.properties.get("width").getLength().mvalue(); - this.height = this.properties.get("height").getLength().mvalue(); - - this.spaceBefore = - this.properties.get("space-before.optimum").getLength().mvalue(); - this.spaceAfter = - this.properties.get("space-after.optimum").getLength().mvalue(); - /* if the SVG is embedded in a block area */ - if (area instanceof BlockArea) { - /* temporarily end the block area */ - area.end(); - } - - this.marker = 0; - - if (breakBefore == BreakBefore.PAGE) { - return FORCE_PAGE_BREAK; - } - - if (breakBefore == BreakBefore.ODD_PAGE) { - return FORCE_PAGE_BREAK_ODD; - } - - if (breakBefore == BreakBefore.EVEN_PAGE) { - return FORCE_PAGE_BREAK_EVEN; - } - } - - /* if there is a space-before */ - if (spaceBefore != 0) { - /* add a display space */ - area.addDisplaySpace(spaceBefore); - } - - /* create an SVG area */ - SVGArea svgArea = new SVGArea(fs, width, height); - svgArea.start(); - - /* add the SVG area to the containing area */ - area.addChild(svgArea); - - /* iterate over the child formatting objects and lay them out - into the SVG area */ - int numChildren = this.children.size(); - for (int i = 0; i < numChildren; i++) { - FONode fo = (FONode) children.elementAt(i); - int status; - if ((status = fo.layout(svgArea)) != OK) { - return status; - } - } - - /* finish off the SVG area */ - svgArea.end(); - - /* increase the height of the containing area accordingly */ - area.increaseHeight(svgArea.getHeight()); - - /* if there is a space-after */ - if (spaceAfter != 0) { - /* add a display space */ - area.addDisplaySpace(spaceAfter); - } - - /* if the SVG is embedded in a block area */ - if (area instanceof BlockArea) { - /* re-start the block area */ - area.start(); - } - - if (breakAfter == BreakAfter.PAGE) { - this.marker = BREAK_AFTER; - return FORCE_PAGE_BREAK; - } - - if (breakAfter == BreakAfter.ODD_PAGE) { - this.marker = BREAK_AFTER; - return FORCE_PAGE_BREAK_ODD; - } - - if (breakAfter == BreakAfter.EVEN_PAGE) { - this.marker = BREAK_AFTER; - return FORCE_PAGE_BREAK_EVEN; - } - - /* return status */ - return OK; - } - } - diff --git a/src/org/apache/fop/svg/SVGArea.java b/src/org/apache/fop/svg/SVGArea.java index 927d13de2..6347d150d 100644 --- a/src/org/apache/fop/svg/SVGArea.java +++ b/src/org/apache/fop/svg/SVGArea.java @@ -50,91 +50,46 @@ */ package org.apache.fop.svg; - - // FOP - import org.apache.fop.render.Renderer; - import org.apache.fop.layout.FontState; - import org.apache.fop.layout.Area; - - /** - * class representing an SVG area in which the SVG graphics sit - */ - public class SVGArea extends Area { - - /** - * construct an SVG area - * - * @param fontState the font state - * @param width the width of the area - * @param height the height of the area - */ - public SVGArea(FontState fontState, int width, int height) { - super(fontState, width, height); - currentHeight = height; - contentRectangleWidth = width; - } - - /** - * add a graphic. - * - * Graphics include SVG Rectangles, Lines and Text - * - * @param graphic the Graphic to add - */ - public void addGraphic(Graphic graphic) { - this.children.addElement(graphic); - } - - /** - * render the SVG. - * - * @param renderer the Renderer to use - */ - public void render(Renderer renderer) { - renderer.renderSVGArea(this); - } - } - diff --git a/src/org/apache/fop/svg/SVGElementMapping.java b/src/org/apache/fop/svg/SVGElementMapping.java index 96db2ce06..32a0f78db 100644 --- a/src/org/apache/fop/svg/SVGElementMapping.java +++ b/src/org/apache/fop/svg/SVGElementMapping.java @@ -50,31 +50,16 @@ */ package org.apache.fop.svg; - - import org.apache.fop.fo.FOTreeBuilder; - import org.apache.fop.fo.ElementMapping; - - public class SVGElementMapping implements ElementMapping { - - public void addToBuilder(FOTreeBuilder builder) { - String uri = "http://www.w3.org/Graphics/SVG/SVG-19990812.dtd"; - builder.addMapping(uri, "svg", SVG.maker()); - builder.addMapping(uri, "rect", Rect.maker()); - builder.addMapping(uri, "line", Line.maker()); - builder.addMapping(uri, "text", Text.maker()); - } - } - diff --git a/src/org/apache/fop/svg/SVGLength.java b/src/org/apache/fop/svg/SVGLength.java index aade265bc..8ada872a3 100644 --- a/src/org/apache/fop/svg/SVGLength.java +++ b/src/org/apache/fop/svg/SVGLength.java @@ -50,155 +50,78 @@ */ package org.apache.fop.svg; - - // FOP - import org.apache.fop.fo.*; - import org.apache.fop.datatypes.*; - import org.apache.fop.apps.FOPException; - - /** - * a class representing all the length properties in SVG - */ - public class SVGLength extends Property { - - /** - * inner class for making SVG Length objects. - */ - public static class Maker extends Property.Maker { - - /** - * whether this property is inherited or not. - * - * @return is this inherited? - */ - public boolean isInherited() { return false; } - - /** - * make an SVG Length property with the given value. - * - * @param propertyList the property list this is a member of - * @param value the explicit string value of the property - */ - public Property make(PropertyList propertyList, String value) - throws FOPException { - return new SVGLength(propertyList, new Length(value)); - } - - /** - * make an SVG Length property with the default value. - * - * @param propertyList the property list the property is a member of - */ - public Property make(PropertyList propertyList) throws FOPException { - return make(propertyList, "0pt"); - } - } - - /** - * returns the maker for this object. - * - * @return the maker for SVG Length objects - */ - public static Property.Maker maker() { - return new SVGLength.Maker(); - } - - /** the length as a Length object */ - protected Length value; - - /** - * construct an SVG length (called by the Maker). - * - * @param propertyList the property list this is a member of - * @param explicitValue the explicit value as a Length object - */ - protected SVGLength(PropertyList propertyList, Length explicitValue) { - this.propertyList = propertyList; - this.value = explicitValue; - } - - /** - * get the length - * - * @return the length as a Length object - */ - public Length getLength() { - return this.value; - } - } - diff --git a/src/org/apache/fop/svg/Text.java b/src/org/apache/fop/svg/Text.java index 786d65de9..6794ce009 100644 --- a/src/org/apache/fop/svg/Text.java +++ b/src/org/apache/fop/svg/Text.java @@ -50,191 +50,96 @@ */ package org.apache.fop.svg; - - // FOP - import org.apache.fop.fo.*; - import org.apache.fop.fo.properties.*; - import org.apache.fop.layout.Area; - import org.apache.fop.layout.FontState; - import org.apache.fop.apps.FOPException; - - /** - * class representing svg:text pseudo flow object. - */ - public class Text extends FObjMixed { - - /** - * inner class for making SVG Text objects. - */ - public static class Maker extends FObj.Maker { - - /** - * make an SVG Text object. - * - * @param parent the parent formatting object - * @param propertyList the explicit properties of this object - * - * @return the SVG Text object - */ - public FObj make(FObj parent, PropertyList propertyList) - throws FOPException { - return new Text(parent, propertyList); - } - } - - /** - * returns the maker for this object. - * - * @return the maker for SVG Text objects - */ - public static FObj.Maker maker() { - return new Text.Maker(); - } - - /** - * the string of text to display - */ - protected String text = ""; - - /** - * constructs an SVG Text object (called by Maker). - * - * @param parent the parent formatting object - * @param propertyList the explicit properties of this object - */ - protected Text(FObj parent, PropertyList propertyList) { - super(parent, propertyList); - this.name = "svg:text"; - } - - /** - * add characters to the string to display. - * - * @param data array of characters - * @param start start offset in character array - * @param length number of characters to add - */ - protected void addCharacters(char data[], int start, int length) { - this.text += new String(data, start, length); - } - - /** - * layout this formatting object. - * - * @param area the area to layout the object into - * - * @return the status of the layout - */ - public int layout(Area area) throws FOPException { - - /* retrieve properties */ - int x = this.properties.get("x").getLength().mvalue(); - int y = this.properties.get("y").getLength().mvalue(); - - /* if the area this is being put into is an SVGArea */ - if (area instanceof SVGArea) { - /* add the text to the SVGArea */ - ((SVGArea) area).addGraphic(new TextGraphic(x, y, text)); - } else { - /* otherwise generate a warning */ - System.err.println("WARNING: svg:text outside svg:svg"); - } - - /* return status */ - return OK; - } - } - diff --git a/src/org/apache/fop/svg/TextGraphic.java b/src/org/apache/fop/svg/TextGraphic.java index 736c74897..98be0c70f 100644 --- a/src/org/apache/fop/svg/TextGraphic.java +++ b/src/org/apache/fop/svg/TextGraphic.java @@ -50,59 +50,30 @@ */ package org.apache.fop.svg; - - /** - * class representing text in an SVG Area - */ - public class TextGraphic extends Graphic { - - /** x-coordinate of text */ - public int x; - - /** y-coordinate of text */ - public int y; - - /** the text string itself */ - public String s; - - /** - * construct a text graphic - * - * @param x x-coordinate of text - * @param y y-coordinate of text - * @param s the text string - */ - public TextGraphic(int x, int y, String s) { - this.x = x; - this.y = y; - this.s = s; - } - } - |