From e958bfd23d914962790ee0269cbcd3684f71aa7d Mon Sep 17 00:00:00 2001 From: "Andreas L. Delmelle" Date: Thu, 20 Sep 2007 20:00:45 +0000 Subject: [PATCH] Bugfix: non-collapsed white-space caused ArrayIndexOutOfBoundsException git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@577899 13f79535-47bb-0310-9956-ffa450edef68 --- .../layoutmgr/inline/TextLayoutManager.java | 52 ++++++++++--------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/src/java/org/apache/fop/layoutmgr/inline/TextLayoutManager.java b/src/java/org/apache/fop/layoutmgr/inline/TextLayoutManager.java index 93196d8ab..923c6261e 100644 --- a/src/java/org/apache/fop/layoutmgr/inline/TextLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/inline/TextLayoutManager.java @@ -804,30 +804,34 @@ public class TextLayoutManager extends LeafNodeLayoutManager { ListIterator oldListIterator = oldList.listIterator(); KnuthElement el = (KnuthElement)oldListIterator.next(); LeafPosition pos = (LeafPosition) ((KnuthBox) el).getPosition(); - AreaInfo ai = (AreaInfo) vecAreaInfo.get(pos.getLeafPos()); - ai.iLScount++; - ai.ipdArea.add(letterSpaceIPD); - if (BREAK_CHARS.indexOf(textArray[iTempStart - 1]) >= 0) { - // the last character could be used as a line break - // append new elements to oldList - oldListIterator = oldList.listIterator(oldList.size()); - oldListIterator.add(new KnuthPenalty(0, KnuthPenalty.FLAGGED_PENALTY, true, - new LeafPosition(this, -1), false)); - oldListIterator.add(new KnuthGlue(letterSpaceIPD.opt, - letterSpaceIPD.max - letterSpaceIPD.opt, - letterSpaceIPD.opt - letterSpaceIPD.min, - new LeafPosition(this, -1), false)); - } else if (letterSpaceIPD.min == letterSpaceIPD.max) { - // constant letter space: replace the box - oldListIterator.set(new KnuthInlineBox(ai.ipdArea.opt, alignmentContext, pos, false)); - } else { - // adjustable letter space: replace the glue - oldListIterator.next(); // this would return the penalty element - oldListIterator.next(); // this would return the glue element - oldListIterator.set(new KnuthGlue(ai.iLScount * letterSpaceIPD.opt, - ai.iLScount * (letterSpaceIPD.max - letterSpaceIPD.opt), - ai.iLScount * (letterSpaceIPD.opt - letterSpaceIPD.min), - new LeafPosition(this, -1), true)); + int idx = pos.getLeafPos(); + //element could refer to '-1' position, for non-collapsed spaces (?) + if (idx >= -1) { + AreaInfo ai = (AreaInfo) vecAreaInfo.get(idx); + ai.iLScount++; + ai.ipdArea.add(letterSpaceIPD); + if (BREAK_CHARS.indexOf(textArray[iTempStart - 1]) >= 0) { + // the last character could be used as a line break + // append new elements to oldList + oldListIterator = oldList.listIterator(oldList.size()); + oldListIterator.add(new KnuthPenalty(0, KnuthPenalty.FLAGGED_PENALTY, true, + new LeafPosition(this, -1), false)); + oldListIterator.add(new KnuthGlue(letterSpaceIPD.opt, + letterSpaceIPD.max - letterSpaceIPD.opt, + letterSpaceIPD.opt - letterSpaceIPD.min, + new LeafPosition(this, -1), false)); + } else if (letterSpaceIPD.min == letterSpaceIPD.max) { + // constant letter space: replace the box + oldListIterator.set(new KnuthInlineBox(ai.ipdArea.opt, alignmentContext, pos, false)); + } else { + // adjustable letter space: replace the glue + oldListIterator.next(); // this would return the penalty element + oldListIterator.next(); // this would return the glue element + oldListIterator.set(new KnuthGlue(ai.iLScount * letterSpaceIPD.opt, + ai.iLScount * (letterSpaceIPD.max - letterSpaceIPD.opt), + ai.iLScount * (letterSpaceIPD.opt - letterSpaceIPD.min), + new LeafPosition(this, -1), true)); + } } return oldList; } -- 2.39.5