Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8319844 : Text/TextFlow.hitTest() is incorrect in RTL orientation #1323

Closed
wants to merge 17 commits into from
Closed
Original file line number Diff line number Diff line change
@@ -503,19 +503,17 @@ public Hit getHitInfo(float x, float y, String text, int textRunStart, int curRu

for (int i = 0; i < runs.length; i++) {
run = runs[i];
if (run.getStart() != curRunStart) {
if (run.getTextSpan().getText().equals(text) && x > run.getWidth() && (run.getLevel() & 0x01) != 1) {
x -= run.getWidth();
}
if (run.getStart() != curRunStart && run.getTextSpan().getText().equals(text) && x > run.getWidth()) {
x -= run.getWidth();
continue;
}
if (run.getTextSpan() != null && run.getTextSpan().getText().equals(text)) {
if ((x > run.getWidth() && (!isMultiRunText || run.getStart() == curRunStart)) || textWidthPrevLine > 0) {
getBounds(run.getTextSpan(), textBounds);
x -= (run.getLocation().x - textBounds.getMinX());
x -= (runs[0].getLocation().x - textBounds.getMinX());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: we are still in the for loop, so perhaps it makes sense to extract
(runs[0].getLocation().x - textBounds.getMinX());
to a variable outside of the loop

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea is that outside the loop we don't know if we need to subtract the textBound min x value and the starting location of the first run or not. That is why this is present inside the loop. Once this is done we are breaking out of the loop so this will not get called multiple times.
Let me know if you have any suggestions.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are right: I missed the break in line 520

}
for (int j = runs.length - 1; j > i; j--) {
if (runs[j].getStart() != curRunStart && runs[j].getTextSpan().getText().equals(text)) {
if (runs[j].getStart() != curRunStart && runs[j].getTextSpan().getText().equals(text) && !runs[j].isLinebreak()) {
ltrIndex += runs[j].getLength();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

runs[j] is repeated 4 times... should it be a local variable?

}
}