public boolean isLegacySkipPagePositionOnly() {
return factory.isLegacySkipPagePositionOnly();
}
+
+ public boolean isLegacyLastPageChangeIPD() {
+ return factory.isLegacyLastPageChangeIPD();
+ }
}
private static final String SIMPLE_LINE_BREAKING = "simple-line-breaking";
private static final String SKIP_PAGE_POSITION_ONLY_ALLOWED = "skip-page-position-only-allowed";
private static final String LEGACY_SKIP_PAGE_POSITION_ONLY = "legacy-skip-page-position-only";
+ private static final String LEGACY_LAST_PAGE_CHANGE_IPD = "legacy-last-page-change-ipd";
private final Log log = LogFactory.getLog(FopConfParser.class);
LogUtil.handleException(log, e, false);
}
}
+ if (cfg.getChild(LEGACY_LAST_PAGE_CHANGE_IPD, false) != null) {
+ try {
+ fopFactoryBuilder.setLegacyLastPageChangeIPD(
+ cfg.getChild(LEGACY_LAST_PAGE_CHANGE_IPD).getValueAsBoolean());
+ } catch (ConfigurationException e) {
+ LogUtil.handleException(log, e, false);
+ }
+ }
// configure font manager
new FontManagerConfigurator(cfg, baseURI, fopFactoryBuilder.getBaseURI(), resourceResolver)
return config.isLegacySkipPagePositionOnly();
}
+ boolean isLegacyLastPageChangeIPD() {
+ return config.isLegacyLastPageChangeIPD();
+ }
+
/**
* Returns a new {@link Fop} instance. FOP will be configured with a default user agent
* instance. Use this factory method if your output type requires an output stream.
return this;
}
+ public FopFactoryBuilder setLegacyLastPageChangeIPD(boolean b) {
+ fopFactoryConfigBuilder.setLegacyLastPageChangeIPD(b);
+ return this;
+ }
+
public static class FopFactoryConfigImpl implements FopFactoryConfig {
private final EnvironmentProfile enviro;
private boolean legacySkipPagePositionOnly;
+ private boolean legacyLastPageChangeIPD;
+
private static final class ImageContextImpl implements ImageContext {
private final FopFactoryConfig config;
return legacySkipPagePositionOnly;
}
+ public boolean isLegacyLastPageChangeIPD() {
+ return legacyLastPageChangeIPD;
+ }
+
public Map<String, String> getHyphenationPatternNames() {
return hyphPatNames;
}
void setSkipPagePositionOnlyAllowed(boolean b);
void setLegacySkipPagePositionOnly(boolean b);
+
+ void setLegacyLastPageChangeIPD(boolean b);
}
private static final class CompletedFopFactoryConfigBuilder implements FopFactoryConfigBuilder {
public void setLegacySkipPagePositionOnly(boolean b) {
throwIllegalStateException();
}
+
+ public void setLegacyLastPageChangeIPD(boolean b) {
+ throwIllegalStateException();
+ }
}
private static final class ActiveFopFactoryConfigBuilder implements FopFactoryConfigBuilder {
public void setLegacySkipPagePositionOnly(boolean b) {
config.legacySkipPagePositionOnly = b;
}
+
+ public void setLegacyLastPageChangeIPD(boolean b) {
+ config.legacyLastPageChangeIPD = b;
+ }
}
}
boolean isLegacySkipPagePositionOnly();
+ boolean isLegacyLastPageChangeIPD();
+
/** @return the hyphenation pattern names */
Map<String, String> getHyphenationPatternNames();
import java.util.LinkedList;
import org.apache.fop.events.EventBroadcaster;
-import org.apache.fop.layoutmgr.table.TableContentPosition;
+import org.apache.fop.layoutmgr.inline.LineLayoutManager;
/**
* Class to find the restart layoutmanager for changing IPD
*/
class RestartAtLM {
protected boolean invalidPosition;
+ private Position lineBreakPosition;
+ private int positionIndex;
protected LayoutManager getRestartAtLM(AbstractBreaker breaker, PageBreakingAlgorithm alg,
boolean ipdChangesOnNextPage, boolean onLastPageAndIPDChanges,
boolean visitedBefore, AbstractBreaker.BlockSequence blockList, int start) {
+ lineBreakPosition = null;
BreakingAlgorithm.KnuthNode optimalBreak = ipdChangesOnNextPage ? alg.getBestNodeBeforeIPDChange() : alg
.getBestNodeForLastPage();
if (onLastPageAndIPDChanges && visitedBefore && breaker.originalRestartAtLM == null) {
optimalBreak = null;
}
- int positionIndex = findPositionIndex(breaker, optimalBreak, alg, start);
- if (breaker.positionAtBreak.getLM() instanceof BlockLayoutManager) {
- positionIndex = findPositionIndex(breaker, optimalBreak, alg, 0);
+ findPositionIndex(breaker, optimalBreak, alg, start);
+ if (!breaker.getPageProvider().foUserAgent.isLegacyLastPageChangeIPD()
+ && breaker.positionAtBreak.getLM() instanceof BlockLayoutManager) {
+ findPositionIndexForBlockLayout(breaker, optimalBreak, alg);
}
if (ipdChangesOnNextPage || (breaker.positionAtBreak != null && breaker.positionAtBreak.getIndex() > -1)) {
breaker.firstElementsForRestart = Collections.EMPTY_LIST;
if (onLastPageAndIPDChanges && !visitedBefore && breaker.positionAtBreak.getPosition() != null) {
restartAtLM = breaker.positionAtBreak.getPosition().getLM();
}
- findLeafPosition(breaker);
- return restartAtLM;
- }
-
- private void findLeafPosition(AbstractBreaker breaker) {
- while (breaker.positionAtBreak instanceof NonLeafPosition) {
- Position pos = breaker.positionAtBreak.getPosition();
- if (pos instanceof TableContentPosition) {
- break;
- }
- breaker.positionAtBreak = pos;
+ if (lineBreakPosition != null && restartAtLM instanceof BlockLayoutManager) {
+ breaker.positionAtBreak = lineBreakPosition;
}
+ return restartAtLM;
}
- private int findPositionIndex(AbstractBreaker breaker, BreakingAlgorithm.KnuthNode optimalBreak,
+ private void findPositionIndex(AbstractBreaker breaker, BreakingAlgorithm.KnuthNode optimalBreak,
PageBreakingAlgorithm alg, int start) {
- int positionIndex = (optimalBreak != null) ? optimalBreak.position : start;
+ positionIndex = (optimalBreak != null) ? optimalBreak.position : start;
for (int i = positionIndex; i < alg.par.size(); i++) {
KnuthElement elementAtBreak = alg.getElement(i);
if (elementAtBreak.getPosition() == null) {
/* Retrieve the original position wrapped into this space position */
breaker.positionAtBreak = breaker.positionAtBreak.getPosition();
if (breaker.positionAtBreak != null) {
- return i;
+ this.positionIndex = i;
+ return;
+ }
+ }
+ }
+
+ private void findPositionIndexForBlockLayout(AbstractBreaker breaker, BreakingAlgorithm.KnuthNode optimalBreak,
+ PageBreakingAlgorithm alg) {
+ int positionIndex = (optimalBreak != null) ? optimalBreak.position : 0;
+ for (int i = positionIndex; i < alg.par.size(); i++) {
+ KnuthElement elementAtBreak = alg.getElement(i);
+ if (elementAtBreak.getPosition() == null) {
+ elementAtBreak = alg.getElement(0);
+ }
+ Position positionAtBreak = elementAtBreak.getPosition();
+ /* Retrieve the original position wrapped into this space position */
+ positionAtBreak = positionAtBreak.getPosition();
+ if (positionAtBreak != null) {
+ findLineBreakPosition(positionAtBreak);
+ if (lineBreakPosition != null) {
+ breaker.positionAtBreak = positionAtBreak;
+ this.positionIndex = i;
+ }
+ break;
+ }
+ }
+ }
+
+ private void findLineBreakPosition(Position positionAtBreak) {
+ while (positionAtBreak instanceof NonLeafPosition) {
+ positionAtBreak = positionAtBreak.getPosition();
+ if (positionAtBreak instanceof LineLayoutManager.LineBreakPosition) {
+ lineBreakPosition = positionAtBreak;
}
}
- return positionIndex;
}
}
* Each value holds the start and end indexes into a List of
* inline break positions.
*/
- static class LineBreakPosition extends LeafPosition {
+ public static class LineBreakPosition extends LeafPosition {
private final int parIndex; // index of the Paragraph this Position refers to
private final int startIndex; //index of the first element this Position refers to
private final int availableShrink;
return delegate.isLegacySkipPagePositionOnly();
}
+ public boolean isLegacyLastPageChangeIPD() {
+ return delegate.isLegacyLastPageChangeIPD();
+ }
+
public Map<String, String> getHyphenationPatternNames() {
return delegate.getHyphenationPatternNames();
}
builder.setSimpleLineBreaking(isSimpleLineBreaking(testDoc));
builder.setSkipPagePositionOnlyAllowed(isSkipPagePositionOnlyAllowed(testDoc));
builder.setLegacySkipPagePositionOnly(isLegacySkipPagePositionOnly(testDoc));
+ builder.setLegacyLastPageChangeIPD(isLegacyLastPageChangeIPD(testDoc));
return builder.build();
}
}
}
+ private boolean isLegacyLastPageChangeIPD(Document testDoc) {
+ try {
+ String s = eval(testDoc, "/testcase/cfg/legacy-last-page-change-ipd");
+ return "true".equalsIgnoreCase(s);
+ } catch (XPathExpressionException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
/**
* Loads a test case into a DOM document.
* @param testFile the test file
--- /dev/null
+<?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 that the definition of a special page-master for the last page with a
+ different width that the previous "rest" page causes FOP to redo the line breaking layout.
+ Legacy option is enabled so wrong line break is used
+ </p>
+ </info>
+ <cfg>
+ <legacy-last-page-change-ipd>true</legacy-last-page-change-ipd>
+ </cfg>
+ <fo>
+<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
+ <fo:layout-master-set>
+ <fo:simple-page-master master-name="Portrait" page-width="8.5in" page-height="11in" margin-bottom="0pt" margin-right="0pt" margin-top="0pt" margin-left="0pt">
+ <fo:region-body margin-bottom="0pt" margin-right="0pt" margin-top="0pt" margin-left="0pt" region-name="Body"/>
+ </fo:simple-page-master>
+ <fo:simple-page-master master-name="Landscape" page-width="11in" page-height="8.5in" margin-bottom="0pt" margin-right="0pt" margin-top="0pt" margin-left="0pt">
+ <fo:region-body region-name="Body" margin-bottom="0pt" margin-right="0pt" margin-top="0pt" margin-left="0pt"/>
+ </fo:simple-page-master>
+ <fo:page-sequence-master master-name="LetterPages">
+ <fo:repeatable-page-master-alternatives>
+ <fo:conditional-page-master-reference page-position="first" master-reference="Portrait"/>
+ <fo:conditional-page-master-reference page-position="rest" master-reference="Portrait"/>
+ <fo:conditional-page-master-reference page-position="last" master-reference="Landscape"/>
+ </fo:repeatable-page-master-alternatives>
+ </fo:page-sequence-master>
+ </fo:layout-master-set>
+ <fo:page-sequence master-reference="LetterPages">
+ <fo:flow flow-name="Body">
+ <fo:block>
+ <fo:block>test</fo:block>
+ <fo:block break-before="page">test2</fo:block>
+ <fo:block>test3</fo:block>
+ </fo:block>
+ </fo:flow>
+ </fo:page-sequence>
+</fo:root>
+ </fo>
+ <checks>
+ <eval expected="2" xpath="count(//pageViewport)"/>
+ <eval expected="test" xpath="//pageViewport[1]//word"/>
+ <eval expected="test3" xpath="//pageViewport[2]//block/block[1]//word"/>
+ </checks>
+</testcase>
--- /dev/null
+<?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 that the definition of a special page-master for the last page with a
+ different width that the previous "rest" page causes FOP to redo the line breaking layout.
+ </p>
+ </info>
+ <fo>
+<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:fox="http://xmlgraphics.apache.org/fop/extensions">
+ <fo:layout-master-set>
+ <fo:simple-page-master master-name="Page" page-width="8.5in" page-height="11in">
+ <fo:region-body region-name="Body"/>
+ </fo:simple-page-master>
+ <fo:simple-page-master master-name="PageRest" page-width="8.5in" page-height="11in">
+ <fo:region-body region-name="Body"/>
+ </fo:simple-page-master>
+ <fo:simple-page-master margin-right="0.48in" master-name="PageLast" page-width="8.5in" page-height="11in">
+ <fo:region-body region-name="Body"/>
+ </fo:simple-page-master>
+ <fo:page-sequence-master master-name="PageSequence">
+ <fo:repeatable-page-master-alternatives>
+ <fo:conditional-page-master-reference page-position="first" master-reference="Page"/>
+ <fo:conditional-page-master-reference page-position="rest" master-reference="PageRest"/>
+ <fo:conditional-page-master-reference page-position="last" master-reference="PageLast"/>
+ </fo:repeatable-page-master-alternatives>
+ </fo:page-sequence-master>
+ </fo:layout-master-set>
+ <fo:page-sequence master-reference="PageSequence">
+ <fo:flow flow-name="Body">
+ <fo:block>
+ <fo:leader/>
+ <fo:block break-before="page"/>NOTE</fo:block>
+ </fo:flow>
+ </fo:page-sequence>
+</fo:root>
+ </fo>
+ <checks>
+ <eval expected="2" xpath="count(//pageViewport)"/>
+ <eval expected="NOTE" xpath="//pageViewport[2]//word"/>
+ </checks>
+</testcase>