diff options
Diffstat (limited to 'src/org/apache/fop/area')
-rw-r--r-- | src/org/apache/fop/area/Area.java | 31 | ||||
-rw-r--r-- | src/org/apache/fop/area/Block.java | 12 | ||||
-rw-r--r-- | src/org/apache/fop/area/LineArea.java | 20 | ||||
-rw-r--r-- | src/org/apache/fop/area/Trait.java | 186 | ||||
-rw-r--r-- | src/org/apache/fop/area/inline/InlineArea.java | 50 | ||||
-rw-r--r-- | src/org/apache/fop/area/inline/InlineParent.java | 16 | ||||
-rw-r--r-- | src/org/apache/fop/area/inline/Word.java | 9 |
7 files changed, 256 insertions, 68 deletions
diff --git a/src/org/apache/fop/area/Area.java b/src/org/apache/fop/area/Area.java index f041f9227..8a3552f0b 100644 --- a/src/org/apache/fop/area/Area.java +++ b/src/org/apache/fop/area/Area.java @@ -10,6 +10,8 @@ package org.apache.fop.area; import java.io.Serializable; import org.apache.fop.fo.FObj; +import java.util.HashMap; + // If the area appears more than once in the output // or if the area has external data it is cached // to keep track of it and to minimize rendered output @@ -126,4 +128,33 @@ public class Area implements Serializable { public FObj getGeneratingFObj() { return this.genFObj; } + + // Do nothing! Let subclasses do something if they can have child areas. + public void addChild(Area child) { + } + + + HashMap props = null; + + public void addTrait(Trait prop) { + if (props == null) { + props = new HashMap(20); + } + props.put(prop.propType, prop.data); + } + + public void addTrait(Object traitCode, Object prop) { + if (props == null) { + props = new HashMap(20); + } + props.put(traitCode, prop); + } + + public HashMap getTraits() { + return this.props; + } + + public Object getTrait(Object oTraitCode) { + return (props != null? props.get(oTraitCode) : null); + } } diff --git a/src/org/apache/fop/area/Block.java b/src/org/apache/fop/area/Block.java index 5dcbb7df4..d1e605d43 100644 --- a/src/org/apache/fop/area/Block.java +++ b/src/org/apache/fop/area/Block.java @@ -71,18 +71,6 @@ public class Block extends BlockParent implements Serializable { return positioning; } - // store properties in array list, need better solution - ArrayList traits = null; - public void addTrait(Trait prop) { - if (traits == null) { - traits = new ArrayList(); - } - traits.add(prop); - } - - public List getTraitList() { - return traits; - } } diff --git a/src/org/apache/fop/area/LineArea.java b/src/org/apache/fop/area/LineArea.java index 25d4d66dc..306d50be6 100644 --- a/src/org/apache/fop/area/LineArea.java +++ b/src/org/apache/fop/area/LineArea.java @@ -46,6 +46,12 @@ public class LineArea extends Area { return new MinOptMax(lineHeight); } + public void addChild(Area childArea) { + if (childArea instanceof InlineArea) { + addInlineArea((InlineArea)childArea); + } + } + public void addInlineArea(InlineArea area) { inlineAreas.add(area); } @@ -54,20 +60,6 @@ public class LineArea extends Area { return inlineAreas; } - // store properties in array list, need better solution - ArrayList props = null; - - public void addTrait(Trait prop) { - if (props == null) { - props = new ArrayList(); - } - props.add(prop); - } - - public List getTraitList() { - return props; - } - public void verticalAlign(int lh, int lead, int follow) { int maxHeight = lh; List inlineAreas = getInlineAreas(); diff --git a/src/org/apache/fop/area/Trait.java b/src/org/apache/fop/area/Trait.java index 7ac537a79..dede23a57 100644 --- a/src/org/apache/fop/area/Trait.java +++ b/src/org/apache/fop/area/Trait.java @@ -8,32 +8,179 @@ package org.apache.fop.area; import org.apache.fop.datatypes.ColorType; +import org.apache.fop.traits.BorderProps; +import org.apache.fop.layout.FontState; import java.io.Serializable; +import java.util.Map; +import java.util.HashMap; +import java.util.Iterator; // properties should be serialized by the holder public class Trait 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 static final int FONT_STATE = 100; - - public int propType; + public static final Integer ID_LINK = new Integer(0); + public static final Integer INTERNAL_LINK = new Integer(1); //resolved + public static final Integer EXTERNAL_LINK = new Integer(2); + public static final Integer FONT_FAMILY = new Integer(3); + public static final Integer FONT_SIZE = new Integer(4); + public static final Integer FONT_WEIGHT = new Integer(5); + public static final Integer FONT_STYLE = new Integer(6); + public static final Integer COLOR = new Integer(7); + public static final Integer ID_AREA = new Integer(8); + public static final Integer BACKGROUND = new Integer(9); + public static final Integer UNDERLINE = new Integer(10); + public static final Integer OVERLINE = new Integer(11); + public static final Integer LINETHROUGH = new Integer(12); + public static final Integer OFFSET = new Integer(13); + public static final Integer SHADOW = new Integer(14); + public static final Integer BORDER_START = new Integer(15); + public static final Integer BORDER_END = new Integer(16); + public static final Integer BORDER_BEFORE = new Integer(17); + public static final Integer BORDER_AFTER = new Integer(18); + public static final Integer PADDING_START = new Integer(19); + public static final Integer PADDING_END = new Integer(20); + public static final Integer PADDING_BEFORE = new Integer(21); + public static final Integer PADDING_AFTER = new Integer(22); + + public static final Integer FONT_STATE = new Integer(100); + + static HashMap s_hmTraitInfo; + + private static class TraitInfo { + String sName; + Class sClass; // Class of trait data + TraitInfo(String sName, Class sClass) { + this.sName = sName; + this.sClass = sClass; + } + } + + static { + // Create a hashmap mapping trait code to name for external representation + s_hmTraitInfo = new HashMap(); + s_hmTraitInfo.put(ID_LINK, + new TraitInfo("id-link", String.class)); + s_hmTraitInfo.put(INTERNAL_LINK, + new TraitInfo("internal-link", String.class)); + s_hmTraitInfo.put(EXTERNAL_LINK, + new TraitInfo("external-link", String.class)); + s_hmTraitInfo.put(FONT_FAMILY, + new TraitInfo("font-family", String.class)); + s_hmTraitInfo.put(FONT_SIZE, + new TraitInfo("font-size", Integer.class)); + s_hmTraitInfo.put(FONT_WEIGHT, + new TraitInfo("font-weight", Integer.class)); + s_hmTraitInfo.put(FONT_STYLE, + new TraitInfo("font-style", String.class)); + s_hmTraitInfo.put(COLOR, + new TraitInfo("color", String.class)); + s_hmTraitInfo.put(ID_AREA, + new TraitInfo("id-area", String.class)); + s_hmTraitInfo.put(BACKGROUND, + new TraitInfo("background", String.class)); + s_hmTraitInfo.put(UNDERLINE, + new TraitInfo("underline", Integer.class)); + s_hmTraitInfo.put(OVERLINE, + new TraitInfo("overline", Integer.class)); + s_hmTraitInfo.put(LINETHROUGH, + new TraitInfo("linethrough", Integer.class)); + s_hmTraitInfo.put(OFFSET, + new TraitInfo("offset", Integer.class)); + s_hmTraitInfo.put(SHADOW, + new TraitInfo("shadow", Integer.class)); + s_hmTraitInfo.put(BORDER_START, + new TraitInfo("border-start", BorderProps.class)); + s_hmTraitInfo.put(BORDER_END, + new TraitInfo("border-end", BorderProps.class)); + s_hmTraitInfo.put(BORDER_BEFORE, + new TraitInfo("border-before", BorderProps.class)); + s_hmTraitInfo.put(BORDER_AFTER, + new TraitInfo("border-after", BorderProps.class)); + s_hmTraitInfo.put(PADDING_START, + new TraitInfo("padding-start", Integer.class)); + s_hmTraitInfo.put(PADDING_END, + new TraitInfo("padding-end", Integer.class)); + s_hmTraitInfo.put(PADDING_BEFORE, + new TraitInfo("padding-before", Integer.class)); + s_hmTraitInfo.put(PADDING_AFTER, + new TraitInfo("padding-after", Integer.class)); + + s_hmTraitInfo.put(FONT_STATE, + new TraitInfo("font-state", FontState.class)); + } + + public static String getTraitName(Object traitCode) { + Object obj = s_hmTraitInfo.get(traitCode); + if (obj != null) { + return ((TraitInfo)obj).sName; + } + else { + return "unknown-trait-" + traitCode.toString(); + } + } + + public static Object getTraitCode(String sTraitName) { + Iterator iter = s_hmTraitInfo.entrySet().iterator(); + while (iter.hasNext()) { + Map.Entry entry = (Map.Entry)iter.next(); + TraitInfo ti = (TraitInfo)entry.getValue(); + if (ti != null && ti.sName.equals(sTraitName)) { + return entry.getKey(); + } + } + return null; + } + + private static Class getTraitClass(Object oTraitCode) { + TraitInfo ti = (TraitInfo)s_hmTraitInfo.get(oTraitCode); + return (ti != null? ti.sClass : null); + } + + public Object propType; public Object data; + public Trait() { + this.propType = null; + this.data = null; + } + + public Trait(Object propType, Object data) { + this.propType = propType; + this.data = data; + } + + public String toString() { + return data.toString(); + } + + public static Object makeTraitValue(Object oCode, String sTraitValue) { + // Get the code from the name + // See what type of object it is + // Convert string value to an object of that type + Class tclass = getTraitClass(oCode); + if (tclass == null) return null; + if (tclass.equals(String.class)) { + return sTraitValue; + } + if (tclass.equals(Integer.class)) { + return new Integer(sTraitValue); + } + // See if the class has a constructor from string or can read from a string + try { + Object o = tclass.newInstance(); + //return o.fromString(sTraitValue); + } catch (IllegalAccessException e1) { + System.err.println("Can't create instance of " + tclass.getName()); + return null; + } catch (InstantiationException e2) { + System.err.println("Can't create instance of " + tclass.getName()); + return null; + } + + + return null; + } + public static class Background { ColorType color; String url; @@ -41,5 +188,6 @@ public class Trait implements Serializable { int horiz; int vertical; } + } diff --git a/src/org/apache/fop/area/inline/InlineArea.java b/src/org/apache/fop/area/inline/InlineArea.java index b7ad5ad29..645e67a0b 100644 --- a/src/org/apache/fop/area/inline/InlineArea.java +++ b/src/org/apache/fop/area/inline/InlineArea.java @@ -11,6 +11,7 @@ import org.apache.fop.area.Area; import org.apache.fop.area.MinOptMax; import org.apache.fop.area.Trait; import org.apache.fop.render.Renderer; +import org.apache.fop.traits.BorderProps; import org.apache.fop.layoutmgr.LayoutInfo; @@ -25,8 +26,10 @@ import java.util.ArrayList; * requested renderer. */ public class InlineArea extends Area { - int width; + // int width; int height; + protected int contentIPD = 0; + // position within the line area, either top or baseline int verticalPosition; // width, height, vertical alignment @@ -42,11 +45,19 @@ public class InlineArea extends Area { } public void setWidth(int w) { - width = w; + contentIPD = w; } public int getWidth() { - return width; + return contentIPD; + } + + public void setIPD(int ipd) { + this.contentIPD = ipd; + } + + public void increaseIPD(int ipd) { + this.contentIPD += ipd; } public void setHeight(int h) { @@ -57,10 +68,27 @@ public class InlineArea extends Area { return height; } + public int getAllocIPD() { + // If start or end border or padding is non-zero, add to content IPD + int iBP = contentIPD; + Object t; + if ((t = getTrait(Trait.PADDING_START)) != null) { + iBP += ((Integer)t).intValue(); + } + if ((t = getTrait(Trait.PADDING_END)) != null) { + iBP += ((Integer)t).intValue(); + } + if ((t = getTrait(Trait.BORDER_START)) != null) { + iBP += ((BorderProps)t).width;; + } + if ((t = getTrait(Trait.BORDER_END)) != null) { + iBP += ((BorderProps)t).width;; + } + return iBP; + } + public MinOptMax getAllocationIPD() { - // Should also account for any borders and padding in the - // inline progression dimension - return new MinOptMax(width); + return new MinOptMax(getAllocIPD()); } public void setOffset(int v) { @@ -71,14 +99,4 @@ public class InlineArea extends Area { return verticalPosition; } - public void addTrait(Trait prop) { - if (props == null) { - props = new ArrayList(); - } - props.add(prop); - } - - public List getTraitList() { - return props; - } } diff --git a/src/org/apache/fop/area/inline/InlineParent.java b/src/org/apache/fop/area/inline/InlineParent.java index 4ec3d0447..8ea743d9c 100644 --- a/src/org/apache/fop/area/inline/InlineParent.java +++ b/src/org/apache/fop/area/inline/InlineParent.java @@ -17,7 +17,6 @@ import java.util.ArrayList; // this is an inline area that can have other inlines as children public class InlineParent extends InlineArea { ArrayList inlines = new ArrayList(); - int width; public InlineParent() { } @@ -26,16 +25,19 @@ public class InlineParent extends InlineArea { renderer.renderInlineParent(this); } - public void addChild(InlineArea child) { - inlines.add(child); + + /** + * Override generic Area method. + */ + public void addChild(Area childArea) { + if (childArea instanceof InlineArea) { + inlines.add(childArea); + increaseIPD( ((InlineArea)childArea).getAllocIPD()); + } } public List getChildAreas() { return inlines; } - public int getWidth() { - return width; - } - } diff --git a/src/org/apache/fop/area/inline/Word.java b/src/org/apache/fop/area/inline/Word.java index 51b009b28..047433c89 100644 --- a/src/org/apache/fop/area/inline/Word.java +++ b/src/org/apache/fop/area/inline/Word.java @@ -13,6 +13,7 @@ public class Word extends InlineArea { // character info: font, char spacing, colour, baseline String word; + int iWSadjust = 0; public void render(Renderer renderer) { renderer.renderWord(this); @@ -25,4 +26,12 @@ public class Word extends InlineArea { public String getWord() { return word; } + + public int getWSadjust() { + return iWSadjust; + } + + public void setWSadjust(int iWSadjust) { + this.iWSadjust = iWSadjust; + } } |