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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. WYSIWYG Printing

WYSIWYG Printing

Scheduled Pinned Locked Moved C / C++ / MFC
helpvisual-studiojsontutorialquestion
1 Posts 1 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.
  • L Offline
    L Offline
    Larry J Siddens
    wrote on last edited by
    #1

    As most of you know, I have been trying to do WYSIWYG printing from a CRichEditCtrl. The problems I was having was that the font bring printed was either too big or too small for the perscribed area. OK, here is some what of a solution (except it isn't bullet proof!) I create a device context to the display (while printing and in print preview), create the font scaled to the display and scaled to the printer. I then get the size of the line for each. I then calculate the scaling factor by getting the pixels in the X axis for both and dividing. For the printer here at work, it is 1200DPI, and the screen is 96DPI. This factor works out to be 12.5. I then take the text width on the screen and multiply it by this ratio to get an ideal output width. Divide the printer width by the ideal width that gives a ratio. I then get the average character width (from GetTextMetrics - Printer). I then multiply this value with the ration from the ideal vs. actual printer. Then set this value in the LOGFONT.lfWidth and create a new font and select it into the printer device context. As an example: The width of text on the display is 410 pixels, this same string on the printer (with no change in the character width) is 5352. The scaling factor of 12.5 means that the ideal lenght is 5112.5 pixels. The division of the Printer/Ideal = 1.066146. The average character width for the printer (with selected font) is 80 pixels. So, divide the 80 / 1.066... and the new character width is 75. I read in Petzold's book that the lfWidth of the LOGFONT can be set to the tmAvgCharWidth from the TEXTMETRIC structure. AND, that it can be scaled. The resulting output for the TIMES NEW ROMAN 12/10pt and COURIER NEW 12/10pt are right on (with the exception of a rounding error of a pixel). I do this for each line. Now the caveat! When I use Arial Normal, the last line which isn't as long as the rest, and this creates an average character width is bigger than the previous lines. I think there is something in the TrueType specification that can help with this. Does anyone know? If so, what? Larry J. Siddens Cornerstone Communications TAME THE DOCUMENT MONSTER www.unifier.biz

    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