How to set default printer font 
Author Message
 How to set default printer font

I am trying to set a default printer font of 12 points. I just tried to use the
following:

    m_fontPrint.CreatePointFont(120, _T("Times New Roman"));

but when I use the following code to allow the user to choose a different font,
then the font in the dialog box shows up with a point size of 2.

////////////////////////////////////////////////////////////////////////
void
CRaceApp::OnFileChooseFont()
{
    LOGFONT lf;

    m_fontPrint.GetObject(sizeof lf, &lf);

    CPrintDialog dlgPrint(FALSE);
    if(!AfxGetApp()->GetPrinterDeviceDefaults(&dlgPrint.m_pd)) {
        AfxMessageBox(_T("Cannot get printer device defaults"));
        return;
    }
    HDC hdcPrint = dlgPrint.CreatePrinterDC();
    if(hdcPrint == NULL) {
        AfxMessageBox(_T("Cannot get printer device context"));
        return;
    }
    CDC dcScreen;
    dcScreen.Attach(::GetDC(NULL));
    CDC dcPrint;
    dcPrint.Attach(hdcPrint);

    // need to map from initial log font to screen metrics
    ::ScaleLogFont(&lf, &dcPrint, &dcScreen);

    // now bring up the dialog since we know the printer DC
    CFontDialog dlg(&lf, CF_PRINTERFONTS, &dcPrint);
    if(dlg.DoModal() == IDOK) {
        // map the resulting font back to printer metrics
        ::ScaleLogFont(&lf, &dcScreen, &dcPrint);

        m_fontPrint.DeleteObject();
        m_fontPrint.CreateFontIndirect(&lf);
    }
    // note destructor will call dcPrint.DeleteDC
    ::ReleaseDC(NULL, dcScreen.Detach());

Quote:
}

On stepping through the CreatePointFont(...), it appears that it gets the screen
device context (from hDC = ::GetDC(NULL); in CreatePointFontIndirect(...)) and
when it finally gets round to calling CreateFontIndirect(...) the iHeight has
been reduced to 20!

I had previously used the following to create the font on startup:

    m_fontPrint.CreateFont(-100, 0, 0, 0, FW_NORMAL
     , 0, 0, 0, DEFAULT_CHARSET, OUT_CHARACTER_PRECIS
     , CLIP_CHARACTER_PRECIS, DEFAULT_QUALITY
     , DEFAULT_PITCH | FF_DONTCARE, "Times New Roman");

and that had shown up in the above CFontDialog as 12 point as desired. The
problem that I was trying to solve was that a user with a different printer was
seeing a default point size of 20 so I was trying to make the point size
independent of the default printer installed on the machine.

Maybe I am being too complicated in the OnFileChooseFont(...) routine. Is there
a simple way to set a default value of font height of 12 point on any printer
and then allow the user to change this interactively prior to any printing that
they may do, again on any printer?

Ed
--

Pharsight Corporation           | Voice:  (978)369-1061
4 South Meadow Ridge            | Fax:    (978)371-1961
Concord, MA 01742               | Web:    www.pharsight.com



Mon, 19 May 2003 03:00:00 GMT  
 How to set default printer font
Try not scaling the font. CFontDialog expects it at the screen resolution.
The printer dc is only used to enumerate printer fonts.


Quote:
> I am trying to set a default printer font of 12 points. I just tried to
use the
> following:

>     m_fontPrint.CreatePointFont(120, _T("Times New Roman"));

> but when I use the following code to allow the user to choose a different
font,
> then the font in the dialog box shows up with a point size of 2.

> ////////////////////////////////////////////////////////////////////////
> void
> CRaceApp::OnFileChooseFont()
> {
>     LOGFONT lf;

>     m_fontPrint.GetObject(sizeof lf, &lf);

>     CPrintDialog dlgPrint(FALSE);
>     if(!AfxGetApp()->GetPrinterDeviceDefaults(&dlgPrint.m_pd)) {
>         AfxMessageBox(_T("Cannot get printer device defaults"));
>         return;
>     }
>     HDC hdcPrint = dlgPrint.CreatePrinterDC();
>     if(hdcPrint == NULL) {
>         AfxMessageBox(_T("Cannot get printer device context"));
>         return;
>     }
>     CDC dcScreen;
>     dcScreen.Attach(::GetDC(NULL));
>     CDC dcPrint;
>     dcPrint.Attach(hdcPrint);

>     // need to map from initial log font to screen metrics
>     ::ScaleLogFont(&lf, &dcPrint, &dcScreen);

>     // now bring up the dialog since we know the printer DC
>     CFontDialog dlg(&lf, CF_PRINTERFONTS, &dcPrint);
>     if(dlg.DoModal() == IDOK) {
>         // map the resulting font back to printer metrics
>         ::ScaleLogFont(&lf, &dcScreen, &dcPrint);

>         m_fontPrint.DeleteObject();
>         m_fontPrint.CreateFontIndirect(&lf);
>     }
>     // note destructor will call dcPrint.DeleteDC
>     ::ReleaseDC(NULL, dcScreen.Detach());
> }

