import java.util.List;
+import org.apache.fop.fo.Constants;
+
/**
* This class represents an unresolved break possibility.
*/
private int penaltyWidth;
private int penaltyValue;
- private int breakClass = -1;
+ private int breakClass;
private List pendingBeforeMarks;
private List pendingAfterMarks;
* @param context the layout context which contains the pending conditional elements
*/
public BreakElement(Position position, int penaltyValue, LayoutContext context) {
- this(position, penaltyValue, -1, context);
+ this(position, penaltyValue, Constants.EN_AUTO, context);
}
/**
super(position);
this.penaltyWidth = penaltyWidth;
this.penaltyValue = penaltyValue;
- this.breakClass = breakClass;
+ setBreakClass(breakClass);
this.pendingBeforeMarks = context.getPendingBeforeMarks();
this.pendingAfterMarks = context.getPendingAfterMarks();
}
*
* @param breakClass one of
* {@link org.apache.fop.fo.Constants#EN_AUTO},
+ * {@link org.apache.fop.fo.Constants#EN_LINE},
* {@link org.apache.fop.fo.Constants#EN_COLUMN},
* {@link org.apache.fop.fo.Constants#EN_PAGE},
* {@link org.apache.fop.fo.Constants#EN_EVEN_PAGE},
* {@link org.apache.fop.fo.Constants#EN_ODD_PAGE}.
*/
public void setBreakClass(int breakClass) {
- this.breakClass = breakClass;
+ switch (breakClass) {
+ case Constants.EN_AUTO:
+ case Constants.EN_LINE:
+ case Constants.EN_COLUMN:
+ case Constants.EN_PAGE:
+ case Constants.EN_EVEN_PAGE:
+ case Constants.EN_ODD_PAGE:
+ this.breakClass = breakClass;
+ break;
+ default: throw new IllegalArgumentException("Illegal value for break class: " + breakClass);
+ }
}
/** @return the pending border and padding elements at the before edge */
documents. Example: the fix of marks layering will be such a case when it's done.
-->
<release version="FOP Trunk" date="TBD">
+ <action context="Layout" dev="VH" type="fix" fixes-bug="53598" due-to="Robert Meyer">
+ Always set the breakClass field to a legal value in BreakElement, so as to avoid
+ IllegalArgumentExceptions in other parts of the code.
+ </action>
<action context="Layout" dev="VH" type="fix" fixes-bug="45715" due-to="Luis Bernardo">
Restored support for break-before on fo:table.
</action>
--- /dev/null
+/*
+ * 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.
+ */
+
+package org.apache.fop.layoutmgr;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+import org.apache.fop.fo.Constants;
+
+public class BreakElementTestCase {
+
+ /**
+ * Tests that the constructor sets the break class to a valid default value.
+ */
+ @Test
+ public void breakClassMustBeValid() {
+ LayoutContext context = LayoutContext.newInstance();
+ BreakElement breakElement = new BreakElement(new Position(null), 0, context);
+ assertEquals(Constants.EN_AUTO, breakElement.getBreakClass());
+ }
+}