1. Win32Lib: any way to GET the font size?

Is there some way to get the font SIZE?  I don't mean the height or width 
extents of CHARACTERS, I mean the value that would be used to SET the font
to a particular size. 

I want to be able to center various text within columns, by changing the 
size of the font as needed, but that text could
be in different sized fonts to begin with, so my routine needs to change
the font size *from* whatever original size it was, so I need to be able to
*find out* what size it happens to be initially.

Dan Moyer

new topic     » topic index » view message » categorize

2. Re: Win32Lib: any way to GET the font size?

Dan Moyer wrote:
> 
> Is there some way to get the font SIZE?  I don't mean the height or width 
> extents of CHARACTERS, I mean the value that would be used to SET the font
> to a particular size. 
> 
> I want to be able to center various text within columns, by changing the 
> size of the font as needed, but that text could
> be in different sized fonts to begin with, so my routine needs to change
> the font size *from* whatever original size it was, so I need to be able to
> *find out* what size it happens to be initially.
> 
> Dan Moyer

Hello Dan,

Try getFontDialog()

Don Cole

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

3. Re: Win32Lib: any way to GET the font size?

don cole wrote:
> 
> 
> Dan Moyer wrote:
> > 
> > Is there some way to get the font SIZE?  I don't mean the height or width 
> > extents of CHARACTERS, I mean the value that would be used to SET the font
> > to a particular size. 
> > 
> > I want to be able to center various text within columns, by changing the 
> > size of the font as needed, but that text could
> > be in different sized fonts to begin with, so my routine needs to change
> > the font size *from* whatever original size it was, so I need to be able to
> > *find out* what size it happens to be initially.
> > 
> > Dan Moyer
> 
> Hello Dan,
> 
> Try getFontDialog()
> 
> Don Cole

Don,

I'm not looking for a *dialog*, wherein a user *selects* a font/size,
but rather a way for my *program* to ascertain what font size is currently
in force for a window.  I want my program to GET the font size first, then
it will decrement it as necessary, then return to original after using 
smaller size as needed to fit space allotted.

Dan

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

4. Re: Win32Lib: any way to GET the font size?

Dan Moyer wrote:
> 
> don cole wrote:
> > 
> > 
> > Dan Moyer wrote:
> > > 
> > > Is there some way to get the font SIZE?  I don't mean the height or width 
> > > extents of CHARACTERS, I mean the value that would be used to SET the font
> > > to a particular size. 
> > > 
> > > I want to be able to center various text within columns, by changing the 
> > > size of the font as needed, but that text could
> > > be in different sized fonts to begin with, so my routine needs to change
> > > the font size *from* whatever original size it was, so I need to be able
> > > to
> > > *find out* what size it happens to be initially.
> > > 
> > > Dan Moyer
> > 
> > Hello Dan,
> > 
> > Try getFontDialog()
> > 
> > Don Cole
> 
> Don,
> 
> I'm not looking for a *dialog*, wherein a user *selects* a font/size,
> but rather a way for my *program* to ascertain what font size is currently
> in force for a window.  I want my program to GET the font size first, then
> it will decrement it as necessary, then return to original after using 
> smaller size as needed to fit space allotted.
> 
> Dan

Hello Dan,

  I was just reading from index.html the desciption of 

   getFontDialog ( window )

   that says 

   Returns: { font name, points, style flags, color } or -1 if cancelled.

I have never used this. However I have a program that I think does what you
  want. It starts out with a randon (large) font size. Then it keeps reducing it
  until all the columns fit on the paper. This print preview program is lengthy and
  I have never posted it in the archives. If you are interested I coulde e-mail it
  to you.

Don Cole

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

5. Re: Win32Lib: any way to GET the font size?

don cole wrote:
> 
> Dan Moyer wrote:
> > 
> > don cole wrote:
> > > 
> > > 
> > > Dan Moyer wrote:
> > > > 
> > > > Is there some way to get the font SIZE?  I don't mean the height or
> > > > width
> > > > extents of CHARACTERS, I mean the value that would be used to SET the
> > > > font
> > > > to a particular size. 
> > > > 
> > > > I want to be able to center various text within columns, by changing the
> > > >
> > > > size of the font as needed, but that text could
> > > > be in different sized fonts to begin with, so my routine needs to change
> > > > the font size *from* whatever original size it was, so I need to be able
> > > > to
> > > > *find out* what size it happens to be initially.
> > > > 
> > > > Dan Moyer
> > > 
> > > Hello Dan,
> > > 
> > > Try getFontDialog()
> > > 
> > > Don Cole
> > 
> > Don,
> > 
> > I'm not looking for a *dialog*, wherein a user *selects* a font/size,
> > but rather a way for my *program* to ascertain what font size is currently
> > in force for a window.  I want my program to GET the font size first, then
> > it will decrement it as necessary, then return to original after using 
> > smaller size as needed to fit space allotted.
> > 
> > Dan
> 
> Hello Dan,
> 
>   I was just reading from index.html the desciption of 
> 
>    getFontDialog ( window )
> 
>    that says 
> 
>    Returns: { font name, points, style flags, color } or -1 if cancelled.
> 
>   I have never used this. However I have a program that I think does what you
> want. It starts out with a randon (large) font size. Then it keeps reducing
> it until all the columns fit on the paper. This print preview program is
> lengthy
> and I have never posted it in the archives. If you are interested I coulde
> e-mail
> it to you.
> 
> Don Cole

