wxBufferedPaintDC GetTextExtent returns too large of a value Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
coderrc
Earned some good credits
Earned some good credits
Posts: 141
Joined: Tue Nov 01, 2016 2:46 pm

wxBufferedPaintDC GetTextExtent returns too large of a value

Post by coderrc » Thu Nov 03, 2016 2:10 pm

I am drawing some text inside a wxBufferedPaintDC. In order to get the placement of the text correct, I call GetTextExtent.

The problem is that I am getting values that are too large.
EG on a run of text that measures 30x9, GetTextExtent returns {31,15}. :shock: thats nearly double the actual height.
In other cases the height may be acceptable, but the width returned by GetTextExtent is as much as 150% the actual display value.
It seems to get worse as the fonts get larger.


I don't need pixel perfect precision, but it needs to be within a few pixels. What can I do to resolve this?

ETA: Ive found the solution. I have to call the long form of the function and subtract out the descent and the externalleading values from the width and height

Post Reply