From: Jeremias Maerki Date: Thu, 22 Dec 2005 10:51:29 +0000 (+0000) Subject: More work on preparing for the intermediate format. X-Git-Tag: fop-0_92-beta~272 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=e6f94a6d688b3150056a1b6842ae45a29b723923;p=xmlgraphics-fop.git More work on preparing for the intermediate format. Font traits are added in a single place in TraitSetter so it will be easier to change those. Remove direct references on FObjs in the area tree for regions. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@358555 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/java/org/apache/fop/area/BodyRegion.java b/src/java/org/apache/fop/area/BodyRegion.java index 1138f3089..565bab42d 100644 --- a/src/java/org/apache/fop/area/BodyRegion.java +++ b/src/java/org/apache/fop/area/BodyRegion.java @@ -42,9 +42,23 @@ public class BodyRegion extends RegionReference { * @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); } @@ -127,7 +141,8 @@ public class BodyRegion extends RegionReference { * @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; diff --git a/src/java/org/apache/fop/area/RegionReference.java b/src/java/org/apache/fop/area/RegionReference.java index 901276da0..b643db4dc 100644 --- a/src/java/org/apache/fop/area/RegionReference.java +++ b/src/java/org/apache/fop/area/RegionReference.java @@ -31,14 +31,16 @@ import org.apache.fop.fo.pagination.Region; 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; /** @@ -48,7 +50,19 @@ public class RegionReference extends Area implements Cloneable { * @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; } @@ -97,12 +111,12 @@ public class RegionReference extends Area implements Cloneable { * @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; } /** @@ -121,7 +135,7 @@ public class RegionReference extends Area implements Cloneable { * @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(); diff --git a/src/java/org/apache/fop/area/inline/UnresolvedPageNumber.java b/src/java/org/apache/fop/area/inline/UnresolvedPageNumber.java index 630d73ecf..99978e7c6 100644 --- a/src/java/org/apache/fop/area/inline/UnresolvedPageNumber.java +++ b/src/java/org/apache/fop/area/inline/UnresolvedPageNumber.java @@ -77,9 +77,14 @@ public class UnresolvedPageNumber extends TextArea implements Resolvable { 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."); + } } } diff --git a/src/java/org/apache/fop/layoutmgr/Page.java b/src/java/org/apache/fop/layoutmgr/Page.java index 568defb0b..e33230c68 100644 --- a/src/java/org/apache/fop/layoutmgr/Page.java +++ b/src/java/org/apache/fop/layoutmgr/Page.java @@ -32,15 +32,23 @@ public class Page { 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; } diff --git a/src/java/org/apache/fop/layoutmgr/TraitSetter.java b/src/java/org/apache/fop/layoutmgr/TraitSetter.java index e67075976..482373ad7 100644 --- a/src/java/org/apache/fop/layoutmgr/TraitSetter.java +++ b/src/java/org/apache/fop/layoutmgr/TraitSetter.java @@ -31,6 +31,7 @@ import org.apache.fop.fo.Constants; 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. @@ -443,6 +444,11 @@ public class TraitSetter { 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 diff --git a/src/java/org/apache/fop/layoutmgr/inline/CharacterLayoutManager.java b/src/java/org/apache/fop/layoutmgr/inline/CharacterLayoutManager.java index d51b2fa15..302e82c26 100644 --- a/src/java/org/apache/fop/layoutmgr/inline/CharacterLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/inline/CharacterLayoutManager.java @@ -97,8 +97,7 @@ public class CharacterLayoutManager extends LeafNodeLayoutManager { 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 diff --git a/src/java/org/apache/fop/layoutmgr/inline/LeaderLayoutManager.java b/src/java/org/apache/fop/layoutmgr/inline/LeaderLayoutManager.java index 5ee42bac8..44009ed51 100644 --- a/src/java/org/apache/fop/layoutmgr/inline/LeaderLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/inline/LeaderLayoutManager.java @@ -135,8 +135,7 @@ public class LeaderLayoutManager extends LeafNodeLayoutManager { 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) { diff --git a/src/java/org/apache/fop/layoutmgr/inline/PageNumberCitationLayoutManager.java b/src/java/org/apache/fop/layoutmgr/inline/PageNumberCitationLayoutManager.java index 37f23c947..79c2d487d 100644 --- a/src/java/org/apache/fop/layoutmgr/inline/PageNumberCitationLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/inline/PageNumberCitationLayoutManager.java @@ -119,8 +119,7 @@ public class PageNumberCitationLayoutManager extends LeafNodeLayoutManager { 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()); diff --git a/src/java/org/apache/fop/layoutmgr/inline/PageNumberLayoutManager.java b/src/java/org/apache/fop/layoutmgr/inline/PageNumberLayoutManager.java index 09daeb212..39a8d08ec 100644 --- a/src/java/org/apache/fop/layoutmgr/inline/PageNumberLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/inline/PageNumberLayoutManager.java @@ -78,9 +78,7 @@ public class PageNumberLayoutManager extends LeafNodeLayoutManager { 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()); @@ -100,7 +98,7 @@ public class PageNumberLayoutManager extends LeafNodeLayoutManager { 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; diff --git a/src/java/org/apache/fop/layoutmgr/inline/TextLayoutManager.java b/src/java/org/apache/fop/layoutmgr/inline/TextLayoutManager.java index b9730b583..4816f5c02 100644 --- a/src/java/org/apache/fop/layoutmgr/inline/TextLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/inline/TextLayoutManager.java @@ -444,8 +444,7 @@ public class TextLayoutManager extends LeafNodeLayoutManager { } } } - 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());