diff options
author | Keiron Liddle <keiron@apache.org> | 2001-10-26 09:27:00 +0000 |
---|---|---|
committer | Keiron Liddle <keiron@apache.org> | 2001-10-26 09:27:00 +0000 |
commit | af113ef5a388ac87b4f1dac63e07ffc7160f8b14 (patch) | |
tree | d40d1802b6728e0e5819e2e2939ff4254da47ffa /src/org/apache/fop/area | |
parent | 3c34d76dfaa0908026069b0763558fa7d464ceb2 (diff) | |
download | xmlgraphics-fop-af113ef5a388ac87b4f1dac63e07ffc7160f8b14.tar.gz xmlgraphics-fop-af113ef5a388ac87b4f1dac63e07ffc7160f8b14.zip |
updates to area tree and reading/rendering with xml
added user agent, xml handlers
added inline level property
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@194521 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/org/apache/fop/area')
23 files changed, 364 insertions, 34 deletions
diff --git a/src/org/apache/fop/area/Area.java b/src/org/apache/fop/area/Area.java index 3d43a5f5b..6a0318275 100644 --- a/src/org/apache/fop/area/Area.java +++ b/src/org/apache/fop/area/Area.java @@ -7,10 +7,12 @@ package org.apache.fop.area; +import java.io.Serializable; + /** - * base object for all areas + * Base object for all areas. */ -public class Area { +public class Area implements Serializable { // stacking directions public static final int LR = 0; public static final int RL = 1; diff --git a/src/org/apache/fop/area/AreaTree.java b/src/org/apache/fop/area/AreaTree.java index 6f3157773..b8544878c 100644 --- a/src/org/apache/fop/area/AreaTree.java +++ b/src/org/apache/fop/area/AreaTree.java @@ -9,6 +9,24 @@ package org.apache.fop.area; import java.util.ArrayList; + +/** + * Area tree for formatting objects. + * + * Concepts: + * The area tree is to be as small as possible. With minimal classes + * and data to fully represent an area tree for formatting objects. + * The area tree needs to be simple to render and follow the spec + * closely. + * This area tree has the concept of page sequences. + * Where ever possible information is discarded or optimised to + * keep memory use low. The data is also organised to make it + * possible for renderers to minimise their output. + * A page can be saved if not fully resolved and once rendered + * a page contains only size and id reference information. + * The area tree pages are organised in a model that depends on the + * type of renderer. + */ public class AreaTree { // allows for different models to deal with adding/rendering // in different situations @@ -40,15 +58,6 @@ public class AreaTree { public abstract void addPage(PageViewport page); } - // this queues pages and will call the render listener - // when the page is ready to be rendered - // if the render supports out of order rendering - // then a ready page is rendered immediately - public static class RenderPagesModel extends AreaTreeModel { - public void startPageSequence(Area title) {} - public void addPage(PageViewport page) {} - } - // this class stores all the pages in the document // for interactive agents public static class StorePagesModel extends AreaTreeModel { @@ -89,10 +98,20 @@ public class AreaTree { return (PageViewport) sequence.get(count); } } -} -abstract class PageRenderListener { - public abstract void startPageSequence(Area title); - public abstract void preparePage(PageViewport page); - public abstract void renderPage(PageViewport page); + // this queues pages and will call the render listener + // when the page is ready to be rendered + // if the render supports out of order rendering + // then a ready page is rendered immediately + public static class RenderPagesModel extends StorePagesModel { + public void startPageSequence(Area title) {} + public void addPage(PageViewport page) {} + } + + public static abstract class PageRenderListener { + public abstract void renderPage(RenderPagesModel model, + int pageseq, int count); + } + } + diff --git a/src/org/apache/fop/area/BeforeFloat.java b/src/org/apache/fop/area/BeforeFloat.java index f313eb559..034d467d2 100644 --- a/src/org/apache/fop/area/BeforeFloat.java +++ b/src/org/apache/fop/area/BeforeFloat.java @@ -21,6 +21,17 @@ public class BeforeFloat extends Area { ArrayList blocks = null; + public void addBlock(Block block) { + if (blocks == null) { + blocks = new ArrayList(); + } + blocks.add(block); + } + + public void setSeparator(Block sep) { + separator = sep; + } + public List getBlocks() { return blocks; } diff --git a/src/org/apache/fop/area/Block.java b/src/org/apache/fop/area/Block.java index cf070497f..9a7e3b30c 100644 --- a/src/org/apache/fop/area/Block.java +++ b/src/org/apache/fop/area/Block.java @@ -7,6 +7,7 @@ package org.apache.fop.area; +import java.io.Serializable; import java.util.ArrayList; import java.util.List; import java.awt.geom.Rectangle2D; @@ -17,7 +18,7 @@ import java.awt.geom.Rectangle2D; // or by relative to the parent for floats, tables and lists // cacheable object // has id information -public class Block extends Area { +public class Block extends Area implements Serializable { // normally stacked with other blocks public static final int STACK = 0; // placed relative to the parent area @@ -79,4 +80,18 @@ public class Block extends Area { public int getPositioning() { return positioning; } + + // store properties in array list, need better solution + ArrayList props = null; + + public void addProperty(Property prop) { + if (props == null) { + props = new ArrayList(); + } + props.add(prop); + } + + public List getPropertyList() { + return props; + } } diff --git a/src/org/apache/fop/area/BodyRegion.java b/src/org/apache/fop/area/BodyRegion.java index 0661ebdd7..e6e886404 100644 --- a/src/org/apache/fop/area/BodyRegion.java +++ b/src/org/apache/fop/area/BodyRegion.java @@ -16,6 +16,19 @@ public class BodyRegion extends Region { super(BODY); } + public void setBeforeFloat(BeforeFloat bf) { + beforeFloat = bf; + } + + public void setMainReference(MainReference mr) { + mainReference = mr; + } + + public void setFootnote(Footnote foot) { + footnote = foot; + } + + public BeforeFloat getBeforeFloat() { return beforeFloat; } diff --git a/src/org/apache/fop/area/Flow.java b/src/org/apache/fop/area/Flow.java index d054a51d5..6cfa09a53 100644 --- a/src/org/apache/fop/area/Flow.java +++ b/src/org/apache/fop/area/Flow.java @@ -18,6 +18,10 @@ public class Flow extends Area { int stacking = TB; int width; + public void addBlock(Block block) { + blocks.add(block); + } + public List getBlocks() { return blocks; } diff --git a/src/org/apache/fop/area/Footnote.java b/src/org/apache/fop/area/Footnote.java index 1baf1502c..dcd62ecdf 100644 --- a/src/org/apache/fop/area/Footnote.java +++ b/src/org/apache/fop/area/Footnote.java @@ -23,6 +23,17 @@ public class Footnote { ArrayList blocks = null; + public void setSeparator(Block sep) { + separator = sep; + } + + public void addBlock(Block block) { + if (blocks == null) { + blocks = new ArrayList(); + } + blocks.add(block); + } + public Block getSeparator() { return separator; } diff --git a/src/org/apache/fop/area/LineArea.java b/src/org/apache/fop/area/LineArea.java index 2e39b5175..8184d332a 100644 --- a/src/org/apache/fop/area/LineArea.java +++ b/src/org/apache/fop/area/LineArea.java @@ -31,6 +31,14 @@ public class LineArea extends Area { ArrayList inlineAreas = new ArrayList(); + public void setHeight(int height) { + lineHeight = height; + } + + public int getHeight() { + return lineHeight; + } + public void addInlineArea(InlineArea area) { inlineAreas.add(area); } @@ -38,11 +46,19 @@ public class LineArea extends Area { public List getInlineAreas() { return inlineAreas; } + + // store properties in array list, need better solution + ArrayList props = null; + + public void addProperty(Property prop) { + if (props == null) { + props = new ArrayList(); + } + props.add(prop); + } + + public List getPropertyList() { + return props; + } } -/* -class LineProperty { - int propType; - int[] range; - Object data; -} -*/ + diff --git a/src/org/apache/fop/area/LineProperty.java b/src/org/apache/fop/area/LineProperty.java new file mode 100644 index 000000000..d5eb3dad9 --- /dev/null +++ b/src/org/apache/fop/area/LineProperty.java @@ -0,0 +1,13 @@ +/* + * $Id$ + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. + */ + +package org.apache.fop.area; + +public class LineProperty extends Property { + int[] range; +} + diff --git a/src/org/apache/fop/area/MainReference.java b/src/org/apache/fop/area/MainReference.java index 4c705637f..b18008b42 100644 --- a/src/org/apache/fop/area/MainReference.java +++ b/src/org/apache/fop/area/MainReference.java @@ -7,15 +7,20 @@ package org.apache.fop.area; +import java.io.Serializable; import java.util.ArrayList; import java.util.List; // the area that contains the flow via the span areas -public class MainReference { +public class MainReference implements Serializable { List spanAreas = new ArrayList(); int columnGap; int width; + public void addSpan(Span span) { + spanAreas.add(span); + } + public List getSpans() { return spanAreas; } diff --git a/src/org/apache/fop/area/Page.java b/src/org/apache/fop/area/Page.java index 059d98150..e8b1bfd62 100644 --- a/src/org/apache/fop/area/Page.java +++ b/src/org/apache/fop/area/Page.java @@ -7,7 +7,9 @@ package org.apache.fop.area; -public class Page { +import java.io.Serializable; + +public class Page implements Serializable { // contains before, start, body, end and after regions RegionViewport regionBefore = null; RegionViewport regionStart = null; diff --git a/src/org/apache/fop/area/PageViewport.java b/src/org/apache/fop/area/PageViewport.java index 29354eda2..18e8ba4ff 100644 --- a/src/org/apache/fop/area/PageViewport.java +++ b/src/org/apache/fop/area/PageViewport.java @@ -8,6 +8,8 @@ package org.apache.fop.area; import java.awt.geom.Rectangle2D; +import java.io.ObjectOutputStream; +import java.io.ObjectInputStream; import java.util.ArrayList; // this is the level that creates the page @@ -15,17 +17,36 @@ import java.util.ArrayList; public class PageViewport { Page page; Rectangle2D viewArea; + boolean clip = false; - public PageViewport(Page p) { + public PageViewport(Page p, Rectangle2D bounds) { page = p; + viewArea = bounds; } // this list is only used when the page is discarded // the information is kept for future reference ArrayList idReferences = null; + public void setClip(boolean c) { + clip = c; + } + + public Rectangle2D getViewArea() { + return viewArea; + } + // a viewport area for page and reference areas public Page getPage() { return page; } + + public void savePage(ObjectOutputStream out) throws Exception { + out.writeObject(page); + page = null; + } + + public void loadPage(ObjectInputStream in) throws Exception { + page = (Page) in.readObject(); + } } diff --git a/src/org/apache/fop/area/Property.java b/src/org/apache/fop/area/Property.java new file mode 100644 index 000000000..3b9a836e0 --- /dev/null +++ b/src/org/apache/fop/area/Property.java @@ -0,0 +1,33 @@ +/* + * $Id$ + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. + */ + +package org.apache.fop.area; + +import java.io.Serializable; + +// properties should be serialized by the holder +public class Property implements Serializable { + public static final int ID_LINK = 0; + public static final int INTERNAL_LINK = 1; //resolved + public static final int EXTERNAL_LINK = 2; + public static final int FONT_FAMILY = 3; + public static final int FONT_SIZE = 4; + public static final int FONT_WEIGHT = 5; + public static final int FONT_STYLE = 6; + public static final int COLOR = 7; + public static final int ID_AREA = 8; + public static final int BACKGROUND = 9; + public static final int UNDERLINE = 10; + public static final int OVERLINE = 11; + public static final int LINETHROUGH = 12; + public static final int OFFSET = 13; + public static final int SHADOW = 14; + public int propType; + public Object data; + +} + diff --git a/src/org/apache/fop/area/Region.java b/src/org/apache/fop/area/Region.java index d51da6e2d..47f2dbfd9 100644 --- a/src/org/apache/fop/area/Region.java +++ b/src/org/apache/fop/area/Region.java @@ -7,10 +7,11 @@ package org.apache.fop.area; +import java.io.Serializable; import java.util.ArrayList; import java.util.List; -public class Region { +public class Region implements Serializable { public static final int BEFORE = 0; public static final int START = 1; public static final int BODY = 2; diff --git a/src/org/apache/fop/area/RegionViewport.java b/src/org/apache/fop/area/RegionViewport.java index 3a90bb95e..43b320399 100644 --- a/src/org/apache/fop/area/RegionViewport.java +++ b/src/org/apache/fop/area/RegionViewport.java @@ -8,20 +8,48 @@ package org.apache.fop.area; import java.awt.geom.Rectangle2D; +import java.io.Serializable; +import java.io.IOException; -public class RegionViewport { +public class RegionViewport implements Serializable { // this rectangle is relative to the page Rectangle2D regionArea; - boolean clip; + boolean clip = false; Region region; + public RegionViewport(Rectangle2D area) { + regionArea = area; + } + public void setRegion(Region reg) { region = reg; } + public Rectangle2D getViewArea() { + return regionArea; + } + public Region getRegion() { return region; } + private void writeObject(java.io.ObjectOutputStream out) + throws IOException { + out.writeFloat((float) regionArea.getX()); + out.writeFloat((float) regionArea.getY()); + out.writeFloat((float) regionArea.getWidth()); + out.writeFloat((float) regionArea.getHeight()); + out.writeBoolean(clip); + out.writeObject(region); + } + + private void readObject(java.io.ObjectInputStream in) + throws IOException, ClassNotFoundException { + regionArea = new Rectangle2D.Float(in.readFloat(), in.readFloat(), + in.readFloat(), in.readFloat()); + clip = in.readBoolean(); + region = (Region) in.readObject(); + } + } diff --git a/src/org/apache/fop/area/Span.java b/src/org/apache/fop/area/Span.java index 28dddc7da..fc8b45913 100644 --- a/src/org/apache/fop/area/Span.java +++ b/src/org/apache/fop/area/Span.java @@ -12,9 +12,17 @@ import java.util.ArrayList; // this is a reference area block area with 0 border and padding public class Span extends Area { // the list of flow reference areas in this span area - ArrayList flowAreas = new ArrayList(); + ArrayList flowAreas; int height; + public Span(int cols) { + flowAreas = new ArrayList(cols); + } + + public void addFlow(Flow flow) { + flowAreas.add(flow); + } + public int getColumnCount() { return flowAreas.size(); } diff --git a/src/org/apache/fop/area/inline/Container.java b/src/org/apache/fop/area/inline/Container.java index 54a9ac493..76c987e21 100644 --- a/src/org/apache/fop/area/inline/Container.java +++ b/src/org/apache/fop/area/inline/Container.java @@ -7,12 +7,14 @@ package org.apache.fop.area.inline; +import org.apache.fop.area.Area; +import org.apache.fop.area.Block; import org.apache.fop.render.Renderer; import java.util.List; import java.util.ArrayList; -public class Container extends InlineArea { +public class Container extends Area { ArrayList blocks = new ArrayList(); // this is an inline area that can have blocks as children @@ -21,6 +23,10 @@ public class Container extends InlineArea { renderer.renderContainer(this); } + public void addBlock(Block block) { + blocks.add(block); + } + public List getBlocks() { return blocks; } diff --git a/src/org/apache/fop/area/inline/ForeignObject.java b/src/org/apache/fop/area/inline/ForeignObject.java index b67575737..54f35f73c 100644 --- a/src/org/apache/fop/area/inline/ForeignObject.java +++ b/src/org/apache/fop/area/inline/ForeignObject.java @@ -18,4 +18,16 @@ public class ForeignObject extends Area { // dom object // height, width + public ForeignObject(Document d, String ns) { + doc = d; + namespace = ns; + } + + public Document getDocument() { + return doc; + } + + public String getNameSpace() { + return namespace; + } } diff --git a/src/org/apache/fop/area/inline/Image.java b/src/org/apache/fop/area/inline/Image.java index 4cf1b7f72..3899997a5 100644 --- a/src/org/apache/fop/area/inline/Image.java +++ b/src/org/apache/fop/area/inline/Image.java @@ -10,8 +10,16 @@ package org.apache.fop.area.inline; import org.apache.fop.area.Area; // cacheable object +// image object, mime type, url public class Image extends Area { + String url; - // image object, mime type, url + public Image(String u) { + url = u; + } + + public String getURL() { + return url; + } } diff --git a/src/org/apache/fop/area/inline/InlineArea.java b/src/org/apache/fop/area/inline/InlineArea.java index 3c61377dc..aa229316f 100644 --- a/src/org/apache/fop/area/inline/InlineArea.java +++ b/src/org/apache/fop/area/inline/InlineArea.java @@ -8,8 +8,19 @@ package org.apache.fop.area.inline; import org.apache.fop.area.Area; +import org.apache.fop.area.Property; import org.apache.fop.render.Renderer; +import java.util.List; +import java.util.ArrayList; + +/** + * Inline Area + * This area is for all inline areas that can be placed + * in a line area. + * Extensions of this class should render themselves with the + * requested renderer. + */ public class InlineArea extends Area { int width; int height; @@ -17,6 +28,9 @@ public class InlineArea extends Area { int verticalPosition; // width, height, vertical alignment + // store properties in array list, need better solution + ArrayList props = null; + // inline areas are expected to implement this method // to render themselves public void render(Renderer renderer) { @@ -30,4 +44,15 @@ public class InlineArea extends Area { public int getWidth() { return width; } + + public void addProperty(Property prop) { + if (props == null) { + props = new ArrayList(); + } + props.add(prop); + } + + public List getPropertyList() { + return props; + } } diff --git a/src/org/apache/fop/area/inline/Leader.java b/src/org/apache/fop/area/inline/Leader.java index f31949acb..2475cac80 100644 --- a/src/org/apache/fop/area/inline/Leader.java +++ b/src/org/apache/fop/area/inline/Leader.java @@ -7,6 +7,8 @@ package org.apache.fop.area.inline; +import org.apache.fop.render.Renderer; + public class Leader extends Stretch { // pattern, length min opt max @@ -16,4 +18,37 @@ public class Leader extends Stretch { // if space replaced with a space // otherwise this is a holder for a line + public static final int DOTTED = 0; + public static final int DASHED = 1; + public static final int SOLID = 2; + public static final int DOUBLE = 3; + public static final int GROOVE = 4; + public static final int RIDGE = 5; + + int ruleStyle = SOLID; + int ruleThickness = 1000; + + public Leader() { + + } + + public void setRuleStyle(int style) { + ruleStyle = style; + } + + public void setRuleThickness(int rt) { + ruleThickness = rt; + } + + public int getRuleStyle() { + return ruleStyle; + } + + public int getRuleThickness() { + return ruleThickness; + } + + public void render(Renderer renderer) { + renderer.renderLeader(this); + } } diff --git a/src/org/apache/fop/area/inline/Viewport.java b/src/org/apache/fop/area/inline/Viewport.java index a7458c53a..5e1ce23d0 100644 --- a/src/org/apache/fop/area/inline/Viewport.java +++ b/src/org/apache/fop/area/inline/Viewport.java @@ -8,15 +8,52 @@ package org.apache.fop.area.inline; import org.apache.fop.area.Area; +import org.apache.fop.render.Renderer; +import java.io.IOException; import java.awt.geom.Rectangle2D; public class Viewport extends InlineArea { - // contents could be foreign object or image + // contents could be container, foreign object or image Area content; // an inline-level viewport area for graphic and instream foreign object boolean clip = false; // position relative to this area Rectangle2D contentPosition; + public Viewport(Area child) { + content = child; + } + + public Area getContent() { + return content; + } + + public void render(Renderer renderer) { + renderer.renderViewport(this); + } + + private void writeObject(java.io.ObjectOutputStream out) + throws IOException { + out.writeBoolean(contentPosition != null); + if (contentPosition != null) { + out.writeFloat((float) contentPosition.getX()); + out.writeFloat((float) contentPosition.getY()); + out.writeFloat((float) contentPosition.getWidth()); + out.writeFloat((float) contentPosition.getHeight()); + } + out.writeBoolean(clip); + out.writeObject(content); + } + + private void readObject(java.io.ObjectInputStream in) + throws IOException, ClassNotFoundException { + if (in.readBoolean()) { + contentPosition = new Rectangle2D.Float(in.readFloat(), + in.readFloat(), in.readFloat(), in.readFloat()); + } + clip = in.readBoolean(); + content = (Area) in.readObject(); + } + } diff --git a/src/org/apache/fop/area/inline/Word.java b/src/org/apache/fop/area/inline/Word.java index 73c9ec26d..070af40ff 100644 --- a/src/org/apache/fop/area/inline/Word.java +++ b/src/org/apache/fop/area/inline/Word.java @@ -7,9 +7,14 @@ package org.apache.fop.area.inline; +import org.apache.fop.render.Renderer; + public class Word extends InlineArea { // character info: font, char spacing, colour, baseline String word; + public void render(Renderer renderer) { + renderer.renderWord(this); + } } |