- // width of the (endChar+1)-th character
- int width = charOffsets[endChar+1] -
- charOffsets[endChar];
-
- // remove the endChar-th character
- removed += width;
- endChar++;
+ // try to remove the last character of the first part of the string
+ if (initialCharToRemove > 0)
+ {
+ // width of the (initialCharToRemove-1)-th character
+ int widthPx;
+ if (initialCharToRemove >= 2)
+ widthPx = charOffsetsPx[initialCharToRemove-1] - charOffsetsPx[initialCharToRemove-2];
+ else
+ widthPx = charOffsetsPx[initialCharToRemove-1];
+ // the (initialCharToRemove-1)-th character is the first char of the string
+
+ wxASSERT(widthPx >= 0); // widthPx is zero for e.g. tab characters
+
+ // mark the (initialCharToRemove-1)-th character as removable
+ initialCharToRemove--;
+ removedPx += widthPx;
+ }
+
+ // try to remove the first character of the last part of the string
+ if (endCharToRemove < len - 1 &&
+ removedPx < excessPx)
+ {
+ // width of the (endCharToRemove+1)-th character
+ int widthPx = charOffsetsPx[endCharToRemove+1] -
+ charOffsetsPx[endCharToRemove];
+
+ wxASSERT(widthPx >= 0); // widthPx is zero for e.g. tab characters
+
+ // mark the (endCharToRemove+1)-th character as removable
+ endCharToRemove++;
+ removedPx += widthPx;
+ }
+
+ if (initialCharToRemove == 0 && endCharToRemove == len-1)
+ {
+ // we need to remove all the characters of the string!
+ break;
+ }