[gnome-contacts] Avatar: Use icon on fallback avater when no label and use cantarell



commit 19ad1fe584d2e10f6bc7ef8479529e02c4284089
Author: Julian Sparber <julian sparber net>
Date:   Thu Jul 25 12:36:22 2019 +0200

    Avatar: Use icon on fallback avater when no label and use cantarell

 src/contacts-avatar-utils.vala | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)
---
diff --git a/src/contacts-avatar-utils.vala b/src/contacts-avatar-utils.vala
index ff51d2d..15e8416 100644
--- a/src/contacts-avatar-utils.vala
+++ b/src/contacts-avatar-utils.vala
@@ -30,7 +30,7 @@ namespace Contacts.AvatarUtils {
     if (label) {
       string? initials = extract_initials_from_name(name);
       if (initials != null) {
-        string font = "Sans %d".printf((int) GLib.Math.ceil(size / 2.5));
+        string font = "Cantarell Ultra-Bold %d".printf((int) GLib.Math.ceil(size / 3));
 
         cr.set_source_rgb(1.0, 1.0, 1.0);
         Pango.Layout layout = Pango.cairo_create_layout(cr);
@@ -46,6 +46,22 @@ namespace Contacts.AvatarUtils {
           );
         Pango.cairo_show_layout(cr, layout);
       }
+    } else {
+      try {
+        var theme = Gtk.IconTheme.get_default ();
+        var fallback_avatar = theme.lookup_icon ("avatar-default",
+                                                 size * 1/2,
+                                                 Gtk.IconLookupFlags.FORCE_SYMBOLIC);
+        Gdk.RGBA fg_color = { 1, 1, 1, 1 };
+        var icon_pixbuf = fallback_avatar.load_symbolic (fg_color);
+        var x = (double) size / 2.0 - (double) icon_pixbuf.width / 2.0;
+        // We also add a offset to the height to visually center the icon
+        var y = (double) size / 2.0 - (double) icon_pixbuf.height / 2.0 - (2 * size / 100.0);
+        Gdk.cairo_set_source_pixbuf (cr, icon_pixbuf, x, y);
+        cr.paint ();
+      } catch (Error e) {
+        warning ("Couldn't get default avatar icon: %s", e.message);
+      }
     }
 
     return Gdk.pixbuf_get_from_surface(


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]