Closed bknoll22 closed 1 month ago
Hi! I assume you have a reason for not simply drawing a line through the text (using Graphics.StrokePath
).
You're correct that this is the intended behaviour when using TextBaselines.Top
; the "correct" way to ensure that the em dash is drawn at the normal position would be to use TextBaselines.Baseline
(for both the text and the em dash).
You can "convert" between the different baseline coordinates using the values returned by the Font.MeasureTextAdvanced
method. In particular, if the baseline is at $b$, the top $t = b -$ Top
.
Note that examples 3 and 4 also work with proportional fonts, while in the first two examples the length of the strikethrough will not be correct in that case (try changing from Courier
to Helvetica
to see the difference).
You can read more about text positioning in the manual (e.g., depending on how accurate you need to be, you may want to take left- and right-side bearings into account).
Let me know if you have any more questions!
Thank you for the response and the additional info!
Hello, It is very possible this is intended behavior, in which case I'm hoping for some direction on how to make it work for us.
My input into the library assumes the y coordinates are the top of the text being drawn. So we use TextBaselines.Top. I have a concept in my code where I draw some text, and then I draw an Em Dash (U+2014) using the same x,y coordinates to create a "strike through" through the text.
I was hoping this would draw the dash through the middle of the text, however it is currently drawing the dash at the top of the text. I'm assuming it is because TextBaselines.Top is using the height of the highest glyph being drawn. Since it is only a dash, there isn't very much height. If the dash is included with text, it is drawn in the middle of the line as expected.
Any suggestions on how to make it work to draw a dash through the middle of the text?