Commit Graph

6 Commits

Author SHA1 Message Date
Francesco Abbate 35f31c8fbc Fix font rendering artifacts bug
Seen with some fonts like FiraSans, github issue:

https://github.com/franko/lite-xl/issues/46

The fix works essentially by looking to the bounds of each glyph to
accurately ensure that there are no overlaps between the glyphs.

The construction of the font atlas was changed to make some related
improvements now that the bounds of each glyph are know. The main
changes are:

- no longer align glyph on the baseline but align them on their upper
  bounds. We ensure this way that very tall fonts do not leak in the
  upper part
- terminate the row based on x bounds of the glyph to be more accurate
- for each row keep trace of the y of the more larger along y of the
  glyph. The value is used to start a new row to be sure that the new
  now does not overlap with the previous one
- sort glyphs by y size before drawing them. In this way the space
  utilization is better. The algorithm used is the very simple insert
  sort. It behaves like O(n^2) with the number of characters but should
  be ok since n is always small, typically below 128.
- compute the optimal image width and height for the given font's atlas
  for optimal memory usage. As a bonus now the lite's code don't have to
  try and repeat to get a good image size
2021-02-23 17:14:08 +01:00
Francesco Abbate a41754b382 Fix font hinting when using subpixel rendering
Ensure we set the font's size with freetype to the intended size so that
hinting works as expected and perform subpixel scaling using affine
matrix coefficient.
2020-12-11 14:36:32 +01:00
Francesco Abbate 3c3662b3ba Add option to disable X axis font's pre-scaling
If used pre-scaling along X null the effect of the font's hinting.
2020-06-12 16:06:39 +02:00
Francesco Abbate ba4c8dbbb5 Remove unneeded checks in get_font_vmetrics 2020-06-08 09:36:07 +02:00
Francesco Abbate 81289d651e Move font resize in a separate function 2020-06-06 19:11:14 +02:00
Francesco Abbate c5575de058 Move font renderer in a separate folder as a library 2020-06-04 18:52:01 +02:00