Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

CDC: Fonts

0 views
Skip to first unread message

Geoffrey J. Corb

unread,
Mar 5, 1998, 3:00:00 AM3/5/98
to

How do you determine the width of a string (in say, 1/100 inch) using a
variable-width font? My problem is that I have a grid that I print-out that
has cells 3/8" wide. I am trying to print text into these cells, and center
the text within the cell. To do so, I figured I would have to determine the
width of the string and do the math. However, I cannot figure out how to
determine the width of the characters of the string, if the font is not
fixed-width. Currently, using a 9pt. Arial font, I *assume* the characters
to be 1/16" wide, which is accurate for most cases, except "i", "W", "M",
!", etc. etc. etc.

Thanks!
--
Geoffrey J. Corb
Center for Medical Informatics
Yale University School of Medicine
geoffr...@yale.edu
http://ycmi.med.yale.edu/~corb

203.737.6028 - phone
203.785.7074 - fax
800.347.2574 PIN# 61502 - pager


David Lowndes

unread,
Mar 6, 1998, 3:00:00 AM3/6/98
to

>How do you determine the width of a string (in say, 1/100 inch) using a
>variable-width font?

Geoffrey,

Have a look at GetTextExtentPoint32.

Dave
----
Address is altered to discourage junk mail.
Remove ".---" for the real address.
http://www.bj.co.uk

Wayne Rigby

unread,
Mar 7, 1998, 3:00:00 AM3/7/98
to

Geoffrey J. Corb wrote in message
<#bxCYVHS...@uppssnewspub04.moswest.msn.net>...

>How do you determine the width of a string (in say, 1/100 inch) using a
>variable-width font? My problem is that I have a grid that I print-out
that
>has cells 3/8" wide. I am trying to print text into these cells, and
center
>the text within the cell. To do so, I figured I would have to determine
the
>width of the string and do the math. However, I cannot figure out how to
>determine the width of the characters of the string, if the font is not
>fixed-width. Currently, using a 9pt. Arial font, I *assume* the characters
>to be 1/16" wide, which is accurate for most cases, except "i", "W", "M",
>!", etc. etc. etc.


Use either the CDC::GetTextExtent() or CDC::GetOutputTextExtent() method.
These methods will return a CSize object containing the height and width of
the string. They simply use different DCs to compute the width. Look them
up in your online help. Also CDC::GetTabbedTextExtent() and
CDC::GetOutputTabbedTextExtent() may be useful. Also you could use the
CDC::DrawText() method and pass in the value DT_CALCRECT as part of the
format flags. This will set the passed-in rectangle to the size of the
string and will not actually draw the string.

Wayne Rigby
Computer and Systems Engineer
meta...@earthling.net


0 new messages