CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Nov 2001
    Location
    Beyond Juslibol
    Posts
    1,688

    Text on screen and print preview

    Hi all, after so many years.

    I must take an old MFC project in VC++ 6.0 and make changes.

    The problem is text size in screen is different from size in print preview.

    for example with this font

    Code:
    CFont f50;
    f50.CreateFont(100,0,0,0,FW_BOLD,0,0,0,DEFAULT_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,FF_DONTCARE,"Frutiger LT Std 45 Light");
    And this text

    Code:
    s=_T("Let's try to calculate the size of this text");
    and with MM_LOMETRIC map mode

    GetTextExtent() returns me:

    On screen: (1595,99)
    Ink printer + print preview: (1589,100)
    PDFCreator + print preview: (1580,100)

    *** is happening here? comparing with screen size the height is bigger but lenght is smaller. I don't understand.

    I can understand that different printers process the fonts in different way and then to have different lenghts. That's not the problem. The problem is I need to simulate in screen the same behaviour i will have on printer because these texts are being aligned in the document, and I don't want to see that the text si aligned different in text than in paper.

    What can I do to render the text on screen with the same size I will have on the printer? Print preview is doing it. Should I change the font parameters? is something related with pixels per inch? I don't see it.

    can anybody help me?

  2. #2
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: Text on screen and print preview

    Try with MM_TWIPS. Besides GetTextExtent accuracy is quite low, you can try GetTextExtentPoint32 instead.
    Best regards,
    Igor

  3. #3
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: Text on screen and print preview

    Screen and printer are different DC's that behave differently because they have different DPI settings
    so your 10 'units' font in the screen DPI setting (which gets approximated to be 100 units in lometric) gets rounded up or down to a pixel size and the same happens on your printer which uses a slightly different setting.

    Additionally antialiassing or cleartype may result in a slightly wider font on screen than it will be when printed.

    If you really need WYSIWYG type approach, then you need to draw onto a bitmap uwing the printer DC, then convert/scale this bitmap to the screen. This will get you the WYSIWYG as far as scaling and relative sizes is concerned, but it will have an impact on the clarity and readability on screen. This can't really be helped, even the best screens have a much much coarser resolution than "cheap" printers.

  4. #4
    Join Date
    Nov 2001
    Location
    Beyond Juslibol
    Posts
    1,688

    Re: Text on screen and print preview

    Thank you for your answers.

    This is what I did. If I am printing I do nothing. If I am not printing I retrieve a (default) printer DC and then I attach its attrib DC to the attrib DC of the screen DC. This way I am obtaining the same metrics. Hope I am doing correctly and safe, I don't want to cause a breach in continuum space time or so.

    Anyway I'll investigate the TWIPS metrics. I also need to create a zoomig system since the two step MFC preview zoom is not enough, so I must see how good this behaves with scaling parameters, or doing something with bitmaps instead, as sugested by OReubens.

    Thank you.

  5. #5
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: Text on screen and print preview

    FYI, MM_TWIPS (as well as any other hi metric modes) is intended to be used with physical devices (printers first of all), and device vendors take special care about being compliant with the mode(s). Which point I doubt of when it is about freeware virtual printers like PDFCreator.
    Last edited by Igor Vartanov; February 4th, 2013 at 08:48 AM.
    Best regards,
    Igor

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured