Commit Graph

15 Commits

Author SHA1 Message Date
Francesco Abbate 9ff6a0325e Mostly fix problem of offset with cursor positioning when using mouse
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.
2021-03-06 16:18:24 +01:00
Francesco Abbate 294f3f14fb Implement subpixel font positioning
Subpixel positioning is only by 1/3 of pixel
2021-03-03 18:36:09 +01:00
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 1fc6d62b14 Fix Lua subproject ofr Mac OS X 2020-06-29 17:01:14 +02:00
Francesco Abbate f5ede27e91 No longer use gamma correction
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.
2020-06-16 14:43:03 +02: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 9e996a2d87 Rename FontRenderer to FR_Renderer 2020-06-11 23:19:08 +02:00
Francesco Abbate 93a36617f9 Bring back simple grayscale rendering option 2020-06-11 23:11:40 +02:00
Francesco Abbate 00c3983da6 Rename FontRenderer* symbols as FR_* 2020-06-11 18:12:47 +02:00
Francesco Abbate 117714390a Make the FontRenderer's Bitmap struct opaque outside the library 2020-06-11 17:52:00 +02:00
Francesco Abbate ce664f85b1 Move rendering buffers pointers computations inside FontRendererBlendGammaSubpixel
The logic is to disentangle the code between renderer.c and FontRenderer
so that this latter has a simple, logical interface.
2020-06-11 17:33:57 +02:00
Francesco Abbate 18865fd32f Remove font renderer debug code 2020-06-09 16:55:26 +02:00
Francesco Abbate e82d766c2b Add more debug information in font's bitmap images 2020-06-07 00:15:38 +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