]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
handle floats inside lists
authorLuis Bernardo <lbernardo@apache.org>
Fri, 14 Nov 2014 09:27:25 +0000 (09:27 +0000)
committerLuis Bernardo <lbernardo@apache.org>
Fri, 14 Nov 2014 09:27:25 +0000 (09:27 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_BasicSideFloats@1639587 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/fop/layoutmgr/FloatContentLayoutManager.java
src/java/org/apache/fop/layoutmgr/PageBreakingAlgorithm.java
src/java/org/apache/fop/layoutmgr/list/ListItemLayoutManager.java
test/layoutengine/standard-testcases/float_6.xml [new file with mode: 0644]

index a1c576140f12efdd0cfae18c189e4cd8cce83c51..5c6f6c685eb266db22f49c6ba4f15f0511802538 100644 (file)
@@ -71,6 +71,7 @@ public class FloatContentLayoutManager extends SpacedBorderedPaddedBlockLayoutMa
         floatContentArea.setIPD(effectiveContentIPD);
         childArea.activateEffectiveIPD();
         if (side == Constants.EN_END || side == Constants.EN_RIGHT) {
+            xOffset += getStartIndent();
             floatContentArea.setXOffset(xOffset + contentIPD - effectiveContentIPD);
         } else if (side == Constants.EN_START || side == Constants.EN_LEFT) {
             floatContentArea.setXOffset(xOffset);
@@ -125,4 +126,16 @@ public class FloatContentLayoutManager extends SpacedBorderedPaddedBlockLayoutMa
     public int getFloatYOffset() {
         return yOffset;
     }
+
+    private int getStartIndent() {
+        int startIndent = 0;
+        LayoutManager lm = getParent();
+        while (!(lm instanceof BlockLayoutManager)) {
+            lm = lm.getParent();
+        }
+        if (lm instanceof BlockLayoutManager) {
+            startIndent = ((BlockLayoutManager) lm).startIndent;
+        }
+        return startIndent;
+    }
 }
index 43a6ca60769c53d64ca744fe5f6b9cbf241492a9..dc3cc591a3db20b20fb2fc14d8cfd2d48f53523c 100644 (file)
@@ -31,7 +31,6 @@ import org.apache.fop.fo.Constants;
 import org.apache.fop.fo.FObj;
 import org.apache.fop.layoutmgr.AbstractBreaker.FloatPosition;
 import org.apache.fop.layoutmgr.AbstractBreaker.PageBreakPosition;
-import org.apache.fop.layoutmgr.BreakingAlgorithm.KnuthNode;
 import org.apache.fop.layoutmgr.WhitespaceManagementPenalty.Variant;
 import org.apache.fop.traits.MinOptMax;
 import org.apache.fop.util.ListUtil;
index ce9746b6a7d2c4166156ca47234fa17269e721ab..d29dba20b329b920d8bf6c1b3614ae862532c11b 100644 (file)
@@ -20,6 +20,7 @@
 package org.apache.fop.layoutmgr.list;
 
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.ListIterator;
@@ -40,15 +41,16 @@ import org.apache.fop.layoutmgr.BreakOpportunity;
 import org.apache.fop.layoutmgr.BreakOpportunityHelper;
 import org.apache.fop.layoutmgr.ElementListObserver;
 import org.apache.fop.layoutmgr.ElementListUtils;
+import org.apache.fop.layoutmgr.FloatContentLayoutManager;
 import org.apache.fop.layoutmgr.FootenoteUtil;
 import org.apache.fop.layoutmgr.Keep;
 import org.apache.fop.layoutmgr.KnuthBlockBox;
-import org.apache.fop.layoutmgr.KnuthBox;
 import org.apache.fop.layoutmgr.KnuthElement;
 import org.apache.fop.layoutmgr.KnuthPenalty;
 import org.apache.fop.layoutmgr.KnuthPossPosIter;
 import org.apache.fop.layoutmgr.LayoutContext;
 import org.apache.fop.layoutmgr.LayoutManager;
+import org.apache.fop.layoutmgr.LeafPosition;
 import org.apache.fop.layoutmgr.ListElement;
 import org.apache.fop.layoutmgr.NonLeafPosition;
 import org.apache.fop.layoutmgr.Position;
@@ -294,8 +296,34 @@ public class ListItemLayoutManager extends SpacedBorderedPaddedBlockLayoutManage
         context.updateKeepWithPreviousPending(childLC.getKeepWithPreviousPending());
         this.keepWithNextPendingOnBody = childLC.getKeepWithNextPending();
 
+        List<ListElement> returnedList = new LinkedList<ListElement>();
+        if (!labelList.isEmpty() && labelList.get(0) instanceof KnuthBlockBox) {
+            KnuthBlockBox kbb = (KnuthBlockBox) labelList.get(0);
+            if (kbb.getWidth() == 0 && kbb.hasFloatAnchors()) {
+                List<FloatContentLayoutManager> floats = kbb.getFloatContentLMs();
+                returnedList.add(new KnuthBlockBox(0, Collections.emptyList(), null, false, floats));
+                Keep keep = getKeepTogether();
+                returnedList.add(new BreakElement(new LeafPosition(this, 0), keep.getPenalty(), keep
+                        .getContext(), context));
+                labelList.remove(0);
+                labelList.remove(0);
+            }
+        }
+        if (!bodyList.isEmpty() && bodyList.get(0) instanceof KnuthBlockBox) {
+            KnuthBlockBox kbb = (KnuthBlockBox) bodyList.get(0);
+            if (kbb.getWidth() == 0 && kbb.hasFloatAnchors()) {
+                List<FloatContentLayoutManager> floats = kbb.getFloatContentLMs();
+                returnedList.add(new KnuthBlockBox(0, Collections.emptyList(), null, false, floats));
+                Keep keep = getKeepTogether();
+                returnedList.add(new BreakElement(new LeafPosition(this, 0), keep.getPenalty(), keep
+                        .getContext(), context));
+                bodyList.remove(0);
+                bodyList.remove(0);
+            }
+        }
+
         // create a combined list
-        List returnedList = getCombinedKnuthElementsForListItem(labelList, bodyList, context);
+        returnedList.addAll(getCombinedKnuthElementsForListItem(labelList, bodyList, context));
 
         // "wrap" the Position inside each element
         wrapPositionElements(returnedList, returnList, true);
@@ -395,14 +423,26 @@ public class ListItemLayoutManager extends SpacedBorderedPaddedBlockLayoutManage
                 footnoteList.addAll(FootenoteUtil.getFootnotes(elementLists[i], start[i], end[i]));
             }
 
