diff options
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | java/awt/font/TextLayout.java | 55 |
2 files changed, 58 insertions, 2 deletions
@@ -1,3 +1,8 @@ +2006-11-22 Roman Kennke <kennke@aicas.com> + + * java/awt/text/TextLayout.java + (getLogicalRangesForVisualSelection): Implemented. + 2006-11-21 Roman Kennke <kennke@aicas.com> * java/awt/text/TextLayout.java diff --git a/java/awt/font/TextLayout.java b/java/awt/font/TextLayout.java index e526e4f68..0362c2687 100644 --- a/java/awt/font/TextLayout.java +++ b/java/awt/font/TextLayout.java @@ -654,9 +654,60 @@ public final class TextLayout implements Cloneable public int[] getLogicalRangesForVisualSelection (TextHitInfo firstEndpoint, TextHitInfo secondEndpoint) - throws NotImplementedException { - throw new Error ("not implemented"); + // Check parameters. + checkHitInfo(firstEndpoint); + checkHitInfo(secondEndpoint); + + // Convert to visual and order correctly. + int start = hitToCaret(firstEndpoint); + int end = hitToCaret(secondEndpoint); + if (start > end) + { + // Swap start and end so that end >= start. + int temp = start; + start = end; + end = temp; + } + + // Now walk through the visual indices and mark the included pieces. + boolean[] include = new boolean[length]; + for (int i = start; i < end; i++) + { + include[visualToLogical[i]] = true; + } + + // Count included runs. + int numRuns = 0; + boolean in = false; + for (int i = 0; i < length; i++) + { + if (include[i] != in) // At each run in/out point we toggle the in var. + { + in = ! in; + if (in) // At each run start we count up. + numRuns++; + } + } + + // Put together the ranges array. + int[] ranges = new int[numRuns * 2]; + int index = 0; + in = false; + for (int i = 0; i < length; i++) + { + if (include[i] != in) + { + ranges[index] = i; + index++; + in = ! in; + } + } + // If the last run ends at the very end, include that last bit too. + if (in) + ranges[index] = length; + + return ranges; } public TextHitInfo getNextLeftHit(int offset) |