@@ -98,7 +98,7 @@ private PendingChange(final GlyphMapping mapping, final int index) {
9898 * be used to influence the start position of the first letter. The entry i+1 defines the
9999 * cursor advancement after the character i. A null entry means no special advancement.
100100 */
101- private final MinOptMax [] letterSpaceAdjustArray ; //size = textArray.length + 1
101+ private MinOptMax [] letterSpaceAdjustArray ; //size = textArray.length + 1
102102
103103 /** Font used for the space between words. */
104104 private Font spaceFont ;
@@ -142,7 +142,6 @@ private PendingChange(final GlyphMapping mapping, final int index) {
142142 */
143143 public TextLayoutManager (FOText node , FOUserAgent userAgent ) {
144144 foText = node ;
145- letterSpaceAdjustArray = new MinOptMax [node .length () + 1 ];
146145 mappings = new ArrayList <GlyphMapping >();
147146 this .userAgent = userAgent ;
148147 }
@@ -267,7 +266,7 @@ private void addMappingAreas(GlyphMapping mapping, int wordSpaceCount, int lette
267266 }
268267
269268 for (int i = mapping .startIndex ; i < mapping .endIndex ; i ++) {
270- MinOptMax letterSpaceAdjustment = letterSpaceAdjustArray [ i + 1 ] ;
269+ MinOptMax letterSpaceAdjustment = getLetterSpaceAdjustment ( i + 1 ) ;
271270 if (letterSpaceAdjustment != null && letterSpaceAdjustment .isElastic ()) {
272271 letterSpaceCount ++;
273272 }
@@ -659,8 +658,7 @@ private void addLetterAdjust(GlyphMapping wordMapping) {
659658 int j = letterSpaceAdjustIndex + i ;
660659 if (j > 0 ) {
661660 int k = wordMapping .startIndex + i ;
662- MinOptMax adj = (k < letterSpaceAdjustArray .length )
663- ? letterSpaceAdjustArray [ k ] : null ;
661+ MinOptMax adj = getLetterSpaceAdjustment (k );
664662 letterSpaceAdjust [ j ] = (adj == null ) ? 0 : adj .getOpt ();
665663 }
666664 if (letterSpaceCount > 0 ) {
@@ -975,6 +973,9 @@ private GlyphMapping processWord(final int alignment, final KnuthSequence sequen
975973 char breakOpportunityChar = breakOpportunity ? ch : 0 ;
976974 char precedingChar = prevMapping != null && !prevMapping .isSpace
977975 && prevMapping .endIndex > 0 ? foText .charAt (prevMapping .endIndex - 1 ) : 0 ;
976+ if (letterSpaceAdjustArray == null && font .hasKerning ()) {
977+ letterSpaceAdjustArray = new MinOptMax [foText .length () + 1 ];
978+ }
978979 GlyphMapping mapping = GlyphMapping .doGlyphMapping (foText , thisStart , lastIndex , font ,
979980 letterSpaceIPD , letterSpaceAdjustArray , precedingChar , breakOpportunityChar ,
980981 endsWithHyphen , level , false , false , retainControls );
@@ -1076,7 +1077,7 @@ public void hyphenate(Position pos, HyphContext hyphContext) {
10761077 newIPD = newIPD .plus (font .getCharWidth (cp ));
10771078 //if (i > startIndex) {
10781079 if (i < stopIndex ) {
1079- MinOptMax letterSpaceAdjust = letterSpaceAdjustArray [ i + 1 ] ;
1080+ MinOptMax letterSpaceAdjust = getLetterSpaceAdjustment ( i + 1 ) ;
10801081 if (i == stopIndex - 1 && hyphenFollows ) {
10811082 //the letter adjust here needs to be handled further down during
10821083 //element generation because it depends on hyph/no-hyph condition
@@ -1388,7 +1389,7 @@ private void addElementsForAWordFragment(List baseList, int alignment, GlyphMapp
13881389 MinOptMax widthIfNoBreakOccurs = null ;
13891390 if (mapping .endIndex < foText .length ()) {
13901391 //Add in kerning in no-break condition
1391- widthIfNoBreakOccurs = letterSpaceAdjustArray [ mapping .endIndex ] ;
1392+ widthIfNoBreakOccurs = getLetterSpaceAdjustment ( mapping .endIndex ) ;
13921393 }
13931394 //if (mapping.breakIndex)
13941395
@@ -1523,4 +1524,10 @@ public String toString() {
15231524 + "}" ;
15241525 }
15251526
1527+ protected MinOptMax getLetterSpaceAdjustment (int i ) {
1528+ if (letterSpaceAdjustArray == null || i >= letterSpaceAdjustArray .length ) {
1529+ return null ;
1530+ }
1531+ return letterSpaceAdjustArray [i ];
1532+ }
15261533}
0 commit comments