LOGFONT text rotation increases the size of the font

asad11 26 Reputation points
2022-05-20T15:10:39.33+00:00

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

HDC hdc = CreateCompatibleDC(NULL);
LOGFONT lf;

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

Windows development | Windows API - Win32
Developer technologies | C++
{count} votes

Accepted answer
  1. Junjie Zhu - MSFT 21,646 Reputation points
    2022-05-23T07:23:22.577+00:00

    Hello,
    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.

    204527-image.png

    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?

    lf.lfQuality = ANTIALIASED_QUALITY;  
    

    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.

    2 people found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.