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. TextExtent???

TextExtent???

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
3 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.
  • M Offline
    M Offline
    Manikandan
    wrote on last edited by
    #1

    I try to measure the dimension for a text say "Hello". I set mapping mode to MM_LOENGLISH. CFont font; font.CreatePointFont(360,"Verdana"); pDC->SelectObject(&font); CSize sz = pDC->GetTextExtent("Hello"); the width sz.cx (1.19 inch) seems ok in real printing. But sz.cy (0.57inch) is greater than the actual (0.344inch) in printout. Can anyone tell me how to calculate the real height???

    P L 2 Replies Last reply
    0
    • M Manikandan

      I try to measure the dimension for a text say "Hello". I set mapping mode to MM_LOENGLISH. CFont font; font.CreatePointFont(360,"Verdana"); pDC->SelectObject(&font); CSize sz = pDC->GetTextExtent("Hello"); the width sz.cx (1.19 inch) seems ok in real printing. But sz.cy (0.57inch) is greater than the actual (0.344inch) in printout. Can anyone tell me how to calculate the real height???

      P Offline
      P Offline
      Paul M Watt
      wrote on last edited by
      #2

      I believe that when windows calculates the height of characters it includes the height of the ascending and descending line of the font, not just the height of the character that you see. I am not 100% certain of this, but one way that you could test this is by calling getTextExtent on 5 different characters, and I believe the same height should come back for all of the characters.


      Build a man a fire, and he will be warm for a day
      Light a man on fire, and he will be warm for the rest of his life!

      1 Reply Last reply
      0
      • M Manikandan

        I try to measure the dimension for a text say "Hello". I set mapping mode to MM_LOENGLISH. CFont font; font.CreatePointFont(360,"Verdana"); pDC->SelectObject(&font); CSize sz = pDC->GetTextExtent("Hello"); the width sz.cx (1.19 inch) seems ok in real printing. But sz.cy (0.57inch) is greater than the actual (0.344inch) in printout. Can anyone tell me how to calculate the real height???

        L Offline
        L Offline
        l a u r e n
        wrote on last edited by
        #3

        look up the font metrics stuff in msdn there are all sorts of bits and pieces added together to get the bounding 'box' of text ... leading, ascenders, descenders, etc all fun stuff if you have nothing else to do ;P --- situations to avoid #37:
        "good morning ... how many sugars do you take in your coffee ... and what was your name again?"

        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