6760148: Certain fonts are not correctly soft wrapped when using JTextComponent.print()
Reviewed-by: peterz
This commit is contained in:
parent
1c0c4dc366
commit
1af9167ee7
@ -390,11 +390,15 @@ public class Utilities {
|
|||||||
}
|
}
|
||||||
if ((x >= currX) && (x < nextX)) {
|
if ((x >= currX) && (x < nextX)) {
|
||||||
// found the hit position... return the appropriate side
|
// found the hit position... return the appropriate side
|
||||||
if ((round == false) || ((x - currX) < (nextX - x))) {
|
int offset = ((round == false) || ((x - currX) < (nextX - x))) ?
|
||||||
return i - txtOffset;
|
(i - txtOffset) : (i + 1 - txtOffset);
|
||||||
} else {
|
// the length of the string measured as a whole may differ from
|
||||||
return i + 1 - txtOffset;
|
// the sum of individual character lengths, for example if
|
||||||
|
// fractional metrics are enabled; and we must guard from this.
|
||||||
|
while (metrics.charsWidth(txt, txtOffset, offset + 1) > (x - x0)) {
|
||||||
|
offset--;
|
||||||
}
|
}
|
||||||
|
return (offset < 0 ? 0 : offset);
|
||||||
}
|
}
|
||||||
currX = nextX;
|
currX = nextX;
|
||||||
}
|
}
|
||||||
@ -403,24 +407,6 @@ public class Utilities {
|
|||||||
return txtCount;
|
return txtCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Adjust text offset so that the length of a resulting string as a whole
|
|
||||||
* fits into the specified width.
|
|
||||||
*/
|
|
||||||
static int adjustOffsetForFractionalMetrics(
|
|
||||||
Segment s, FontMetrics fm, int offset, int width) {
|
|
||||||
// Sometimes the offset returned by getTabbedTextOffset is beyond the
|
|
||||||
// available area, when fractional metrics are enabled. We should
|
|
||||||
// guard against this.
|
|
||||||
if (offset < s.count) {
|
|
||||||
while (offset > 0 &&
|
|
||||||
fm.charsWidth(s.array, s.offset, offset + 1) > width) {
|
|
||||||
offset--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return offset;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine where to break the given text to fit
|
* Determine where to break the given text to fit
|
||||||
* within the given span. This tries to find a word boundary.
|
* within the given span. This tries to find a word boundary.
|
||||||
@ -443,7 +429,6 @@ public class Utilities {
|
|||||||
int txtCount = s.count;
|
int txtCount = s.count;
|
||||||
int index = Utilities.getTabbedTextOffset(s, metrics, x0, x,
|
int index = Utilities.getTabbedTextOffset(s, metrics, x0, x,
|
||||||
e, startOffset, false);
|
e, startOffset, false);
|
||||||
index = adjustOffsetForFractionalMetrics(s, metrics, index, x - x0);
|
|
||||||
|
|
||||||
if (index >= txtCount - 1) {
|
if (index >= txtCount - 1) {
|
||||||
return txtCount;
|
return txtCount;
|
||||||
|
@ -239,11 +239,9 @@ public class WrappedPlainView extends BoxView implements TabExpander {
|
|||||||
tabBase, tabBase + currentWidth,
|
tabBase, tabBase + currentWidth,
|
||||||
this, p0);
|
this, p0);
|
||||||
} else {
|
} else {
|
||||||
int offset = Utilities.getTabbedTextOffset(segment, metrics,
|
p = p0 + Utilities.getTabbedTextOffset(segment, metrics,
|
||||||
tabBase, tabBase + currentWidth, this, p0, false);
|
tabBase, tabBase + currentWidth,
|
||||||
offset = Utilities.adjustOffsetForFractionalMetrics(
|
this, p0, false);
|
||||||
segment, metrics, offset, currentWidth);
|
|
||||||
p = p0 + offset;
|
|
||||||
}
|
}
|
||||||
SegmentCache.releaseSharedSegment(segment);
|
SegmentCache.releaseSharedSegment(segment);
|
||||||
return p;
|
return p;
|
||||||
|
Loading…
Reference in New Issue
Block a user