< prev index next >

src/java.desktop/share/classes/javax/swing/text/Utilities.java

Print this page




 509             if (txt[i] == '\t'
 510                 || ((spaceAddon != 0 || i <= spaceAddonLeftoverEnd)
 511                     && (txt[i] == ' ')
 512                     && startJustifiableContent <= i
 513                     && i <= endJustifiableContent
 514                     )){
 515                 if (txt[i] == '\t') {
 516                     if (e != null) {
 517                         nextX = e.nextTabStop(nextX, startOffset + i - txtOffset);
 518                     } else {
 519                         nextX += getFontCharWidth(' ', metrics, useFPAPI);
 520                     }
 521                 } else if (txt[i] == ' ') {
 522                     nextX += getFontCharWidth(' ', metrics, useFPAPI);
 523                     nextX += spaceAddon;
 524                     if (i <= spaceAddonLeftoverEnd) {
 525                         nextX++;
 526                     }
 527                 }
 528             } else {
 529                 nextX += getFontCharWidth(txt[i], metrics, useFPAPI);





 530             }
 531             if (x < nextX) {
 532                 // found the hit position... return the appropriate side
 533                 int offset;
 534 
 535                 // the length of the string measured as a whole may differ from
 536                 // the sum of individual character lengths, for example if
 537                 // fractional metrics are enabled; and we must guard from this.
 538                 if (round) {
 539                     offset = i + 1 - txtOffset;
 540 
 541                     float width = getFontCharsWidth(txt, txtOffset, offset,
 542                                                     metrics, useFPAPI);
 543                     float span = x - x0;
 544 
 545                     if (span < width) {
 546                         while (offset > 0) {
 547                             float charsWidth = getFontCharsWidth(txt, txtOffset,
 548                                     offset - 1, metrics, useFPAPI);
 549                             float nextWidth = offset > 1 ? charsWidth : 0;




 509             if (txt[i] == '\t'
 510                 || ((spaceAddon != 0 || i <= spaceAddonLeftoverEnd)
 511                     && (txt[i] == ' ')
 512                     && startJustifiableContent <= i
 513                     && i <= endJustifiableContent
 514                     )){
 515                 if (txt[i] == '\t') {
 516                     if (e != null) {
 517                         nextX = e.nextTabStop(nextX, startOffset + i - txtOffset);
 518                     } else {
 519                         nextX += getFontCharWidth(' ', metrics, useFPAPI);
 520                     }
 521                 } else if (txt[i] == ' ') {
 522                     nextX += getFontCharWidth(' ', metrics, useFPAPI);
 523                     nextX += spaceAddon;
 524                     if (i <= spaceAddonLeftoverEnd) {
 525                         nextX++;
 526                     }
 527                 }
 528             } else {
 529                 // Use the floating point API directly as char width can be in 
 530                 // floating point for non-integer window scale
 531                 Rectangle2D bounds = metrics.getFont().
 532                                      getStringBounds(new char[]{txt[i]}, 0, 1,
 533                                                      metrics.getFontRenderContext());
 534                 nextX += (float) bounds.getWidth();
 535             }
 536             if (x < nextX) {
 537                 // found the hit position... return the appropriate side
 538                 int offset;
 539 
 540                 // the length of the string measured as a whole may differ from
 541                 // the sum of individual character lengths, for example if
 542                 // fractional metrics are enabled; and we must guard from this.
 543                 if (round) {
 544                     offset = i + 1 - txtOffset;
 545 
 546                     float width = getFontCharsWidth(txt, txtOffset, offset,
 547                                                     metrics, useFPAPI);
 548                     float span = x - x0;
 549 
 550                     if (span < width) {
 551                         while (offset > 0) {
 552                             float charsWidth = getFontCharsWidth(txt, txtOffset,
 553                                     offset - 1, metrics, useFPAPI);
 554                             float nextWidth = offset > 1 ? charsWidth : 0;


< prev index next >