Clone in a terminal:
Commit 4b80f60
Johan Mattsson - 2012-08-08T10:35:24+00:00
4b80f607c130f89fbb1887ffd9f6d7895c81b074johan.mattsson.m@gmail.com

png thumbnails

Changed files (9)

Diff

diff --git a/layout/style.css b/layout/style.cssindex 1769986..842d379 100644--- a/layout/style.css+++ b/layout/style.css@@ -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;+}diff --git a/src/ContentDisplay.vala b/src/ContentDisplay.valaindex 2ad0e24..766ec44 100644--- a/src/ContentDisplay.vala+++ b/src/ContentDisplay.vala@@ -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 ();diff --git a/src/Font.vala b/src/Font.valaindex fd6ea8b..e342ee1 100644--- a/src/Font.vala+++ b/src/Font.vala@@ -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; 	} 	diff --git a/src/FontDisplay.vala b/src/FontDisplay.valaindex 5937aea..bf7826f 100644--- a/src/FontDisplay.vala+++ b/src/FontDisplay.vala@@ -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"); 	}  }diff --git a/src/KeyBindings.vala b/src/KeyBindings.valaindex 99072a9..da308bc 100644--- a/src/KeyBindings.vala+++ b/src/KeyBindings.vala@@ -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); 			} 		}+		* */ 	} } diff --git a/src/MainWindow.vala b/src/MainWindow.valaindex 5ab0f4a..95f727c 100644--- a/src/MainWindow.vala+++ b/src/MainWindow.vala@@ -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;
diff --git a/src/Supplement.vala b/src/Supplement.valaindex e717173..11459e0 100644--- a/src/Supplement.vala+++ b/src/Supplement.vala@@ -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");
diff --git a/src/Toolbox.vala b/src/Toolbox.valaindex 8bcd432..311473a 100644--- a/src/Toolbox.vala+++ b/src/Toolbox.vala@@ -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; 	}diff --git a/src/wscript b/src/wscriptindex aa0fbdd..88320d8 100644--- a/src/wscript+++ b/src/wscript@@ -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',

Contact

Email: johan.mattsson.m@gmail.com
Mastodon: typo.social/@birdfont
GitHub: johanmattssonm
LinkedIn: johan-mattsson-2ab324112