Don,

Thanks, I can do it myself once I know the font size (which I'll work around
by making sure that I keep track of it whenever it gets changed), but I'm
always interested in how others code a similar problem, so if you will,
go ahead & email it to me.

Actually I'm just concerned with fitting things onto the *screen* right now,
but as soon as I get that working I will want
to do the exact same thing for printer, also.

Dan

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

6. Re: Win32Lib: any way to GET the font size?

Dan Moyer wrote:
> 
> don cole wrote:
> > 
> > Dan Moyer wrote:
> > > 
> > > don cole wrote:
> > > > 
> > > > 
> > > > Dan Moyer wrote:
> > > > > 
> > > > > Is there some way to get the font SIZE?  I don't mean the height or
> > > > > width
> </font></i>
> > > > > extents of CHARACTERS, I mean the value that would be used to SET the
> > > > > font
> > > > > to a particular size. 
> > > > > 
> > > > > I want to be able to center various text within columns, by changing
> > > > > the
> > > > > size of the font as needed, but that text could
> > > > > be in different sized fonts to begin with, so my routine needs to
> > > > > change
> > > > > the font size *from* whatever original size it was, so I need to be
> > > > > able
> to</font></i>
> > > > > *find out* what size it happens to be initially.
> > > > > 
> > > > > Dan Moyer
> > > > 
> > > > Hello Dan,
> > > > 
> > > > Try getFontDialog()
> > > > 
> > > > Don Cole
> > > 
> > > Don,
> > > 
> > > I'm not looking for a *dialog*, wherein a user *selects* a font/size,
> > > but rather a way for my *program* to ascertain what font size is currently
> > > in force for a window.  I want my program to GET the font size first, then
> > > it will decrement it as necessary, then return to original after using 
> > > smaller size as needed to fit space allotted.
> > > 
> > > Dan
> > 
> > Hello Dan,
> > 
> >   I was just reading from index.html the desciption of 
> > 
> >    getFontDialog ( window )
> > 
> >    that says 
> > 
> >    Returns: { font name, points, style flags, color } or -1 if cancelled.
> > 
> >   I have never used this. However I have a program that I think does what
> >   you
> > want. It starts out with a randon (large) font size. Then it keeps reducing
> > it until all the columns fit on the paper. This print preview program is
> > lengthy
> > and I have never posted it in the archives. If you are interested I coulde
> > e-mail
> > it to you.
> > 
> > Don Cole
> 
> Don,
> 
> Thanks, I can do it myself once I know the font size (which I'll work around
> by making sure that I keep track of it whenever it gets changed), but I'm
> always interested in how others code a similar problem, so if you will,
> go ahead & email it to me.
> 
> Actually I'm just concerned with fitting things onto the *screen* right now,
> but as soon as I get that working I will want
> to do the exact same thing for printer, also.
> 
> Dan

Done. Let me know if any includes are missing and I will send them to you.

Don Cole

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

7. Re: Win32Lib: any way to GET the font size?

