1. win32lib bug in getFontSize

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

new topic     » topic index » view message » categorize

2. Re: win32lib bug in getFontSize

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

new topic     » goto parent     » topic index » view message » categorize

3. Re: win32lib bug in getFontSize

What I'm saying is the the character height should read as follows:

height = w32fetch(tm,tmHeight) + w32fetch(tm,tmExternalLeading

new topic     » goto parent     » topic index » view message » categorize

4. Re: win32lib bug in getFontSize

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

new topic     » goto parent     » topic index » view message » categorize

5. Re: win32lib bug in getFontSize

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.

new topic     » goto parent     » topic index » view message » categorize

6. Re: win32lib bug in getFontSize

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

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu