SixLabors / Fonts

:black_nib: Font loading and layout library.
https://sixlabors.com/products/fonts
Other
308 stars 71 forks source link

TextMeasurer.MeasureSize: Incorrect text height calculation #347

Closed Bykiev closed 1 year ago

Bykiev commented 1 year ago

Description

In the latest version text height is calculating incorrectly. In previous beta version for font Calibri, 20px TextMeasurer.MeasureSize height was 33, but now it's getting 18.

Steps to Reproduce

string stringValue = "test";

FontFamily fontFamily;

if (SystemFonts.TryGet("Calibri", CultureInfo.CurrentCulture, out fontFamily))
{
    Font font = new Font(fontFamily, 20);

    var measureResult = TextMeasurer.MeasureSize(stringValue, new TextOptions(font) { Dpi = 96 });
    Console.WriteLine(measureResult.Height);
}

System Configuration

tocsoft commented 1 year ago

The font mesuring was recently completly rebuilt so there is an extreamly good chance that the old measurment wasn't correct.

If you believe it is still incorrect please provide some details on why its wrong (more than its different that it used to be) i.e. something along the lines of the images in #332 showing us what bits are wrong would be a major benefit to understanding the problem you think your seeing

tocsoft commented 1 year ago

maybe try using one of the other Measure apis MeasureAdvance & MeasureBounds they each measure different things about the rendered text.

Bykiev commented 1 year ago

maybe try using one of the other Measure apis MeasureAdvance & MeasureBounds they each measure different things about the rendered text.

Sorry, I'm new to the fonts, from the docs I can't understand what is the difference between MeasureSize, MeasureAdvance and MeasureBounds?

Bykiev commented 1 year ago

I believe I need MeasureSize method. I did some tests and in latest version it returns Arial font's size greater than Calibri. You can check the row height in Excel, and Calibri row height will be greater. I've tried with MeasureAdvance and it returns 27px for both of them.

So, the correct height for 20px Calibri on 96 DPI is 33 and 31 for Arial

JimBobSquarePants commented 1 year ago

How do you know what the “correct” height is?

Text and glyph measurement is extremely accurate and comes from the metrics within the font.

Advance - This measures the vertical and horizontal advance of the glyphs and text. I.E the glyph bounds + any padding. This includes line height.

Size - This measures the glyph bounds and the vertical ascent which includes any leading vertical padding.

Bounds - This measures the glyph bounds with no padding.

Since you know little about fonts I would recommend asking questions in our discussion forums rather than opening issues. Issues are for verified defects only.

I’m going to close this just now.