Another piece on that TextLayout thingy. This was quite
straightforward.
2006-11-22 Roman Kennke <[EMAIL PROTECTED]>
* java/awt/text/TextLayout.java
(getLogicalRangesForVisualSelection): Implemented.
/Roman
Index: java/awt/font/TextLayout.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/awt/font/TextLayout.java,v
retrieving revision 1.17
diff -u -1 -5 -r1.17 TextLayout.java
--- java/awt/font/TextLayout.java 21 Nov 2006 21:31:23 -0000 1.17
+++ java/awt/font/TextLayout.java 22 Nov 2006 14:38:30 -0000
@@ -642,33 +642,84 @@
if( r == null )
r = r2;
else
r = r.createUnion(r2);
}
gi = 0; // reset glyph index into run for next run.
advance += gv.getLogicalBounds().getWidth();
}
return r;
}
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)
{
return getNextLeftHit(offset, DEFAULT_CARET_POLICY);
}
public TextHitInfo getNextLeftHit(int offset, CaretPolicy policy)
{
if (policy == null)
throw new IllegalArgumentException("Null policy not allowed");
if (offset < 0 || offset > length)
throw new IllegalArgumentException("Offset out of bounds");
TextHitInfo hit1 = TextHitInfo.afterOffset(offset);