Baseline font offset calculation changed between versions? #2888
Unanswered
gpatrut-matica
asked this question in
Q&A
Replies: 1 comment 3 replies
-
Vertical metrics are used for laying out vertical text and are often different to the horizontal ones. Could you try the Horizontal metrics and report back? They should be unchanged. |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello everyone,
We've been using ImageSharp for quite a while now, we even bought the commercial license and we've had no isseus so far, but recently we've had to update all the packages (previous versions were Fonts 1.0.0-beta19, Drawing 1.0.0-beta15 and ImageSharp 3.0.1). In our use case we had to draw some text at a specified x and y position with its baseline as the vertical position. In the old version, we did this by simply calculating a small offest to apply to the text options like this:
var yVariation = (float)(-font.FontMetrics.Descender + font.FontMetrics.LineGap) / font.FontMetrics.UnitsPerEm * font.Size; adjustedTextOrigin.Y += yVariation;
which worked fine when doing
canvas.Mutate(x => { x .SetDrawingTransform(rotationMatrix) .DrawText(drawingOptions, textOptions, Content, brush, new Pen(Color.Transparent, 1)); });
which produced the following result, the green cross signs the desired origin, after the offest is applied.
But after updating to the latests versions (Fonts 2.1.2, ImageSharp 3.1.6, Drawing 2.1.5) all the offsets are now wrong and the text is no longer correctly aligned.
This is how we do it in the latest version and the result
var yVariation = (double)(-font.FontMetrics.VerticalMetrics.Descender + font.FontMetrics.VerticalMetrics.LineGap) / font.FontMetrics.UnitsPerEm * font.Size; adjustedTextOrigin.Y += (float)yVariation;
Now, my first guess is that perhaps there have been some API changes that I've missed, in which case I would love if anyone could point me on what I'm doing wrong. Thanks.
Beta Was this translation helpful? Give feedback.
All reactions