aboutsummaryrefslogtreecommitdiffstats
path: root/fop-core
diff options
context:
space:
mode:
authorSimon Steiner <ssteiner@apache.org>2023-04-06 12:54:38 +0100
committerSimon Steiner <ssteiner@apache.org>2023-04-06 12:54:38 +0100
commit95ddfc80503820b6cd5d07121595f6419cfbe221 (patch)
treed991ebdf5475d28744367c2a219bbd3b03098078 /fop-core
parentaa9091d44d190a65b696f12f9d84cfe32524086d (diff)
downloadxmlgraphics-fop-95ddfc80503820b6cd5d07121595f6419cfbe221.tar.gz
xmlgraphics-fop-95ddfc80503820b6cd5d07121595f6419cfbe221.zip
FOP-3090: Allow use of page position only on redo of layout
Diffstat (limited to 'fop-core')
-rw-r--r--fop-core/src/main/java/org/apache/fop/apps/FOUserAgent.java4
-rw-r--r--fop-core/src/main/java/org/apache/fop/apps/FopConfParser.java10
-rw-r--r--fop-core/src/main/java/org/apache/fop/apps/FopFactory.java4
-rw-r--r--fop-core/src/main/java/org/apache/fop/apps/FopFactoryBuilder.java21
-rw-r--r--fop-core/src/main/java/org/apache/fop/apps/FopFactoryConfig.java2
-rw-r--r--fop-core/src/main/java/org/apache/fop/layoutmgr/PageProvider.java8
-rw-r--r--fop-core/src/test/java/org/apache/fop/apps/MutableConfig.java4
-rw-r--r--fop-core/src/test/java/org/apache/fop/intermediate/TestAssistant.java10
8 files changed, 61 insertions, 2 deletions
diff --git a/fop-core/src/main/java/org/apache/fop/apps/FOUserAgent.java b/fop-core/src/main/java/org/apache/fop/apps/FOUserAgent.java
index 3ab871dfc..02b0128cd 100644
--- a/fop-core/src/main/java/org/apache/fop/apps/FOUserAgent.java
+++ b/fop-core/src/main/java/org/apache/fop/apps/FOUserAgent.java
@@ -839,4 +839,8 @@ public class FOUserAgent {
public boolean isSimpleLineBreaking() {
return factory.isSimpleLineBreaking();
}
+
+ public boolean isSkipPagePositionOnlyAllowed() {
+ return factory.isSkipPagePositionOnlyAllowed();
+ }
}
diff --git a/fop-core/src/main/java/org/apache/fop/apps/FopConfParser.java b/fop-core/src/main/java/org/apache/fop/apps/FopConfParser.java
index 7e41de624..3bece2002 100644
--- a/fop-core/src/main/java/org/apache/fop/apps/FopConfParser.java
+++ b/fop-core/src/main/java/org/apache/fop/apps/FopConfParser.java
@@ -58,6 +58,7 @@ public class FopConfParser {
private static final String PREFER_RENDERER = "prefer-renderer";
private static final String TABLE_BORDER_OVERPAINT = "table-border-overpaint";
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 final Log log = LogFactory.getLog(FopConfParser.class);
@@ -290,6 +291,15 @@ public class FopConfParser {
}
}
+ if (cfg.getChild(SKIP_PAGE_POSITION_ONLY_ALLOWED, false) != null) {
+ try {
+ fopFactoryBuilder.setSkipPagePositionOnlyAllowed(
+ cfg.getChild(SKIP_PAGE_POSITION_ONLY_ALLOWED).getValueAsBoolean());
+ } catch (ConfigurationException e) {
+ LogUtil.handleException(log, e, false);
+ }
+ }
+
// configure font manager
new FontManagerConfigurator(cfg, baseURI, fopFactoryBuilder.getBaseURI(), resourceResolver)
.configure(fopFactoryBuilder.getFontManager(), strict);
diff --git a/fop-core/src/main/java/org/apache/fop/apps/FopFactory.java b/fop-core/src/main/java/org/apache/fop/apps/FopFactory.java
index 8bcbf01fd..0c57d2643 100644
--- a/fop-core/src/main/java/org/apache/fop/apps/FopFactory.java
+++ b/fop-core/src/main/java/org/apache/fop/apps/FopFactory.java
@@ -223,6 +223,10 @@ public final class FopFactory implements ImageContext {
return config.isSimpleLineBreaking();
}
+ boolean isSkipPagePositionOnlyAllowed() {
+ return config.isSkipPagePositionOnlyAllowed();
+ }
+
/**
* 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.
diff --git a/fop-core/src/main/java/org/apache/fop/apps/FopFactoryBuilder.java b/fop-core/src/main/java/org/apache/fop/apps/FopFactoryBuilder.java
index 848454e7f..afbcb227e 100644
--- a/fop-core/src/main/java/org/apache/fop/apps/FopFactoryBuilder.java
+++ b/fop-core/src/main/java/org/apache/fop/apps/FopFactoryBuilder.java
@@ -350,6 +350,11 @@ public final class FopFactoryBuilder {
return this;
}
+ public FopFactoryBuilder setSkipPagePositionOnlyAllowed(boolean b) {
+ fopFactoryConfigBuilder.setSkipPagePositionOnlyAllowed(b);
+ return this;
+ }
+
public static class FopFactoryConfigImpl implements FopFactoryConfig {
private final EnvironmentProfile enviro;
@@ -394,6 +399,8 @@ public final class FopFactoryBuilder {
private boolean tableBorderOverpaint;
private boolean simpleLineBreaking;
+ private boolean skipPagePositionOnlyAllowed = true;
+
private static final class ImageContextImpl implements ImageContext {
private final FopFactoryConfig config;
@@ -518,6 +525,10 @@ public final class FopFactoryBuilder {
return simpleLineBreaking;
}
+ public boolean isSkipPagePositionOnlyAllowed() {
+ return skipPagePositionOnlyAllowed;
+ }
+
public Map<String, String> getHyphenationPatternNames() {
return hyphPatNames;
}
@@ -567,6 +578,8 @@ public final class FopFactoryBuilder {
void setTableBorderOverpaint(boolean b);
void setSimpleLineBreaking(boolean b);
+
+ void setSkipPagePositionOnlyAllowed(boolean b);
}
private static final class CompletedFopFactoryConfigBuilder implements FopFactoryConfigBuilder {
@@ -658,6 +671,10 @@ public final class FopFactoryBuilder {
public void setSimpleLineBreaking(boolean b) {
throwIllegalStateException();
}
+
+ public void setSkipPagePositionOnlyAllowed(boolean b) {
+ throwIllegalStateException();
+ }
}
private static final class ActiveFopFactoryConfigBuilder implements FopFactoryConfigBuilder {
@@ -750,6 +767,10 @@ public final class FopFactoryBuilder {
public void setSimpleLineBreaking(boolean b) {
config.simpleLineBreaking = b;
}
+
+ public void setSkipPagePositionOnlyAllowed(boolean b) {
+ config.skipPagePositionOnlyAllowed = b;
+ }
}
}
diff --git a/fop-core/src/main/java/org/apache/fop/apps/FopFactoryConfig.java b/fop-core/src/main/java/org/apache/fop/apps/FopFactoryConfig.java
index c9495afb8..55cf7143e 100644
--- a/fop-core/src/main/java/org/apache/fop/apps/FopFactoryConfig.java
+++ b/fop-core/src/main/java/org/apache/fop/apps/FopFactoryConfig.java
@@ -167,6 +167,8 @@ public interface FopFactoryConfig {
boolean isSimpleLineBreaking();
+ boolean isSkipPagePositionOnlyAllowed();
+
/** @return the hyphenation pattern names */
Map<String, String> getHyphenationPatternNames();
diff --git a/fop-core/src/main/java/org/apache/fop/layoutmgr/PageProvider.java b/fop-core/src/main/java/org/apache/fop/layoutmgr/PageProvider.java
index 7926ba756..378280694 100644
--- a/fop-core/src/main/java/org/apache/fop/layoutmgr/PageProvider.java
+++ b/fop-core/src/main/java/org/apache/fop/layoutmgr/PageProvider.java
@@ -24,6 +24,7 @@ import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.area.AreaTreeHandler;
import org.apache.fop.area.BodyRegion;
import org.apache.fop.area.PageViewport;
@@ -78,6 +79,7 @@ public class PageProvider implements Constants {
private PageSequence pageSeq;
protected boolean skipPagePositionOnly;
+ protected FOUserAgent foUserAgent;
/**
* Main constructor.
@@ -88,6 +90,7 @@ public class PageProvider implements Constants {
this.areaTreeHandler = ath;
this.pageSeq = ps;
this.startPageOfPageSequence = ps.getStartingPageNumber();
+ foUserAgent = ath.getUserAgent();
}
public void initialize() {
@@ -358,11 +361,12 @@ public class PageProvider implements Constants {
private Page cacheNextPage(int index, boolean isBlank, boolean isLastPage, boolean spanAll) {
String pageNumberString = pageSeq.makeFormattedPageNumber(index);
boolean isFirstPage = (startPageOfPageSequence == index);
+ boolean skipPagePositionOnlyCheck = skipPagePositionOnly && foUserAgent.isSkipPagePositionOnlyAllowed();
SimplePageMaster spm = pageSeq.getNextSimplePageMaster(
- index, isFirstPage, isLastPage, isBlank, skipPagePositionOnly);
+ index, isFirstPage, isLastPage, isBlank, skipPagePositionOnlyCheck);
boolean isPagePositionOnly = pageSeq.hasPagePositionOnly() && !skipPagePositionOnly;
if (isPagePositionOnly) {
- spm = pageSeq.getNextSimplePageMaster(index, isFirstPage, true, isBlank, skipPagePositionOnly);
+ spm = pageSeq.getNextSimplePageMaster(index, isFirstPage, true, isBlank, false);
}
Page page = new Page(spm, index, pageNumberString, isBlank, spanAll, isPagePositionOnly);
//Set unique key obtained from the AreaTreeHandler
diff --git a/fop-core/src/test/java/org/apache/fop/apps/MutableConfig.java b/fop-core/src/test/java/org/apache/fop/apps/MutableConfig.java
index 6f1a18752..27ff94f7c 100644
--- a/fop-core/src/test/java/org/apache/fop/apps/MutableConfig.java
+++ b/fop-core/src/test/java/org/apache/fop/apps/MutableConfig.java
@@ -141,6 +141,10 @@ public final class MutableConfig implements FopFactoryConfig {
return delegate.isSimpleLineBreaking();
}
+ public boolean isSkipPagePositionOnlyAllowed() {
+ return delegate.isSkipPagePositionOnlyAllowed();
+ }
+
public Map<String, String> getHyphenationPatternNames() {
return delegate.getHyphenationPatternNames();
}
diff --git a/fop-core/src/test/java/org/apache/fop/intermediate/TestAssistant.java b/fop-core/src/test/java/org/apache/fop/intermediate/TestAssistant.java
index 7048a9fd9..daf4b50dc 100644
--- a/fop-core/src/test/java/org/apache/fop/intermediate/TestAssistant.java
+++ b/fop-core/src/test/java/org/apache/fop/intermediate/TestAssistant.java
@@ -125,6 +125,7 @@ public class TestAssistant {
builder.getFontManager().setBase14KerningEnabled(isBase14KerningEnabled(testDoc));
builder.setTableBorderOverpaint(isTableBorderOverpaint(testDoc));
builder.setSimpleLineBreaking(isSimpleLineBreaking(testDoc));
+ builder.setSkipPagePositionOnlyAllowed(isSkipPagePositionOnlyAllowed(testDoc));
return builder.build();
}
@@ -169,6 +170,15 @@ public class TestAssistant {
}
}
+ private boolean isSkipPagePositionOnlyAllowed(Document testDoc) {
+ try {
+ String s = eval(testDoc, "/testcase/cfg/skip-page-position-only-allowed");
+ return !"false".equalsIgnoreCase(s);
+ } catch (XPathExpressionException e) {
+ throw new RuntimeException("Error while evaluating XPath expression", e);
+ }
+ }
+
/**
* Loads a test case into a DOM document.
* @param testFile the test file