Commit a32c242
look up name in kerning tab
Changed files (6)
modifiedsrc/Context.valamodifiedsrc/Font.valamodifiedsrc/GlyphTable.valamodifiedsrc/Path.valamodifiedsrc/PenTool.valamodifiedsrc/TestCases.vala
Diff
@@ -143,8 +143,6 @@ class ContextDisplay : FontDisplay { font.touch (); - // handle++; // use handle before next glyph- a = ""; b = ""; @@ -158,7 +156,6 @@ class ContextDisplay : FontDisplay { b = s; if (handle == wi) {- print (@"SET get $a\n"); kern = font.get_kerning (a, b) + val; font.set_kerning (a, b, kern); }@@ -212,7 +209,8 @@ class ContextDisplay : FontDisplay { public override void key_press (EventKey e) { unichar c = (unichar) e.keyval;- StringBuilder s = new StringBuilder ();+ Font f = Supplement.get_current_font ();+ string name; if (e.type == EventType.KEY_PRESS && (KeyBindings.singleton.modifier == NONE || KeyBindings.singleton.modifier == SHIFT)) { @@ -225,8 +223,8 @@ class ContextDisplay : FontDisplay { } if (!is_modifier_key (c) && c.validate ()) {- s.append_unichar (c);- row.first ().data.glyph.append (s.str);+ name = f.get_name_for_character (c);+ row.first ().data.glyph.append (name); } } @@ -351,7 +351,32 @@ class Font : GLib.Object { } } - bool has_name (string name) {+ public string get_name_for_character (unichar c) {+ // if some glyph is already mapped to unichar, return it's name+ uint i = 0;+ Glyph? gl;+ Glyph g;+ StringBuilder sb;+ + while ((gl = get_glyph_indice (i++)) != null) {+ g = (!) gl;+ + if (g.unichar_code == c) {+ return g.name;+ }+ }+ + // otherwise return some default name, possibly from unicode database+ if (c == 0) {+ return ".null".dup ();+ }+ + sb = new StringBuilder ();+ sb.append_unichar (c);+ return sb.str; + }+ + public bool has_name (string name) { foreach (string n in glyph_names) { if (n == name) { return true;@@ -397,12 +422,6 @@ class Font : GLib.Object { return gc; } - public Glyph? get_glyph_from_unichar (unichar glyph) {- StringBuilder name = new StringBuilder ();- name.append_unichar (glyph);- return get_glyph (name.str);- }- public Glyph? get_glyph (string glyph) { GlyphCollection? gc = get_glyph_collection (glyph); @@ -797,32 +816,6 @@ class Font : GLib.Object { return true; } - /** Measure height of x or other lower case letter. */- private double estimate_xheight () {- Glyph? g;- double ym = 0;- for (unichar c = 'x'; c >= 'a' ; c--) {- g = get_glyph_from_unichar (c);- - // we want x-height skip letters with ascender- if (c == 'l' || c == 'k' || c == 'i' - || c == 'j' || c == 'h' || c == 'd') {- continue;- }- - if (g != null) {- foreach (Path path in ((!) g).path_list) {- path.update_region_boundries ();- if (path.ymax > ym) {- ym = path.ymax;- }- }- } - }- - return -ym;- }- public bool parse_file (string path) { Parser.init (); @@ -258,16 +258,6 @@ class GlyphTable : GLib.Object { unowned List<Item>? find_next_index (string n) { unowned List<Item>? next = find_next_via_index (n);- - if (next != null) {- /*- if (compare (n, ((!)next).data) == 0) { // not unique- warning (@"Index is not unique $n == $(((!)next).data.name)");- }- */- //return ((!)next).prev;- }- return next; } @@ -43,6 +43,7 @@ class Path { bool edit = true; bool open = true; + bool set_direction_from_tool = true; bool no_derived_direction = false; bool clockwise_direction = true; @@ -1040,11 +1041,12 @@ class Path { EditPointHandle eh; quadratic_path = copy ();- + quadratic_path.close ();+ if (quadratic_path.points.length () < 2) { return quadratic_path; }- + // split all curves in as many regions as we need split_cubic_in_parts (quadratic_path); @@ -1069,9 +1071,9 @@ class Path { eh.length = 0; eh = ((!)quadratic_path.points.last ().prev).data.get_right_handle ();- eh.set_point_type (PointType.NONE);- eh.length *= 1.7;- + eh.set_point_type (PointType.CURVE);+ eh.length *= 1.6;+ return quadratic_path; } @@ -1121,12 +1123,15 @@ class Path { if (split_cubic_in_half (cubic_path, middle)) { need_split = true; }- + e = (!) cubic_path.points.first (); for (uint i = 0; i < len - 1; i++) { middle.prev = e; middle.next = e.next; + middle.get_prev ().data.recalculate_linear_handles ();+ middle.get_next ().data.recalculate_linear_handles ();+ if (split_cubic_in_half (cubic_path, middle)) { e = (!) e.next.next; need_split = true;@@ -384,7 +384,7 @@ class PenTool : Tool { ((!)glyph.active_path).points.last ().data.right_handle.parent.recalculate_linear_handles (); } - void set_default_handle_positions () {+ public static void set_default_handle_positions () { Glyph g = MainWindow.get_current_glyph (); foreach (var p in g.path_list) { if (p.is_editable ()) {@@ -394,14 +394,7 @@ class PenTool : Tool { } } - void set_default_handle_positions_on_path (Path path) {- EditPointHandle h;- EditPoint n;- double nx, ny;- - // set handle pointing at next point to create a line to next point- // as default handle position for LINE points.- + static void set_default_handle_positions_on_path (Path path) { foreach (EditPoint e in path.points) { e.recalculate_linear_handles (); }@@ -38,6 +38,25 @@ class TestCases { add (test_view_result, "View result in web browser"); add (test_save_backup, "Save backup"); add (test_convert_to_quadratic_bezier_path, "Convert to quadratic path");+ add (test_notdef, "Notdef");+ }++ public static void test_notdef () {+ Font f = Supplement.get_current_font ();+ Glyph n = f.get_not_def_character ();+ Glyph g;+ Path pn;+ + f.add_glyph (n);+ + Tool.test_open_next_glyph ();+ g = MainWindow.get_current_glyph ();+ foreach (Path p in n.path_list) {+ pn = p.copy ().get_quadratic_points ();+ g.path_list.append (pn);+ pn.move (50, 0);+ g.path_list.append (p.copy ());+ } } public static void test_convert_to_quadratic_bezier_path () {