gmazza 2003/11/24 11:07:35 Modified: src/java/org/apache/fop/fo InlineCharIterator.java src/java/org/apache/fop/fo/flow TableCell.java src/java/org/apache/fop/fo/properties CommonBorderAndPadding.java src/java/org/apache/fop/layoutmgr BlockLayoutManager.java TraitSetter.java src/java/org/apache/fop/render AbstractRenderer.java src/java/org/apache/fop/render/pdf PDFRenderer.java Log: 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. Revision Changes Path 1.5 +4 -5 xml-fop/src/java/org/apache/fop/fo/InlineCharIterator.java Index: InlineCharIterator.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/fo/InlineCharIterator.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- InlineCharIterator.java 1 Sep 2003 18:33:05 -0000 1.4 +++ InlineCharIterator.java 24 Nov 2003 19:07:35 -0000 1.5 @@ -71,11 +71,10 @@ 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); } /** 1.8 +15 -19 xml-fop/src/java/org/apache/fop/fo/flow/TableCell.java Index: TableCell.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/fo/flow/TableCell.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- TableCell.java 16 Sep 2003 18:11:52 -0000 1.7 +++ TableCell.java 24 Nov 2003 19:07:35 -0000 1.8 @@ -286,23 +286,19 @@ */ 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 @@ /* 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; } 1.3 +26 -22 xml-fop/src/java/org/apache/fop/fo/properties/CommonBorderAndPadding.java Index: CommonBorderAndPadding.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/fo/properties/CommonBorderAndPadding.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- CommonBorderAndPadding.java 5 Nov 2003 23:48:47 -0000 1.2 +++ CommonBorderAndPadding.java 24 Nov 2003 19:07:35 -0000 1.3 @@ -64,11 +64,15 @@ 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 @@ 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 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"; } } 1.10 +3 -0 xml-fop/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java Index: BlockLayoutManager.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- BlockLayoutManager.java 11 Nov 2003 13:50:00 -0000 1.9 +++ BlockLayoutManager.java 24 Nov 2003 19:07:35 -0000 1.10 @@ -190,6 +190,9 @@ LayoutProcessor curLM; // currently active LM int ipd = context.getRefIPD(); + int iIndents = borderProps.getPaddingStart(false) + + borderProps.getPaddingEnd(false); + ipd -= iIndents; MinOptMax stackSize = new MinOptMax(); 1.4 +4 -4 xml-fop/src/java/org/apache/fop/layoutmgr/TraitSetter.java Index: TraitSetter.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/layoutmgr/TraitSetter.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- TraitSetter.java 26 Oct 2003 19:29:14 -0000 1.3 +++ TraitSetter.java 24 Nov 2003 19:07:35 -0000 1.4 @@ -132,19 +132,19 @@ * @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); } 1.18 +76 -76 xml-fop/src/java/org/apache/fop/render/AbstractRenderer.java Index: AbstractRenderer.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/render/AbstractRenderer.java,v retrieving revision 1.17 retrieving revision 1.18 diff -u -r1.17 -r1.18 --- AbstractRenderer.java 1 Nov 2003 04:28:01 -0000 1.17 +++ AbstractRenderer.java 24 Nov 2003 19:07:35 -0000 1.18 @@ -475,6 +475,82 @@ } /** + * 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. * * @param block The block area @@ -519,49 +595,6 @@ } /** - * 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. <p> * * A line area may have grouped styling for its children such as underline, @@ -665,39 +698,6 @@ ((InlineArea) iter.next()).acceptVisitor(this); } 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(); - } - } } /** 1.24 +38 -17 xml-fop/src/java/org/apache/fop/render/pdf/PDFRenderer.java Index: PDFRenderer.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/render/pdf/PDFRenderer.java,v retrieving revision 1.23 retrieving revision 1.24 diff -u -r1.23 -r1.24 --- PDFRenderer.java 2 Nov 2003 16:20:16 -0000 1.23 +++ PDFRenderer.java 24 Nov 2003 19:07:35 -0000 1.24 @@ -227,12 +227,14 @@ 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 @@ } /** - * 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 @@ 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(); } @@ -542,6 +540,29 @@ } /** + * 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 * the position. @@ -888,7 +909,7 @@ } // 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();
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]