DrawFormattedText vertical center alignment behaves strange

Hi there,


I have a Lenovo b570e laptop, running Windows 7 SP1,

CPU Intel Pentium B960, with 4Gb RAM and 120Gb SSD storage.


I have a few days old, freshly installed, latest version 

Octave 5.1.0 "x86_64-win64-mingw32" 

and Psychtoolbox 3 Beta-2019-08-07_V3.0.16


I experienced that when I use this command:

DrawFormattedText(win, '+test+test+', 'center', 'center', white);


then the center of the middle cross in this string label is aligned...

1, correctly in the center of the screen regarding the x axis

2, incorrectly aligned on the y axis, as it is lower than it should be. I measured that the top pixel line of the drawn text is aligned to the y axis center. I expected the midpoint of the label's bounding box to be centered.


I think this may be because of a bug, because on the x axis, 'center' argument definitely aligns the text labels midpoint to the center on x axis. 


In my current experiment, I am using a + sign as fixation cross, so that it is crucial to be correctly aligned on both axes, so I now have to manually correct the y alignment coordinates by subtracting the half height of the label. 


Please check out this problem. Thanks!

I’m noticing the same thing with PTB 3.0.19, Matlab 2024b, Ubuntu 24.04.1.
[screenXpixels, screenYpixels] = Screen(‘WindowSize’, info.window);
stimStartY=round(screenYpixels/2);
fixationCircle=183;
Screen(‘TextSize’, info.window, 48);
Screen(‘TextFont’, info.window, ‘Geneva’)
DrawFormattedText(info.window, fixationCircle, ‘center’, stimStartY, info.white);
DrawFormattedText(info.window, fixationCircle, ‘center’, ‘center’, info.white);

The first one appears to be located about half a character length above the second.
1920 x 1080 screen pixels
So for characters, the coordinates sx and sy are for the lower left hand corner of a text character (consistent with Matlab convention), and ‘center’ corrects for this in order to center the character?

What does help DrawFormattedText say wrt. text centering?

y position is the baseline of the text, ie. the so called descender of text glyphs will extend below the “vertically centered” y position, e.g., the “stalks” of y or q or g. As the help text say, the centering is approximate, based on information stored in the text fonts, as guaranteed pixel perfect centering, e.g., by using image processing to find the exact center of mass would not be possible with any good performance.

I know many people use text characters like + signs or o’s or similar as fixation points, but this is not guaranteed to be pixel exact, because text drawing is not meant for that. Drawing a fixation cross or circle with drawing functions is.

Your latter DrawFormattedText() command takes the y position as baseline into account, your former does not, so the latter is probably a bit more correct, as far as correctness goes here. Also, you can look at DrawFormattedText.m to understand the centering methods.