- // width of the (endChar+1)-th character
- int width = charOffsets[endChar+1] -
- charOffsets[endChar];
-
- // remove the endChar-th character
- removed += width;
- endChar++;
+ if (initialChar > 0)
+ {
+ // width of the initialChar-th character
+ int width = charOffsets[initialChar] -
+ charOffsets[initialChar-1];
+
+ // remove the initialChar-th character
+ removed += width;
+ initialChar--;
+ }
+
+ if (endChar < len - 1 &&
+ removed < excessPixels)
+ {
+ // width of the (endChar+1)-th character
+ int width = charOffsets[endChar+1] -
+ charOffsets[endChar];
+
+ // remove the endChar-th character
+ removed += width;
+ endChar++;
+ }
+
+ if (initialChar == 0 && endChar == len-1)
+ {
+ nChars = len+1;
+ break;
+ }