How to get text width and height in DirectWrite/Direct2D

thebluetropics 1,046 Reputation points
2022-09-16T07:58:44.353+00:00

I need an approach to get the text width and height (like getBoundingClientRect() in DOM) in DirectWrite/Direct2D.

I know IDWriteTextLayout::GetMetrics() but, the width and height seems doesn't right. Is there built-in helper method to achieve this in DirectWrite?

Windows development | Windows API - Win32
Developer technologies | C++
Developer technologies | C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
0 comments No comments
{count} votes

Answer accepted by question author
  1. Castorix31 91,506 Reputation points
    2022-09-16T08:16:31.467+00:00

    GetMetrics normally works.
    I had adapted MS code for more precise calculations with GetOverhangMetrics in
    CScrollingText.cpp
    (inside OnPaintProc)


0 additional answers

Sort by: Most helpful

Your answer

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