Skip to content

Commit

Permalink
FOP-3219: Remove space generated by wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
simonsteiner1984 committed Nov 15, 2024
1 parent 8c1be2a commit b39685b
Show file tree
Hide file tree
Showing 12 changed files with 205 additions and 31 deletions.
4 changes: 4 additions & 0 deletions fop-core/src/main/java/org/apache/fop/apps/FOUserAgent.java
Original file line number Diff line number Diff line change
Expand Up @@ -855,4 +855,8 @@ public boolean isLegacySkipPagePositionOnly() {
public boolean isLegacyLastPageChangeIPD() {
return factory.isLegacyLastPageChangeIPD();
}

public boolean isLegacyFoWrapper() {
return factory.isLegacyFoWrapper();
}
}
65 changes: 37 additions & 28 deletions fop-core/src/main/java/org/apache/fop/apps/FopConfParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ public class FopConfParser {
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 static final String LEGACY_FO_WRAPPER = "legacy-fo-wrapper";

private final Log log = LogFactory.getLog(FopConfParser.class);
private static final Log LOG = LogFactory.getLog(FopConfParser.class);

private final FopFactoryBuilder fopFactoryBuilder;

Expand Down Expand Up @@ -169,8 +170,8 @@ public FopConfParser(Configuration cfg, FopFactoryBuilder fopFactoryBuilder) thr

private void configure(final URI baseURI, final ResourceResolver resourceResolver,
Configuration cfg) throws FOPException {
if (log.isDebugEnabled()) {
log.debug("Initializing FopFactory Configuration");
if (LOG.isDebugEnabled()) {
LOG.debug("Initializing FopFactory Configuration");
}

// strict fo validation
Expand All @@ -179,7 +180,7 @@ private void configure(final URI baseURI, final ResourceResolver resourceResolve
boolean strict = cfg.getChild("strict-validation").getValueAsBoolean();
fopFactoryBuilder.setStrictFOValidation(strict);
} catch (ConfigurationException e) {
LogUtil.handleException(log, e, false);
LogUtil.handleException(LOG, e, false);
}
}

Expand All @@ -189,7 +190,7 @@ private void configure(final URI baseURI, final ResourceResolver resourceResolve
strict = cfg.getChild("strict-configuration").getValueAsBoolean();
fopFactoryBuilder.setStrictUserConfigValidation(strict);
} catch (ConfigurationException e) {
LogUtil.handleException(log, e, false);
LogUtil.handleException(LOG, e, false);
}
}

Expand All @@ -199,7 +200,7 @@ private void configure(final URI baseURI, final ResourceResolver resourceResolve
fopFactoryBuilder.setKeepEmptyTags(
cfg.getChild("accessibility").getAttributeAsBoolean(Accessibility.KEEP_EMPTY_TAGS, true));
} catch (ConfigurationException e) {
LogUtil.handleException(log, e, false);
LogUtil.handleException(LOG, e, false);
}
}

Expand All @@ -209,7 +210,7 @@ private void configure(final URI baseURI, final ResourceResolver resourceResolve
URI confUri = InternalResourceResolver.getBaseURI(cfg.getChild("base").getValue(null));
fopFactoryBuilder.setBaseURI(baseURI.resolve(confUri));
} catch (URISyntaxException use) {
LogUtil.handleException(log, use, strict);
LogUtil.handleException(LOG, use, strict);
}
}

