15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


Rotated text

Mats Mеnhav -- manhav@connectum.skurup.se
Wednesday, May 22, 1996

-- [ From: Mats Manhav * EMC.Ver #2.5.02 ] --

ENV. MSVC 4.1 NT 4.0 / 95

Hi,

Can anoyne give me an idea how I can put rotated text into dialog in my MFC
app.
I know from the Schedule+ that it is possible to paint text that is oriented
in another angle than horizontal on the screen. But I cannot find anything
in docs about it.

Mats
--
==========================================================================
Mats Mеnhav (Mats Manhav for 7-bit people)
email:manhav@connectum.skurup.se   WWW: http://connectum.skurup.se/~manhav
FAX:  (int) 46 (0) 414 243 05      Phone: (int) 46 (0) 414 243 05         
==========================================================================




LeRoy Baxter -- lbaxter@cinfo.com
Tuesday, May 28, 1996

[Mini-digest: 15 responses]

If I remember correctly, you specify the rotation/orientation in the  LOGFONT structure
when you create the font.

-----From: Mario Contestabile

CRect rc;
GetClientRect(rc);
CString string("string");
CFont font;
LOGFONT lgfont;

memset(&lgfont, 0, sizeof(LOGFONT));
lgfont.lfHeight = MulDiv(14, -pDC->GetDeviceCaps(LOGPIXELSY), 72);
lgfont.lfWeight= FW_NORMAL;
lgfont.lfClipPrecision = CLIP_LH_ANGLES;
strcpy(lgfont.lfFaceName, "Arial");

for(int i=0; i<3600;i +=200){
 lgfont.lfEscapement = i;
 font.CreateFontIndirect(&lgfont);
 CFont* OldFont = pDC->SelectObject(&font);
 pDC->TextOut(rc.right/2, rc.bottom/2, str);
 pDC->SelectObject(OldFont);
font.DeleteObject();
}

-----From: kitk@mudshark.sunquest.com (Kit Kauffmann)

I suspect the LOGFONT.lfEscapement is provided for such purposes, but have=
=20
never used such a font.

HTH!
Kit
He who dies with the most toys, is, nonetheless, still dead.

-----From: Munene Kiruja 

Have you tried the documentation for CFont class and in particular the 
CreateFontIndirect member? This Create function allows you to doctor the LOGFONT 
structure to your whims and then use it to create a font. I haven't tried 
interesting angles myself, (at least not intentionally - I once had a bug where I 
was using a malinitialized LOGFONT structure and I was getting oblique text on 
the screen) so if it is any help, please let me know. 

The documentaion for the LOGFONT structure names two members I would look to 
playing with for this purpose. 

lfEscapement: Specifies the angle, in tenths of degrees, of each line of text 
written in the font (relative to the bottom of the page).

 and 

lfOrientation : Specifies the angle, in tenths of degrees, of each character’s 
base line (relative to the bottom of the page).
-----From: dshoots@lmcorp.com (David Shoots)

Refer to the nEscapement parameter for CreateFont().

As far as I know, you'll have to draw it yourself (using an owner-drawn
button or similar mechanism), but you can create the font to draw it using
CreateFont().

-dws

-----From: "Frederic Steppe" 

You can draw rotated text using TextOut.  What you need is a rotated font, 
obtained by setting the lfEscapement setting of a standard font the the angle 
you want.  Search for "ROTATING LINES OF TEXT" in books online (4.0) for an 
example.

To draw taxt in a dialog, I find it easy to use an owner drawn control.

Frederic Steppe (frederics@msn.com)


-----From: "Steve Dunn" 

Look at LOGFONT in the documentation.  There is a couple of parameters for
angle/escapement. See also CreateFontIndirect.

-----From: Don.Irvine@net-tel.co.uk

An extract from Abu Wawda's FAQ (http://www.netvoyage.net/=7Eabu/Faq/window=
s.txt):


2. How do I rotate text?

Create a font using either CreateFont() or CreateFontIndirect() and
specify the angle you want to rotate the font in the lfEscapement
parameter. Then simply select the font into your device-context and use
any text drawing function (e.g. TextOut) to draw with this rotated font.
Remember to delete the font when you are done.

Also remember to set the =22CLIP_LH_ANGLES=22 flag in the =22ClipPrecision=
=22
parameter; unless you do this, your text will rotate the opposite
direction on printers and on the screen=21 Another good flag to set in
the same parameter is =22CLIP_TT_ALWAYS=22-this forces Windows to select a
TrueType font, which is required for rotation.


Hope this helps,

Don
=
-----From: Marcello Perin 

