Skip to content

Commit b39685b

Browse files
FOP-3219: Remove space generated by wrapper
1 parent 8c1be2a commit b39685b

File tree

12 files changed

+205
-31
lines changed

12 files changed

+205
-31
lines changed

fop-core/src/main/java/org/apache/fop/apps/FOUserAgent.java

+4
Original file line numberDiff line numberDiff line change
@@ -855,4 +855,8 @@ public boolean isLegacySkipPagePositionOnly() {
855855
public boolean isLegacyLastPageChangeIPD() {
856856
return factory.isLegacyLastPageChangeIPD();
857857
}
858+
859+
public boolean isLegacyFoWrapper() {
860+
return factory.isLegacyFoWrapper();
861+
}
858862
}

fop-core/src/main/java/org/apache/fop/apps/FopConfParser.java

+37-28
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@ public class FopConfParser {
6161
private static final String SKIP_PAGE_POSITION_ONLY_ALLOWED = "skip-page-position-only-allowed";
6262
private static final String LEGACY_SKIP_PAGE_POSITION_ONLY = "legacy-skip-page-position-only";
6363
private static final String LEGACY_LAST_PAGE_CHANGE_IPD = "legacy-last-page-change-ipd";
64+
private static final String LEGACY_FO_WRAPPER = "legacy-fo-wrapper";
6465

65-
private final Log log = LogFactory.getLog(FopConfParser.class);
66+
private static final Log LOG = LogFactory.getLog(FopConfParser.class);
6667

6768
private final FopFactoryBuilder fopFactoryBuilder;
6869

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

170171
private void configure(final URI baseURI, final ResourceResolver resourceResolver,
171172
Configuration cfg) throws FOPException {
172-
if (log.isDebugEnabled()) {
173-
log.debug("Initializing FopFactory Configuration");
173+
if (LOG.isDebugEnabled()) {
174+
LOG.debug("Initializing FopFactory Configuration");
174175
}
175176

176177
// strict fo validation
@@ -179,7 +180,7 @@ private void configure(final URI baseURI, final ResourceResolver resourceResolve
179180
boolean strict = cfg.getChild("strict-validation").getValueAsBoolean();
180181
fopFactoryBuilder.setStrictFOValidation(strict);
181182
} catch (ConfigurationException e) {
182-
LogUtil.handleException(log, e, false);
183+
LogUtil.handleException(LOG, e, false);
183184
}
184185
}
185186

@@ -189,7 +190,7 @@ private void configure(final URI baseURI, final ResourceResolver resourceResolve
189190
strict = cfg.getChild("strict-configuration").getValueAsBoolean();
190191
fopFactoryBuilder.setStrictUserConfigValidation(strict);
191192
} catch (ConfigurationException e) {
192-
LogUtil.handleException(log, e, false);
193+
LogUtil.handleException(LOG, e, false);
193194
}
194195
}
195196

@@ -199,7 +200,7 @@ private void configure(final URI baseURI, final ResourceResolver resourceResolve
199200
fopFactoryBuilder.setKeepEmptyTags(
200201
cfg.getChild("accessibility").getAttributeAsBoolean(Accessibility.KEEP_EMPTY_TAGS, true));
201202
} catch (ConfigurationException e) {
202-
LogUtil.handleException(log, e, false);
203+
LogUtil.handleException(LOG, e, false);
203204
}
204205
}
205206

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

