Yes, this is an important insight, I've made a visual comparison of #4 (red) compared to #1 (blue)
http://ws.stfx.eu/LWMJN1SY7VXT plus compared to the other ones it can even tell the height... now to teach Roassal how to use it... Peter On Tue, Oct 27, 2015 at 4:11 PM, Thierry Goubier <[email protected]> wrote: > Hi Alex, > > thanks, this is very usefull. Can you tell which one of these measures is > the closest to the effective length of a string morph? Number 4? > > Thierry > > > 2015-10-27 12:02 GMT+01:00 Aliaksei Syrel <[email protected]>: > >> Hi >> >> I'm sending it here so that it doesn't get lost. >> >> >> There are multiple ways to measure string width. In the following >> examples performance will be tested measuring 10`000 times the width of the >> following string: >> >> *string := 'abcdefghijklmnopqrstuvwxyz 0123456789!@#$%^&*()_+'.* >> >> 1) The most straightforward way is to send #widthOfString: to the font. >> Time to run gives around 250ms. >> http://ws.stfx.eu/2Q5YA9DFTRDR >> Resulting value is rounded to integer and seems to be not absolutely >> correct and precise. >> >> 2) More complex way is to go deeper on the level of glyphs and manually >> summarise the width of each character in the string sending >> #getGlyphWidth: character to the font. Time to run gives around 750ms. >> http://ws.stfx.eu/ETBEW1EHAAZ8 >> Resulting value is float and looks like correct and precise value. >> >> 3) Even more complex is to use CairoFontMetricsProvider instead of font's >> methods. The same as in 2nd case we measure each character. Time to run >> around 350ms. >> http://ws.stfx.eu/7I89DMD0ZLM3 >> Resulting value is exactly the same as in the 2nd case. With almost equal >> performance to 1st it is nice alternative. >> >> 4) One more way is to let native cairo to calculate everything for us. >> Calls happen through nativeboost. Time to run around 120ms. >> http://ws.stfx.eu/HYD76OMIOM7L <http://ws.stfx.eu/HYD76OMIOM7L> >> As result it returns *CairoTextExtents* which allows to calculate width >> and height with one call. >> >> Cheers, >> Alex >> > >