Expand All @@ -218,41 +219,41 @@ private void configure(final URI baseURI, final ResourceResolver resourceResolve
float srcRes = cfg.getChild("source-resolution").getValueAsFloat(
FopFactoryConfig.DEFAULT_SOURCE_RESOLUTION);
fopFactoryBuilder.setSourceResolution(srcRes);
if (log.isDebugEnabled()) {
log.debug("source-resolution set to: " + srcRes + "dpi");
if (LOG.isDebugEnabled()) {
LOG.debug("source-resolution set to: " + srcRes + "dpi");
}
}
if (cfg.getChild("target-resolution", false) != null) {
float targetRes = cfg.getChild("target-resolution").getValueAsFloat(
FopFactoryConfig.DEFAULT_TARGET_RESOLUTION);
fopFactoryBuilder.setTargetResolution(targetRes);
if (log.isDebugEnabled()) {
log.debug("target-resolution set to: " + targetRes + "dpi");
if (LOG.isDebugEnabled()) {
LOG.debug("target-resolution set to: " + targetRes + "dpi");
}
}
if (cfg.getChild("break-indent-inheritance", false) != null) {
try {
fopFactoryBuilder.setBreakIndentInheritanceOnReferenceAreaBoundary(
cfg.getChild("break-indent-inheritance").getValueAsBoolean());
} catch (ConfigurationException e) {
LogUtil.handleException(log, e, strict);
LogUtil.handleException(LOG, e, strict);
}
}
Configuration pageConfig = cfg.getChild("default-page-settings");
if (pageConfig.getAttribute("height", null) != null) {
String pageHeight = pageConfig.getAttribute("height",
FopFactoryConfig.DEFAULT_PAGE_HEIGHT);
fopFactoryBuilder.setPageHeight(pageHeight);
if (log.isInfoEnabled()) {
log.info("Default page-height set to: " + pageHeight);
if (LOG.isInfoEnabled()) {
LOG.info("Default page-height set to: " + pageHeight);
}
}
if (pageConfig.getAttribute("width", null) != null) {
String pageWidth = pageConfig.getAttribute("width",
FopFactoryConfig.DEFAULT_PAGE_WIDTH);
fopFactoryBuilder.setPageWidth(pageWidth);
if (log.isInfoEnabled()) {
log.info("Default page-width set to: " + pageWidth);
if (LOG.isInfoEnabled()) {
LOG.info("Default page-width set to: " + pageWidth);
}
}

Expand All @@ -271,7 +272,7 @@ private void configure(final URI baseURI, final ResourceResolver resourceResolve
fopFactoryBuilder.setPreferRenderer(
cfg.getChild(PREFER_RENDERER).getValueAsBoolean());
} catch (ConfigurationException e) {
LogUtil.handleException(log, e, strict);
LogUtil.handleException(LOG, e, strict);
}
}

Expand All @@ -280,7 +281,7 @@ private void configure(final URI baseURI, final ResourceResolver resourceResolve
fopFactoryBuilder.setTableBorderOverpaint(
cfg.getChild(TABLE_BORDER_OVERPAINT).getValueAsBoolean());
} catch (ConfigurationException e) {
LogUtil.handleException(log, e, false);
LogUtil.handleException(LOG, e, false);
}
}

Expand All @@ -289,7 +290,7 @@ private void configure(final URI baseURI, final ResourceResolver resourceResolve
fopFactoryBuilder.setSimpleLineBreaking(
cfg.getChild(SIMPLE_LINE_BREAKING).getValueAsBoolean());
} catch (ConfigurationException e) {
LogUtil.handleException(log, e, false);
LogUtil.handleException(LOG, e, false);
}
}

Expand All @@ -298,23 +299,31 @@ private void configure(final URI baseURI, final ResourceResolver resourceResolve
fopFactoryBuilder.setSkipPagePositionOnlyAllowed(
cfg.getChild(SKIP_PAGE_POSITION_ONLY_ALLOWED).getValueAsBoolean());
} catch (ConfigurationException e) {
LogUtil.handleException(log, e, false);
LogUtil.handleException(LOG, e, false);
}
}
if (cfg.getChild(LEGACY_SKIP_PAGE_POSITION_ONLY, false) != null) {
try {
fopFactoryBuilder.setLegacySkipPagePositionOnly(
cfg.getChild(LEGACY_SKIP_PAGE_POSITION_ONLY).getValueAsBoolean());
} catch (ConfigurationException e) {
LogUtil.handleException(log, e, false);
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);
LogUtil.handleException(LOG, e, false);
}
}
if (cfg.getChild(LEGACY_FO_WRAPPER, false) != null) {
try {
fopFactoryBuilder.setLegacyFoWrapper(
cfg.getChild(LEGACY_FO_WRAPPER).getValueAsBoolean());
} catch (ConfigurationException e) {
LogUtil.handleException(LOG, e, false);
}
}

