From: Hans de Goede Date: Thu, 19 Sep 2019 14:05:17 +0000 (+0200) Subject: label: Properly deal with pixel-buffers with non-upright device_rotation X-Git-Tag: 0.9.5~39^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7ef8b7edbfae8ca96655b8263c2cc2f2392ecdfa;p=thirdparty%2Fplymouth.git label: Properly deal with pixel-buffers with non-upright device_rotation Fix the label plugin rendering garbled (wrong pitch) top to bottom text, instead of proper left to right text when the pixel-buffer has a device-rotation of rotate-clockwise or rotate-counter-clockwise. BugLink: https://bugzilla.redhat.com/show_bug.cgi?id=1753418 Signed-off-by: Hans de Goede --- diff --git a/src/plugins/controls/label/plugin.c b/src/plugins/controls/label/plugin.c index b552981c..f1b687a6 100644 --- a/src/plugins/controls/label/plugin.c +++ b/src/plugins/controls/label/plugin.c @@ -96,27 +96,58 @@ destroy_control (ply_label_plugin_control_t *label) static cairo_t * get_cairo_context_for_pixel_buffer (ply_label_plugin_control_t *label, - ply_pixel_buffer_t *pixel_buffer) + ply_pixel_buffer_t *pixel_buffer, + long *center_x, + long *center_y) { cairo_surface_t *cairo_surface; cairo_t *cairo_context; unsigned char *data; - ply_rectangle_t size; + unsigned long width, height; uint32_t scale; + ply_pixel_buffer_rotation_t rotation; data = (unsigned char *) ply_pixel_buffer_get_argb32_data (pixel_buffer); - ply_pixel_buffer_get_size (pixel_buffer, &size); + width = ply_pixel_buffer_get_width (pixel_buffer); + height = ply_pixel_buffer_get_height (pixel_buffer); scale = ply_pixel_buffer_get_device_scale (pixel_buffer); + rotation = ply_pixel_buffer_get_device_rotation (pixel_buffer); + + *center_x = width / 2; + *center_y = height / 2; + + if (rotation == PLY_PIXEL_BUFFER_ROTATE_CLOCKWISE || + rotation == PLY_PIXEL_BUFFER_ROTATE_COUNTER_CLOCKWISE) { + unsigned long tmp = width; + width = height; + height = tmp; + } cairo_surface = cairo_image_surface_create_for_data (data, CAIRO_FORMAT_ARGB32, - size.width * scale, - size.height * scale, - size.width * scale * 4); + width * scale, + height * scale, + width * scale * 4); cairo_surface_set_device_scale (cairo_surface, scale, scale); cairo_context = cairo_create (cairo_surface); cairo_surface_destroy (cairo_surface); + /* Rotate around the center */ + cairo_translate (cairo_context, width / 2, height / 2); + switch (rotation) { + case PLY_PIXEL_BUFFER_ROTATE_UPRIGHT: + break; + case PLY_PIXEL_BUFFER_ROTATE_UPSIDE_DOWN: + cairo_rotate (cairo_context, M_PI); + break; + case PLY_PIXEL_BUFFER_ROTATE_CLOCKWISE: + cairo_rotate (cairo_context, 0.5 * M_PI); + break; + case PLY_PIXEL_BUFFER_ROTATE_COUNTER_CLOCKWISE: + cairo_rotate (cairo_context, -0.5 * M_PI); + break; + } + return cairo_context; } @@ -202,13 +233,15 @@ draw_control (ply_label_plugin_control_t *label, { cairo_t *cairo_context; PangoLayout *pango_layout; + long center_x; + long center_y; int text_width; int text_height; if (label->is_hidden) return; - cairo_context = get_cairo_context_for_pixel_buffer (label, pixel_buffer); + cairo_context = get_cairo_context_for_pixel_buffer (label, pixel_buffer, ¢er_x, ¢er_y); pango_layout = init_pango_text_layout (cairo_context, label->text, label->fontdesc, label->alignment, label->width); @@ -216,11 +249,11 @@ draw_control (ply_label_plugin_control_t *label, label->area.width = (long) ((double) text_width / PANGO_SCALE); label->area.height = (long) ((double) text_height / PANGO_SCALE); - cairo_rectangle (cairo_context, x, y, width, height); + cairo_rectangle (cairo_context, x - center_x, y - center_y, width, height); cairo_clip (cairo_context); cairo_move_to (cairo_context, - label->area.x, - label->area.y); + label->area.x - center_x, + label->area.y - center_y); cairo_set_source_rgba (cairo_context, label->red, label->green,