You should override WM_PAINT in your dialog class, create the font
with appropriate escapement angle (in 0.1-degree units), select
the font and paint the text.

Please, see the following example:


   void CMyDialog::OnPaint( )
   {
           CPaintDC DC( this );

      int nEscapement = 900;  // 900 * 0.1 = 90 degree
      CFont Font;
      Font.CreateFont( 0, 0, nEscapement, 0, FW_NORMAL, FALSE,
         FALSE, FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS,
         CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH,
         "Arial" );
      CFont* pOldFont = DC.SelectObject( &Font );
      DC.TextOut( 200, 200, "This is a Text in 90 degree!" );
      DC.SelectObject( pOldFont );
   }

Good Luck.

[]s Marcello Perin

    email: Marcello.Perin@bbs.centroin.com.br

-----From: Barry Tannenbaum 

When you create a font you can specify the angle of the text.  Check out the
documentation on the LOGFONT structure.  You use it with the
CreateFontIndirect function.

        - Barry

--------------------------------------------------------------------------------

3DV Technology, Inc              Phone: (603) 595-2200 X228
410 Amherst St., Suite 150       Fax:   (603) 595-2228
Nashua, NH  03063                Net:   barry@dddv.com

-----From: "Dan Liliedahl" 

You need to create a font and override the OnPaint handler for the dialog.
 When you create the font,
one of the arguments is its rotation angle (I believe only TrueType fonts
can rotate, but not sure).
Then select the font object and draw the text.

-----From: Deepak Saxena 

Take a look at the ::SetWorldTransform() API function

-----From: "Rondal C. Ellifritt" 

You have to create a font with a non-zero Escapement and select that font for 
your rotated output. I know this works well for printing, but I've never tried 
it on the screen.

Rondal
-- 
=================================================================
| Rondal C. Ellifritt   Market Vision Corp.  rondal@mvision.com |
| Voice: 212.306.0374                         Fax: 212.587.3976 |
+---------------------------------------------------------------+
| Opinions expressed herein should be interpreted as the crazed |
|    rantings of a lunatic and lent no Creedence whatsoever.    |
=================================================================
-----From: Patrick.Lee.McClendon@jacobs.com (McClendon, Patrick Lee)


You can use rotated text by changing the escapement and orientation   
properties of a font.  This code fills a LOGFONT structure with   
information about the current font.  It then sets the values of   
escapement and orientation in the LOGFONT structure to 90 degrees.  A new   
font is then created by passing the LOGFONT structure to CFont's   
CreateFontIndirect function.  Any text that is drawn using this font will   
be rotated 90 degrees.  The CreateFont member function of CFont can also   
be used but you must specify the information that is contained in the   
LOGFONT structure as parameters.

CFont *pOldFont = pDC->GetCurrentFont();
LOGFONT logfont;

// retrieve the information about the current font
pOldFont->GetLogFont(&logfont);

// set the escapement and orientation to rotate the text 90 degrees
logfont.lfEscapement = 900;
logfont.lfOrientation = 900;

// create a rotated font from the LOGFONT structure
CFont font;
font.CreateFontIndirect(&logfont);

pOldFont = pDC->SelectObject(&font);

-----From: "Igarashi, Sammi" 

Here's my idea on how you may want to accomplish this. When you create   
your dialog template in the resource editor, add a picture control   
(frame, rectangle or whatever) at the location where you want to see the   
rotated text and name it something other than IDC_STATIC. Declare the   
control as a member variable of the dialog through class wizard. By   
default you get CStatic for the control you added in the resource editor.   
Say you named it m_Text. In "OnPaint()" handler of the dialogbox, get the   
rectangle of m_Text and draw the rotated text. Here's a sample code.

void CTesterDlg::OnPaint()
{
 CPaintDC dc(this);

 CRect rect;
 m_Text.GetClientRect( &rect );
 m_Text.MapWindowPoints( this, &rect );

 LOGFONT lf;
 lf.lfHeight = 12;
 lf.lfWidth = 0;
 lf.lfEscapement = 900; // 90 degrees
 lf.lfOrientation = 0;
 lf.lfWeight = 0;
 lf.lfItalic = FALSE;
 lf.lfUnderline = FALSE;
 lf.lfStrikeOut = FALSE;
 lf.lfCharSet = ANSI_CHARSET;
 lf.lfOutPrecision = OUT_DEFAULT_PRECIS;
 lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
 lf.lfQuality = DEFAULT_QUALITY;
 lf.lfPitchAndFamily = DEFAULT_PITCH | FF_SWISS;
 strcpy(lf.lfFaceName, "Arial");
  
 CFont* pRotatedFont = new CFont;
 pRotatedFont->CreateFontIndirect( &lf );
 CFont* pOldFont = dc.SelectObject( pRotatedFont );
 CString strRotated = "Rotated text here, Rotated text here";
 //dc.TextOut( rect.left, rect.bottom, strRotated );
 dc.ExtTextOut( rect.left, rect.bottom, ETO_CLIPPED, &rect, strRotated,   
NULL );
 dc.SelectObject( pOldFont );
 pRotatedFont->DeleteObject();
 delete pRotatedFont;
}