Expand All @@ -336,7 +345,7 @@ private void setHyphenationBase(Configuration cfg, ResourceResolver resourceReso
ResourceResolverFactory.createInternalResourceResolver(
baseURI.resolve(fontBase), resourceResolver));
} catch (URISyntaxException use) {
LogUtil.handleException(log, use, true);
LogUtil.handleException(LOG, use, true);
}
} else {
fopFactoryBuilder.setHyphenBaseResourceResolver(
Expand Down Expand Up @@ -388,7 +397,7 @@ private void setHyphPatNames(Configuration cfg, FopFactoryBuilder builder, boole
}

if (error.length() != 0) {
LogUtil.handleError(log, error.toString(), strict);
LogUtil.handleError(LOG, error.toString(), strict);
continue;
}

Expand All @@ -402,8 +411,8 @@ private void setHyphPatNames(Configuration cfg, FopFactoryBuilder builder, boole
} else {
hyphPatNames.put(llccKey, filename);
}
if (log.isDebugEnabled()) {
log.debug("Using hyphenation pattern filename " + filename
if (LOG.isDebugEnabled()) {
LOG.debug("Using hyphenation pattern filename " + filename
+ " for lang=\"" + lang + "\""
+ (country != null ? ", country=\"" + country + "\"" : ""));
}
Expand Down Expand Up @@ -436,15 +445,15 @@ private void configureImageLoading(Configuration parent, boolean strict) throws
try {
p = Penalty.toPenalty(Integer.parseInt(value));
} catch (NumberFormatException nfe) {
LogUtil.handleException(log, nfe, strict);
LogUtil.handleException(LOG, nfe, strict);
}
}
if (p != null) {
registry.setAdditionalPenalty(className, p);
}
}
} catch (ConfigurationException e) {
LogUtil.handleException(log, e, strict);
LogUtil.handleException(LOG, e, strict);
}
}

Expand Down
4 changes: 4 additions & 0 deletions fop-core/src/main/java/org/apache/fop/apps/FopFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,10 @@ boolean isLegacyLastPageChangeIPD() {
return config.isLegacyLastPageChangeIPD();
}

boolean isLegacyFoWrapper() {
return config.isLegacyFoWrapper();
}

/**
* 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.
Expand Down
21 changes: 21 additions & 0 deletions fop-core/src/main/java/org/apache/fop/apps/FopFactoryBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,11 @@ public FopFactoryBuilder setLegacyLastPageChangeIPD(boolean b) {
return this;
}

public FopFactoryBuilder setLegacyFoWrapper(boolean b) {
fopFactoryConfigBuilder.setLegacyFoWrapper(b);
return this;
}

public static class FopFactoryConfigImpl implements FopFactoryConfig {

private final EnvironmentProfile enviro;
Expand Down Expand Up @@ -415,6 +420,8 @@ public static class FopFactoryConfigImpl implements FopFactoryConfig {

private boolean legacyLastPageChangeIPD;

private boolean legacyFoWrapper;

private static final class ImageContextImpl implements ImageContext {

private final FopFactoryConfig config;
Expand Down Expand Up @@ -551,6 +558,10 @@ public boolean isLegacyLastPageChangeIPD() {
return legacyLastPageChangeIPD;
}

public boolean isLegacyFoWrapper() {
return legacyFoWrapper;
}

public Map<String, String> getHyphenationPatternNames() {
return hyphPatNames;
}
Expand Down Expand Up @@ -606,6 +617,8 @@ private interface FopFactoryConfigBuilder {
void setLegacySkipPagePositionOnly(boolean b);

void setLegacyLastPageChangeIPD(boolean b);

void setLegacyFoWrapper(boolean b);
}

private static final class CompletedFopFactoryConfigBuilder implements FopFactoryConfigBuilder {
Expand Down Expand Up @@ -709,6 +722,10 @@ public void setLegacySkipPagePositionOnly(boolean b) {
public void setLegacyLastPageChangeIPD(boolean b) {
throwIllegalStateException();
}

public void setLegacyFoWrapper(boolean b) {
throwIllegalStateException();
}
}

private static final class ActiveFopFactoryConfigBuilder implements FopFactoryConfigBuilder {
Expand Down Expand Up @@ -813,6 +830,10 @@ public void setLegacySkipPagePositionOnly(boolean b) {
public void setLegacyLastPageChangeIPD(boolean b) {
config.legacyLastPageChangeIPD = b;
}

public void setLegacyFoWrapper(boolean b) {
config.legacyFoWrapper = b;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ public interface FopFactoryConfig {

boolean isLegacyLastPageChangeIPD();

boolean isLegacyFoWrapper();

/** @return the hyphenation pattern names */
Map<String, String> getHyphenationPatternNames();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
import org.apache.fop.layoutmgr.AbstractLayoutManager;
import org.apache.fop.layoutmgr.InlineKnuthSequence;
import org.apache.fop.layoutmgr.KnuthBox;
import org.apache.fop.layoutmgr.KnuthGlue;
import org.apache.fop.layoutmgr.KnuthPenalty;
import org.apache.fop.layoutmgr.KnuthSequence;
Expand Down Expand Up @@ -278,15 +279,19 @@ public List<KnuthSequence> getNextKnuthElements(LayoutContext context, int align

addKnuthElementsForBorderPaddingStart(seq);

seq.add(new KnuthInlineBox(areaInfo.ipdArea.getOpt(), alignmentContext,
notifyPos(new LeafPosition(this, 0)), false));
seq.add(makeBox());

addKnuthElementsForBorderPaddingEnd(seq);

setFinished(true);
return Collections.singletonList(seq);
}

