From 5d9d387dc7d2a1272aa336d9740e7d2a6ced7d7f Mon Sep 17 00:00:00 2001 From: Jeremias Maerki Date: Tue, 26 Jul 2005 13:31:53 +0000 Subject: [PATCH] Various fixes for ID management. Border/Padding/Background for instream-foreign-object and external-graphic. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@225304 13f79535-47bb-0310-9956-ffa450edef68 --- .../layoutmgr/PageSequenceLayoutManager.java | 1 + .../inline/CharacterLayoutManager.java | 1 + .../inline/ExternalGraphicLayoutManager.java | 35 +++++++++++++++++-- .../layoutmgr/inline/InlineLayoutManager.java | 25 ++++++++++++- .../inline/InlineStackingLayoutManager.java | 9 +++++ .../inline/InstreamForeignObjectLM.java | 30 +++++++++++++++- .../layoutmgr/inline/LeaderLayoutManager.java | 2 ++ .../inline/LeafNodeLayoutManager.java | 4 +++ .../PageNumberCitationLayoutManager.java | 1 + .../inline/PageNumberLayoutManager.java | 1 + 10 files changed, 105 insertions(+), 4 deletions(-) diff --git a/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java b/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java index 493cac7d8..fd0cfe8cc 100644 --- a/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java @@ -137,6 +137,7 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager { curPV = makeNewPage(false, false); + addIDToPage(pageSeq.getId()); Flow mainFlow = pageSeq.getMainFlow(); childFLM = getLayoutManagerMaker(). makeFlowLayoutManager(this, mainFlow); diff --git a/src/java/org/apache/fop/layoutmgr/inline/CharacterLayoutManager.java b/src/java/org/apache/fop/layoutmgr/inline/CharacterLayoutManager.java index 6d5a26f36..498d0ed0b 100644 --- a/src/java/org/apache/fop/layoutmgr/inline/CharacterLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/inline/CharacterLayoutManager.java @@ -67,6 +67,7 @@ public class CharacterLayoutManager extends LeafNodeLayoutManager { private InlineArea getCharacterInlineArea(Character node) { org.apache.fop.area.inline.Character ch = new org.apache.fop.area.inline.Character(node.getCharacter()); + TraitSetter.setProducerID(ch, node.getId()); TraitSetter.addTextDecoration(ch, fobj.getTextDecoration()); return ch; } diff --git a/src/java/org/apache/fop/layoutmgr/inline/ExternalGraphicLayoutManager.java b/src/java/org/apache/fop/layoutmgr/inline/ExternalGraphicLayoutManager.java index a0196f8d4..2be4ea14f 100644 --- a/src/java/org/apache/fop/layoutmgr/inline/ExternalGraphicLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/inline/ExternalGraphicLayoutManager.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2004 The Apache Software Foundation. + * Copyright 1999-2005 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,6 +27,7 @@ import org.apache.fop.area.inline.InlineArea; import org.apache.fop.area.inline.Viewport; import org.apache.fop.datatypes.Length; import org.apache.fop.fo.flow.ExternalGraphic; +import org.apache.fop.fo.properties.CommonBorderPaddingBackground; import org.apache.fop.layoutmgr.TraitSetter; /** @@ -183,6 +184,33 @@ public class ExternalGraphicLayoutManager extends LeafNodeLayoutManager { default: break; } + + + CommonBorderPaddingBackground borderProps = fobj.getCommonBorderPaddingBackground(); + + //Determine extra BPD from borders etc. + int beforeBPD = borderProps.getPadding(CommonBorderPaddingBackground.BEFORE, false); + beforeBPD += borderProps.getBorderWidth(CommonBorderPaddingBackground.BEFORE, + false); + int afterBPD = borderProps.getPadding(CommonBorderPaddingBackground.AFTER, false); + afterBPD += borderProps.getBorderWidth(CommonBorderPaddingBackground.AFTER, false); + + yoffset += beforeBPD; + viewHeight += beforeBPD; + viewHeight += afterBPD; + + //Determine extra IPD from borders etc. + int startIPD = borderProps.getPadding(CommonBorderPaddingBackground.START, + false/*bNotFirst*/); + startIPD += borderProps.getBorderWidth(CommonBorderPaddingBackground.START, + false/*bNotFirst*/); + int endIPD = borderProps.getPadding(CommonBorderPaddingBackground.END, false/*bNotLast*/); + endIPD += borderProps.getBorderWidth(CommonBorderPaddingBackground.END, false/*bNotLast*/); + + xoffset += startIPD; + viewWidth += startIPD; + viewWidth += endIPD; + placement = new Rectangle2D.Float(xoffset, yoffset, cwidth, cheight); } @@ -194,7 +222,9 @@ public class ExternalGraphicLayoutManager extends LeafNodeLayoutManager { */ public InlineArea getExternalGraphicInlineArea() { Image imArea = new Image(fobj.getSrc()); + TraitSetter.setProducerID(imArea, fobj.getId()); Viewport vp = new Viewport(imArea); + TraitSetter.setProducerID(vp, fobj.getId()); vp.setIPD(viewWidth); vp.setBPD(viewHeight); vp.setClip(clip); @@ -208,7 +238,8 @@ public class ExternalGraphicLayoutManager extends LeafNodeLayoutManager { return vp; } - protected void addId() { + /** @see org.apache.fop.layoutmgr.inline.LeafNodeLayoutManager#addId() */ + protected void addId() { getPSLM().addIDToPage(fobj.getId()); } } diff --git a/src/java/org/apache/fop/layoutmgr/inline/InlineLayoutManager.java b/src/java/org/apache/fop/layoutmgr/inline/InlineLayoutManager.java index 76222cf11..7f0943a9f 100755 --- a/src/java/org/apache/fop/layoutmgr/inline/InlineLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/inline/InlineLayoutManager.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2004 The Apache Software Foundation. + * Copyright 1999-2005 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,6 +21,8 @@ package org.apache.fop.layoutmgr.inline; import java.util.ListIterator; import java.util.LinkedList; +import org.apache.fop.area.inline.InlineParent; +import org.apache.fop.fo.flow.Inline; import org.apache.fop.fo.flow.InlineLevel; import org.apache.fop.fo.properties.CommonBorderPaddingBackground; import org.apache.fop.fo.properties.CommonMarginInline; @@ -58,6 +60,10 @@ public class InlineLayoutManager extends InlineStackingLayoutManager initialize(); } + private Inline getInlineFO() { + return (Inline)fobj; + } + private void initialize() { inlineProps = fobj.getCommonMarginInline(); borderProps = fobj.getCommonBorderPaddingBackground(); @@ -102,6 +108,16 @@ public class InlineLayoutManager extends InlineStackingLayoutManager return inlineProps.spaceEnd; } + /** @see org.apache.fop.layoutmgr.inline.InlineStackingLayoutManager#createArea() */ + protected InlineParent createArea() { + InlineParent area = super.createArea(); + TraitSetter.setProducerID(area, getInlineFO().getId()); + return area; + } + + /** + * @see org.apache.fop.layoutmgr.inline.InlineStackingLayoutManager#setTraits(boolean, boolean) + */ protected void setTraits(boolean bNotFirst, boolean bNotLast) { // Add border and padding to current area and set flags (FIRST, LAST ...) @@ -114,6 +130,7 @@ public class InlineLayoutManager extends InlineStackingLayoutManager } } + /** @see org.apache.fop.layoutmgr.LayoutManager */ public LinkedList getNextKnuthElements(LayoutContext lc, int alignment) { InlineLevelLayoutManager curLM; @@ -314,5 +331,11 @@ public class InlineLayoutManager extends InlineStackingLayoutManager } return returnList; }*/ + + /** @see org.apache.fop.layoutmgr.inline.LeafNodeLayoutManager#addId() */ + protected void addId() { + getPSLM().addIDToPage(getInlineFO().getId()); + } + } diff --git a/src/java/org/apache/fop/layoutmgr/inline/InlineStackingLayoutManager.java b/src/java/org/apache/fop/layoutmgr/inline/InlineStackingLayoutManager.java index 28be05277..0b05cc8aa 100644 --- a/src/java/org/apache/fop/layoutmgr/inline/InlineStackingLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/inline/InlineStackingLayoutManager.java @@ -181,6 +181,14 @@ public class InlineStackingLayoutManager extends AbstractLayoutManager return new InlineParent(); } + /** + * This method is called by addAreas() so IDs can be added to a page for FOs that + * support the 'id' property. + */ + protected void addId() { + // Do nothing here, overriden in subclasses that have an 'id' property. + } + /** * Generate and add areas to parent area. * Set size of each area. This should only create and return one @@ -193,6 +201,7 @@ public class InlineStackingLayoutManager extends AbstractLayoutManager */ public void addAreas(PositionIterator parentIter, LayoutContext context) { + addId(); InlineParent parent = createArea(); parent.setBPD(context.getLineHeight()); parent.setOffset(0); diff --git a/src/java/org/apache/fop/layoutmgr/inline/InstreamForeignObjectLM.java b/src/java/org/apache/fop/layoutmgr/inline/InstreamForeignObjectLM.java index 3b88ac0b1..e0d06dcb5 100644 --- a/src/java/org/apache/fop/layoutmgr/inline/InstreamForeignObjectLM.java +++ b/src/java/org/apache/fop/layoutmgr/inline/InstreamForeignObjectLM.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2004 The Apache Software Foundation. + * Copyright 1999-2005 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,6 +25,7 @@ import java.awt.geom.Rectangle2D; import org.apache.fop.datatypes.Length; import org.apache.fop.fo.XMLObj; import org.apache.fop.fo.flow.InstreamForeignObject; +import org.apache.fop.fo.properties.CommonBorderPaddingBackground; import org.apache.fop.layoutmgr.TraitSetter; import org.apache.fop.area.inline.ForeignObject; import org.apache.fop.area.inline.Viewport; @@ -168,6 +169,31 @@ public class InstreamForeignObjectLM extends LeafNodeLayoutManager { int xoffset = fobj.computeXOffset(ipd, cwidth); int yoffset = fobj.computeYOffset(bpd, cheight); + CommonBorderPaddingBackground borderProps = fobj.getCommonBorderPaddingBackground(); + + //Determine extra BPD from borders etc. + int beforeBPD = borderProps.getPadding(CommonBorderPaddingBackground.BEFORE, false); + beforeBPD += borderProps.getBorderWidth(CommonBorderPaddingBackground.BEFORE, + false); + int afterBPD = borderProps.getPadding(CommonBorderPaddingBackground.AFTER, false); + afterBPD += borderProps.getBorderWidth(CommonBorderPaddingBackground.AFTER, false); + + yoffset += beforeBPD; + bpd += beforeBPD; + bpd += afterBPD; + + //Determine extra IPD from borders etc. + int startIPD = borderProps.getPadding(CommonBorderPaddingBackground.START, + false/*bNotFirst*/); + startIPD += borderProps.getBorderWidth(CommonBorderPaddingBackground.START, + false/*bNotFirst*/); + int endIPD = borderProps.getPadding(CommonBorderPaddingBackground.END, false/*bNotLast*/); + endIPD += borderProps.getBorderWidth(CommonBorderPaddingBackground.END, false/*bNotLast*/); + + xoffset += startIPD; + ipd += startIPD; + ipd += endIPD; + Rectangle2D placement = new Rectangle2D.Float(xoffset, yoffset, cwidth, cheight); org.w3c.dom.Document doc = child.getDOMDocument(); @@ -175,8 +201,10 @@ public class InstreamForeignObjectLM extends LeafNodeLayoutManager { //fobj.childNodes = null; This is bad for i-f-o in static-content!!!!! ForeignObject foreign = new ForeignObject(doc, ns); + TraitSetter.setProducerID(foreign, fobj.getId()); Viewport vp = new Viewport(foreign); + TraitSetter.setProducerID(vp, fobj.getId()); vp.setIPD(ipd); vp.setBPD(bpd); vp.setContentPosition(placement); diff --git a/src/java/org/apache/fop/layoutmgr/inline/LeaderLayoutManager.java b/src/java/org/apache/fop/layoutmgr/inline/LeaderLayoutManager.java index 0bfa38810..8dc2481c8 100644 --- a/src/java/org/apache/fop/layoutmgr/inline/LeaderLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/inline/LeaderLayoutManager.java @@ -34,6 +34,7 @@ import org.apache.fop.layoutmgr.LayoutContext; import org.apache.fop.layoutmgr.LeafPosition; import org.apache.fop.layoutmgr.Position; import org.apache.fop.layoutmgr.PositionIterator; +import org.apache.fop.layoutmgr.TraitSetter; import org.apache.fop.traits.MinOptMax; import java.util.List; @@ -151,6 +152,7 @@ public class LeaderLayoutManager extends LeafNodeLayoutManager { } leaderArea = fa; } + TraitSetter.setProducerID(leaderArea, fobj.getId()); return leaderArea; } diff --git a/src/java/org/apache/fop/layoutmgr/inline/LeafNodeLayoutManager.java b/src/java/org/apache/fop/layoutmgr/inline/LeafNodeLayoutManager.java index 7fe310fe2..1bd06564c 100644 --- a/src/java/org/apache/fop/layoutmgr/inline/LeafNodeLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/inline/LeafNodeLayoutManager.java @@ -193,6 +193,10 @@ public abstract class LeafNodeLayoutManager extends AbstractLayoutManager return curArea; } + /** + * This method is called by addAreas() so IDs can be added to a page for FOs that + * support the 'id' property. + */ protected void addId() { // Do nothing here, overriden in subclasses that have an 'id' property. } diff --git a/src/java/org/apache/fop/layoutmgr/inline/PageNumberCitationLayoutManager.java b/src/java/org/apache/fop/layoutmgr/inline/PageNumberCitationLayoutManager.java index 3fe902bdf..0957cf36f 100644 --- a/src/java/org/apache/fop/layoutmgr/inline/PageNumberCitationLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/inline/PageNumberCitationLayoutManager.java @@ -100,6 +100,7 @@ public class PageNumberCitationLayoutManager extends LeafNodeLayoutManager { inline.setIPD(width); } + TraitSetter.setProducerID(inline, fobj.getId()); inline.setBPD(font.getAscender() - font.getDescender()); inline.setOffset(font.getAscender()); inline.addTrait(Trait.FONT_NAME, font.getFontName()); diff --git a/src/java/org/apache/fop/layoutmgr/inline/PageNumberLayoutManager.java b/src/java/org/apache/fop/layoutmgr/inline/PageNumberLayoutManager.java index 409efa35a..dd58e992d 100644 --- a/src/java/org/apache/fop/layoutmgr/inline/PageNumberLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/inline/PageNumberLayoutManager.java @@ -83,6 +83,7 @@ public class PageNumberLayoutManager extends LeafNodeLayoutManager { //TODO or even better: delay area creation until addAreas() stage //TextArea is cloned because the LM is reused in static areas and the area can't be. TextArea ta = new TextArea(); + TraitSetter.setProducerID(ta, fobj.getId()); ta.setIPD(baseArea.getIPD()); ta.setBPD(baseArea.getBPD()); ta.setOffset(baseArea.getOffset()); -- 2.39.5