if(firstEndpoint < 0 || secondEndpoint > characterCount) {
throw new IllegalArgumentException("Range is invalid in TextLayout.getLogicalHighlightShape()");
}
GeneralPath result = new GeneralPath(GeneralPath.WIND_EVEN_ODD);
int[] carets = new int[10]; // would this ever not handle all cases?
int count = 0;
if (firstEndpoint < secondEndpoint) {
int logIndex = firstEndpoint;
do {
carets[count++] = hitToCaret(TextHitInfo.leading(logIndex));
boolean ltr = textLine.isCharLTR(logIndex);
do {
logIndex++;
} while (logIndex < secondEndpoint && textLine.isCharLTR(logIndex) == ltr);
int hitCh = logIndex;
carets[count++] = hitToCaret(TextHitInfo.trailing(hitCh - 1));
if (count == carets.length) {
int[] temp = new int[carets.length + 10];
System.arraycopy(carets, 0, temp, 0, count);
carets = temp;
}
} while (logIndex < secondEndpoint);
}
else {
count = 2;
carets[0] = carets[1] = hitToCaret(TextHitInfo.leading(firstEndpoint));
}
// now create paths for pairs of carets
for (int i = 0; i < count; i += 2) {
result.append(caretBoundingShape(carets[i], carets[i+1], bounds),
false);
}
if (firstEndpoint != secondEndpoint) {
if ((textLine.isDirectionLTR() && firstEndpoint == 0) || (!textLine.isDirectionLTR() &&
secondEndpoint == characterCount)) {
GeneralPath ls = leftShape(bounds);
if (!ls.getBounds().isEmpty()) {
result.append(ls, false);
}
}
if ((textLine.isDirectionLTR() && secondEndpoint == characterCount) ||
(!textLine.isDirectionLTR() && firstEndpoint == 0)) {
GeneralPath rs = rightShape(bounds);
if (!rs.getBounds().isEmpty()) {
result.append(rs, false);
}
}
}