Re: win32lib bug in getFontSize
- Posted by CChris <christian.cuvier at agricult??e.gouv.fr> Nov 29, 2007
- 487 views
George Walters wrote: > > I posted this once in "Analyze this" but I suspect that no one probably > noticed. > > I've discovered that win32lib getFontSize is wrong..at least in my opinion. > > Look at this link which has a drawing of characters explaining the vars used. > > <a > href="http://msdn2.microsoft.com/en-us/library/ms534015.aspx">http://msdn2.microsoft.com/en-us/library/ms534015.aspx</a> > From the illustration posted on that page, I'd replace one of the tmInternalLeading by tmExternalLeading. But I'm not very experienced in typesetting, so please anyone prove me wrong. CChris > Then look at the winlib32 code below. "tmInternalLeading" is actually added > twice. It's first contained in "tmHeight" then getFontSize adds it again. > I think that "tmInternalLeading" should be removed from the char heigth. > I've rem'd it out on my copy and my list boxes have the correct height since > I'm sizing them by character heights. If I'm wrong please explain. > > > global function getFontSize( integer id ) > > -- get metrics for current font > > integer width, height, maxwidth > atom tm > > -- text metric structure > tm = w32acquire_mem(0, SIZEOF_TEXTMETRIC ) > > -- get the metrics of the font (queryFont will prepend the DC) > if not queryFont( id, xGetTextMetrics, {tm} ) then > warnErr( Err_GETFONTSIZE ) > end if > > -- assign values > width = w32fetch(tm,tmAveCharWidth) > maxwidth = w32fetch(tm,tmMaxCharWidth) > height = w32fetch(tm,tmHeight) + > w32fetch(tm,tmInternalLeading) + <----------- remove this > w32fetch(tm,tmExternalLeading) > > -- release > w32release_mem( tm ) > > -- return results > return { width, height, maxwidth } > > end function