Commit graph

52 commits

Author SHA1 Message Date
Daniel Eklöf
90bfcc1fbd
render: fix underline/strikeout positioning
There were two errors:

* We subtracted half the line width instead of adding it to the
  baseline

* We rounded the line positioning and thickness before the positioning
  calculation. In particular, rounding the thickness before using it
  to adjust the position was wrong. Now we round just before the
  pixman call.
2019-11-30 14:53:22 +01:00
Daniel Eklöf
719d521e33
font: bug: bad multiplier when converting from 16.16 fixed float 2019-11-30 13:10:20 +01:00
Daniel Eklöf
10f563dc6b
font: cache_size -> glyph_cache_size
This makes it more clear it has nothing to do with the font cache.
2019-11-30 12:41:09 +01:00
Daniel Eklöf
7a4d1b1a6e
font: destructor: pop elements as we go
Otherwise we'll end up free:ing the same font over and over again.
2019-11-30 12:39:18 +01:00
Daniel Eklöf
4e1a6b5739
font: original -> requested 2019-11-30 12:38:54 +01:00
Daniel Eklöf
62a239bcd1
font: log freetype errors 2019-11-30 12:35:07 +01:00
Daniel Eklöf
8274e3e034
font: never set glyph->cols to something that is less than 0 2019-11-30 00:15:54 +01:00
Daniel Eklöf
cb168ec8d7
font: add missing ';' 2019-11-28 21:33:45 +01:00
Daniel Eklöf
bd3f2fdf0e
font: use pixelsizefixupfactor on regular bitmap fonts too, if set
But if it isn't set, only estimate it if the font is a *scalable*
non-outline (bitmap) font.
2019-11-28 21:32:28 +01:00
Daniel Eklöf
c5602fde96
font: set pixman filter when re-scaling glyph 2019-11-27 21:33:08 +01:00
Daniel Eklöf
c18ff22a95
font: estimate pixel size fixup when not provided by fontconfig
But only do this when the font is scalable but not an outline. This is
only true for color bitmap fonts (emoji fonts), and not e.g. regular
bitmap fonts.
2019-11-26 19:02:36 +01:00
Daniel Eklöf
20a8fd6acf
font: use DPI=75 if there's no DPI attribute from fontconfig
This is the fontconfig default as well
2019-11-26 19:02:36 +01:00
Daniel Eklöf
f358211904
font: underline/strikeout: use y-scale, not x-scale 2019-11-26 19:02:35 +01:00
Daniel Eklöf
bc86cd61c7
font: move metrics from terminal struct to font struct 2019-11-26 19:02:35 +01:00
Daniel Eklöf
431800a8a5
font: cleanup and return error when failing to load font file 2019-11-25 20:17:15 +01:00
Daniel Eklöf
a277eaeb31
font: use FT_Set_Pixel_Sizes() instead of FT_Set_Char_Size()
Since we're working with pixel sizes anyway...
2019-11-25 20:14:48 +01:00
Daniel Eklöf
8deba5fdb7
font: don't spam failures to lookup glyphs 2019-11-20 10:23:17 +01:00
Daniel Eklöf
43462b24f3
font: cache loaded fonts globally
Each font instance has a ref-counter. Whenever we want to instantiate
a font that has already been loaded, we instead return the
already-loaded instance, and bump the ref counter.

When the last font instance is destroyed, it is also removed from the
cache.
2019-11-01 20:40:42 +01:00
Daniel Eklöf
6fd4f6000b
font: glyph_for_wchar(): ensure glyph->valid == false, in *all* error cases 2019-10-18 19:50:48 +02:00
Daniel Eklöf
3c42691e1b
font: load fallback fonts on demand
When instantiating a primary font, build the fallback font list, but
don't actually instantiate the fallback fonts.

Instead, remember the (full) pattern that we should use if/when we
instantiate it.

Then, when looking up a glyph and we need a fallback font, loop the
list and instantiate the font(s) there and then.
2019-10-17 17:53:03 +02:00
Daniel Eklöf
e218e19ea3
font: load all fallbacks when instantiating a primary font
The caching of fallback fonts didn't work. It "worked" because we
didn't free the fonts... When we started doing that, the fallback
fonts were no longer cached.

Another solution would have been to keep the cached fallback fonts
around until exit, and free them there. But that didn't seem very
clean.

So, for now, load *all* fallbacks when instantiating a
primary (non-fallback) font.

Note that this slows down initial startup time.
2019-10-17 17:43:40 +02:00
Daniel Eklöf
5a80bcff18
font: rename cache -> glyph_cache 2019-10-17 17:12:04 +02:00
Daniel Eklöf
1875f98945
font: fc_idx may not be the requested one 2019-10-17 17:07:37 +02:00
Daniel Eklöf
af85c10127
font: rename fc_loaded_fonts -> fc_loaded_fallbacks 2019-10-17 17:07:22 +02:00
Daniel Eklöf
04edd96018
font: cache top-level fonts
This greatly improves the performance when loading user-configured
fallback fonts.