+            LinkedList<FloatContentLayoutManager> floats = new LinkedList<FloatContentLayoutManager>();
+            for (int i = 0; i < elementLists.length; i++) {
+                floats.addAll(FloatContentLayoutManager.checkForFloats(elementLists[i], start[i], end[i]));
+            }
+
             // add the new elements
             addedBoxHeight += boxHeight;
             ListItemPosition stepPosition = new ListItemPosition(this, start[0], end[0], start[1], end[1]);
             stepPosition.setOriginalLabelPosition(originalLabelPosition);
             stepPosition.setOriginalBodyPosition(originalBodyPosition);
-            if (footnoteList.isEmpty()) {
-                returnList.add(new KnuthBox(boxHeight, stepPosition, false));
+
+            if (floats.isEmpty()) {
+                returnList.add(new KnuthBlockBox(boxHeight, footnoteList, stepPosition, false));
             } else {
+                // add a line with height zero and no content and attach float to it
+                returnList.add(new KnuthBlockBox(0, Collections.emptyList(), stepPosition, false, floats));
+                // add a break element to signal that we should restart LB at this break
+                Keep keep = getKeepTogether();
+                returnList.add(new BreakElement(stepPosition, keep.getPenalty(), keep.getContext(), context));
+                // add the original line where the float was but without the float now
                 returnList.add(new KnuthBlockBox(boxHeight, footnoteList, stepPosition, false));
             }
 
@@ -581,6 +621,10 @@ public class ListItemLayoutManager extends SpacedBorderedPaddedBlockLayoutManage
                 positionList.add(pos.getPosition());
             }
         }
+        if (positionList.isEmpty()) {
+            reset();
+            return;
+        }
 
         registerMarkers(true, isFirst(firstPos), isLast(lastPos));
 
