From c0388acf51d54ca414b91bb06941f041fd09497a Mon Sep 17 00:00:00 2001 From: Vincent Hennebert Date: Thu, 24 Mar 2011 18:14:23 +0000 Subject: [PATCH] Bugzilla #50763: Implemented non-standard behavior for basic-link areas, such that they take into account the heights of their descendants areas git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1085058 13f79535-47bb-0310-9956-ffa450edef68 --- .../fop/area/inline/AbstractTextArea.java | 11 +++ .../apache/fop/area/inline/BasicLinkArea.java | 53 +++++++++++++++ .../apache/fop/area/inline/InlineArea.java | 27 ++++++++ .../apache/fop/area/inline/InlineParent.java | 46 ++++++++----- .../inline/BasicLinkLayoutManager.java | 8 +++ .../layoutmgr/inline/InlineLayoutManager.java | 12 ++-- status.xml | 4 ++ test/layoutengine/disabled-testcases.xml | 7 -- .../basic-link_external-destination_2.xml | 12 ++-- .../standard-testcases/basic-link_height.xml | 53 +++++++++++++++ .../basic-link_height_baseline-shift.xml | 62 +++++++++++++++++ .../basic-link_height_inline-child.xml | 62 +++++++++++++++++ .../basic-link_height_multi-child.xml | 58 ++++++++++++++++ .../basic-link_height_multi-line.xml | 67 +++++++++++++++++++ 14 files changed, 449 insertions(+), 33 deletions(-) create mode 100644 src/java/org/apache/fop/area/inline/BasicLinkArea.java create mode 100644 test/layoutengine/standard-testcases/basic-link_height.xml create mode 100644 test/layoutengine/standard-testcases/basic-link_height_baseline-shift.xml create mode 100644 test/layoutengine/standard-testcases/basic-link_height_inline-child.xml create mode 100644 test/layoutengine/standard-testcases/basic-link_height_multi-child.xml create mode 100644 test/layoutengine/standard-testcases/basic-link_height_multi-line.xml diff --git a/src/java/org/apache/fop/area/inline/AbstractTextArea.java b/src/java/org/apache/fop/area/inline/AbstractTextArea.java index 08997a817..1558e8160 100644 --- a/src/java/org/apache/fop/area/inline/AbstractTextArea.java +++ b/src/java/org/apache/fop/area/inline/AbstractTextArea.java @@ -185,4 +185,15 @@ public abstract class AbstractTextArea extends InlineParent { public void setBaselineOffset(int baselineOffset) { this.baselineOffset = baselineOffset; } + + @Override + int getVirtualOffset() { + return getOffset(); + } + + @Override + int getVirtualBPD() { + /* Word and space areas don't have a properly set bpd; return this area's bpd instead. */ + return getBPD(); + } } diff --git a/src/java/org/apache/fop/area/inline/BasicLinkArea.java b/src/java/org/apache/fop/area/inline/BasicLinkArea.java new file mode 100644 index 000000000..fce913944 --- /dev/null +++ b/src/java/org/apache/fop/area/inline/BasicLinkArea.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* $Id$ */ + +package org.apache.fop.area.inline; + +import org.apache.fop.area.Area; + +/** + * An inline area produced by an fo:basic-link element. This class implements a different + * behavior to what is prescribed by the XSL-FO 1.1 Recommendation. With the standard + * behavior, there is no easy way to make a link cover e.g. a whole image. + * + *

See following bug report at W3C's: + * http://www.w3.org/Bugs/Public/show_bug.cgi?id=11672

