?
Solved

DrawText  at an Angle

Posted on 2003-03-18
16
Medium Priority
?
1,468 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +2
16 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
Get MySQL database support online, now!

At Percona’s web store you can order your MySQL database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit 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

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

741 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