This PR fixes 2 problems in cairo on Windows where, for whatever reason, the text and font extents do not return the same value as on macOS:
The text extent width is around 2pt bigger
The font extents ascent and descent are more or less rounded to the next integer, so that the ascent + descent is not the font height.
We correct this by removing 2pt to the text width, and make an approximation of the correct ascent for vertical alignment.
The vertical alignment is not perfect, because ascent and descent are rounded independently, but most probably good enough: in our tests, this is at worst 0.1mm-precise, which is typically less than the front panel machine tolerance (either drilled aluminum or PCB).
One should note that cairocffi.FontOptions.set_hint_metrics with cairocffi.HINT_METRICS_OFF doesn't seem to have any impact on that.
Another problem is that the font weight for bold interpretation is different, even though we supply the bold font. It seems impossible to correct this for some reason unfortunately.
A better way to fix all this would be probably to scrap all font handling from cairo, and use freetype directly. We tried also to use pango, but for some reason kerning is not properly acknowledged for the fonts we use, which is even worse.
This PR fixes 2 problems in cairo on Windows where, for whatever reason, the text and font extents do not return the same value as on macOS:
We correct this by removing 2pt to the text width, and make an approximation of the correct ascent for vertical alignment.
The vertical alignment is not perfect, because ascent and descent are rounded independently, but most probably good enough: in our tests, this is at worst 0.1mm-precise, which is typically less than the front panel machine tolerance (either drilled aluminum or PCB).
One should note that
cairocffi.FontOptions.set_hint_metrics
withcairocffi.HINT_METRICS_OFF
doesn't seem to have any impact on that.Another problem is that the font weight for bold interpretation is different, even though we supply the bold font. It seems impossible to correct this for some reason unfortunately.
A better way to fix all this would be probably to scrap all font handling from cairo, and use freetype directly. We tried also to use pango, but for some reason kerning is not properly acknowledged for the fonts we use, which is even worse.