Comparion of LogicalFontInstance::ImplGetGlyphBoundRect() between platforms

Chris Sherlock chris.sherlock79 at
Fri Oct 21 14:42:25 UTC 2022

On 16 Oct 2022, at 9:03 am, Chris Sherlock <chris.sherlock79 at> wrote:
> On Sun, Oct 16, 2022 at 2:07 AM Caolán McNamara <caolanm at <mailto:caolanm at>> wrote:
> On Sat, 2022-10-15 at 22:13 +1100, Chris Sherlock wrote:
> > So an update… after I shifted to using Liberation Sans as the font
> > face and added gb_CppunitTest_use_more_fonts the only platform that
> > varies is MacOS.
> > 
> > Test name: VclLogicalFontInstanceTest::testglyphboundrect
> > equality assertion failed
> > - Expected: 7x9@(0,-8)
> > - Actual  : 7x10@(0,-8)
> And what if you use a larger font size. say font size 110 instead of
> 11, maybe its a hinting related thing.
> Just tried, looks like it is out by 1. 
> Test name: VclLogicalFontInstanceTest::testglyphboundrect
> equality assertion failed
> - Expected: 51x82@(7,-80)
> - Actual  : 51x83@(7,-80)

I’ve had another look at the code, with some help from Khaled. The issue is the way in which we do our final rounding. 

On Freetype, it uses 26.6 fixed point, and thus needs it’s own special FreeType ceil and floor functions. CoreText appears to using floating point, but the std::ceil and std::floor functions give slight different results. 

I am confused why this might be… does anyone have any ideas?

FWIW, the reasoning for using 26.6 in Freetype can be found here: <>

The floor and ceiling functions used are defined here: <>

And the control box function that gets the bounding box is FT_Glyph_Get_CBox(), which can be found here: <>

We basically copied the ceil and floor used in Freetype in an attempt to get CoreText as close as possible to FreeType. It’s a pity it is off by 1 in many cases… would love it if something with more knowledge than me can see why this differs!

I’ve written a utility to get the bounding boxes of all the glyphs of a particular font, incidentally. It can be found here: <>


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the LibreOffice mailing list