aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Steiner <ssteiner@apache.org>2021-04-22 10:45:11 +0000
committerSimon Steiner <ssteiner@apache.org>2021-04-22 10:45:11 +0000
commit5ce5fe50a74b9e3f84cabcffee46f860c86dbd47 (patch)
tree406c831e285c8157dda3226918a28bb7db479594
parent678d6c0e04fd6a5464012be0241bb771cf9bb506 (diff)
downloadxmlgraphics-fop-5ce5fe50a74b9e3f84cabcffee46f860c86dbd47.tar.gz
xmlgraphics-fop-5ce5fe50a74b9e3f84cabcffee46f860c86dbd47.zip
FOP-3008: Table with linefeed-treatment may give ClassCastException
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1889102 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--fop-core/src/main/java/org/apache/fop/fo/flow/Wrapper.java2
-rw-r--r--fop-core/src/main/java/org/apache/fop/layoutmgr/AreaAdditionUtil.java2
-rw-r--r--fop-core/src/main/java/org/apache/fop/layoutmgr/BlockStackingLayoutManager.java4
-rw-r--r--fop-core/src/main/java/org/apache/fop/layoutmgr/ElementListUtils.java3
-rw-r--r--fop-core/src/main/java/org/apache/fop/layoutmgr/KnuthPenalty.java4
-rw-r--r--fop-core/src/main/java/org/apache/fop/util/ListUtil.java10
-rw-r--r--fop/test/layoutengine/standard-testcases/table_linefeed.xml57
7 files changed, 76 insertions, 6 deletions
diff --git a/fop-core/src/main/java/org/apache/fop/fo/flow/Wrapper.java b/fop-core/src/main/java/org/apache/fop/fo/flow/Wrapper.java
index 39f472cbb..809125088 100644
--- a/fop-core/src/main/java/org/apache/fop/fo/flow/Wrapper.java
+++ b/fop-core/src/main/java/org/apache/fop/fo/flow/Wrapper.java
@@ -121,7 +121,7 @@ public class Wrapper extends FObjMixed implements CommonAccessibilityHolder {
while (ancestor.getNameId() == Constants.FO_WRAPPER) {
ancestor = ancestor.getParent();
}
- if (!(ancestor instanceof FObjMixed)) {
+ if (!(ancestor instanceof FObjMixed) && !child.toString().trim().isEmpty()) {
invalidChildError(
getLocator(),
getLocalName(),
diff --git a/fop-core/src/main/java/org/apache/fop/layoutmgr/AreaAdditionUtil.java b/fop-core/src/main/java/org/apache/fop/layoutmgr/AreaAdditionUtil.java
index d731ab62a..e341078de 100644
--- a/fop-core/src/main/java/org/apache/fop/layoutmgr/AreaAdditionUtil.java
+++ b/fop-core/src/main/java/org/apache/fop/layoutmgr/AreaAdditionUtil.java
@@ -65,7 +65,7 @@ public final class AreaAdditionUtil {
}
lastPos = pos;
}
- if (pos instanceof NonLeafPosition) {
+ if (pos instanceof NonLeafPosition && pos.getPosition() != null) {
// pos was created by a child of this FlowLM
positionList.add(pos.getPosition());
lastLM = (pos.getPosition().getLM());
diff --git a/fop-core/src/main/java/org/apache/fop/layoutmgr/BlockStackingLayoutManager.java b/fop-core/src/main/java/org/apache/fop/layoutmgr/BlockStackingLayoutManager.java
index 4dddbcf11..1e55edd07 100644
--- a/fop-core/src/main/java/org/apache/fop/layoutmgr/BlockStackingLayoutManager.java
+++ b/fop-core/src/main/java/org/apache/fop/layoutmgr/BlockStackingLayoutManager.java
@@ -535,8 +535,8 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager
return;
}
- ListElement last = ListUtil.getLast(contentList);
- if (last.isGlue()) {
+ ListElement last = ListUtil.getLastListElement(contentList);
+ if (last == null || last.isGlue()) {
// the last element in contentList is a glue;
// it is a feasible breakpoint, there is no need to add
// a penalty
diff --git a/fop-core/src/main/java/org/apache/fop/layoutmgr/ElementListUtils.java b/fop-core/src/main/java/org/apache/fop/layoutmgr/ElementListUtils.java
index 9b964843e..3920481e7 100644
--- a/fop-core/src/main/java/org/apache/fop/layoutmgr/ElementListUtils.java
+++ b/fop-core/src/main/java/org/apache/fop/layoutmgr/ElementListUtils.java
@@ -178,7 +178,8 @@ public final class ElementListUtils {
* @return true if the list ends with a forced break
*/
public static boolean endsWithForcedBreak(List elems) {
- return ((ListElement) ListUtil.getLast(elems)).isForcedBreak();
+ ListElement last = ListUtil.getLastListElement(elems);
+ return last == null || last.isForcedBreak();
}
/**
diff --git a/fop-core/src/main/java/org/apache/fop/layoutmgr/KnuthPenalty.java b/fop-core/src/main/java/org/apache/fop/layoutmgr/KnuthPenalty.java
index 220f9c35d..c80cb389b 100644
--- a/fop-core/src/main/java/org/apache/fop/layoutmgr/KnuthPenalty.java
+++ b/fop-core/src/main/java/org/apache/fop/layoutmgr/KnuthPenalty.java
@@ -19,6 +19,8 @@
package org.apache.fop.layoutmgr;
+import org.apache.fop.fo.Constants;
+
/**
* An instance of this class represents information about a feasible
* breaking point; it does not represent any piece of content.
@@ -47,7 +49,7 @@ public class KnuthPenalty extends KnuthElement {
private int penalty;
private boolean penaltyFlagged;
- private int breakClass = -1;
+ private int breakClass = Constants.EN_AUTO;
/**
* Create a new KnuthPenalty.
diff --git a/fop-core/src/main/java/org/apache/fop/util/ListUtil.java b/fop-core/src/main/java/org/apache/fop/util/ListUtil.java
index 8e88e4cbf..45af2b5c3 100644
--- a/fop-core/src/main/java/org/apache/fop/util/ListUtil.java
+++ b/fop-core/src/main/java/org/apache/fop/util/ListUtil.java
@@ -21,6 +21,8 @@ package org.apache.fop.util;
import java.util.List;
+import org.apache.fop.layoutmgr.ListElement;
+
/**
* Provides helper functions for {@link java.util.List}.
*
@@ -42,6 +44,14 @@ public final class ListUtil {
return list.get(list.size() - 1);
}
+ public static ListElement getLastListElement(List list) {
+ Object last = getLast(list);
+ if (last instanceof ListElement) {
+ return (ListElement) last;
+ }
+ return null;
+ }
+
/**
* Retrieve and remove the last element from a list.
*
diff --git a/fop/test/layoutengine/standard-testcases/table_linefeed.xml b/fop/test/layoutengine/standard-testcases/table_linefeed.xml
new file mode 100644
index 000000000..0486e51b2
--- /dev/null
+++ b/fop/test/layoutengine/standard-testcases/table_linefeed.xml
@@ -0,0 +1,57 @@
+<?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 table linefeed in certain situations.
+ </p>
+ </info>
+ <fo>
+<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
+ <fo:layout-master-set>
+ <fo:simple-page-master master-name="ref" page-height="297.0mm" page-width="210.0mm">
+ <fo:region-body region-name="xsl-region-body" />
+ </fo:simple-page-master>
+ <fo:page-sequence-master master-name="master">
+ <fo:repeatable-page-master-reference master-reference="ref" maximum-repeats="99999" />
+ </fo:page-sequence-master>
+ </fo:layout-master-set>
+ <fo:page-sequence master-reference="master">
+ <fo:flow flow-name="xsl-region-body" linefeed-treatment="preserve">
+ <fo:block>
+ <fo:table table-layout="fixed" >
+ <fo:table-column column-width="226pt" />
+ <fo:table-body >
+ <fo:table-row>
+ <fo:table-cell >
+ <fo:wrapper>
+ </fo:wrapper>
+ </fo:table-cell>
+ </fo:table-row>
+ </fo:table-body>
+ </fo:table>
+ </fo:block>
+ </fo:flow>
+ </fo:page-sequence>
+</fo:root>
+ </fo>
+ <checks>
+ <eval expected="595275" xpath="//lineArea[1]/@ipd"/>
+ </checks>
+</testcase>