@@ -218,41 +219,41 @@ private void configure(final URI baseURI, final ResourceResolver resourceResolve
218219
float srcRes = cfg.getChild("source-resolution").getValueAsFloat(
219220
FopFactoryConfig.DEFAULT_SOURCE_RESOLUTION);
220221
fopFactoryBuilder.setSourceResolution(srcRes);
221-
if (log.isDebugEnabled()) {
222-
log.debug("source-resolution set to: " + srcRes + "dpi");
222+
if (LOG.isDebugEnabled()) {
223+
LOG.debug("source-resolution set to: " + srcRes + "dpi");
223224
}
224225
}
225226
if (cfg.getChild("target-resolution", false) != null) {
226227
float targetRes = cfg.getChild("target-resolution").getValueAsFloat(
227228
FopFactoryConfig.DEFAULT_TARGET_RESOLUTION);
228229
fopFactoryBuilder.setTargetResolution(targetRes);
229-
if (log.isDebugEnabled()) {
230-
log.debug("target-resolution set to: " + targetRes + "dpi");
230+
if (LOG.isDebugEnabled()) {
231+
LOG.debug("target-resolution set to: " + targetRes + "dpi");
231232
}
232233
}
233234
if (cfg.getChild("break-indent-inheritance", false) != null) {
234235
try {
235236
fopFactoryBuilder.setBreakIndentInheritanceOnReferenceAreaBoundary(
236237
cfg.getChild("break-indent-inheritance").getValueAsBoolean());
237238
} catch (ConfigurationException e) {
238-
LogUtil.handleException(log, e, strict);
239+
LogUtil.handleException(LOG, e, strict);
239240
}
240241
}
241242
Configuration pageConfig = cfg.getChild("default-page-settings");
242243
if (pageConfig.getAttribute("height", null) != null) {
243244
String pageHeight = pageConfig.getAttribute("height",
244245
FopFactoryConfig.DEFAULT_PAGE_HEIGHT);
245246
fopFactoryBuilder.setPageHeight(pageHeight);
246-
if (log.isInfoEnabled()) {
247-
log.info("Default page-height set to: " + pageHeight);
247+
if (LOG.isInfoEnabled()) {
248+
LOG.info("Default page-height set to: " + pageHeight);
248249
}
249250
}
250251
if (pageConfig.getAttribute("width", null) != null) {
251252
String pageWidth = pageConfig.getAttribute("width",
252253
FopFactoryConfig.DEFAULT_PAGE_WIDTH);
253254
fopFactoryBuilder.setPageWidth(pageWidth);
254-
if (log.isInfoEnabled()) {
255-
log.info("Default page-width set to: " + pageWidth);
255+
if (LOG.isInfoEnabled()) {
256+
LOG.info("Default page-width set to: " + pageWidth);
256257
}
257258
}
258259

@@ -271,7 +272,7 @@ private void configure(final URI baseURI, final ResourceResolver resourceResolve
271272
fopFactoryBuilder.setPreferRenderer(
272273
cfg.getChild(PREFER_RENDERER).getValueAsBoolean());
273274
} catch (ConfigurationException e) {
274-
LogUtil.handleException(log, e, strict);
275+
LogUtil.handleException(LOG, e, strict);
275276
}
276277
}
277278

@@ -280,7 +281,7 @@ private void configure(final URI baseURI, final ResourceResolver resourceResolve
280281
fopFactoryBuilder.setTableBorderOverpaint(
281282
cfg.getChild(TABLE_BORDER_OVERPAINT).getValueAsBoolean());
282283
} catch (ConfigurationException e) {
283-
LogUtil.handleException(log, e, false);
284+
LogUtil.handleException(LOG, e, false);
284285
}
285286
}
286287

@@ -289,7 +290,7 @@ private void configure(final URI baseURI, final ResourceResolver resourceResolve
289290
fopFactoryBuilder.setSimpleLineBreaking(
290291
cfg.getChild(SIMPLE_LINE_BREAKING).getValueAsBoolean());
291292
} catch (ConfigurationException e) {
292-
LogUtil.handleException(log, e, false);
293+
LogUtil.handleException(LOG, e, false);
293294
}
294295
}
295296

@@ -298,23 +299,31 @@ private void configure(final URI baseURI, final ResourceResolver resourceResolve
298299
fopFactoryBuilder.setSkipPagePositionOnlyAllowed(
299300
cfg.getChild(SKIP_PAGE_POSITION_ONLY_ALLOWED).getValueAsBoolean());
300301
} catch (ConfigurationException e) {
301-
LogUtil.handleException(log, e, false);
302+
LogUtil.handleException(LOG, e, false);
302303
}
303304
}
304305
if (cfg.getChild(LEGACY_SKIP_PAGE_POSITION_ONLY, false) != null) {
305306
try {
306307
fopFactoryBuilder.setLegacySkipPagePositionOnly(
307308
cfg.getChild(LEGACY_SKIP_PAGE_POSITION_ONLY).getValueAsBoolean());
308309
} catch (ConfigurationException e) {
309-
LogUtil.handleException(log, e, false);
310+
LogUtil.handleException(LOG, e, false);
310311
}
311312
}
312313
if (cfg.getChild(LEGACY_LAST_PAGE_CHANGE_IPD, false) != null) {
313314
try {
314315
fopFactoryBuilder.setLegacyLastPageChangeIPD(
315316
cfg.getChild(LEGACY_LAST_PAGE_CHANGE_IPD).getValueAsBoolean());
316317
} catch (ConfigurationException e) {
317-
LogUtil.handleException(log, e, false);
318+
LogUtil.handleException(LOG, e, false);
319+
}
320+
}
321+
if (cfg.getChild(LEGACY_FO_WRAPPER, false) != null) {
322+
try {
323+
fopFactoryBuilder.setLegacyFoWrapper(
324+
cfg.getChild(LEGACY_FO_WRAPPER).getValueAsBoolean());
325+
} catch (ConfigurationException e) {
326+
LogUtil.handleException(LOG, e, false);
318327
}
319328
}
320329

