From 99729ee7d09b6adee9caa2a7ba72c1813757648f Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Tue, 5 Dec 2006 00:03:01 +0000 Subject: * 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 c271361ed..a3b03113b 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 * javax/management/openmbean/OpenType.java: diff --git a/java/awt/font/TextLayout.java b/java/awt/font/TextLayout.java index dde28df0a..dc0e537eb 100644 --- a/java/awt/font/TextLayout.java +++ b/java/awt/font/TextLayout.java @@ -1176,16 +1176,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. @@ -1198,12 +1196,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); @@ -1217,16 +1215,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. @@ -1239,12 +1235,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