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;
}
{
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);
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,