* @param parent the parent region viewport
*/
public BodyRegion(RegionBody rb, RegionViewport parent) {
- super(rb, parent);
- this.columnCount = rb.getColumnCount();
- this.columnGap = rb.getColumnGap();
+ this(rb.getNameId(), rb.getRegionName(), parent, rb.getColumnCount(), rb.getColumnGap());
+ }
+
+ /**
+ * Constructor which can read traits directly
+ * from an fo:region-body formatting object.
+ * @param regionClass the region class (as returned by Region.getNameId())
+ * @param regionName the name of the region (as returned by Region.getRegionName())
+ * @param parent the parent region viewport
+ * @param columnCount the number of columns
+ * @param columnGap the gap between columns
+ */
+ public BodyRegion(int regionClass, String regionName, RegionViewport parent,
+ int columnCount, int columnGap) {
+ super(regionClass, regionName, parent);
+ this.columnCount = columnCount;
+ this.columnGap = columnGap;
mainReference = new MainReference(this);
}
* @return a shallow copy of this object
*/
public Object clone() {
- BodyRegion br = new BodyRegion((RegionBody) regionFO, regionViewport);
+ BodyRegion br = new BodyRegion(getRegionClass(), getRegionName(), regionViewport,
+ getColumnCount(), getColumnGap());
br.setCTM(getCTM());
br.setIPD(getIPD());
br.beforeFloat = beforeFloat;
public class RegionReference extends Area implements Cloneable {
/** Reference to the region FO. */
- protected Region regionFO;
+ //protected Region regionFO;
+ private int regionClass;
+ private String regionName;
private CTM ctm;
// the list of block areas from the static flow
private ArrayList blocks = new ArrayList();
- // the parent RegionViewport for this object
+ /** the parent RegionViewport for this object */
protected RegionViewport regionViewport;
/**
* @param parent the viewport for this region.
*/
public RegionReference(Region regionFO, RegionViewport parent) {
- this.regionFO = regionFO;
+ this(regionFO.getNameId(), regionFO.getRegionName(), parent);
+ }
+
+ /**
+ * Create a new region reference area.
+ *
+ * @param regionClass the region class (as returned by Region.getNameId())
+ * @param regionName the name of the region (as returned by Region.getRegionName())
+ * @param parent the viewport for this region.
+ */
+ public RegionReference(int regionClass, String regionName, RegionViewport parent) {
+ this.regionClass = regionClass;
+ this.regionName = regionName;
addTrait(Trait.IS_REFERENCE_AREA, Boolean.TRUE);
regionViewport = parent;
}
* @return the region class
*/
public int getRegionClass() {
- return regionFO.getNameId();
+ return this.regionClass;
}
/** @return the region name */
public String getRegionName() {
- return regionFO.getRegionName();
+ return this.regionName;
}
/**
* @return a copy of this region reference area
*/
public Object clone() {
- RegionReference rr = new RegionReference(regionFO, regionViewport);
+ RegionReference rr = new RegionReference(regionClass, regionName, regionViewport);
rr.ctm = ctm;
rr.setIPD(getIPD());
rr.blocks = (ArrayList)blocks.clone();
removeText();
addWord(page.getPageNumberString(), 0);
// update ipd
- updateIPD(font.getWordWidth(text));
- // set the Font object to null, as we don't need it any more
- font = null;
+ if (font != null) {
+ updateIPD(font.getWordWidth(text));
+ // set the Font object to null, as we don't need it any more
+ font = null;
+ } else {
+ log.warn("Cannot update the IPD of an unresolved page number."
+ + " No font information avilable.");
+ }
}
}
private SimplePageMaster spm;
private PageViewport pageViewport;
- public Page(SimplePageMaster spm, String pageStr, boolean blank) {
+ /**
+ * Main constructor
+ * @param spm the simple-page-master used for this page
+ * @param pageNumberStr the page number (as a String)
+ * @param blank true if this is a blank page
+ */
+ public Page(SimplePageMaster spm, String pageNumberStr, boolean blank) {
this.spm = spm;
- this.pageViewport = new PageViewport(spm, pageStr, blank);
+ this.pageViewport = new PageViewport(spm, pageNumberStr, blank);
}
+ /** @return the simple-page-master that created this page */
public SimplePageMaster getSimplePageMaster() {
return this.spm;
}
+ /** @return the page viewport representing this page in the area tree */
public PageViewport getPageViewport() {
return this.pageViewport;
}
import org.apache.fop.fo.properties.CommonMarginBlock;
import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
import org.apache.fop.fo.properties.CommonTextDecoration;
+import org.apache.fop.fonts.Font;
/**
* This is a helper class used for setting common traits on areas.
area.addTrait(Trait.BREAK_BEFORE, new Integer(breakBefore));
}
+ public static void addFontTraits(Area area, Font font) {
+ area.addTrait(Trait.FONT_NAME, font.getFontName());
+ area.addTrait(Trait.FONT_SIZE, new Integer(font.getFontSize()));
+ }
+
/**
* Adds the text-decoration traits to the area.
* @param area the area to set the traits on
curArea.setIPD(ipd.opt);
curArea.setBPD(font.getAscender() - font.getDescender());
- curArea.addTrait(Trait.FONT_NAME, font.getFontName());
- curArea.addTrait(Trait.FONT_SIZE, new Integer(font.getFontSize()));
+ TraitSetter.addFontTraits(curArea, font);
curArea.addTrait(Trait.COLOR, fobj.getColor());
// TODO: may need some special handling for fo:character
t.setIPD(width);
t.setBPD(width);
t.setBaselineOffset(width);
- t.addTrait(Trait.FONT_NAME, font.getFontName());
- t.addTrait(Trait.FONT_SIZE, new Integer(font.getFontSize()));
+ TraitSetter.addFontTraits(t, font);
t.addTrait(Trait.COLOR, fobj.getColor());
Space spacer = null;
if (fobj.getLeaderPatternWidth().getValue(this) > width) {
TraitSetter.setProducerID(inline, fobj.getId());
inline.setBPD(font.getAscender() - font.getDescender());
inline.setBaselineOffset(font.getAscender());
- inline.addTrait(Trait.FONT_NAME, font.getFontName());
- inline.addTrait(Trait.FONT_SIZE, new Integer(font.getFontSize()));
+ TraitSetter.addFontTraits(inline, font);
inline.addTrait(Trait.COLOR, fobj.getColor());
TraitSetter.addTextDecoration(inline, fobj.getTextDecoration());
text.setIPD(width);
text.setBPD(font.getAscender() - font.getDescender());
text.setBaselineOffset(font.getAscender());
- text.addTrait(Trait.FONT_NAME, font.getFontName());
- text.addTrait(Trait.FONT_SIZE,
- new Integer(font.getFontSize()));
+ TraitSetter.addFontTraits(text, font);
text.addTrait(Trait.COLOR, fobj.getColor());
TraitSetter.addTextDecoration(text, fobj.getTextDecoration());
ta.setBPD(baseArea.getBPD());
ta.setOffset(baseArea.getOffset());
ta.setBaselineOffset(baseArea.getBaselineOffset());
- ta.addTrait(Trait.FONT_NAME, font.getFontName()); //only to initialize the trait map
+ ta.addTrait(Trait.COLOR, fobj.getColor()); //only to initialize the trait map
ta.getTraits().putAll(baseArea.getTraits());
updateContent(ta);
return ta;
}
}
}
- textArea.addTrait(Trait.FONT_NAME, font.getFontName());
- textArea.addTrait(Trait.FONT_SIZE, new Integer(font.getFontSize()));
+ TraitSetter.addFontTraits(textArea, font);
textArea.addTrait(Trait.COLOR, foText.getColor());
TraitSetter.addTextDecoration(textArea, foText.getTextDecoration());