protected KnuthBox makeBox() {
return new KnuthInlineBox(areaInfo.ipdArea.getOpt(), alignmentContext,
notifyPos(new LeafPosition(this, 0)), false);
}

/** {@inheritDoc} */
public List<ListElement> addALetterSpaceTo(List<ListElement> oldList) {
// return the unchanged elements
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@
import org.apache.fop.fo.flow.Wrapper;
import org.apache.fop.layoutmgr.BlockLayoutManager;
import org.apache.fop.layoutmgr.BlockStackingLayoutManager;
import org.apache.fop.layoutmgr.KnuthBox;
import org.apache.fop.layoutmgr.KnuthSequence;
import org.apache.fop.layoutmgr.LayoutContext;
import org.apache.fop.layoutmgr.LeafPosition;
import org.apache.fop.layoutmgr.PositionIterator;
import org.apache.fop.layoutmgr.TraitSetter;

Expand Down Expand Up @@ -98,4 +100,11 @@ public List<KnuthSequence> getNextKnuthElements(LayoutContext context, int align
}
return list;
}

protected KnuthBox makeBox() {
if (parentLayoutManager instanceof InlineLayoutManager || fobj.getUserAgent().isLegacyFoWrapper()) {
return super.makeBox();
}
return new KnuthBox(areaInfo.ipdArea.getOpt(), notifyPos(new LeafPosition(this, 0)), false);
}
}
4 changes: 4 additions & 0 deletions fop-core/src/test/java/org/apache/fop/apps/MutableConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ public boolean isLegacyLastPageChangeIPD() {
return delegate.isLegacyLastPageChangeIPD();
}

public boolean isLegacyFoWrapper() {
return delegate.isLegacyFoWrapper();
}

public Map<String, String> getHyphenationPatternNames() {
return delegate.getHyphenationPatternNames();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ public FopFactory getFopFactory(Document testDoc) {
builder.setSkipPagePositionOnlyAllowed(isSkipPagePositionOnlyAllowed(testDoc));
builder.setLegacySkipPagePositionOnly(isLegacySkipPagePositionOnly(testDoc));
builder.setLegacyLastPageChangeIPD(isLegacyLastPageChangeIPD(testDoc));
builder.setLegacyFoWrapper(isLegacyFoWrapper(testDoc));
return builder.build();
}

Expand Down Expand Up @@ -199,6 +200,15 @@ private boolean isLegacyLastPageChangeIPD(Document testDoc) {
}
}

private boolean isLegacyFoWrapper(Document testDoc) {
try {
String s = eval(testDoc, "/testcase/cfg/legacy-fo-wrapper");
return "true".equalsIgnoreCase(s);
} catch (XPathExpressionException e) {
throw new RuntimeException(e);
}
}

/**
* Loads a test case into a DOM document.
* @param testFile the test file
Expand Down
Loading

0 comments on commit b39685b

Please sign in to comment.