[sushi] font: add a font viewer plugin



commit 347f022fbb26a1b4fcd2eb75742e710a791d64cd
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Wed May 11 00:56:32 2011 -0400

    font: add a font viewer plugin

 data/style/gtk-style.css |    5 ++++
 src/Makefile-js.am       |    3 +-
 src/js/viewers/font.js   |   58 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 65 insertions(+), 1 deletions(-)
---
diff --git a/data/style/gtk-style.css b/data/style/gtk-style.css
index e1ef6ce..139144b 100644
--- a/data/style/gtk-style.css
+++ b/data/style/gtk-style.css
@@ -12,6 +12,11 @@ GtkLabel {
     color: #fff;
 }
 
+SushiFontWidget {
+    color: @np_fg_color;
+    padding: 2;
+}
+
 .spinner {
     color: @np_fg_color;
 }
diff --git a/src/Makefile-js.am b/src/Makefile-js.am
index 784062a..4ac381a 100644
--- a/src/Makefile-js.am
+++ b/src/Makefile-js.am
@@ -14,7 +14,8 @@ dist_jsviewers_DATA = \
     js/viewers/gst.js \
     js/viewers/audio.js \
     js/viewers/evince.js \
-    js/viewers/folder.js
+    js/viewers/folder.js \
+    js/viewers/font.js
 
 jsutildir = $(pkgdatadir)/js/util
 dist_jsutil_DATA = \
diff --git a/src/js/viewers/font.js b/src/js/viewers/font.js
new file mode 100644
index 0000000..b3a0200
--- /dev/null
+++ b/src/js/viewers/font.js
@@ -0,0 +1,58 @@
+let MimeHandler = imports.ui.mimeHandler;
+let GtkClutter = imports.gi.GtkClutter;
+let Gtk = imports.gi.Gtk;
+let GLib = imports.gi.GLib;
+
+let Sushi = imports.gi.Sushi;
+
+function FontRenderer(args) {
+    this._init(args);
+}
+
+FontRenderer.prototype = {
+    _init : function(args) {
+        this.moveOnClick = true;
+        this.canFullScreen = false;
+    },
+
+    render : function(file, mainWindow) {
+        this._fontWidget = new Sushi.FontWidget({ uri: file.get_uri() });
+        this._fontWidget.show();
+
+        this._fontWidget.connect
+        ("loaded",
+         Lang.bind (this,
+                    function() {
+                        if (this._fontWidget.get_realized())
+                            mainWindow.refreshSize();
+                        else
+                            this._fontWidget.connect("realize",
+                                                     function() {
+                                                         mainWindow.refreshSize();
+                                                     })}));
+
+        this._fontActor = new GtkClutter.Actor({ contents: this._fontWidget });
+
+        return this._fontActor;
+    },
+
+    getSizeForAllocation : function(allocation) {
+        let size = [ this._fontWidget.get_preferred_size()[1].width,
+                     this._fontWidget.get_preferred_size()[1].height ];
+
+        log ("allocation " + allocation[0] + " " + allocation[1] + " size " + size[0] + " " + size[1]);
+
+        if (size[0] > allocation[0])
+            size[0] = allocation[0];
+
+        if (size[1] > allocation[1])
+            size[1] = allocation[1];
+
+        return size;
+    }
+}
+
+let handler = new MimeHandler.MimeHandler();
+let renderer = new FontRenderer();
+
+handler.registerMime("application/x-font-ttf", renderer);



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