diff --git a/test/layoutengine/standard-testcases/float_6.xml b/test/layoutengine/standard-testcases/float_6.xml
new file mode 100644 (file)
index 0000000..543096a
--- /dev/null
@@ -0,0 +1,134 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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$ -->
+<testcase>
+  <info>
+    <p>
+      This test checks floats.
+    </p>
+  </info>
+  <fo>
+<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
+  <fo:layout-master-set>
+    <fo:simple-page-master margin="0.25in" master-name="page" page-height="11in" page-width="8.5in">
+      <fo:region-body />
+    </fo:simple-page-master>
+  </fo:layout-master-set>
+  <fo:page-sequence master-reference="page">
+    <fo:flow flow-name="xsl-region-body">
+      <fo:block>
+Did you know... (taken from Wikipedia main page on November 6th, 2014, with the order slightly changed to better show the wrapping around the float)
+      </fo:block>
+      <fo:block>
+From Wikipedia's new and recently improved content:
+      </fo:block>
+      <fo:block>
+        <fo:list-block>
+          <fo:list-item>
+            <fo:list-item-label end-indent="label-end()">
+              <fo:block>&#x2022;</fo:block>
+            </fo:list-item-label>
+            <fo:list-item-body start-indent="body-start()">
+              <fo:block>
+... that while testifying in a 2004 lawsuit involving the meaning of the word steakburger, a corporate CEO was grilled on the witness stand?
+              </fo:block>
+            </fo:list-item-body>
+          </fo:list-item>
+          <fo:list-item>
+            <fo:list-item-label end-indent="label-end()">
+              <fo:block>&#x2022;</fo:block>
+            </fo:list-item-label>
+            <fo:list-item-body start-indent="body-start()">
+              <fo:block>
+... that the Queen Anne house (pictured) 
+        <fo:float float="end">
+          <fo:block border="1pt solid red" padding="5pt" end-indent="0pt" start-indent="0pt">
+            <fo:block-container inline-progression-dimension="120pt">
+              <fo:block background-color="yellow">
+The former dean's house at the University of Wisconsin (this is the alt text of the image in the Wikipedia page)
+              </fo:block>
+            </fo:block-container>
+          </fo:block>
+        </fo:float>
+at the Allen Centennial Gardens was home to four deans of the University of Wisconsin–Madison College of Agricultural and Life Sciences?
+              </fo:block>
+            </fo:list-item-body>
+          </fo:list-item>
+          <fo:list-item>
+            <fo:list-item-label end-indent="label-end()">
+              <fo:block>&#x2022;</fo:block>
+            </fo:list-item-label>
+            <fo:list-item-body start-indent="body-start()">
+              <fo:block>
+... that rhapsodomancy was so vague, Virgil wrote against it in The Aeneid?
+              </fo:block>
+            </fo:list-item-body>
+          </fo:list-item>
+          <fo:list-item>
+            <fo:list-item-label end-indent="label-end()">
+              <fo:block>&#x2022;</fo:block>
+            </fo:list-item-label>
+            <fo:list-item-body start-indent="body-start()">
+              <fo:block>
+... that Australian physician Claudia Burton Bradley was one of the first diabetics to be treated with insulin?
+              </fo:block>
+            </fo:list-item-body>
+          </fo:list-item>
+          <fo:list-item>
+            <fo:list-item-label end-indent="label-end()">
+              <fo:block>&#x2022;</fo:block>
+            </fo:list-item-label>
+            <fo:list-item-body start-indent="body-start()">
+              <fo:block>
+... that Green Bay Packers offensive lineman David Bakhtiari was the first rookie in Packers history to start every game at left tackle in a season since the start of the 16-game season?
+              </fo:block>
+            </fo:list-item-body>
+          </fo:list-item>
+          <fo:list-item>
+            <fo:list-item-label end-indent="label-end()">
+              <fo:block>&#x2022;</fo:block>
+            </fo:list-item-label>
+            <fo:list-item-body start-indent="body-start()">
+              <fo:block>
+... that in the Byzantine Empire, the office of orphanotrophos, head of the imperial orphanage, ranked among the higher offices of state?
+              </fo:block>
+            </fo:list-item-body>
+          </fo:list-item>
+          <fo:list-item>
+            <fo:list-item-label end-indent="label-end()">
+              <fo:block>&#x2022;</fo:block>
+            </fo:list-item-label>
+            <fo:list-item-body start-indent="body-start()">
+              <fo:block>
+... that the stream Shingle Run is actually named after sawmills?
+              </fo:block>
+            </fo:list-item-body>
+          </fo:list-item>
+        </fo:list-block>
+      </fo:block>
+    </fo:flow>
+  </fo:page-sequence>
+</fo:root>
+  </fo>
+  <checks>
+    <!-- first float -->
+    <eval expected="450000" xpath="//pageViewport[1]/page/regionViewport[1]//flow[1]/block[4]/@left-offset" />
+    <eval expected="... that the Queen Anne house (pictured) at the Allen Centennial Gardens" xpath="//pageViewport[1]/page/regionViewport[1]//flow[1]/block[5]/block[1]/block[1]/block[2]/block[1]/lineArea[1]" />
+    <eval expected="was home to four deans of the University of Wisconsin–Madison College of" xpath="//pageViewport[1]/page/regionViewport[1]//flow[1]/block[5]/block[1]/block[1]/block[2]/block[1]/lineArea[2]" />
+  </checks>
+</testcase>