Commit 82438e1
progress bar
Changed files (8)
modifiedlibbirdfont/ExportTool.valamodifiedlibbirdfont/MenuTab.valamodifiedlibbirdfont/OpenFontFormatWriter.valaaddedlibbirdfont/ProgressBar.valamodifiedlibbirdfont/TabBar.valamodifiedlibbirdfont/TooltipArea.valamodifiedlibbirdfont/load_svg_font.cmodifiedwin32/build_win32.py
Diff
@@ -17,26 +17,11 @@ namespace BirdFont { -public class ExportTool : Tool {+public class ExportTool : GLib.Object { private static ExportThread export_thread; private static bool stop_export_thread = false; public ExportTool (string n) {- base (n, _("Export glyph to svg file"), 'e', CTRL);- - select_action.connect((self) => {- export_svg_font ();- // Fixa: add export_glyph_to_svg (); as tool in toolbox- });- - press_action.connect((self, b, x, y) => {- });-- release_action.connect((self, b, x, y) => {- });- - move_action.connect ((self, x, y) => {- }); } public static string export_selected_paths_to_string () {@@ -177,13 +162,14 @@ public class ExportTool : Tool { public static bool export_all () { Font font = BirdFont.get_current_font (); bool f;+ bool r = true; if (font.get_ttf_export ()) { f = export_ttf_font (); if (!f) { warning ("Failed to export font");- return false;+ r = false; } } @@ -192,11 +178,11 @@ public class ExportTool : Tool { if (!f) { warning ("Failed to export font");- return false;+ r = false; } } - return true;+ return r; } public static void generate_html_document (string html_file, Font font) {@@ -403,37 +389,70 @@ os.put_string ( return r; } - public static string get_birdfont_export () {+ private static string[] get_birdfont_export (File folder, string temp_file) { File f;+ string dest = @"\"$((!) folder.get_path ())\" \"$temp_file\""; f = File.new_for_path ("birdfont-export.sh"); if (f.query_exists ()) {- return "sh birdfont-export.sh";+ return { + "sh", + "birdfont-export.sh",+ "-ttf",+ "--o",+ dest+ }; } f = File.new_for_path ("../birdfont-export.sh"); if (f.query_exists ()) {- return "sh ../birdfont-export.sh";+ return { + "sh", + "../birdfont-export.sh",+ "-ttf",+ "--o",+ dest+ }; } f = File.new_for_path ("birdfont-export.exe"); if (f.query_exists ()) {- return (!) f.get_path ();+ return { + (!) f.get_path (),+ "-ttf",+ "--o",+ dest+ }; } f = File.new_for_path (@"$PREFIX/birdfont-export"); if (f.query_exists ()) {- return @"$PREFIX/bin/birdfont-export";+ return { + @"$PREFIX/bin/birdfont-export",+ "-ttf",+ "--o",+ dest+ }; } f = File.new_for_path ("birdfont-export"); if (f.query_exists ()) {- return (!) f.get_path ();+ return { + (!) f.get_path (),+ "-ttf",+ "--o",+ dest+ }; } warning ("Can't find birdfont-export."); - return "birdfont-export";+ return { + "birdfont-export",+ "-ttf",+ "--o",+ dest+ }; } public static bool export_ttf_font_path (File folder, bool async = true) {@@ -442,7 +461,6 @@ os.put_string ( File eot_file; string temp_file; bool done = true;- string export_command; if (BirdFont.win32) { async = false;@@ -470,15 +488,7 @@ os.put_string ( export_thread = new ExportThread (temp_file, (!) ttf_file.get_path (), (!) eot_file.get_path ()); if (async) {- export_command = @"$(get_birdfont_export ()) --ttf -o \"$((!) folder.get_path ())\" \"$temp_file\"";- print (@"Running export command: $export_command\n");- - try {- Process.spawn_command_line_async (export_command);- } catch (Error e) {- stderr.printf (@"Failed to execute \"$export_command\" \n");- critical (@"$(e.message)");- }+ spawn_export (folder, temp_file); } if (!async) {@@ -492,6 +502,34 @@ os.put_string ( return done; }++ public static int spawn_export (File folder, string temp_file) {+ try {+ string[] spawn_env = Environ.get ();+ Pid child_pid;+ int cin, cout, cerr;+ string[] spawn_args = get_birdfont_export (folder, temp_file);++ Process.spawn_async_with_pipes (+ "/",+ spawn_args,+ spawn_env,+ SpawnFlags.SEARCH_PATH | SpawnFlags.DO_NOT_REAP_CHILD,+ null,+ out child_pid,+ out cin,+ out cout,+ out cerr);++ ChildWatch.add (child_pid, (pid, exit_status) => {+ status (_ ("Wrote font files."));+ });+ } catch (SpawnError e) {+ warning (e.message);+ }+ + return 0;+ } public static bool export_svg_font () { Font font = BirdFont.get_current_font ();@@ -521,7 +559,6 @@ os.put_string ( return false; } - status (_ ("Wrote font files")); return true; } @@ -22,6 +22,9 @@ namespace BirdFont { public class MenuTab : FontDisplay { List<Font> recent_fonts = new List<Font> ();+ + /** Ignore actions when export is in progress. */+ public static bool suppress_event = false; public MenuTab () { // html callbacks:@@ -55,7 +58,11 @@ public class MenuTab : FontDisplay { MainWindow.get_tool_tip ().show_text (val); }); }- + + public static void set_suppress_event (bool e) {+ suppress_event = e;+ }+ public override string get_name () { return "Menu"; }@@ -250,13 +257,23 @@ c.append (""" } public void load_backup (string file_name) {- File backup_file = BirdFont.get_backup_directory ();+ File backup_file;+ + if (!suppress_event) {+ return;+ }+ + backup_file = BirdFont.get_backup_directory (); backup_file = backup_file.get_child (file_name); load_font ((!) backup_file.get_path ()); } public void load_font (string fn) { Font font = BirdFont.get_current_font ();++ if (!suppress_event) {+ return;+ } SaveDialog save = new SaveDialog (); save.finished.connect (() => {@@ -296,6 +313,10 @@ c.append (""" } private static void select_overview () {+ if (!suppress_event) {+ return;+ }+ if (BirdFont.get_current_font ().is_empty ()) { Toolbox.select_tool_by_name ("custom_character_set"); } else {@@ -308,6 +329,10 @@ c.append (""" string f; bool saved = false; Font font = BirdFont.get_current_font ();++ if (!suppress_event) {+ return;+ } fn = MainWindow.file_chooser_save (_("Save")); @@ -331,6 +356,10 @@ c.append (""" string fn; bool saved = false; + if (!suppress_event) {+ return;+ }+ f.delete_backup (); fn = (!) f.font_file;@@ -356,8 +385,16 @@ c.append (""" } public static void new_file () {- Font font = BirdFont.get_current_font ();- SaveDialog save = new SaveDialog ();+ Font font;+ SaveDialog save;++ if (!suppress_event) {+ return;+ }++ save = new SaveDialog ();+ font = BirdFont.get_current_font ();+ save.finished.connect (() => { BirdFont.new_font (); MainWindow.close_all_tabs ();@@ -380,6 +417,10 @@ c.append (""" SaveDialog save = new SaveDialog (); Font font = BirdFont.get_current_font (); + if (!suppress_event) {+ return;+ }+ save.finished.connect (() => { load_new_font (); });@@ -392,8 +433,15 @@ c.append (""" } private static void load_new_font () {- string? fn = MainWindow.file_chooser_open (_("Open"));- Font f = BirdFont.get_current_font ();+ string? fn;+ Font f;++ if (!suppress_event) {+ return;+ }+ + f = BirdFont.get_current_font ();+ fn = MainWindow.file_chooser_open (_("Open")); if (fn != null) { f.delete_backup ();@@ -412,9 +460,17 @@ c.append (""" } public static void preview () {- TabBar tab_bar = MainWindow.get_tab_bar ();- FontFormat format = BirdFont.get_current_font ().format;- OverwriteDialog overwrite = new OverwriteDialog ();+ TabBar tab_bar;+ FontFormat format;+ OverwriteDialog overwrite;++ if (!suppress_event) {+ return;+ }++ tab_bar = MainWindow.get_tab_bar ();+ format = BirdFont.get_current_font ().format;+ overwrite = new OverwriteDialog (); overwrite.finished.connect (() => { tab_bar.add_unique_tab (new Preview (), 80); @@ -1660,9 +1660,14 @@ class GlyfTable : Table { public void process () throws GLib.Error { FontData fd = new FontData (); + uint last_len = 0; + uint i = 0; + uint num_glyphs; create_glyph_table (); - uint last_len = 0; + + num_glyphs = glyphs.length (); + foreach (Glyph g in glyphs) { // set values for loca table assert (fd.length () % 4 == 0); @@ -1674,6 +1679,8 @@ class GlyfTable : Table { printd (@"loca fd.length (): $(fd.length ())\n"); last_len = fd.length (); + + ProgressBar.set_progress ((double) (++i) / num_glyphs); } location_offsets.append (fd.length ()); // last entry in loca table is special @@ -4187,10 +4194,9 @@ class CffTable : Table { return 0; } - List<uint32> read_index () { + List<uint32> read_index () throws Error { uint32 offset_size, off; - int entries, len; - string data; + int entries; List<uint32> offsets = new List<uint32> (); entries = dis.read_ushort (); @@ -4215,7 +4221,7 @@ class CffTable : Table { } public override void parse (FontData dis) throws Error { - uint v1, v2, offset_size, entries, header_size, len; + uint v1, v2, offset_size, header_size, len; string data; List<uint32> offsets, dict_index; int id, val; @@ -4291,7 +4297,6 @@ class CffTable : Table { public void process () throws GLib.Error { FontData fd = new FontData (); string name = "typeface"; - uint8 dict_length; // header fd.add_byte (1); // format version (1.0) @@ -4658,14 +4663,20 @@ class GposTable : Table { } // pair table + i = 0; + foreach (Kern k in kern_table.kernings) { // pair value record fd.add_ushort (1); // n pair vaules fd.add_ushort (k.right); // gid to second glyph fd.add_short (k.kerning); // value of ValueFormat1, horizontal adjustment for advance // value of ValueFormat2 is null + + ProgressBar.set_progress ((double) (num_kerning_values - ++i) / num_kerning_values); } + ProgressBar.set_progress (0); // reset progress bar + // coverage fd.add_ushort (1); // format fd.add_ushort (num_kerning_values); // number of gid new file mode 100644@@ -0,0 +1,58 @@+/*+ Copyright (C) 2012, 2013 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/>.+*/++namespace BirdFont {++/** Progress bar */+class ProgressBar {+ + static double current_progress = 0;+ + public signal void new_progress ();++ static ProgressBar? singleton = null;++ public ProgressBar () {+ singleton = this;+ }++ public static void set_progress (double d) {+ ProgressBar p;+ + if (singleton == null) {+ return;+ }+ + p = (!) singleton;+ current_progress = d;+ p.new_progress ();+ }++ public static double get_progress () {+ ProgressBar p;+ + if (singleton == null) {+ return 0;+ }+ + p = (!) singleton;+ + return ProgressBar.current_progress;+ }+}++}@@ -409,6 +409,10 @@ public class TabBar : GLib.Object { public void select_tab_click (double x, double y, int width, int height) { int over, close; + if (MenuTab.suppress_event) {+ return;+ }+ this.width = width; this.height = height; @@ -23,12 +23,24 @@ namespace BirdFont { public class TooltipArea : GLib.Object { string tool_tip;+ ProgressBar progress_bar;+ public signal void redraw (); public TooltipArea () {+ progress_bar = new ProgressBar ();+ progress_bar.new_progress.connect (progress);+ set_text_from_tool (); } + void progress () {+ redraw ();+ MenuTab.set_suppress_event (true);+ Tool.yield ();+ MenuTab.set_suppress_event (false);+ }+ public void update_text () { set_text_from_current_tool (); redraw ();@@ -110,6 +122,14 @@ public class TooltipArea : GLib.Object { cr.restore (); cr.save ();+ cr.rectangle (0, 0, alloc.width * ProgressBar.get_progress (), alloc.height);+ cr.set_line_width (0);+ cr.set_source_rgba (255/255.0, 255/255.0, 255/255.0, 1);+ cr.fill_preserve ();+ cr.stroke ();+ cr.restore ();+ + cr.save (); cr.set_font_size (14); cr.move_to (5, 15); cr.show_text (tool_tip);@@ -16,6 +16,7 @@ */ #include <assert.h>+#include <glib.h> #include <stdio.h> #include <string.h> #include <stdlib.h>@@ -25,7 +26,7 @@ #include FT_OPENTYPE_VALIDATE_H #include FT_TRUETYPE_TABLES_H -#include <glib.h>+//#include "birdfont.h" /** Error codes. */ #define OK 0@@ -85,7 +86,8 @@ void create_contour (FT_Vector* points, char* flags, int* length, FT_Vector** ne j = 0; for (i = 0; i < len; i++) { if (is_quadratic (flags[i])) {- if (prev_is_curve && j != 0) { // i == 0?+ if (prev_is_curve && j != 0) {+ // add a new point if half way between two off curve points x = p[j - 1].x + ((points[i].x - p[j - 1].x) / 2.0); y = p[j - 1].y + ((points[i].y - p[j - 1].y) / 2.0); @@ -338,6 +340,8 @@ GString* get_svg_font (FT_Face face, int* err) { g_string_append (svg, svg_data->str); g_string_append (svg, "\" />\n");+ + bird_font_progress_bar_set_progress ((double)i / face->num_glyphs); } // kerning@@ -345,6 +349,8 @@ GString* get_svg_font (FT_Face face, int* err) { hkern = get_kerning_data (face, i); g_string_append (svg, hkern->str); g_string_free (hkern, 0);++ bird_font_progress_bar_set_progress ((double)(face->num_glyphs - i) / face->num_glyphs); } g_string_append (svg, "</font>\n");@@ -363,7 +369,7 @@ int validate_font (FT_Face face) { const FT_Byte* GPOS_table = NULL; const FT_Byte* GSUB_table = NULL; const FT_Byte* JSTF_table = NULL;- int error = OK;+ int error; error = FT_OpenType_Validate (face, FT_VALIDATE_BASE | FT_VALIDATE_GDEF | FT_VALIDATE_GPOS | FT_VALIDATE_GSUB | FT_VALIDATE_JSTF, &BASE_table, &GDEF_table, &GPOS_table, &GSUB_table, &JSTF_table); @@ -102,7 +102,7 @@ def build(): # generate c code run("cp ../libbirdfont/*.c ../build/win32/libbirdfont/")- run("valac -C --basedir ../build/win32/libbirdfont/ --library libbirdfont -H birdfont.h ../libbirdfont/*.vala --pkg libxml-2.0 --pkg gio-2.0 --pkg cairo --pkg libsoup-2.4 --pkg gdk-pixbuf-2.0 --pkg webkit-1.0")+ run("valac -C --basedir ../build/win32/libbirdfont/ --library libbirdfont -H ../build/win32/libbirdfont/birdfont.h ../libbirdfont/*.vala --pkg libxml-2.0 --pkg gio-2.0 --pkg cairo --pkg libsoup-2.4 --pkg gdk-pixbuf-2.0 --pkg webkit-1.0") run("valac -C ../birdfont/* --vapidir=./ --pkg libxml-2.0 --pkg gio-2.0 --pkg cairo --pkg libsoup-2.4 --pkg gdk-pixbuf-2.0 --pkg webkit-1.0 --pkg gtk+-2.0 --pkg libbirdfont") run("mv ./*.c ../build/win32/birdfont/")