ohmtech-rdi / eurorack-blocks

Software to Hardware Prototyping for Eurorack using C++, Max/Gen~ or Faust
Other
303 stars 21 forks source link

Fix cairo font alignments on windows #505

Closed ohmtech-rdi closed 1 year ago

ohmtech-rdi commented 1 year ago

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 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.