> On stepping through the CreatePointFont(...), it appears that it gets the
screen
> device context (from hDC = ::GetDC(NULL); in CreatePointFontIndirect(...))
and
> when it finally gets round to calling CreateFontIndirect(...) the iHeight
has
> been reduced to 20!

> I had previously used the following to create the font on startup:

>     m_fontPrint.CreateFont(-100, 0, 0, 0, FW_NORMAL
>      , 0, 0, 0, DEFAULT_CHARSET, OUT_CHARACTER_PRECIS
>      , CLIP_CHARACTER_PRECIS, DEFAULT_QUALITY
>      , DEFAULT_PITCH | FF_DONTCARE, "Times New Roman");

> and that had shown up in the above CFontDialog as 12 point as desired. The
> problem that I was trying to solve was that a user with a different
printer was
> seeing a default point size of 20 so I was trying to make the point size
> independent of the default printer installed on the machine.

> Maybe I am being too complicated in the OnFileChooseFont(...) routine. Is
there
> a simple way to set a default value of font height of 12 point on any
printer
> and then allow the user to change this interactively prior to any printing
that
> they may do, again on any printer?

> Ed
> --

> Pharsight Corporation           | Voice:  (978)369-1061
> 4 South Meadow Ridge            | Fax:    (978)371-1961
> Concord, MA 01742               | Web:    www.pharsight.com



Mon, 19 May 2003 03:00:00 GMT  
 How to set default printer font
I removed both the scalings:

    // need to map from initial log font to screen metrics
    ::ScaleLogFont(&lf, &dcPrint, &dcScreen);
...
        // map the resulting font back to printer metrics
        ::ScaleLogFont(&lf, &dcScreen, &dcPrint);

I first off tried just using the CFontDialog without the &dcPrint as the third
argument but I there was a runtime warning that said that I didn't have any
fonts installed on the system and no dialog box! Then I removed the
CF_PRINTERFONTS from the CFontDialog so that I just had:

        CFontDialog dlg(&lf)

the font showed up in the dialog box as 12 point, but when I went to print it,
there were about 100 lines in about just over three inches - about 2 points per
line.

After more experimentation, it appears that if the LOGFONT.lfHeight member of
the LOGFONT struct is 100 when it is used by CFontDialog, then the font reported
in the dialog box is 60.  If it's 20, then the font is 12.  Unfortunately, when
we get to print with an lfHeight of 20, then the font turns out to be 2.

If the lf.lfHeight member is 100, then the print is at 12 point as desired. The
code in my View::OnBeginPrinting(...) is as follows:

