|
-
February 11th, 2005, 11:36 AM
#1
Getting Font Dimensions
Hello. I'm wondering if there is a way to get the dimensions (height, width) of a specific character or string using a certain windows font.
So is there any way I can find out this information if I have a font name ie) Arial, and a CString ? I basically just need the ratio of the string height to the width.
I don't want to draw the text, just need this height to width ratio. Either for each character, or the whole string.
Thanks for any help or suggestions.
-
February 11th, 2005, 11:46 AM
#2
Re: Getting Font Dimensions
Use GetTextExtent.
check out this post.
-
February 11th, 2005, 11:46 AM
#3
Re: Getting Font Dimensions
In MFC you could do it like this:
Code:
CDC dc;
dc.CreateCompatibleDC(NULL);
dc.SaveDC();
dc.SelectObject(&font);
CString text("Text i want to measure");
CSize size = dc.GetTextExtent(text);
dc.RestoreDC(-1);
dc.DeleteDC();
Please use meaningful question titles - "Help me" does not let me know whether I can help with your question, and I am unlikely to bother reading it.
Please remember to rate useful answers. It lets us know when a question has been answered.
-
February 13th, 2005, 05:31 AM
#4
Re: Getting Font Dimensions
 Originally Posted by CodeGoose
I'm wondering if there is a way to get the dimensions (height, width) of a specific character or string using a certain windows font.
So is there any way I can find out this information if I have a font name ie) Arial, and a CString ? I basically just need the ratio of the string height to the width.
I don't want to draw the text, just need this height to width ratio. Either for each character, or the whole string.
Thanks for any help or suggestions.
You could use GetTextExtentPoint32 (suppose most precise from its family). There are so many ways to do the thing - for example DrawText with DT_CALCRECT flag.
About calculating sizes for particular font name. You can do it being selecting already created font into device context and then performing necessary call(s) for size retrieving. There's no way to get font metrics for non-created font (having its name only).
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|