Updating branch refs/heads/4.10_panel_support
         to cb13f27b1a2b14a412a260b58a42a35c50dffc92 (commit)
       from 71a87726f0cbbad1df2143c7f84d885a1b6df7e9 (commit)

commit cb13f27b1a2b14a412a260b58a42a35c50dffc92
Author: Igor Slepchin <igor.slepc...@gmail.com>
Date:   Mon Mar 25 16:50:53 2013 -0400

    Scale layout label text to the size of the button
    
    large text size will scale to the max size that fits into the button;
    medium size is 0.7 of that size; small is 0.475 of the max.
    
    The default text label size is now large.
    (largely cherry picked from commit e0fe4255033fab3615006ca23358bfbb7dba1604)

 panel-plugin/xfce4-xkb-plugin.c |    4 +-
 panel-plugin/xkb-cairo.c        |   82 +++++++++++++++++++++++++++------------
 panel-plugin/xkb-cairo.h        |   16 ++++----
 3 files changed, 67 insertions(+), 35 deletions(-)

diff --git a/panel-plugin/xfce4-xkb-plugin.c b/panel-plugin/xfce4-xkb-plugin.c
index 879346b..073fba7 100644
--- a/panel-plugin/xfce4-xkb-plugin.c
+++ b/panel-plugin/xfce4-xkb-plugin.c
@@ -297,7 +297,7 @@ xkb_load_config (t_xkb *xkb, const gchar *filename)
         xfce_rc_set_group (rcfile, NULL);
 
         xkb->display_type = xfce_rc_read_int_entry (rcfile, "display_type", 
DISPLAY_TYPE_IMAGE);
-        xkb->display_textsize = xfce_rc_read_int_entry (rcfile, 
"display_textsize", DISPLAY_TEXTSIZE_SMALL);
+        xkb->display_textsize = xfce_rc_read_int_entry (rcfile, 
"display_textsize", DISPLAY_TEXTSIZE_LARGE);
         xkb->settings->group_policy = xfce_rc_read_int_entry (rcfile, 
"group_policy", GROUP_POLICY_PER_APPLICATION);
 
         if (xkb->settings->group_policy != GROUP_POLICY_GLOBAL)
