Set font size in CFontDialog 
Author Message
 Set font size in CFontDialog

Quote:
>I used LOGFONT to initialize CFontDialog control settings.  I tried to
>assign a certain number to the font size control, but was unable to assign a
>fixed number, such as 11, that I desired.  In LOGFONT, the lfHeight  member
>uses logical unit, while the CFontDialog returns size in point.  I could not
>always set the desired point value from a corresponding lfHeight.  Some size
>values would simply be off by 1 point.

Richard,

Here's an example of how I use it:

#define PointSizeToPixel(Point, DPI) (-MulDiv( Point, DPI, 72 ) )

        LOGFONT lf;

        // lf get's initialised with the last settings

        CFontDialog dlg;

        dlg.m_cf.lpLogFont = &lf;
        dlg.m_cf.nSizeMin = 4;
        dlg.m_cf.nSizeMax = 16;
        dlg.m_cf.Flags |= CF_PRINTERFONTS | CF_FORCEFONTEXIST |
                        CF_LIMITSIZE | CF_INITTOLOGFONTSTRUCT;

        {
                /* Convert the point size to pixels */
                /***** The LOGFONT height used here uses the screen
DPI rather than the printers ****/
                HDC hDispDC = ::GetDC( m_hWnd );

                lf.lfHeight = PointSizeToPixel( lf.lfHeight,
                        GetDeviceCaps( hDispDC, LOGPIXELSY ) ) / 10;

                ::ReleaseDC( m_hWnd, hDispDC );
        }

        if ( dlg.DoModal() == IDOK )
        {
                /* Save the lfHeight in tenths of a point rather than
in pixels specific to a device */
                lf.lfHeight = dlg.m_cf.iPointSize;
        }

Dave
--
MVP VC++ FAQ: http://www.*-*-*.com/
My address is altered to discourage junk mail.
Please post responses to the newsgroup thread,
there's no need for follow-up email copies.



Tue, 10 Dec 2002 03:00:00 GMT  
 Set font size in CFontDialog
David,

Thanks for the example code.  They helped solve my problem.  I had used
brute-force calculation for the point-to-pixel transformation, which always
rounded DOWN to an integer.  MulDiv offered the possibility of rounding up
and solved the problem.

Thanks again for your help.

Richard L. Chen


Quote:
> >I used LOGFONT to initialize CFontDialog control settings.  I tried to
> >assign a certain number to the font size control, but was unable to
assign a
> >fixed number, such as 11, that I desired.  In LOGFONT, the lfHeight
member
> >uses logical unit, while the CFontDialog returns size in point.  I could
not
> >always set the desired point value from a corresponding lfHeight.  Some
size
> >values would simply be off by 1 point.

> Richard,

> Here's an example of how I use it:

> #define PointSizeToPixel(Point, DPI) (-MulDiv( Point, DPI, 72 ) )

> LOGFONT lf;

> // lf get's initialised with the last settings

> CFontDialog dlg;

> dlg.m_cf.lpLogFont = &lf;
> dlg.m_cf.nSizeMin = 4;
> dlg.m_cf.nSizeMax = 16;
> dlg.m_cf.Flags |= CF_PRINTERFONTS | CF_FORCEFONTEXIST |
> CF_LIMITSIZE | CF_INITTOLOGFONTSTRUCT;

> {
> /* Convert the point size to pixels */
> /***** The LOGFONT height used here uses the screen
> DPI rather than the printers ****/
> HDC hDispDC = ::GetDC( m_hWnd );

> lf.lfHeight = PointSizeToPixel( lf.lfHeight,
> GetDeviceCaps( hDispDC, LOGPIXELSY ) ) / 10;

> ::ReleaseDC( m_hWnd, hDispDC );
> }

> if ( dlg.DoModal() == IDOK )
> {
> /* Save the lfHeight in tenths of a point rather than
> in pixels specific to a device */
> lf.lfHeight = dlg.m_cf.iPointSize;
> }

> Dave
> --
> MVP VC++ FAQ: http://www.mvps.org/vcfaq
> My address is altered to discourage junk mail.
> Please post responses to the newsgroup thread,
> there's no need for follow-up email copies.



Wed, 11 Dec 2002 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Setting font size in CFontDialog

2. Set font size in CFontDialog

3. CRichEditCtrl & CFontDialog font sizes screwed up

4. CFontDialog sets initial font color to black

5. Setting font types/sizes in textboxes

6. setting font size

7. setting font size dynamically

8. CDC::TextOut() and setting font sizes

9. How do I set a control's font size

10. CRichEditCtrl - Setting Font Size/Type

11. Set Label/Static Text font size

12. Setting font size in CStatic ?

 

 
Powered by phpBB® Forum Software