1. win32lib bug in getFontSize
- Posted by George Walters <gwalters at s?.rr.c?m> Nov 29, 2007
- 493 views
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. http://msdn2.microsoft.com/en-us/library/ms534015.aspx 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
2. 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
3. Re: win32lib bug in getFontSize
- Posted by George Walters <gwalters at sc.r?.com> Nov 29, 2007
- 479 views
What I'm saying is the the character height should read as follows: height = w32fetch(tm,tmHeight) + w32fetch(tm,tmExternalLeading
4. Re: win32lib bug in getFontSize
- Posted by CChris <christian.cuvier at ?griculture.gouv.?r> Nov 29, 2007
- 500 views
- Last edited Nov 30, 2007
George Walters wrote: > > What I'm saying is the the character height should read as follows: > > height = w32fetch(tm,tmHeight) + w32fetch(tm,tmExternalLeading My perception would be height = w32fetch(tm,tmHeight) + w32fetch(tm,tmExternalLeading) + w32fetch(tm,tmInternalLeading) Any thoughts? CChris
5. Re: win32lib bug in getFontSize
- Posted by George Walters <gwalters at sc?r?.com> Nov 29, 2007
- 494 views
- Last edited Nov 30, 2007
Chris, getFontSize has that now. My point is that tmHeight contains the top (leading space) tmInternalLeading, so you only need to add tmExternalLeading for the total height. The lower tmInternalLeading in the diagram belongs to the lower character in the diagram.
6. Re: win32lib bug in getFontSize
- Posted by Derek Parnell <ddparnell at big?ond?com> Nov 29, 2007
- 488 views
- Last edited Nov 30, 2007
George Walters wrote: > I've discovered that win32lib getFontSize is wrong..at least in my opinion. I agree that it is wrong. The tmHeight value already includes the tmInternalLeading value so the win32lib function should not add it in again. -- Derek Parnell Melbourne, Australia Skype name: derek.j.parnell