@@ -336,7 +345,7 @@ private void setHyphenationBase(Configuration cfg, ResourceResolver resourceReso
336345
ResourceResolverFactory.createInternalResourceResolver(
337346
baseURI.resolve(fontBase), resourceResolver));
338347
} catch (URISyntaxException use) {
339-
LogUtil.handleException(log, use, true);
348+
LogUtil.handleException(LOG, use, true);
340349
}
341350
} else {
342351
fopFactoryBuilder.setHyphenBaseResourceResolver(
@@ -388,7 +397,7 @@ private void setHyphPatNames(Configuration cfg, FopFactoryBuilder builder, boole
388397
}
389398

390399
if (error.length() != 0) {
391-
LogUtil.handleError(log, error.toString(), strict);
400+
LogUtil.handleError(LOG, error.toString(), strict);
392401
continue;
393402
}
394403

@@ -402,8 +411,8 @@ private void setHyphPatNames(Configuration cfg, FopFactoryBuilder builder, boole
402411
} else {
403412
hyphPatNames.put(llccKey, filename);
404413
}
405-
if (log.isDebugEnabled()) {
406-
log.debug("Using hyphenation pattern filename " + filename
414+
if (LOG.isDebugEnabled()) {
415+
LOG.debug("Using hyphenation pattern filename " + filename
407416
+ " for lang=\"" + lang + "\""
408417
+ (country != null ? ", country=\"" + country + "\"" : ""));
409418
}
@@ -436,15 +445,15 @@ private void configureImageLoading(Configuration parent, boolean strict) throws
436445
try {
437446
p = Penalty.toPenalty(Integer.parseInt(value));
438447
} catch (NumberFormatException nfe) {
439-
LogUtil.handleException(log, nfe, strict);
448+
LogUtil.handleException(LOG, nfe, strict);
440449
}
441450
}
442451
if (p != null) {
443452
registry.setAdditionalPenalty(className, p);
444453
}
445454
}
446455
} catch (ConfigurationException e) {
447-
LogUtil.handleException(log, e, strict);
456+
LogUtil.handleException(LOG, e, strict);
448457
}
449458
}
450459

fop-core/src/main/java/org/apache/fop/apps/FopFactory.java

