Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Text Draw problem with Print Preview

Text Draw problem with Print Preview

Scheduled Pinned Locked Moved C / C++ / MFC
helpcsharpvisual-studioquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Anik33
    wrote on last edited by
    #1

    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?

    H 1 Reply Last reply
    0
    • A Anik33

      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?

      H Offline
      H Offline
      Hamid Taebi
      wrote on last edited by
      #2

      Does this[^] helpful?

      A 1 Reply Last reply
      0
      • H Hamid Taebi

        Does this[^] helpful?

        A Offline
        A Offline
        Anik33
        wrote on last edited by
        #3

        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.

        R 1 Reply Last reply
        0
        • A Anik33

          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.

          R Offline
          R Offline
          Roger Allen
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups