2019-06-13 16:24:35 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
2019-07-28 12:09:22 +02:00
|
|
|
#include <stdbool.h>
|
2019-07-29 20:10:55 +02:00
|
|
|
#include <threads.h>
|
|
|
|
|
|
2019-07-30 18:04:28 +02:00
|
|
|
#include <ft2build.h>
|
|
|
|
|
#include FT_FREETYPE_H
|
|
|
|
|
#include FT_LCD_FILTER_H
|
2019-08-10 20:34:22 +02:00
|
|
|
#include <fontconfig/fontconfig.h>
|
2019-08-16 20:40:32 +02:00
|
|
|
#include <pixman.h>
|
2019-06-13 16:24:35 +02:00
|
|
|
|
2019-07-30 18:04:28 +02:00
|
|
|
#include "tllist.h"
|
|
|
|
|
//#include "terminal.h"
|
|
|
|
|
|
|
|
|
|
typedef tll(const char *) font_list_t;
|
|
|
|
|
|
|
|
|
|
struct glyph {
|
|
|
|
|
wchar_t wc;
|
2019-08-16 20:40:32 +02:00
|
|
|
int cols;
|
2019-07-30 18:04:28 +02:00
|
|
|
|
2019-08-16 20:40:32 +02:00
|
|
|
pixman_image_t *pix;
|
|
|
|
|
int x;
|
|
|
|
|
int y;
|
|
|
|
|
int width;
|
|
|
|
|
int height;
|
2019-07-30 18:04:28 +02:00
|
|
|
|
2019-08-02 18:19:07 +02:00
|
|
|
bool valid;
|
2019-07-30 18:04:28 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
typedef tll(struct glyph) hash_entry_t;
|
|
|
|
|
|
2019-10-17 17:53:03 +02:00
|
|
|
struct font_fallback {
|
|
|
|
|
char *pattern;
|
|
|
|
|
struct font *font;
|
|
|
|
|
};
|
|
|
|
|
|
2019-07-30 18:04:28 +02:00
|
|
|
struct font {
|
2019-10-17 17:43:40 +02:00
|
|
|
char *name;
|
|
|
|
|
|
2019-10-16 22:18:57 +02:00
|
|
|
mtx_t lock;
|
2019-07-30 18:04:28 +02:00
|
|
|
FT_Face face;
|
|
|
|
|
int load_flags;
|
|
|
|
|
int render_flags;
|
|
|
|
|
FT_LcdFilter lcd_filter;
|
2019-10-16 22:18:57 +02:00
|
|
|
|
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
|
|
|
double pixel_size_fixup; /* Scale factor - should only be used with ARGB32 glyphs */
|
2019-08-19 17:45:21 +02:00
|
|
|
bool bgr; /* True for FC_RGBA_BGR and FC_RGBA_VBGR */
|
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
|
|
|
|
2019-07-30 18:04:28 +02:00
|
|
|
struct {
|
2019-08-16 22:06:06 +02:00
|
|
|
int position;
|
|
|
|
|
int thickness;
|
2019-07-30 18:04:28 +02:00
|
|
|
} underline;
|
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
|
|
|
|
2019-07-30 18:04:28 +02:00
|
|
|
struct {
|
2019-08-16 22:06:06 +02:00
|
|
|
int position;
|
|
|
|
|
int thickness;
|
2019-07-30 18:04:28 +02:00
|
|
|
} strikeout;
|
|
|
|
|
|
|
|
|
|
bool is_fallback;
|
2019-10-17 17:53:03 +02:00
|
|
|
tll(struct font_fallback) fallbacks;
|
2019-07-30 18:04:28 +02:00
|
|
|
|
2019-10-16 22:34:23 +02:00
|
|
|
size_t ref_counter;
|
|
|
|
|
|
2019-10-16 22:18:57 +02:00
|
|
|
/* Fields below are only valid for non-fallback fonts */
|
|
|
|
|
FcPattern *fc_pattern;
|
|
|
|
|
FcFontSet *fc_fonts;
|
|
|
|
|
int fc_idx;
|
2019-10-17 17:06:42 +02:00
|
|
|
struct font **fc_loaded_fallbacks; /* fc_fonts->nfont array */
|
2019-10-16 22:18:57 +02:00
|
|
|
|
2019-10-17 17:12:04 +02:00
|
|
|
hash_entry_t **glyph_cache;
|
2019-07-30 18:04:28 +02:00
|
|
|
};
|
|
|
|
|
|
2019-10-16 21:52:12 +02:00
|
|
|
struct font *font_from_name(font_list_t names, const char *attributes);
|
2019-08-02 18:19:07 +02:00
|
|
|
const struct glyph *font_glyph_for_wc(struct font *font, wchar_t wc);
|
2019-07-28 21:03:38 +02:00
|
|
|
void font_destroy(struct font *font);
|