TextExtent???
-
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???
-
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???
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! -
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???
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?"