Clone in a terminal:
Commit b07e8fd
Johan Mattsson - 2013-06-24T22:02:34+00:00
b07e8fd6bfea2ea430a962f386c4f3f28a781008johan.mattsson.m@gmail.com

fields for creating a proper name table in TTF fonts

Changed files (10)

Diff

diff --git a/birdfont/GtkWindow.vala b/birdfont/GtkWindow.valaindex 0343da1..6d6457f 100644--- a/birdfont/GtkWindow.vala+++ b/birdfont/GtkWindow.vala@@ -408,6 +408,10 @@ public class GtkWindow : Gtk.Window, NativeWindow { 		preview_item.activate.connect (() => { MenuTab.preview (); }); 		preview_item.add_accelerator ("activate", accel_group, 'P', Gdk.ModifierType.CONTROL_MASK, Gtk.AccelFlags.VISIBLE); +		Gtk.MenuItem description_item = new Gtk.MenuItem.with_mnemonic(_("_Description"));+		file_menu.append (description_item);+		description_item.activate.connect (() => { MenuTab.show_description (); });+ 		Gtk.MenuItem kerning_item = new Gtk.MenuItem.with_mnemonic (_("_Kerning")); 		file_menu.append (kerning_item); 		kerning_item.activate.connect (() => { MenuTab.show_kerning_context (); });diff --git a/layout/style.css b/layout/style.cssindex f268b31..5e5544e 100644--- a/layout/style.css+++ b/layout/style.css@@ -32,6 +32,14 @@ div.menu_item:hover { 	background-color: #E6ECF6;  } +div.naming_box {+	float: left;+	width: 350px;+	padding: 0 0 0 0;+	margin: 0 10px 0 0;+	top: 50%;+}+ div.inner_format_box { 	float: left; 	width: 210px;diff --git a/layout/supplement.js b/layout/supplement.jsindex 77a7260..14cc000 100644--- a/layout/supplement.js+++ b/layout/supplement.js@@ -3,12 +3,36 @@ function call (command) { 	document.title='done'; } +// MenuTab text fields function update_text_fields () {-	mess = 'export_name:';-	mess += document.getElementById('fontname').value;-	call (mess);-	 	mess = 'glyph_sequence:'; 	mess += document.getElementById('glyph_sequence').value; 	call (mess);	 }++// DescriptionTab text fields+function update_name_fields () {+	mess = 'postscript_name:';+	mess += document.getElementById('postscript_name').value;+	call (mess);+	+	mess = 'name:';+	mess += document.getElementById('name').value;+	call (mess);+	+	mess = 'subfamily:';+	mess += document.getElementById('subfamily').value;+	call (mess);++	mess = 'full_name:';+	mess += document.getElementById('full_name').value;+	call (mess);++	mess = 'unique_identifier:';+	mess += document.getElementById('unique_identifier').value;+	call (mess);+	+	mess = 'version:';+	mess += document.getElementById('version').value;+	call (mess);+}diff --git a/libbirdfont/BirdFontFile.vala b/libbirdfont/BirdFontFile.valaindex f224e02..79b9fc7 100644--- a/libbirdfont/BirdFontFile.vala+++ b/libbirdfont/BirdFontFile.vala@@ -115,9 +115,14 @@ class BirdFontFile { 				os.put_string (@"<!-- This is a backup of the following font: -->\n");	 				os.put_string (@"<backup>$((!) font.get_path ())</backup>\n");	 			}-			+		 			os.put_string ("\n");-			os.put_string (@"<name>$(font.get_name ())</name>\n");+			os.put_string (@"<postscript_name>$(font.postscript_name)</postscript_name>\n");+			os.put_string (@"<name>$(font.name)</name>\n");+			os.put_string (@"<subfamily>$(font.subfamily)</subfamily>\n");+			os.put_string (@"<full_name>$(font.full_name)</full_name>\n");+			os.put_string (@"<unique_identifier>$(font.unique_identifier)</unique_identifier>\n");+			os.put_string (@"<version>$(font.version)</version>\n"); 			 			os.put_string ("\n"); 			os.put_string ("<lines>\n");@@ -437,10 +442,30 @@ class BirdFontFile { 				parse_background_selection (iter); 			} +			if (iter->name == "postscript_name" && iter->children != null) {+				font.postscript_name = iter->children->content;+			}+			 			if (iter->name == "name" && iter->children != null) {-				font.set_name (iter->children->content);+				font.name = iter->children->content;+			}++			if (iter->name == "subfamily" && iter->children != null) {+				font.subfamily = iter->children->content; 			} +			if (iter->name == "full_name" && iter->children != null) {+				font.full_name = iter->children->content;+			}+			+			if (iter->name == "unique_identifier" && iter->children != null) {+				font.unique_identifier = iter->children->content;+			}++			if (iter->name == "version" && iter->children != null) {+				font.version = iter->children->content;+			}+			 			if (iter->name == "hkern") { 				parse_kerning (iter); 			}diff --git a/libbirdfont/ClipTool.vala b/libbirdfont/ClipTool.valaindex df84ad0..2968b72 100644--- a/libbirdfont/ClipTool.vala+++ b/libbirdfont/ClipTool.vala@@ -33,7 +33,7 @@ public class ClipTool : Tool { 		}  		 		if (fd is Glyph) {	-			// the internal clipboard contains data in .bf format and the +			// the internal clipboard contains path objects and the 			// external clibboard contains inkscape compatible vector graphics 			while (internal_clipboard.length () > 0) { 				internal_clipboard.remove_link (internal_clipboard.first ());diff --git a/libbirdfont/DescriptionTab.vala b/libbirdfont/DescriptionTab.valanew file mode 100644index 0000000..232016e--- /dev/null+++ b/libbirdfont/DescriptionTab.vala@@ -0,0 +1,122 @@+/*+    Copyright (C) 2012 Johan Mattsson++    This program is free software: you can redistribute it and/or modify+    it under the terms of the GNU General Public License as published by+    the Free Software Foundation, either version 3 of the License, or+    (at your option) any later version.++    This program is distributed in the hope that it will be useful,+    but WITHOUT ANY WARRANTY; without even the implied warranty of+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the+    GNU General Public License for more details.++    You should have received a copy of the GNU General Public License+    along with this program.  If not, see <http://www.gnu.org/licenses/>.+*/++using WebKit;++namespace BirdFont {++/** Names and description for the TTF Name table. */+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;+		});+	}++	public override string get_name () {+		return _("Description");+	}+	+	public override bool is_html_canvas () {+		return true;+	}++	public override string get_html () {+		StringBuilder c = new StringBuilder ();+		+		// TODO: description & license ++		// 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>""" + _("Subfamily name") + " (Regular/Bold/Italic)" + """</h3>+			<input class="text" type="text" id="subfamily" value=""" + "\"" + font.subfamily + "\"" + """ onchange="update_name_fields ();"/><br />++			<h3>""" + _("Full name (name & subfamily)") + """</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 />+		</form>+	</div>+</body>+</html>+""");++#if traslations +	// for xgettext:+	_("Postscript name");+	_("Name");+	_("Subfamily name");+	_("Full name (name & subfamily)");+	_("Unique identifier");+	_("Version");+#endif+		return c.str;+	}+}++}diff --git a/libbirdfont/Font.vala b/libbirdfont/Font.valaindex 619ea06..69b7b59 100644--- a/libbirdfont/Font.vala+++ b/libbirdfont/Font.vala@@ -62,7 +62,14 @@ public class Font : GLib.Object { 	 	bool modified = false; 	-	private string name = "typeface";+	// name table descriptions+	public string postscript_name = "Typeface";+	public string name = "Typeface";+	public string subfamily = "Regular";+	public string full_name = "Typeface-Regular";+	public string unique_identifier = "";+	public string version = "Version 1.0";+ 	public bool initialised = true;  	OpenFontFormatReader otf;diff --git a/libbirdfont/MenuTab.vala b/libbirdfont/MenuTab.valaindex c474d5a..9537a4c 100644--- a/libbirdfont/MenuTab.vala+++ b/libbirdfont/MenuTab.vala@@ -73,7 +73,7 @@ public class MenuTab : FontDisplay { 	} 	 	public override string get_name () {-		return "Menu";+		return _("Menu"); 	} 	 	public override bool is_html_canvas () {@@ -81,7 +81,6 @@ public class MenuTab : FontDisplay { 	}  	public override string get_html () {-		Font f = BirdFont.get_current_font (); 		StringBuilder c = new StringBuilder (); 		string fn; 		@@ -108,9 +107,6 @@ c.append (""" 				<h3>""" + _("Glyph sequence") + """</h3> 				<input class="text" type="text" id="glyph_sequence" value=""" + "\"" + Preferences.get ("glyph_sequence") + "\"" + """ onchange="update_text_fields ();"/><br /> -				<h3>""" + _("Name") + """</h3>-				<input class="text" type="text" id="fontname" value=""" + "\"" + f.get_name () + "\"" + """ onchange="update_text_fields ();"/><br />-				 				<input class="button" type="button" value=""" + "\"" + _("Export") + "\"" + """ id="export_button" onclick="call ('export:fonts');" onmouseover="call ('help:(Ctrl+e) """ + _("Export SVG, TTF & EOT fonts") + """');"/> 				<input class="button" type="button" value=""" + "\"" + _("Preview") + "\"" + """ id="preview_button" onclick="call ('preview:fonts');" onmouseover="call ('help:(Ctrl+p) """ + _("Export SVG font and view the result") + """');"/><br /> """);@@ -501,6 +497,10 @@ c.append (""" 		} 	} 	+	public static void show_description () {+		MainWindow.get_tab_bar ().add_unique_tab (new DescriptionTab (), 110, false);+	}+	 	public static void show_kerning_context () { 		MainWindow.get_tab_bar ().add_unique_tab (new KerningDisplay (), 85, false); 	}diff --git a/libbirdfont/OpenFontFormat/NameTable.vala b/libbirdfont/OpenFontFormat/NameTable.valaindex f388f3f..f152e5d 100644--- a/libbirdfont/OpenFontFormat/NameTable.vala+++ b/libbirdfont/OpenFontFormat/NameTable.vala@@ -25,6 +25,7 @@ class NameTable : Table { 	public static const uint16 UNIQUE_IDENTIFIER = 3; 	public static const uint16 FULL_FONT_NAME = 4; // name + subfamily 	public static const uint16 VERSION = 5;+	public static const uint16 POSTSCRIPT_NAME = 6; 	public static const uint16 DESCRIPTION = 10; 	public static const uint16 PREFERED_FAMILY = 16; 	public static const uint16 PREFERED_SUB_FAMILY = 17;@@ -150,30 +151,31 @@ class NameTable : Table { 		text.append ("Copyright"); 		type.append (COPYRIGHT_NOTICE); 		-		text.append (font.get_name ());+		text.append (font.name); 		type.append (FONT_NAME); -		text.append ("Regular");+		text.append (font.subfamily); 		type.append (SUBFAMILY_NAME); -		text.append (font.get_name ()); // TODO: validate+		text.append (font.unique_identifier); 		type.append (UNIQUE_IDENTIFIER); -		text.append (font.get_name ());+		text.append (font.full_name); 		type.append (FULL_FONT_NAME); 		-		// This does for some reason cause an internal error in ms fontvalidatior utility.-		// Head table can't parse integer from string.-		text.append ("Version 1.0");+		text.append (font.version); 		type.append (VERSION);		++		text.append (font.postscript_name);+		type.append (POSTSCRIPT_NAME); 		 		text.append (""); 		type.append (DESCRIPTION);-				-		text.append (font.get_name ());+		+		text.append (font.name); 		type.append (PREFERED_FAMILY); 		-		text.append ("Regular");+		text.append (font.subfamily); 		type.append (PREFERED_SUB_FAMILY); 			 		num_records = (uint16) text.length ();diff --git a/libbirdfont/OpenFontFormat/load_font.c b/libbirdfont/OpenFontFormat/load_font.cindex 8f226ee..f3e74c0 100644--- a/libbirdfont/OpenFontFormat/load_font.c+++ b/libbirdfont/OpenFontFormat/load_font.c@@ -25,6 +25,7 @@ #include FT_GLYPH_H #include FT_OPENTYPE_VALIDATE_H #include FT_TRUETYPE_TABLES_H+#include FT_SFNT_NAMES_H  /** Error codes. */ #define OK 0@@ -591,9 +592,11 @@ GString* get_bf_font (FT_Face face, char* file, int* err) { 	FT_Error error; 	FT_Long i; 	FT_ULong charcode;+	FT_SfntName name_table_data; 	double units_per_em; 	double units; 	+	 	*err = OK;  	units_per_em = face->units_per_EM;@@ -602,11 +605,34 @@ GString* get_bf_font (FT_Face face, char* file, int* err) { 	g_string_append (bf, "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>\n"); 	 	// libxml2 fails on doctype declaration in windows.-		-	// TODO: load from font+	 	g_string_append (bf, "<font>\n"); +	g_string_append_printf (bf, "<postscript_name>%s</postscript_name>\n", FT_Get_Postscript_Name(face)); 	g_string_append_printf (bf, "<name>%s</name>\n", face->family_name);+	+	if (face->style_name != NULL) {+		g_string_append_printf (bf, "<subfamily>%s</subfamily>\n", face->style_name);+	}+	+	if (FT_Get_Sfnt_Name (face, 4, &name_table_data) == 0) { // full name+		g_string_append (bf, "<full_name>");+		g_string_append_len (bf, name_table_data.string, name_table_data.string_len);+		g_string_append (bf, "</full_name>");+	}	++	if (FT_Get_Sfnt_Name (face, 3, &name_table_data) == 0) { // unique identifier+		g_string_append (bf, "<unique_identifier>");+		g_string_append_len (bf, name_table_data.string, name_table_data.string_len);+		g_string_append (bf, "</unique_identifier>");+	}++	if (FT_Get_Sfnt_Name (face, 5, &name_table_data) == 0) { // version+		g_string_append (bf, "<version>");+		g_string_append_len (bf, name_table_data.string, name_table_data.string_len);+		g_string_append (bf, "</version>");+	}+ 	g_string_append_printf (bf, "<backup>%s</backup>\n", file);  	g_string_append_printf (bf, "<lines>\n");

Contact

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