0

For an eye tracking study i need the positions of each word in a text drawn to the window. I can see how I can get the bounding box of the whole text as a return value using

[nx, ny, textbounds] = DrawFormattedText(win, tstring)

Is there a better way than drawing a whole sentence using this function word by word?

wuschLOR
  • 155
  • 1
  • 6
sven.io
  • 3
  • 1

1 Answers1

0

Something like this should do it:

teststr = {'Hello World!' ; 'How are you doing?'}

ystart = 100
xstart = 200
wordgap = 10

for i=1:size(teststr,1)

  str=teststr{i};
  wordlist = strsplit(str , ' ');

  for j=1:size(wordlist)(1)
    [nx, ny, textbounds]=DrawFormattedText(win, wordlist{j} ,xstart, ystart);
    poslist{j} = textbounds;
    xstart=nx+wordgap;
  end

end

Not pretty, but it works. You will get problems if you have linebreaks.

EDIT: 2015-07-14: added wordgap suggestion from sven.io

wuschLOR
  • 155
  • 1
  • 6
  • probably a little whitespace between the words would be required, like `wordgap = 10`. and nx and ny are the top left corner of the drawn text, so `xstart = nx + textbounds.width + wordgap;` i would expect? – sven.io Jul 13 '15 at 10:09
  • "The function returns the new (nx, ny) position of the text drawing cursor and the bounding rectangle 'textbounds' of the drawn string. (nx,ny) can be used as new start position for connecting further text strings to the bottom of the drawn text string." The wordgap is a good hint! – wuschLOR Jul 14 '15 at 12:21