+4
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,10 @@ boolean isLegacyLastPageChangeIPD() {
252252
return config.isLegacyLastPageChangeIPD();
253253
}
254254

255+
boolean isLegacyFoWrapper() {
256+
return config.isLegacyFoWrapper();
257+
}
258+
255259
/**
256260
* Returns a new {@link Fop} instance. FOP will be configured with a default user agent
257261
* instance. Use this factory method if your output type requires an output stream.

fop-core/src/main/java/org/apache/fop/apps/FopFactoryBuilder.java

+21
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,11 @@ public FopFactoryBuilder setLegacyLastPageChangeIPD(boolean b) {
365365
return this;
366366
}
367367

368+
public FopFactoryBuilder setLegacyFoWrapper(boolean b) {
369+
fopFactoryConfigBuilder.setLegacyFoWrapper(b);
370+
return this;
371+
}
372+
368373
public static class FopFactoryConfigImpl implements FopFactoryConfig {
369374

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

416421
private boolean legacyLastPageChangeIPD;
417422

423+
private boolean legacyFoWrapper;
424+
418425
private static final class ImageContextImpl implements ImageContext {
419426

420427
private final FopFactoryConfig config;
@@ -551,6 +558,10 @@ public boolean isLegacyLastPageChangeIPD() {
551558
return legacyLastPageChangeIPD;
552559
}
553560

561+
public boolean isLegacyFoWrapper() {
562+
return legacyFoWrapper;
563+
}
564+
554565
public Map<String, String> getHyphenationPatternNames() {
555566
return hyphPatNames;
556567
}
@@ -606,6 +617,8 @@ private interface FopFactoryConfigBuilder {
606617
void setLegacySkipPagePositionOnly(boolean b);
607618

608619
void setLegacyLastPageChangeIPD(boolean b);
620+
621+
void setLegacyFoWrapper(boolean b);
609622
}
610623

611624
private static final class CompletedFopFactoryConfigBuilder implements FopFactoryConfigBuilder {
@@ -709,6 +722,10 @@ public void setLegacySkipPagePositionOnly(boolean b) {
709722
public void setLegacyLastPageChangeIPD(boolean b) {
710723
throwIllegalStateException();
711724
}
725+
726+
public void setLegacyFoWrapper(boolean b) {
727+
throwIllegalStateException();
728+
}
712729
}
713730

714731
private static final class ActiveFopFactoryConfigBuilder implements FopFactoryConfigBuilder {
@@ -813,6 +830,10 @@ public void setLegacySkipPagePositionOnly(boolean b) {
813830
public void setLegacyLastPageChangeIPD(boolean b) {
814831
config.legacyLastPageChangeIPD = b;
815832
}
833+
834+
public void setLegacyFoWrapper(boolean b) {
835+
config.legacyFoWrapper = b;
836+
}
816837
}
817838

818839
}

fop-core/src/main/java/org/apache/fop/apps/FopFactoryConfig.java

+2
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ public interface FopFactoryConfig {
173173

174174
boolean isLegacyLastPageChangeIPD();
175175

176+
boolean isLegacyFoWrapper();
177+
176178
/** @return the hyphenation pattern names */
177179
Map<String, String> getHyphenationPatternNames();
178180

fop-core/src/main/java/org/apache/fop/layoutmgr/inline/LeafNodeLayoutManager.java

+7-2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
3333
import org.apache.fop.layoutmgr.AbstractLayoutManager;
3434
import org.apache.fop.layoutmgr.InlineKnuthSequence;
35+
import org.apache.fop.layoutmgr.KnuthBox;
3536
import org.apache.fop.layoutmgr.KnuthGlue;
3637
import org.apache.fop.layoutmgr.KnuthPenalty;
3738
import org.apache.fop.layoutmgr.KnuthSequence;
@@ -278,15 +279,19 @@ public List<KnuthSequence> getNextKnuthElements(LayoutContext context, int align
278279

279280
addKnuthElementsForBorderPaddingStart(seq);
280281

281-
seq.add(new KnuthInlineBox(areaInfo.ipdArea.getOpt(), alignmentContext,
282-
notifyPos(new LeafPosition(this, 0)), false));
282+
seq.add(makeBox());
283283

284284
addKnuthElementsForBorderPaddingEnd(seq);
285285

286286
setFinished(true);
287287
return Collections.singletonList(seq);
288288
}
289289

290+
protected KnuthBox makeBox() {
291+
return new KnuthInlineBox(areaInfo.ipdArea.getOpt(), alignmentContext,
292+
notifyPos(new LeafPosition(this, 0)), false);
293+
}
294+
290295
/** {@inheritDoc} */
291296
public List<ListElement> addALetterSpaceTo(List<ListElement> oldList) {
292297
// return the unchanged elements

fop-core/src/main/java/org/apache/fop/layoutmgr/inline/WrapperLayoutManager.java

+9
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@
2727
import org.apache.fop.fo.flow.Wrapper;
2828
import org.apache.fop.layoutmgr.BlockLayoutManager;
2929
import org.apache.fop.layoutmgr.BlockStackingLayoutManager;
30+
import org.apache.fop.layoutmgr.KnuthBox;
3031
import org.apache.fop.layoutmgr.KnuthSequence;
3132
import org.apache.fop.layoutmgr.LayoutContext;
33+
import org.apache.fop.layoutmgr.LeafPosition;
3234
import org.apache.fop.layoutmgr.PositionIterator;
3335
import org.apache.fop.layoutmgr.TraitSetter;
3436

@@ -98,4 +100,11 @@ public List<KnuthSequence> getNextKnuthElements(LayoutContext context, int align
98100
}
99101
return list;
100102
}
103+
104+
protected KnuthBox makeBox() {
105+
if (parentLayoutManager instanceof InlineLayoutManager || fobj.getUserAgent().isLegacyFoWrapper()) {
106+
return super.makeBox();
107+
}
108+
return new KnuthBox(areaInfo.ipdArea.getOpt(), notifyPos(new LeafPosition(this, 0)), false);
109+
}
101110
}

fop-core/src/test/java/org/apache/fop/apps/MutableConfig.java

+4
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@ public boolean isLegacyLastPageChangeIPD() {
153153
return delegate.isLegacyLastPageChangeIPD();
154154
}
155155

156+
public boolean isLegacyFoWrapper() {
157+
return delegate.isLegacyFoWrapper();
158+
}
159+
156160
public Map<String, String> getHyphenationPatternNames() {
157161
return delegate.getHyphenationPatternNames();
158162
}

fop-core/src/test/java/org/apache/fop/intermediate/TestAssistant.java

+10
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ public FopFactory getFopFactory(Document testDoc) {
128128
builder.setSkipPagePositionOnlyAllowed(isSkipPagePositionOnlyAllowed(testDoc));
129129
builder.setLegacySkipPagePositionOnly(isLegacySkipPagePositionOnly(testDoc));
130130
builder.setLegacyLastPageChangeIPD(isLegacyLastPageChangeIPD(testDoc));
131+
builder.setLegacyFoWrapper(isLegacyFoWrapper(testDoc));
131132
return builder.build();
132133
}
133134

@@ -199,6 +200,15 @@ private boolean isLegacyLastPageChangeIPD(Document testDoc) {
199200
}
200201
}
201202

203+
private boolean isLegacyFoWrapper(Document testDoc) {
204+
try {
205+
String s = eval(testDoc, "/testcase/cfg/legacy-fo-wrapper");
206+
return "true".equalsIgnoreCase(s);
207+
} catch (XPathExpressionException e) {
208+
throw new RuntimeException(e);
209+
}
210+
}
211+
202212
/**
203213
* Loads a test case into a DOM document.
204214
* @param testFile the test file

0 commit comments

Comments
 (0)