Commit a08828b
Show progress bar while loading big font files
Changed files (10)
modifiedlibbirdfont/BirdFontFile.valamodifiedlibbirdfont/OpenFontFormat/FontData.valamodifiedlibbirdfont/OpenFontFormat/GlyfData.valamodifiedlibbirdfont/OpenFontFormat/GlyfTable.valamodifiedlibbirdfont/OpenFontFormat/GposTable.valamodifiedlibbirdfont/OpenFontFormat/KernTable.valamodifiedlibbirdfont/OpenFontFormat/OpenFontFormatWriter.valamodifiedlibbirdfont/PreviewTools.valamodifiedlibbirdfont/ProgressBar.valamodifiedlibbirdfont/SvgFontFormatWriter.vala
Diff
@@ -155,7 +155,8 @@ class BirdFontFile { os.put_string (@"</images>\n"); os.put_string ("\n"); }- + + // FIXME: no need to iterate over all glyphs twise font.glyph_cache.for_each ((gc) => { if (is_null (gc)) { warning ("No glyph collection");@@ -166,6 +167,9 @@ class BirdFontFile { } catch (GLib.Error e) { warning (e.message); }+ + ProgressBar.set_progress (0); + MainWindow.get_tool_tip ().show_text (t_("Saving")); }); font.glyph_cache.for_each ((gc) => {@@ -173,9 +177,7 @@ class BirdFontFile { try { string data;- foreach (Glyph g in gc.get_version_list ().glyphs) {- if (g.get_background_image () != null) { bg = (!) g.get_background_image (); data = bg.get_png_base64 ();@@ -196,13 +198,15 @@ class BirdFontFile { warning (@"Failed to save $path \n"); warning (@"$(ef.message) \n"); }+ + ProgressBar.set_progress (0); + MainWindow.get_tool_tip ().show_text (t_("Saving")); }); num_kerning_pairs = KerningClasses.get_instance ().classes_first.length (); progress = num_kerning_pairs; ProgressBar.set_progress (1); for (uint i = 0; i < num_kerning_pairs; i++) {- range = KerningClasses.get_instance ().classes_first.nth (i).data.get_all_ranges (); os.put_string ("<kerning ");@@ -244,6 +248,9 @@ class BirdFontFile { } catch (GLib.Error e) { warning (@"$(e.message) \n"); }+ + ProgressBar.set_progress (0);+ MainWindow.get_tool_tip ().show_text (t_("Saving")); }); os.put_string ("</font>");@@ -464,7 +471,7 @@ class BirdFontFile { private bool parse_file (Xml.Node* root) { Xml.Node* node = root;- + int i = 0; for (Xml.Node* iter = node->children; iter != null; iter = iter->next) { // this is a backup file set path to the original @@ -487,10 +494,12 @@ class BirdFontFile { parse_font_boundaries (iter); } + // horizontal lines in the new format if (iter->name == "horizontal") { parse_horizontal_lines (iter); } -+ + // grid buttons if (iter->name == "grid") { parse_grid (iter); }@@ -550,6 +559,14 @@ class BirdFontFile { if (iter->name == "kerning") { parse_kerning (iter); }+ + ProgressBar.set_progress (++i / 1024.0);+ + if (i == 1024) {+ i = 0;+ }+ + MainWindow.get_tool_tip ().show_text (t_("Loading BirdFont XML data.")); } return true;@@ -55,6 +55,7 @@ public class FontData : Object { public void write_table (OtfInputStream dis, uint32 offset, uint32 length) throws Error { uint32 l = length + (length % 4); // padding after end of table+ uint32 added_bytes = 0; uint8 b; if (length >= l) {@@ -73,6 +74,11 @@ public class FontData : Object { while (wp < l) { b = dis.read_byte (); add (b);+ added_bytes++;+ + if (added_bytes % 1024 == 0) {+ OpenFontFormatWriter.show_progress (added_bytes / (double) l);+ } } rp = 0;@@ -70,11 +70,13 @@ class GlyfData : GLib.Object { } } - process_end_points ();- process_flags ();- process_x ();- process_y ();- process_bounding_box (); + if (paths.length () > 0) {+ process_end_points ();+ process_flags ();+ process_x ();+ process_y ();+ process_bounding_box ();+ } } bool is_empty (Path p) {@@ -151,7 +151,8 @@ public class GlyfTable : Table { Font font = OpenFontFormatWriter.get_current_font (); uint32 indice; List<Glyph> unassigned_glyphs;- + uint32 num_glyphs = font.length ();+ uint32 i = 0; // add notdef. character at index zero + other special chars first glyphs.append (font.get_not_def_character ()); glyphs.append (font.get_null_character ());@@ -188,6 +189,8 @@ public class GlyfTable : Table { printd ("Adding unassigned glyph."); unassigned_glyphs.append (g); }+ + OpenFontFormatWriter.show_progress (++i / num_glyphs); } foreach (Glyph ug in unassigned_glyphs) {@@ -215,6 +215,8 @@ public class GposTable : Table { } catch (Error e) { warning (e.message); }+ + OpenFontFormatWriter.show_progress (i / num_pairs); }, num_pairs); if (unlikely (pairs_set_length () != written)) {@@ -163,6 +163,8 @@ public class KernTable : Table { } catch (GLib.Error e) { warning (e.message); }+ + OpenFontFormatWriter.show_progress (i / n_pairs); }, n_pairs); fd.pad ();@@ -70,6 +70,10 @@ public class OpenFontFormatWriter : Object { } } + public static void show_progress (double progress) {+ ProgressBar.set_progress (progress);+ }+ public void close () throws Error { os.close (); }@@ -64,6 +64,7 @@ public class PreviewTools : ToolCollection { suppress_event = true; ExportTool.export_ttf_font_sync (); ExportTool.export_svg_font ();+ MainWindow.get_tool_tip ().show_text (t_("Three font files has been created.")); suppress_event = false; } }@@ -18,9 +18,7 @@ namespace BirdFont { class ProgressBar { static double current_progress = 0;- public signal void new_progress ();- static ProgressBar? singleton = null; public ProgressBar () {@@ -83,6 +83,9 @@ class SvgFontFormatWriter : Object { put (@"<glyph unicode=\"$(b.str)\" horiz-adv-x=\"$(glyph.get_width ())\" d=\"$(glyph.get_svg_data ())\" />"); } }+ + ProgressBar.set_progress (0);+ Tool.yield (); } // FIXME: ligatures