Commit 0877a19
speed optimisation
Changed files (7)
modifiedREADMEmodifiedsrc/Argument.valamodifiedsrc/Font.valamodifiedsrc/OpenFontFormatWriter.valamodifiedsrc/OverView.valamodifiedsrc/Path.valamodifiedsrc/Supplement.vala
Diff
@@ -12,7 +12,7 @@ Building Supplement from source Install vala and all required libraries, they are most likely in packages with a -dev or -devel affix. You can run this as root if you are using Debian: -apt-get install valac libglib-2.0-dev libgtk+2.0-dev libxml2-dev+apt-get install valac libglib-2.0-dev libgtk+2.0-dev libxml2-dev libwebkitgtk-dev Configure, build and install with waf: ./waf configure@@ -46,6 +46,13 @@ class Argument : GLib.Object { i++; continue; }+ + // file name+ if (i == 1 && !a.has_prefix ("-")) {+ prev = a;+ i++;+ continue;+ } // a single character, like -t if (!a.has_prefix ("--") && a.has_prefix ("-")) {@@ -61,8 +68,8 @@ class Argument : GLib.Object { return i; } - // not argument to test- if (prev != "--test") {+ // not argument to parameter+ if (!(prev == "--test")) { return i; } @@ -73,6 +80,21 @@ class Argument : GLib.Object { return 0; } + /** Return the font file parameter. */+ public string get_file () {+ string f = "";+ + if (args.length () >= 2) {+ f = args.nth (1).data;+ }++ if (f.has_prefix ("-")) {+ return "";+ }+ + return f;+ }+ public void print_all () { print (@"$(args.length ()) arguments:\n"); @@ -200,7 +222,7 @@ class Argument : GLib.Object { { stdout.printf ("Usage: "); stdout.printf (args.nth (0).data);- stdout.printf (" [OPTION ...]\n");+ stdout.printf (" [FILE] [OPTION ...]\n"); print_padded ("-e, --exit", "exit if a testcase failes"); print_padded ("-h, --help", "show this message");@@ -954,11 +954,18 @@ class Font : GLib.Object { this.kerning.insert (@"$left$right", k); } - private void parse_background (Xml.Node* node) {+ private void parse_background (Xml.Node* node) + requires (node != null)+ { string attr_name; string attr_content; for (Xml.Attr* prop = node->properties; prop != null; prop = prop->next) {+ + return_if_fail (!is_null (prop->name));+ return_if_fail (!is_null (prop->children));+ return_if_fail (!is_null (prop->children->content));+ attr_name = prop->name; attr_content = prop->children->content; @@ -2454,10 +2454,9 @@ class OffsetTable : Table { public void process () { FontData fd = new FontData (); - Fixed version = 1 << 16; + + // sfnt version 1.0 for TTF CFF else use OTTO - // version 1.0 for TTF CFF else use OTTO - assert (version.equals (1, 0)); num_tables = (uint16) directory_table.get_tables ().length () - 2; // number of tables, skip DirectoryTable and OffsetTable @@ -2465,7 +2464,7 @@ class OffsetTable : Table { entry_selector = max_log_2_less_than_i (num_tables); range_shift = 16 * num_tables - search_range; - fd.add_fixed (version); + fd.add_tag ("OTTO"); fd.add_u16 (num_tables); fd.add_u16 (search_range); fd.add_u16 (entry_selector); @@ -4552,20 +4551,20 @@ class DirectoryTable : Table { public bool validate_tables (FontData dis, File file) { bool valid = true; uint p = head_table.get_checksum_position (); - FontData fd = new FontData (); uint32 checksum; try { - + dis.seek (0); + if (!validate_checksum_for_entire_font (dis, file)) { warning ("file has invalid checksum"); } // zero out checksum entry in head table before validating it - fd.write_at (p + 0, 0); - fd.write_at (p + 1, 0); - fd.write_at (p + 2, 0); - fd.write_at (p + 3, 0); + dis.write_at (p + 0, 0); + dis.write_at (p + 1, 0); + dis.write_at (p + 2, 0); + dis.write_at (p + 3, 0); checksum = (uint32) dis.check_sum (); @@ -4633,6 +4632,8 @@ class DirectoryTable : Table { checksum_head = head_table.get_font_checksum (); + dis.seek (0); + // zero out checksum entry in head table before validating it dis.write_at (p + 0, 0); dis.write_at (p + 1, 0); @@ -577,7 +577,7 @@ class OverView : FontDisplay { public void scroll_to (double percent) { int64 r;- int64 l;+ double l; Font f; if (all_avail) {@@ -587,7 +587,8 @@ class OverView : FontDisplay { l = glyph_range.length (); } - r = (int64) ((percent * l * items_per_row) / rows);+ l /= rows;+ r = (int64) (percent * l * items_per_row); scroll_to_position (r); } @@ -868,7 +868,7 @@ class Path { second_last_point = last_point; last_point = p; - update_region_boundries ();+ // CPU hog update_region_boundries (); return np; @@ -73,8 +73,9 @@ class Supplement { return args.get_argument (param); } - public static void main(string[] arg) { + public static int main(string[] arg) { int err_arg; + File font_file; args = new Argument.command_line (arg); @@ -95,6 +96,15 @@ class Supplement { current_font = new Font (); + if (args.get_file () != "") { + font_file = File.new_for_path (args.get_file ()); + + if (!font_file.query_exists ()) { + stderr.printf (@"File $(args.get_file ()) not found."); + return -1; + } + } + Gtk.init (ref arg); var window = new MainWindow ("Supplement"); window.show_all (); @@ -102,6 +112,12 @@ class Supplement { var idle = new IdleSource (); idle.set_callback(() => { preferences.load (); + + if (args.get_file () != "") { + current_font.load (args.get_file ()); + MainWindow.get_toolbox ().select_tool_by_name ("available_characters"); + } + return false; }); @@ -110,8 +126,14 @@ class Supplement { Gtk.main (); preferences.set_last_file (get_current_font ().get_path ()); + + return 0; } } +internal bool is_null (void* n) { + return n == null; +} + }