mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-05 04:06:08 -05:00
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.
55 lines
1 KiB
C
55 lines
1 KiB
C
#pragma once
|
|
|
|
#include <stdbool.h>
|
|
#include <threads.h>
|
|
|
|
#include <ft2build.h>
|
|
#include FT_FREETYPE_H
|
|
#include FT_LCD_FILTER_H
|
|
#include <cairo.h>
|
|
|
|
#include "tllist.h"
|
|
//#include "terminal.h"
|
|
|
|
typedef tll(const char *) font_list_t;
|
|
|
|
struct glyph {
|
|
wchar_t wc;
|
|
int width;
|
|
|
|
cairo_surface_t *surf;
|
|
int left;
|
|
int top;
|
|
|
|
double pixel_size_fixup;
|
|
};
|
|
|
|
typedef tll(struct glyph) hash_entry_t;
|
|
|
|
struct font {
|
|
FT_Face face;
|
|
int load_flags;
|
|
int render_flags;
|
|
FT_LcdFilter lcd_filter;
|
|
double pixel_size_fixup; /* Scale factor - should only be used with ARGB32 glyphs */
|
|
|
|
struct {
|
|
double position;
|
|
double thickness;
|
|
} underline;
|
|
|
|
struct {
|
|
double position;
|
|
double thickness;
|
|
} strikeout;
|
|
|
|
bool is_fallback;
|
|
tll(char *) fallbacks;
|
|
|
|
hash_entry_t **cache;
|
|
mtx_t lock;
|
|
};
|
|
|
|
bool font_from_name(font_list_t names, const char *attributes, struct font *result);
|
|
const struct glyph *font_glyph_for_utf8(struct font *font, const char *utf8);
|
|
void font_destroy(struct font *font);
|