text_size when text ends with a whitspace
Hi all,
I am building an eye-tracking reading experiment, and I am encountering some issues to draw areas of interest. So far, I have been using the text_size function per each area of my sentence (five, in this case). However, it seems that text_size ignores whether there is a whitespace at the end of the word - meaning that, at the end, all my areas of interest are shifted to the left. I have tried:
- Adding a whitespace after each word in the loop
- Adding a whitespace via an inline python plugin before calling text_size
Any ideas as to how to go about this? (or even if text_size is the way to go)
Thank you!
Comments
Hi Nadia,
Sounds weird. But if you have the sizes as returned by the
text_sizefunction, can't you adapt that variables somewhat? Like, there is a whitespace in the string, shift the values to the right (i.e. adding a few pixels onto the number)?Would that work?
Eduard
Hi Eduard,
Thanks for your answer! I did actually try something like that: Create an additional text that is just space, get its width, and then add it to the areas of interest calculation but it didn't quite work (maybe I did something wrong!).
I just came back from the lab and I used .rect instead of text_size and this time it worked (I don't discard having made additional changes that were the issue in my first post that I was unaware of)-- the new additional problem is that the space between words that are in different areas of interest is not as "big" as that of within areas of interest (in the picture below, the first space is between areas of interest, the second is within). Any suggestion for this? Thank you again for your response!
Hi @nadia27 and @eduard ,
A cheap trick to include spaces that have a fixed size is by using a visible character, and then give this character the color of the background. For example, the text string below would appear as though there is a space between 'Word' and 'Another word', but really it's an underscore that's not visible because it has the background color. The main reason to do this is to avoid the space from not being taken into account when calculating the text size.
Word<span style="color:{background};">_</span>Another word— Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!
Hi @sebastiaan,
Just saw this now - thank you! I just tried it out and noticed something: does Text() add a tiny bit of space at the end of the text? I noticed that the gap between words was bigger than the space taken by an underscore, so I printed it with colour and noticed there was space between the words (see example below, where I changed the underscore for an 'i')
@nadia27 I see what you mean, yes. It seems the
spanelement is flanked by whitespace. Maybe you can use an empty span instead? This is regular HTML formatting, so you can play around using all the tools available in HTML.Check out SigmundAI.eu for our OpenSesame AI assistant!