From 383c93a41589a42fb657ae8cba7991b9cb6f4a4f Mon Sep 17 00:00:00 2001 From: Daiki Ueno Date: Thu, 18 Aug 2011 18:06:52 +0900 Subject: [PATCH] Fix fit-size calculation. --- eek/eek-gtk-renderer.c | 14 ++++++++++---- eek/eek-renderer.c | 13 +++++++++++-- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/eek/eek-gtk-renderer.c b/eek/eek-gtk-renderer.c index 3fe996fd..c88e685e 100644 --- a/eek/eek-gtk-renderer.c +++ b/eek/eek-gtk-renderer.c @@ -87,10 +87,16 @@ eek_gtk_renderer_real_render_key_icon (EekRenderer *self, width = gdk_pixbuf_get_width (pixbuf); height = gdk_pixbuf_get_height (pixbuf); - if (bounds.width * height < bounds.height * width) - scale = bounds.width / width; - else - scale = bounds.height / height; + if (bounds.height * width / bounds.width <= height) + scale = width / bounds.width; + else if (bounds.width * height / bounds.height <= width) + scale = height / bounds.height; + else { + if (bounds.width * height < bounds.height * width) + scale = bounds.width / width; + else + scale = bounds.height / height; + } cairo_save (cr); cairo_translate (cr, diff --git a/eek/eek-renderer.c b/eek/eek-renderer.c index 942376bc..6fc0cbb8 100644 --- a/eek/eek-renderer.c +++ b/eek/eek-renderer.c @@ -880,8 +880,17 @@ eek_renderer_set_allocation_size (EekRenderer *renderer, priv->allocation_height = height; eek_element_get_bounds (EEK_ELEMENT(priv->keyboard), &bounds); - scale = width > height ? height / bounds.height : - width / bounds.width; + + if (bounds.height * width / bounds.width <= height) + scale = width / bounds.width; + else if (bounds.width * height / bounds.height <= width) + scale = height / bounds.height; + else { + if (bounds.width * height < bounds.height * width) + scale = bounds.width / width; + else + scale = bounds.height / height; + } if (scale != priv->scale) { priv->scale = scale;