Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Coordinates of a specific character in a multi-lined WPF FormattedText

Tags:

c#

geometry

wpf

How to get the position (x y coordinates) of a specific character in a multi-lined WPF FormattedText ?

My text could contain italic parts, bold parts, different fonts, different font sizes, different alignments, etc. and I need to get the coordinates of, say, the 30th character, which could be on the 3rd line.

There is some kind of a half working trick by using the Children (letters) of Children (words) of the Geometry that I can get built from the FormattedText (BuildGeometry), but this does not always work, because some Glyphs are merged in a single geometry (like for "fi": one geometry only).

like image 338
Marc G. Avatar asked Oct 25 '22 01:10

Marc G.


1 Answers

FormattedText.BuildHighlightGeometry, method (Point, Int32, Int32) does exactly that.

like image 52
Marc G. Avatar answered Nov 15 '22 05:11

Marc G.