OK, apologies for when I said relatively simple…
Here is the API for the text stimulus:
I haven’t done this before, but I guess you’ll need to access three properties of your TextStim:
.pos : where on the screen it is centred
.boundingBox : “bounding box of the text (w,h). This differs from width in that the width represents the width of the margins, which might differ from the width of the text within them. NOTE: currently always returns the size in pixels (this will change to return in stimulus units)”
.wrapWidth: “The width the text should run before wrapping”. You might not actually need to use this if you don’t set it and your text doesn’t overflow the size of the stimulus.
e.g. Let’s say you are displaying the string
len() function tells you its number of characters (for a unicode text at least). If the bounding box gives a width of 200 pixels, and the text has 5 characters, then you know that each takes 40 pixels. If the stimulus is centred at
[0, 0], then for a monospaced font, the first character starts at 100 pixels left of centre and extends to 60 pixels left of centre. The next spans from -60 to -20, and so on. Similar calculations can be done for the vertical extent, yielding the vertices of a square which contain your character. The same process can be done for entire words, if that is what you are after, by calculating the entire width of word based on its number of letters.
The wrapWidth complicates things, but not too much, in terms of working out if and when text flows to the next line.