Commit 8ed1aea
truncate kerning table
Changed files (9)
modifiedREADMEmodifiedbirdfont-export.shmodifiedbirdfont-export/BirdfontExport.valamodifiedbirdfont.shmodifiedlibbirdfont/BirdFont.valamodifiedlibbirdfont/ExportTool.valamodifiedlibbirdfont/Font.valamodifiedlibbirdfont/OpenFontFormatWriter.valamodifiedlibbirdfont/load_svg_font.c
Diff
@@ -61,6 +61,8 @@ You need to install the windows version on drive C:. A Ubuntu package is avalilable at https://launchpad.net You can apt-get install birdfont form Olivier Bertens repository. +A Debian packages is available at http://packages.debian.org + A Machintosh binary image is available at http://birdfont.org You might need to install a more recent version of XOrg. Install the server and run: @@ -1,4 +1,6 @@+#!/bin/bash export LD_LIBRARY_PATH="./build/:$LD_LIBRARY_PATH" PKG_PATH=$(dirname "$(readlink -f "$0")") cd "${PKG_PATH}"-./build/bin/birdfont-export $@++./build/bin/birdfont-export "$@"@@ -17,7 +17,6 @@ using BirdFont; -/** Stand alone command line utility for exporting fonts. */-public static int main (string[] arg) { +public static int main (string[] arg) { return run_export (arg); }@@ -1,3 +1,4 @@+#!/bin/bash export LD_LIBRARY_PATH="./build/:$LD_LIBRARY_PATH" PKG_PATH=$(dirname "$(readlink -f "$0")") cd "${PKG_PATH}"@@ -18,7 +18,7 @@ using BirdFont; const string GETTEXT_PACKAGE = "birdfont"; namespace BirdFont {-+ static void print_export_help (string[] arg) { stdout.printf (_("Usage:")); stdout.printf (arg[0]);@@ -38,7 +38,7 @@ public static int run_export (string[] arg) { bool write_svg = false; File directory;- + if (arg.length < 2) { print_export_help (arg); return -1;@@ -177,13 +177,13 @@ public bool has_flag (uint32 flag, uint32 mask) { public class BirdFont { public static Argument args; public static bool experimental = false;- internal static bool show_coordinates = false;- internal static bool fatal_wanings = false;+ public static bool show_coordinates = false;+ public static bool fatal_wanings = false; public static bool win32 = false; public static bool mac = false;- internal static string exec_path = "";+ public static string exec_path = ""; - internal static Font current_font;+ public static Font current_font; public static Glyph current_glyph; public void init (string[] arg) {@@ -471,6 +471,7 @@ os.put_string ( 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);@@ -481,7 +482,6 @@ os.put_string ( } if (!async) {- print ("sync\n"); export_thread.run (); } @@ -886,7 +886,6 @@ public class Font : GLib.Object { } private bool parse_svg_file (string path) {- print ("parse_svg_file\n"); SvgFont svg_font = new SvgFont (this); svg_font.load (path); return true;@@ -275,14 +275,14 @@ class FontData : Object { public uint64 read_uint64 () { uint64 f; - f = read () << 8 * 7; - f += read () << 8 * 6; - f += read () << 8 * 5; - f += read () << 8 * 4; - f += read () << 8 * 3; - f += read () << 8 * 2; - f += read () << 8 * 1; - f += read () << 8 * 0; + f = (uint64) read () << 8 * 7; + f += (uint64) read () << 8 * 6; + f += (uint64) read () << 8 * 5; + f += (uint64) read () << 8 * 4; + f += (uint64) read () << 8 * 3; + f += (uint64) read () << 8 * 2; + f += (uint64) read () << 8 * 1; + f += (uint64) read () << 8 * 0; return f; } @@ -4240,6 +4240,7 @@ class KernTable : Table { uint16 search_range = 0; Kern kern; + int i; fd.add_ushort (0); // version fd.add_ushort (1); // n subtables @@ -4253,8 +4254,8 @@ class KernTable : Table { } if (n_pairs > (uint16.MAX - 14) / 6.0) { - warning ("Too many kerning pairs!"); // TODO: find a way to deal with it. - n_pairs = 0; + warning ("Too many kerning pairs!"); + n_pairs = (uint16) ((uint16.MAX - 14) / 6.0); } this.kerning_pairs = n_pairs; @@ -4274,27 +4275,31 @@ class KernTable : Table { gid_left = 0; - if (n_pairs != 0) { // n_pairs will be set to zero to prevent buffer overflow - foreach (Glyph g in glyf_table.glyphs) { + i = 0; + foreach (Glyph g in glyf_table.glyphs) { + + foreach (Kerning k in g.kerning) { + // n_pairs is used to truncate this table to prevent buffer overflow + if (n_pairs == ++i) { + break; + } + + gid_right = glyf_table.get_gid (k.glyph_right); - foreach (Kerning k in g.kerning) { - gid_right = glyf_table.get_gid (k.glyph_right); - - if (gid_right == -1) { - warning ("right glyph not found in kerning table"); - } - - kern = new Kern (gid_left, (uint16)gid_right, (int16) (k.val * UNITS)); - - fd.add_ushort (kern.left); - fd.add_ushort (kern.right); - fd.add_short (kern.kerning); - - kernings.append (kern); + if (gid_right == -1) { + warning ("right glyph not found in kerning table"); } - gid_left++; + kern = new Kern (gid_left, (uint16)gid_right, (int16) (k.val * UNITS)); + + fd.add_ushort (kern.left); + fd.add_ushort (kern.right); + fd.add_short (kern.kerning); + + kernings.append (kern); } + + gid_left++; } fd.pad (); @@ -4772,7 +4777,7 @@ class DirectoryTable : Table { fd = new FontData (); - return_val_if_fail (offset_table.num_tables > 0, fd); + return_if_fail (offset_table.num_tables > 0); table_offset += offset_table.get_font_data ().length_with_padding (); @@ -4842,7 +4847,7 @@ internal static uint16 largest_pow2_exponent (uint16 max) { } void printd (string s) { - print (s); + //print (s); } } @@ -199,7 +199,6 @@ GString* get_svg_glyph_data (FT_Face face, int* err) { int end; if (face->glyph->outline.n_points == 0) {- fprintf (stderr, "Freetype error no points for outline in glyph.\n"); // FIXME: DELETE return svg; }