Commit 07e20b3
Open huge fonts Load fonts with libxml TextReader. This commit adds support for huge CJK fonts.
Changed files (4)
modifiedlibbirdfont/Argument.valamodifiedlibbirdfont/BirdFont.valamodifiedlibbirdfont/BirdFontFile.valamodifiedlibbirdfont/OpenFontFormat/load_font.c
Diff
@@ -70,6 +70,7 @@ public class Argument : GLib.Object { a == "--no-translation" || a == "--mac" || a == "--android" ||+ a == "--log" || a == "--donated") { prev = a; i++;@@ -206,6 +207,8 @@ public class Argument : GLib.Object { return "--test"; case 'a': return "--android";+ case 'l': + return "--log"; } return "";@@ -247,6 +250,7 @@ public class Argument : GLib.Object { print_padded ("-e, --exit", t_("exit if a test case fails")); print_padded ("-f, --fatal-warning", t_("treat warnings as fatal")); print_padded ("-h, --help", t_("show this message"));+ print_padded ("-l, --log", t_("write a log file")); print_padded ("-m, --mac", t_("enable Machintosh customizations")); print_padded ("-n, --no-translation", t_("don't translate")); print_padded ("-s, --slow", t_("sleep between each command in test suite"));@@ -210,8 +210,7 @@ public class BirdFont { #if ANDROID BirdFont.logging = true;- init_logfile ();-+ __android_log_print (ANDROID_LOG_WARN, "BirdFont", @"libbirdfont version $VERSION"); LogLevelFlags log_levels = LogLevelFlags.LEVEL_ERROR | LogLevelFlags.LEVEL_CRITICAL | LogLevelFlags.LEVEL_WARNING; Log.set_handler (null, log_levels, android_warning);@@ -222,7 +221,12 @@ public class BirdFont { stdout.printf ("built on %s\n", BUILD_TIMESTAMP); android = args.has_argument ("--android");+ BirdFont.logging = args.has_argument ("--log"); #endif++ if (BirdFont.logging) {+ init_logfile ();+ } if (!args.has_argument ("--no-translation")) { init_gettext ();@@ -31,33 +31,16 @@ class BirdFontFile { * @param path path to a valid .bf file */ public bool load (string path) {- bool ok = true;- Xml.Doc* doc;- Xml.Node* root;- - printd (@"Init xml parser.\n");+ TextReader tr;+ bool ok; Parser.init (); - printd (@"Loading $path\n");+ tr = new TextReader.filename (path);+ ok = load_xml (tr); - font.font_file = path; // this will be updated if we are loading a backup file-- doc = Parser.parse_file (path);- root = doc->get_root_element ();- - if (root == null) {- warning ("no root element");- delete doc;- return false;- }-- create_background_files (root);- ok = parse_file (root);-- delete doc; Parser.cleanup ();- + return ok; } @@ -65,31 +48,76 @@ class BirdFontFile { * @param xml_data data for a valid .bf file */ public bool load_data (string xml_data) {+ TextReader tr;+ bool ok;+ + Parser.init ();+ + printd ("Load data:\n");+ printd (xml_data);+ + tr = new TextReader.for_doc (xml_data, "");+ ok = load_xml (tr);+ + Parser.cleanup ();+ + return ok;+ }++ private bool load_xml (TextReader tr) { bool ok = true;- Xml.Doc* doc;+ int parsed; Xml.Node* root; - Parser.init ();+ tr.read ();+ root = tr.expand (); - font.font_file = "typeface.bf"; // FIXME- doc = Parser.parse_doc (xml_data);- root = doc->get_root_element ();+ font.font_file = "typeface.bf"; - if (root == null) {- warning ("no root element");- delete doc;+ if (is_null (root)) {+ warning ("No root element");+ tr.close (); return false; } create_background_files (root); ok = parse_file (root);-- delete doc;- Parser.cleanup (); + tr.close ();+ return ok; } + private string get_attribute (TextReader tr, string attribute_name) {+ string? c = tr.get_attribute (attribute_name);+ + if (c == null) {+ return "";+ }+ + return (!) c;+ }+ + private string get_value (TextReader tr) {+ string? v = tr.value ();+ + if (v == null) {+ return "";+ }+ + return (!) v;+ }++ private string get_name (TextReader tr) {+ string? n = tr.name ();+ + if (n == null) {+ return "";+ }+ + return (!) n;+ }+ public bool write_font_file (string path, bool backup = false) { try { File file = File.new_for_path (path);@@ -505,15 +533,6 @@ class BirdFontFile { if (iter->name == "postscript_name" && iter->children != null) { font.postscript_name = iter->children->content;- - printd ("PostScript name:"); // FIXME: delete when debugging is done- printd (iter->children->content);- printd ("\n");- }- - // FIXME: delete when debugging is done- if (iter->name == "postscript_name" && iter->children == null) {- printd ("Found PostScipt name but content for this node is null in libxml.\n"); } if (iter->name == "name" && iter->children != null) {@@ -576,6 +576,7 @@ FT_ULong get_charcode (FT_Face face, FT_UInt gid) { /** Obtain kerning data in .bf format for one glyph. * @param gid glyph id */+// FIXME: GString* get_kerning_data (FT_Face face, FT_Long gid, double units) { FT_Error error; FT_Vector kerning;@@ -667,18 +668,19 @@ int get_descender (FT_Face face) { void append_description (GString* str, FT_SfntName* name_table_data) { gchar* utf8_str; gsize read, written;- GError* error = NULL;+ 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) {- - // Unicode BMP (UCS-2) is the right encoding- // utf8_str = g_convert (name_table_data->string, name_table_data->string_len, "utf-8", "ucs-2", &read, &written, &error);- - g_warning ("CONVERT");- - // DELETE utf-16be+ if (name_table_data->encoding_id == 0 && name_table_data->platform_id == 1) { // mac roman+ utf8_str = g_convert (name_table_data->string, name_table_data->string_len, "utf-8", "macintosh", &read, &written, &error);++ if (error == NULL) {+ g_string_append (str, utf8_str);+ g_free (utf8_str);+ } else {+ g_warning ("Error in append_description: %s\n", error->message);+ g_error_free (error);+ }+ } else if (name_table_data->encoding_id == 1 && name_table_data->platform_id == 3) { // windows unicode utf8_str = g_convert (name_table_data->string, name_table_data->string_len, "utf-8", "ucs-2be", &read, &written, &error); if (error == NULL) {@@ -691,8 +693,6 @@ void append_description (GString* str, FT_SfntName* name_table_data) { } else { g_warning ("Encoding %u is not supported.\n", name_table_data->encoding_id); }- - g_warning ("name_table_data->encoding_id: %d, plat: %d str: %s \n", name_table_data->encoding_id, name_table_data->platform_id, str->str); } /** Convert font to bf format.@@ -808,12 +808,15 @@ GString* get_bf_font (FT_Face face, char* file, int* err) { } // kerning+ // FIXME+ /* for (i = 0; i < face->num_glyphs; i++) { hkern = get_kerning_data (face, i, units); g_string_append (bf, hkern->str); g_string_free (hkern, 0); bird_font_progress_bar_set_progress ((double)(face->num_glyphs - i) / face->num_glyphs); }+ */ g_string_append (bf, "</font>\n");