Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

DrawText  at an Angle

Posted on 2003-03-18
16
Medium Priority
?
1,524 Views
Last Modified: 2013-11-20
Hi all,
I want to output a string at an angle on a DC. How do I do it?
I've tried fitting my text into rectangles by using ExtTextOut
but still the text remains straight.
Also used DrawTextEx() but the text does not get displayed at all

How to tilt the text?

Regards,
Prem.
0
Comment
Question by:premadhas
  • 4
  • 3
  • 2
  • +2
13 Comments
 
LVL 48

Expert Comment

by:AlexFM
ID: 8159000
If you are working in WinNT or later, you can use SetWorldTransform to rotate coordinate axes before drawing the text (text may be drawn by any DC function: DrawText...)

In GDI+ you can use Graphics::RotateTransform for the same purpose.

0
 
LVL 1

Expert Comment

by:keitha1
ID: 8161098
Create a LOG_FONT with the rotation desired. You then do a SelectObject (pLogFont);

0
 
LVL 3

Expert Comment

by:aphillips
ID: 8164853
> Create a LOG_FONT with the rotation desired.

Sorry, this does not achieve anything useful. The lfOrientation field of LOGFONT changes the baseline but does not rotate the characters.

I believe AlexFM's soln will work.  Also GDI+ can be installed on Windows 98 (95?) too, I think.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 48

Expert Comment

by:AlexFM
ID: 8164957
GDI+ can be used in all Windows-based applications. GDI+ is new technology that is included in the Microsoft® Windows® XP and Windows .NET Server operating systems. It is required as a redistributable for applications that run on the Windows NT® 4.0 SP6, Windows 2000, Windows 98, and Windows Millennium Edition operating systems.

Introduction to GDI+
http://www.codeproject.com/vcpp/gdiplus/startinggdiplus.asp

It is available in Microsoft Platform SDK. I think having Visual Studio .NET we don't need SDK.
0
 
LVL 31

Expert Comment

by:Zoppo
ID: 8165210
>Sorry, this does not achieve anything useful.
I disagree ... with lfEscapement and lfOrientation you can
specify the rotation of the text.

I think it's a bit unclear what premadhas means with
'DrawText  at an Angle' exactly. Rotated text (baseline not
horizontal and characters vertical to baseline) or text where
the characters are not vertical on the baseline.

ZOPPO
0
 

Author Comment

by:premadhas
ID: 8166174
As Zoppo has said lfEscapement and lfOrientation
are not giving any desired output.

By "at an angle" I mean when DrawText is called normally the characters drawn are vertical to the baseline.
When you click on Windows->Start button the windows version that appears I term it at as "a text at an angle of 90 degrees". Hope this is clear
0
 
LVL 1

Expert Comment

by:keitha1
ID: 8167012
A LogFont DOES work. Set both lfOrientation and lfEscapement to the same value. I believe that value is in 100ths of a degree so a 90 degree rotation will be 9000 units.

Make sure you have the right flags set in the LogFont, such as TrueType. There may be some fixed fonts that don't rotate but TrueType one's do.
0
 
LVL 31

Accepted Solution

by:
Zoppo earned 200 total points
ID: 8167494
> As Zoppo has said lfEscapement and lfOrientation
> are not giving any desired output.
That's exactly NOT what I said ... coz, since for the last
some years I used this really often.

But, maybe the problem is another one: there seems to be fonts
which cannot be rotated, i.e. "System" ... look at this code:

void CTestView::OnDraw(CDC* pDC)
{
 CFont font, *pFont;
 LOGFONT lf;
 pFont = pDC->GetCurrentFont();
 pFont->GetLogFont( &lf );

// strcpy( lf.lfFaceName, "Arial" ); // THIS LINE
 lf.lfEscapement = lf.lfOrientation = 900;

 font.CreateFontIndirect( &lf );
 pFont = (CFont*)pDC->SelectObject( &font );

 pDC->TextOut( 100, 100, "Hello, world!" );

 pDC->SelectObject( pFont );
}

this produces un-rotated text until you un-comment the line
with the comment 'THIS LINE' ... afterwards it creates a
90-degree rotated text...

ZOPPO
0
 

Author Comment

by:premadhas
ID: 8172887
Thanks Zoppo...
That changing of the system font was the problem.
Your sample works cool
0
 
LVL 3

Expert Comment

by:aphillips
ID: 8172962
In my experince you cannot get LOGFONT to draw the text at any angle except 0, 90, 180 etc.  What happens if you try the above with an angle of 30 not 90 degrees?
0
 
LVL 31

Expert Comment

by:Zoppo
ID: 8173173
It's no problem ... works with any angle on every Windows at
least since Win95/WinNT4.
0
 
LVL 31

Expert Comment

by:Zoppo
ID: 8173175
Simply replace the 900 in the above sample by 300 and you have text at 30 degrees.
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 8173330
Zoppo, excellent! I add your code fragment to my collection.
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Integration Management Part 2

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question