@@ -329,7 +329,7 @@ static void
 xkb_load_default (t_xkb *xkb)
 {
     xkb->display_type = DISPLAY_TYPE_IMAGE;
-    xkb->display_textsize = DISPLAY_TEXTSIZE_SMALL;
+    xkb->display_textsize = DISPLAY_TEXTSIZE_LARGE;
     xkb->settings->group_policy = GROUP_POLICY_PER_APPLICATION;
     xkb->settings->default_group = 0;
     xkb->settings->kbd_config = NULL;
diff --git a/panel-plugin/xkb-cairo.c b/panel-plugin/xkb-cairo.c
index 8a3a4ef..af598a7 100644
--- a/panel-plugin/xkb-cairo.c
+++ b/panel-plugin/xkb-cairo.c
@@ -27,7 +27,7 @@
 #include "xkb-util.h"
 #include "xfce4-xkb-plugin.h"
 
-#define XKB_PREFERRED_FONT "Courier New, Courier 10 Pitch, Monospace Bold %d"
+#define XKB_PREFERRED_FONT "Courier New, Courier 10 Pitch, Monospace Bold"
 
 #define xkb_cairo_arc_for_flag(cr, x, y, r, a1, a2) \
     xx = layoutx + width - 12 + x; \
@@ -126,28 +126,31 @@ xkb_cairo_draw_flag (cairo_t *cr,
 void
 xkb_cairo_draw_label (cairo_t *cr,
                       const gchar *group_name,
-                      gint panel_size,
-                      gint actual_width,
-                      gint actual_height,
-                      gint width,
-                      gint height,
-                      gint variant_markers_count,
-                      gint textsize,
-                      GdkColor fgcolor)
+                      const gint panel_size,
+                      const gint actual_width,
+                      const gint actual_height,
+                      const gint width,
+                      const gint height,
+                      const gint variant_markers_count,
+                      const gint textsize,
+                      const GdkColor fgcolor)
 {
     gchar *normalized_group_name;
-    gchar font_str[80];
     gint pango_width, pango_height;
-    gint layoutx, layouty;
+    double layoutx, layouty, text_width, text_height;
     double xx, yy;
+    double scalex, scaley;
     gint i;
-    gint radius;
+    double radius, diameter;
 
     PangoLayout *layout;
     PangoFontDescription *desc;
 
     g_assert (cr != NULL);
 
+    DBG ("actual width/height: %d/%d; markers: %d",
+         actual_width, actual_height, variant_markers_count);
+
     layout = pango_cairo_create_layout (cr);
     normalized_group_name = xkb_util_normalize_group_name (group_name);
 
@@ -160,40 +163,69 @@ xkb_cairo_draw_label (cairo_t *cr,
     }
 
     pango_layout_set_text (layout, normalized_group_name, -1);
+
+    desc = pango_font_description_from_string ( XKB_PREFERRED_FONT );
+    pango_layout_set_font_description (layout, desc);
+    pango_font_description_free (desc);
+
+    gdk_cairo_set_source_color (cr, &fgcolor);
+    pango_layout_get_pixel_size (layout, &pango_width, &pango_height);
+    DBG ("pango_width/height: %d/%d", pango_width, pango_height);
+
     switch (textsize){
         case DISPLAY_TEXTSIZE_SMALL:
         default:    /* catch misconfiguration */
-            g_sprintf (font_str, XKB_PREFERRED_FONT, (int)(0.375 * panel_size) 
);
+            scalex = scaley = 0.475;
             break;
         case DISPLAY_TEXTSIZE_MEDIUM:
-            g_sprintf (font_str, XKB_PREFERRED_FONT, (int)(0.600 * panel_size) 
);
+            scalex = scaley = 0.7;
             break;
         case DISPLAY_TEXTSIZE_LARGE:
-            g_sprintf (font_str, XKB_PREFERRED_FONT, (int)(0.900 * panel_size) 
);
+            scalex = scaley = 1;
             break;
     }
 
-    desc = pango_font_description_from_string (font_str);
-    pango_layout_set_font_description (layout, desc);
-    pango_font_description_free (desc);
+    DBG ("txt size scale x/y: %.2f/%.2f", scalex, scaley);
 
-    gdk_cairo_set_source_color (cr, &fgcolor);
-    pango_layout_get_pixel_size (layout, &pango_width, &pango_height);
+    text_height = actual_height * scaley;
+    scaley = text_height / pango_height;
+    radius = (text_height < 32) ? 1.2 : 2.5;
+    diameter = 2 * radius;
+
+    text_width  = actual_width * scalex;
+    if (actual_width - text_width < 3 + variant_markers_count * diameter)
+    {
+        text_width = actual_width - 3 - (variant_markers_count) * diameter;
+    }
+    else if (textsize == DISPLAY_TEXTSIZE_LARGE)
+    {
+        text_width -= 3;
+    }
 
-    layoutx = (int) (actual_width - (pango_width + variant_markers_count * 7)) 
/ 2;
-    layouty = (int) (actual_height - pango_height) / 2;
+    scalex =  text_width/pango_width;
+
+    layoutx = (actual_width -
+               (text_width + (variant_markers_count ? 3:0) +
+                variant_markers_count * diameter)) / 2;
+    layouty = (actual_height - text_height) / 2;
+
+    DBG ("text_width/height: %.2f/%.2f", text_width, text_height);
+    DBG ("layout x/y: %.2f/%.2f scale x/y: %.2f/%.2f, radius: %.2f",
+         layoutx, layouty, scalex, scaley, radius);
 
     xkb_cairo_move_to (cr, layoutx, layouty);
+    cairo_save (cr);
+    cairo_scale (cr, scalex, scaley);
     pango_cairo_show_layout (cr, layout);
+    cairo_restore (cr);
 
     for (i = 0; i < variant_markers_count; i++)
     {
         cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
         cairo_set_line_width (cr, 1);
-        radius = (panel_size < 32) ? 1.5 : 2.5;
         xkb_cairo_arc_for_label (cr,
-                layoutx + pango_width + 3 + (7 * i),
-                layouty + pango_height - (pango_height / 5),
+                layoutx + text_width + 3 + (diameter * i),
+                layouty + text_height - (text_height / 5),
                 radius, 0, 2 * G_PI
         );
         cairo_fill (cr);
diff --git a/panel-plugin/xkb-cairo.h b/panel-plugin/xkb-cairo.h
index 13b790a..4be2b24 100644
--- a/panel-plugin/xkb-cairo.h
+++ b/panel-plugin/xkb-cairo.h
@@ -46,14 +46,14 @@ void        xkb_cairo_draw_flag     (cairo_t *cr,
 
 void        xkb_cairo_draw_label    (cairo_t *cr,
                                      const gchar *group_name,
-                                     gint panel_size,
-                                     gint actual_width,
-                                     gint actual_height,
-                                     gint width,
-                                     gint height,
-                                     gint variant_markers_count,
-                                     gint textsize,
-                                     GdkColor fgcolor);
+                                     const gint panel_size,
+                                     const gint actual_width,
+                                     const gint actual_height,
+                                     const gint width,
+                                     const gint height,
+                                     const gint variant_markers_count,
+                                     const gint textsize,
+                                     const GdkColor fgcolor);
 
 #endif
 
_______________________________________________
Xfce4-commits mailing list
Xfce4-commits@xfce.org
https://mail.xfce.org/mailman/listinfo/xfce4-commits

Reply via email to