void
CRaceView::OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo)
{
    LOGFONT lf;

    // pick up the user choice for the font to print with
    theApp.GetCurrentFont(&lf);

    // make a copy into this class
    int ret = m_fontPrint.CreateFontIndirect(&lf);
    if(!ret) {
        throw(CRaceErr(CRaceErr::RE_BADERROR
         , _T("Unable to create font %s"), lf.lfFaceName));
    }
    CFont* pFontOld = pDC->SelectObject(&m_fontPrint);
    ...

and I use the pDC for printing from here on.

When I step through the original code applying the scale factors, the first
scale of:

    // need to map from initial log font to screen metrics
    ::ScaleLogFont(&lf, &dcPrint, &dcScreen);

changes lf.lfHeight from -100 to -20 which then shows up in the CFontDialog as
12 point. On exit the returning scaling of:

        // map the resulting font back to printer metrics
        ::ScaleLogFont(&lf, &dcScreen, &dcPrint);

returns the lf.lfHeight from -20 to -100 and the printer actually prints at 12
point.

My problem is making this bullet proof. It works fine on my machine with the
scaling but a user has reported that the default font chosen on their machine is
20 but I don't know what the lf.lfHeight would be on their system.

Ed

Quote:

> Try not scaling the font. CFontDialog expects it at the screen resolution.
> The printer dc is only used to enumerate printer fonts.



> > I am trying to set a default printer font of 12 points. I just tried to
> use the
> > following:

> >     m_fontPrint.CreatePointFont(120, _T("Times New Roman"));

> > but when I use the following code to allow the user to choose a different
> font,
> > then the font in the dialog box shows up with a point size of 2.

> > ////////////////////////////////////////////////////////////////////////
> > void
> > CRaceApp::OnFileChooseFont()
> > {
> >     LOGFONT lf;

> >     m_fontPrint.GetObject(sizeof lf, &lf);

> >     CPrintDialog dlgPrint(FALSE);
> >     if(!AfxGetApp()->GetPrinterDeviceDefaults(&dlgPrint.m_pd)) {
> >         AfxMessageBox(_T("Cannot get printer device defaults"));
> >         return;
> >     }
> >     HDC hdcPrint = dlgPrint.CreatePrinterDC();
> >     if(hdcPrint == NULL) {
> >         AfxMessageBox(_T("Cannot get printer device context"));
> >         return;
> >     }
> >     CDC dcScreen;
> >     dcScreen.Attach(::GetDC(NULL));
> >     CDC dcPrint;
> >     dcPrint.Attach(hdcPrint);

> >     // need to map from initial log font to screen metrics
> >     ::ScaleLogFont(&lf, &dcPrint, &dcScreen);

> >     // now bring up the dialog since we know the printer DC
> >     CFontDialog dlg(&lf, CF_PRINTERFONTS, &dcPrint);
> >     if(dlg.DoModal() == IDOK) {
> >         // map the resulting font back to printer metrics
> >         ::ScaleLogFont(&lf, &dcScreen, &dcPrint);

> >         m_fontPrint.DeleteObject();
> >         m_fontPrint.CreateFontIndirect(&lf);
> >     }
> >     // note destructor will call dcPrint.DeleteDC
> >     ::ReleaseDC(NULL, dcScreen.Detach());
> > }

> > On stepping through the CreatePointFont(...), it appears that it gets the
> screen
> > device context (from hDC = ::GetDC(NULL); in CreatePointFontIndirect(...))
> and
> > when it finally gets round to calling CreateFontIndirect(...) the iHeight
> has
> > been reduced to 20!

> > I had previously used the following to create the font on startup:

> >     m_fontPrint.CreateFont(-100, 0, 0, 0, FW_NORMAL
> >      , 0, 0, 0, DEFAULT_CHARSET, OUT_CHARACTER_PRECIS
> >      , CLIP_CHARACTER_PRECIS, DEFAULT_QUALITY
> >      , DEFAULT_PITCH | FF_DONTCARE, "Times New Roman");

> > and that had shown up in the above CFontDialog as 12 point as desired. The
> > problem that I was trying to solve was that a user with a different
> printer was
> > seeing a default point size of 20 so I was trying to make the point size
> > independent of the default printer installed on the machine.

> > Maybe I am being too complicated in the OnFileChooseFont(...) routine. Is
> there
> > a simple way to set a default value of font height of 12 point on any
> printer
> > and then allow the user to change this interactively prior to any printing
> that
> > they may do, again on any printer?

> > Ed
> > --

> > Pharsight Corporation           | Voice:  (978)369-1061
> > 4 South Meadow Ridge            | Fax:    (978)371-1961
> > Concord, MA 01742               | Web:    www.pharsight.com

--

Pharsight Corporation           | Voice:  (978)369-1061
4 South Meadow Ridge            | Fax:    (978)371-1961
Concord, MA 01742               | Web:    www.pharsight.com


Tue, 20 May 2003 03:00:00 GMT  
 How to set default printer font
Try adding the printer DC to your call to CreatePointFont. I'm thinking
that code like this might initialize the font to match the printer:

        CPrintDialog prtdlg(TRUE);
        prtdlg.GetDefaults();
        HDC hdc = prtdlg.CreatePrinterDC();
        m_fontPrint.CreatePointFont(120, _T("Times New Roman"),
CDC::FromHandle(hdc));

You appear to have  a call to a function ScaleLogFont that rescales for the
screen and back for the font dialog display. I don't know what that
function is or what it does, but as long as that function doesn't affect
the printer scaling, this may be worth a try. Without the printer dc, the
font is calculated using a screen device.



Sat, 24 May 2003 08:55:24 GMT  
 How to set default printer font
I created the font in my MDI app constructor using the suggested code as
follows:

    CPrintDialog prtdlg(TRUE);
    prtdlg.GetDefaults();
    HDC hDC = prtdlg.CreatePrinterDC();

    m_fontPrint.CreatePointFont(120, _T("Times New Roman")
     , CDC::FromHandle(hDC));

the LOGFONT within the m_fontPrint (a CFont) has lfHeight as -100 which is what
I would expect for the printer font. (Without the printer DC in the above call
to CreatePointFont(...), the lfHeight comes out as -20).

The problem comes when I go to the OnChooseFont message handler where the user
should see as the starting off font a 12 point Times Roman. In fact if the
lfHeight is -100, the font is presented as being 60 point. The font dialog is
invoked as so:

    // now bring up the dialog since we know the printer DC
    CFontDialog dlg(&lf, CF_PRINTERFONTS, &dcPrint);

If I leave off the third argument for the printer DC, I get a message saying
that "There are no fonts installed\nOpen the Fonts folder from tbe Control Panel
to install fonts."

If I put the scale in prior to the font dialog as:

    // need to map from initial log font to screen metrics
    ::ScaleLogFont(&lf, &dcPrint, &dcScreen);

this changes the lfHeight to -20 and the font starts off at 12 point in the font
dialog box. However, if I leave the height at -20, then when I come to print it
shows up at 2 points. That's why I put the inverse scale in after the font
dialog to hopefully get it back to printer units (and a value of 100). This was
done by:

        // map the resulting font back to printer metrics
        ::ScaleLogFont(&lf, &dcScreen, &dcPrint);
        m_fontPrint.DeleteObject();
        m_fontPrint.CreateFontIndirect(&lf);

In summary, it seems as if an lfHeight of -100 going in to CFontDialog shows up
as a font of 60. If I choose 12 point then it is changed to -20 on exit.

When I come to print, my OnBeginPrinting looks like:

void
CRaceView::OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo)
{
    LOGFONT lf;
    // pick up the user choice for the font to print with
    theApp.GetCurrentFont(&lf);
    // make a copy into this class
    int ret = m_fontPrint.CreateFontIndirect(&lf);
    if(!ret) { ... }
    CFont* pFontOld = pDC->SelectObject(&m_fontPrint);

If the lfHeight of the lf struct is -20 at this point, when I print using the
pDC, I see an actual print height of 2 point. If it's -100, it comes out as I
want as 12 point.

Again I can make it work on my machine by doing the appropriate scaling. On a
user machine this morning though, the default font in the CFontDialog showed up
as 26 point. I didn't check the OS but their monitor was being run in 800x600
mode. My monitor is 1280x1024 so there could be a difference in scaling to
screen pixels though how 12 gets changed to 26 I don't know.

Ed

Quote:

> Try adding the printer DC to your call to CreatePointFont. I'm thinking
> that code like this might initialize the font to match the printer:

>         CPrintDialog prtdlg(TRUE);
>         prtdlg.GetDefaults();
>         HDC hdc = prtdlg.CreatePrinterDC();
>         m_fontPrint.CreatePointFont(120, _T("Times New Roman"),
> CDC::FromHandle(hdc));

> You appear to have  a call to a function ScaleLogFont that rescales for the
> screen and back for the font dialog display. I don't know what that
> function is or what it does, but as long as that function doesn't affect
> the printer scaling, this may be worth a try. Without the printer dc, the
> font is calculated using a screen device.

--

Pharsight Corporation           | Voice:  (978)369-1061
4 South Meadow Ridge            | Fax:    (978)371-1961
Concord, MA 01742               | Web:    www.pharsight.com


Sat, 24 May 2003 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Windows Default Printers and Default Printer Setups

2. CView:draw cause default font size for different printer

3. CView:draw cause default font size for different printer

4. Set Default Printer

5. Set default printer

6. how to Set Default Printer

7. Q: How to set default printer bin?

8. Problems Setting the Default printer with Win32 API SDK

9. Help : How to set the default printer

10. Setting the Default Printer

11. how to Set Default Printer

12. Setting default printer via DEVMODE struct and EnumPrinters

 

 
Powered by phpBB® Forum Software