jdk/src/share/classes/javax/swing/text/Utilities.java
changeset 9218 883c22142aa9
parent 8533 0537e84f6e69
child 9232 9e29d6359705
equal deleted inserted replaced
9217:f795ef267353 9218:883c22142aa9
   393                 int offset = ((round == false) || ((x - currX) < (nextX - x))) ?
   393                 int offset = ((round == false) || ((x - currX) < (nextX - x))) ?
   394                         (i - txtOffset) : (i + 1 - txtOffset);
   394                         (i - txtOffset) : (i + 1 - txtOffset);
   395                 // the length of the string measured as a whole may differ from
   395                 // the length of the string measured as a whole may differ from
   396                 // the sum of individual character lengths, for example if
   396                 // the sum of individual character lengths, for example if
   397                 // fractional metrics are enabled; and we must guard from this.
   397                 // fractional metrics are enabled; and we must guard from this.
   398                 while (metrics.charsWidth(txt, txtOffset, offset + 1) > (x - x0)) {
   398                 while (offset > 0 && metrics.charsWidth(txt, txtOffset, offset) > (x - x0)) {
   399                     offset--;
   399                     offset--;
   400                 }
   400                 }
   401                 return (offset < 0 ? 0 : offset);
   401                 return offset;
   402             }
   402             }
   403             currX = nextX;
   403             currX = nextX;
   404         }
   404         }
   405 
   405 
   406         // didn't find, return end offset
   406         // didn't find, return end offset