Commit f43d804
Fix spacing classes
Changed files (6)
modifiedlibbirdfont/GlyphRange.valamodifiedlibbirdfont/KerningClasses.valamodifiedlibbirdfont/Path.valamodifiedlibbirdfont/PointConverter.valamodifiedlibbirdfont/SpacingClass.valamodifiedlibbirdfont/SpacingData.vala
Diff
@@ -533,7 +533,9 @@ public class GlyphRange { uns = unserialize (c); if (uns.char_count () != 1) {- warning (@"Expecting a single character got $c");+ // the glyph was not found by its name because it is not in the list of+ // unassigned characters+ return false; } s = uns.get_char ();@@ -80,6 +80,27 @@ public class KerningClasses : GLib.Object { } } + /** Copy kerning pairs for newly created spacing classes. */+ public void copy_single_kerning_pairs (string from_spacing_class, string to_spacing_class) {+ double? kerning;+ + foreach (string left in single_kerning_letters_left) { + kerning = get_kerning_for_single_glyphs (left, from_spacing_class);+ + if (kerning != null) {+ set_kerning_for_single_glyphs (left, to_spacing_class, (!) kerning);+ }+ }++ foreach (string right in single_kerning_letters_right) { + kerning = get_kerning_for_single_glyphs (from_spacing_class, right);+ + if (kerning != null) {+ set_kerning_for_single_glyphs (to_spacing_class, right, (!) kerning);+ }+ } + }+ /** Class based gpos kerning. */ public double get_kerning_for_pair (string a, string b, GlyphRange? gr_left, GlyphRange? gr_right) { double k = 0;@@ -127,34 +148,19 @@ public class KerningClasses : GLib.Object { return 0; } - public void update_space_class (string c) {- double? k;- - foreach (string l in single_kerning_letters_left) { - k = get_kerning_for_single_glyphs (l, c);- - if (k != null) {- set_kerning_for_single_glyphs (l, c, (!) k);- }- }-- foreach (string r in single_kerning_letters_right) { - k = get_kerning_for_single_glyphs (c, r);- - if (k != null) {- set_kerning_for_single_glyphs (c, r, (!) k);- }- } - }- public double? get_kerning_for_single_glyphs (string first, string next) { double? k = null;+ double? kerning = null; string left = GlyphRange.serialize (first); string right = GlyphRange.serialize (next); foreach (string l in get_spacing_class (left)) { foreach (string r in get_spacing_class (right)) {- k = single_kerning.get (@"$l - $r");+ kerning = single_kerning.get (@"$l - $r");+ + if (kerning != null) {+ k = kerning;+ } } } @@ -1533,7 +1533,7 @@ public class Path : GLib.Object { if (steps == -1) { steps = (int) (10 * get_length_from (start, stop));- }+ } if (right == PointType.DOUBLE_CURVE || left == PointType.DOUBLE_CURVE) { return all_of_double (start.x, start.y, start.get_right_handle ().x, start.get_right_handle ().y, stop.get_left_handle ().x, stop.get_left_handle ().y, stop.x, stop.y, iter, steps, min_t, max_t);@@ -1,5 +1,5 @@ /*- Copyright (C) 2014 Johan Mattsson+ Copyright (C) 2014 2016 Johan Mattsson This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as @@ -50,6 +50,8 @@ public class PointConverter { } } + + if (!original_path.is_open ()) { if (quadratic_path.get_last_point ().get_right_handle ().type == PointType.CUBIC) { PenTool.convert_point_segment_type (quadratic_path.get_last_point (),@@ -93,8 +95,9 @@ public class PointConverter { quadratic_segment_start = segment_start.copy (); quadratic_segment_stop = segment_stop.copy (); - PenTool.convert_point_segment_type (quadratic_segment_start, quadratic_segment_stop, PointType.DOUBLE_CURVE);- + PenTool.convert_point_segment_type (quadratic_segment_start, quadratic_segment_stop, PointType.DOUBLE_CURVE); ++ // add new points to estimate path distance = 0; e = new EditPoint (); if (segment_start.get_right_handle ().is_line () @@ -124,7 +127,7 @@ public class PointConverter { out double distance, out EditPoint new_point, out double step) { double max_d; double min_d;- int steps = (int) (1.6 * Path.get_length_from (a0, a1));+ int steps; double x_out, y_out; double step_out; @@ -56,12 +56,11 @@ public class SpacingClass : GLib.Object { } else { next = v.dup (); }- - updated (this); }); listener.signal_submit.connect (() => { TabContent.hide_text_input ();+ updated (this); }); TabContent.show_text_input (listener);@@ -83,11 +83,11 @@ public class SpacingData : GLib.Object { } public void add_class (string first, string next) {- SpacingClass s = new SpacingClass (first, next);- s.updated.connect (update_all_rows);- s.updated.connect (update_kerning);- classes.add (s);- update_kerning (s);+ SpacingClass spacing_class = new SpacingClass (first, next);+ spacing_class.updated.connect (update_all_rows);+ spacing_class.updated.connect (update_kerning);+ classes.add (spacing_class);+ update_kerning (spacing_class); } void update_all_rows (SpacingClass s) {@@ -103,14 +103,18 @@ public class SpacingData : GLib.Object { return; } - kerning_classes.update_space_class (s.next);+ if (s.next == "" || s.first == "") {+ return;+ }+ + kerning_classes.copy_single_kerning_pairs (s.first, s.next);+ g = font.get_glyph_collection (s.next); if (g != null) { gc = (!) g; gc.get_current ().update_spacing_class (); } - kerning_classes.update_space_class (s.first); g = font.get_glyph_collection (s.first); if (g != null) { gc = (!) g;