From 862f28b0608e4c669b19c0730b9f730cfdb69076 Mon Sep 17 00:00:00 2001 From: Manuel Mall Date: Mon, 14 Nov 2005 05:05:35 +0000 Subject: [PATCH] Correct a few more problems related to leaders: text-align was not handled correctly, use-content was drawing incorrect borders git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@344037 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/fop/area/inline/FilledArea.java | 17 +- .../layoutmgr/inline/InlineLayoutManager.java | 56 ++++--- .../layoutmgr/inline/LeaderLayoutManager.java | 44 +++-- test/layoutengine/disabled-testcases.txt | 1 + .../leader_border_padding.xml | 44 ++++- .../leader_leader-pattern_use-content.xml | 14 +- .../leader_leader-pattern_use-content_bug.xml | 57 +++++++ .../standard-testcases/leader_text-align.xml | 158 ++++++++++++++++++ 8 files changed, 343 insertions(+), 48 deletions(-) create mode 100755 test/layoutengine/standard-testcases/leader_leader-pattern_use-content_bug.xml create mode 100755 test/layoutengine/standard-testcases/leader_text-align.xml diff --git a/src/java/org/apache/fop/area/inline/FilledArea.java b/src/java/org/apache/fop/area/inline/FilledArea.java index 9c3bcf4ca..214e4110a 100644 --- a/src/java/org/apache/fop/area/inline/FilledArea.java +++ b/src/java/org/apache/fop/area/inline/FilledArea.java @@ -21,6 +21,7 @@ package org.apache.fop.area.inline; import java.util.List; import java.util.ListIterator; import java.util.ArrayList; +import java.util.Iterator; /** * Filled area. @@ -84,7 +85,21 @@ public class FilledArea extends InlineParent { } /** - * Get the child areas for this filed area. + * @see org.apache.fop.area.Area#getBPD + */ + public int getBPD() { + int bpd = 0; + for (Iterator childAreaIt = getChildAreas().iterator(); childAreaIt.hasNext();) { + InlineArea area = (InlineArea)childAreaIt.next(); + if (bpd < area.getBPD()) { + bpd = area.getBPD(); + } + } + return bpd; + } + + /** + * Get the child areas for this filled area. * This copies the references of the inline areas so that * it fills the total width of the area a whole number of times * for the unit width. diff --git a/src/java/org/apache/fop/layoutmgr/inline/InlineLayoutManager.java b/src/java/org/apache/fop/layoutmgr/inline/InlineLayoutManager.java index ea1eb11a0..c24245f79 100755 --- a/src/java/org/apache/fop/layoutmgr/inline/InlineLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/inline/InlineLayoutManager.java @@ -98,18 +98,13 @@ public class InlineLayoutManager extends InlineStackingLayoutManager { /** @see LayoutManager#initialize */ public void initialize() { - inlineProps = fobj.getCommonMarginInline(); - borderProps = fobj.getCommonBorderPaddingBackground(); - - int padding = borderProps.getPadding(CommonBorderPaddingBackground.BEFORE, false, this); - padding += borderProps.getBorderWidth(CommonBorderPaddingBackground.BEFORE, - false); - padding += borderProps.getPadding(CommonBorderPaddingBackground.AFTER, false, this); - padding += borderProps.getBorderWidth(CommonBorderPaddingBackground.AFTER, false); - extraBPD = new MinOptMax(padding); + int padding = 0; font = fobj.getCommonFont().getFontState(fobj.getFOEventHandler().getFontInfo(), this); lineHeight = fobj.getLineHeight(); + if (fobj instanceof Inline) { + inlineProps = fobj.getCommonMarginInline(); + borderProps = fobj.getCommonBorderPaddingBackground(); alignmentAdjust = ((Inline)fobj).getAlignmentAdjust(); alignmentBaseline = ((Inline)fobj).getAlignmentBaseline(); baselineShift = ((Inline)fobj).getBaselineShift(); @@ -120,42 +115,57 @@ public class InlineLayoutManager extends InlineStackingLayoutManager { baselineShift = ((Leader)fobj).getBaselineShift(); dominantBaseline = ((Leader)fobj).getDominantBaseline(); } + if (borderProps != null) { + padding = borderProps.getPadding(CommonBorderPaddingBackground.BEFORE, false, this); + padding += borderProps.getBorderWidth(CommonBorderPaddingBackground.BEFORE, + false); + padding += borderProps.getPadding(CommonBorderPaddingBackground.AFTER, false, this); + padding += borderProps.getBorderWidth(CommonBorderPaddingBackground.AFTER, false); + } + extraBPD = new MinOptMax(padding); } /** @see InlineStackingLayoutManager#getExtraIPD(boolean, boolean) */ protected MinOptMax getExtraIPD(boolean isNotFirst, boolean isNotLast) { - int borderAndPadding - = borderProps.getPadding(CommonBorderPaddingBackground.START, isNotFirst, this); - borderAndPadding - += borderProps.getBorderWidth(CommonBorderPaddingBackground.START, isNotFirst); - borderAndPadding - += borderProps.getPadding(CommonBorderPaddingBackground.END, isNotLast, this); - borderAndPadding - += borderProps.getBorderWidth(CommonBorderPaddingBackground.END, isNotLast); + int borderAndPadding = 0; + if (borderProps != null) { + borderAndPadding + = borderProps.getPadding(CommonBorderPaddingBackground.START, isNotFirst, this); + borderAndPadding + += borderProps.getBorderWidth(CommonBorderPaddingBackground.START, isNotFirst); + borderAndPadding + += borderProps.getPadding(CommonBorderPaddingBackground.END, isNotLast, this); + borderAndPadding + += borderProps.getBorderWidth(CommonBorderPaddingBackground.END, isNotLast); + } return new MinOptMax(borderAndPadding); } /** @see InlineStackingLayoutManager#hasLeadingFence(boolean) */ protected boolean hasLeadingFence(boolean isNotFirst) { - return borderProps.getPadding(CommonBorderPaddingBackground.START, isNotFirst, this) > 0 - || borderProps.getBorderWidth(CommonBorderPaddingBackground.START, isNotFirst) > 0; + return borderProps != null + && (borderProps.getPadding(CommonBorderPaddingBackground.START, isNotFirst, this) > 0 + || borderProps.getBorderWidth(CommonBorderPaddingBackground.START, isNotFirst) > 0 + ); } /** @see InlineStackingLayoutManager#hasTrailingFence(boolean) */ protected boolean hasTrailingFence(boolean isNotLast) { - return borderProps.getPadding(CommonBorderPaddingBackground.END, isNotLast, this) > 0 - || borderProps.getBorderWidth(CommonBorderPaddingBackground.END, isNotLast) > 0; + return borderProps != null + && (borderProps.getPadding(CommonBorderPaddingBackground.END, isNotLast, this) > 0 + || borderProps.getBorderWidth(CommonBorderPaddingBackground.END, isNotLast) > 0 + ); } /** @see InlineStackingLayoutManager#getSpaceStart */ protected SpaceProperty getSpaceStart() { - return inlineProps.spaceStart; + return inlineProps != null ? inlineProps.spaceStart : null; } /** @see InlineStackingLayoutManager#getSpaceEnd */ protected SpaceProperty getSpaceEnd() { - return inlineProps.spaceEnd; + return inlineProps != null ? inlineProps.spaceEnd : null; } /** @see org.apache.fop.layoutmgr.inline.InlineLayoutManager#createArea(boolean) */ diff --git a/src/java/org/apache/fop/layoutmgr/inline/LeaderLayoutManager.java b/src/java/org/apache/fop/layoutmgr/inline/LeaderLayoutManager.java index ede040d21..9731cc960 100644 --- a/src/java/org/apache/fop/layoutmgr/inline/LeaderLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/inline/LeaderLayoutManager.java @@ -201,6 +201,14 @@ public class LeaderLayoutManager extends LeafNodeLayoutManager { widthAdjustArea(curArea, context); + if (commonBorderPaddingBackground != null) { + // Add border and padding to area + TraitSetter.setBorderPaddingTraits(curArea, + commonBorderPaddingBackground, + false, false, this); + TraitSetter.addBackground(curArea, commonBorderPaddingBackground, this); + } + // add content areas KnuthPossPosIter contentIter = new KnuthPossPosIter(contentList, 0, contentList.size()); clm.addAreas(contentIter, context); @@ -251,11 +259,19 @@ public class LeaderLayoutManager extends LeafNodeLayoutManager { new LeafPosition(this, -1), true)); seq.add(new KnuthPenalty(0, KnuthElement.INFINITE, false, new LeafPosition(this, -1), true)); - seq.add - (new KnuthGlue(areaInfo.ipdArea.opt, - areaInfo.ipdArea.max - areaInfo.ipdArea.opt, - areaInfo.ipdArea.opt - areaInfo.ipdArea.min, - new LeafPosition(this, 0), false)); + if (alignment == EN_JUSTIFY || alignment == 0) { + seq.add + (new KnuthGlue(areaInfo.ipdArea.opt, + areaInfo.ipdArea.max - areaInfo.ipdArea.opt, + areaInfo.ipdArea.opt - areaInfo.ipdArea.min, + new LeafPosition(this, 0), false)); + } else { + seq.add + (new KnuthGlue(areaInfo.ipdArea.opt, + 0, + 0, + new LeafPosition(this, 0), false)); + } seq.add(new KnuthInlineBox(0, alignmentContext, new LeafPosition(this, -1), true)); @@ -294,11 +310,19 @@ public class LeaderLayoutManager extends LeafNodeLayoutManager { new LeafPosition(this, -1), true)); returnList.add(new KnuthPenalty(0, KnuthElement.INFINITE, false, new LeafPosition(this, -1), true)); - returnList.add - (new KnuthGlue(areaInfo.ipdArea.opt, - areaInfo.ipdArea.max - areaInfo.ipdArea.opt, - areaInfo.ipdArea.opt - areaInfo.ipdArea.min, - new LeafPosition(this, 0), false)); + if (alignment == EN_JUSTIFY || alignment == 0) { + returnList.add + (new KnuthGlue(areaInfo.ipdArea.opt, + areaInfo.ipdArea.max - areaInfo.ipdArea.opt, + areaInfo.ipdArea.opt - areaInfo.ipdArea.min, + new LeafPosition(this, 0), false)); + } else { + returnList.add + (new KnuthGlue(areaInfo.ipdArea.opt, + 0, + 0, + new LeafPosition(this, 0), false)); + } returnList.add(new KnuthInlineBox(0, areaInfo.alignmentContext, new LeafPosition(this, -1), true)); diff --git a/test/layoutengine/disabled-testcases.txt b/test/layoutengine/disabled-testcases.txt index 86ba90031..7fc929258 100644 --- a/test/layoutengine/disabled-testcases.txt +++ b/test/layoutengine/disabled-testcases.txt @@ -19,6 +19,7 @@ inline_letter-spacing.xml inline_word-spacing.xml inline_word-spacing_text-align_justify.xml leader-alignment.xml +leader_leader-pattern_use-content_bug.xml list-block_keep-with-previous.xml list-item_block_keep-with-previous.xml page-breaking_4.xml diff --git a/test/layoutengine/standard-testcases/leader_border_padding.xml b/test/layoutengine/standard-testcases/leader_border_padding.xml index aa89bcbfa..a51514635 100755 --- a/test/layoutengine/standard-testcases/leader_border_padding.xml +++ b/test/layoutengine/standard-testcases/leader_border_padding.xml @@ -47,10 +47,8 @@ space solid 1pt red border - @@ -69,10 +67,8 @@ space solid 5pt red border 5pt padding - @@ -91,10 +87,8 @@ space uneven border and padding - @@ -141,6 +135,16 @@ + + + + + + + + + + @@ -197,6 +201,20 @@ + + + + + + + + + + + + + + @@ -252,5 +270,19 @@ + + + + + + + + + + + + + + diff --git a/test/layoutengine/standard-testcases/leader_leader-pattern_use-content.xml b/test/layoutengine/standard-testcases/leader_leader-pattern_use-content.xml index a27218736..9b8306bbd 100644 --- a/test/layoutengine/standard-testcases/leader_leader-pattern_use-content.xml +++ b/test/layoutengine/standard-testcases/leader_leader-pattern_use-content.xml @@ -60,15 +60,13 @@ Content is svg 10 x 10 - - + - + - - - Content is svg 20 x 10 which is wider than the default leader-length + + Content is svg 20 x 10 which is wider than the leader-length @@ -167,9 +165,9 @@ - + - + diff --git a/test/layoutengine/standard-testcases/leader_leader-pattern_use-content_bug.xml b/test/layoutengine/standard-testcases/leader_leader-pattern_use-content_bug.xml new file mode 100755 index 000000000..9a7766672 --- /dev/null +++ b/test/layoutengine/standard-testcases/leader_leader-pattern_use-content_bug.xml @@ -0,0 +1,57 @@ + + + + + +

+ This test demonstrates a bug with fo:leader use-content +

+
+ + + + + + + + + + + x + use-content x font-size="24pt" + + + x + use-content x solid 5pt red border 5pt padding + + + + + + + + + + + + + + + + + +
diff --git a/test/layoutengine/standard-testcases/leader_text-align.xml b/test/layoutengine/standard-testcases/leader_text-align.xml new file mode 100755 index 000000000..086090f28 --- /dev/null +++ b/test/layoutengine/standard-testcases/leader_text-align.xml @@ -0,0 +1,158 @@ + + + + + +

+ This test checks fo:leader with different text-align +

+
+ + + + + + + + + + + + dots + + + + rule double + + + + space + + + x + use-content x + + + + dots text-align-last="justify" + + + + rule double text-align-last="justify" + + + + space text-align-last="justify" + + + x + use-content x text-align-last="justify" + + + + dots text-align-last="end" + + + + rule double text-align-last="end" + + + + space text-align-last="end" + + + x + use-content x text-align-last="end" + + + + dots text-align-last="center" + + + + rule double text-align-last="center" + + + + space text-align-last="center" + + + x + use-content x text-align-last="center" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
-- 2.39.5