问题
I would like to know how to calculate the height of a given a font (with its properties, like size, weight, style...) in a Window Universal Application using Win2D.
I previously used a CanvasTextLayout
, but it requires a text to work, like in this line:
var ctl = new CanvasTextLayout(session, "Some text", new CanvasTextFormat(), constraintWidth, constraintHeight
);
In my case, I will NOT have a text because what I'm looking for is the height in which all the glyphs of a given font (with its style, size, weight...) are fit.
EDIT: I have also tried with the CanvasFontFace
class, but it seems it doesn't have any public constructor.
回答1:
But you are already on the right way. Use e. g. fg
as text. The f
allocates the upper area, the g
the lower one, so you get the total height of a text in the current font of the canvas.
来源:https://stackoverflow.com/questions/42162481/how-to-calculate-the-height-of-a-fontfamily-with-win2d-line-spacing