Rectangle2D viewArea = parseRect(attributes.getValue("bounds"));
int pageNumber = getAttributeAsInteger(attributes, "nr", -1);
String pageNumberString = attributes.getValue("formatted-nr");
- currentPageViewport = new PageViewport(viewArea, pageNumber, pageNumberString);
+ String pageMaster = attributes.getValue("simple-page-master-name");
+ boolean blank = getAttributeAsBoolean(attributes, "blank", false);
+ currentPageViewport = new PageViewport(viewArea,
+ pageNumber, pageNumberString,
+ pageMaster, blank);
} else if ("page".equals(localName)) {
Page p = new Page();
currentPageViewport.setPage(p);
rv = new RegionViewport(viewArea);
rv.setClip(getAttributeAsBoolean(attributes, "clipped", false));
setAreaAttributes(attributes, rv);
- setTraits(attributes, rv);
+ setTraits(attributes, rv, SUBSET_COMMON);
+ setTraits(attributes, rv, SUBSET_BOX);
+ setTraits(attributes, rv, SUBSET_COLOR);
areaStack.push(rv);
} else if ("regionBefore".equals(localName)) {
pushNewRegionReference(attributes, Constants.FO_REGION_BEFORE);
block.setYOffset(getAttributeAsInteger(attributes, "top-offset", 0));
}
setAreaAttributes(attributes, block);
- setTraits(attributes, block);
+ setTraits(attributes, block, SUBSET_COMMON);
+ setTraits(attributes, block, SUBSET_BOX);
+ setTraits(attributes, block, SUBSET_COLOR);
Area parent = (Area)areaStack.peek();
//BlockParent parent = getCurrentBlockParent();
parent.addChildArea(block);
} else if ("lineArea".equals(localName)) {
LineArea line = new LineArea();
setAreaAttributes(attributes, line);
- setTraits(attributes, line);
+ setTraits(attributes, line, SUBSET_COMMON);
+ setTraits(attributes, line, SUBSET_BOX);
+ setTraits(attributes, line, SUBSET_COLOR);
BlockParent parent = getCurrentBlockParent();
parent.addChildArea(line);
areaStack.push(line);
InlineParent ip = new InlineParent();
ip.setOffset(getAttributeAsInteger(attributes, "offset", 0));
setAreaAttributes(attributes, ip);
- setTraits(attributes, ip);
+ setTraits(attributes, ip, SUBSET_COMMON);
+ setTraits(attributes, ip, SUBSET_BOX);
+ setTraits(attributes, ip, SUBSET_COLOR);
+ setTraits(attributes, ip, SUBSET_LINK);
Area parent = (Area)areaStack.peek();
parent.addChildArea(ip);
areaStack.push(ip);
InlineBlockParent ibp = new InlineBlockParent();
ibp.setOffset(getAttributeAsInteger(attributes, "offset", 0));
setAreaAttributes(attributes, ibp);
- setTraits(attributes, ibp);
+ setTraits(attributes, ibp, SUBSET_COMMON);
+ setTraits(attributes, ibp, SUBSET_BOX);
+ setTraits(attributes, ibp, SUBSET_COLOR);
Area parent = (Area)areaStack.peek();
parent.addChildArea(ibp);
areaStack.push(ibp);
}
TextArea text = new TextArea();
setAreaAttributes(attributes, text);
- setTraits(attributes, text);
+ setTraits(attributes, text, SUBSET_COMMON);
+ setTraits(attributes, text, SUBSET_BOX);
+ setTraits(attributes, text, SUBSET_COLOR);
+ setTraits(attributes, text, SUBSET_FONT);
text.setBaselineOffset(getAttributeAsInteger(attributes, "baseline", 0));
+ text.setOffset(getAttributeAsInteger(attributes, "offset", 0));
text.setTextLetterSpaceAdjust(getAttributeAsInteger(attributes,
"tlsadjust", 0));
text.setTextWordSpaceAdjust(getAttributeAsInteger(attributes,
} else if ("leader".equals(localName)) {
Leader leader = new Leader();
setAreaAttributes(attributes, leader);
- setTraits(attributes, leader);
+ setTraits(attributes, leader, SUBSET_COMMON);
+ setTraits(attributes, leader, SUBSET_BOX);
+ setTraits(attributes, leader, SUBSET_COLOR);
+ setTraits(attributes, leader, SUBSET_FONT);
leader.setOffset(getAttributeAsInteger(attributes, "offset", 0));
String ruleStyle = attributes.getValue("ruleStyle");
if (ruleStyle != null) {
} else if ("viewport".equals(localName)) {
Viewport viewport = new Viewport(null);
setAreaAttributes(attributes, viewport);
- setTraits(attributes, viewport);
+ setTraits(attributes, viewport, SUBSET_COMMON);
+ setTraits(attributes, viewport, SUBSET_BOX);
+ setTraits(attributes, viewport, SUBSET_COLOR);
viewport.setContentPosition(getAttributeAsRectangle2D(attributes, "pos"));
viewport.setClip(getAttributeAsBoolean(attributes, "clip", false));
viewport.setOffset(getAttributeAsInteger(attributes, "offset", 0));
String url = attributes.getValue("url");
Image image = new Image(url);
setAreaAttributes(attributes, image);
- setTraits(attributes, image);
+ setTraits(attributes, image, SUBSET_COMMON);
getCurrentViewport().setContent(image);
} else if ("foreignObject".equals(localName)) {
String ns = attributes.getValue("ns");
}
ForeignObject foreign = new ForeignObject(ns);
setAreaAttributes(attributes, foreign);
- setTraits(attributes, foreign);
+ setTraits(attributes, foreign, SUBSET_COMMON);
getCurrentViewport().setContent(foreign);
areaStack.push(foreign);
} else if ("extension-attachments".equals(localName)) {
} else {
Space space = new Space();
setAreaAttributes(lastAttributes, space);
- setTraits(lastAttributes, space);
- space.setOffset(getAttributeAsInteger(lastAttributes, "offset", 0));
+ setTraits(lastAttributes, space, SUBSET_COMMON);
+ setTraits(lastAttributes, space, SUBSET_BOX);
+ setTraits(lastAttributes, space, SUBSET_COLOR);
+ space.setOffset(offset);
Area parent = (Area)areaStack.peek();
parent.addChildArea(space);
}
String txt = content.toString();
Character ch = new Character(txt.charAt(0));
setAreaAttributes(lastAttributes, ch);
- setTraits(lastAttributes, ch);
+ setTraits(lastAttributes, ch, SUBSET_COMMON);
+ setTraits(lastAttributes, ch, SUBSET_BOX);
+ setTraits(lastAttributes, ch, SUBSET_COLOR);
+ setTraits(lastAttributes, ch, SUBSET_FONT);
ch.setOffset(getAttributeAsInteger(lastAttributes, "offset", 0));
ch.setBaselineOffset(getAttributeAsInteger(lastAttributes, "baseline", 0));
Area parent = (Area)areaStack.peek();
area.setIPD(Integer.parseInt(attributes.getValue("ipd")));
area.setBPD(Integer.parseInt(attributes.getValue("bpd")));
}
+
+ private static final Object[] SUBSET_COMMON = new Object[] {
+ Trait.PROD_ID};
+ private static final Object[] SUBSET_LINK = new Object[] {
+ Trait.INTERNAL_LINK, Trait.EXTERNAL_LINK};
+ private static final Object[] SUBSET_COLOR = new Object[] {
+ Trait.BACKGROUND, Trait.COLOR};
+ private static final Object[] SUBSET_FONT = new Object[] {
+ Trait.FONT, Trait.FONT_SIZE, Trait.BLINK,
+ Trait.OVERLINE, Trait.OVERLINE_COLOR,
+ Trait.LINETHROUGH, Trait.LINETHROUGH_COLOR,
+ Trait.UNDERLINE, Trait.UNDERLINE_COLOR};
+ private static final Object[] SUBSET_BOX = new Object[] {
+ Trait.BORDER_BEFORE, Trait.BORDER_AFTER, Trait.BORDER_START, Trait.BORDER_END,
+ Trait.SPACE_BEFORE, Trait.SPACE_AFTER, Trait.SPACE_START, Trait.SPACE_END,
+ Trait.PADDING_BEFORE, Trait.PADDING_AFTER, Trait.PADDING_START, Trait.PADDING_END,
+ Trait.START_INDENT, Trait.END_INDENT,
+ Trait.IS_REFERENCE_AREA, Trait.IS_VIEWPORT_AREA};
- private void setTraits(Attributes attributes, Area area) {
- for (int i = 0, c = Trait.TRAIT_LIST.length; i < c; i++) {
- Object trait = Trait.TRAIT_LIST[i];
- Class cl = Trait.getTraitClass(trait);
- if (cl == Boolean.class) {
- String value = attributes.getValue(Trait.getTraitName(trait));
- if (value != null) {
- area.addTrait(trait, Boolean.valueOf(value));
- }
- } else if (cl == Integer.class) {
- String value = attributes.getValue(Trait.getTraitName(trait));
- if (value != null) {
- area.addTrait(trait, new Integer(value));
- }
- } else if (cl == String.class) {
- String value = attributes.getValue(Trait.getTraitName(trait));
- if (value != null) {
- area.addTrait(trait, value);
- }
- } else if (cl == FontTriplet.class) {
- String fontName = attributes.getValue("font-name");
- if (fontName != null) {
- String fontStyle = attributes.getValue("font-style");
- int fontWeight = getAttributeAsInteger(
- attributes, "font-weight", Font.NORMAL);
- area.addTrait(trait,
- new FontTriplet(fontName, fontStyle, fontWeight));
- }
- } else if (cl == Color.class) {
- String value = attributes.getValue(Trait.getTraitName(trait));
- if (value != null) {
- area.addTrait(trait, Color.valueOf(value));
- }
- } else if (cl == Background.class) {
- String value = attributes.getValue(Trait.getTraitName(trait));
- if (value != null) {
- Background bkg = new Background();
- Color col = Color.valueOf(attributes.getValue("bkg-color"));
- if (col != null) {
- bkg.setColor(col);
- }
- String url = attributes.getValue("bkg-img");
- if (url != null) {
- bkg.setURL(url);
-
- ImageFactory fact = ImageFactory.getInstance();
- FopImage img = fact.getImage(url, userAgent);
- if (img == null) {
- log.error("Background image not available: " + url);
- } else {
- // load dimensions
- if (!img.load(FopImage.DIMENSIONS)) {
- log.error("Cannot read background image dimensions: "
- + url);
- }
+ private void setTraits(Attributes attributes, Area area, Object[] traitSubset) {
+ for (int i = 0, c = traitSubset.length; i < c; i++) {
+ Object trait = traitSubset[i];
+ String traitName = Trait.getTraitName(trait);
+ String value = attributes.getValue(traitName);
+ if (value != null) {
+ Class cl = Trait.getTraitClass(trait);
+ if (cl == Integer.class) {
+ //if (value != null) {
+ area.addTrait(trait, new Integer(value));
+ //}
+ } else if (cl == Boolean.class) {
+ //String value = attributes.getValue(Trait.getTraitName(trait));
+ //if (value != null) {
+ area.addTrait(trait, Boolean.valueOf(value));
+ //}
+ } else if (cl == String.class) {
+ //String value = attributes.getValue(Trait.getTraitName(trait));
+ //if (value != null) {
+ area.addTrait(trait, value);
+ //}
+ } else if (cl == Color.class) {
+ //String value = attributes.getValue(Trait.getTraitName(trait));
+ //if (value != null) {
+ area.addTrait(trait, Color.valueOf(value));
+ //}
+ } else if (cl == Background.class) {
+ //String value = attributes.getValue(Trait.getTraitName(trait));
+ //if (value != null) {
+ Background bkg = new Background();
+ Color col = Color.valueOf(attributes.getValue("bkg-color"));
+ if (col != null) {
+ bkg.setColor(col);
}
- bkg.setFopImage(img);
-
- String repeat = attributes.getValue("bkg-repeat");
- if (repeat != null) {
- bkg.setRepeat(repeat);
+ String url = attributes.getValue("bkg-img");
+ if (url != null) {
+ bkg.setURL(url);
+
+ ImageFactory fact = ImageFactory.getInstance();
+ FopImage img = fact.getImage(url, userAgent);
+ if (img == null) {
+ log.error("Background image not available: " + url);
+ } else {
+ // load dimensions
+ if (!img.load(FopImage.DIMENSIONS)) {
+ log.error("Cannot read background image dimensions: "
+ + url);
+ }
+ }
+ bkg.setFopImage(img);
+
+ String repeat = attributes.getValue("bkg-repeat");
+ if (repeat != null) {
+ bkg.setRepeat(repeat);
+ }
+ bkg.setHoriz(getAttributeAsInteger(attributes,
+ "bkg-horz-offset", 0));
+ bkg.setVertical(getAttributeAsInteger(attributes,
+ "bkg-vert-offset", 0));
}
- bkg.setHoriz(getAttributeAsInteger(attributes,
- "bkg-horz-offset", 0));
- bkg.setVertical(getAttributeAsInteger(attributes,
- "bkg-vert-offset", 0));
- }
- area.addTrait(trait, bkg);
+ area.addTrait(trait, bkg);
+ //}
+ } else if (cl == BorderProps.class) {
+ //String value = attributes.getValue(Trait.getTraitName(trait));
+ //if (value != null) {
+ area.addTrait(trait, BorderProps.valueOf(value));
+ //}
}
- } else if (cl == BorderProps.class) {
- String value = attributes.getValue(Trait.getTraitName(trait));
- if (value != null) {
- area.addTrait(trait, BorderProps.valueOf(value));
+ } else {
+ Class cl = Trait.getTraitClass(trait);
+ if (cl == FontTriplet.class) {
+ String fontName = attributes.getValue("font-name");
+ if (fontName != null) {
+ String fontStyle = attributes.getValue("font-style");
+ int fontWeight = getAttributeAsInteger(
+ attributes, "font-weight", Font.NORMAL);
+ area.addTrait(trait,
+ new FontTriplet(fontName, fontStyle, fontWeight));
+ }
}
}
}
package org.apache.fop.area;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
import org.apache.fop.datatypes.ColorType;
import org.apache.fop.fo.Constants;
import org.apache.fop.fonts.FontTriplet;
import org.apache.fop.traits.BorderProps;
import java.io.Serializable;
-import java.util.Map;
-import java.util.HashMap;
-import java.util.Iterator;
// properties should be serialized by the holder
/**
*/
public class Trait implements Serializable {
- /** Logger instance */
- private static Log log = LogFactory.getLog(Trait.class);
-
/**
* Id reference line, not resolved.
* not sure if this is needed.
*/
- public static final Integer ID_LINK = new Integer(0);
+ //public static final Integer ID_LINK = new Integer(0);
/**
* Internal link trait.
/**
* Shadow offset.
*/
- public static final Integer OFFSET = new Integer(13);
+ //public static final Integer OFFSET = new Integer(13);
/**
* The shadow for text.
*/
- public static final Integer SHADOW = new Integer(14);
+ //public static final Integer SHADOW = new Integer(14);
/**
* The border start.
/**
* break before
*/
- public static final Integer BREAK_BEFORE = new Integer(25);
+ //public static final Integer BREAK_BEFORE = new Integer(25);
/**
* break after
*/
- public static final Integer BREAK_AFTER = new Integer(26);
+ //public static final Integer BREAK_AFTER = new Integer(26);
/**
* The start-indent trait.
/** Trait for color of linethrough decorations when rendering inline parent. */
public static final Integer LINETHROUGH_COLOR = new Integer(36);
- private static final Map TRAIT_INFO = new HashMap();
+ /** Maximum value used by trait keys */
+ public static final int MAX_TRAIT_KEY = 36;
+
+ private static final TraitInfo[] TRAIT_INFO = new TraitInfo[MAX_TRAIT_KEY + 1];
- /** The list of simple traits in order to avoid iterators */
- public static final Object[] TRAIT_LIST;
-
private static class TraitInfo {
private String name;
private Class clazz; // Class of trait data
}
}
+ private static void put(Integer key, TraitInfo info) {
+ TRAIT_INFO[key.intValue()] = info;
+ }
+
static {
// Create a hashmap mapping trait code to name for external representation
- TRAIT_INFO.put(ID_LINK, new TraitInfo("id-link", String.class));
- TRAIT_INFO.put(INTERNAL_LINK,
- new TraitInfo("internal-link", String.class));
- TRAIT_INFO.put(EXTERNAL_LINK,
- new TraitInfo("external-link", String.class));
- TRAIT_INFO.put(FONT,
- new TraitInfo("font", FontTriplet.class));
- TRAIT_INFO.put(FONT_SIZE,
- new TraitInfo("font-size", Integer.class));
- TRAIT_INFO.put(COLOR, new TraitInfo("color", Color.class));
- TRAIT_INFO.put(PROD_ID, new TraitInfo("prod-id", String.class));
- TRAIT_INFO.put(BACKGROUND,
- new TraitInfo("background", Background.class));
- TRAIT_INFO.put(UNDERLINE,
- new TraitInfo("underline-score", Boolean.class));
- TRAIT_INFO.put(UNDERLINE_COLOR, new TraitInfo("underline-score-color", Color.class));
- TRAIT_INFO.put(OVERLINE,
- new TraitInfo("overline-score", Boolean.class));
- TRAIT_INFO.put(OVERLINE_COLOR, new TraitInfo("overline-score-color", Color.class));
- TRAIT_INFO.put(LINETHROUGH,
- new TraitInfo("through-score", Boolean.class));
- TRAIT_INFO.put(LINETHROUGH_COLOR, new TraitInfo("through-score-color", Color.class));
- TRAIT_INFO.put(BLINK,
- new TraitInfo("blink", Boolean.class));
- TRAIT_INFO.put(OFFSET, new TraitInfo("offset", Integer.class));
- TRAIT_INFO.put(SHADOW, new TraitInfo("shadow", Integer.class));
- TRAIT_INFO.put(BORDER_START,
+ //put(ID_LINK, new TraitInfo("id-link", String.class));
+ put(INTERNAL_LINK, new TraitInfo("internal-link", String.class));
+ put(EXTERNAL_LINK, new TraitInfo("external-link", String.class));
+ put(FONT, new TraitInfo("font", FontTriplet.class));
+ put(FONT_SIZE, new TraitInfo("font-size", Integer.class));
+ put(COLOR, new TraitInfo("color", Color.class));
+ put(PROD_ID, new TraitInfo("prod-id", String.class));
+ put(BACKGROUND, new TraitInfo("background", Background.class));
+ put(UNDERLINE, new TraitInfo("underline-score", Boolean.class));
+ put(UNDERLINE_COLOR, new TraitInfo("underline-score-color", Color.class));
+ put(OVERLINE, new TraitInfo("overline-score", Boolean.class));
+ put(OVERLINE_COLOR, new TraitInfo("overline-score-color", Color.class));
+ put(LINETHROUGH, new TraitInfo("through-score", Boolean.class));
+ put(LINETHROUGH_COLOR, new TraitInfo("through-score-color", Color.class));
+ put(BLINK, new TraitInfo("blink", Boolean.class));
+ //put(OFFSET, new TraitInfo("offset", Integer.class));
+ //put(SHADOW, new TraitInfo("shadow", Integer.class));
+ put(BORDER_START,
new TraitInfo("border-start", BorderProps.class));
- TRAIT_INFO.put(BORDER_END,
+ put(BORDER_END,
new TraitInfo("border-end", BorderProps.class));
- TRAIT_INFO.put(BORDER_BEFORE,
+ put(BORDER_BEFORE,
new TraitInfo("border-before", BorderProps.class));
- TRAIT_INFO.put(BORDER_AFTER,
+ put(BORDER_AFTER,
new TraitInfo("border-after", BorderProps.class));
- TRAIT_INFO.put(PADDING_START,
+ put(PADDING_START,
new TraitInfo("padding-start", Integer.class));
- TRAIT_INFO.put(PADDING_END,
+ put(PADDING_END,
new TraitInfo("padding-end", Integer.class));
- TRAIT_INFO.put(PADDING_BEFORE,
+ put(PADDING_BEFORE,
new TraitInfo("padding-before", Integer.class));
- TRAIT_INFO.put(PADDING_AFTER,
+ put(PADDING_AFTER,
new TraitInfo("padding-after", Integer.class));
- TRAIT_INFO.put(SPACE_START,
+ put(SPACE_START,
new TraitInfo("space-start", Integer.class));
- TRAIT_INFO.put(SPACE_END,
+ put(SPACE_END,
new TraitInfo("space-end", Integer.class));
- TRAIT_INFO.put(BREAK_BEFORE,
- new TraitInfo("break-before", Integer.class));
- TRAIT_INFO.put(BREAK_AFTER,
- new TraitInfo("break-after", Integer.class));
- TRAIT_INFO.put(START_INDENT,
+ //put(BREAK_BEFORE,
+ // new TraitInfo("break-before", Integer.class));
+ //put(BREAK_AFTER,
+ // new TraitInfo("break-after", Integer.class));
+ put(START_INDENT,
new TraitInfo("start-indent", Integer.class));
- TRAIT_INFO.put(END_INDENT,
+ put(END_INDENT,
new TraitInfo("end-indent", Integer.class));
- TRAIT_INFO.put(SPACE_BEFORE,
+ put(SPACE_BEFORE,
new TraitInfo("space-before", Integer.class));
- TRAIT_INFO.put(SPACE_AFTER,
+ put(SPACE_AFTER,
new TraitInfo("space-after", Integer.class));
- TRAIT_INFO.put(IS_REFERENCE_AREA,
+ put(IS_REFERENCE_AREA,
new TraitInfo("is-reference-area", Boolean.class));
- TRAIT_INFO.put(IS_VIEWPORT_AREA,
+ put(IS_VIEWPORT_AREA,
new TraitInfo("is-viewport-area", Boolean.class));
- TRAIT_LIST = TRAIT_INFO.keySet().toArray();
}
/**
* @return the trait name
*/
public static String getTraitName(Object traitCode) {
- Object obj = TRAIT_INFO.get(traitCode);
- if (obj != null) {
- return ((TraitInfo) obj).getName();
- } else {
- return "unknown-trait-" + traitCode.toString();
- }
+ return TRAIT_INFO[((Integer)traitCode).intValue()].getName();
}
/**
* @param sTraitName the name of the trait to find
* @return the trait code object
*/
+ /*
public static Object getTraitCode(String sTraitName) {
Iterator iter = TRAIT_INFO.entrySet().iterator();
while (iter.hasNext()) {
}
}
return null;
- }
+ }*/
/**
* Get the data storage class for the trait.
*
- * @param oTraitCode the trait code to lookup
+ * @param traitCode the trait code to lookup
* @return the class type for the trait
*/
- public static Class getTraitClass(Object oTraitCode) {
- TraitInfo ti = (TraitInfo) TRAIT_INFO.get(oTraitCode);
- return (ti != null ? ti.getClazz() : null);
+ public static Class getTraitClass(Object traitCode) {
+ return TRAIT_INFO[((Integer)traitCode).intValue()].getClazz();
}
/**
* @param sTraitValue trait value as String
* @return the trait value as object
*/
+ /*
public static Object makeTraitValue(Object oCode, String sTraitValue) {
// Get the code from the name
// See what type of object it is
return null;
- }
+ }*/
/**
* Serializable ColorType implementation for the area tree.