Commit 4b80f60
png thumbnails
Changed files (9)
modifiedlayout/style.cssmodifiedsrc/ContentDisplay.valamodifiedsrc/Font.valamodifiedsrc/FontDisplay.valamodifiedsrc/KeyBindings.valamodifiedsrc/MainWindow.valamodifiedsrc/Supplement.valamodifiedsrc/Toolbox.valamodifiedsrc/wscript
Diff
@@ -1,5 +1,7 @@ @charset "UTF-8"; +.clearBoth { clear:both; }+ body { } @@ -17,21 +19,45 @@ div.heading { color: #FFFFFF; } -div.format_box {- margin: auto auto;+div.menu_item {+ width: 100%;+ background-color: #CEDAE7; + color: #000000;+ margin: 0 0 2px 0;+ padding: 0 -3px 0 3px;+ cursor: default;+}++div.menu_item:hover {+ background-color: #E6ECF6; } div.inner_format_box {- background-color: #EFEFEF; + float: left; width: 170px; height: 200px;- margin-top: 50px;- margin-left: auto;- margin-right: auto; padding: 0 0 0 0;+ margin: 0 10px 0 0; top: 50%; } +div.recent_font {+ float: left;+ overflow: hidden;+ background-color: #EFEFEF; + width: 100px;+ height: 100px;+ margin: 5px 5px 5px 5px;+ font-size: 10pt;+ text-align: center;+ padding: 10px 10px 10px 10px;+ cursor: default;+}++div.recent_list {+ margin: 50px 0 0 0; +}+ h2 { font-size: 12pt; margin-left: 3px;@@ -47,3 +73,7 @@ h3 { input.text { width: 100%; }++span.one_line {+ overflow: hidden;+}@@ -147,7 +147,7 @@ class ContentDisplay : FontDisplay { t.set_default_color (1, 1, 1); } }-+ private void save () { SaveDialog s = new SaveDialog (); save_dialog (s);@@ -166,7 +166,7 @@ class ContentDisplay : FontDisplay { s.finished (); } }-+ private void new_file () { SaveDialog save = new SaveDialog (); save.finished.connect (() => {@@ -276,7 +276,7 @@ class ContentDisplay : FontDisplay { x = 10; foreach (var font in recent_fonts) {- string svg = font.get_svg_thumbnail ();+ string svg = ""; string font_file = (!) font.font_file; cr.save ();@@ -57,8 +57,6 @@ class Font : GLib.Object { bool modified = false; - private string? svg_thumbnail = null;- private string name = "typeface"; bool ttf_export = true;@@ -133,8 +131,8 @@ class Font : GLib.Object { return sb.str; }- - public File get_folder () {++ public string get_file_name () { string p = get_path (); int i = p.last_index_of ("/"); @@ -142,93 +140,22 @@ class Font : GLib.Object { i = p.last_index_of ("\\"); } - p = p.substring (0, i);+ p = p.substring (i + 1); - return File.new_for_path (p);+ return p; }-- public string get_svg_thumbnail () {- if (svg_thumbnail == null) {- svg_thumbnail = load_svg_thumbnail ();- }- - return (!) svg_thumbnail;- }- - public string load_svg_thumbnail () {- File file;- string line;- string? l;- DataInputStream dis;- - int start, stop, len;- - if (unlikely (font_file == null)) {- warning (@"File is null in load_svg_thumbnail.\n");- return "";- }- - file = File.new_for_path ((!)font_file);- - if (unlikely (!file.query_exists ())) {- warning (@"File '$((!)font_file)' doesn't exist.\n");- return "";- }-- try {- dis = new DataInputStream (file.read ());- - while ((l = dis.read_line (null)) != null) {- - assert (l != null);- - line = (!) l;- - if (likely (line.index_of ("<thumbnail svg=\"") == 0)) {- start = line.index_of ("\"");- stop = line.last_index_of ("\"");- - if (unlikely (start == -1 || stop == -1)) {- warning ("No delimter found for line: $line\n");- return "";- }- - len = stop - start;- - return line.substring (start, len);- }- }- - } catch (GLib.Error e) {- warning (@"$(e.message)");- } - warning (@"No thumbnail found in '$((!)font_file)'");- - return "";- }- - public string get_new_svg_thumbnail () {- Glyph? g;- Glyph glyph;- - g = get_glyph ("a");+ public File get_folder () {+ string p = get_path ();+ int i = p.last_index_of ("/"); - if (is_valid_thumbnail (g)) {- glyph = (!) g;- return glyph.get_svg_data ();+ if (i == -1) {+ i = p.last_index_of ("\\"); } - for (int i = 0; i < 100; i++) {- g = get_glyph_indice (i);- - if (is_valid_thumbnail (g)) {- glyph = (!) g;- return glyph.get_svg_data ();- }- }+ p = p.substring (0, i); - return "";+ return File.new_for_path (p); } bool is_valid_thumbnail (Glyph? g) {@@ -375,16 +302,16 @@ class Font : GLib.Object { g.left_limit = -33; g.right_limit = 33; - p.add (-30, 30);- p.add (30, 30);- p.add (30, -30);- p.add (-30, -30);+ p.add (-20, 20);+ p.add (20, 20);+ p.add (20, -20);+ p.add (-20, -20); p.close (); - i.add (-25, 25);- i.add (25, 25);- i.add (25, -25);- i.add (-25, -25);+ i.add (-15, 15);+ i.add (15, 15);+ i.add (15, -15);+ i.add (-15, -15); i.reverse (); i.close (); @@ -539,6 +466,8 @@ class Font : GLib.Object { } modified = false;+ add_thumbnail ();+ Preferences.add_recent_files (get_path ()); return r; }@@ -563,8 +492,6 @@ class Font : GLib.Object { os.put_string ("<font>\n"); - os.put_string (@"<thumbnail svg=\"$(get_new_svg_thumbnail ())\"/>\n");- os.put_string ("\n"); os.put_string (@"<name>$(get_name ())</name>\n"); @@ -726,9 +653,48 @@ class Font : GLib.Object { return loaded; }- ++ private void add_thumbnail () {+ File f = Supplement.get_thumbnail_directory ().get_child (@"$((!) get_file_name ()).png");+ Glyph? gl = get_glyph ("a");+ Glyph g;+ ImageSurface img;+ Context cr;+ double gx, gy;+ double x1, x2, y1, y2;++ if (gl == null) {+ print ("no glyph a\n");+ glyph_cache.print_all ();+ }++ if (gl == null) {+ gl = get_glyph_indice (4);+ } + + if (gl == null) {+ gl = get_not_def_character ();+ }+ + g = (!) gl;+ + g.boundries (out x1, out y1, out x2, out y2);+ + gx = 0;+ gy = y2 - y1;+ + img = new ImageSurface (Format.ARGB32, (int) (x2 - x1) + 5, (int) (y2 - y1) + 3);+ cr = new Context (img);+ + Svg.draw_svg_path (cr, g.get_svg_data (), gx, gy, 1.0); + + img.write_to_png ((!) f.get_path ());+ }+ /** Callbackt function for finishing parsing of font file. */ public void loading_finished_callback () {+ add_thumbnail ();+ Preferences.add_recent_files (get_path ()); print ("Done Loading.\n"); } @@ -886,6 +852,7 @@ class Font : GLib.Object { delete doc; Parser.cleanup (); + loading_finished_callback (); return true; } @@ -176,14 +176,12 @@ public abstract class FontDisplay : GLib.Object { } if (j >= property.length ()) {- warning (@"key $k not found in property list");+ warning (@"key \"$k\" not found in property list, value: $v"); return; } cb = call.nth (j).data; cb.call (v);- - print (@"Got $k -> $v\n"); } }@@ -94,7 +94,12 @@ class BindingList { new CloseTab (), new UndoAction (), new Copy (),- new Paste ()+ new Paste (),+ new Save (),+ new NewFile (),+ new Load (),+ new ShowKerningContext (),+ new ShowPreview () }; nc = default_bindings;@@ -103,6 +108,63 @@ class BindingList { } } ++class ShowPreview : ShortCut {+ + public override void run () {+ MenuTab.preview ();+ }+ + public override uint get_default_modifier () { return CTRL; }+ public override uint get_default_key () { return ','; } + public override unowned string get_description () { return "Preview"; }+}+++class ShowKerningContext : ShortCut {+ + public override void run () {+ MenuTab.show_kerning_context ();+ }+ + public override uint get_default_modifier () { return CTRL; }+ public override uint get_default_key () { return 'k'; } + public override unowned string get_description () { return "Kerning context"; }+}++class Load : ShortCut {+ + public override void run () {+ MenuTab.load ();+ }+ + public override uint get_default_modifier () { return CTRL; }+ public override uint get_default_key () { return 'o'; } + public override unowned string get_description () { return "Open file"; }+}++class NewFile : ShortCut {+ + public override void run () {+ MenuTab.new_file ();+ }+ + public override uint get_default_modifier () { return CTRL; }+ public override uint get_default_key () { return 'n'; } + public override unowned string get_description () { return "New file"; }+}++class Save : ShortCut {+ + public override void run () {+ MenuTab.save ();+ }+ + public override uint get_default_modifier () { return CTRL; }+ public override uint get_default_key () { return 's'; } + public override unowned string get_description () { return "Save"; }+}+ class Paste : ShortCut { public override void run () {@@ -530,11 +592,13 @@ class KeyBindings { } } + /* // FIXA foreach (Tool t in MainWindow.get_content_display ().tools) { if (t.key == event.keyval && t.modifier_flag == modifier) { t.select_action (t); } }+ * */ } } @@ -35,7 +35,7 @@ public class MainWindow : Gtk.Window { static GlyphCanvas glyph_canvas; static MainWindow singleton; static KeyBindings key_bindings; - static ContentDisplay content; + static MenuTab content; static TooltipArea tool_tip; static DrawingArea margin_bottom; @@ -51,7 +51,7 @@ public class MainWindow : Gtk.Window { glyph_canvas = new GlyphCanvas (); tools = new Toolbox (glyph_canvas); tabs = new TabBar (); - content = new ContentDisplay (); + content = new MenuTab (); tool_tip = new TooltipArea (); margin_bottom = new DrawingArea (); @@ -69,7 +69,6 @@ public class MainWindow : Gtk.Window { html_canvas = new WebView (); html_canvas.title_changed.connect ((p, s) => { - print (@"property $s\n"); FontDisplay fd = get_current_display (); fd.process_property (s); }); @@ -109,7 +108,7 @@ public class MainWindow : Gtk.Window { } }); - // Hide this canvas when windown is realized and flip canvas + // Hide this canvas when window is realized and flip canvas // visibility in tab selection signal. html_canvas.expose_event.connect ((t, e) => { glyph_canvas.set_visible (false); @@ -121,7 +120,7 @@ public class MainWindow : Gtk.Window { tabs.add_unique_tab (content, 60, true); tabs.add_unique_tab (over_view, 75, false); - tabs.select_tab_name ("File"); + tabs.select_tab_name ("Menu"); canvas_box = new HBox (false, 0); canvas_box.child = (glyph_canvas); @@ -261,9 +260,9 @@ public class MainWindow : Gtk.Window { return over_view; } - internal static ContentDisplay get_content_display () { - if (unlikely ((ContentDisplay?) get_singleton ().content == null)) { - warning ("ContentDisplay not instantiated."); + internal static MenuTab get_content_display () { + if (unlikely ((MenuTab?) get_singleton ().content == null)) { + warning ("MenuTab not instantiated."); } return get_singleton ().content; @@ -32,7 +32,17 @@ class Supplement { public static void new_font () { current_font = new Font (); } - + + public static File get_thumbnail_directory () { + File thumbnails = get_settings_directory ().get_child ("thumbnails"); + + if (!thumbnails.query_exists ()) { + DirUtils.create ((!) thumbnails.get_path (), 0xFFFFFF); + } + + return thumbnails; + } + public static File get_settings_directory () { File home = File.new_for_path (Environment.get_home_dir ()); File settings = home.get_child (".supplement"); @@ -827,11 +827,14 @@ class Toolbox : DrawingArea { } } + // FIXA:+ /* foreach (Tool t in MainWindow.get_content_display ().tools) { if (t.is_active ()) { return t; } }+ */ return null; }@@ -4,11 +4,9 @@ SUPPLEMENT_MAIN = [ 'BackgroundTool.vala', 'BackgroundSelection.vala', 'ExportTool.vala', - 'ExportPreferences.vala', 'FontDisplay.vala', 'CharDatabase.vala', 'Context.vala', - 'ContentDisplay.vala', 'CutBackgroundTool.vala', 'CutTool.vala', 'ClipTool.vala', @@ -28,6 +26,7 @@ SUPPLEMENT_MAIN = [ 'KeyBindings.vala', 'Line.vala', 'MainWindow.vala', + 'MenuTab.vala', 'MergeTool.vala', 'MoveTool.vala', 'IOThread.vala',