Dan Moyer wrote:
> 
> don cole wrote:
> > 
> > Dan Moyer wrote:
> > > 
> > > don cole wrote:
> > > > 
> > > > 
> > > > Dan Moyer wrote:
> > > > > 
> > > > > Is there some way to get the font SIZE?  I don't mean the height or
> > > > > width
> </font></i>
> > > > > extents of CHARACTERS, I mean the value that would be used to SET the
> > > > > font
> > > > > to a particular size. 
> > > > > 
> > > > > I want to be able to center various text within columns, by changing
> > > > > the
> > > > > size of the font as needed, but that text could
> > > > > be in different sized fonts to begin with, so my routine needs to
> > > > > change
> > > > > the font size *from* whatever original size it was, so I need to be
> > > > > able
> to</font></i>
> > > > > *find out* what size it happens to be initially.
> > > > > 
> > > > > Dan Moyer
> > > > 
> > > > Hello Dan,
> > > > 
> > > > Try getFontDialog()
> > > > 
> > > > Don Cole
> > > 
> > > Don,
> > > 
> > > I'm not looking for a *dialog*, wherein a user *selects* a font/size,
> > > but rather a way for my *program* to ascertain what font size is currently
> > > in force for a window.  I want my program to GET the font size first, then
> > > it will decrement it as necessary, then return to original after using 
> > > smaller size as needed to fit space allotted.
> > > 
> > > Dan
> > 
> > Hello Dan,
> > 
> >   I was just reading from index.html the desciption of 
> > 
> >    getFontDialog ( window )
> > 
> >    that says 
> > 
> >    Returns: { font name, points, style flags, color } or -1 if cancelled.
> > 
> >   I have never used this. However I have a program that I think does what
> >   you
> > want. It starts out with a randon (large) font size. Then it keeps reducing
> > it until all the columns fit on the paper. This print preview program is
> > lengthy
> > and I have never posted it in the archives. If you are interested I coulde
> > e-mail
> > it to you.
> > 
> > Don Cole
> 
> Don,
> 
> Thanks, I can do it myself once I know the font size (which I'll work around
> by making sure that I keep track of it whenever it gets changed), but I'm
> always interested in how others code a similar problem, so if you will,
> go ahead & email it to me.
> 
> Actually I'm just concerned with fitting things onto the *screen* right now,
> but as soon as I get that working I will want
> to do the exact same thing for printer, also.
> 
> Dan

The following appears to work. It reverses what convPointsToLogical() does.

include win32lib.ew
constant
   Err_ECFSAVEDCFAIL = {"ezCreateFont:SaveDC failed.", 491},
   Err_ECFRESTOREDC = {"ezCreateFont:RestoreDC failed.", 486},
xGetCurrentObject=registerw32Function(gdi32,"GetCurrentObject",{C_POINTER,C_LONG},C_POINTER),
xLPtoDP=registerw32Function(gdi32,"LPtoDP",{C_POINTER,C_POINTER,C_LONG},C_LONG)

global function getFontPointSize(object pDC)
    integer pointSize
    atom lDC
    atom lSavedDC,currentFont
    atom lDpiY
    atom lPoint,logFont

    -- save the current device context because I'm about to
    -- possibly mess it up.

    if atom(pDC) then
        -- Then a control ID was passed
        lDC = getDC(pDC)
    elsif length(pDC)>1 then
        -- Then a raw window handle is at position 1
        lDC=w32Func(xGetDC,{pDC[1]})
    else
        -- Else a real dc was passed
        lDC = pDC[1]
    end if

    lSavedDC = w32Func( xSaveDC, {lDC} )
    if lSavedDC = 0 then
        abortErr( Err_ECFSAVEDCFAIL )
    end if

    -- these are NT specific. they should have no effect in Win95
    VOID = w32Func( xSetGraphicsMode, {lDC, GM_ADVANCED} )
    VOID = w32Func( xModifyWorldTransform, {lDC, NULL, MWT_IDENTITY} )

    VOID = w32Func( xSetViewportOrgEx, {lDC, 0, 0, NULL} )
    VOID = w32Func( xSetWindowOrgEx,   {lDC, 0, 0, NULL} )

    lDpiY = w32Func( xGetDeviceCaps, {lDC, LOGPIXELSY} )

    -- w32allot
    lPoint = w32acquire_mem( 0, SIZEOF_POINT )
    currentFont = w32Func(xGetCurrentObject,{lDC,6}) -- OBJ_FONT
    logFont = w32acquire_mem(0,SIZEOF_LOGFONT)
    VOID = w32Func(xGetObject,{currentFont,SIZEOF_LOGFONT,logFont})
    w32store( lPoint,ptY, peek4u(logFont))
    VOID = w32Func( xLPtoDP, {lDC, lPoint, 1} )
    pointSize = w32fetch( lPoint,ptY )
    w32release_mem(lPoint)
    w32release_mem(logFont)
    pointSize = floor(pointSize*(72.0/lDpiY)+0.5)

    -- restore the device context
    if not w32Func( xRestoreDC, {lDC, lSavedDC} ) then
        abortErr( Err_ECFRESTOREDC )
    end if

    if atom(pDC) then
        releaseDC( pDC )
    end if

    return pointSize

end function

constant w=create(Window,"taaaa",0,50,50,50,50,0)
procedure p(integer id,integer event,sequence data)
?getFontPointSize(w)
end procedure -- prints 12 here, and the floor() isn't really needed

setHandler(w,w32HActivate,routine_id("p"))

WinMain(w,Normal)


CChris

