From 1c2c9e622dee59f76540bfb4af460f06cff3ef2d Mon Sep 17 00:00:00 2001 From: Ray Strode Date: Wed, 3 Jan 2024 16:24:50 -0500 Subject: label-freetype: Fix rowstride bug with hidpi displays The freetype plugin correctly doubles the DPI on hidpi displays, but fails to account for the doubled pixels in display's pixel buffer. This commit adds a factor of 2 to the size and positioncomputations, to hopefully fix a row stride and a positioning bug. --- src/plugins/controls/label-freetype/plugin.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/plugins/controls/label-freetype/plugin.c b/src/plugins/controls/label-freetype/plugin.c index fc4446e0..9b2f369c 100644 --- a/src/plugins/controls/label-freetype/plugin.c +++ b/src/plugins/controls/label-freetype/plugin.c @@ -429,13 +429,13 @@ finish_measuring_line (ply_label_plugin_control_t *label, line_height.as_integer = label->face->size->metrics.ascender + -label->face->size->metrics.descender; - dimensions->x = label->area.x; + dimensions->x = label->area.x * label->scale_factor; dimensions->width = glyph_x->as_pixels_unit.pixels - dimensions->x; - label->area.width = MAX (label->area.width, dimensions->width); + label->area.width = MAX (label->area.width, dimensions->width / label->scale_factor); dimensions->height = line_height.as_pixels_unit.pixels; - label->area.height += dimensions->height; + label->area.height += dimensions->height / label->scale_factor; entry = calloc (1, sizeof(ply_rectangle_t)); *entry = *dimensions; @@ -459,6 +459,7 @@ align_lines (ply_label_plugin_control_t *label) return; width = label->width > 0? label->width : label->area.width; + width *= label->scale_factor; dimensions_of_lines = (ply_rectangle_t **) ply_array_get_pointer_elements (label->dimensions_of_lines); @@ -482,8 +483,8 @@ load_glyphs (ply_label_plugin_control_t *label, ply_utf8_string_iterator_t utf8_string_iterator; uint32_t *target = NULL; ply_rectangle_t target_size; - ply_freetype_unit_t glyph_x = { .as_pixels_unit = { .pixels = label->area.x } }; - ply_freetype_unit_t glyph_y = { .as_pixels_unit = { .pixels = label->area.y } }; + ply_freetype_unit_t glyph_x = { .as_pixels_unit = { .pixels = label->area.x * label->scale_factor } }; + ply_freetype_unit_t glyph_y = { .as_pixels_unit = { .pixels = label->area.y * label->scale_factor } }; FT_Error error; FT_UInt previous_glyph_index = 0; bool is_first_character = true; @@ -510,8 +511,8 @@ load_glyphs (ply_label_plugin_control_t *label, clear_dimensions_of_lines (label); line_dimensions = alloca (sizeof(ply_rectangle_t)); - line_dimensions->x = label->area.x; - line_dimensions->y = label->area.y; + line_dimensions->x = label->area.x * label->scale_factor; + line_dimensions->y = label->area.y * label->scale_factor; line_dimensions->width = 0; line_dimensions->height = 0; label->area.width = 0; @@ -535,6 +536,9 @@ load_glyphs (ply_label_plugin_control_t *label, if (target_size.height == 0) return; + + target_size.width *= label->scale_factor; + target_size.height *= label->scale_factor; } /* Go through each line */ -- cgit v1.2.3 From 345d28b3cbb898bcadfb430eeb58f3c2896a6648 Mon Sep 17 00:00:00 2001 From: Ray Strode Date: Thu, 4 Jan 2024 16:05:40 -0500 Subject: label-freetype: Force resize calculation when moving control When moving the label around we need to do a full recalculation of the metrics, because the position is part of the computation. --- src/plugins/controls/label-freetype/plugin.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/plugins/controls/label-freetype/plugin.c b/src/plugins/controls/label-freetype/plugin.c index 9b2f369c..917b04c0 100644 --- a/src/plugins/controls/label-freetype/plugin.c +++ b/src/plugins/controls/label-freetype/plugin.c @@ -854,15 +854,19 @@ show_control (ply_label_plugin_control_t *label, long y) { ply_rectangle_t dirty_area; + bool force_resize = false; dirty_area = label->area; label->display = display; - label->area.x = x; - label->area.y = y; + if (label->area.x != x || label->area.y != y) { + label->area.x = x; + label->area.y = y; + force_resize = true; + } label->is_hidden = false; - size_control (label, false); + size_control (label, force_resize); if (!label->is_hidden && label->display != NULL) ply_pixel_display_draw_area (label->display, -- cgit v1.2.3