Text Draw problem with Print Preview
-
I am using Visual Studio 6.0. Print preview changes text width on different zoom view. Let me describe in details.(Tested in an SDI application) I want to draw a text "Sample text1 Sample text1 Sample text1" whose font size is 10 and face is Arial.Just below this text I want to draw another text "Sample text2 Sample text2" whose font size is 15 and face is Comic Sans MS. Both are aligned LEFT or RIGHT.It draws fine. Now when I want to see the print preview it shows different text width than what was drawn previously. Now after zoom in again the view changes. In a word I dont get actual print preview. Can you help me plz?
-
I am using Visual Studio 6.0. Print preview changes text width on different zoom view. Let me describe in details.(Tested in an SDI application) I want to draw a text "Sample text1 Sample text1 Sample text1" whose font size is 10 and face is Arial.Just below this text I want to draw another text "Sample text2 Sample text2" whose font size is 15 and face is Comic Sans MS. Both are aligned LEFT or RIGHT.It draws fine. Now when I want to see the print preview it shows different text width than what was drawn previously. Now after zoom in again the view changes. In a word I dont get actual print preview. Can you help me plz?
-
Not Solved Yet. Just Create an SDI Application and insert the following codes in OnDraw()
CRect rcPos = CRect(10,10,500,40); CFont font; LOGFONT lf; ZeroMemory(&lf,sizeof(lf)); lf.lfHeight = 25; lstrcpy(lf.lfFaceName,"Arial"); lf.lfWeight = FW_BOLD; lf.lfCharSet = DEFAULT_CHARSET; font.CreateFontIndirect(&lf); pDC->SelectObject(&font); CString str = "Sample Text1 Sample Text1 Sample Text1"; pDC->DrawText(str, &rcPos, DT_LEFT|DT_VCENTER|DT_SINGLELINE); font.DeleteObject(); rcPos.top += 30; rcPos.bottom += 30; lf.lfHeight = 30; lstrcpy(lf.lfFaceName,"Comic Sans MS"); font.CreateFontIndirect(&lf); pDC->SelectObject(&font); str = "Sample Text2 Sample Text2"; pDC->DrawText(str, &rcPos, DT_LEFT|DT_VCENTER|DT_SINGLELINE); font.DeleteObject();
and insert following code to OnPrepareDC()pDC->SetMapMode(MM_ANISOTROPIC); CSize sizeDoc = CSize(1000,1000); pDC->SetWindowExt(sizeDoc); CDC dcScreen; dcScreen.CreateCompatibleDC(0); int nLogPixelX = dcScreen.GetDeviceCaps(LOGPIXELSX); int nLogPixelY = dcScreen.GetDeviceCaps(LOGPIXELSY); int nDevPixelX = pDC->GetDeviceCaps(LOGPIXELSX); int nDevPixelY = pDC->GetDeviceCaps(LOGPIXELSY); if (nLogPixelX != nDevPixelX || nLogPixelY != nDevPixelY) { sizeDoc.cx = (sizeDoc.cx * nDevPixelX) / nLogPixelX; sizeDoc.cy = (sizeDoc.cy * nDevPixelY) / nLogPixelY; } pDC->SetViewportExt(sizeDoc);
Now run the exe. and see print preview. -
Not Solved Yet. Just Create an SDI Application and insert the following codes in OnDraw()
CRect rcPos = CRect(10,10,500,40); CFont font; LOGFONT lf; ZeroMemory(&lf,sizeof(lf)); lf.lfHeight = 25; lstrcpy(lf.lfFaceName,"Arial"); lf.lfWeight = FW_BOLD; lf.lfCharSet = DEFAULT_CHARSET; font.CreateFontIndirect(&lf); pDC->SelectObject(&font); CString str = "Sample Text1 Sample Text1 Sample Text1"; pDC->DrawText(str, &rcPos, DT_LEFT|DT_VCENTER|DT_SINGLELINE); font.DeleteObject(); rcPos.top += 30; rcPos.bottom += 30; lf.lfHeight = 30; lstrcpy(lf.lfFaceName,"Comic Sans MS"); font.CreateFontIndirect(&lf); pDC->SelectObject(&font); str = "Sample Text2 Sample Text2"; pDC->DrawText(str, &rcPos, DT_LEFT|DT_VCENTER|DT_SINGLELINE); font.DeleteObject();
and insert following code to OnPrepareDC()pDC->SetMapMode(MM_ANISOTROPIC); CSize sizeDoc = CSize(1000,1000); pDC->SetWindowExt(sizeDoc); CDC dcScreen; dcScreen.CreateCompatibleDC(0); int nLogPixelX = dcScreen.GetDeviceCaps(LOGPIXELSX); int nLogPixelY = dcScreen.GetDeviceCaps(LOGPIXELSY); int nDevPixelX = pDC->GetDeviceCaps(LOGPIXELSX); int nDevPixelY = pDC->GetDeviceCaps(LOGPIXELSY); if (nLogPixelX != nDevPixelX || nLogPixelY != nDevPixelY) { sizeDoc.cx = (sizeDoc.cx * nDevPixelX) / nLogPixelX; sizeDoc.cy = (sizeDoc.cy * nDevPixelY) / nLogPixelY; } pDC->SetViewportExt(sizeDoc);
Now run the exe. and see print preview.Its not an issue with your code, its an issue with the way print preview is implemented itself. As the screen metrics (resolution/ dpi etc) may/are not an exact match to the target print device, especially when zooming in on the content, print preview has to do an estimation when converting from the requested font size of the target DC to the screen dpi/zoom metric DC used to display the preview. This causes the generated font size to vary slightly at various zoom levels. To see this when you select a font into a CPreviewDC you should see that is does a lot of extra work converting the font from the outputDC to the previewDC format, its at thispoint that the scaling issues occur.
If you vote me down, my score will only get lower