Skip to main content
gamedev.net
🔒 Locked

How GetCharWidth works?

Started by Craazer May 8, 2004 at 12:53 PM 5 replies 2.2k views
Original Post
Craazer
Craazer
Hi I understand if dont like questons like this but I have read the docs and it says width returned is in logical coordinates. So I asume they must be converted to "pixels" but how? Could this be done whit GetDeviceCaps() ?
Craazer
Craazer
That returns the average width but i need width of each character. Example a has difrend width than i. Thanks though!

also note that even I would use GetTextExtentPoint32 for single chars I would still have to convert logical units. Right?
Sailorstick
Sailorstick
In my experience it doesn''t. (work, that is)
Check out my previous experience:
[url]http://www.gamedev.net/community/forums/topic.asp?topic_id=165540[/url]
Craazer
Craazer
quote:
Original post by Sailorstick
In my experience it doesn't. (work, that is)
Check out my previous experience:
[url]http://www.gamedev.net/community/forums/topic.asp?topic_id=165540[/url]



What windows you got?
I have 98 SE and GetCharWidth32() doesnt work in that so Im using GetCharWidth() wich works and returns somehow sensible values... So now they should be converted...

The main queston isnt yet answerd, what is logical width? And how to convert?


[edited by - Craazer on May 9, 2004 12:33:51 PM]
Craazer
Craazer
So far no good. However this is how I understand the conversion should work from the docs:


SIZE wext,vext;
GetWindowExtEx(mhdc,&wext);
GetViewportExtEx(mhdc,&vext);
for(int x = 0; x < NUM_CHARS;x++)
{
// cwidths are gained by GetCharWidth()

pcharwidths[x] = (MulDiv(cwidths[x],vext.cx,wext.cx));
}


So "quess" what, that doesnt work.
The window and viewport x's are both 1, wich I know nothing about, but character widths are still too short or unaccurate.

[edited by - Craazer on May 9, 2004 2:25:46 PM]
Craazer
Craazer
Got it working!!!

I had forgot to select the font object before using GetCharWidth!

Man im so happy for being so stupid sometimes...

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.