asad11-6840 avatar image
0 Votes"
asad11-6840 asked JunjieZhu-MSFT commented

LOGFONT text rotation increases the size of the font

I tried rotating the text by 270 degrees but the size of the text also ends up changing.

 HDC hdc = CreateCompatibleDC(NULL);
 lf.lfHeight = 40;
 lf.lfWidth = 0;
 lf.lfEscapement = 2700;
 lf.lfOrientation = 2700;
 lf.lfWeight = FW_SEMIBOLD;
 lf.lfItalic = 0;
 lf.lfUnderline = 0;
 lf.lfStrikeOut = 0;
 lf.lfCharSet = DEFAULT_CHARSET;
 lf.lfOutPrecision = 0;
 lf.lfClipPrecision = 0;
 lf.lfQuality = 0;
 lf.lfPitchAndFamily = 0;
 strcpy(lf.lfFaceName, "Arial");
 hFont = CreateFontIndirect(&lf);
 SelectObject(hdc, hFont);
 TextOut(hdc, 120, 79, "hello", SIGNED_STRLEN("hello"));

However the size of the font gets bigger when the lfEscapement and lfOrientation parameters are set to 2700 for a 270 degrees as opposed to 0 for no rotation.

How do I keep the text size the same when I rotate it?
By size I mean lf.tmHeight or lf.tmWidth are -2 or -1 from when the text was not rotated.

Also what does the escapement have to do with the rotation? I couldn't understand from the documentation

· 16
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I tested various flags in GDI (Antialiased and others) and I also don't get exactly the same size when rotated
But I tested in GDI+, and I get exactly the same font size (Rotate 90, not antialiased) :


2 Votes 2 ·
rotate-text.jpg (90.6 KiB)

If you don't specify the face name, does it make any difference?

0 Votes 0 ·
asad11-6840 avatar image asad11-6840 DavidLowndes-6766 ·

nope. Not specifying a name doesn't affect anything.

0 Votes 0 ·

Try specifying a negative size, for example: lf.lfHeight = -34.

0 Votes 0 ·

that makes the text even bigger

0 Votes 0 ·

Did you try other negative values (the same for rotated and non-rotated text) and check if the size on screen is different?

0 Votes 0 ·
Show more comments

Hi, is there any progress on this issue?

0 Votes 0 ·

Hi, I have read your response and understood what you have said. The thing is I was initially using 2 HDCs. I wrote the text into one of them, did the rotation and copied it into the other HDC using bitblt but this makes the text unselectable. As, from what I understand, the HDC that is being copied into doesn't know whether that copy is a picture or a piece of text.

Do you have another solution to this that doesn't involve copying in between buffers?

1 Vote 1 ·

After reading Castorix31's comment, I also went and tested it with GDI+,
I use Graphics::RotateTransform to rotate the text. In GDI, the font attribute is used to achieve the rotation. In GDI+, many attributes are independent.
It does work, it seems that this is the best solution for you.

0 Votes 0 ·

It's been a few days, may I ask if our discussions and responses were helpful to your question?

0 Votes 0 ·

1 Answer

JunjieZhu-MSFT avatar image
1 Vote"
JunjieZhu-MSFT answered JunjieZhu-MSFT edited

Welcome to Microsoft Q&A!

1. Background

ClearType, a software technology developed by Microsoft that improves the readability of text on existing LCDs (Liquid Crystal Displays), In ClearType font rendering, the width of 'm' becomes smaller after rendering.


2. Why does the text become different after rotation?

When GDI displays strings horizontally, each subsequent character starts at the decimal place, which is simulated by antialiasing or subpixel (ClearType) display. However, when rendered vertically, the starting position of each subsequent character is rounded to the next whole pixel, which tends to make vertical text a few pixels "longer" than horizontal text.

3. How to solve this issue?


Use ANTIALIASED_QUALITY, Make sure the rendered pixels are the same.
For vertical text content, draw them horizontally to an offscreen buffer, rotate it, and set the buffer to the screen. This makes vertical text and horizontal text look exactly the same.

4. Solution from @Castorix31
You can use GDI+ to draw text and use Graphics::RotateTransform to rotate text.

Thank you.

If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

image.png (7.9 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.