Drawing fonts on the client area

Drawing fonts on the client area

I am drawing text on the client area as a series of vectors. The vectors depend on the font. The text can be at any position, size and rotation.

I can draw text using a number of fonts, but I must have the definition of the font as vectors.

I now want to be able to draw text using any font - such as true type fonts. Is there any way to do this?



8 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Font is a GDI object similar to a, say, brush or pen. Font is created
using CreateFont or CreateFontIndirect, which return a font handle.
Then, you select a font into DC with SelectObject and any subsequent
text-drawing operations will be performed using that font:

hArialH8=CreateFont(-iFontSize,0,0,0,FW_NORMAL,0,0,0,          & 

creates a Arial 8 pt font (normal, horizontally drawn). First several
arguments determine bold, italic, underline and rotation attributes
(see SDK documentation). Now, if you need several fonts, you can
define an array of hFonts and select them into DC as needed (of
course, be careful to do DeleteObject with all when not needed
anymore). TextOut, DrawText, TabbedTextOut will all use the
font selected.



I have tried using CreateFont and it works well - but the 4th parameter - the orientation, doesn't seem to work as there is no change in the text display.



You have to set both nEscapement (3rd) and nOrientation (4th) arguments
to the same value in order to get it. IIRC, Windows NT/2000 handles
those separately, while under Win98 they must be the same.


Is there a call to return the size of a text string in the currently selected font, i.e. the height and length, or the coordinates of the corners of the text rectangle?


David, I don't want to be offensive, but I think you'd be far more efficient
if you consult your manual from time to time. All the information I posted
here is clearly stated in Win32 SDK help. The one about orientation is
described under CreateFont reference, while you could find this one if
you click on "Group" button for a text-output function you're familiar with (say, TextOut). SDK/MSDN is organized in chapters, and every chapter ends with reference section, describing structures, messages and functions related with the topic. Isn't it easier to do some investigation with the information you have at hand than to post a question here and wait for someone to answer?


Sorry, with some these questions I looked in the help, didn't find the answer, posted a question, did some more investigation then found the answer.
As you say I will have to do more investigation in future before posting.

Hi David,

I highly recommend "Programming Windows, The Definitive Guide to the Win32 API" by Charles Petzold. (the fifth edition of this windows programming classic)

Windows application programming in Fortran is just SDK programming, for which Petzold is the reference, from his first edition (Win 3.1) to his fifth. If you can manage the mental translation from C to Fortran there is no better reference.


Leave a Comment

Please sign in to add a comment. Not a member? Join today