summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDebarshi Ray <debarshir@gnome.org>2016-12-15 10:51:06 +0100
committerDebarshi Ray <debarshir@gnome.org>2016-12-15 14:15:53 +0100
commit78a910b0440854f97af80a9b0bd8cb4a3d3a06e1 (patch)
tree301d2e21100bb43ebefc8744a88660297bbc2fa1
parent3ed74952612a5e6dbde3f5785b40141fae760c60 (diff)
downloadlibgd-78a910b0440854f97af80a9b0bd8cb4a3d3a06e1.tar.gz
main-view: Fix the size and offset of the counter icon on HiDpi
The cairo_surface_create_similar API expects the width and height to be in device-space units, not pixels. So either we need to scale down the outputs of cairo_image_surface_get_{width, height}, or we need to use cairo_surface_create_similar_image. I prefer the latter because it makes it obvious that we are interested in image surfaces. Note that unlike cairo_surface_create_similar, we need to manually set the device scale because cairo_surface_create_similar_image doesn't inherit it. For the rest of the drawing and positioning code, we continue using device-space units as before. https://bugzilla.gnome.org/show_bug.cgi?id=776133
-rw-r--r--libgd/gd-main-view.c31
1 files changed, 24 insertions, 7 deletions
diff --git a/libgd/gd-main-view.c b/libgd/gd-main-view.c
index 0e3688f..c4fa561 100644
--- a/libgd/gd-main-view.c
+++ b/libgd/gd-main-view.c
@@ -25,6 +25,7 @@
#include "gd-main-icon-view.h"
#include "gd-main-list-view.h"
+#include <math.h>
#include <cairo-gobject.h>
#define MAIN_VIEW_TYPE_INITIAL -1
@@ -249,10 +250,16 @@ gd_main_view_get_counter_icon (GdMainView *self,
GtkStyleContext *context;
cairo_t *cr, *emblem_cr;
cairo_surface_t *surface, *emblem_surface;
- gint width, height;
+ gint height;
+ gint height_scaled;
+ gint width;
+ gint width_scaled;
gint layout_width, layout_height;
gint emblem_size;
+ gint emblem_size_scaled;
gdouble scale;
+ gdouble scale_x;
+ gdouble scale_y;
gchar *str;
PangoLayout *layout;
PangoAttrList *attr_list;
@@ -264,18 +271,28 @@ gd_main_view_get_counter_icon (GdMainView *self,
gtk_style_context_save (context);
gtk_style_context_add_class (context, "documents-counter");
- width = cairo_image_surface_get_width (base);
- height = cairo_image_surface_get_height (base);
+ width_scaled = cairo_image_surface_get_width (base);
+ height_scaled = cairo_image_surface_get_height (base);
+ cairo_surface_get_device_scale (base, &scale_x, &scale_y);
+
+ width = width_scaled / (gint) floor (scale_x),
+ height = height_scaled / (gint) floor (scale_y);
+
+ surface = cairo_surface_create_similar_image (base, CAIRO_FORMAT_ARGB32,
+ width_scaled, height_scaled);
+ cairo_surface_set_device_scale (surface, scale_x, scale_y);
- surface = cairo_surface_create_similar (base, CAIRO_CONTENT_COLOR_ALPHA,
- width, height);
cr = cairo_create (surface);
cairo_set_source_surface (cr, base, 0, 0);
cairo_paint (cr);
+ emblem_size_scaled = MIN (width_scaled / 2, height_scaled / 2);
emblem_size = MIN (width / 2, height / 2);
- emblem_surface = cairo_surface_create_similar (base, CAIRO_CONTENT_COLOR_ALPHA,
- emblem_size, emblem_size);
+
+ emblem_surface = cairo_surface_create_similar_image (base, CAIRO_FORMAT_ARGB32,
+ emblem_size_scaled, emblem_size_scaled);
+ cairo_surface_set_device_scale (emblem_surface, scale_x, scale_y);
+
emblem_cr = cairo_create (emblem_surface);
gtk_render_background (context, emblem_cr,
0, 0, emblem_size, emblem_size);