1

I want to get the exact height of characters such as [.] [,] [j] [g] [a] [l].

I tried this

FormattedText formattedText = getText(".");
var height1 = formattedText.Height; //Extra space will be included
var height2 = formattedText.Baseline; //Characters such as [j] are cut off.
  • `FormattedText` is a control, to [measure text in wpf](https://stackoverflow.com/q/632445/1997232) I expect you will need something else, some low level function used to print/draw text. – Sinatr Apr 24 '20 at 07:40

1 Answers1

1

You need to convert your formattedText to a geometry object and thus get the actual height and width dimensions.

Point p_text = new Point(0, 0);
Geometry _pathGeometry;
            _pathGeometry = formattedText.BuildGeometry(p_text);
Path path = new Path();
            path.Data = _pathGeometry;
            double height = path.Height;
            double width = path.Width;

Try to do it.