Commit Graph

89 Commits

Author SHA1 Message Date
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 ea8a8770ea Do not use nullptr and add check 2021-02-24 09:46:48 +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 afda299fe4 Implement optional font rendering options
The user can now choose antialiasing grayscale and subpixel and hinting
non, slight or full.
2020-12-04 16:15:54 +01:00
Francesco Abbate cdcd89d6d7 Merge remote-tracking branch 'rxi/master' 2020-11-17 10:24:27 +01:00
rxi 878c94a334 Changed rencache to store font tab_width with font command
Fixes bug where text would be drawn/cached wrongly if more than one tab_width
was used in a given frame
2020-09-05 15:09:54 +01: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 dcf6b06629 Cleanup debug code 2020-06-06 13:08:39 +02:00
Francesco Abbate d17fde1b13 WIP: debugging stuff 2020-06-06 10:52:50 +02:00
Francesco Abbate a2a4668887 Add some comments and remove unused code 2020-06-04 17:23:39 +02:00
Francesco Abbate a0e7d16167 Implement subpixel LCD font rendering 2020-06-04 16:29:28 +02:00
Francesco Abbate d46cf80226 Adjust xadvance computation to use rounding instead of truncate 2020-06-02 17:52:02 +02:00
Francesco Abbate ae032cd185 Ember blender with gamma correction into FontRenderer 2020-06-02 17:18:52 +02:00
Francesco Abbate bc74b2860d Add gamma correct pixel blender 2020-06-02 14:47:06 +02:00
Francesco Abbate c41d6a82e1 Adjust BakeFontBitmap issues 2020-06-01 17:23:18 +02:00
Francesco Abbate c2949edcd7 Check for errors when loading fonts 2020-06-01 17:01:42 +02:00
Francesco Abbate b734390388 Use font_renderer in aGG font testing program 2020-06-01 16:57:33 +02:00
Francesco Abbate 98f5c16932 Remove unused variable 2020-06-01 15:16:07 +02:00
Francesco Abbate fa06862177 Completely remove usage of stb_truetype 2020-06-01 14:43:45 +02:00
Francesco Abbate 91a82d8ae4 Add missing function to free FontRenderer 2020-06-01 14:42:57 +02:00
Francesco Abbate 0389bd000a Fix y offset in BakeFontBitmap
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).
2020-06-01 14:33:46 +02:00
Francesco Abbate 4c6e15b66c Rename GlyphSetA to GlyphSet 2020-06-01 14:08:50 +02:00
Francesco Abbate 3a8cb05ea6 Replace stb's BakeBitmapFont with AGG based font's renderer 2020-06-01 12:56:23 +02:00
Francesco Abbate 4a8df09829 Fix y coordinate orientation in font rendering call 2020-05-29 09:27:00 +02:00
Francesco Abbate 23a080ca45 WIP: compiles but completely broken
AGG files imported from AGG repository, sdl-testing branch.

the pixfmt_bgra32_lcd is just implemented and is not tested.
2020-05-28 12:15:24 +02:00
Francesco Abbate 618078829c Add meson build configuration
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.
2020-05-25 12:22:23 +02:00
rxi 5102088aca Deferred showing window until after the first frame has rendered
Fixes #97
2020-05-14 23:06:14 +01:00
rxi b2756d8a49 Removed xalloc.c/h 2020-05-08 13:41:39 +01:00
rxi 613f9c2ba6 Changed renderer to make tab and newline glyphs invisible
Fixes #16
2020-02-05 20:16:09 +00:00
rxi d8c4bfa6ba Initial commit 2019-12-28 11:17:56 +00:00