PS: you can avoid calling GetCurrentObject() by sending the control the
 WM_GETFONT message. However, if you only have a DC, you'll have to retrieve
 the control handle using WindowFromDC().

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

8. Re: Win32Lib: any way to GET the font size?

CChris wrote:
> 
> Dan Moyer wrote:
> > 
> > don cole wrote:
> > > 
> > > Dan Moyer wrote:
> > > > 
> > > > don cole wrote:
> > > > > 
> > > > > 
> > > > > Dan Moyer wrote:
> > > > > > 
> > > > > > Is there some way to get the font SIZE?  > > 

<<<<snip>>>>

> > Dan
> 
> The following appears to work. It reverses what convPointsToLogical() does.
> 
> }}}
<eucode>
> include win32lib.ew
> constant
>    Err_ECFSAVEDCFAIL = {"ezCreateFont:SaveDC failed.", 491},
>    Err_ECFRESTOREDC = {"ezCreateFont:RestoreDC failed.", 486},
>   
>    xGetCurrentObject=registerw32Function(gdi32,"GetCurrentObject",{C_POINTER,C_LONG},C_POINTER),
>   
>    xLPtoDP=registerw32Function(gdi32,"LPtoDP",{C_POINTER,C_POINTER,C_LONG},C_LONG)
> 
> global function getFontPointSize(object pDC)
>     integer pointSize
>     atom lDC
>     atom lSavedDC,currentFont
>     atom lDpiY
>     atom lPoint,logFont
> 
>     -- save the current device context because I'm about to
>     -- possibly mess it up.
> 
>     if atom(pDC) then
>         -- Then a control ID was passed
>         lDC = getDC(pDC)
>     elsif length(pDC)>1 then
>         -- Then a raw window handle is at position 1
>         lDC=w32Func(xGetDC,{pDC[1]})
>     else
>         -- Else a real dc was passed
>         lDC = pDC[1]
>     end if
> 
>     lSavedDC = w32Func( xSaveDC, {lDC} )
>     if lSavedDC = 0 then
>         abortErr( Err_ECFSAVEDCFAIL )
>     end if
> 
>     -- these are NT specific. they should have no effect in Win95
>     VOID = w32Func( xSetGraphicsMode, {lDC, GM_ADVANCED} )
>     VOID = w32Func( xModifyWorldTransform, {lDC, NULL, MWT_IDENTITY} )
> 
>     VOID = w32Func( xSetViewportOrgEx, {lDC, 0, 0, NULL} )
>     VOID = w32Func( xSetWindowOrgEx,   {lDC, 0, 0, NULL} )
> 
>     lDpiY = w32Func( xGetDeviceCaps, {lDC, LOGPIXELSY} )
> 
>     -- w32allot
>     lPoint = w32acquire_mem( 0, SIZEOF_POINT )
>     currentFont = w32Func(xGetCurrentObject,{lDC,6}) -- OBJ_FONT
>     logFont = w32acquire_mem(0,SIZEOF_LOGFONT)
>     VOID = w32Func(xGetObject,{currentFont,SIZEOF_LOGFONT,logFont})
>     w32store( lPoint,ptY, peek4u(logFont))
>     VOID = w32Func( xLPtoDP, {lDC, lPoint, 1} )
>     pointSize = w32fetch( lPoint,ptY )
>     w32release_mem(lPoint)
>     w32release_mem(logFont)
>     pointSize = floor(pointSize*(72.0/lDpiY)+0.5)
> 
>     -- restore the device context
>     if not w32Func( xRestoreDC, {lDC, lSavedDC} ) then
>         abortErr( Err_ECFRESTOREDC )
>     end if
> 
>     if atom(pDC) then
>         releaseDC( pDC )
>     end if
> 
>     return pointSize
> 
> end function
> 
> constant w=create(Window,"taaaa",0,50,50,50,50,0)
> procedure p(integer id,integer event,sequence data)
> ?getFontPointSize(w)
> end procedure -- prints 12 here, and the floor() isn't really needed
> 
> setHandler(w,w32HActivate,routine_id("p"))
> 
> WinMain(w,Normal)
> </eucode>
{{{

> 
> CChris
> 
> PS: you can avoid calling GetCurrentObject() by sending the control the
>  WM_GETFONT message. However, if you only have a DC, you'll have to retrieve
>  the control handle using WindowFromDC().

Thanks CChris!  Looks like something that might be good to add to Win32Lib?
If only for symmetry?

Right now I'm working on keeping better track of what the font size is
(and changes to) during app use, so I can just use that value as needed,
but if that becomes too tedious, I'll just use your routine instead! :)

Dan

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

Search



Quick Links

User menu

Not signed in.

Misc Menu