git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1904062 13f79535-47bb-0310-9956-ffa450edef68tags/fop-2_8
@@ -835,4 +835,8 @@ public class FOUserAgent { | |||
public boolean isTableBorderOverpaint() { | |||
return factory.isTableBorderOverpaint(); | |||
} | |||
public boolean isSimpleLineBreaking() { | |||
return factory.isSimpleLineBreaking(); | |||
} | |||
} |
@@ -57,6 +57,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 final Log log = LogFactory.getLog(FopConfParser.class); | |||
@@ -280,6 +281,15 @@ public class FopConfParser { | |||
} | |||
} | |||
if (cfg.getChild(SIMPLE_LINE_BREAKING, false) != null) { | |||
try { | |||
fopFactoryBuilder.setSimpleLineBreaking( | |||
cfg.getChild(SIMPLE_LINE_BREAKING).getValueAsBoolean()); | |||
} catch (ConfigurationException e) { | |||
LogUtil.handleException(log, e, false); | |||
} | |||
} | |||
// configure font manager | |||
new FontManagerConfigurator(cfg, baseURI, fopFactoryBuilder.getBaseURI(), resourceResolver) | |||
.configure(fopFactoryBuilder.getFontManager(), strict); |
@@ -219,6 +219,10 @@ public final class FopFactory implements ImageContext { | |||
return config.isTableBorderOverpaint(); | |||
} | |||
boolean isSimpleLineBreaking() { | |||
return config.isSimpleLineBreaking(); | |||
} | |||
/** | |||
* 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. |
@@ -345,6 +345,11 @@ public final class FopFactoryBuilder { | |||
return this; | |||
} | |||
public FopFactoryBuilder setSimpleLineBreaking(boolean b) { | |||
fopFactoryConfigBuilder.setSimpleLineBreaking(b); | |||
return this; | |||
} | |||
public static class FopFactoryConfigImpl implements FopFactoryConfig { | |||
private final EnvironmentProfile enviro; | |||
@@ -387,6 +392,7 @@ public final class FopFactoryBuilder { | |||
private Map<String, String> hyphPatNames; | |||
private boolean tableBorderOverpaint; | |||
private boolean simpleLineBreaking; | |||
private static final class ImageContextImpl implements ImageContext { | |||
@@ -508,6 +514,10 @@ public final class FopFactoryBuilder { | |||
return tableBorderOverpaint; | |||
} | |||
public boolean isSimpleLineBreaking() { | |||
return simpleLineBreaking; | |||
} | |||
public Map<String, String> getHyphenationPatternNames() { | |||
return hyphPatNames; | |||
} | |||
@@ -555,6 +565,8 @@ public final class FopFactoryBuilder { | |||
void setHyphPatNames(Map<String, String> hyphPatNames); | |||
void setTableBorderOverpaint(boolean b); | |||
void setSimpleLineBreaking(boolean b); | |||
} | |||
private static final class CompletedFopFactoryConfigBuilder implements FopFactoryConfigBuilder { | |||
@@ -642,6 +654,10 @@ public final class FopFactoryBuilder { | |||
public void setTableBorderOverpaint(boolean b) { | |||
throwIllegalStateException(); | |||
} | |||
public void setSimpleLineBreaking(boolean b) { | |||
throwIllegalStateException(); | |||
} | |||
} | |||
private static final class ActiveFopFactoryConfigBuilder implements FopFactoryConfigBuilder { | |||
@@ -730,6 +746,10 @@ public final class FopFactoryBuilder { | |||
public void setTableBorderOverpaint(boolean b) { | |||
config.tableBorderOverpaint = b; | |||
} | |||
public void setSimpleLineBreaking(boolean b) { | |||
config.simpleLineBreaking = b; | |||
} | |||
} | |||
} |
@@ -165,6 +165,8 @@ public interface FopFactoryConfig { | |||
boolean isTableBorderOverpaint(); | |||
boolean isSimpleLineBreaking(); | |||
/** @return the hyphenation pattern names */ | |||
Map<String, String> getHyphenationPatternNames(); | |||
@@ -887,12 +887,14 @@ public class LineLayoutManager extends InlineStackingLayoutManager | |||
// now try something different | |||
log.debug("Hyphenation possible? " + canHyphenate); | |||
boolean simpleLineBreaking = fobj.getUserAgent().isSimpleLineBreaking(); | |||
// Note: if allowedBreaks is guaranteed to be unchanged by alg.findBreakingPoints(), | |||
// the below check can be simplified to 'if (canHyphenate) ...' | |||
if (canHyphenate && allowedBreaks != BreakingAlgorithm.ONLY_FORCED_BREAKS) { | |||
// consider every hyphenation point as a legal break | |||
allowedBreaks = BreakingAlgorithm.ALL_BREAKS; | |||
} else { | |||
} else if (!simpleLineBreaking) { | |||
// try with a higher threshold | |||
maxAdjustment = 5; | |||
} | |||
@@ -905,7 +907,9 @@ public class LineLayoutManager extends InlineStackingLayoutManager | |||
log.debug("No set of breaking points found with maxAdjustment = " | |||
+ maxAdjustment + (canHyphenate ? " and hyphenation" : "")); | |||
} | |||
maxAdjustment = 20; | |||
if (!simpleLineBreaking) { | |||
maxAdjustment = 20; | |||
} | |||
alg.findBreakingPoints(currPar, maxAdjustment, true, allowedBreaks); | |||
} | |||
@@ -137,6 +137,10 @@ public final class MutableConfig implements FopFactoryConfig { | |||
return delegate.isTableBorderOverpaint(); | |||
} | |||
public boolean isSimpleLineBreaking() { | |||
return delegate.isSimpleLineBreaking(); | |||
} | |||
public Map<String, String> getHyphenationPatternNames() { | |||
return delegate.getHyphenationPatternNames(); | |||
} |
@@ -124,6 +124,7 @@ public class TestAssistant { | |||
builder.setStrictFOValidation(isStrictValidation(testDoc)); | |||
builder.getFontManager().setBase14KerningEnabled(isBase14KerningEnabled(testDoc)); | |||
builder.setTableBorderOverpaint(isTableBorderOverpaint(testDoc)); | |||
builder.setSimpleLineBreaking(isSimpleLineBreaking(testDoc)); | |||
return builder.build(); | |||
} | |||
@@ -159,6 +160,15 @@ public class TestAssistant { | |||
return (String) xPath.compile(xpath).evaluate(doc, XPathConstants.STRING); | |||
} | |||
private boolean isSimpleLineBreaking(Document testDoc) { | |||
try { | |||
String s = eval(testDoc, "/testcase/cfg/simple-line-breaking"); | |||
return "true".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 |