This reverts commit 461266e97d.
Related to github issue #122.
The void *data field is not used but the glyphset index can
someting be equal to -1 and the unused field prevent faulty
writes before the allocated struct.
In order to fix the issue with cursor positioning a subpixel-aware draw
text operation within rencache was required.
With this modification the cursor positioning problem is completely
resolved.
A new function renderer.draw_text_subpixel is introduced to perform
consecutive, inline, text drawings with subpixel accuracy.
In order to get right the cursor position on text on mouse clicks it is
needed to take into account text's subpixel positioning.
This fix mostly corrects the problem but cursor positioning is still
somewhat inaccurate for long lines due to repeated commands to draw a text
along a line. Repeated draw text calls make the subpixel information
lost and small errors will add-up.
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
Text looks more correct without the gamma correction. With gamma correction
text looks too bold in dark mode and too light in light mode. This
behavior is a sign that gamma correction is not the right thing to do.
The problem is seen with gamma at 1.5 used previously but is even worst
if a gamma value of 2.2, the theoretical value, is used.
Compute Y offset more accurately and the way it is required in
renderer.c.
Instead of returning y offset wrt the baseline position returns it
wrt the top position (the baseline plus the font's ascent).
Currently the editor will not work if it is not installed.
There is also a caveat about the 'data' directory which is installed
in the bin directory. This may work but does not seem ok because it is
pollution a shared bin directory and the 'data' folder may not be unique
to Lite.