Clone in a terminal:
Commit 6aad145
Johan Mattsson - 2013-08-28T07:17:50+00:00
6aad1458fe470d905e75c84eb4065c403b42d138johan.mattsson.m@gmail.com

GTK widget for name table entries

Changed files (3)

Diff

diff --git a/birdfont/GtkWindow.vala b/birdfont/GtkWindow.valaindex 1683506..99a3ab1 100644--- a/birdfont/GtkWindow.vala+++ b/birdfont/GtkWindow.vala@@ -42,6 +42,8 @@ public class GtkWindow : Gtk.Window, NativeWindow { 	VScrollbar scrollbar; 	bool scrollbar_supress_signal = false; 	+	DescriptionForm description;+	 	/** Text input and callbacks. */ 	public static bool text_input_is_active = false; 	TextListener text_listener = new TextListener ("", "", "");@@ -56,6 +58,8 @@ public class GtkWindow : Gtk.Window, NativeWindow { 	} 	 	public void init () {+		description = new DescriptionForm ();+		 		clipboard = Clipboard.get_for_display (get_display (), Gdk.SELECTION_CLIPBOARD); 		 		scrollbar.value_changed.connect (() => {@@ -96,8 +100,13 @@ public class GtkWindow : Gtk.Window, NativeWindow { 			MainWindow.glyph_canvas.set_current_glyph (fd); 			 			scrollbar.set_visible (fd.has_scrollbar ());-					-			if (html) {+			+			if (fd.get_name () == "Description") {+				description.update_fields ();+				description.canvas.set_visible (true);+				html_box.set_visible (false);+				glyph_canvas_area.set_visible (false);+			} else if (html) { 				layout_dir = FontDisplay.find_layout_dir (); 				uri = fd.get_uri (); 				@@ -177,9 +186,11 @@ public class GtkWindow : Gtk.Window, NativeWindow { 				 				html_box.set_visible (html); 				glyph_canvas_area.set_visible (!html);+				description.canvas.set_visible (false); 			} else { 				html_box.set_visible (false); 				glyph_canvas_area.set_visible (true);+				description.canvas.set_visible (false); 			} 		}); @@ -196,6 +207,7 @@ public class GtkWindow : Gtk.Window, NativeWindow { 		canvas_box = new HBox (false, 0); 		canvas_box.pack_start (glyph_canvas_area, true, true, 0); 		canvas_box.pack_start (html_box, true, true, 0);+		canvas_box.pack_start (description.canvas, true, true, 0); 		canvas_box.pack_start (scrollbar, false, true, 0);  		submit_text_button = new Button ();@@ -273,6 +285,8 @@ public class GtkWindow : Gtk.Window, NativeWindow { 		show_all (); 		 		scrollbar.set_visible (false);+		description.canvas.set_visible (false);+		 		hide_text_input (); 	} @@ -1103,4 +1117,135 @@ public class TooltipCanvas : DrawingArea { 	} } +public class DescriptionForm : GLib.Object {+	+	public ScrolledWindow canvas;+	public VBox box;+	+	Entry postscript_name;+	Entry font_name;+	Entry style;+	Entry full_name;+	Entry id;+	Entry version;++	TextView description;+	TextView copyright;+		+	public DescriptionForm () {+		box = new VBox (false, 6);+		canvas = new ScrolledWindow (null, null);+		canvas.set_policy (Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC);+		+		postscript_name = new Entry ();+		add_entry (postscript_name, _("Postscript Name"));+		postscript_name.changed.connect (() => {+			Font f = BirdFont.get_current_font ();+			f.postscript_name = postscript_name.text;+		});+		+		font_name = new Entry ();+		add_entry (font_name, _("Name"));+		font_name.changed.connect (() => {+			Font f = BirdFont.get_current_font ();+			f.name = font_name.text;+		});+		+		style = new Entry ();+		add_entry (style, _("Style"));+		style.changed.connect (() => {+			Font f = BirdFont.get_current_font ();+			f.subfamily = style.text;+		});+		+		full_name = new Entry ();+		add_entry (full_name, _("Full name (name and style)"));+		full_name.changed.connect (() => {+			Font f = BirdFont.get_current_font ();+			f.full_name = full_name.text;+		});+		+		id = new Entry ();+		add_entry (id, _("Unique identifier"));+		id.changed.connect (() => {+			Font f = BirdFont.get_current_font ();+			f.unique_identifier = id.text;+		});+		+		version = new Entry ();+		add_entry (version, _("Version"));+		version.changed.connect (() => {+			Font f = BirdFont.get_current_font ();+			f.version = version.text;+		});+		+		description = new TextView ();+		add_textview (description, _("Description"));+		description.get_buffer ().changed.connect (() => {+			Font f = BirdFont.get_current_font ();+			f.description = description.get_buffer ().text;+			print (description.get_buffer ().text);+		});++		copyright = new TextView ();+		add_textview (copyright, _("Copyright"));+		copyright.get_buffer ().changed.connect (() => {+			Font f = BirdFont.get_current_font ();+			f.copyright = copyright.get_buffer ().text;+		});+		+		update_fields ();+		+		canvas.add_with_viewport (box);+		canvas.show_all ();+	}+	+	public void update_fields () {+		Font font = BirdFont.get_current_font ();+		postscript_name.set_text (font.postscript_name);+		font_name.set_text (font.name);+		style.set_text (font.subfamily);+		full_name.set_text (font.full_name);+		id.set_text (font.unique_identifier);+		version.set_text (font.version);+		+		description.get_buffer ().set_text (font.description.dup ());+		copyright.get_buffer ().set_text (font.copyright.dup ());+	}+	+	void add_entry (Entry e, string label) {+		VBox vb;+		HBox hb;+		Label l;+		HBox margin;+		+		margin = new HBox (false, 6);+		l = new Label (label);+		vb = new VBox (false, 2);+		hb = new HBox (false, 2);+		hb.pack_start (l, false, false, 0);+		vb.pack_start (hb, true, true, 5);+		vb.pack_start (e, true, true, 0);+		margin.pack_start (vb, true, true, 5);+		box.pack_start (margin, false, false, 5);+	}++	void add_textview (TextView t, string label) {+		VBox vb;+		HBox hb;+		Label l;+		HBox margin;+		+		margin = new HBox (false, 6);+		l = new Label (label);+		vb = new VBox (false, 2);+		hb = new HBox (false, 2);+		hb.pack_start (l, false, false, 0);+		vb.pack_start (hb, true, true, 5);+		vb.pack_start (t, true, true, 0);+		margin.pack_start (vb, true, true, 5);+		box.pack_start (margin, false, false, 5);+	}+}+ }diff --git a/libbirdfont/CharDatabase.vala b/libbirdfont/CharDatabase.valaindex b1c1ff5..854da50 100644--- a/libbirdfont/CharDatabase.vala+++ b/libbirdfont/CharDatabase.vala@@ -37,6 +37,7 @@ public class CharDatabase { 			show_loading_message (); 			parse_all_entries (); 			database_is_loaded = true;+			ProgressBar.set_progress (0); 			return false; 		}); 		idle.attach (null);diff --git a/libbirdfont/DescriptionTab.vala b/libbirdfont/DescriptionTab.valaindex 0872ea0..934b576 100644--- a/libbirdfont/DescriptionTab.vala+++ b/libbirdfont/DescriptionTab.vala@@ -1,6 +1,5 @@- /*-    Copyright (C) 2012 Johan Mattsson+    Copyright (C) 2012 2013 Johan Mattsson      This library is free software; you can redistribute it and/or modify      it under the terms of the GNU Lesser General Public License as @@ -15,135 +14,24 @@  namespace BirdFont { -/** Names and description for the TTF Name table. */+/** Names and description for the TTF Name table.+ * The actual tab is implemented in the GTK window.+ */ public class DescriptionTab : FontDisplay {	--	Font font;- 	public DescriptionTab () {-		font = BirdFont.get_current_font ();-		-		add_html_callback ("postscript_name", (val) => {-			font.postscript_name = val;-		});--		add_html_callback ("name", (val) => {-			font.name = val;-		});-		-		add_html_callback ("subfamily", (val) => {-			font.subfamily = val;-		});		--		add_html_callback ("full_name", (val) => {-			font.full_name = val;-		});--		add_html_callback ("unique_identifier", (val) => {-			font.unique_identifier = val;-		});--		add_html_callback ("version", (val) => {-			font.version = val;-		});--		add_html_callback ("description", (val) => {-			font.description = val;-		});--		add_html_callback ("copyright", (val) => {-			font.copyright = val;-		}); 	}-+	 	public override string get_name () {-		return _("Description");+		_("Description");+		return "Description"; 	} 	 	public override bool is_html_canvas () {-		return true;+		return false; 	}  	public override string get_html () {-		StringBuilder c = new StringBuilder (); --		// TODO: trademark, prefered family etc. -		// or maybe not, many fields in the name table seems to be irrelevant.-		-		// TODO: provide good explenations of these fields	--		c.append (-"""-<html>-<head>-	<script type="text/javascript" src="supplement.js"></script>-	<style type="text/css">@import url("style.css");</style>-	<script type="text/javascript">-		document.onkeyup = update_name_fields; -	</script>-</head>-<body>-	<div class="naming_box">-		<form>-			<h3>""" + _("Postscript name") + """</h3>-			<input class="text" type="text" id="postscript_name" value=""" + "\"" + font.postscript_name + "\"" + """ onchange="update_name_fields ();"/><br />--			<h3>""" + _("Name") + """</h3>-			<input class="text" type="text" id="name" value=""" + "\"" + font.name + "\"" + """ onchange="update_name_fields ();"/><br />--			<h3>""" + _("Style") + " (Regular/Bold/Italic)" + """</h3>-			<input class="text" type="text" id="subfamily" value=""" + "\"" + font.subfamily + "\"" + """ onchange="update_name_fields ();"/><br />--			<h3>""" + _("Full name (name and style)") + """</h3>-			<input class="text" type="text" id="full_name" value=""" + "\"" + font.full_name + "\"" + """ onchange="update_name_fields ();"/><br />--			<h3>""" + _("Unique identifier") + """</h3>-			<input class="text" type="text" id="unique_identifier" value=""" + "\"" + font.unique_identifier + "\"" + """ onchange="update_name_fields ();"/><br />--			<h3>""" + _("Version") + """</h3>-			<input class="text" type="text" id="version" value=""" + "\"" + font.version + "\"" + """ onchange="update_name_fields ();"/><br />--""");--	// There is a bug in webkit on windows that makes it imposible-	// to display textareas.-	if (BirdFont.win32) {-		c.append ("""<div style="visibility: hidden;">""");-	}-	-c.append (-"""-			<h3>""" + _("Description") + """</h3>-			<textarea rows="4" cols="50" id="description" name="description" onchange="update_name_fields ();">""" + font.description + """</textarea>--			<h3>""" + _("Copyright") + """</h3>-			<textarea rows="4" cols="50" id="copyright" name="copyright" onchange="update_name_fields ();">""" + font.copyright + """</textarea>-""");--	if (BirdFont.win32) {-		c.append ("</div>");-	}--c.append (-"""-		</form>-	</div>-</body>-</html>-""");--#if translations -	// for xgettext:-	_("Postscript name");-	_("Name");-	_("Style");-	_("Full name (name and style)");-	_("Unique identifier");-	_("Version");-	_("Description");-	_("Copyright");-#endif-		return c.str;+		return "".dup (); 	} } 

Contact

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