From: twbrown@PE-Nelson.COM (Tom W. Brown)
Newsgroups: comp.os.ms-windows.programmer.misc
Subject: Re: printing text at an angle without learning all about fonts
Date: 14 Oct 92 20:49:13 GMT
Organization: PE-Nelson

In article <1992Oct13.232736.15896@emr1.emr.ca>, jagrant@emr1.emr.ca (John Grant) writes:
|> I am quite satisfied with the default font (whatever it is, I don't care), but
|> I want to label a few things with text at various angles.  I started to read
|> Petzold 3.1 chapter 14 and said "this is nuts - I shouldn't have to learn all
|> of this - I'm not writing a word processor!".  In other graphics systems, I
|> can use something like:
|> 	PlotText(float x,float y,float angle,char *text);
|> so why can't I do the same in Windows?
|> 
|> So the question is "What is the simplest way to print text at an angle,
|> without learning too much about fonts?"
|> 
|> I saw the .lfEscapement field in LOGFONT and I suppose that is the only way
|> to change the angle.  I also know how to get the handle of the default font:
|> 	hfont=GetStockObject(SYSTEM_FONT);
|> Now, how can I get a LOGFONT for the SYSTEM_FONT, so I can go in and modify
|> .lfEscapement?

Try this (for, say, 90 degree rotated text):
   
   LOGFONT lf;
   HFONT font;

   GetObject(GetStockObject(SYSTEM_FONT), sizeof lf, &lf);
   lf.lfEscapement = 900;   // remember, units are in 10ths of a degree and
   lf.lfOrientation = 900;  // you need to set both of these the same

   font = CreateFontIndirect(&lf);

I haven't tried this so I don't know if it will work or not.  Please note that
it is *not* rotating the system font, rather it is a request to create a
new font that is much like the system font as possible, just rotated.

If this doesn't work, then you'll need to tinker with more fields in the
logical font structure.  Look, it's not that complicated!  Just write a routine
for yourself like this:

   HFONT CreateRotatedFont(int height, int width, int angle, int weight
                           BYTE italic, BYTE underline, BYTE strike)
   {
      return CreateFont(height, width,
                        angle * 10,    // assume parameter is in degrees
                        angle * 10,
                        weight,
                        italic,
                        underline,
                        strike,
                        ANSI_CHARSET,
                        OUT_DEFAULT_PRECIS,
                        CLIP_DEFAULT_PRECIS | CLIP_LH_ANGLES,
                        DEFAULT_QUALITY,
                        VARIABLE_PITCH | FF_SWISS,
                        "");
   }

This should give you what you want.  If things like weight, italic, etc. are
always the same for your application then take them out of the parameter
list to simplify the call.


----------------------------------------------------------------------------
Tom Brown               |  "Strange women, lying in ponds, distributing
PE Nelson Systems       |   swords is no basis for a system of government."
twbrown@pe-nelson.com   |                    Monty Python and the Holy Grail
----------------------------------------------------------------------------

   
Newsgroups: comp.os.ms-windows.programmer.misc