Commit 48a2267
thumbnails for recent files
Changed files (5)
modifiedlayout/style.cssmodifiedsrc/Font.valamodifiedsrc/Glyph.valamodifiedsrc/MenuTab.valamodifiedsrc/Preferences.vala
Diff
@@ -41,12 +41,19 @@ div.inner_format_box { top: 50%; } +div.one_line {+ position: relative;+ top: 100px;+ overflow: hidden;+ white-space: nowrap; +}+ div.recent_font { float: left; overflow: hidden; background-color: #EFEFEF; width: 100px;- height: 100px;+ height: 120px; margin: 5px 5px 5px 5px; font-size: 10pt; text-align: center;@@ -73,7 +80,3 @@ h3 { input.text { width: 100%; }--span.one_line {- overflow: hidden;-}@@ -659,9 +659,11 @@ class Font : GLib.Object { Glyph? gl = get_glyph ("a"); Glyph g; ImageSurface img;+ ImageSurface img_scale; Context cr;- double gx, gy;- double x1, x2, y1, y2;+ double scale;+ + Font font = Supplement.get_current_font (); if (gl == null) { gl = get_glyph_indice (4);@@ -672,18 +674,29 @@ class Font : GLib.Object { } g = (!) gl;++ img = g.get_thumbnail ();+ scale = 70.0 / img.get_width (); - g.boundries (out x1, out y1, out x2, out y2);- - gx = 0;- gy = y2 - y1;+ if (scale > 70.0 / img.get_height ()) {+ scale = 70.0 / img.get_height ();+ } - img = new ImageSurface (Format.ARGB32, (int) (x2 - x1) + 5, (int) (y2 - y1) + 3);- cr = new Context (img);+ if (scale > 1) {+ scale = 1;+ }++ img_scale = new ImageSurface (Format.ARGB32, (int) (scale * img.get_width ()), (int) (scale * img.get_height ()));+ cr = new Context (img_scale); - Svg.draw_svg_path (cr, g.get_svg_data (), gx, gy, 1.0); + cr.scale (scale, scale);++ cr.save ();+ cr.set_source_surface (img, 0, 0);+ cr.paint ();+ cr.restore (); - img.write_to_png ((!) f.get_path ());+ img_scale.write_to_png ((!) f.get_path ()); } /** Callbackt function for finishing parsing of font file. */ @@ -132,12 +132,14 @@ class Glyph : FontDisplay { return; } - x1 = double.MAX;- y1 = double.MAX;- x2 = double.MIN;- y2 = double.MIN;+ x1 = path_list.first ().data.xmin;+ y1 = path_list.first ().data.ymin;+ x2 = path_list.first ().data.xmax;+ y2 = path_list.first ().data.ymax; foreach (Path p in path_list) {+ p.update_region_boundries ();+ if (p.xmin < x1) x1 = p.xmin; if (p.xmax > x2) x2 = p.xmax; if (p.ymin < y1) y1 = p.ymin;@@ -1566,6 +1568,26 @@ class Glyph : FontDisplay { undo_list.remove_link (undo_list.last ()); } + public ImageSurface get_thumbnail () {+ ImageSurface img;+ Context cr;+ double gx, gy;+ double x1, x2, y1, y2;+ Font font = Supplement.get_current_font ();++ remove_empty_paths ();+ boundries (out x1, out y1, out x2, out y2);+ + gx = left_limit - x1;+ gy = (y2 - y1) + font.base_line + y1;+ + img = new ImageSurface (Format.ARGB32, (int) (x2 - x1), (int) (y2 - y1));+ cr = new Context (img);+ + Svg.draw_svg_path (cr, get_svg_data (), gx, gy, 1.0); + + return img;+ } } }@@ -99,7 +99,7 @@ class MenuTab : FontDisplay { } public override void selected_canvas () {- MainWindow.get_webview ().reload_bypass_cache ();+ MainWindow.get_webview ().reload (); } public override string get_name () {@@ -172,16 +172,17 @@ foreach (Font font in recent_fonts) { fn = fn.substring (fn.replace ("\\", "/").last_index_of ("/") + 1); c.append ("""<div class="recent_font" """ + "onclick=\"call ('load:" + (!) font.font_file + "');\">");++ c.append ("<div class=\"one_line\">");+ c.append (fn);+ c.append ("</div>");+ c.append ("<img src=\""); c.append ((!) Supplement.get_thumbnail_directory ().get_path ()); c.append ("/"); c.append (fn);- c.append (".png\" alt=\"\"><br /><br />");- - c.append ("<span class=\"one_line\">");- c.append (fn);- c.append ("</span>");- + c.append (@".png?$(Random.next_int ())\" alt=\"\"><br /><br />");+ c.append ("</div>\n"); } @@ -56,28 +56,10 @@ class Preferences { return files; } - public static bool is_font_file (string file) {- // Valabug: char_count deal with non-ascii letters- // return (file.last_index_of (".ffi") != file.char_count () - 4);- int i = file.last_index_of (".ffi");- - if (i > -1) {- return true;- }- - i = file.last_index_of (".ttf");- return (i > -1);- }- public static void add_recent_files (string file) { string escaped_string = file.replace ("\t", "\\t"); StringBuilder recent = new StringBuilder (); - if (!is_font_file (file)) {- warning (@"\"$file\" is not a .ffi file.");- return;- }- foreach (string f in get_recent_files ()) { if (f != file) { recent.append (f.replace ("\t", "\\t"));