Commit 23c8018
Fix bugs in load and save code
Changed files (7)
modifiedfonts/Downstream.bfmodifiedlibbirdfont/FileTab.valamodifiedlibbirdfont/LoadCallback.valamodifiedlibbirdfont/MenuTab.valamodifiedlibbirdfont/OpenFontFormat/OpenFontFormatReader.valamodifiedlibbirdfont/OpenFontFormat/load_font.cmodifiedlibbirdfont/Path.vala
Diff
@@ -133,7 +133,7 @@ <path stroke="0" data="S -18.6739130435,23.1304347826 Q -8.6739130435,10.5217391304 4.8043478261,18.2608695652 L 4.2826086957,33.7391304348 Q -2.6293698792,38.7952734624 -12.0652173913,36.0000000000 L -20.0652173913,36.0000000000 L -24.0442477876,38.5221238938 L -21.9782608696,72.0000000000 L 20.0088495575,71.9823008850 L 20.0088495575,60.0442477876 L -3.3695652174,60.0000000000 L -4.0652173913,48.0000000000 Q 24.4565217391,52.1739130435 24.4565217391,24.0000000000 Q 23.9347826087,0.0000000000 -4.0652173913,0.0000000000 Q -14.2891199263,0.4076291476 -19.8913043478,4.0000000000 L -25.4565217391,9.7391304348 L -18.6739130435,23.1304347826" /> </glyph> <glyph id="2" left="-28" right="28">- <path stroke="0" data="S 18.0209553367,43.7690758044 Q 25.0951574944,37.3031543954 24.7928049250,25.1769911504 Q 24.8490542963,18.8231542727 22.1486970492,13.5296665407 Q 19.6298764238,8.5920435301 14.7126270049,4.5769939131 Q 8.7909672673,0.6135654969 -4.0652173913,0.0000000000 Q -14.2891199263,0.4076291476 -19.8913043478,4.0000000000 L -25.4565217391,9.7391304348 L -18.8420546364,21.1127356676 Q -8.0885477159,10.0024211066 0.6008080031,16.2431704502 Q 3.7839796311,18.4654955494 3.6541256985,24.6876334281 Q 3.5174738155,29.5151444054 1.0879184302,32.2258560985 T Q -4.1589042274,38.0798586932 -11.8970757984,33.8141592920 L -19.8970757984,33.8141592920 L -23.8761061947,36.3362831858 L -21.9782608696,72.0000000000 L 20.0088495575,71.9823008850 L 20.0088495575,60.0442477876 L -3.3695652174,60.0000000000 L -4.4015005771,45.8141592920 Q 1.2937228803,48.7516262541 7.1423597912,48.3395371667 Q 13.9009511431,47.5348182481 18.0209553367,43.7690758044 T" />+ <path stroke="0" data="S 18.0209553367,43.7690758044 Q 25.0951574944,37.3031543954 24.7928049250,25.1769911504 Q 24.8490542963,18.8231542727 22.1486970492,13.5296665407 Q 19.6298764238,8.5920435301 14.7126270049,4.5769939131 Q 8.7909672673,0.6135654969 -4.0652173913,0.0000000000 Q -14.2891199263,0.4076291476 -19.8913043478,4.0000000000 L -25.4565217391,9.7391304348 L -18.8420546364,21.1127356676 Q -8.0885477159,10.0024211066 0.6008080031,16.2431704502 Q 3.7839796311,18.4654955494 3.6541256985,24.6876334281 Q 3.5174738155,29.5151444054 1.0879184302,32.2258560985 Q -4.1589042274,38.0798586932 -11.8970757984,33.8141592920 L -19.8970757984,33.8141592920 L -23.8761061947,36.3362831858 L -21.9782608696,72.0000000000 L 20.0088495575,71.9823008850 L 20.0088495575,60.0442477876 L -3.3695652174,60.0000000000 L -4.4015005771,45.8141592920 Q 1.2937228803,48.7516262541 7.1423597912,48.3395371667 Q 13.9009511431,47.5348182481 18.0209553367,43.7690758044 T" /> </glyph> </collection> <collection unicode="U+3a">@@ -40,8 +40,27 @@ public class FileTab : FontDisplay { } font = BirdFont.get_current_font ();++ MenuTab.load_callback = new LoadCallback ();+ MenuTab.load_callback.file_loaded.connect (() => {+ Font f;++ if (MenuTab.suppress_event) {+ return;+ }+ + f = BirdFont.get_current_font ();+ + MainWindow.get_drawing_tools ().remove_all_grid_buttons ();+ foreach (string v in f.grid_width) {+ MainWindow.get_drawing_tools ().parse_grid (v);+ }+ + MainWindow.get_drawing_tools ().background_scale.set_value (f.background_scale);+ KerningTools.update_kerning_classes ();+ MenuTab.select_overview ();+ }); - // FIXME: clean up this nested lamda function dialog.signal_discard.connect (() => { Font f; @@ -50,47 +69,32 @@ public class FileTab : FontDisplay { } f = BirdFont.new_font ();- f.delete_backup (); MainWindow.clear_glyph_cache (); MainWindow.close_all_tabs (); - MenuTab.load_callback = new LoadCallback ();- f.set_file (fn); MainWindow.native_window.load (); // background thread- - MenuTab.load_callback.file_loaded.connect (() => {- MainWindow.get_drawing_tools ().remove_all_grid_buttons ();- foreach (string v in f.grid_width) {- MainWindow.get_drawing_tools ().parse_grid (v);- }- - MainWindow.get_drawing_tools ().background_scale.set_value (f.background_scale);- KerningTools.update_kerning_classes ();- MenuTab.select_overview ();- }); }); dialog.signal_save.connect (() => {- SaveCallback save_callback;- if (MenuTab.suppress_event) {+ warn_if_test ("Event suppressed."); return; } - save_callback = new SaveCallback ();- save_callback.file_saved.connect (() => {+ MenuTab.save_callback = new SaveCallback ();+ MenuTab.save_callback.file_saved.connect (() => {+ print ("DISC:..\n"); dialog.signal_discard (); });- save_callback.save ();+ MenuTab.save_callback.save (); // background thread }); if (!font.is_modified ()) { dialog.signal_discard (); } else { MainWindow.native_window.set_save_dialog (dialog);- dialog.signal_discard (); } } @@ -34,15 +34,17 @@ public class LoadCallback : GLib.Object { font = BirdFont.get_current_font (); dialog.signal_discard.connect (() => {- print ("Discard and oad_new_font\n"); MainWindow.close_all_tabs (); load_new_font (); }); dialog.signal_save.connect (() => { MainWindow.close_all_tabs ();- MenuTab.save ();- load_new_font ();+ MenuTab.save_callback = new SaveCallback ();+ MenuTab.save_callback.file_saved.connect (() => {+ load_new_font ();+ });+ MenuTab.save_callback.save (); // background thread }); if (!font.is_modified ()) {@@ -165,11 +165,6 @@ public class MenuTab : FontDisplay { return; } - if (!set_suppress_event (true)) {- warning ("Can't lock UI.");- return;- }- font = BirdFont.get_current_font (); dialog.signal_discard.connect (() => {@@ -184,14 +179,16 @@ public class MenuTab : FontDisplay { KerningTools.update_kerning_classes (); MainWindow.native_window.font_loaded ();+ + select_overview (); }); dialog.signal_save.connect (() => {- // FIXME: clean up background nested lambda- MainWindow.native_window.save (); // background thread+ MenuTab.save_callback = new SaveCallback (); MenuTab.save_callback.file_saved.connect (() => { dialog.signal_discard (); });+ save_callback.save (); }); if (!font.is_modified ()) {@@ -199,9 +196,6 @@ public class MenuTab : FontDisplay { } else { MainWindow.native_window.set_save_dialog (dialog); }-- set_suppress_event (false);- select_overview (); return; }@@ -223,9 +217,12 @@ public class MenuTab : FontDisplay { }); dialog.signal_save.connect (() => {- MenuTab.save ();- ensure_main_loop_is_empty ();- MainWindow.native_window.quit ();+ MenuTab.save_callback = new SaveCallback ();+ MenuTab.save_callback.file_saved.connect (() => {+ ensure_main_loop_is_empty ();+ MainWindow.native_window.quit ();+ });+ save_callback.save (); }); if (!font.is_modified ()) {@@ -375,8 +372,8 @@ public class MenuTab : FontDisplay { } public static void load () {- load_callback = new LoadCallback ();- load_callback.load ();+ MenuTab.load_callback = new LoadCallback ();+ MenuTab.load_callback.load (); } }@@ -147,7 +147,12 @@ public class OpenFontFormatReader : Object { return directory_table.head_table.get_adjusted_checksum (); } - public static string? parse_kerning (string file_name) {+ public static void append_kerning (StringBuilder bf_data, string file_name) {+ string s = parse_kerning (file_name);+ bf_data.append (s);+ }+ + public static string parse_kerning (string file_name) { KernTable kern_table; CmapTable cmap_table; HeadTable head_table;@@ -156,7 +161,6 @@ public class OpenFontFormatReader : Object { unichar left, right; double kerning, units_per_em; uint npairs = 0;- string result = ""; try { reader.parse_index (file_name);@@ -194,14 +198,8 @@ public class OpenFontFormatReader : Object { } catch (GLib.Error e) { warning (@"Failed to parse font. $(e.message)"); }- - result = bf_kerning.str;- - if (result == "") {- return null;- } - return result.dup (); + return bf_kerning.str; } } }@@ -757,7 +757,6 @@ GString* get_bf_font (FT_Face face, char* file, int* err) { g_string_append_printf (bf, "</collection>\n"); } - // glyph outlines for (i = 0; i < face->num_glyphs; i++) { error = FT_Load_Glyph (face, i, FT_LOAD_DEFAULT | FT_LOAD_NO_SCALE);@@ -794,12 +793,7 @@ GString* get_bf_font (FT_Face face, char* file, int* err) { g_string_free (glyph, 0); } - kerning = (gchar*) bird_font_open_font_format_reader_parse_kerning (file); -- if (kerning != NULL) {- g_string_append (bf, kerning);- g_free (kerning); - }+ bird_font_open_font_format_reader_append_kerning (bf, file); g_string_append (bf, "</font>\n"); @@ -725,7 +725,7 @@ public class Path { // generate a rasterized image of the object- width = 80;+ width = 160; click_map = new ClickMap (width); px = 0; py = 0;@@ -736,10 +736,8 @@ public class Path { click_y = (int) (width * ((y - ymin) / (ymax - ymin))); in_path = click_map.get_value (click_x, click_y) != '\0';-- click_map.set_value (click_x, click_y, 'X'); - click_map.print ();+ click_map.set_value (click_x, click_y, 'X'); return in_path; }