From 22bd14a3a7ecf5c8a11ffb7ff57d4eef4c1f2cc1 Mon Sep 17 00:00:00 2001 From: Roman Kennke Date: Mon, 4 Dec 2006 18:33:27 +0000 Subject: 2006-12-04 Roman Kennke * java/awt/font/TextLayout.java (hitTestChar): Fixed conditions for inclusion of range. Use layout information in the run for more efficiency. --- ChangeLog | 6 ++++++ java/awt/font/TextLayout.java | 24 ++++++++++-------------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9fa8d2274..f5af97a42 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2006-12-04 Roman Kennke + + * java/awt/font/TextLayout.java + (hitTestChar): Fixed conditions for inclusion of range. + Use layout information in the run for more efficiency. + 2006-12-04 Andrew John Hughes * gnu/java/lang/management/BeanImpl.java: diff --git a/java/awt/font/TextLayout.java b/java/awt/font/TextLayout.java index 2f810cddf..26e784b9a 100644 --- a/java/awt/font/TextLayout.java +++ b/java/awt/font/TextLayout.java @@ -1174,16 +1174,14 @@ public final class TextLayout implements Cloneable // TODO: Perform binary search for maximum efficiency. However, we // need the run location laid out statically to do that. int numRuns = runs.length; - float offs = 0; Run hitRun = null; for (int i = 0; i < numRuns && hitRun == null; i++) { Run run = runs[i]; Rectangle2D lBounds = run.glyphVector.getLogicalBounds(); - if (lBounds.getMinY() + offs <= y && lBounds.getMaxY() + offs > y) + if (lBounds.getMinY() + run.location <= y + && lBounds.getMaxY() + run.location >= y) hitRun = run; - else - offs += lBounds.getHeight(); } // Now we have (hopefully) found a run that hits. Now find the // right character. @@ -1196,12 +1194,12 @@ public final class TextLayout implements Cloneable int gi = i - hitRun.runStart; Rectangle2D lBounds = gv.getGlyphLogicalBounds(gi) .getBounds2D(); - if (lBounds.getMinY() + offs <= y - && lBounds.getMaxY() + offs > y) + if (lBounds.getMinY() + hitRun.location <= y + && lBounds.getMaxY() + hitRun.location >= y) { // Found hit. Now check if we are leading or trailing. boolean leading = true; - if (lBounds.getCenterY() + offs <= y) + if (lBounds.getCenterY() + hitRun.location <= y) leading = false; hitInfo = leading ? TextHitInfo.leading(i) : TextHitInfo.trailing(i); @@ -1215,16 +1213,14 @@ public final class TextLayout implements Cloneable // TODO: Perform binary search for maximum efficiency. However, we // need the run location laid out statically to do that. int numRuns = runs.length; - float offs = 0; Run hitRun = null; for (int i = 0; i < numRuns && hitRun == null; i++) { Run run = runs[i]; Rectangle2D lBounds = run.glyphVector.getLogicalBounds(); - if (lBounds.getMinX() + offs <= x && lBounds.getMaxX() + offs > x) + if (lBounds.getMinX() + run.location <= x + && lBounds.getMaxX() + run.location >= x) hitRun = run; - else - offs += lBounds.getWidth(); } // Now we have (hopefully) found a run that hits. Now find the // right character. @@ -1237,12 +1233,12 @@ public final class TextLayout implements Cloneable int gi = i - hitRun.runStart; Rectangle2D lBounds = gv.getGlyphLogicalBounds(gi) .getBounds2D(); - if (lBounds.getMinX() + offs <= x - && lBounds.getMaxX() + offs > x) + if (lBounds.getMinX() + hitRun.location <= x + && lBounds.getMaxX() + hitRun.location >= x) { // Found hit. Now check if we are leading or trailing. boolean leading = true; - if (lBounds.getCenterX() + offs <= x) + if (lBounds.getCenterX() + hitRun.location <= x) leading = false; hitInfo = leading ? TextHitInfo.leading(i) : TextHitInfo.trailing(i); -- cgit v1.2.1