I've got a really simple setup - I have a string
, a font and a font size on the ready. I want to render this to a Silverlight WriteableBitmap
.
There's one catch - I want to be able to tell apart the letters in the rendered text. Ideally, I'd like to have a System.Windows.Rect
for every rendered letter.
The problem is Silverlight's API, which is missing all of the useful stuff like Graphics.MeasureString
, which I could have used to measure the letters separately.
What adequate options do I have to get the letters' measures in codebehind?
I sort of figured this out on my own. The solution is slow and far from perfect, but hey, it works!
The idea is to render the text many times, adding one letter at a time, and finding the difference between the current and previous TextBlock
widths.
So, for example, if the text is "ab"
, we first render "a"
and get its length. Then we render "ab"
and find the difference, which should be the size of the rendered "b"
.