Click here to Skip to main content
15,921,062 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I have changed the maping mode as the code below is shown: to work with (1 logical unit = 1 millimeter)
void CGLVImpressionView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo)
{
    CView::OnPrepareDC(pDC, pInfo);
    // TODO: Add your specialized code here and/or call the base class
    pDC->SetMapMode(MM_ISOTROPIC);
    // Working with (1 logical unit = 1 mm) for both width & height of the device context.
    pDC->SetWindowExt(1, 1);
    pDC->SetViewportExt(pDC->GetDeviceCaps(HORZRES) / pDC->GetDeviceCaps(HORZSIZE),
                        pDC->GetDeviceCaps(VERTRES) / pDC->GetDeviceCaps(VERTSIZE));
    pDC->SetBkMode(TRANSPARENT);
    //CView::OnPrepareDC(pDC, pInfo);
}


and when I create a font like this:
void CGLVImpressionView::OnBeginPrinting(CDC* pDC, CPrintInfo* /*pInfo*/) 
{
	// TODO: Add your specialized code here and/or call the base class
	m_fnTimes12.CreatePointFont(120, _T("Times New Roman"), pDC);
	m_fnTimes14.CreatePointFont(140, _T("Times New Roman"), pDC);

        //CView::OnBeginPrinting(pDC, pInfo);
}


It will be drawn with a huge size :(
What am I doing wrong ?
Help me please.

This image may be useful:
http://img546.imageshack.us/img546/7144/dpiw.jpg
Posted
Updated 17-Mar-11 9:53am
v7

Your initialisation is wrong. The order of functions called:
1.) OnPreparePrinting
2.) OnBeginPrinting
3.) OnPrepareDC
4.) OnDraw
yous should create the fonts in OnPrepareDC function.
Regards.

[edit] your fonts are ceated for MM_TEXT but drawn with MM_ISOTROPIC.
 
Share this answer
 
v2
Comments
Mr. Tomay 20-Mar-11 6:11am    
Yes you are right, the order of printing functions is:
1.) OnPreparePrinting()
2.) OnBeginPrinting()
3.) OnPrepareDC()
4.) OnDraw() / OnPrint()
5.) OnEndPrinting()

But I just found the origin of my problem 1 day before your answer. Thanks anyway ;). I corrected this using this code:

void CGLVImpressionView::OnBeginPrinting(CDC* pDC, CPrintInfo* /*pInfo*/)
{
// TODO: Add your specialized code here and/or call the base class
pDC->SetMapMode(MM_ISOTROPIC);
// Working with (1 logical unit = 1 mm) for both width & height of the device context.
pDC->SetWindowExt(pDC->GetDeviceCaps(HORZSIZE), pDC->GetDeviceCaps(VERTSIZE));
pDC->SetViewportExt(pDC->GetDeviceCaps(HORZRES), pDC->GetDeviceCaps(VERTRES));

m_fnTimes12.CreatePointFont(120, _T("Times New Roman"), pDC);
m_fnTimes14.CreatePointFont(140, _T("Times New Roman"), pDC);

//CView::OnBeginPrinting(pDC, pInfo);
}


void CGLVImpressionView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo)
{
CView::OnPrepareDC(pDC, pInfo);
// TODO: Add your specialized code here and/or call the base class
pDC->SetMapMode(MM_ISOTROPIC);
// Working with (1 logical unit = 1 mm) for both width & height of the device context.
pDC->SetWindowExt(pDC->GetDeviceCaps(HORZSIZE), pDC->GetDeviceCaps(VERTSIZE));
pDC->SetViewportExt(pDC->GetDeviceCaps(HORZRES), pDC->GetDeviceCaps(VERTRES));

pDC->SetBkMode(TRANSPARENT);

//CView::OnPrepareDC(pDC, pInfo);
}
The mapping mode will probably affect the font size. Try to reset the mapping mode to normal just before drawing the text, then set it back to whatever you want.

Or you may just reduce your font size as a quick workaround...
 
Share this answer
 
v2
Comments
Mr. Tomay 17-Mar-11 13:40pm    
Not a bad idea, but it's not good for programming for your first idea.
For font sizes, it will not be exact (Just Estimated) for your second idea.
Olivier Levrey 18-Mar-11 4:27am    
I am not an expert in printing programming, I just tried to find a solution to your problem. If nobody else offers a solution, I am affraid you will have to cope with my "not good for programming" one...
I think your calculation may be incorrect. Looking at my printer I get the following values
HORZRES : 2892
HORZSIZE : 204

VERTRES : 4125
VERTSIZE : 291

Giving a ViewPort Extent of 14 x 14 so your characters will be scaled up by 14 times in each direction when rendered. You may find it easier just to leave the mapping at MM_TEXT which will correctly scale from Window to ViewPort when printing text.
 
Share this answer
 
Comments
Mr. Tomay 17-Mar-11 14:30pm    
14 here means 14 pixels per 1 millimeter
check this
Richard MacCutchan 17-Mar-11 14:41pm    
Try changing those values to a smaller number and see what happens. Also, as I said before, why not just stick with MM_TEXT?
Mr. Tomay 17-Mar-11 14:53pm    
I am not using MM_TEXT because I want to work with 1 millimeter as a logical unit to print an A4 paper, so my calculation will be exact.
All GDI drawing went as expected, except font drawings
Richard MacCutchan 18-Mar-11 10:10am    
Well, you can either take my advice, and switch to MM_TEXT when writing characters, or change your font creation. Instead of using
CreatePointFont() use CreateFont() which allows you to specify the font size in logical units rather than points.

And perhaps you would care to revise your 1-vote of my (valid and true) explanation of your problem.
Olivier Levrey 18-Mar-11 11:00am    
I agree. Have my 5. Op is distributing 1 to everybody...
Use 12 and 14 instead of 120 and 140 in createpointfont. May be this'll solve your problem
 
Share this answer
 
Comments
Olivier Levrey 17-Mar-11 8:20am    
This is an obvious and easy workaround. My 5.
Mr. Tomay 17-Mar-11 13:31pm    
CreatePointFont() creates a font in tenths of a point
check this
You're specifying a 120 and 140-point font height. No matter what mapping mode you use, the fonts are going to be huge.
 
Share this answer
 
Comments
Olivier Levrey 17-Mar-11 8:15am    
The size parameter of the CreatePointFont is in tenths of a point. Passing 120 will result as a 12-point font.
Mr. Tomay 17-Mar-11 13:34pm    
Oliver is right
try this code in your onpreparedc
MIDL
int dpi=pDC->GetDeviceCaps(LOGPIXELSX);
int dpmm=dpi/25; //dots per mm

pDC->SetMapMode(MM_ISOTROPIC);
pDC->SetWindowExt(1, 1);
pDC->SetViewportExt(dpmm,dpmm);
 
Share this answer
 
Comments
Mr. Tomay 18-Mar-11 18:46pm    
your calculations is exactly the same as mine, I've just did it in other way

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900