Sammi Igarashi
GeoGraphix, Inc



Patrick Shainin -- patrick@shainin.com
Sunday, October 27, 1996

Environment: Windows 95, VC++ 4.1
also VC++ Cross Platform Edition for Mac 4.0B and Mac 7.5.5

Hi all,
I am trying to rotate text in a cross-platform app for Win32 and Mac 
platforms using MFC.

Setting the lfEscapement member of the LOGFONT structure before passing 
to CreateFontIndirect works well on the Windows side, but has no effect 
ported to the Mac.

The porting guide seems to indicate that because the Mac Font Manager has 
a simpler font model, "extra" parameters such as lfEscapement and 
lfClipPrecision are not used in mapping Windows fonts to Mac fonts during 
porting.  Does this mean that rotated text is not supported by MFC for 
Macintosh?  I have not found any explicit indication that rotated text is 
not supported.  

Perhaps I am missing some trick in the way I am handling the font to get 
it to port properly?  
Or maybe I need to take a different approach to rotate text with MFC for 
Macintosh?
Here is my code.

CFont tempFont;
CFont rotatedFont;
LOGFONT logFont;

tempFont.CreatePointFont( 100, "Courier New"); //create the base line 
HFONT

tempFont.GetLogFont(&LogFont);  //copy the LOGFONT structure.

//change just the rotation angle and fix the direction of rotation.
logFont.lfEscapement = 900;  
logFont.lfClipPrecision = logFont.lfClipPrecision | CLIP_LH_ANGLES; 

rotatedFont.CreateFontIndirect(&logFont); //create the rotated HFONT

pDC->SelectObject(&rotatedFont);
pDC->TextOut(x,y,m_textString);

Thanks for considering this.

Patrick Shainin
patrick@shainin.com



George Grant -- doubleg@ix.netcom.com
Monday, October 28, 1996

I used to be a Mac programmer for several years until I came over to The =
Dark Side. As far as I remember, if you want to do rotated text on the =
Mac you need to draw your string into a bitmap and rotate the bitmap =
yourself, taking into account the string metrics, etc.




David Elliott -- dce@netcom.com
Thursday, October 31, 1996


>I used to be a Mac programmer for several years until I came over to The =
>Dark Side. As far as I remember, if you want to do rotated text on the =
>Mac you need to draw your string into a bitmap and rotate the bitmap =
>yourself, taking into account the string metrics, etc.

Several people responded to this, but their answers were about Windows
(except for the ones that were more relevant to the use of the
term "Dark Side").

The original question is how to do rotated text on the Mac using
MFC.  The person asking the question noted that the lfEscapement
value seemed to be ignored under the cross-development system.

David Elliott - dce@netcom.com

Visit The Land of the Squishy - http://www.btw.com/dce



Scott Daniels -- scottdfl@sprynet.com
Thursday, November 07, 1996

I have been working on this problem on the Mac side for some time. The only
Apple sanctioned way is to use QuickDrawGX. The only alternative I can
think of (other than the bitmap approach previously mentioned) is to parse
the actual TrueType font resource and rotat the polygon for each glyph and
render that polygon. That approach would probably be a real nightmare.
Unfortunately, Apple always does everything the complex way.

Good luck,
Scott

----------
> From: David Elliott 
> To: mfc-l@netcom.com
> Subject: Re: rotated text 
> Date: Thursday, October 31, 1996 12:27 PM
> 
> 
> >I used to be a Mac programmer for several years until I came over to The
=
> >Dark Side. As far as I remember, if you want to do rotated text on the =
> >Mac you need to draw your string into a bitmap and rotate the bitmap =
> >yourself, taking into account the string metrics, etc.
> 
> Several people responded to this, but their answers were about Windows
> (except for the ones that were more relevant to the use of the
> term "Dark Side").
> 
> The original question is how to do rotated text on the Mac using
> MFC.  The person asking the question noted that the lfEscapement
> value seemed to be ignored under the cross-development system.
> 
> David Elliott - dce@netcom.com
> 
> Visit The Land of the Squishy - http://www.btw.com/dce




| Вернуться в корень Архива |