mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-03-31 07:11:09 -04:00
font: tentative support for BGR, V-RGB and V-BGR
This commit is contained in:
parent
d84b485202
commit
9029478e8c
2 changed files with 23 additions and 7 deletions
29
font.c
29
font.c
|
|
@ -125,9 +125,9 @@ from_font_set(FcPattern *pattern, FcFontSet *fonts, int start_idx, const font_li
|
||||||
load_flags |= FT_LOAD_DEFAULT | FT_LOAD_NO_HINTING | FT_LOAD_TARGET_NORMAL;
|
load_flags |= FT_LOAD_DEFAULT | FT_LOAD_NO_HINTING | FT_LOAD_TARGET_NORMAL;
|
||||||
else if (fc_hinting && fc_hintstyle == FC_HINT_SLIGHT)
|
else if (fc_hinting && fc_hintstyle == FC_HINT_SLIGHT)
|
||||||
load_flags |= FT_LOAD_DEFAULT | FT_LOAD_TARGET_LIGHT;
|
load_flags |= FT_LOAD_DEFAULT | FT_LOAD_TARGET_LIGHT;
|
||||||
else if (fc_rgba == FC_RGBA_RGB)
|
else if (fc_rgba == FC_RGBA_RGB || fc_rgba == FC_RGBA_BGR)
|
||||||
load_flags |= FT_LOAD_DEFAULT | FT_LOAD_TARGET_LCD;
|
load_flags |= FT_LOAD_DEFAULT | FT_LOAD_TARGET_LCD;
|
||||||
else if (fc_rgba == FC_RGBA_VRGB)
|
else if (fc_rgba == FC_RGBA_VRGB || fc_rgba == FC_RGBA_VBGR)
|
||||||
load_flags |= FT_LOAD_DEFAULT | FT_LOAD_TARGET_LCD_V;
|
load_flags |= FT_LOAD_DEFAULT | FT_LOAD_TARGET_LCD_V;
|
||||||
else
|
else
|
||||||
load_flags |= FT_LOAD_DEFAULT | FT_LOAD_TARGET_NORMAL;
|
load_flags |= FT_LOAD_DEFAULT | FT_LOAD_TARGET_NORMAL;
|
||||||
|
|
@ -144,9 +144,9 @@ from_font_set(FcPattern *pattern, FcFontSet *fonts, int start_idx, const font_li
|
||||||
if (!fc_antialias)
|
if (!fc_antialias)
|
||||||
render_flags |= FT_RENDER_MODE_MONO;
|
render_flags |= FT_RENDER_MODE_MONO;
|
||||||
else {
|
else {
|
||||||
if (fc_rgba == FC_RGBA_RGB)
|
if (fc_rgba == FC_RGBA_RGB || fc_rgba == FC_RGBA_BGR)
|
||||||
render_flags |= FT_RENDER_MODE_LCD;
|
render_flags |= FT_RENDER_MODE_LCD;
|
||||||
else if (fc_rgba == FC_RGBA_VRGB)
|
else if (fc_rgba == FC_RGBA_VRGB || fc_rgba == FC_RGBA_VBGR)
|
||||||
render_flags |= FT_RENDER_MODE_LCD_V;
|
render_flags |= FT_RENDER_MODE_LCD_V;
|
||||||
else
|
else
|
||||||
render_flags |= FT_RENDER_MODE_NORMAL;
|
render_flags |= FT_RENDER_MODE_NORMAL;
|
||||||
|
|
@ -171,6 +171,7 @@ from_font_set(FcPattern *pattern, FcFontSet *fonts, int start_idx, const font_li
|
||||||
font->render_flags = render_flags;
|
font->render_flags = render_flags;
|
||||||
font->is_fallback = is_fallback;
|
font->is_fallback = is_fallback;
|
||||||
font->pixel_size_fixup = scalable ? pixel_fixup : 1.;
|
font->pixel_size_fixup = scalable ? pixel_fixup : 1.;
|
||||||
|
font->bgr = fc_rgba == FC_RGBA_BGR || fc_rgba == FC_RGBA_VBGR;
|
||||||
font->fc_idx = font_idx;
|
font->fc_idx = font_idx;
|
||||||
|
|
||||||
if (!is_fallback) {
|
if (!is_fallback) {
|
||||||
|
|
@ -279,7 +280,7 @@ hash_index(wchar_t wc)
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
glyph_for_wchar(struct font *font, wchar_t wc, struct glyph *glyph)
|
glyph_for_wchar(const struct font *font, wchar_t wc, struct glyph *glyph)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* LCD filter is per library instance. Thus we need to re-set it
|
* LCD filter is per library instance. Thus we need to re-set it
|
||||||
|
|
@ -428,9 +429,9 @@ glyph_for_wchar(struct font *font, wchar_t wc, struct glyph *glyph)
|
||||||
case FT_PIXEL_MODE_LCD:
|
case FT_PIXEL_MODE_LCD:
|
||||||
for (size_t r = 0; r < bitmap->rows; r++) {
|
for (size_t r = 0; r < bitmap->rows; r++) {
|
||||||
for (size_t c = 0; c < bitmap->width; c += 3) {
|
for (size_t c = 0; c < bitmap->width; c += 3) {
|
||||||
unsigned char _r = bitmap->buffer[r * bitmap->pitch + c + 0];
|
unsigned char _r = bitmap->buffer[r * bitmap->pitch + c + (font->bgr ? 2 : 0)];
|
||||||
unsigned char _g = bitmap->buffer[r * bitmap->pitch + c + 1];
|
unsigned char _g = bitmap->buffer[r * bitmap->pitch + c + 1];
|
||||||
unsigned char _b = bitmap->buffer[r * bitmap->pitch + c + 2];
|
unsigned char _b = bitmap->buffer[r * bitmap->pitch + c + (font->bgr ? 0 : 2)];
|
||||||
|
|
||||||
uint32_t *p = (uint32_t *)&data[r * stride + 4 * (c / 3)];
|
uint32_t *p = (uint32_t *)&data[r * stride + 4 * (c / 3)];
|
||||||
*p = _r << 16 | _g << 8 | _b;
|
*p = _r << 16 | _g << 8 | _b;
|
||||||
|
|
@ -438,6 +439,20 @@ glyph_for_wchar(struct font *font, wchar_t wc, struct glyph *glyph)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case FT_PIXEL_MODE_LCD_V:
|
||||||
|
/* Unverified */
|
||||||
|
for (size_t r = 0; r < bitmap->rows; r += 3) {
|
||||||
|
for (size_t c = 0; c < bitmap->width; c++) {
|
||||||
|
unsigned char _r = bitmap->buffer[(r + (font->bgr ? 2 : 0)) * bitmap->pitch + c];
|
||||||
|
unsigned char _g = bitmap->buffer[(r + 1) * bitmap->pitch + c];
|
||||||
|
unsigned char _b = bitmap->buffer[(r + (font->bgr ? 0 : 2)) * bitmap->pitch + c];
|
||||||
|
|
||||||
|
uint32_t *p = (uint32_t *)&data[r / 3 * stride + 4 * c];
|
||||||
|
*p = _r << 16 | _g << 8 | _b;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
abort();
|
abort();
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
1
font.h
1
font.h
|
|
@ -39,6 +39,7 @@ struct font {
|
||||||
int render_flags;
|
int render_flags;
|
||||||
FT_LcdFilter lcd_filter;
|
FT_LcdFilter lcd_filter;
|
||||||
double pixel_size_fixup; /* Scale factor - should only be used with ARGB32 glyphs */
|
double pixel_size_fixup; /* Scale factor - should only be used with ARGB32 glyphs */
|
||||||
|
bool bgr; /* True for FC_RGBA_BGR and FC_RGBA_VBGR */
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
int position;
|
int position;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue