If i write a text on SWT say "this text" in a particular font/style , i want the individual coords of 't' 'h' 'i' 's' and so on. Is there any way to obtain the same.
A:
Text text = new Text(parent, SWT.NONE);
text.setText("This");
GC gc = new GC(text);
int currentPixelsX = text.getBounds().x;
int currentPixelsY = text.getBounds().y;
for (int i = 0; i < text.getText().length(); i++) {
System.out.println("X co-ordinate of " + text.getText().charAt(i) + ":" + currentPixelsX);
System.out.println("Y co-ordinate of " + text.getText().charAt(i) + ":" + currentPixelsY);
currentPixelsX = currentPixelsX + gc.getCharWidth(text.getText().charAt(i));
}
This gives the the pixel co-ordinates with respect to the parent of the text box.
Rusty
2009-10-11 05:22:02
The solution you are suggesting does not accomodate for char spacing/word spacing adjustments of GDI.
Jagan
2009-10-11 15:54:03