[gnome-documents] documents: store images in cairo surfaces



commit 59ae90741a1c4b560770a437a89faa00e1004b3c
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Tue Aug 6 15:46:23 2013 +0200

    documents: store images in cairo surfaces
    
    This adds support for HiDpi.

 src/documents.js |   19 ++++++++++++-------
 src/view.js      |    8 ++++----
 2 files changed, 16 insertions(+), 11 deletions(-)
---
diff --git a/src/documents.js b/src/documents.js
index 258bc18..f055f70 100644
--- a/src/documents.js
+++ b/src/documents.js
@@ -229,7 +229,7 @@ const DocCommon = new Lang.Class({
         this.author = null;
         this.mtime = null;
         this.resourceUrn = null;
-        this.pixbuf = null;
+        this.surface = null;
         this.origPixbuf = null;
         this.defaultAppName = null;
 
@@ -328,9 +328,10 @@ const DocCommon = new Lang.Class({
             icon = Utils.iconFromRdfType(this.rdfType);
 
         let iconInfo =
-            Gtk.IconTheme.get_default().lookup_by_gicon(icon, Utils.getIconSize(),
-                                                        Gtk.IconLookupFlags.FORCE_SIZE |
-                                                        Gtk.IconLookupFlags.GENERIC_FALLBACK);
+            Gtk.IconTheme.get_default().lookup_by_gicon_for_scale(icon, Utils.getIconSize(),
+                                                                  Application.application.getScaleFactor(),
+                                                                  Gtk.IconLookupFlags.FORCE_SIZE |
+                                                                  Gtk.IconLookupFlags.GENERIC_FALLBACK);
 
         let pixbuf = null;
         if (iconInfo != null) {
@@ -441,8 +442,9 @@ const DocCommon = new Lang.Class({
             function(object, res) {
                 try {
                     let stream = object.read_finish(res);
+                    let scale = Application.application.getScaleFactor();
                     GdkPixbuf.Pixbuf.new_from_stream_at_scale_async(stream,
-                        Utils.getIconSize(), Utils.getIconSize(),
+                        Utils.getIconSize() * scale, Utils.getIconSize() * scale,
                         true, null, Lang.bind(this,
                             function(object, res) {
                                 try {
@@ -470,7 +472,8 @@ const DocCommon = new Lang.Class({
     },
 
     _createSymbolicEmblem: function(name) {
-        let pix = Gd.create_symbolic_icon(name, Utils.getIconSize());
+        let pix = Gd.create_symbolic_icon(name, Utils.getIconSize() *
+                                          Application.application.getScaleFactor());
 
         if (!pix)
             pix = new Gio.ThemedIcon({ name: name });
@@ -534,7 +537,9 @@ const DocCommon = new Lang.Class({
             thumbnailedPixbuf = emblemedPixbuf;
         }
 
-        this.pixbuf = thumbnailedPixbuf;
+        this.surface = Gdk.cairo_surface_create_from_pixbuf(thumbnailedPixbuf,
+            Application.application.getScaleFactor(),
+            Application.application.getGdkWindow());
 
         this.emit('info-updated');
     },
diff --git a/src/view.js b/src/view.js
index 8eaa6de..3f40125 100644
--- a/src/view.js
+++ b/src/view.js
@@ -19,9 +19,9 @@
  *
  */
 
+const Cairo = imports.gi.cairo;
 const Gd = imports.gi.Gd;
 const Gdk = imports.gi.Gdk;
-const GdkPixbuf = imports.gi.GdkPixbuf;
 const Gettext = imports.gettext;
 const GLib = imports.gi.GLib;
 const GObject = imports.gi.GObject;
@@ -114,7 +114,7 @@ const ViewModel = new Lang.Class({
               GObject.TYPE_STRING,
               GObject.TYPE_STRING,
               GObject.TYPE_STRING,
-              GdkPixbuf.Pixbuf,
+              Cairo.Surface,
               GObject.TYPE_LONG,
               GObject.TYPE_BOOLEAN,
               GObject.TYPE_UINT ]);
@@ -144,7 +144,7 @@ const ViewModel = new Lang.Class({
         this.model.set(iter,
             [ 0, 1, 2, 3, 4, 5 ],
             [ doc.id, doc.uri, doc.name,
-              doc.author, doc.pixbuf, doc.mtime ]);
+              doc.author, doc.surface, doc.mtime ]);
 
         let treePath = this.model.get_path(iter);
         let treeRowRef = Gtk.TreeRowReference.new(this.model, treePath);
@@ -160,7 +160,7 @@ const ViewModel = new Lang.Class({
                     this.model.set(objectIter,
                         [ 0, 1, 2, 3, 4, 5 ],
                         [ doc.id, doc.uri, doc.name,
-                          doc.author, doc.pixbuf, doc.mtime ]);
+                          doc.author, doc.surface, doc.mtime ]);
             }));
     },
 


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