mirror of
https://github.com/apache/xmlgraphics-fop.git
synced 2024-09-14 00:01:49 +02:00
Application of the patch submitted by Alexander Kiel to improve variable names around Kerning and KnuthElement (see https://issues.apache.org/bugzilla/show_bug.cgi?id=48003).
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@825646 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
ea58935a59
commit
3938e8f60e
@ -170,6 +170,9 @@ public class Font {
|
||||
|
||||
/**
|
||||
* Returns the amount of kerning between two characters.
|
||||
*
|
||||
* The value returned measures in pt. So it is already adjusted for font size.
|
||||
*
|
||||
* @param ch1 first character
|
||||
* @param ch2 second character
|
||||
* @return the distance to adjust for kerning, 0 if there's no kerning
|
||||
@ -179,7 +182,7 @@ public class Font {
|
||||
if (kernPair != null) {
|
||||
Integer width = (Integer)kernPair.get(new Integer(ch2));
|
||||
if (width != null) {
|
||||
return width.intValue();
|
||||
return width.intValue() * getFontSize() / 1000;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
@ -588,7 +588,7 @@ public abstract class AbstractBreaker {
|
||||
.listIterator(startElementIndex);
|
||||
while (effectiveListIterator.nextIndex() <= endElementIndex) {
|
||||
KnuthElement tempEl = (KnuthElement)effectiveListIterator.next();
|
||||
if (tempEl.isBox() && tempEl.getW() > 0) {
|
||||
if (tempEl.isBox() && tempEl.getWidth() > 0) {
|
||||
boxCount++;
|
||||
}
|
||||
}
|
||||
@ -861,9 +861,9 @@ public abstract class AbstractBreaker {
|
||||
case BlockLevelLayoutManager.LINE_NUMBER_ADJUSTMENT:
|
||||
// potential line number adjustment
|
||||
lineNumberMaxAdjustment.max += ((KnuthGlue) thisElement)
|
||||
.getY();
|
||||
.getStretch();
|
||||
lineNumberMaxAdjustment.min -= ((KnuthGlue) thisElement)
|
||||
.getZ();
|
||||
.getShrink();
|
||||
adjustableLinesList.add(thisElement);
|
||||
break;
|
||||
case BlockLevelLayoutManager.LINE_HEIGHT_ADJUSTMENT:
|
||||
@ -885,9 +885,9 @@ public abstract class AbstractBreaker {
|
||||
KnuthGlue blockSpace = (KnuthGlue) unconfirmedList
|
||||
.removeFirst();
|
||||
spaceMaxAdjustment.max += ((KnuthGlue) blockSpace)
|
||||
.getY();
|
||||
.getStretch();
|
||||
spaceMaxAdjustment.min -= ((KnuthGlue) blockSpace)
|
||||
.getZ();
|
||||
.getShrink();
|
||||
blockSpacesList.add(blockSpace);
|
||||
}
|
||||
}
|
||||
@ -898,11 +898,11 @@ public abstract class AbstractBreaker {
|
||||
log.debug("| space adj = "
|
||||
+ spaceMaxAdjustment);
|
||||
|
||||
if (thisElement.isPenalty() && thisElement.getW() > 0) {
|
||||
if (thisElement.isPenalty() && thisElement.getWidth() > 0) {
|
||||
log.debug(" mandatory variation to the number of lines!");
|
||||
((BlockLevelLayoutManager) thisElement
|
||||
.getLayoutManager()).negotiateBPDAdjustment(
|
||||
thisElement.getW(), thisElement);
|
||||
thisElement.getWidth(), thisElement);
|
||||
}
|
||||
|
||||
if (thisBreak.bpdAdjust != 0
|
||||
@ -967,7 +967,7 @@ public abstract class AbstractBreaker {
|
||||
int partial = 0;
|
||||
while (spaceListIterator.hasNext()) {
|
||||
KnuthGlue blockSpace = (KnuthGlue)spaceListIterator.next();
|
||||
partial += (difference > 0 ? blockSpace.getY() : blockSpace.getZ());
|
||||
partial += (difference > 0 ? blockSpace.getStretch() : blockSpace.getShrink());
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("available = " + partial + " / " + total);
|
||||
log.debug("competenza = "
|
||||
@ -990,7 +990,7 @@ public abstract class AbstractBreaker {
|
||||
int partial = 0;
|
||||
while (lineListIterator.hasNext()) {
|
||||
KnuthGlue line = (KnuthGlue)lineListIterator.next();
|
||||
partial += (difference > 0 ? line.getY() : line.getZ());
|
||||
partial += (difference > 0 ? line.getStretch() : line.getShrink());
|
||||
int newAdjust = ((BlockLevelLayoutManager) line.getLayoutManager()).negotiateBPDAdjustment(((int) ((float) partial * difference / total)) - adjustedDiff, line);
|
||||
adjustedDiff += newAdjust;
|
||||
}
|
||||
|
@ -1133,7 +1133,7 @@ public class BlockContainerLayoutManager extends BlockStackingLayoutManager
|
||||
// by this BlockLM, and must be ignored
|
||||
if (element.getLayoutManager() != this) {
|
||||
splitList.add(element);
|
||||
splitLength += element.getW();
|
||||
splitLength += element.getWidth();
|
||||
lastLM = element.getLayoutManager();
|
||||
}
|
||||
}
|
||||
|
@ -339,7 +339,7 @@ public class BlockLayoutManager extends BlockStackingLayoutManager
|
||||
// by this BlockLM, and must be ignored
|
||||
if (element.getLayoutManager() != this) {
|
||||
splitList.add(element);
|
||||
splitLength += element.getW();
|
||||
splitLength += element.getWidth();
|
||||
lastLM = element.getLayoutManager();
|
||||
}
|
||||
}
|
||||
|
@ -695,11 +695,11 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager
|
||||
/*LF*/ //log.debug(" BLM.negotiateBPDAdjustment> bpunit con penalty");
|
||||
KnuthPenalty storedPenalty = (KnuthPenalty)
|
||||
storedList.get(mappingPos.getLastIndex());
|
||||
if (storedPenalty.getW() > 0) {
|
||||
if (storedPenalty.getWidth() > 0) {
|
||||
// the original penalty has width > 0
|
||||
/*LF*/ //log.debug(" BLM.negotiateBPDAdjustment> chiamata passata");
|
||||
return ((BlockLevelLayoutManager)storedPenalty.getLayoutManager())
|
||||
.negotiateBPDAdjustment(storedPenalty.getW(),
|
||||
.negotiateBPDAdjustment(storedPenalty.getWidth(),
|
||||
storedPenalty);
|
||||
} else {
|
||||
// the original penalty has width = 0
|
||||
@ -1406,17 +1406,17 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager
|
||||
while (oldListIterator.hasNext()) {
|
||||
KnuthElement element = (KnuthElement) oldListIterator.next();
|
||||
if (element.isBox()) {
|
||||
totalLength.add(new MinOptMax(element.getW()));
|
||||
//log.debug("box " + element.getW());
|
||||
totalLength.add(new MinOptMax(element.getWidth()));
|
||||
//log.debug("box " + element.getWidth());
|
||||
} else if (element.isGlue()) {
|
||||
totalLength.min -= element.getZ();
|
||||
totalLength.max += element.getY();
|
||||
totalLength.min -= element.getShrink();
|
||||
totalLength.max += element.getStretch();
|
||||
//leafValue = ((LeafPosition) element.getPosition()).getLeafPos();
|
||||
//log.debug("glue " + element.getW() + " + "
|
||||
// + ((KnuthGlue) element).getY() + " - " + ((KnuthGlue) element).getZ());
|
||||
//log.debug("glue " + element.getWidth() + " + "
|
||||
// + ((KnuthGlue) element).getStretch() + " - " + ((KnuthGlue) element).getShrink());
|
||||
} else {
|
||||
//log.debug((((KnuthPenalty)element).getP() == KnuthElement.INFINITE
|
||||
// ? "PENALTY " : "penalty ") + element.getW());
|
||||
//log.debug((((KnuthPenalty)element).getPenalty() == KnuthElement.INFINITE
|
||||
// ? "PENALTY " : "penalty ") + element.getWidth());
|
||||
}
|
||||
}
|
||||
// compute the total amount of "units"
|
||||
@ -1443,22 +1443,22 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager
|
||||
KnuthElement element = (KnuthElement) oldListIterator.next();
|
||||
lastIndex++;
|
||||
if (element.isBox()) {
|
||||
lengthBeforeBreak.add(new MinOptMax(element.getW()));
|
||||
lengthAfterBreak.subtract(new MinOptMax(element.getW()));
|
||||
lengthBeforeBreak.add(new MinOptMax(element.getWidth()));
|
||||
lengthAfterBreak.subtract(new MinOptMax(element.getWidth()));
|
||||
bPrevIsBox = true;
|
||||
} else if (element.isGlue()) {
|
||||
lengthBeforeBreak.min -= element.getZ();
|
||||
lengthAfterBreak.min += element.getZ();
|
||||
lengthBeforeBreak.max += element.getY();
|
||||
lengthAfterBreak.max -= element.getY();
|
||||
lengthBeforeBreak.min -= element.getShrink();
|
||||
lengthAfterBreak.min += element.getShrink();
|
||||
lengthBeforeBreak.max += element.getStretch();
|
||||
lengthAfterBreak.max -= element.getStretch();
|
||||
bPrevIsBox = false;
|
||||
} else {
|
||||
lengthBeforeBreak.add(new MinOptMax(element.getW()));
|
||||
lengthBeforeBreak.add(new MinOptMax(element.getWidth()));
|
||||
bPrevIsBox = false;
|
||||
}
|
||||
|
||||
// create the new elements
|
||||
if (element.isPenalty() && element.getP() < KnuthElement.INFINITE
|
||||
if (element.isPenalty() && element.getPenalty() < KnuthElement.INFINITE
|
||||
|| element.isGlue() && bPrevIsBox
|
||||
|| !oldListIterator.hasNext()) {
|
||||
// suppress elements after the breaking point
|
||||
@ -1468,8 +1468,8 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager
|
||||
iStepsForward++;
|
||||
if (el.isGlue()) {
|
||||
// suppressed glue
|
||||
lengthAfterBreak.min += el.getZ();
|
||||
lengthAfterBreak.max -= el.getY();
|
||||
lengthAfterBreak.min += el.getShrink();
|
||||
lengthAfterBreak.max -= el.getStretch();
|
||||
} else if (el.isPenalty()) {
|
||||
// suppressed penalty, do nothing
|
||||
} else {
|
||||
@ -1489,8 +1489,8 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager
|
||||
for (int i = 0; i < iStepsForward; i++) {
|
||||
KnuthElement el = (KnuthElement) oldListIterator.previous();
|
||||
if (el.isGlue()) {
|
||||
lengthAfterBreak.min -= el.getZ();
|
||||
lengthAfterBreak.max += el.getY();
|
||||
lengthAfterBreak.min -= el.getShrink();
|
||||
lengthAfterBreak.max += el.getStretch();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1611,7 +1611,7 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager
|
||||
}
|
||||
|
||||
if (element.isPenalty()) {
|
||||
lengthBeforeBreak.add(new MinOptMax(-element.getW()));
|
||||
lengthBeforeBreak.add(new MinOptMax(-element.getWidth()));
|
||||
}
|
||||
|
||||
}
|
||||
@ -1640,14 +1640,14 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager
|
||||
- neededUnits(totalLength.opt - adjustedSpaceBefore))
|
||||
* bpUnit;
|
||||
// insert the correct elements
|
||||
newList.addFirst(new KnuthBox(wrongBox.getW() - decreasedLength,
|
||||
newList.addFirst(new KnuthBox(wrongBox.getWidth() - decreasedLength,
|
||||
wrongBox.getPosition(), false));
|
||||
newList.addFirst(new KnuthGlue(decreasedLength, 0, 0, SPACE_BEFORE_ADJUSTMENT,
|
||||
wrongBox.getPosition(), false));
|
||||
//log.debug(" rimosso box " + neededUnits(wrongBox.getW()));
|
||||
//log.debug(" rimosso box " + neededUnits(wrongBox.getWidth()));
|
||||
//log.debug(" aggiunto glue " + neededUnits(decreasedLength) + " 0 0");
|
||||
//log.debug(" aggiunto box " + neededUnits(
|
||||
// wrongBox.getW() - decreasedLength));
|
||||
// wrongBox.getWidth() - decreasedLength));
|
||||
}
|
||||
|
||||
// if space-after.conditionality is "discard", correct newList
|
||||
@ -1663,7 +1663,7 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager
|
||||
// (it cannot be parted and has some stretch or shrink)
|
||||
// the wrong box is the first one, not the last one
|
||||
LinkedList preserveList = new LinkedList();
|
||||
if (wrongBox.getW() == 0) {
|
||||
if (wrongBox.getWidth() == 0) {
|
||||
preserveList.add(wrongBox);
|
||||
preserveList.addFirst((KnuthGlue) newList.removeLast());
|
||||
preserveList.addFirst((KnuthPenalty) newList.removeLast());
|
||||
@ -1676,7 +1676,7 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager
|
||||
- neededUnits(totalLength.opt - adjustedSpaceAfter))
|
||||
* bpUnit;
|
||||
// insert the correct box
|
||||
newList.addLast(new KnuthBox(wrongBox.getW() - decreasedLength,
|
||||
newList.addLast(new KnuthBox(wrongBox.getWidth() - decreasedLength,
|
||||
wrongBox.getPosition(), false));
|
||||
// add preserved elements
|
||||
if (!preserveList.isEmpty()) {
|
||||
@ -1685,9 +1685,9 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager
|
||||
// insert the correct glue
|
||||
newList.addLast(new KnuthGlue(decreasedLength, 0, 0, SPACE_AFTER_ADJUSTMENT,
|
||||
wrongBox.getPosition(), false));
|
||||
//log.debug(" rimosso box " + neededUnits(wrongBox.getW()));
|
||||
//log.debug(" rimosso box " + neededUnits(wrongBox.getWidth()));
|
||||
//log.debug(" aggiunto box " + neededUnits(
|
||||
// wrongBox.getW() - decreasedLength));
|
||||
// wrongBox.getWidth() - decreasedLength));
|
||||
//log.debug(" aggiunto glue " + neededUnits(decreasedLength) + " 0 0");
|
||||
}
|
||||
|
||||
|
@ -676,7 +676,7 @@ public abstract class BreakingAlgorithm {
|
||||
protected void handleBox(KnuthBox box) {
|
||||
// a KnuthBox object is not a legal line break,
|
||||
// just add the width to the total
|
||||
totalWidth += box.getW();
|
||||
totalWidth += box.getWidth();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -697,9 +697,9 @@ public abstract class BreakingAlgorithm {
|
||||
&& !(allowedBreaks == ONLY_FORCED_BREAKS)) {
|
||||
considerLegalBreak(glue, position);
|
||||
}
|
||||
totalWidth += glue.getW();
|
||||
totalStretch += glue.getY();
|
||||
totalShrink += glue.getZ();
|
||||
totalWidth += glue.getWidth();
|
||||
totalStretch += glue.getStretch();
|
||||
totalShrink += glue.getShrink();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -716,8 +716,8 @@ public abstract class BreakingAlgorithm {
|
||||
// only if its penalty is not infinite;
|
||||
// consider all penalties, non-flagged penalties or non-forcing penalties
|
||||
// according to the value of allowedBreaks
|
||||
if (((penalty.getP() < KnuthElement.INFINITE)
|
||||
&& (!(allowedBreaks == NO_FLAGGED_PENALTIES) || !penalty.isFlagged())
|
||||
if (((penalty.getPenalty() < KnuthElement.INFINITE)
|
||||
&& (!(allowedBreaks == NO_FLAGGED_PENALTIES) || !penalty.isPenaltyFlagged())
|
||||
&& (!(allowedBreaks == ONLY_FORCED_BREAKS)
|
||||
|| penalty.isForcedBreak()))) {
|
||||
considerLegalBreak(penalty, position);
|
||||
@ -880,7 +880,7 @@ public abstract class BreakingAlgorithm {
|
||||
*/
|
||||
protected boolean elementCanEndLine(KnuthElement element, int line, int difference) {
|
||||
return (!element.isPenalty()
|
||||
|| element.getP() < KnuthElement.INFINITE);
|
||||
|| element.getPenalty() < KnuthElement.INFINITE);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -921,9 +921,9 @@ public abstract class BreakingAlgorithm {
|
||||
if (tempElement.isBox()) {
|
||||
break;
|
||||
} else if (tempElement.isGlue()) {
|
||||
newWidth += tempElement.getW();
|
||||
newStretch += tempElement.getY();
|
||||
newShrink += tempElement.getZ();
|
||||
newWidth += tempElement.getWidth();
|
||||
newStretch += tempElement.getStretch();
|
||||
newShrink += tempElement.getShrink();
|
||||
} else if (tempElement.isForcedBreak() && i != elementIdx) {
|
||||
break;
|
||||
}
|
||||
@ -1034,9 +1034,9 @@ public abstract class BreakingAlgorithm {
|
||||
if (tempElement.isBox()) {
|
||||
break;
|
||||
} else if (tempElement.isGlue()) {
|
||||
newWidth += tempElement.getW();
|
||||
newStretch += tempElement.getY();
|
||||
newShrink += tempElement.getZ();
|
||||
newWidth += tempElement.getWidth();
|
||||
newStretch += tempElement.getStretch();
|
||||
newShrink += tempElement.getShrink();
|
||||
} else if (tempElement.isForcedBreak() && i != elementIdx) {
|
||||
break;
|
||||
}
|
||||
@ -1075,7 +1075,7 @@ public abstract class BreakingAlgorithm {
|
||||
// compute the adjustment ratio
|
||||
int actualWidth = totalWidth - activeNode.totalWidth;
|
||||
if (element.isPenalty()) {
|
||||
actualWidth += element.getW();
|
||||
actualWidth += element.getWidth();
|
||||
}
|
||||
return getLineWidth() - actualWidth;
|
||||
}
|
||||
@ -1133,7 +1133,7 @@ public abstract class BreakingAlgorithm {
|
||||
double f = Math.abs(r);
|
||||
f = 1 + 100 * f * f * f;
|
||||
if (element.isPenalty()) {
|
||||
double penalty = element.getP();
|
||||
double penalty = element.getPenalty();
|
||||
if (penalty >= 0) {
|
||||
f += penalty;
|
||||
demerits = f * f;
|
||||
@ -1146,9 +1146,9 @@ public abstract class BreakingAlgorithm {
|
||||
demerits = f * f;
|
||||
}
|
||||
|
||||
if (element.isPenalty() && ((KnuthPenalty) element).isFlagged()
|
||||
if (element.isPenalty() && ((KnuthPenalty) element).isPenaltyFlagged()
|
||||
&& getElement(activeNode.position).isPenalty()
|
||||
&& ((KnuthPenalty) getElement(activeNode.position)).isFlagged()) {
|
||||
&& ((KnuthPenalty) getElement(activeNode.position)).isPenaltyFlagged()) {
|
||||
// add demerit for consecutive breaks at flagged penalties
|
||||
demerits += repeatedFlaggedDemerit;
|
||||
// there are at least two consecutive lines ending with a flagged penalty;
|
||||
@ -1160,7 +1160,7 @@ public abstract class BreakingAlgorithm {
|
||||
prevNode = prevNode.previous) {
|
||||
KnuthElement prevElement = getElement(prevNode.position);
|
||||
if (prevElement.isPenalty()
|
||||
&& ((KnuthPenalty) prevElement).isFlagged()) {
|
||||
&& ((KnuthPenalty) prevElement).isPenaltyFlagged()) {
|
||||
// the previous line ends with a flagged penalty too
|
||||
flaggedPenaltiesCount++;
|
||||
} else {
|
||||
|
@ -62,13 +62,13 @@ public final class ElementListUtils {
|
||||
if (el.isPenalty()) {
|
||||
KnuthPenalty penalty = (KnuthPenalty)el;
|
||||
//Convert all penalties to break inhibitors
|
||||
if (penalty.getP() < KnuthPenalty.INFINITE) {
|
||||
iter.set(new KnuthPenalty(penalty.getW(), KnuthPenalty.INFINITE,
|
||||
penalty.isFlagged(), penalty.getPosition(), penalty.isAuxiliary()));
|
||||
if (penalty.getPenalty() < KnuthPenalty.INFINITE) {
|
||||
iter.set(new KnuthPenalty(penalty.getWidth(), KnuthPenalty.INFINITE,
|
||||
penalty.isPenaltyFlagged(), penalty.getPosition(), penalty.isAuxiliary()));
|
||||
}
|
||||
} else if (el.isGlue()) {
|
||||
KnuthGlue glue = (KnuthGlue)el;
|
||||
len += glue.getW();
|
||||
len += glue.getWidth();
|
||||
iter.previous();
|
||||
el = (ListElement)iter.previous();
|
||||
iter.next();
|
||||
@ -84,7 +84,7 @@ public final class ElementListUtils {
|
||||
}
|
||||
} else {
|
||||
KnuthElement kel = (KnuthElement)el;
|
||||
len += kel.getW();
|
||||
len += kel.getWidth();
|
||||
}
|
||||
if (len >= constraint) {
|
||||
return false;
|
||||
@ -109,13 +109,13 @@ public final class ElementListUtils {
|
||||
if (el.isPenalty()) {
|
||||
KnuthPenalty penalty = (KnuthPenalty)el;
|
||||
//Convert all penalties to break inhibitors
|
||||
if (penalty.getP() < KnuthPenalty.INFINITE) {
|
||||
i.set(new KnuthPenalty(penalty.getW(), KnuthPenalty.INFINITE,
|
||||
penalty.isFlagged(), penalty.getPosition(), penalty.isAuxiliary()));
|
||||
if (penalty.getPenalty() < KnuthPenalty.INFINITE) {
|
||||
i.set(new KnuthPenalty(penalty.getWidth(), KnuthPenalty.INFINITE,
|
||||
penalty.isPenaltyFlagged(), penalty.getPosition(), penalty.isAuxiliary()));
|
||||
}
|
||||
} else if (el.isGlue()) {
|
||||
KnuthGlue glue = (KnuthGlue)el;
|
||||
len += glue.getW();
|
||||
len += glue.getWidth();
|
||||
el = (ListElement)i.previous();
|
||||
i.next();
|
||||
if (el.isBox()) {
|
||||
@ -134,7 +134,7 @@ public final class ElementListUtils {
|
||||
}
|
||||
} else {
|
||||
KnuthElement kel = (KnuthElement)el;
|
||||
len += kel.getW();
|
||||
len += kel.getWidth();
|
||||
}
|
||||
if (len >= constraint) {
|
||||
return false;
|
||||
@ -158,9 +158,9 @@ public final class ElementListUtils {
|
||||
while (iter.hasNext()) {
|
||||
ListElement el = (ListElement)iter.next();
|
||||
if (el.isBox()) {
|
||||
len += ((KnuthElement)el).getW();
|
||||
len += ((KnuthElement)el).getWidth();
|
||||
} else if (el.isGlue()) {
|
||||
len += ((KnuthElement)el).getW();
|
||||
len += ((KnuthElement)el).getWidth();
|
||||
} else {
|
||||
//log.debug("Ignoring penalty: " + el);
|
||||
//ignore penalties
|
||||
@ -210,7 +210,7 @@ public final class ElementListUtils {
|
||||
*/
|
||||
public static boolean endsWithNonInfinitePenalty(List elems) {
|
||||
ListElement last = (ListElement) ListUtil.getLast(elems);
|
||||
if (last.isPenalty() && ((KnuthPenalty)last).getP() < KnuthElement.INFINITE) {
|
||||
if (last.isPenalty() && ((KnuthPenalty)last).getPenalty() < KnuthElement.INFINITE) {
|
||||
return true;
|
||||
} else if (last instanceof BreakElement
|
||||
&& ((BreakElement)last).getPenaltyValue() < KnuthElement.INFINITE) {
|
||||
@ -230,7 +230,7 @@ public final class ElementListUtils {
|
||||
int prevBreak = startIndex - 1;
|
||||
while (prevBreak >= 0) {
|
||||
KnuthElement el = (KnuthElement)elems.get(prevBreak);
|
||||
if (el.isPenalty() && el.getP() < KnuthElement.INFINITE) {
|
||||
if (el.isPenalty() && el.getPenalty() < KnuthElement.INFINITE) {
|
||||
break;
|
||||
}
|
||||
prevBreak--;
|
||||
|
@ -72,7 +72,7 @@ public class InlineKnuthSequence extends KnuthSequence {
|
||||
lastOldElement = getLast();
|
||||
firstNewElement = sequence.getElement(0);
|
||||
if (firstNewElement.isBox() && !((KnuthElement) firstNewElement).isAuxiliary()
|
||||
&& lastOldElement.isBox() && ((KnuthElement) lastOldElement).getW() != 0) {
|
||||
&& lastOldElement.isBox() && ((KnuthElement) lastOldElement).getWidth() != 0) {
|
||||
addALetterSpace();
|
||||
}
|
||||
addAll(sequence);
|
||||
|
@ -37,12 +37,12 @@ public class KnuthBox extends KnuthElement {
|
||||
/**
|
||||
* Create a new KnuthBox.
|
||||
*
|
||||
* @param w the width of this box
|
||||
* @param width the width of this box
|
||||
* @param pos the Position stored in this box
|
||||
* @param bAux is this box auxiliary?
|
||||
* @param auxiliary is this box auxiliary?
|
||||
*/
|
||||
public KnuthBox(int w, Position pos, boolean bAux) {
|
||||
super(w, pos, bAux);
|
||||
public KnuthBox(int width, Position pos, boolean auxiliary) {
|
||||
super(width, pos, auxiliary);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@ -52,14 +52,14 @@ public class KnuthBox extends KnuthElement {
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public String toString() {
|
||||
StringBuffer sb = new StringBuffer(64);
|
||||
StringBuffer buffer = new StringBuffer(64);
|
||||
if (isAuxiliary()) {
|
||||
sb.append("aux. ");
|
||||
buffer.append("aux. ");
|
||||
}
|
||||
sb.append("box");
|
||||
sb.append(" w=");
|
||||
sb.append(getW());
|
||||
return sb.toString();
|
||||
buffer.append("box");
|
||||
buffer.append(" w=");
|
||||
buffer.append(getWidth());
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -33,44 +33,44 @@ public abstract class KnuthElement extends ListElement {
|
||||
public static final int INFINITE = 1000;
|
||||
|
||||
private int width;
|
||||
private boolean bIsAuxiliary;
|
||||
private boolean auxiliary;
|
||||
|
||||
/**
|
||||
* Create a new KnuthElement.
|
||||
* This class being abstract, this can be called only by subclasses.
|
||||
*
|
||||
* @param w the width of this element
|
||||
* @param width the width of this element
|
||||
* @param pos the Position stored in this element
|
||||
* @param bAux is this an auxiliary element?
|
||||
* @param auxiliary is this an auxiliary element?
|
||||
*/
|
||||
protected KnuthElement(int w, Position pos, boolean bAux) {
|
||||
protected KnuthElement(int width, Position pos, boolean auxiliary) {
|
||||
super(pos);
|
||||
width = w;
|
||||
bIsAuxiliary = bAux;
|
||||
this.width = width;
|
||||
this.auxiliary = auxiliary;
|
||||
}
|
||||
|
||||
/** @return true if this element is an auxiliary one. */
|
||||
public boolean isAuxiliary() {
|
||||
return bIsAuxiliary;
|
||||
return auxiliary;
|
||||
}
|
||||
|
||||
/** @return the width of this element. */
|
||||
public int getW() {
|
||||
public int getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
/** @return the penalty value of this element, if applicable. */
|
||||
public int getP() {
|
||||
public int getPenalty() {
|
||||
throw new RuntimeException("Element is not a penalty");
|
||||
}
|
||||
|
||||
/** @return the stretch value of this element, if applicable. */
|
||||
public int getY() {
|
||||
public int getStretch() {
|
||||
throw new RuntimeException("Element is not a glue");
|
||||
}
|
||||
|
||||
/** @return the shrink value of this element, if applicable. */
|
||||
public int getZ() {
|
||||
public int getShrink() {
|
||||
throw new RuntimeException("Element is not a glue");
|
||||
}
|
||||
|
||||
|
@ -54,24 +54,25 @@ public class KnuthGlue extends KnuthElement {
|
||||
/**
|
||||
* Create a new KnuthGlue.
|
||||
*
|
||||
* @param w the width of this glue
|
||||
* @param y the stretchability of this glue
|
||||
* @param z the shrinkability of this glue
|
||||
* @param width the width of this glue
|
||||
* @param stretchability the stretchability of this glue
|
||||
* @param shrinkability the shrinkability of this glue
|
||||
* @param pos the Position stored in this glue
|
||||
* @param bAux is this glue auxiliary?
|
||||
* @param auxiliary is this glue auxiliary?
|
||||
*/
|
||||
public KnuthGlue(int w, int y, int z, Position pos, boolean bAux) {
|
||||
super(w, pos, bAux);
|
||||
stretchability = y;
|
||||
shrinkability = z;
|
||||
public KnuthGlue(int width, int stretchability, int shrinkability, Position pos,
|
||||
boolean auxiliary) {
|
||||
super(width, pos, auxiliary);
|
||||
this.stretchability = stretchability;
|
||||
this.shrinkability = shrinkability;
|
||||
}
|
||||
|
||||
public KnuthGlue(int w, int y, int z,
|
||||
int iAdjClass, Position pos, boolean bAux) {
|
||||
super(w, pos, bAux);
|
||||
stretchability = y;
|
||||
shrinkability = z;
|
||||
adjustmentClass = iAdjClass;
|
||||
public KnuthGlue(int width, int stretchability, int shrinkability, int adjustmentClass,
|
||||
Position pos, boolean auxiliary) {
|
||||
super(width, pos, auxiliary);
|
||||
this.stretchability = stretchability;
|
||||
this.shrinkability = shrinkability;
|
||||
this.adjustmentClass = adjustmentClass;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@ -80,12 +81,12 @@ public class KnuthGlue extends KnuthElement {
|
||||
}
|
||||
|
||||
/** @return the stretchability of this glue. */
|
||||
public int getY() {
|
||||
public int getStretch() {
|
||||
return stretchability;
|
||||
}
|
||||
|
||||
/** @return the shrinkability of this glue. */
|
||||
public int getZ() {
|
||||
public int getShrink() {
|
||||
return shrinkability;
|
||||
}
|
||||
|
||||
@ -96,18 +97,18 @@ public class KnuthGlue extends KnuthElement {
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public String toString() {
|
||||
StringBuffer sb = new StringBuffer(64);
|
||||
StringBuffer buffer = new StringBuffer(64);
|
||||
if (isAuxiliary()) {
|
||||
sb.append("aux. ");
|
||||
buffer.append("aux. ");
|
||||
}
|
||||
sb.append("glue");
|
||||
sb.append(" w=").append(getW());
|
||||
sb.append(" stretch=").append(getY());
|
||||
sb.append(" shrink=").append(getZ());
|
||||
buffer.append("glue");
|
||||
buffer.append(" w=").append(getWidth());
|
||||
buffer.append(" stretch=").append(getStretch());
|
||||
buffer.append(" shrink=").append(getShrink());
|
||||
if (getAdjustmentClass() >= 0) {
|
||||
sb.append(" adj-class=").append(getAdjustmentClass());
|
||||
buffer.append(" adj-class=").append(getAdjustmentClass());
|
||||
}
|
||||
return sb.toString();
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -45,39 +45,40 @@ public class KnuthPenalty extends KnuthElement {
|
||||
public static final int FLAGGED_PENALTY = 50;
|
||||
|
||||
private int penalty;
|
||||
private boolean isFlagged;
|
||||
private boolean penaltyFlagged;
|
||||
private int breakClass = -1;
|
||||
|
||||
/**
|
||||
* Create a new KnuthPenalty.
|
||||
*
|
||||
* @param w the width of this penalty
|
||||
* @param p the penalty value of this penalty
|
||||
* @param f is this penalty flagged?
|
||||
* @param width the width of this penalty
|
||||
* @param penalty the penalty value of this penalty
|
||||
* @param penaltyFlagged is this penalty flagged?
|
||||
* @param pos the Position stored in this penalty
|
||||
* @param isAuxiliary is this penalty auxiliary?
|
||||
* @param auxiliary is this penalty auxiliary?
|
||||
*/
|
||||
public KnuthPenalty(int w, int p, boolean f, Position pos, boolean isAuxiliary) {
|
||||
super(w, pos, isAuxiliary);
|
||||
penalty = p;
|
||||
isFlagged = f;
|
||||
public KnuthPenalty(int width, int penalty, boolean penaltyFlagged, Position pos,
|
||||
boolean auxiliary) {
|
||||
super(width, pos, auxiliary);
|
||||
this.penalty = penalty;
|
||||
this.penaltyFlagged = penaltyFlagged;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new KnuthPenalty.
|
||||
*
|
||||
* @param w the width of this penalty
|
||||
* @param p the penalty value of this penalty
|
||||
* @param f is this penalty flagged?
|
||||
* @param width the width of this penalty
|
||||
* @param penalty the penalty value of this penalty
|
||||
* @param penaltyFlagged is this penalty flagged?
|
||||
* @param breakClass the break class of this penalty (one of
|
||||
* {@link Constants#EN_AUTO}, {@link Constants#EN_COLUMN}, {@link Constants#EN_PAGE},
|
||||
* {@link Constants#EN_EVEN_PAGE}, {@link Constants#EN_ODD_PAGE})
|
||||
* @param pos the Position stored in this penalty
|
||||
* @param isAuxiliary is this penalty auxiliary?
|
||||
*/
|
||||
public KnuthPenalty(int w, int p, boolean f,
|
||||
int breakClass, Position pos, boolean isAuxiliary) {
|
||||
this(w, p, f, pos, isAuxiliary);
|
||||
public KnuthPenalty(int width, int penalty, boolean penaltyFlagged, int breakClass,
|
||||
Position pos, boolean isAuxiliary) {
|
||||
this(width, penalty, penaltyFlagged, pos, isAuxiliary);
|
||||
this.breakClass = breakClass;
|
||||
}
|
||||
|
||||
@ -90,6 +91,8 @@ public class KnuthPenalty extends KnuthElement {
|
||||
* (Mainly used in {@link #toString()} methods, to improve readability
|
||||
* of the trace logs.)
|
||||
*
|
||||
* TODO: shouldn't be penalty a class of its own?
|
||||
*
|
||||
* @param penaltyValue the penalty value
|
||||
* @return the penalty value as a {@link java.lang.String}
|
||||
*/
|
||||
@ -110,21 +113,21 @@ public class KnuthPenalty extends KnuthElement {
|
||||
/**
|
||||
* @return the penalty value of this penalty.
|
||||
*/
|
||||
public int getP() {
|
||||
public int getPenalty() {
|
||||
return penalty;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a new penalty value.
|
||||
* @param p the new penalty value
|
||||
* @param penalty the new penalty value
|
||||
*/
|
||||
public void setP(int p) {
|
||||
this.penalty = p;
|
||||
public void setPenalty(int penalty) {
|
||||
this.penalty = penalty;
|
||||
}
|
||||
|
||||
/** @return true is this penalty is a flagged one. */
|
||||
public boolean isFlagged() {
|
||||
return isFlagged;
|
||||
public boolean isPenaltyFlagged() {
|
||||
return penaltyFlagged;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@ -142,28 +145,28 @@ public class KnuthPenalty extends KnuthElement {
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public String toString() {
|
||||
StringBuffer sb = new StringBuffer(64);
|
||||
StringBuffer buffer = new StringBuffer(64);
|
||||
if (isAuxiliary()) {
|
||||
sb.append("aux. ");
|
||||
buffer.append("aux. ");
|
||||
}
|
||||
sb.append("penalty");
|
||||
sb.append(" p=");
|
||||
sb.append(valueOf(this.penalty));
|
||||
if (this.isFlagged) {
|
||||
sb.append(" [flagged]");
|
||||
buffer.append("penalty");
|
||||
buffer.append(" p=");
|
||||
buffer.append(valueOf(this.penalty));
|
||||
if (this.penaltyFlagged) {
|
||||
buffer.append(" [flagged]");
|
||||
}
|
||||
sb.append(" w=");
|
||||
sb.append(getW());
|
||||
buffer.append(" w=");
|
||||
buffer.append(getWidth());
|
||||
if (isForcedBreak()) {
|
||||
sb.append(" (forced break, ")
|
||||
buffer.append(" (forced break, ")
|
||||
.append(getBreakClassName(this.breakClass))
|
||||
.append(")");
|
||||
} else if (this.penalty >= 0 && this.breakClass != -1) {
|
||||
//penalty corresponding to a keep constraint
|
||||
sb.append(" (keep constraint, ")
|
||||
buffer.append(" (keep constraint, ")
|
||||
.append(getBreakClassName(this.breakClass))
|
||||
.append(")");
|
||||
}
|
||||
return sb.toString();
|
||||
return buffer.toString();
|
||||
}
|
||||
}
|
||||
|
@ -26,9 +26,12 @@ import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
|
||||
/**
|
||||
* Represents a list of Knuth elements.
|
||||
* Represents a list of {@link KnuthElement Knuth elements}.
|
||||
*/
|
||||
public abstract class KnuthSequence extends ArrayList {
|
||||
|
||||
//TODO: do not extend ArrayList
|
||||
|
||||
/**
|
||||
* Creates a new and empty list.
|
||||
*/
|
||||
|
@ -320,7 +320,7 @@ class PageBreakingAlgorithm extends BreakingAlgorithm {
|
||||
* will not have considered it a legal break, but it could still
|
||||
* be one.
|
||||
*/
|
||||
if (penalty.getP() == KnuthPenalty.INFINITE) {
|
||||
if (penalty.getPenalty() == KnuthPenalty.INFINITE) {
|
||||
int breakClass = penalty.getBreakClass();
|
||||
if (breakClass == Constants.EN_PAGE
|
||||
|| breakClass == Constants.EN_COLUMN) {
|
||||
@ -363,7 +363,7 @@ class PageBreakingAlgorithm extends BreakingAlgorithm {
|
||||
noteListIterator.hasNext();) {
|
||||
final KnuthElement element = (KnuthElement) noteListIterator.next();
|
||||
if (element.isBox() || element.isGlue()) {
|
||||
noteLength += element.getW();
|
||||
noteLength += element.getWidth();
|
||||
}
|
||||
}
|
||||
int prevLength = (lengthList == null || lengthList.isEmpty())
|
||||
@ -445,22 +445,22 @@ class PageBreakingAlgorithm extends BreakingAlgorithm {
|
||||
return true;
|
||||
} else {
|
||||
KnuthPenalty p = (KnuthPenalty) element;
|
||||
if (p.getP() <= 0) {
|
||||
if (p.getPenalty() <= 0) {
|
||||
return true;
|
||||
} else {
|
||||
int context = p.getBreakClass();
|
||||
switch (context) {
|
||||
case Constants.EN_LINE:
|
||||
case Constants.EN_COLUMN:
|
||||
return p.getP() < KnuthPenalty.INFINITE;
|
||||
return p.getPenalty() < KnuthPenalty.INFINITE;
|
||||
case Constants.EN_PAGE:
|
||||
return p.getP() < KnuthPenalty.INFINITE
|
||||
return p.getPenalty() < KnuthPenalty.INFINITE
|
||||
|| !pageProvider.endPage(line - 1);
|
||||
case Constants.EN_AUTO:
|
||||
log.debug("keep is not auto but context is");
|
||||
return true;
|
||||
default:
|
||||
if (p.getP() < KnuthPenalty.INFINITE) {
|
||||
if (p.getPenalty() < KnuthPenalty.INFINITE) {
|
||||
log.debug("Non recognized keep context:" + context);
|
||||
return true;
|
||||
} else {
|
||||
@ -479,7 +479,7 @@ class PageBreakingAlgorithm extends BreakingAlgorithm {
|
||||
int footnoteSplit = 0;
|
||||
boolean canDeferOldFootnotes;
|
||||
if (element.isPenalty()) {
|
||||
actualWidth += element.getW();
|
||||
actualWidth += element.getWidth();
|
||||
}
|
||||
if (footnotesPending) {
|
||||
// compute the total length of the footnotes not yet inserted
|
||||
@ -588,7 +588,7 @@ class PageBreakingAlgorithm extends BreakingAlgorithm {
|
||||
index++) {
|
||||
if (par.getElement(index).isGlue() && par.getElement(index - 1).isBox()
|
||||
|| par.getElement(index).isPenalty()
|
||||
&& ((KnuthElement) par.getElement(index)).getP() < KnuthElement.INFINITE) {
|
||||
&& ((KnuthElement) par.getElement(index)).getPenalty() < KnuthElement.INFINITE) {
|
||||
// break found
|
||||
break;
|
||||
}
|
||||
@ -711,7 +711,7 @@ class PageBreakingAlgorithm extends BreakingAlgorithm {
|
||||
element = (KnuthElement) noteListIterator.next();
|
||||
if (element.isBox()) {
|
||||
// element is a box
|
||||
splitLength += element.getW();
|
||||
splitLength += element.getWidth();
|
||||
boxPreceding = true;
|
||||
} else if (element.isGlue()) {
|
||||
// element is a glue
|
||||
@ -721,10 +721,10 @@ class PageBreakingAlgorithm extends BreakingAlgorithm {
|
||||
break;
|
||||
}
|
||||
boxPreceding = false;
|
||||
splitLength += element.getW();
|
||||
splitLength += element.getWidth();
|
||||
} else {
|
||||
// element is a penalty
|
||||
if (element.getP() < KnuthElement.INFINITE) {
|
||||
if (element.getPenalty() < KnuthElement.INFINITE) {
|
||||
// end of the sub-sequence
|
||||
index = noteListIterator.previousIndex();
|
||||
break;
|
||||
@ -792,7 +792,7 @@ class PageBreakingAlgorithm extends BreakingAlgorithm {
|
||||
double f = Math.abs(r);
|
||||
f = 1 + 100 * f * f * f;
|
||||
if (element.isPenalty()) {
|
||||
double penalty = element.getP();
|
||||
double penalty = element.getPenalty();
|
||||
if (penalty >= 0) {
|
||||
f += penalty;
|
||||
demerits = f * f;
|
||||
@ -805,9 +805,9 @@ class PageBreakingAlgorithm extends BreakingAlgorithm {
|
||||
demerits = f * f;
|
||||
}
|
||||
|
||||
if (element.isPenalty() && ((KnuthPenalty) element).isFlagged()
|
||||
if (element.isPenalty() && ((KnuthPenalty) element).isPenaltyFlagged()
|
||||
&& getElement(activeNode.position).isPenalty()
|
||||
&& ((KnuthPenalty) getElement(activeNode.position)).isFlagged()) {
|
||||
&& ((KnuthPenalty) getElement(activeNode.position)).isPenaltyFlagged()) {
|
||||
// add demerit for consecutive breaks at flagged penalties
|
||||
demerits += repeatedFlaggedDemerit;
|
||||
}
|
||||
|
@ -266,12 +266,12 @@ public class ContentLayoutManager extends AbstractBaseLayoutManager
|
||||
KnuthSequence ks = (KnuthSequence)obj;
|
||||
for (Iterator it = ks.iterator(); it.hasNext(); ) {
|
||||
contentElement = (KnuthElement)it.next();
|
||||
stackSize += contentElement.getW();
|
||||
stackSize += contentElement.getWidth();
|
||||
contentList.add(contentElement);
|
||||
}
|
||||
} else {
|
||||
contentElement = (KnuthElement)obj;
|
||||
stackSize += contentElement.getW();
|
||||
stackSize += contentElement.getWidth();
|
||||
contentList.add(contentElement);
|
||||
}
|
||||
}
|
||||
|
@ -680,7 +680,7 @@ public class LineLayoutManager extends InlineStackingLayoutManager
|
||||
assert lastElement != null;
|
||||
previousIsBox = lastElement.isBox()
|
||||
&& !((KnuthElement) lastElement).isAuxiliary()
|
||||
&& ((KnuthElement) lastElement).getW() != 0;
|
||||
&& ((KnuthElement) lastElement).getWidth() != 0;
|
||||
|
||||
// if last paragraph is open, add the new elements to the paragraph
|
||||
// else this is the last paragraph
|
||||
@ -705,7 +705,7 @@ public class LineLayoutManager extends InlineStackingLayoutManager
|
||||
|
||||
// finish last paragraph if it was closed with a linefeed
|
||||
if (lastElement.isPenalty()
|
||||
&& ((KnuthPenalty) lastElement).getP() == -KnuthPenalty.INFINITE) {
|
||||
&& ((KnuthPenalty) lastElement).getPenalty() == -KnuthPenalty.INFINITE) {
|
||||
// a penalty item whose value is -inf
|
||||
// represents a preserved linefeed,
|
||||
// which forces a line break
|
||||
@ -1172,7 +1172,7 @@ public class LineLayoutManager extends InlineStackingLayoutManager
|
||||
LeafPosition pos = (LeafPosition)lastElement.getPosition();
|
||||
int totalAdj = adj;
|
||||
//if (lastElement.isPenalty()) {
|
||||
// totalAdj += lastElement.getW();
|
||||
// totalAdj += lastElement.getWidth();
|
||||
//}
|
||||
//int lineNumberDifference = (int)((double) totalAdj / constantLineHeight);
|
||||
int lineNumberDifference = (int) Math.round((double) totalAdj / constantLineHeight
|
||||
|
@ -54,6 +54,8 @@ import org.apache.fop.util.ListUtil;
|
||||
*/
|
||||
public class TextLayoutManager extends LeafNodeLayoutManager {
|
||||
|
||||
//TODO: remove all final modifiers at local variables
|
||||
|
||||
/**
|
||||
* Store information about each potential text area.
|
||||
* Index of character which ends the area, IPD of area, including
|
||||
@ -686,39 +688,39 @@ public class TextLayoutManager extends LeafNodeLayoutManager {
|
||||
}
|
||||
|
||||
private AreaInfo processWord(final int alignment, final KnuthSequence sequence,
|
||||
AreaInfo prevAi, final char ch, final boolean breakOpportunity,
|
||||
AreaInfo prevAreaInfo, final char ch, final boolean breakOpportunity,
|
||||
final boolean checkEndsWithHyphen) {
|
||||
AreaInfo ai;
|
||||
|
||||
//Word boundary found, process widths and kerning
|
||||
int lastIndex = this.nextStart;
|
||||
while (lastIndex > 0
|
||||
&& this.foText.charAt(lastIndex - 1) == CharUtilities.SOFT_HYPHEN) {
|
||||
&& foText.charAt(lastIndex - 1) == CharUtilities.SOFT_HYPHEN) {
|
||||
lastIndex--;
|
||||
}
|
||||
final boolean endsWithHyphen = checkEndsWithHyphen
|
||||
&& this.foText.charAt(lastIndex) == CharUtilities.SOFT_HYPHEN;
|
||||
&& foText.charAt(lastIndex) == CharUtilities.SOFT_HYPHEN;
|
||||
final Font font = FontSelector
|
||||
.selectFontForCharactersInText(this.foText,
|
||||
this.thisStart, lastIndex, this.foText, this);
|
||||
.selectFontForCharactersInText(foText,
|
||||
this.thisStart, lastIndex, foText, this);
|
||||
final int wordLength = lastIndex - this.thisStart;
|
||||
final boolean kerning = font.hasKerning();
|
||||
final MinOptMax wordIPD = new MinOptMax(0);
|
||||
for (int i = this.thisStart; i < lastIndex; i++) {
|
||||
final char c = this.foText.charAt(i);
|
||||
final char currentChar = foText.charAt(i);
|
||||
|
||||
//character width
|
||||
final int charWidth = font.getCharWidth(c);
|
||||
final int charWidth = font.getCharWidth(currentChar);
|
||||
wordIPD.add(charWidth);
|
||||
|
||||
//kerning
|
||||
if (kerning) {
|
||||
int kern = 0;
|
||||
if (i > this.thisStart) {
|
||||
final char previous = this.foText.charAt(i - 1);
|
||||
kern = font.getKernValue(previous, c) * font.getFontSize() / 1000;
|
||||
} else if (prevAi != null && !prevAi.isSpace && prevAi.breakIndex > 0) {
|
||||
final char previous = this.foText.charAt(prevAi.breakIndex - 1);
|
||||
kern = font.getKernValue(previous, c) * font.getFontSize() / 1000;
|
||||
final char previousChar = foText.charAt(i - 1);
|
||||
kern = font.getKernValue(previousChar, currentChar);
|
||||
} else if (prevAreaInfo != null && !prevAreaInfo.isSpace && prevAreaInfo.breakIndex > 0) {
|
||||
final char previousChar = foText.charAt(prevAreaInfo.breakIndex - 1);
|
||||
kern = font.getKernValue(previousChar, currentChar);
|
||||
}
|
||||
if (kern != 0) {
|
||||
this.addToLetterAdjust(i, kern);
|
||||
@ -731,11 +733,10 @@ public class TextLayoutManager extends LeafNodeLayoutManager {
|
||||
&& !TextLayoutManager.isSpace(ch)
|
||||
&& lastIndex > 0
|
||||
&& endsWithHyphen) {
|
||||
final int kern = font.getKernValue(
|
||||
this.foText.charAt(lastIndex - 1), ch)
|
||||
* font.getFontSize() / 1000;
|
||||
final int kern = font.getKernValue(foText.charAt(lastIndex - 1), ch);
|
||||
if (kern != 0) {
|
||||
this.addToLetterAdjust(lastIndex, kern);
|
||||
//TODO: add kern to wordIPD?
|
||||
}
|
||||
}
|
||||
int iLetterSpaces = wordLength - 1;
|
||||
@ -748,20 +749,20 @@ public class TextLayoutManager extends LeafNodeLayoutManager {
|
||||
wordIPD.add(MinOptMax.multiply(this.letterSpaceIPD, iLetterSpaces));
|
||||
|
||||
// create the AreaInfo object
|
||||
ai = new AreaInfo(this.thisStart, lastIndex, 0,
|
||||
AreaInfo areaInfo = new AreaInfo(this.thisStart, lastIndex, 0,
|
||||
iLetterSpaces, wordIPD,
|
||||
endsWithHyphen,
|
||||
false, breakOpportunity, font);
|
||||
prevAi = ai;
|
||||
this.vecAreaInfo.add(ai);
|
||||
prevAreaInfo = areaInfo;
|
||||
this.vecAreaInfo.add(areaInfo);
|
||||
this.tempStart = this.nextStart;
|
||||
|
||||
//add the elements
|
||||
this.addElementsForAWordFragment(sequence, alignment, ai,
|
||||
this.addElementsForAWordFragment(sequence, alignment, areaInfo,
|
||||
this.vecAreaInfo.size() - 1, this.letterSpaceIPD);
|
||||
ai = null;
|
||||
this.thisStart = this.nextStart;
|
||||
return prevAi;
|
||||
|
||||
return prevAreaInfo;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
|
@ -298,14 +298,14 @@ public class ListItemLayoutManager extends BlockStackingLayoutManager
|
||||
int stepPenalty = 0;
|
||||
KnuthElement endEl = (KnuthElement)elementLists[0].get(end[0]);
|
||||
if (endEl instanceof KnuthPenalty) {
|
||||
additionalPenaltyHeight = endEl.getW();
|
||||
stepPenalty = Math.max(stepPenalty, endEl.getP());
|
||||
additionalPenaltyHeight = endEl.getWidth();
|
||||
stepPenalty = Math.max(stepPenalty, endEl.getPenalty());
|
||||
}
|
||||
endEl = (KnuthElement)elementLists[1].get(end[1]);
|
||||
if (endEl instanceof KnuthPenalty) {
|
||||
additionalPenaltyHeight = Math.max(
|
||||
additionalPenaltyHeight, endEl.getW());
|
||||
stepPenalty = Math.max(stepPenalty, endEl.getP());
|
||||
additionalPenaltyHeight, endEl.getWidth());
|
||||
stepPenalty = Math.max(stepPenalty, endEl.getPenalty());
|
||||
}
|
||||
|
||||
int boxHeight = step - addedBoxHeight - penaltyHeight;
|
||||
@ -367,7 +367,7 @@ public class ListItemLayoutManager extends BlockStackingLayoutManager
|
||||
end[i]++;
|
||||
KnuthElement el = (KnuthElement)elementLists[i].get(end[i]);
|
||||
if (el.isPenalty()) {
|
||||
if (el.getP() < KnuthElement.INFINITE) {
|
||||
if (el.getPenalty() < KnuthElement.INFINITE) {
|
||||
//First legal break point
|
||||
break;
|
||||
}
|
||||
@ -379,9 +379,9 @@ public class ListItemLayoutManager extends BlockStackingLayoutManager
|
||||
break;
|
||||
}
|
||||
}
|
||||
partialHeights[i] += el.getW();
|
||||
partialHeights[i] += el.getWidth();
|
||||
} else {
|
||||
partialHeights[i] += el.getW();
|
||||
partialHeights[i] += el.getWidth();
|
||||
}
|
||||
}
|
||||
if (end[i] < start[i]) {
|
||||
|
@ -158,9 +158,9 @@ class ActiveCell {
|
||||
private int contentLength;
|
||||
|
||||
FillerPenalty(KnuthPenalty p, int length) {
|
||||
super(length, p.getP(), p.isFlagged(), p.getBreakClass(),
|
||||
super(length, p.getPenalty(), p.isPenaltyFlagged(), p.getBreakClass(),
|
||||
p.getPosition(), p.isAuxiliary());
|
||||
contentLength = p.getW();
|
||||
contentLength = p.getWidth();
|
||||
}
|
||||
|
||||
FillerPenalty(int length) {
|
||||
@ -190,7 +190,7 @@ class ActiveCell {
|
||||
} else if (el instanceof FillerBox) {
|
||||
return 0;
|
||||
} else {
|
||||
return el.getW();
|
||||
return el.getWidth();
|
||||
}
|
||||
}
|
||||
|
||||
@ -248,17 +248,17 @@ class ActiveCell {
|
||||
KnuthElement el = (KnuthElement) iter.next();
|
||||
if (el.isBox()) {
|
||||
prevIsBox = true;
|
||||
cumulateLength += el.getW();
|
||||
cumulateLength += el.getWidth();
|
||||
} else if (el.isGlue()) {
|
||||
if (prevIsBox) {
|
||||
elementList.add(iter.nextIndex() - 1,
|
||||
new FillerPenalty(minBPD - cumulateLength));
|
||||
}
|
||||
prevIsBox = false;
|
||||
cumulateLength += el.getW();
|
||||
cumulateLength += el.getWidth();
|
||||
} else {
|
||||
prevIsBox = false;
|
||||
if (cumulateLength + el.getW() < minBPD) {
|
||||
if (cumulateLength + el.getWidth() < minBPD) {
|
||||
iter.set(new FillerPenalty((KnuthPenalty) el, minBPD - cumulateLength));
|
||||
}
|
||||
}
|
||||
@ -314,7 +314,7 @@ class ActiveCell {
|
||||
KnuthElement el = (KnuthElement) knuthIter.next();
|
||||
if (el.isPenalty()) {
|
||||
prevIsBox = false;
|
||||
if (el.getP() < KnuthElement.INFINITE
|
||||
if (el.getPenalty() < KnuthElement.INFINITE
|
||||
|| ((KnuthPenalty) el).getBreakClass() == Constants.EN_PAGE) {
|
||||
// TODO too much is being done in that test, only to handle
|
||||
// keep.within-column properly.
|
||||
@ -322,8 +322,8 @@ class ActiveCell {
|
||||
// First legal break point
|
||||
breakFound = true;
|
||||
KnuthPenalty p = (KnuthPenalty) el;
|
||||
afterNextStep.penaltyLength = p.getW();
|
||||
afterNextStep.penaltyValue = p.getP();
|
||||
afterNextStep.penaltyLength = p.getWidth();
|
||||
afterNextStep.penaltyValue = p.getPenalty();
|
||||
if (p.isForcedBreak()) {
|
||||
afterNextStep.breakClass = p.getBreakClass();
|
||||
}
|
||||
@ -333,9 +333,9 @@ class ActiveCell {
|
||||
// Second legal break point
|
||||
breakFound = true;
|
||||
} else {
|
||||
afterNextStep.contentLength += el.getW();
|
||||
afterNextStep.contentLength += el.getWidth();
|
||||
if (!boxFound) {
|
||||
afterNextStep.condBeforeContentLength += el.getW();
|
||||
afterNextStep.condBeforeContentLength += el.getWidth();
|
||||
}
|
||||
}
|
||||
prevIsBox = false;
|
||||
@ -348,7 +348,7 @@ class ActiveCell {
|
||||
}
|
||||
prevIsBox = true;
|
||||
boxFound = true;
|
||||
afterNextStep.contentLength += el.getW();
|
||||
afterNextStep.contentLength += el.getWidth();
|
||||
}
|
||||
}
|
||||
afterNextStep.end = knuthIter.nextIndex() - 1;
|
||||
|
@ -361,7 +361,7 @@ class RowPainter {
|
||||
while (iter.nextIndex() < endIndex) {
|
||||
KnuthElement el = (KnuthElement) iter.next();
|
||||
if (el.isBox() || el.isGlue()) {
|
||||
len += el.getW();
|
||||
len += el.getWidth();
|
||||
}
|
||||
}
|
||||
len += ActiveCell.getElementContentLength((KnuthElement) iter.next());
|
||||
|
@ -202,7 +202,7 @@ public class TableCellLayoutManager extends BlockStackingLayoutManager
|
||||
if (lastItem.isForcedBreak()) {
|
||||
KnuthPenalty p = (KnuthPenalty) lastItem;
|
||||
primaryGridUnit.setBreakAfter(p.getBreakClass());
|
||||
p.setP(0);
|
||||
p.setPenalty(0);
|
||||
}
|
||||
|
||||
setFinished(true);
|
||||
|
@ -83,10 +83,10 @@ public class ElementListCheck implements LayoutEngineCheck {
|
||||
}
|
||||
if (domEl.getAttribute("w").length() > 0) {
|
||||
int w = Integer.parseInt(domEl.getAttribute("w"));
|
||||
if (w != knuthEl.getW()) {
|
||||
if (w != knuthEl.getWidth()) {
|
||||
fail("Expected w=" + w
|
||||
+ " at position " + pos
|
||||
+ " but got: " + knuthEl.getW());
|
||||
+ " but got: " + knuthEl.getWidth());
|
||||
}
|
||||
}
|
||||
if ("true".equals(domEl.getAttribute("aux"))) {
|
||||
@ -110,24 +110,24 @@ public class ElementListCheck implements LayoutEngineCheck {
|
||||
KnuthPenalty pen = (KnuthPenalty)knuthEl;
|
||||
if (domEl.getAttribute("w").length() > 0) {
|
||||
int w = Integer.parseInt(domEl.getAttribute("w"));
|
||||
if (w != knuthEl.getW()) {
|
||||
if (w != knuthEl.getWidth()) {
|
||||
fail("Expected w=" + w
|
||||
+ " at position " + pos
|
||||
+ " but got: " + knuthEl.getW());
|
||||
+ " but got: " + knuthEl.getWidth());
|
||||
}
|
||||
}
|
||||
if (domEl.getAttribute("p").length() > 0) {
|
||||
if ("<0".equals(domEl.getAttribute("p"))) {
|
||||
if (knuthEl.getP() >= 0) {
|
||||
if (knuthEl.getPenalty() >= 0) {
|
||||
fail("Expected p<0"
|
||||
+ " at position " + pos
|
||||
+ " but got: " + knuthEl.getP());
|
||||
+ " but got: " + knuthEl.getPenalty());
|
||||
}
|
||||
} else if (">0".equals(domEl.getAttribute("p"))) {
|
||||
if (knuthEl.getP() <= 0) {
|
||||
if (knuthEl.getPenalty() <= 0) {
|
||||
fail("Expected p>0"
|
||||
+ " at position " + pos
|
||||
+ " but got: " + knuthEl.getP());
|
||||
+ " but got: " + knuthEl.getPenalty());
|
||||
}
|
||||
} else {
|
||||
int p;
|
||||
@ -142,20 +142,20 @@ public class ElementListCheck implements LayoutEngineCheck {
|
||||
} else {
|
||||
p = Integer.parseInt(domEl.getAttribute("p"));
|
||||
}
|
||||
if (p != knuthEl.getP()) {
|
||||
if (p != knuthEl.getPenalty()) {
|
||||
fail("Expected p=" + p
|
||||
+ " at position " + pos
|
||||
+ " but got: " + knuthEl.getP());
|
||||
+ " but got: " + knuthEl.getPenalty());
|
||||
}
|
||||
}
|
||||
}
|
||||
if ("true".equals(domEl.getAttribute("flagged"))) {
|
||||
if (!pen.isFlagged()) {
|
||||
if (!pen.isPenaltyFlagged()) {
|
||||
fail("Expected flagged penalty"
|
||||
+ " at position " + pos);
|
||||
}
|
||||
} else if ("false".equals(domEl.getAttribute("flagged"))) {
|
||||
if (pen.isFlagged()) {
|
||||
if (pen.isPenaltyFlagged()) {
|
||||
fail("Expected non-flagged penalty"
|
||||
+ " at position " + pos);
|
||||
}
|
||||
@ -180,26 +180,26 @@ public class ElementListCheck implements LayoutEngineCheck {
|
||||
KnuthGlue glue = (KnuthGlue)knuthEl;
|
||||
if (domEl.getAttribute("w").length() > 0) {
|
||||
int w = Integer.parseInt(domEl.getAttribute("w"));
|
||||
if (w != knuthEl.getW()) {
|
||||
if (w != knuthEl.getWidth()) {
|
||||
fail("Expected w=" + w
|
||||
+ " at position " + pos
|
||||
+ " but got: " + knuthEl.getW());
|
||||
+ " but got: " + knuthEl.getWidth());
|
||||
}
|
||||
}
|
||||
if (domEl.getAttribute("y").length() > 0) {
|
||||
int stretch = Integer.parseInt(domEl.getAttribute("y"));
|
||||
if (stretch != knuthEl.getY()) {
|
||||
if (stretch != knuthEl.getStretch()) {
|
||||
fail("Expected y=" + stretch
|
||||
+ " (stretch) at position " + pos
|
||||
+ " but got: " + knuthEl.getY());
|
||||
+ " but got: " + knuthEl.getStretch());
|
||||
}
|
||||
}
|
||||
if (domEl.getAttribute("z").length() > 0) {
|
||||
int shrink = Integer.parseInt(domEl.getAttribute("z"));
|
||||
if (shrink != knuthEl.getZ()) {
|
||||
if (shrink != knuthEl.getShrink()) {
|
||||
fail("Expected z=" + shrink
|
||||
+ " (shrink) at position " + pos
|
||||
+ " but got: " + knuthEl.getZ());
|
||||
+ " but got: " + knuthEl.getShrink());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -55,9 +55,9 @@ public class ElementListUtilsTestCase extends TestCase {
|
||||
|
||||
assertFalse(res);
|
||||
|
||||
assertEquals(KnuthElement.INFINITE, ((KnuthPenalty)lst.get(1)).getP());
|
||||
assertEquals(KnuthElement.INFINITE, ((KnuthPenalty)lst.get(3)).getP());
|
||||
assertEquals(0, ((KnuthPenalty)lst.get(5)).getP());
|
||||
assertEquals(KnuthElement.INFINITE, ((KnuthPenalty)lst.get(1)).getPenalty());
|
||||
assertEquals(KnuthElement.INFINITE, ((KnuthPenalty)lst.get(3)).getPenalty());
|
||||
assertEquals(0, ((KnuthPenalty)lst.get(5)).getPenalty());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -82,11 +82,11 @@ public class ElementListUtilsTestCase extends TestCase {
|
||||
assertFalse(res);
|
||||
|
||||
//Must insert an INFINITE penalty
|
||||
assertEquals(KnuthElement.INFINITE, ((KnuthPenalty)lst.get(1)).getP());
|
||||
assertEquals(0, ((KnuthGlue)lst.get(2)).getW());
|
||||
assertEquals(KnuthElement.INFINITE, ((KnuthPenalty)lst.get(4)).getP());
|
||||
assertEquals(0, ((KnuthGlue)lst.get(5)).getW());
|
||||
assertEquals(0, ((KnuthGlue)lst.get(7)).getW());
|
||||
assertEquals(KnuthElement.INFINITE, ((KnuthPenalty)lst.get(1)).getPenalty());
|
||||
assertEquals(0, ((KnuthGlue)lst.get(2)).getWidth());
|
||||
assertEquals(KnuthElement.INFINITE, ((KnuthPenalty)lst.get(4)).getPenalty());
|
||||
assertEquals(0, ((KnuthGlue)lst.get(5)).getWidth());
|
||||
assertEquals(0, ((KnuthGlue)lst.get(7)).getWidth());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -110,9 +110,9 @@ public class ElementListUtilsTestCase extends TestCase {
|
||||
|
||||
assertFalse(res);
|
||||
|
||||
assertEquals(0, ((KnuthPenalty)lst.get(1)).getP());
|
||||
assertEquals(KnuthElement.INFINITE, ((KnuthPenalty)lst.get(3)).getP());
|
||||
assertEquals(KnuthElement.INFINITE, ((KnuthPenalty)lst.get(5)).getP());
|
||||
assertEquals(0, ((KnuthPenalty)lst.get(1)).getPenalty());
|
||||
assertEquals(KnuthElement.INFINITE, ((KnuthPenalty)lst.get(3)).getPenalty());
|
||||
assertEquals(KnuthElement.INFINITE, ((KnuthPenalty)lst.get(5)).getPenalty());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -137,10 +137,10 @@ public class ElementListUtilsTestCase extends TestCase {
|
||||
assertFalse(res);
|
||||
|
||||
//Must insert an INFINITE penalty
|
||||
assertEquals(0, ((KnuthPenalty)lst.get(1)).getP());
|
||||
assertEquals(KnuthElement.INFINITE, ((KnuthPenalty)lst.get(3)).getP());
|
||||
assertEquals(KnuthElement.INFINITE, ((KnuthPenalty)lst.get(5)).getP());
|
||||
assertEquals(0, ((KnuthGlue)lst.get(6)).getW());
|
||||
assertEquals(0, ((KnuthPenalty)lst.get(1)).getPenalty());
|
||||
assertEquals(KnuthElement.INFINITE, ((KnuthPenalty)lst.get(3)).getPenalty());
|
||||
assertEquals(KnuthElement.INFINITE, ((KnuthPenalty)lst.get(5)).getPenalty());
|
||||
assertEquals(0, ((KnuthGlue)lst.get(6)).getWidth());
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user