Linux: Fix rendering of emoji when using scalable fonts such as Segoe UI Emoji

This commit is contained in:
Kovid Goyal 2022-02-06 13:20:55 +05:30
parent f047678711
commit dddff91fad
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 17 additions and 14 deletions

View File

@ -103,6 +103,8 @@ Detailed list of changes
for the :doc:`launch <launch>` command to be used for pager positioning.
(:iss:`4462`)
- Linux: Fix rendering of emoji when using scalable fonts such as Segoe UI Emoji
0.24.2 [2022-02-03]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

View File

@ -522,19 +522,20 @@ detect_right_edge(ProcessedBitmap *ans) {
static bool
render_color_bitmap(Face *self, int glyph_id, ProcessedBitmap *ans, unsigned int cell_width, unsigned int cell_height, unsigned int num_cells, unsigned int baseline UNUSED) {
unsigned short best = 0, diff = USHRT_MAX;
const short limit = self->face->num_fixed_sizes;
for (short i = 0; i < limit; i++) {
unsigned short w = self->face->available_sizes[i].width;
unsigned short d = w > (unsigned short)cell_width ? w - (unsigned short)cell_width : (unsigned short)cell_width - w;
if (d < diff) {
diff = d;
best = i;
if (self->face->num_fixed_sizes > 0) {
const short limit = self->face->num_fixed_sizes;
for (short i = 0; i < limit; i++) {
unsigned short w = self->face->available_sizes[i].width;
unsigned short d = w > (unsigned short)cell_width ? w - (unsigned short)cell_width : (unsigned short)cell_width - w;
if (d < diff) {
diff = d;
best = i;
}
}
}
FT_Error error = FT_Select_Size(self->face, best);
if (error) { set_freetype_error("Failed to set char size for non-scalable font, with error:", error); return false; }
if (!load_glyph(self, glyph_id, FT_LOAD_COLOR)) return false;
FT_Set_Char_Size(self->face, 0, self->char_height, self->xdpi, self->ydpi);
FT_Error error = FT_Select_Size(self->face, best);
if (error) { set_freetype_error("Failed to set char size for non-scalable font, with error:", error); return false; }
} else FT_Set_Char_Size(self->face, 0, self->char_height, self->xdpi, self->ydpi);
if (!load_glyph(self, glyph_id, FT_LOAD_COLOR | FT_LOAD_RENDER)) return false;
FT_Bitmap *bitmap = &self->face->glyph->bitmap;
if (bitmap->pixel_mode != FT_PIXEL_MODE_BGRA) return false;
ans->buf = bitmap->buffer;

View File

@ -134,7 +134,7 @@ choose_bitmap_size(FT_Face face, FT_UInt desired_height) {
static void
set_pixel_size(RenderCtx *ctx, Face *face, FT_UInt sz, bool get_metrics UNUSED) {
if (sz != face->pixel_size) {
if (FT_HAS_COLOR(face->freetype)) sz = choose_bitmap_size(face->freetype, font_units_to_pixels_y(main_face.freetype, main_face.freetype->height));
if (face->freetype->num_fixed_sizes > 0 && FT_HAS_COLOR(face->freetype)) choose_bitmap_size(face->freetype, font_units_to_pixels_y(main_face.freetype, main_face.freetype->height));
else FT_Set_Pixel_Sizes(face->freetype, sz, sz);
hb_ft_font_changed(face->hb);
hb_ft_font_set_load_flags(face->hb, get_load_flags(face->hinting, face->hintstyle, FT_LOAD_DEFAULT));
@ -304,7 +304,7 @@ render_run(RenderCtx *ctx, RenderState *rs) {
hb_glyph_info_t *info = hb_buffer_get_glyph_infos(hb_buffer, NULL);
hb_glyph_position_t *positions = hb_buffer_get_glyph_positions(hb_buffer, NULL);
int baseline = font_units_to_pixels_y(face, face->ascender);
int load_flags = get_load_flags(rs->current_face->hinting, rs->current_face->hintstyle, has_color ? FT_LOAD_COLOR : FT_LOAD_RENDER);
int load_flags = get_load_flags(rs->current_face->hinting, rs->current_face->hintstyle, FT_LOAD_RENDER | (has_color ? FT_LOAD_COLOR : 0));
float pos = rs->x;
unsigned int limit = len;
for (unsigned int i = 0; i < len; i++) {