Commit 7ad3924
menu items for removing kerning classes
Changed files (13)
modifiedbirdfont/GtkWindow.valamodifiedlibbirdfont/BirdFontFile.valamodifiedlibbirdfont/Font.valamodifiedlibbirdfont/Glyph.valamodifiedlibbirdfont/KerningClasses.valamodifiedlibbirdfont/KerningDisplay.valamodifiedlibbirdfont/KerningRange.valamodifiedlibbirdfont/KerningTools.valamodifiedlibbirdfont/OpenFontFormat/GposTable.valamodifiedlibbirdfont/OpenFontFormat/Kern.valamodifiedlibbirdfont/OpenFontFormat/OpenFontFormatWriter.valamodifiedlibbirdfont/SvgFont.valamodifiedlibbirdfont/SvgFontFormatWriter.vala
Diff
@@ -457,6 +457,7 @@ public class GtkWindow : Gtk.Window, NativeWindow { Gtk.Menu edit_menu = new Gtk.Menu (); Gtk.Menu tab_menu = new Gtk.Menu (); Gtk.Menu tool_menu = new Gtk.Menu ();+ Gtk.Menu kerning_menu = new Gtk.Menu (); AccelGroup accel_group = new Gtk.AccelGroup(); add_accel_group (accel_group);@@ -497,11 +498,6 @@ public class GtkWindow : Gtk.Window, NativeWindow { file_menu.append (description_item); description_item.activate.connect (() => { MenuTab.show_description (); }); - Gtk.MenuItem kerning_item = new Gtk.MenuItem.with_mnemonic (_("_Kerning"));- file_menu.append (kerning_item);- kerning_item.activate.connect (() => { MenuTab.show_kerning_context (); });- kerning_item.add_accelerator ("activate", accel_group, 'K', Gdk.ModifierType.CONTROL_MASK, Gtk.AccelFlags.VISIBLE);- Gtk.MenuItem select_language_item = new Gtk.MenuItem.with_mnemonic (_("Select _Character Set")); file_menu.append (select_language_item); select_language_item.activate.connect (() => { MenuTab.select_language (); });@@ -709,6 +705,27 @@ public class GtkWindow : Gtk.Window, NativeWindow { }); zoom_1_1_item.add_accelerator ("activate", accel_group, '0', Gdk.ModifierType.CONTROL_MASK, Gtk.AccelFlags.VISIBLE); + // Kerning+ Gtk.MenuItem show_kerning_tab = new Gtk.MenuItem.with_mnemonic (_("Show Kerning _Tab"));+ kerning_menu.append (show_kerning_tab);+ show_kerning_tab.activate.connect (() => { + MenuTab.show_kerning_context ();+ });+ show_kerning_tab.add_accelerator ("activate", accel_group, 'k', Gdk.ModifierType.CONTROL_MASK, Gtk.AccelFlags.VISIBLE);++ Gtk.MenuItem remove_all_kerning_pairs = new Gtk.MenuItem.with_mnemonic (_("_Remove All Kerning Pairs"));+ kerning_menu.append (remove_all_kerning_pairs);+ remove_all_kerning_pairs.activate.connect (() => { + KerningClasses.get_instance ().remove_all_pairs ();+ });++ Gtk.MenuItem remove_all_kerning_classes = new Gtk.MenuItem.with_mnemonic (_("Remove All Kerning _Classes"));+ kerning_menu.append (remove_all_kerning_classes);+ remove_all_kerning_classes.activate.connect (() => { + KerningClasses.get_instance ().remove_all_pairs ();+ KerningTools.remove_all_kerning_classes ();+ });+ // Add menus Gtk.MenuItem file_launcher = new Gtk.MenuItem.with_mnemonic (_("_File")); file_launcher.set_submenu (file_menu);@@ -721,11 +738,15 @@ public class GtkWindow : Gtk.Window, NativeWindow { Gtk.MenuItem tool_launcher = new Gtk.MenuItem.with_mnemonic (_("T_ool")); tool_launcher.set_submenu (tool_menu);++ Gtk.MenuItem kerning_launcher = new Gtk.MenuItem.with_mnemonic (_("_Kerning"));+ kerning_launcher.set_submenu (kerning_menu); menubar.append (file_launcher); menubar.append (edit_launcher); menubar.append (tab_launcher); menubar.append (tool_launcher);+ menubar.append (kerning_launcher); return menubar; }@@ -199,19 +199,19 @@ class BirdFontFile { } }); - uint num_kerning_pairs = KerningClasses.classes_first.length ();+ uint num_kerning_pairs = KerningClasses.get_instance ().classes_first.length (); for (uint i = 0; i < num_kerning_pairs; i++) { os.put_string ("<kerning "); os.put_string ("left=\"");- os.put_string (KerningClasses.classes_first.nth (i).data.get_all_ranges ());+ os.put_string (KerningClasses.get_instance ().classes_first.nth (i).data.get_all_ranges ()); os.put_string ("\" "); os.put_string ("right=\"");- os.put_string (KerningClasses.classes_last.nth (i).data.get_all_ranges ());+ os.put_string (KerningClasses.get_instance ().classes_last.nth (i).data.get_all_ranges ()); os.put_string ("\" "); os.put_string ("hadjustment=\"");- os.put_string (float_point (KerningClasses.classes_kerning.nth (i).data.val));+ os.put_string (float_point (KerningClasses.get_instance ().classes_kerning.nth (i).data.val)); os.put_string ("\" />\n"); } @@ -538,7 +538,7 @@ class BirdFontFile { KerningTools.add_unique_class (kerning_range); } - KerningClasses.set_kerning (range_left, range_right, hadjusment);+ KerningClasses.get_instance ().set_kerning (range_left, range_right, hadjusment); } catch (MarkupError e) { warning (e.message);@@ -583,7 +583,7 @@ class BirdFontFile { grr = new GlyphRange (); grr.parse_ranges (right); - KerningClasses.set_kerning (grl, grr, double.parse (kern)); + KerningClasses.get_instance ().set_kerning (grl, grr, double.parse (kern)); } catch (MarkupError e) { warning (e.message); }@@ -79,7 +79,7 @@ public class Font : GLib.Object { /** File format. */ public FontFormat format = FontFormat.BIRDFONT; - KerningClasses kerning_classes;+ KerningClasses kerning_classes = new KerningClasses (); public Font () { // positions in pixels at first zoom level@@ -90,14 +90,16 @@ public class Font : GLib.Object { base_line = 0; bottom_position = 20; bottom_limit = 27;- - kerning_classes = new KerningClasses (); } public void touch () { modified = true; } + public KerningClasses get_kerning_classes () {+ return kerning_classes;+ }+ public File get_backgrounds_folder () { string fn = @"$(get_name ()) backgrounds"; File f = BirdFont.get_settings_directory ().get_child (fn);@@ -1713,7 +1713,7 @@ public class Glyph : FontDisplay { juxtaposed = (font.has_glyph (name)) ? (!) font.get_glyph (name) : font.get_space (); if (font.has_glyph (last_name) && font.has_glyph (name)) {- kern = KerningClasses.get_kerning (last_name, name);+ kern = KerningClasses.get_instance ().get_kerning (last_name, name); } else { kern = 0; }@@ -1727,7 +1727,7 @@ public class Glyph : FontDisplay { cr.restore (); } - x += juxtaposed.get_width () + KerningClasses.get_kerning (glyph.name, name) + kern;+ x += juxtaposed.get_width () + KerningClasses.get_instance ().get_kerning (glyph.name, name) + kern; last_name = name; } @@ -1739,7 +1739,7 @@ public class Glyph : FontDisplay { juxtaposed = (font.has_glyph (name)) ? (!) font.get_glyph (name) : font.get_space (); if (font.has_glyph (last_name) && font.has_glyph (name)) {- kern = KerningClasses.get_kerning (name, last_name);+ kern = KerningClasses.get_instance ().get_kerning (name, last_name); } else { kern = 0; }@@ -21,29 +21,25 @@ namespace BirdFont { public class KerningClasses : GLib.Object { // kerning for classes- public static List<GlyphRange> classes_first;- public static List<GlyphRange> classes_last;- public static List<Kerning> classes_kerning;+ public List<GlyphRange> classes_first;+ public List<GlyphRange> classes_last;+ public List<Kerning> classes_kerning; public delegate void KerningIterator (string left, string right, double kerning); public KerningClasses () {- init ();- }- - public static void init () { classes_first = new List<GlyphRange> (); classes_last = new List<GlyphRange> (); classes_kerning = new List<Kerning> (); } - public static void set_kerning (GlyphRange left_range, GlyphRange right_range, double k) {+ public static KerningClasses get_instance () {+ return BirdFont.get_current_font ().get_kerning_classes ();+ }+ + public void set_kerning (GlyphRange left_range, GlyphRange right_range, double k) { int index = get_kerning_item_index (left_range, right_range); - if (is_null (classes_first)) { // FIXME: find a place to run init- init ();- }- // keep the list sorted (classes first then single glyphs) if (index == -1) { classes_first.append (left_range);@@ -57,7 +53,7 @@ public class KerningClasses : GLib.Object { } } - static void update_order (uint i) {+ void update_order (uint i) { unowned List<GlyphRange> l; unowned List<GlyphRange> r; unowned List<Kerning> k;@@ -101,7 +97,7 @@ public class KerningClasses : GLib.Object { } } - public static double get_kerning_for_range (GlyphRange range_first, GlyphRange range_last) {+ public double get_kerning_for_range (GlyphRange range_first, GlyphRange range_last) { unowned List<GlyphRange> r; unowned List<GlyphRange> l; int len = (int) classes_first.length ();@@ -128,7 +124,7 @@ public class KerningClasses : GLib.Object { return 0; } - public static int get_first_non_class () {+ public int get_first_non_class () { unowned List<GlyphRange> r; unowned List<GlyphRange> l; int len = (int) classes_first.length ();@@ -149,7 +145,7 @@ public class KerningClasses : GLib.Object { return -1; } - public static int get_kerning_item_index (GlyphRange range_first, GlyphRange range_last) {+ public int get_kerning_item_index (GlyphRange range_first, GlyphRange range_last) { unowned List<GlyphRange> r; unowned List<GlyphRange> l; int len = (int) classes_first.length ();@@ -165,10 +161,6 @@ public class KerningClasses : GLib.Object { l = classes_first.nth (i); r = classes_last.nth (i); - print (@"$(r.data.get_all_ranges ()) == $(range_first.get_all_ranges ())\n");- print (@"$(l.data.get_all_ranges ()) == $(range_last.get_all_ranges ())\n");- print (@"$(classes_kerning.nth (i).data.val)\n");- if (!l.data.is_class () && !r.data.is_class () && search_range_is_class) { continue; }@@ -182,7 +174,7 @@ public class KerningClasses : GLib.Object { return -1; } - public static double get_kerning (string left_glyph, string right_glyph) {+ public double get_kerning (string left_glyph, string right_glyph) { unowned List<GlyphRange> r; unowned List<GlyphRange> l; int len = (int) classes_first.length ();@@ -204,7 +196,7 @@ public class KerningClasses : GLib.Object { return 0; } - public static double get_kern_for_range_to_char (GlyphRange left_range, string right_char) {+ public double get_kern_for_range_to_char (GlyphRange left_range, string right_char) { unowned List<GlyphRange> r; unowned List<GlyphRange> l; int len = (int) classes_first.length ();@@ -231,7 +223,7 @@ public class KerningClasses : GLib.Object { return 0; } - public static double get_kern_for_char_to_range (string left_char, GlyphRange right_range) {+ public double get_kern_for_char_to_range (string left_char, GlyphRange right_range) { unowned List<GlyphRange> r; unowned List<GlyphRange> l; int len = (int) classes_first.length ();@@ -258,7 +250,7 @@ public class KerningClasses : GLib.Object { return 0; } - public static void print_all () {+ public void print_all () { print ("Kernings:\n"); for (int i = 0; i < classes_first.length (); i++) { print (classes_first.nth (i).data.get_all_ranges ());@@ -276,7 +268,7 @@ public class KerningClasses : GLib.Object { } } - public static void all_pairs (KerningIterator kerningIterator) {+ public void all_pairs (KerningIterator kerningIterator) { Font f = BirdFont.get_current_font (); Glyph? g1, g2; Glyph glyph1, glyph2;@@ -293,7 +285,7 @@ public class KerningClasses : GLib.Object { while (g2 != null) { glyph2 = (!) g2; - k = KerningClasses.get_kerning (glyph1.get_name (), glyph2.get_name ());+ k = KerningClasses.get_instance ().get_kerning (glyph1.get_name (), glyph2.get_name ()); if (k != 0) { kerningIterator (glyph1.get_name (), glyph2.get_name (), k); }@@ -306,6 +298,30 @@ public class KerningClasses : GLib.Object { g1 = f.get_glyph_indice (i); } }++ public void remove_all_pairs () {+ print ("Remove all kerning pairs\n");+ + while (classes_first.length () > 0) {+ classes_first.remove_link (classes_first.first ());+ }++ while (classes_last.length () > 0) {+ classes_last.remove_link (classes_last.first ());+ }+ + while (classes_kerning.length () > 0) {+ classes_kerning.remove_link (classes_kerning.first ());+ }+ + if (!is_null (MainWindow.get_glyph_canvas ())) { // FIXME: reorganize+ MainWindow.get_glyph_canvas ().redraw ();+ }+ + if (!is_null (MainWindow.get_toolbox ())) { // FIXME: reorganize+ Toolbox.redraw_tool_box ();+ }+ } } }@@ -230,7 +230,10 @@ public class KerningDisplay : FontDisplay { b = ((!) g).get_name (); if (handle == wi) {- return_if_fail (wi < word_with_ligatures.ranges.length ());+ if (wi >= word_with_ligatures.ranges.length ()) {+ warning (@"$wi > $(word_with_ligatures.ranges.length ())");+ return;+ } return_if_fail (wi - 1 >= 0); if (word_with_ligatures.ranges.length () != word_with_ligatures.glyph.length ()) {@@ -240,14 +243,6 @@ public class KerningDisplay : FontDisplay { gr_left = word_with_ligatures.ranges.nth (wi - 1).data; gr_right = word_with_ligatures.ranges.nth (wi).data; - /*- * // DELETE- // Kern table kerning and single glyph positioning- if (gr_left == null && gr_right == null) {- kern = font.get_kerning_by_name (a, b) + val;- font.set_kerning_by_name (a, b, kern);- }- */ set_kerning_pair (a, b, ref gr_left, ref gr_right, val); } @@ -282,13 +277,11 @@ public class KerningDisplay : FontDisplay { grr = (!) gr_right; } - KerningClasses.set_kerning (grl, grr, kern + val);+ KerningClasses.get_instance ().set_kerning (grl, grr, kern + val); } catch (MarkupError e) { // FIXME: unassigned glyphs and ligatures warning (e.message); }- - KerningClasses.print_all (); } /** Class based gpos kerning. */@@ -310,19 +303,19 @@ public class KerningDisplay : FontDisplay { } if (gr_left != null && gr_right != null) {- return KerningClasses.get_kerning_for_range (grl, grr);+ return KerningClasses.get_instance ().get_kerning_for_range (grl, grr); } if (gr_left != null && gr_right == null) {- return KerningClasses.get_kern_for_range_to_char (grl, b);+ return KerningClasses.get_instance ().get_kern_for_range_to_char (grl, b); } if (gr_left == null && gr_right != null) {- return KerningClasses.get_kern_for_char_to_range (a, grr);+ return KerningClasses.get_instance ().get_kern_for_char_to_range (a, grr); } if (gr_left == null && gr_right == null) {- return KerningClasses.get_kerning (a, b);+ return KerningClasses.get_instance ().get_kerning (a, b); } } catch (MarkupError e) { // FIXME: unassigned glyphs and ligatures@@ -69,9 +69,11 @@ public class KerningRange : Tool { glyph_range.set_class (true); malformed = false;- KerningClasses.print_all ();+ + // FIXME: create gui tool+ KerningClasses.get_instance ().print_all (); } catch (MarkupError e) {- KerningClasses.print_all ();+ KerningClasses.get_instance ().print_all (); warning (e.message); malformed = true; }@@ -50,6 +50,22 @@ public class KerningTools : ToolCollection { expanders.append (classes); } + public static void remove_all_kerning_classes () {+ if (is_null (classes) || is_null (classes.tool)) {+ return; // FIXME: reorganize+ }+ + print ("Remove all kerning classes\n");+ + while (classes.tool.length () > 0) {+ classes.tool.remove_link (classes.tool.first ());+ }+ + if (!is_null (MainWindow.get_toolbox ())) {+ MainWindow.get_toolbox ().update_expanders ();+ }+ }+ public static void add_unique_class (KerningRange kerning_class) { KerningRange k; @@ -198,7 +198,7 @@ class GposTable : Table { kerning_pairs.remove_link (kerning_pairs.first ()); } - KerningClasses.all_pairs ((left, right, kerning) => {+ KerningClasses.get_instance ().all_pairs ((left, right, kerning) => { uint16 gid1, gid2; PairFormat1 pair; int pair_index;@@ -120,7 +120,7 @@ class KernTable : Table { fd.add_ushort (0); // subtable version - KerningClasses.all_pairs ((left, right, k) => {+ KerningClasses.get_instance ().all_pairs ((left, right, k) => { n_pairs++; }); @@ -148,7 +148,7 @@ class KernTable : Table { i = 0; - KerningClasses.all_pairs ((left, right, k) => {+ KerningClasses.get_instance ().all_pairs ((left, right, k) => { uint16 gid1, gid2; try {@@ -76,7 +76,7 @@ class OpenFontFormatWriter : Object { } void printd (string s) {- print (s);+ //print (s); } }@@ -123,7 +123,7 @@ class SvgFont : GLib.Object { grr = new GlyphRange (); grr.parse_ranges (sr.str); - KerningClasses.set_kerning (grl, grr, -kerning);+ KerningClasses.get_instance ().set_kerning (grl, grr, -kerning); } catch (MarkupError e) { warning (e.message); } @@ -87,7 +87,7 @@ class SvgFontFormatWriter : Object { // FIXME: ligatures - KerningClasses.all_pairs ((left, right, k) => {+ KerningClasses.get_instance ().all_pairs ((left, right, k) => { string l, r; Font f = BirdFont.get_current_font (); Glyph? gr = f.get_glyph (right);