Browse Source

FOP-2860: Add light weight line breaking option

git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1904062 13f79535-47bb-0310-9956-ffa450edef68
tags/fop-2_8
Simon Steiner 1 year ago
parent
commit
3f35111f4c

+ 4
- 0
fop-core/src/main/java/org/apache/fop/apps/FOUserAgent.java View File

public boolean isTableBorderOverpaint() { public boolean isTableBorderOverpaint() {
return factory.isTableBorderOverpaint(); return factory.isTableBorderOverpaint();
} }

public boolean isSimpleLineBreaking() {
return factory.isSimpleLineBreaking();
}
} }

+ 10
- 0
fop-core/src/main/java/org/apache/fop/apps/FopConfParser.java View File



private static final String PREFER_RENDERER = "prefer-renderer"; private static final String PREFER_RENDERER = "prefer-renderer";
private static final String TABLE_BORDER_OVERPAINT = "table-border-overpaint"; 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); private final Log log = LogFactory.getLog(FopConfParser.class);


} }
} }


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 // configure font manager
new FontManagerConfigurator(cfg, baseURI, fopFactoryBuilder.getBaseURI(), resourceResolver) new FontManagerConfigurator(cfg, baseURI, fopFactoryBuilder.getBaseURI(), resourceResolver)
.configure(fopFactoryBuilder.getFontManager(), strict); .configure(fopFactoryBuilder.getFontManager(), strict);

+ 4
- 0
fop-core/src/main/java/org/apache/fop/apps/FopFactory.java View File

return config.isTableBorderOverpaint(); return config.isTableBorderOverpaint();
} }


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

/** /**
* Returns a new {@link Fop} instance. FOP will be configured with a default user agent * 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. * instance. Use this factory method if your output type requires an output stream.

+ 20
- 0
fop-core/src/main/java/org/apache/fop/apps/FopFactoryBuilder.java View File

return this; return this;
} }


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

public static class FopFactoryConfigImpl implements FopFactoryConfig { public static class FopFactoryConfigImpl implements FopFactoryConfig {


private final EnvironmentProfile enviro; private final EnvironmentProfile enviro;
private Map<String, String> hyphPatNames; private Map<String, String> hyphPatNames;


private boolean tableBorderOverpaint; private boolean tableBorderOverpaint;
private boolean simpleLineBreaking;


private static final class ImageContextImpl implements ImageContext { private static final class ImageContextImpl implements ImageContext {


return tableBorderOverpaint; return tableBorderOverpaint;
} }


public boolean isSimpleLineBreaking() {
return simpleLineBreaking;
}

public Map<String, String> getHyphenationPatternNames() { public Map<String, String> getHyphenationPatternNames() {
return hyphPatNames; return hyphPatNames;
} }
void setHyphPatNames(Map<String, String> hyphPatNames); void setHyphPatNames(Map<String, String> hyphPatNames);


void setTableBorderOverpaint(boolean b); void setTableBorderOverpaint(boolean b);

void setSimpleLineBreaking(boolean b);
} }


private static final class CompletedFopFactoryConfigBuilder implements FopFactoryConfigBuilder { private static final class CompletedFopFactoryConfigBuilder implements FopFactoryConfigBuilder {
public void setTableBorderOverpaint(boolean b) { public void setTableBorderOverpaint(boolean b) {
throwIllegalStateException(); throwIllegalStateException();
} }

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


private static final class ActiveFopFactoryConfigBuilder implements FopFactoryConfigBuilder { private static final class ActiveFopFactoryConfigBuilder implements FopFactoryConfigBuilder {
public void setTableBorderOverpaint(boolean b) { public void setTableBorderOverpaint(boolean b) {
config.tableBorderOverpaint = b; config.tableBorderOverpaint = b;
} }

public void setSimpleLineBreaking(boolean b) {
config.simpleLineBreaking = b;
}
} }


} }

+ 2
- 0
fop-core/src/main/java/org/apache/fop/apps/FopFactoryConfig.java View File



boolean isTableBorderOverpaint(); boolean isTableBorderOverpaint();


boolean isSimpleLineBreaking();

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



+ 6
- 2
fop-core/src/main/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java View File



// now try something different // now try something different
log.debug("Hyphenation possible? " + canHyphenate); log.debug("Hyphenation possible? " + canHyphenate);
boolean simpleLineBreaking = fobj.getUserAgent().isSimpleLineBreaking();

// Note: if allowedBreaks is guaranteed to be unchanged by alg.findBreakingPoints(), // Note: if allowedBreaks is guaranteed to be unchanged by alg.findBreakingPoints(),
// the below check can be simplified to 'if (canHyphenate) ...' // the below check can be simplified to 'if (canHyphenate) ...'
if (canHyphenate && allowedBreaks != BreakingAlgorithm.ONLY_FORCED_BREAKS) { if (canHyphenate && allowedBreaks != BreakingAlgorithm.ONLY_FORCED_BREAKS) {
// consider every hyphenation point as a legal break // consider every hyphenation point as a legal break
allowedBreaks = BreakingAlgorithm.ALL_BREAKS; allowedBreaks = BreakingAlgorithm.ALL_BREAKS;
} else {
} else if (!simpleLineBreaking) {
// try with a higher threshold // try with a higher threshold
maxAdjustment = 5; maxAdjustment = 5;
} }
log.debug("No set of breaking points found with maxAdjustment = " log.debug("No set of breaking points found with maxAdjustment = "
+ maxAdjustment + (canHyphenate ? " and hyphenation" : "")); + maxAdjustment + (canHyphenate ? " and hyphenation" : ""));
} }
maxAdjustment = 20;
if (!simpleLineBreaking) {
maxAdjustment = 20;
}
alg.findBreakingPoints(currPar, maxAdjustment, true, allowedBreaks); alg.findBreakingPoints(currPar, maxAdjustment, true, allowedBreaks);
} }



+ 4
- 0
fop-core/src/test/java/org/apache/fop/apps/MutableConfig.java View File

return delegate.isTableBorderOverpaint(); return delegate.isTableBorderOverpaint();
} }


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

public Map<String, String> getHyphenationPatternNames() { public Map<String, String> getHyphenationPatternNames() {
return delegate.getHyphenationPatternNames(); return delegate.getHyphenationPatternNames();
} }

+ 10
- 0
fop-core/src/test/java/org/apache/fop/intermediate/TestAssistant.java View File

builder.setStrictFOValidation(isStrictValidation(testDoc)); builder.setStrictFOValidation(isStrictValidation(testDoc));
builder.getFontManager().setBase14KerningEnabled(isBase14KerningEnabled(testDoc)); builder.getFontManager().setBase14KerningEnabled(isBase14KerningEnabled(testDoc));
builder.setTableBorderOverpaint(isTableBorderOverpaint(testDoc)); builder.setTableBorderOverpaint(isTableBorderOverpaint(testDoc));
builder.setSimpleLineBreaking(isSimpleLineBreaking(testDoc));
return builder.build(); return builder.build();
} }


return (String) xPath.compile(xpath).evaluate(doc, XPathConstants.STRING); 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. * Loads a test case into a DOM document.
* @param testFile the test file * @param testFile the test file

+ 49
- 0
fop/test/layoutengine/standard-testcases/simple-line-breaking.xml
File diff suppressed because it is too large
View File


Loading…
Cancel
Save