Commit e56486c
description and copyright fields
Changed files (9)
modifiedlayout/supplement.jsmodifiedlibbirdfont/BirdFontFile.valamodifiedlibbirdfont/CharDatabase.valamodifiedlibbirdfont/DescriptionTab.valamodifiedlibbirdfont/Font.valamodifiedlibbirdfont/OpenFontFormat/DirectoryTable.valamodifiedlibbirdfont/OpenFontFormat/FontData.valamodifiedlibbirdfont/OpenFontFormat/NameTable.valamodifiedlibbirdfont/OpenFontFormat/load_font.c
Diff
@@ -35,4 +35,13 @@ function update_name_fields () { mess = 'version:'; mess += document.getElementById('version').value; call (mess);++ mess = 'description:';+ mess += document.getElementById('description').value;+ call (mess);+ + mess = 'copyright:';+ mess += document.getElementById('copyright').value;+ call (mess);+ }@@ -123,6 +123,8 @@ class BirdFontFile { 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 (@"<description>$(font.description)</description>\n");+ os.put_string (@"<copyright>$(font.copyright)</copyright>\n"); os.put_string ("\n"); os.put_string ("<lines>\n");@@ -465,7 +467,15 @@ class BirdFontFile { if (iter->name == "version" && iter->children != null) { font.version = iter->children->content; }++ if (iter->name == "description" && iter->children != null) {+ font.description = iter->children->content;+ } + if (iter->name == "copyright" && iter->children != null) {+ font.copyright = iter->children->content;+ }+ if (iter->name == "hkern") { parse_kerning (iter); }@@ -104,6 +104,7 @@ class CharDatabase { if (description == "") { warning ("no description found");+ description = Font.to_hex (c).replace ("U+", "") + "\t"; } fin.close ();@@ -50,6 +50,14 @@ public class DescriptionTab : FontDisplay { 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 () {@@ -61,9 +69,7 @@ public class DescriptionTab : FontDisplay { } public override string get_html () {- StringBuilder c = new StringBuilder ();- - // TODO: description & license + StringBuilder c = new StringBuilder (); // TODO: trademark, prefered family etc. // or maybe not, many fields in the name table seems to be irrelevant.@@ -100,13 +106,37 @@ public class DescriptionTab : FontDisplay { <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 traslations +#if translations // for xgettext: _("Postscript name"); _("Name");@@ -114,6 +144,8 @@ public class DescriptionTab : FontDisplay { _("Full name (name & subfamily)"); _("Unique identifier"); _("Version");+ _("Description");+ _("Copyright"); #endif return c.str; }@@ -66,9 +66,11 @@ public class Font : GLib.Object { public string postscript_name = "Typeface"; public string name = "Typeface"; public string subfamily = "Regular";- public string full_name = "Typeface-Regular";+ public string full_name = "Typeface"; public string unique_identifier = ""; public string version = "Version 1.0";+ public string description = "";+ public string copyright = ""; public bool initialised = true; @@ -90,10 +90,6 @@ class DirectoryTable : Table { tables.append (this); if (kern_table.kerning_pairs > 0) {- // FIXME: Firefox will ignore the Kern table of GPOS is present - // but not adjust the values according to the GPOS table.- // - // Maybe there is a problem with gpos_table that I am not aware of. tables.append (gpos_table); } @@ -107,10 +103,13 @@ class DirectoryTable : Table { tables.append (hhea_table); tables.append (hmtx_table); + // FIXME: Remove the kern table.+ // It looks like the old kerning table is no longer needed+ // since the most important browsers uses the GPOS table. if (kern_table.kerning_pairs > 0) { tables.append (kern_table); }- + tables.append (loca_table); tables.append (maxp_table); tables.append (name_table);@@ -351,6 +351,8 @@ class FontData : Object { uint8 c1; int l = 0; + // FIXME: gconvert it instead.+ while (s.get_next_char (ref index, out c)) { c0 = (uint8) (c >> 8); c1 = (uint8) (c - (c0 << 8));@@ -147,8 +147,8 @@ class NameTable : Table { List<uint16> type = new List<uint16> (); List<string> text = new List<string> ();- - text.append ("");++ text.append (font.copyright); type.append (COPYRIGHT_NOTICE); text.append (font.name);@@ -164,12 +164,12 @@ class NameTable : Table { type.append (FULL_FONT_NAME); text.append (font.version);- type.append (VERSION); -+ type.append (VERSION);+ text.append (font.postscript_name); type.append (POSTSCRIPT_NAME);- - text.append ("");++ text.append (font.description); type.append (DESCRIPTION); text.append (font.name);@@ -177,7 +177,7 @@ class NameTable : Table { text.append (font.subfamily); type.append (PREFERED_SUB_FAMILY);- + num_records = (uint16) text.length (); fd.add_ushort (0); // format 1@@ -201,7 +201,7 @@ class NameTable : Table { for (int i = 0; i < num_records; i++) { t = (!) text.nth (i).data; p = (!) type.nth (i).data;- l = (uint16) (2 * t.char_count ());+ l = (uint16) (2 * t.char_count ()); // FIXME: handle UTF-16 in a better way, gconvert it. fd.add_ushort (3); // platform fd.add_ushort (1); // encoding id@@ -664,6 +664,28 @@ int get_descender (FT_Face face) { return (int) -bbox.yMin; } +/** Append name table data to a gstring. */+void append_description (GString* str, FT_SfntName* name_table_data) {+ gchar* utf8_str;+ gsize read, written;+ GError* error = NULL;+ + if (name_table_data->encoding_id == 0) {+ g_string_append_len (str, name_table_data->string, name_table_data->string_len);+ } else if (name_table_data->encoding_id == 1) {+ utf8_str = g_convert (name_table_data->string, name_table_data->string_len, "utf-8", "ucs-2", &read, &written, &error);+ if (error == NULL) {+ g_string_append (str, utf8_str);+ g_free (utf8_str);+ } else {+ fprintf (stderr, "Error in append_description: %s\n", error->message);+ g_error_free (error);+ }+ } else {+ fprintf (stderr, "Encoding %u is not supported.\n", name_table_data->encoding_id);+ }+}+ /** Convert font to bf format. * @param face freetype font face * @param err error code@@ -681,7 +703,6 @@ GString* get_bf_font (FT_Face face, char* file, int* err) { double units_per_em; double units; - *err = OK; units_per_em = face->units_per_EM;@@ -702,22 +723,34 @@ GString* get_bf_font (FT_Face face, char* file, int* err) { 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>");+ append_description (bf, &name_table_data);+ g_string_append (bf, "</full_name>\n"); } 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>");+ append_description (bf, &name_table_data);+ g_string_append (bf, "</unique_identifier>\n"); } 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>");+ append_description (bf, &name_table_data);+ g_string_append (bf, "</version>\n"); } + if (FT_Get_Sfnt_Name (face, 10, &name_table_data) == 0) { // description+ g_string_append (bf, "<description>");+ append_description (bf, &name_table_data);+ g_string_append (bf, "</description>\n");+ }+ + if (FT_Get_Sfnt_Name (face, 0, &name_table_data) == 0) { // copyright+ g_string_append (bf, "<copyright>");+ append_description (bf, &name_table_data);+ g_string_append (bf, "</copyright>\n");+ }+ g_string_append_printf (bf, "<backup>%s</backup>\n", file); g_string_append_printf (bf, "<lines>\n");