aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org
diff options
context:
space:
mode:
authorLuca Furini <lfurini@apache.org>2005-09-16 13:24:16 +0000
committerLuca Furini <lfurini@apache.org>2005-09-16 13:24:16 +0000
commitbbd08a9bb0c11581bf3ef496d5b8aacab30d8c6a (patch)
tree77796af4d649618ddaefed0f538bf6a09b30a6a4 /src/java/org
parent29697aee2699b47a3951a266463306b88ce2c38b (diff)
downloadxmlgraphics-fop-bbd08a9bb0c11581bf3ef496d5b8aacab30d8c6a.tar.gz
xmlgraphics-fop-bbd08a9bb0c11581bf3ef496d5b8aacab30d8c6a.zip
Implemented the wrap-option property.
The overflow property is not yet implemented, so at the moment if wrap-option = "no-wrap" and the text overflows it invades the margins. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@289531 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org')
-rw-r--r--src/java/org/apache/fop/fo/flow/Block.java7
-rw-r--r--src/java/org/apache/fop/layoutmgr/AbstractBreaker.java4
-rw-r--r--src/java/org/apache/fop/layoutmgr/BreakingAlgorithm.java24
-rw-r--r--src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java2
-rw-r--r--src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java32
5 files changed, 45 insertions, 24 deletions
diff --git a/src/java/org/apache/fop/fo/flow/Block.java b/src/java/org/apache/fop/fo/flow/Block.java
index f9a79bbdb..45f8cc959 100644
--- a/src/java/org/apache/fop/fo/flow/Block.java
+++ b/src/java/org/apache/fop/fo/flow/Block.java
@@ -305,6 +305,13 @@ public class Block extends FObjMixed {
}
/**
+ * @return the "wrap-option" property.
+ */
+ public int getWrapOption() {
+ return wrapOption;
+ }
+
+ /**
* @see org.apache.fop.fo.FONode#validateChildNode(Locator, String, String)
* XSL Content Model: marker* initial-property-set? (#PCDATA|%inline;|%block;)*
* Additionally: "An fo:bidi-override that is a descendant of an fo:leader
diff --git a/src/java/org/apache/fop/layoutmgr/AbstractBreaker.java b/src/java/org/apache/fop/layoutmgr/AbstractBreaker.java
index cd011b366..74df8e188 100644
--- a/src/java/org/apache/fop/layoutmgr/AbstractBreaker.java
+++ b/src/java/org/apache/fop/layoutmgr/AbstractBreaker.java
@@ -237,7 +237,7 @@ public abstract class AbstractBreaker {
//iOptPageCount = alg.firstFit(effectiveList, flowBPD, 1, true);
alg.setConstantLineWidth(flowBPD);
iOptPageCount = alg.findBreakingPoints(effectiveList, /*flowBPD,*/
- 1, true, true);
+ 1, true, BreakingAlgorithm.ALL_BREAKS);
log.debug("PLM> iOptPageCount= " + iOptPageCount
+ " pageBreaks.size()= " + alg.getPageBreaks().size());
@@ -519,7 +519,7 @@ public abstract class AbstractBreaker {
int iOptPageNumber;
alg.setConstantLineWidth(availableBPD);
iOptPageNumber = alg.findBreakingPoints(blockList, /*availableBPD,*/
- 1, true, true);
+ 1, true, BreakingAlgorithm.ALL_BREAKS);
log.debug("PLM> iOptPageNumber= " + iOptPageNumber);
//
diff --git a/src/java/org/apache/fop/layoutmgr/BreakingAlgorithm.java b/src/java/org/apache/fop/layoutmgr/BreakingAlgorithm.java
index 5909f3391..c689e37a3 100644
--- a/src/java/org/apache/fop/layoutmgr/BreakingAlgorithm.java
+++ b/src/java/org/apache/fop/layoutmgr/BreakingAlgorithm.java
@@ -47,6 +47,11 @@ public abstract class BreakingAlgorithm {
private static final int MAX_RECOVERY_ATTEMPTS = 50;
+ // constants identifying a subset of the feasible breaks
+ public static final int ALL_BREAKS = 0; // all feasible breaks are ok
+ public static final int NO_FLAGGED_PENALTIES = 1; // this forbids hyphenation
+ public static final int ONLY_FORCED_BREAKS = 2; // wrap-option = "no-wrap"
+
// parameters of Knuth's algorithm:
// penalty value for flagged penalties
private int flaggedPenalty = 50;
@@ -324,14 +329,14 @@ public abstract class BreakingAlgorithm {
public int findBreakingPoints(KnuthSequence par, /*int lineWidth,*/
double threshold, boolean force,
- boolean hyphenationAllowed) {
- return findBreakingPoints(par, 0, threshold, force, hyphenationAllowed);
+ int allowedBreaks) {
+ return findBreakingPoints(par, 0, threshold, force, allowedBreaks);
}
public int findBreakingPoints(KnuthSequence par, int startIndex,
/*int lineWidth,*/
double threshold, boolean force,
- boolean hyphenationAllowed) {
+ int allowedBreaks) {
this.par = par;
this.threshold = threshold;
this.force = force;
@@ -378,7 +383,9 @@ public abstract class BreakingAlgorithm {
} else if (thisElement.isGlue()) {
// a KnuthGlue object is a legal line break
// only if the previous object is a KnuthBox
- if (previousIsBox) {
+ // consider these glues according to the value of allowedBreaks
+ if (previousIsBox
+ && !(allowedBreaks == ONLY_FORCED_BREAKS)) {
considerLegalBreak(thisElement, i);
}
totalWidth += thisElement.getW();
@@ -388,10 +395,11 @@ public abstract class BreakingAlgorithm {
} else {
// a KnuthPenalty is a legal line break
// only if its penalty is not infinite;
- // if hyphenationAllowed is false, ignore flagged penalties
- if (((KnuthPenalty) thisElement).getP()
- < KnuthElement.INFINITE
- && (hyphenationAllowed || !((KnuthPenalty) thisElement).isFlagged())) {
+ // consider all penalties, non-flagged penalties or non-forcing penalties
+ // according to the value of allowedBreaks
+ if (((KnuthPenalty) thisElement).getP() < KnuthElement.INFINITE
+ && (!(allowedBreaks == NO_FLAGGED_PENALTIES) || !(((KnuthPenalty) thisElement).isFlagged()))
+ && (!(allowedBreaks == ONLY_FORCED_BREAKS) || ((KnuthPenalty) thisElement).getP() == -KnuthElement.INFINITE)) {
considerLegalBreak(thisElement, i);
}
previousIsBox = false;
diff --git a/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java b/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java
index 57ceb82a0..ed557b5a8 100644
--- a/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java
+++ b/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java
@@ -340,7 +340,7 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager {
//alg.setConstantLineWidth(flowBPD);
int iOptPageCount = algRestart.findBreakingPoints(effectiveList,
newStartPos,
- 1, true, true);
+ 1, true, BreakingAlgorithm.ALL_BREAKS);
AbstractBreaker.log.debug("restart: iOptPageCount= " + iOptPageCount
+ " pageBreaks.size()= " + algRestart.getPageBreaks().size());
if (iOptPageCount > getCurrentPV().getBodyRegion().getColumnCount()) {
diff --git a/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java b/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java
index d0aa71e12..86f13b2cd 100644
--- a/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java
+++ b/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java
@@ -74,7 +74,7 @@ public class LineLayoutManager extends InlineStackingLayoutManager
textIndent = fobj.getTextIndent();
lastLineEndIndent = fobj.getLastLineEndIndent();
hyphProps = fobj.getCommonHyphenation();
-
+ wrapOption = fobj.getWrapOption();
//
effectiveAlignment = getEffectiveAlignment(bTextAlignment, bTextAlignmentLast);
}
@@ -139,6 +139,7 @@ public class LineLayoutManager extends InlineStackingLayoutManager
private Length lastLineEndIndent;
private int iIndents = 0;
private CommonHyphenation hyphProps;
+ private int wrapOption = EN_WRAP;
//private LayoutProps layoutProps;
private Length lineHeight;
@@ -404,8 +405,7 @@ public class LineLayoutManager extends InlineStackingLayoutManager
(textAlign == Constants.EN_END) ? difference : 0;
indent += (bestActiveNode.line == 1 && bFirst) ?
textIndent : 0;
- double ratio = (textAlign == Constants.EN_JUSTIFY
- || bestActiveNode.adjustRatio < 0) ? bestActiveNode.adjustRatio : 0;
+ double ratio = (textAlign == Constants.EN_JUSTIFY) ? bestActiveNode.adjustRatio : 0;
// add nodes at the beginning of the list, as they are found
// backwards, from the last one to the first one
@@ -518,9 +518,9 @@ public class LineLayoutManager extends InlineStackingLayoutManager
public int findBreakingPoints(Paragraph par, /*int lineWidth,*/
double threshold, boolean force,
- boolean hyphenationAllowed) {
+ int allowedBreaks) {
return super.findBreakingPoints(par, /*lineWidth,*/
- threshold, force, hyphenationAllowed);
+ threshold, force, allowedBreaks);
}
protected int filterActiveNodes() {
@@ -1025,10 +1025,15 @@ public class LineLayoutManager extends InlineStackingLayoutManager
}
// first try
- boolean bHyphenationAllowed = false;
+ int allowedBreaks;
+ if (wrapOption == EN_NO_WRAP) {
+ allowedBreaks = BreakingAlgorithm.ONLY_FORCED_BREAKS;
+ } else {
+ allowedBreaks = BreakingAlgorithm.NO_FLAGGED_PENALTIES;
+ }
alg.setConstantLineWidth(iLineWidth);
iBPcount = alg.findBreakingPoints(currPar,
- maxAdjustment, false, bHyphenationAllowed);
+ maxAdjustment, false, allowedBreaks);
if (iBPcount == 0 || alignment == EN_JUSTIFY) {
// if the first try found a set of breaking points, save them
if (iBPcount > 0) {
@@ -1041,9 +1046,10 @@ public class LineLayoutManager extends InlineStackingLayoutManager
// now try something different
log.debug("Hyphenation possible? " + (hyphProps.hyphenate == EN_TRUE));
- if (hyphProps.hyphenate == EN_TRUE) {
+ if (hyphProps.hyphenate == EN_TRUE
+ && !(allowedBreaks == BreakingAlgorithm.ONLY_FORCED_BREAKS)) {
// consider every hyphenation point as a legal break
- bHyphenationAllowed = true;
+ allowedBreaks = BreakingAlgorithm.ALL_BREAKS;
} else {
// try with a higher threshold
maxAdjustment = 5;
@@ -1051,7 +1057,7 @@ public class LineLayoutManager extends InlineStackingLayoutManager
if ((iBPcount
= alg.findBreakingPoints(currPar,
- maxAdjustment, false, bHyphenationAllowed)) == 0) {
+ maxAdjustment, false, allowedBreaks)) == 0) {
// the second try failed too, try with a huge threshold
// and force the algorithm to find
// a set of breaking points
@@ -1060,7 +1066,7 @@ public class LineLayoutManager extends InlineStackingLayoutManager
maxAdjustment = 20;
iBPcount
= alg.findBreakingPoints(currPar,
- maxAdjustment, true, bHyphenationAllowed);
+ maxAdjustment, true, allowedBreaks);
}
// use non-hyphenated breaks, when possible
@@ -1080,7 +1086,7 @@ public class LineLayoutManager extends InlineStackingLayoutManager
int savedLineWidth = iLineWidth;
iLineWidth = (int) (iLineWidth * 0.95);
iBPcount = alg.findBreakingPoints(currPar,
- maxAdjustment, true, bHyphenationAllowed);
+ maxAdjustment, true, allowedBreaks);
// use normal lines, when possible
lineLayouts.restorePossibilities();
iLineWidth = savedLineWidth;
@@ -1093,7 +1099,7 @@ public class LineLayoutManager extends InlineStackingLayoutManager
iLineWidth = (int) (iLineWidth * 1.05);
alg.setConstantLineWidth(iLineWidth);
iBPcount = alg.findBreakingPoints(currPar,
- maxAdjustment, true, bHyphenationAllowed);
+ maxAdjustment, true, allowedBreaks);
// use normal lines, when possible
lineLayouts.restorePossibilities();
iLineWidth = savedLineWidth;