Honor the outputs scale factor

This commit is contained in:
Guido Günther
2019-07-13 16:18:23 +02:00
parent cd81aeb286
commit d0fa444a0e
3 changed files with 19 additions and 4 deletions

View File

@ -124,6 +124,8 @@ eek_gtk_keyboard_real_draw (GtkWidget *self,
eek_renderer_set_allocation_size (priv->renderer, eek_renderer_set_allocation_size (priv->renderer,
allocation.width, allocation.width,
allocation.height); allocation.height);
eek_renderer_set_scale_factor (priv->renderer,
gtk_widget_get_scale_factor (self));
} }
eek_renderer_render_keyboard (priv->renderer, cr); eek_renderer_render_keyboard (priv->renderer, cr);

View File

@ -48,6 +48,7 @@ typedef struct _EekRendererPrivate
gdouble allocation_width; gdouble allocation_width;
gdouble allocation_height; gdouble allocation_height;
gdouble scale; gdouble scale;
gint scale_factor; /* the outputs scale factor */
PangoFontDescription *ascii_font; PangoFontDescription *ascii_font;
PangoFontDescription *font; PangoFontDescription *font;
@ -499,20 +500,20 @@ render_key (EekRenderer *self,
#define SCALE 0.4 #define SCALE 0.4
if (eek_symbol_get_icon_name (symbol)) { if (eek_symbol_get_icon_name (symbol)) {
gint scale = priv->scale_factor;
cairo_surface_t *icon_surface = cairo_surface_t *icon_surface =
eek_renderer_get_icon_surface (self, eek_renderer_get_icon_surface (self,
eek_symbol_get_icon_name (symbol), eek_symbol_get_icon_name (symbol),
MIN(bounds.width, bounds.height), MIN(bounds.width, bounds.height),
1); scale);
if (icon_surface) { if (icon_surface) {
gint width = cairo_image_surface_get_width (icon_surface); gint width = cairo_image_surface_get_width (icon_surface);
gint height = cairo_image_surface_get_height (icon_surface); gint height = cairo_image_surface_get_height (icon_surface);
cairo_save (cr); cairo_save (cr);
cairo_translate (cr, cairo_translate (cr,
(bounds.width - width * SCALE) / 2, (bounds.width - width * SCALE / scale) / 2,
(bounds.height - height * SCALE) / 2); (bounds.height - height * SCALE / scale) / 2);
cairo_rectangle (cr, 0, 0, width, height); cairo_rectangle (cr, 0, 0, width, height);
cairo_scale (cr, SCALE, SCALE); cairo_scale (cr, SCALE, SCALE);
cairo_clip (cr); cairo_clip (cr);
@ -845,6 +846,7 @@ eek_renderer_init (EekRenderer *self)
priv->allocation_width = 0.0; priv->allocation_width = 0.0;
priv->allocation_height = 0.0; priv->allocation_height = 0.0;
priv->scale = 1.0; priv->scale = 1.0;
priv->scale_factor = 1;
priv->font = NULL; priv->font = NULL;
priv->outline_surface_cache = priv->outline_surface_cache =
g_hash_table_new_full (g_direct_hash, g_hash_table_new_full (g_direct_hash,
@ -1029,6 +1031,15 @@ eek_renderer_get_scale (EekRenderer *renderer)
return priv->scale; return priv->scale;
} }
void
eek_renderer_set_scale_factor (EekRenderer *renderer, gint scale)
{
g_return_if_fail (EEK_IS_RENDERER(renderer));
EekRendererPrivate *priv = eek_renderer_get_instance_private (renderer);
priv->scale_factor = scale;
}
PangoLayout * PangoLayout *
eek_renderer_create_pango_layout (EekRenderer *renderer) eek_renderer_create_pango_layout (EekRenderer *renderer)
{ {

View File

@ -82,6 +82,8 @@ void eek_renderer_get_key_bounds (EekRenderer *renderer,
gboolean rotate); gboolean rotate);
gdouble eek_renderer_get_scale (EekRenderer *renderer); gdouble eek_renderer_get_scale (EekRenderer *renderer);
void eek_renderer_set_scale_factor (EekRenderer *renderer,
gint scale);
PangoLayout *eek_renderer_create_pango_layout PangoLayout *eek_renderer_create_pango_layout
(EekRenderer *renderer); (EekRenderer *renderer);