Previously, we had to re-load these fallback fonts over and over again
for each (new) glyph.
2019-10-16 22:34:23 +02:00
Daniel Eklöf
bf5ad13df0
font: from_name() returns an allocated font struct 2019-10-16 22:22:26 +02:00
Daniel Eklöf
928e86b423
font: cache loaded fontconfig fallback fonts 2019-10-16 22:18:57 +02:00
Daniel Eklöf
a789230cf9
font: font_from_name() returns an allocated font struct 2019-10-16 21:52:12 +02:00
Daniel Eklöf
5a0bb292ee
font: calculate underline/strikeout metrics in font, not main 2019-09-29 13:03:48 +02:00
Daniel Eklöf
9029478e8c
font: tentative support for BGR, V-RGB and V-BGR 2019-08-19 17:45:21 +02:00
Daniel Eklöf
33b5210a6a
refactor: break out stride calculation to new function 2019-08-18 17:59:43 +02:00
Daniel Eklöf
0060e33912
font: implement subpixel antialiasing 2019-08-18 17:40:57 +02:00
Daniel Eklöf
f45e5c6aef
Remove all references to cairo; we now use pixman only 2019-08-16 22:11:22 +02:00
Daniel Eklöf
bed7b34c28
wip: render background and glyphs using pixman 2019-08-16 20:40:32 +02:00
Daniel Eklöf
30d5847d06
font: fix broken debug log 2019-08-16 18:00:56 +02:00
Daniel Eklöf
9e7106018e
font: don't bother creating a cairo surface for zero-width glyphs 2019-08-13 20:44:30 +02:00
Daniel Eklöf
8035bbfbdb
font: handle invalid glyphs correctly
*All* glyphs are cached.

But we never set the 'wc' member of failed glyphs, causing a later
cache lookup of the same glyph miss in the cache, and thus re-generate
yet another glyph (that is inserted into the cache). I.e. if the
same (invalid) glyph is rendered over and over again, we'll end up
growing the cache indefinitely.

Fix by setting the 'wc' member of invalid glyphs. This causes a cache
lookup to hit. But, we must also check the glyphs validity, and return
NULL if the glyph isn't valid.

Finally, when destroying a font, skip invalid glyphs, since they have
no resources that needs to be freed.
2019-08-13 20:41:21 +02:00
Daniel Eklöf
00b6948d9f
font: cleanup 2019-08-10 21:10:56 +02:00
Daniel Eklöf
92319d1570
font: initial support for fontconfig font fallback
When we've exhausted our own fallback list, try the font list provided
by fontconfig.

This means, the user's fallback fonts have priority, but in case all
of them fail, we hopefully get lucky with fontconfig...
2019-08-10 20:34:22 +02:00
Daniel Eklöf
83a10402af
font: improve logging 2019-08-08 17:57:58 +02:00
Daniel Eklöf
4d7993b36f
cell: pack more efficiently and store glyph as a wchar
The 'attributes' struct is now 8 bytes and naturally packed (used to
be 9 bytes, artificially packed).

'cell' struct is now 12 bytes, naturally packed (used to be 13 bytes,
artificially packed).

Furthermore, the glyph is stored as a wchar instead of a char*. This
makes it easier (faster) to do glyph lookup when rendering.
2019-08-02 18:19:07 +02:00
Daniel Eklöf
858a0d9906
font: initial support for double-width *and* color emoji glyphs
Fonts are now loaded with FT_LOAD_COLOR and we recognize and support
the FT_PIXEL_MODE_BGRA pixel mode.

This is mapped to a CAIRO_FORMAT_ARGB32 surface, that is blitted
as-is (instead of used as a mask like we do for gray and mono glyphs).

Furthermore, since many emojis are double-width, we add initial
support for double-width glyphs.

These are assumed to always be utf8. When PRINT:ing an utf8 character,
we check its width, and add empty "spacer" cells after the cell with
the multi-column glyph.

When rendering, we render the columns in each row backwards. This
ensures the spacer cells get cleared *before* we render the glyph (so
that we don't end up erasing part of the glyph).

Finally, emoji fonts are usually bitmap fonts with *large*
glyphs. These aren't automatically scaled down. I.e. even if we
request a glyph of 13 pixels, we might end up getting a 100px glyph.

To handle this, fontconfig must be configured to scale bitmap
fonts. When it is, we can look at the 'scalable' and 'pixelsizefixup'
properties, and use these to scale the rendered glyph.
2019-07-31 18:03:35 +02:00
Daniel Eklöf
73b4d5d05a
font: add support for fallback fonts
A top-level font now has a list of fallback fonts. When a glyph cannot
be found, we try each fallback font in turn, until we either find one
that has the glyph, or until we've exhausted the list.

To make this actually work in practise (read: to make performance
acceptable), the cache is re-worked and is now populated on demand.

It also supports non-ASCII characters, by using the 4-byte unicode
character as index instead.

Since having an array that can be indexed by a 4-byte value isn't
really viable, we now have a simple hash table instead of an array.
2019-07-30 18:04:28 +02:00
Daniel Eklöf
4302d3eb68
font: set FT load and render flags from FontConfig properties 2019-07-29 20:10:55 +02:00
Daniel Eklöf
fe882bddba
font: populate glyph cache (ASCII characters only) when instantiating font 2019-07-28 21:03:38 +02:00
Daniel Eklöf
9e57ba2108
font: add font_glyph_for_utf8()
This function fills in a struct glyph with glyph bitmap data for the
provided utf-8 character (essentially a FT_Bitmap wrapped in a cairo
surface).
2019-07-28 20:37:59 +02:00
Daniel Eklöf
175dc9cf94
cairo-ft: remove all usages of cairo-ft 2019-07-28 12:45:01 +02:00
Daniel Eklöf
cb02c9cf41
font: load FreeType face, and set it's pixel sizes 2019-07-28 12:09:22 +02:00
Daniel Eklöf
df929a251a
font: don't warn when failing to get hinting/antialias
These properties aren't always included in the pattern, and when they
aren't, trying to get them will fail.

This isn't an error, just fallback to a default value.
2019-07-18 10:03:08 +02:00
Daniel Eklöf
7ad87fdf2b
font: remove assert that was only there for debugging 2019-07-18 09:29:36 +02:00