public class SpaceSpecifier implements Cloneable {
- private boolean bStartsReferenceArea;
- private boolean bHasForcing = false;
- private List vecSpaceVals = new java.util.ArrayList();
+ private boolean startsReferenceArea;
+ private boolean hasForcing = false;
+ private List spaceVals = new ArrayList();
/**
* Creates a new SpaceSpecifier.
- * @param bStarts true if it starts a new reference area
+ * @param startsReferenceArea true if it starts a new reference area
*/
- public SpaceSpecifier(boolean bStarts) {
- bStartsReferenceArea = bStarts;
+ public SpaceSpecifier(boolean startsReferenceArea) {
+ this.startsReferenceArea = startsReferenceArea;
}
/**
public Object clone() {
try {
SpaceSpecifier ss = (SpaceSpecifier) super.clone();
- ss.bStartsReferenceArea = this.bStartsReferenceArea;
- ss.bHasForcing = this.bHasForcing;
+ ss.startsReferenceArea = startsReferenceArea;
+ ss.hasForcing = hasForcing;
// Clone the vector, but share the objects in it!
- ss.vecSpaceVals = new ArrayList();
- ss.vecSpaceVals.addAll(this.vecSpaceVals);
+ ss.spaceVals = new ArrayList();
+ ss.spaceVals.addAll(spaceVals);
return ss;
} catch (CloneNotSupportedException cnse) {
return null;
* Clear all space specifiers
*/
public void clear() {
- bHasForcing = false;
- vecSpaceVals.clear();
+ hasForcing = false;
+ spaceVals.clear();
}
/**
* @return true if any space-specifiers have been added.
*/
public boolean hasSpaces() {
- return (vecSpaceVals.size() > 0);
+ return (spaceVals.size() > 0);
}
/**
* add it to the sequence.
*/
public void addSpace(SpaceVal moreSpace) {
- if (!bStartsReferenceArea
+ if (!startsReferenceArea
|| !moreSpace.isConditional()
- || !vecSpaceVals.isEmpty()) {
+ || !spaceVals.isEmpty()) {
if (moreSpace.isForcing()) {
- if (bHasForcing == false) {
+ if (!hasForcing) {
// Remove all other values (must all be non-forcing)
- vecSpaceVals.clear();
- bHasForcing = true;
+ spaceVals.clear();
+ hasForcing = true;
}
- vecSpaceVals.add(moreSpace);
- } else if (bHasForcing == false) {
+ spaceVals.add(moreSpace);
+ } else if (!hasForcing) {
// Don't bother adding all 0 space-specifier if not forcing
if (moreSpace.getSpace().min != 0
|| moreSpace.getSpace().opt != 0
|| moreSpace.getSpace().max != 0) {
- vecSpaceVals.add(moreSpace);
+ spaceVals.add(moreSpace);
}
}
}
/**
* Resolve the current sequence of space-specifiers, accounting for
* forcing values.
- * @param bEndsReferenceArea True if the sequence should be resolved
+ * @param endsReferenceArea True if the sequence should be resolved
* at the trailing edge of reference area.
* @return The resolved value as a min/opt/max triple.
*/
- public MinOptMax resolve(boolean bEndsReferenceArea) {
- int lastIndex = vecSpaceVals.size();
- if (bEndsReferenceArea) {
+ public MinOptMax resolve(boolean endsReferenceArea) {
+ int lastIndex = spaceVals.size();
+ if (endsReferenceArea) {
// Start from the end and count conditional specifiers
// Stop at first non-conditional
for (; lastIndex > 0; --lastIndex) {
- SpaceVal sval = (SpaceVal) vecSpaceVals.get(
- lastIndex - 1);
- if (!sval.isConditional()) {
+ SpaceVal spaceVal = (SpaceVal) spaceVals.get(lastIndex - 1);
+ if (!spaceVal.isConditional()) {
break;
}
}
}
- MinOptMax resSpace = new MinOptMax(0);
- int iMaxPrec = -1;
+ MinOptMax resolvedSpace = new MinOptMax(0);
+ int maxPrecedence = -1;
for (int index = 0; index < lastIndex; index++) {
- SpaceVal sval = (SpaceVal) vecSpaceVals.get(index);
- if (bHasForcing) {
- resSpace.add(sval.getSpace());
- } else if (sval.getPrecedence() > iMaxPrec) {
- iMaxPrec = sval.getPrecedence();
- resSpace = sval.getSpace();
- } else if (sval.getPrecedence() == iMaxPrec) {
- if (sval.getSpace().opt > resSpace.opt) {
- resSpace = sval.getSpace();
- } else if (sval.getSpace().opt == resSpace.opt) {
- if (resSpace.min < sval.getSpace().min) {
- resSpace.min = sval.getSpace().min;
+ SpaceVal spaceVal = (SpaceVal) spaceVals.get(index);
+ if (hasForcing) {
+ resolvedSpace.add(spaceVal.getSpace());
+ } else if (spaceVal.getPrecedence() > maxPrecedence) {
+ maxPrecedence = spaceVal.getPrecedence();
+ resolvedSpace = spaceVal.getSpace();
+ } else if (spaceVal.getPrecedence() == maxPrecedence) {
+ if (spaceVal.getSpace().opt > resolvedSpace.opt) {
+ resolvedSpace = spaceVal.getSpace();
+ } else if (spaceVal.getSpace().opt == resolvedSpace.opt) {
+ if (resolvedSpace.min < spaceVal.getSpace().min) {
+ resolvedSpace.min = spaceVal.getSpace().min;
}
- if (resSpace.max > sval.getSpace().max) {
- resSpace.max = sval.getSpace().max;
+ if (resolvedSpace.max > spaceVal.getSpace().max) {
+ resolvedSpace.max = spaceVal.getSpace().max;
}
}
}
}
- return resSpace;
+ return resolvedSpace;
}
public String toString() {
private Block fobj;
public void initialize() {
- bTextAlignment = fobj.getTextAlign();
- bTextAlignmentLast = fobj.getTextAlignLast();
+ textAlignment = fobj.getTextAlign();
+ textAlignmentLast = fobj.getTextAlignLast();
textIndent = fobj.getTextIndent();
lastLineEndIndent = fobj.getLastLineEndIndent();
- hyphProps = fobj.getCommonHyphenation();
+ hyphenationProperties = fobj.getCommonHyphenation();
wrapOption = fobj.getWrapOption();
//
- effectiveAlignment = getEffectiveAlignment(bTextAlignment, bTextAlignmentLast);
+ effectiveAlignment = getEffectiveAlignment(textAlignment, textAlignmentLast);
}
private int getEffectiveAlignment(int alignment, int alignmentLast) {
- if (bTextAlignment != EN_JUSTIFY && bTextAlignmentLast == EN_JUSTIFY) {
+ if (textAlignment != EN_JUSTIFY && textAlignmentLast == EN_JUSTIFY) {
return 0;
} else {
- return bTextAlignment;
+ return textAlignment;
}
}
}
- /** Break positions returned by inline content. */
- private List vecInlineBreaks = new java.util.ArrayList();
-
- private int bTextAlignment = EN_JUSTIFY;
- private int bTextAlignmentLast;
+ private int textAlignment = EN_JUSTIFY;
+ private int textAlignmentLast;
private int effectiveAlignment;
private Length textIndent;
private Length lastLineEndIndent;
private int iIndents = 0;
- private CommonHyphenation hyphProps;
+ private CommonHyphenation hyphenationProperties;
private int wrapOption = EN_WRAP;
//private LayoutProps layoutProps;
public void startSequence() {
// set the minimum amount of empty space at the end of the
// last line
- if (bTextAlignment == EN_CENTER) {
+ if (textAlignment == EN_CENTER) {
lineFiller = new MinOptMax(lastLineEndIndent);
} else {
lineFiller = new MinOptMax(lastLineEndIndent, lastLineEndIndent, lineWidth);
}
// add auxiliary elements at the beginning of the paragraph
- if (bTextAlignment == EN_CENTER && bTextAlignmentLast != EN_JUSTIFY) {
+ if (textAlignment == EN_CENTER && textAlignmentLast != EN_JUSTIFY) {
this.add(new KnuthGlue(0, 3 * DEFAULT_SPACE_WIDTH, 0,
null, false));
ignoreAtStart ++;
// remove elements representig spaces at the end of the paragraph
removeElementsForTrailingSpaces();
if (this.size() > ignoreAtStart) {
- if (bTextAlignment == EN_CENTER
- && bTextAlignmentLast != EN_JUSTIFY) {
+ if (textAlignment == EN_CENTER
+ && textAlignmentLast != EN_JUSTIFY) {
this.add(new KnuthGlue(0, 3 * DEFAULT_SPACE_WIDTH, 0,
null, false));
this.add(new KnuthPenalty(lineFiller.opt, -KnuthElement.INFINITE,
false, null, false));
ignoreAtEnd = 2;
- } else if (bTextAlignmentLast != EN_JUSTIFY) {
+ } else if (textAlignmentLast != EN_JUSTIFY) {
// add the elements representing the space
// at the end of the last line
// and the forced break
MinOptMax availIPD = context.getStackLimit();
clearPrevIPD();
- int iPrevLineEnd = vecInlineBreaks.size();
-
- if (iPrevLineEnd == 0 && bTextAlignment == EN_START) {
+ if (textAlignment == EN_START) {
availIPD.subtract(new MinOptMax(textIndent.getValue(this)));
}
// else this is the last paragraph
if (lastPar == null) {
lastPar = new Paragraph(this,
- bTextAlignment, bTextAlignmentLast,
+ textAlignment, textAlignmentLast,
textIndent.getValue(this), lastLineEndIndent.getValue(this));
lastPar.startParagraph(availIPD.opt);
if (log.isTraceEnabled()) {
if (!findBreakingPoints(par, lineWidth, maxAdjustment, false)) {
// the first try failed, now try something different
log.debug("No set of breaking points found with maxAdjustment = " + maxAdjustment);
- if (hyphProps.hyphenate == Constants.EN_TRUE) {
+ if (hyphenationProperties.hyphenate == Constants.EN_TRUE) {
// consider every hyphenation point as a legal break
findHyphenationPoints(par);
} else {
// the second try failed too, try with a huge threshold;
// if this fails too, use a different algorithm
log.debug("No set of breaking points found with maxAdjustment = " + maxAdjustment
- + (hyphProps.hyphenate == Constants.EN_TRUE ? " and hyphenation" : ""));
+ + (hyphenationProperties.hyphenate == Constants.EN_TRUE ? " and hyphenation" : ""));
maxAdjustment = 20;
if (!findBreakingPoints(par, lineWidth, maxAdjustment, true)) {
log.debug("No set of breaking points found, using first-fit algorithm");
difference += par.lineFillerWidth;
}
int textAlign = (line < lines)
- ? bTextAlignment : bTextAlignmentLast;
+ ? textAlignment : textAlignmentLast;
int indent = (textAlign == EN_CENTER)
? difference / 2
: (textAlign == EN_END) ? difference : 0;
double maxAdjustment = 1;
int iBPcount = 0;
LineBreakingAlgorithm alg = new LineBreakingAlgorithm(alignment,
- bTextAlignment, bTextAlignmentLast,
+ textAlignment, textAlignmentLast,
textIndent.getValue(this), currPar.lineFiller.opt,
lineHeight.getValue(this), lead, follow, middleShift,
(knuthParagraphs.indexOf(currPar) == 0),
this);
- if (hyphProps.hyphenate == EN_TRUE) {
+ if (hyphenationProperties.hyphenate == EN_TRUE) {
findHyphenationPoints(currPar);
}
}
// now try something different
- log.debug("Hyphenation possible? " + (hyphProps.hyphenate == EN_TRUE));
- if (hyphProps.hyphenate == EN_TRUE
+ log.debug("Hyphenation possible? " + (hyphenationProperties.hyphenate == EN_TRUE));
+ if (hyphenationProperties.hyphenate == EN_TRUE
&& !(allowedBreaks == BreakingAlgorithm.ONLY_FORCED_BREAKS)) {
// consider every hyphenation point as a legal break
allowedBreaks = BreakingAlgorithm.ALL_BREAKS;
// and force the algorithm to find
// a set of breaking points
log.debug("No set of breaking points found with maxAdjustment = " + maxAdjustment
- + (hyphProps.hyphenate == EN_TRUE ? " and hyphenation" : ""));
+ + (hyphenationProperties.hyphenate == EN_TRUE ? " and hyphenation" : ""));
maxAdjustment = 20;
iBPcount
= alg.findBreakingPoints(currPar,
is justify and the paragraph has only one layout, try using
shorter or longer lines */
//TODO This code snippet is disabled. Reenable?
- if (false && alignment == EN_JUSTIFY && bTextAlignment == EN_JUSTIFY) {
+ if (false && alignment == EN_JUSTIFY && textAlignment == EN_JUSTIFY) {
//System.out.println("LLM.getNextKnuthElements> layouts with more lines? " + lineLayouts.canUseMoreLines());
//System.out.println(" layouts with fewer lines? " + lineLayouts.canUseLessLines());
if (!lineLayouts.canUseMoreLines()) {
private HyphContext getHyphenContext(StringBuffer sbChars) {
// Find all hyphenation points in this word
// (get in an array of offsets)
- // hyphProps are from the block level?.
+ // hyphenationProperties are from the block level?.
// Note that according to the spec,
// they also "apply to" fo:character.
// I don't know what that means, since
// since these properties inherit and could be specified
// on an inline or wrapper below the block level.
Hyphenation hyph
- = Hyphenator.hyphenate(hyphProps.language,
- hyphProps.country, sbChars.toString(),
- hyphProps.hyphenationRemainCharacterCount,
- hyphProps.hyphenationPushCharacterCount);
+ = Hyphenator.hyphenate(hyphenationProperties.language,
+ hyphenationProperties.country, sbChars.toString(),
+ hyphenationProperties.hyphenationRemainCharacterCount,
+ hyphenationProperties.hyphenationPushCharacterCount);
// They hyph structure contains the information we need
// Now start from prev: reset to that position, ask that LM to get
// a Position for the first hyphenation offset. If the offset isn't in
KnuthSequence seq = (KnuthSequence) knuthParagraphs.get(iCurrParIndex);
iEndElement = lbp.getLeafPos();
- LineArea lineArea = new LineArea((lbp.getLeafPos() < seq.size() - 1 ? bTextAlignment : bTextAlignmentLast),
+ LineArea lineArea = new LineArea((lbp.getLeafPos() < seq.size() - 1 ? textAlignment : textAlignmentLast),
lbp.difference, lbp.availableStretch, lbp.availableShrink);
lineArea.setStartIndent(lbp.startIndent);
lineArea.setBPD(lbp.lineHeight);
/* extension (not in the XSL FO recommendation): if the left and right margins
have been optimized, recompute indents and / or adjust ratio, according
to the paragraph horizontal alignment */
- if (false && bTextAlignment == EN_JUSTIFY) {
+ if (false && textAlignment == EN_JUSTIFY) {
// re-compute space adjust ratio
int updatedDifference = context.getStackLimit().opt - lbp.lineWidth + lbp.difference;
double updatedRatio = 0.0;
lc.setIPDAdjust(updatedRatio);
//System.out.println("LLM.addAreas> old difference = " + lbp.difference + " new difference = " + updatedDifference);
//System.out.println(" old ratio = " + lbp.ipdAdjust + " new ratio = " + updatedRatio);
- } else if (false && bTextAlignment == EN_CENTER) {
+ } else if (false && textAlignment == EN_CENTER) {
// re-compute indent
int updatedIndent = lbp.startIndent + (context.getStackLimit().opt - lbp.lineWidth) / 2;
lineArea.setStartIndent(updatedIndent);
- } else if (false && bTextAlignment == EN_END) {
+ } else if (false && textAlignment == EN_END) {
// re-compute indent
int updatedIndent = lbp.startIndent + (context.getStackLimit().opt - lbp.lineWidth);
lineArea.setStartIndent(updatedIndent);