Cinder icon indicating copy to clipboard operation
Cinder copied to clipboard

linux: TextureFont vertical alignment off

Open richardeakin opened this issue 7 years ago • 5 comments

This is affecting any platforms using the FreeType impl of ci::gl::TextureFont. You can see how the vertical alignment is different in the TextureFont sample by adding these two lines here:

gl::color( 1, 0, 0 );
gl::drawStrokedRect( boundsRect );

Compare windows desktop:

texturefontapp_msw

to Ubuntu desktop:

texturefontapp_linux

The issue becomes more apparent with a more involved interface, such as the _audio/DeviceTest. Windows desktop:

devicetestapp_msw

and Ubuntu Desktop:

devicetest_linux

This also affects Raspberry Pi and TK1 platforms, as initially reported in #1844.

richardeakin avatar May 26 '17 23:05 richardeakin

Has anyone made any progress with this issue? cc @richardeakin

Hebali avatar Oct 08 '21 12:10 Hebali

It's a longstanding issue that awaits a complete text rewrite, there are quite a few posts about that but no ETA.. For the time being there are also various other text wrappers available.

richardeakin avatar Oct 23 '21 14:10 richardeakin

Thanks @richardeakin ! I appreciate your looking into this. Not sure that I have the bandwidth to dive deep and pull all the threads together at the moment. But might try at some point if no one beats me to it :)

Hebali avatar Oct 26 '21 21:10 Hebali

Ok, I'm not all the way there, but there's a problem here: https://github.com/cinder/Cinder/blob/ef8254525eed9e2589b6bf1b19e2205f148c5de8/src/cinder/gl/TextureFont.cpp#L761

Specifically, glyphInfoIt->second.mTexCoords.getSize() gives the wrong values. I haven't traced through the logic yet, but it's set here: https://github.com/cinder/Cinder/blob/ef8254525eed9e2589b6bf1b19e2205f148c5de8/src/cinder/gl/TextureFont.cpp#L382

From my limited tests and use-cases, the output looks right to me if I replace L761 with: result += glyphInfoIt->second.mOriginOffset + getFont().getGlyphBoundingBox( glyphMeasures.back().first ).getSize();

Oh, almost forgot to mention the offset itself: drawString()'s vertical alignment is off by the ascent. A call to: textureFont->drawString( str, basePos ); is replaced by: textureFont->drawString( str, basePos + vec2( 0, textureFont->getAscent() ) );

I haven't gone very deep into understanding this implementation and I know it's due for a big rewrite, so I defer to you @richardeakin as to whether this is worth taking any further. Certainly this is at best a hotfix.

Hebali avatar Dec 15 '21 02:12 Hebali

I think if you find a fix it's worth posting, but as mentioned a complete overhaul is imminent (though pending a few people's work schedules) - if you can manage it we can probably merge, otherwise I'd suggest looking at an alternative text rendering solution when the layout gets particular such as Potion / Cinder-Text.

richardeakin avatar Dec 16 '21 17:12 richardeakin