From: Glen Mazza Date: Mon, 24 Nov 2003 19:07:35 +0000 (+0000) Subject: 1.) Chris Bowditch's patch on padding-start implemented. (Changes were X-Git-Tag: Root_Temp_KnuthStylePageBreaking~993 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=2c6e0b5da1bc758874b5e3dfe8b687871448c8a2;p=xmlgraphics-fop.git 1.) Chris Bowditch's patch on padding-start implemented. (Changes were extended to implement part of padding-end as well.) 2.) Switched from TOP/BOTTOM/LEFT/RIGHT to BEFORE/AFTER/START/END in CommonBorderAndPadding--this is more appropriate for BlockLayout, also the various places calling it already were either (1) commenting on the need to switch to the above, or (2) placing the results of the above functions using the former constants into variables emphasizing the latter. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@197023 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/java/org/apache/fop/fo/InlineCharIterator.java b/src/java/org/apache/fop/fo/InlineCharIterator.java index 065a831ed..9b0241b23 100644 --- a/src/java/org/apache/fop/fo/InlineCharIterator.java +++ b/src/java/org/apache/fop/fo/InlineCharIterator.java @@ -71,11 +71,10 @@ public class InlineCharIterator extends RecursiveCharIterator { private void checkBoundaries(CommonBorderAndPadding bap) { - // TODO! use start and end in BAP!! - bStartBoundary = (bap.getBorderLeftWidth(false) > 0 - || bap.getPaddingLeft(false) > 0); - bEndBoundary = (bap.getBorderRightWidth(false) > 0 - || bap.getPaddingRight(false) > 0); + bStartBoundary = (bap.getBorderStartWidth(false) > 0 + || bap.getPaddingStart(false) > 0); + bEndBoundary = (bap.getBorderEndWidth(false) > 0 + || bap.getPaddingEnd(false) > 0); } /** diff --git a/src/java/org/apache/fop/fo/flow/TableCell.java b/src/java/org/apache/fop/fo/flow/TableCell.java index c569c9683..1453a3228 100644 --- a/src/java/org/apache/fop/fo/flow/TableCell.java +++ b/src/java/org/apache/fop/fo/flow/TableCell.java @@ -286,23 +286,19 @@ public class TableCell extends FObj { */ int iSep = properties.get( "border-separation.inline-progression-direction").getLength().getValue(); - this.startAdjust = iSep / 2 + bp.getBorderLeftWidth(false) - + bp.getPaddingLeft(false); - /* - * int contentOffset = iSep + bp.getBorderStartWidth(false) + - * bp.getPaddingStart(false); - */ + this.startAdjust = iSep / 2 + bp.getBorderStartWidth(false) + + bp.getPaddingStart(false); + this.widthAdjust = startAdjust + iSep - iSep / 2 - + bp.getBorderRightWidth(false) - + bp.getPaddingRight(false); - // bp.getBorderEndWidth(false) + bp.getPaddingEnd(false); + + bp.getBorderEndWidth(false) + + bp.getPaddingEnd(false); + // Offset of content rectangle in the block-progression direction borderSeparation = properties.get( "border-separation.block-progression-direction").getLength().getValue(); this.beforeOffset = borderSeparation / 2 - + bp.getBorderTopWidth(false) - + bp.getPaddingTop(false); - // bp.getBorderBeforeWidth(false) + bp.getPaddingBefore(false); + + bp.getBorderBeforeWidth(false) + + bp.getPaddingBefore(false); } else { // System.err.println("Collapse borders"); @@ -355,16 +351,16 @@ public class TableCell extends FObj { /* ivan demakov */ - int borderStart = bp.getBorderLeftWidth(false); - int borderEnd = bp.getBorderRightWidth(false); - int borderBefore = bp.getBorderTopWidth(false); - int borderAfter = bp.getBorderBottomWidth(false); + int borderStart = bp.getBorderStartWidth(false); + int borderEnd = bp.getBorderEndWidth(false); + int borderBefore = bp.getBorderBeforeWidth(false); + int borderAfter = bp.getBorderAfterWidth(false); - this.startAdjust = borderStart / 2 + bp.getPaddingLeft(false); + this.startAdjust = borderStart / 2 + bp.getPaddingStart(false); this.widthAdjust = startAdjust + borderEnd / 2 - + bp.getPaddingRight(false); - this.beforeOffset = borderBefore / 2 + bp.getPaddingTop(false); + + bp.getPaddingEnd(false); + this.beforeOffset = borderBefore / 2 + bp.getPaddingBefore(false); // Half border height to fix overestimate of area size! this.borderHeight = (borderBefore + borderAfter) / 2; } diff --git a/src/java/org/apache/fop/fo/properties/CommonBorderAndPadding.java b/src/java/org/apache/fop/fo/properties/CommonBorderAndPadding.java index c172bc041..b332f2825 100644 --- a/src/java/org/apache/fop/fo/properties/CommonBorderAndPadding.java +++ b/src/java/org/apache/fop/fo/properties/CommonBorderAndPadding.java @@ -64,11 +64,15 @@ public class CommonBorderAndPadding implements Cloneable { public static final int START = 2; public static final int END = 3; +/* TODO: need new definitions (below relations not always the same, + also unsure if direct access of absolute properties needed; + resolution of absolute & relative properties--Spec 5.3.1--can + possibly be done within this class alone) public static final int TOP = BEFORE; public static final int BOTTOM = AFTER; public static final int LEFT = START; public static final int RIGHT = END; - +*/ private static class ResolvedCondLength implements Cloneable { private int iLength; // Resolved length value private boolean bDiscard; @@ -143,36 +147,36 @@ public class CommonBorderAndPadding implements Cloneable { borderInfo[side].mWidth.iLength = iLength; } - public int getBorderLeftWidth(boolean bDiscard) { - return getBorderWidth(LEFT, bDiscard); + public int getBorderStartWidth(boolean bDiscard) { + return getBorderWidth(START, bDiscard); } - public int getBorderRightWidth(boolean bDiscard) { - return getBorderWidth(RIGHT, bDiscard); + public int getBorderEndWidth(boolean bDiscard) { + return getBorderWidth(END, bDiscard); } - public int getBorderTopWidth(boolean bDiscard) { - return getBorderWidth(TOP, bDiscard); + public int getBorderBeforeWidth(boolean bDiscard) { + return getBorderWidth(BEFORE, bDiscard); } - public int getBorderBottomWidth(boolean bDiscard) { - return getBorderWidth(BOTTOM, bDiscard); + public int getBorderAfterWidth(boolean bDiscard) { + return getBorderWidth(AFTER, bDiscard); } - public int getPaddingLeft(boolean bDiscard) { - return getPadding(LEFT, bDiscard); + public int getPaddingStart(boolean bDiscard) { + return getPadding(START, bDiscard); } - public int getPaddingRight(boolean bDiscard) { - return getPadding(RIGHT, bDiscard); + public int getPaddingEnd(boolean bDiscard) { + return getPadding(END, bDiscard); } - public int getPaddingBottom(boolean bDiscard) { - return getPadding(BOTTOM, bDiscard); + public int getPaddingBefore(boolean bDiscard) { + return getPadding(BEFORE, bDiscard); } - public int getPaddingTop(boolean bDiscard) { - return getPadding(TOP, bDiscard); + public int getPaddingAfter(boolean bDiscard) { + return getPadding(AFTER, bDiscard); } public int getBorderWidth(int side, boolean bDiscard) { @@ -211,11 +215,11 @@ public class CommonBorderAndPadding implements Cloneable { public String toString() { return "CommonBordersAndPadding (Before, After, Start, End):\n" + - "Borders: (" + getBorderTopWidth(false) + ", " + getBorderBottomWidth(false) + ", " + - getBorderLeftWidth(false) + ", " + getBorderRightWidth(false) + ")\n" + + "Borders: (" + getBorderBeforeWidth(false) + ", " + getBorderAfterWidth(false) + ", " + + getBorderStartWidth(false) + ", " + getBorderEndWidth(false) + ")\n" + "Border Colors: (" + getBorderColor(BEFORE) + ", " + getBorderColor(AFTER) + ", " + getBorderColor(START) + ", " + getBorderColor(END) + ")\n" + - "Padding: (" + getPaddingTop(false) + ", " + getPaddingBottom(false) + ", " + - getPaddingLeft(false) + ", " + getPaddingRight(false) + ")\n"; + "Padding: (" + getPaddingBefore(false) + ", " + getPaddingAfter(false) + ", " + + getPaddingStart(false) + ", " + getPaddingEnd(false) + ")\n"; } } diff --git a/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java b/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java index 24f1efee6..83b7add62 100644 --- a/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java @@ -190,6 +190,9 @@ public class BlockLayoutManager extends BlockStackingLayoutManager { LayoutProcessor curLM; // currently active LM int ipd = context.getRefIPD(); + int iIndents = borderProps.getPaddingStart(false) + + borderProps.getPaddingEnd(false); + ipd -= iIndents; MinOptMax stackSize = new MinOptMax(); diff --git a/src/java/org/apache/fop/layoutmgr/TraitSetter.java b/src/java/org/apache/fop/layoutmgr/TraitSetter.java index 6c0ff71e7..87975058d 100644 --- a/src/java/org/apache/fop/layoutmgr/TraitSetter.java +++ b/src/java/org/apache/fop/layoutmgr/TraitSetter.java @@ -132,19 +132,19 @@ public class TraitSetter { * @param bordProps border properties */ public static void addBorders(Area curBlock, CommonBorderAndPadding bordProps) { - BorderProps bps = getBorderProps(bordProps, CommonBorderAndPadding.TOP); + BorderProps bps = getBorderProps(bordProps, CommonBorderAndPadding.BEFORE); if (bps.width != 0) { curBlock.addTrait(Trait.BORDER_BEFORE, bps); } - bps = getBorderProps(bordProps, CommonBorderAndPadding.BOTTOM); + bps = getBorderProps(bordProps, CommonBorderAndPadding.AFTER); if (bps.width != 0) { curBlock.addTrait(Trait.BORDER_AFTER, bps); } - bps = getBorderProps(bordProps, CommonBorderAndPadding.LEFT); + bps = getBorderProps(bordProps, CommonBorderAndPadding.START); if (bps.width != 0) { curBlock.addTrait(Trait.BORDER_START, bps); } - bps = getBorderProps(bordProps, CommonBorderAndPadding.RIGHT); + bps = getBorderProps(bordProps, CommonBorderAndPadding.END); if (bps.width != 0) { curBlock.addTrait(Trait.BORDER_END, bps); } diff --git a/src/java/org/apache/fop/render/AbstractRenderer.java b/src/java/org/apache/fop/render/AbstractRenderer.java index 39e18e33b..c15b51e02 100644 --- a/src/java/org/apache/fop/render/AbstractRenderer.java +++ b/src/java/org/apache/fop/render/AbstractRenderer.java @@ -474,6 +474,82 @@ public abstract class AbstractRenderer extends AbstractLogEnabled } } + /** + * Handle block traits. + * This method is called when the correct ip and bp posiiton is + * set. This should be overridden to draw border and background + * traits for the block area. + * + * @param block the block area + */ + protected void handleBlockTraits(Block block) { + // draw border and background + } + + /** + * Renders a block viewport. + * + * @param bv The block viewport + * @param children The children to render within the block viewport + */ + protected void renderBlockViewport(BlockViewport bv, List children) { + // clip and position viewport if necessary + if (bv.getPositioning() == Block.ABSOLUTE) { + // save positions + int saveIP = currentIPPosition; + int saveBP = currentBPPosition; + + CTM ctm = bv.getCTM(); + currentIPPosition = 0; + currentBPPosition = 0; + + startVParea(ctm); + handleBlockTraits(bv); + renderBlocks(children); + endVParea(); + + // clip if necessary + + currentIPPosition = saveIP; + currentBPPosition = saveBP; + } else { + renderBlocks(children); + } + } + + /** + * Renders a list of block areas. + * + * @param blocks The block areas + */ + protected void renderBlocks(List blocks) { + // the position of the containing block is used for + // absolutely positioned areas + int contBP = currentBPPosition; + int contIP = currentIPPosition; + containingBPPosition = contBP; + containingIPPosition = contIP; + + for (int count = 0; count < blocks.size(); count++) { + Object obj = blocks.get(count); + if (obj instanceof Block) { + containingBPPosition = contBP; + containingIPPosition = contIP; + renderBlock((Block) obj); + containingBPPosition = contBP; + containingIPPosition = contIP; + } else { + // a line area is rendered from the top left position + // of the line, each inline object is offset from there + LineArea line = (LineArea) obj; + currentBlockIPPosition = + currentIPPosition + line.getStartIndent(); + renderLineArea(line); + currentBPPosition += line.getHeight(); + } + } + } + /** * Renders a block area. * @@ -518,49 +594,6 @@ public abstract class AbstractRenderer extends AbstractLogEnabled } } - /** - * Handle block traits. - * This method is called when the correct ip and bp posiiton is - * set. This should be overridden to draw border and background - * traits for the block area. - * - * @param block the block area - */ - protected void handleBlockTraits(Block block) { - // draw border and background - } - - /** - * Renders a block viewport. - * - * @param bv The block viewport - * @param children The children to render within the block viewport - */ - protected void renderBlockViewport(BlockViewport bv, List children) { - // clip and position viewport if necessary - if (bv.getPositioning() == Block.ABSOLUTE) { - // save positions - int saveIP = currentIPPosition; - int saveBP = currentBPPosition; - - CTM ctm = bv.getCTM(); - currentIPPosition = 0; - currentBPPosition = 0; - - startVParea(ctm); - handleBlockTraits(bv); - renderBlocks(children); - endVParea(); - - // clip if necessary - - currentIPPosition = saveIP; - currentBPPosition = saveBP; - } else { - renderBlocks(children); - } - } - /** * Renders a line area.

* @@ -667,39 +700,6 @@ public abstract class AbstractRenderer extends AbstractLogEnabled currentBlockIPPosition = saveIP + ip.getWidth(); } - /** - * Renders a list of block areas. - * - * @param blocks The block areas - */ - protected void renderBlocks(List blocks) { - // the position of the containing block is used for - // absolutely positioned areas - int contBP = currentBPPosition; - int contIP = currentIPPosition; - containingBPPosition = contBP; - containingIPPosition = contIP; - - for (int count = 0; count < blocks.size(); count++) { - Object obj = blocks.get(count); - if (obj instanceof Block) { - containingBPPosition = contBP; - containingIPPosition = contIP; - renderBlock((Block) obj); - containingBPPosition = contBP; - containingIPPosition = contIP; - } else { - // a line area is rendered from the top left position - // of the line, each inline object is offset from there - LineArea line = (LineArea) obj; - currentBlockIPPosition = - currentIPPosition + line.getStartIndent(); - renderLineArea(line); - currentBPPosition += line.getHeight(); - } - } - } - /** * Set the default xml handler for the given mime type. * @param mime MIME type diff --git a/src/java/org/apache/fop/render/pdf/PDFRenderer.java b/src/java/org/apache/fop/render/pdf/PDFRenderer.java index 5ee316c0f..7327960fb 100644 --- a/src/java/org/apache/fop/render/pdf/PDFRenderer.java +++ b/src/java/org/apache/fop/render/pdf/PDFRenderer.java @@ -227,12 +227,14 @@ public class PDFRenderer extends PrintRenderer { private StringBuffer wordAreaPDF = new StringBuffer(); /** - * Offset for rendering text, taking into account borders and padding + * Offset for rendering text, taking into account borders and padding for + * both region and block. */ protected int BPMarginOffset = 0; /** - * Offset for rendering text, taking into account borders and padding + * Offset for rendering text, taking into account borders and padding for + * both the region and block. */ protected int IPMarginOffset = 0; @@ -503,19 +505,15 @@ public class PDFRenderer extends PrintRenderer { } /** - * Handle block traits. - * The block could be any sort of block with any positioning - * so this should render the traits such as border and background - * in its position. - * - * @param block the block to render the traits + * @see org.apache.fop.render.AbstractRenderer#renderBlock(Block) */ - protected void handleBlockTraits(Block block) { - float startx = (currentIPPosition + IPMarginOffset)/ 1000f; - float starty = (currentBPPosition + BPMarginOffset)/ 1000f; - drawBackAndBorders(block, startx, starty, - block.getWidth() / 1000f, block.getHeight() / 1000f); - } + protected void renderBlock(Block block) { + int marginOffset = IPMarginOffset; + super.renderBlock(block); + // super.renderBlock() may render child blocks (with their own offsets) + // so need to restore (this parent's) IPMarginOffset when finished. + IPMarginOffset = marginOffset; + } /** * Handle the traits for a region @@ -531,9 +529,9 @@ public class PDFRenderer extends PrintRenderer { float width = (float)(viewArea.getWidth() / 1000f); float height = (float)(viewArea.getHeight() / 1000f); - if (region.getRegion().getRegionClass() + if (region.getRegion().getRegionClass() == org.apache.fop.fo.pagination.Region.BODY_CODE) - { + { BPMarginOffset = region.getBorderAndPaddingWidthBefore(); IPMarginOffset = region.getBorderAndPaddingWidthStart(); } @@ -541,6 +539,29 @@ public class PDFRenderer extends PrintRenderer { drawBackAndBorders(region, startx, starty, width, height); } + /** + * Handle block traits. + * The block could be any sort of block with any positioning + * so this should render the traits such as border and background + * in its position. + * + * @param block the block to render the traits + */ + protected void handleBlockTraits(Block block) { + /* IPMarginOffset for a particular block = region border + + * region padding + parent block padding + current block padding + */ + Integer paddingStart = (Integer) block.getTrait(Trait.PADDING_START); + if (paddingStart != null) { + IPMarginOffset += paddingStart.intValue(); + } + + float startx = (currentIPPosition + IPMarginOffset) / 1000f; + float starty = (currentBPPosition + BPMarginOffset) / 1000f; + drawBackAndBorders(block, startx, starty, + block.getWidth() / 1000f, block.getHeight() / 1000f); + } + /** * Draw the background and borders. * This draws the background and border traits for an area given @@ -888,7 +909,7 @@ public class PDFRenderer extends PrintRenderer { } // word.getOffset() = only height of text itself - // currentBlockIPPosition: 0 for beginning of line; nonzero + // currentBlockIPPosition: 0 for beginning of line; nonzero // where previous line area failed to take up entire allocated space int rx = currentBlockIPPosition + IPMarginOffset; int bl = currentBPPosition + BPMarginOffset + text.getOffset();