+ */ +public class BasicLinkArea extends InlineParent { + + private static final long serialVersionUID = 5183753430412208151L; + + @Override + public void setParentArea(Area parentArea) { + super.setParentArea(parentArea); + /* + * Perform necessary modifications to make this area encompass all of its children + * elements, so as to have a useful active area. We assume that this method is + * called after all of the children areas have been added to this area. + */ + /* Make this area start at its beforest child. */ + setOffset(getOffset() + minChildOffset); + /* Update children offsets accordingly. */ + for (InlineArea inline : inlines) { + inline.setOffset(inline.getOffset() - minChildOffset); + } + setBPD(getVirtualBPD()); + } + +} diff --git a/src/java/org/apache/fop/area/inline/InlineArea.java b/src/java/org/apache/fop/area/inline/InlineArea.java index 515f45b68..d62e6f721 100644 --- a/src/java/org/apache/fop/area/inline/InlineArea.java +++ b/src/java/org/apache/fop/area/inline/InlineArea.java @@ -251,5 +251,32 @@ public class InlineArea extends Area { storedIPDVariation += ipdVariation; } } + + /** + * Returns the offset that this area would have if its offset and size were taking + * children areas into account. The bpd of an inline area is taken from its nominal + * font and doesn't depend on the bpds of its children elements. However, in the case + * of a basic-link element we want the active area to cover all of the children + * elements. + * + * @return the offset that this area would have if the before-edge of its + * content-rectangle were coinciding with the beforest before-edge of its + * children allocation-rectangles. + * @see #getVirtualBPD() + * @see BasicLinkArea + */ + int getVirtualOffset() { + return getOffset(); + } + + /** + * Returns the block-progression-dimension that this area would have if it were taking + * its children elements into account. See {@linkplain #getVirtualOffset()}. + * + * @return the bpd + */ + int getVirtualBPD() { + return getBPD(); + } } diff --git a/src/java/org/apache/fop/area/inline/InlineParent.java b/src/java/org/apache/fop/area/inline/InlineParent.java index db8f2f056..521080469 100644 --- a/src/java/org/apache/fop/area/inline/InlineParent.java +++ b/src/java/org/apache/fop/area/inline/InlineParent.java @@ -39,31 +39,42 @@ public class InlineParent extends InlineArea { /** Controls whether the IPD is automatically adjusted based on the area's children. */ protected transient boolean autoSize; - /** - * Create a new inline parent to add areas to. - */ - public InlineParent() { - } + /** The offset of the beforest child area of this area. */ + protected int minChildOffset; /** - * Override generic Area method. - * - * @param childArea the child area to add + * The offset of the afterest child area of this area. Offset from the + * before-edge of this area's content-rectangle and the after-edge of the child area's + * allocation-rectangle. */ + private int maxAfterEdge; + @Override - public void addChildArea(Area childArea) { + public void addChildArea(Area c) { + assert c instanceof InlineArea; if (inlines.size() == 0) { autoSize = (getIPD() == 0); } - if (childArea instanceof InlineArea) { - InlineArea inlineChildArea = (InlineArea) childArea; - inlines.add(inlineChildArea); - // set the parent area for the child area - inlineChildArea.setParentArea(this); - if (autoSize) { - increaseIPD(inlineChildArea.getAllocIPD()); - } + InlineArea childArea = (InlineArea) c; + inlines.add(childArea); + // set the parent area for the child area + childArea.setParentArea(this); + if (autoSize) { + increaseIPD(childArea.getAllocIPD()); } + int childOffset = childArea.getVirtualOffset(); + minChildOffset = Math.min(minChildOffset, childOffset); + maxAfterEdge = Math.max(maxAfterEdge, childOffset + childArea.getVirtualBPD()); + } + + @Override + int getVirtualOffset() { + return getOffset() + minChildOffset; + } + + @Override + int getVirtualBPD() { + return maxAfterEdge - minChildOffset; } /** @@ -98,5 +109,6 @@ public class InlineParent extends InlineArea { return hasUnresolvedAreas; } + } diff --git a/src/java/org/apache/fop/layoutmgr/inline/BasicLinkLayoutManager.java b/src/java/org/apache/fop/layoutmgr/inline/BasicLinkLayoutManager.java index eef649c97..40c9a324e 100644 --- a/src/java/org/apache/fop/layoutmgr/inline/BasicLinkLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/inline/BasicLinkLayoutManager.java @@ -21,7 +21,9 @@ package org.apache.fop.layoutmgr.inline; import org.apache.fop.area.LinkResolver; import org.apache.fop.area.Trait; +import org.apache.fop.area.inline.BasicLinkArea; import org.apache.fop.area.inline.InlineArea; +import org.apache.fop.area.inline.InlineParent; import org.apache.fop.datatypes.URISpecification; import org.apache.fop.fo.Constants; import org.apache.fop.fo.flow.BasicLink; @@ -77,4 +79,10 @@ public class BasicLinkLayoutManager extends InlineLayoutManager { } } } + + @Override + protected InlineParent createInlineParent() { + return new BasicLinkArea(); + } + } diff --git a/src/java/org/apache/fop/layoutmgr/inline/InlineLayoutManager.java b/src/java/org/apache/fop/layoutmgr/inline/InlineLayoutManager.java index 085174fae..9563b491e 100644 --- a/src/java/org/apache/fop/layoutmgr/inline/InlineLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/inline/InlineLayoutManager.java @@ -198,13 +198,13 @@ public class InlineLayoutManager extends InlineStackingLayoutManager { /** * Create and initialize an InlineArea * - * @param hasInlineParent true if the parent is an inline + * @param isInline true if the parent is an inline * @return the area */ - protected InlineArea createArea(boolean hasInlineParent) { + protected InlineArea createArea(boolean isInline) { InlineArea area; - if (hasInlineParent) { - area = new InlineParent(); + if (isInline) { + area = createInlineParent(); area.setOffset(0); } else { area = new InlineBlockParent(); @@ -215,6 +215,10 @@ public class InlineLayoutManager extends InlineStackingLayoutManager { return area; } + protected InlineParent createInlineParent() { + return new InlineParent(); + } + /** {@inheritDoc} */ @Override protected void setTraits(boolean isNotFirst, boolean isNotLast) { diff --git a/status.xml b/status.xml index 304c08173..20a77f567 100644 --- a/status.xml +++ b/status.xml @@ -59,6 +59,10 @@ documents. Example: the fix of marks layering will be such a case when it's done. --> + + Implemented non-standard behavior for basic-link areas, such that they take into account the + heights of their descendants areas. + Bugfix: keep-together does not apply to fo:table-cell. diff --git a/test/layoutengine/disabled-testcases.xml b/test/layoutengine/disabled-testcases.xml index 6c61ca747..cd63ad03f 100644 --- a/test/layoutengine/disabled-testcases.xml +++ b/test/layoutengine/disabled-testcases.xml @@ -19,13 +19,6 @@ - - External link around an SVG not properly sized - basic-link_external-destination_2.xml - The bpd trait of the inlineparent area for the basic-link - is not sized correctly if it wraps an image that is higher than the - nominal line. - Auto-height block-containers produce fences block-container_space-before_space-after_3.xml diff --git a/test/layoutengine/standard-testcases/basic-link_external-destination_2.xml b/test/layoutengine/standard-testcases/basic-link_external-destination_2.xml index f804893ac..0f00da82c 100644 --- a/test/layoutengine/standard-testcases/basic-link_external-destination_2.xml +++ b/test/layoutengine/standard-testcases/basic-link_external-destination_2.xml @@ -47,10 +47,12 @@ - - - - - + + + + + + + diff --git a/test/layoutengine/standard-testcases/basic-link_height.xml b/test/layoutengine/standard-testcases/basic-link_height.xml new file mode 100644 index 000000000..cb56f7f00 --- /dev/null +++ b/test/layoutengine/standard-testcases/basic-link_height.xml @@ -0,0 +1,53 @@ + + + + + +

+ This test checks the height of an fo:basic-link wrapping a bigger element. +

+
+ + + + + + + + + + Lorem ipsum dolor sit amet, consectetur adipiscing elit. In in egestas nisi. + Etiam at ante eget velit placerat ullamcorper. + + + + + + + + + + + + + +
diff --git a/test/layoutengine/standard-testcases/basic-link_height_baseline-shift.xml b/test/layoutengine/standard-testcases/basic-link_height_baseline-shift.xml new file mode 100644 index 000000000..582ef6143 --- /dev/null +++ b/test/layoutengine/standard-testcases/basic-link_height_baseline-shift.xml @@ -0,0 +1,62 @@ + + + + + +

+ This test checks the height of an fo:basic-link with baseline-shift. +

+
+ + + + + + + + + + Lorem ipsum dolor sit amet, consectetur + adipiscingelit. + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/test/layoutengine/standard-testcases/basic-link_height_inline-child.xml b/test/layoutengine/standard-testcases/basic-link_height_inline-child.xml new file mode 100644 index 000000000..3b74781d8 --- /dev/null +++ b/test/layoutengine/standard-testcases/basic-link_height_inline-child.xml @@ -0,0 +1,62 @@ + + + + + +

+ This test checks the height of an fo:basic-link having several child elements wrapped into a + single fo:inline element. +

+
+ + + + + + + + + + Lorem ipsum dolor sit amet, consectetur adipiscing elit. In + in egestas nisi. Etiam + at ante eget velit placerat ullamcorper. + + + + + + + + + + + + + + + + + + + + +
diff --git a/test/layoutengine/standard-testcases/basic-link_height_multi-child.xml b/test/layoutengine/standard-testcases/basic-link_height_multi-child.xml new file mode 100644 index 000000000..845a1d130 --- /dev/null +++ b/test/layoutengine/standard-testcases/basic-link_height_multi-child.xml @@ -0,0 +1,58 @@ + + + + + +

+ This test checks the height of an fo:basic-link having several child elements. +

+
+ + + + + + + + + + Lorem ipsum dolor sit amet, consectetur adipiscing elit. In in egestas nisi. Etiam at ante eget + velit placerat ullamcorper. + + + + + + + + + + + + + + + + + +
diff --git a/test/layoutengine/standard-testcases/basic-link_height_multi-line.xml b/test/layoutengine/standard-testcases/basic-link_height_multi-line.xml new file mode 100644 index 000000000..9a52d0128 --- /dev/null +++ b/test/layoutengine/standard-testcases/basic-link_height_multi-line.xml @@ -0,0 +1,67 @@ + + + + + +

+ This test checks the height of an fo:basic-link spanning over several lines. +

+
+ + + + + + + + + + Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer quis neque + vitae lectus condimentum. In in egestas nisi. Etiam at ante eget + velit placerat ullamcorper. + + + + + + + + + + + + + + + + + + + + + + + + + + +
-- 2.39.5