Commit 2cb1acf
Fix memory leaks
Changed files (13)
modifiedlibbirdfont/ClipTool.valamodifiedlibbirdfont/DrawingTools.valamodifiedlibbirdfont/Font.valamodifiedlibbirdfont/Glyph.valamodifiedlibbirdfont/MoveTool.valamodifiedlibbirdfont/OpenFontFormat/GlyfTable.valamodifiedlibbirdfont/Path.valamodifiedlibbirdfont/PathList.valamodifiedlibbirdfont/PenTool.valamodifiedlibbirdfont/ResizeTool.valamodifiedlibbirdfont/SvgParser.valamodifiedlibbirdfont/TestCases.valamodifiedlibbirdfont/TrackTool.vala
Diff
@@ -107,7 +107,7 @@ public class ClipTool : Tool { s.append ("\n"); s.append ("<!-- BirdFontClipboard\n"); - if (glyph.path_list.length () > 0 && !glyph.path_list.first ().data.is_editable ()) {+ if (glyph.path_list.size > 0) { foreach (Path path in glyph.active_paths) { s.append ("BF path: "); s.append (BirdFontFile.get_point_data (path));@@ -193,7 +193,7 @@ public class ClipTool : Tool { if (path.points.length () > 0) { glyph.add_path (path);- glyph.active_paths.append (path);+ glyph.active_paths.add (path); path.update_region_boundaries (); } @@ -278,7 +278,7 @@ public class DrawingTools : ToolCollection { foreach (Path p in g.active_paths) { g.path_list.remove (p);- g.path_list.prepend (p);+ g.path_list.insert (0, p); } }); path_tool_modifiers.add_tool (move_layer);@@ -248,7 +248,7 @@ public class Font : GLib.Object { ret.right_limit = 0; ret.remove_empty_paths (); - assert (ret.path_list.length () == 0);+ assert (ret.path_list.size == 0); return ret; }@@ -266,7 +266,7 @@ public class Font : GLib.Object { n.right_limit = 0; n.remove_empty_paths (); - assert (n.path_list.length () == 0);+ assert (n.path_list.size == 0); return n; }@@ -288,7 +288,7 @@ public class Font : GLib.Object { n.right_limit = 27; n.remove_empty_paths (); - assert (n.path_list.length () == 0);+ assert (n.path_list.size == 0); return n; }@@ -30,8 +30,8 @@ public class Glyph : FontDisplay { int zoom_list_index = 0; // Paths- public List<Path> path_list;- public List<Path> active_paths = new List<Path> ();+ public Gee.ArrayList<Path> path_list = new Gee.ArrayList<Path> ();+ public Gee.ArrayList<Path> active_paths = new Gee.ArrayList<Path> (); // The point where edit event begun double pointer_begin_x = 0;@@ -86,8 +86,8 @@ public class Glyph : FontDisplay { public Glyph (string name, unichar unichar_code = 0) { this.name = name; this.unichar_code = unichar_code;- - path_list.append (new Path ());++ path_list.add (new Path ()); add_help_lines (); @@ -95,17 +95,17 @@ public class Glyph : FontDisplay { right_limit = 28; } - public override void close () {- undo_list.clear ();- }- public Glyph.no_lines (string name, unichar unichar_code = 0) { this.name = name; this.unichar_code = unichar_code; - path_list.append (new Path ());+ path_list.add (new Path ()); }- ++ public override void close () {+ undo_list.clear ();+ }+ public string get_ligature_string () { return substitution; }@@ -163,9 +163,7 @@ public class Glyph : FontDisplay { } public void clear_active_paths () {- while (active_paths.length () > 0) {- active_paths.remove_link (active_paths.first ());- }+ active_paths.clear (); } public void add_active_path (Path? p) {@@ -177,24 +175,15 @@ public class Glyph : FontDisplay { Toolbox.set_object_stroke (path.stroke); } - foreach (Path pi in active_paths) {- if (pi == p) {- return;- }+ if (!active_paths.contains (path)) {+ active_paths.add (path); }- - active_paths.append (path); } } public Path? get_active_path () {- return_val_if_fail (!is_null(active_paths), null);- - if (!is_null(active_paths.last ())) {- return null;- }- - return active_paths.last ().data;+ return_val_if_fail (active_paths.size > 0, null);+ return active_paths.get (active_paths.size - 1); } // It looks like this can be remove but firefox refuses to load@@ -208,19 +197,13 @@ public class Glyph : FontDisplay { } public void boundaries (out double x1, out double y1, out double x2, out double y2) {- if (path_list.length () == 0) {+ if (path_list.size == 0) { x1 = 0; y1 = 0; x2 = 0; y2 = 0; return; }-- path_list.first ().data.update_region_boundaries ();- x1 = path_list.first ().data.xmin;- y1 = path_list.first ().data.ymin;- x2 = path_list.first ().data.xmax;- y2 = path_list.first ().data.ymax; foreach (Path p in path_list) { p.update_region_boundaries ();@@ -259,7 +242,7 @@ public class Glyph : FontDisplay { } if (px2 == -10000 || px == 10000) {- warning (@"No box for selected paths. ($(active_paths.length ()))");+ warning (@"No box for selected paths. ($(active_paths.size))"); px = 0; py = 0; px2 = 0;@@ -346,7 +329,7 @@ public class Glyph : FontDisplay { } public void add_path (Path p) {- path_list.append (p);+ path_list.add (p); } public override void selected_canvas () {@@ -490,17 +473,8 @@ public class Glyph : FontDisplay { } } - public void delete_path (Path p) requires (path_list.length () > 0) {- for (unowned List<Path> pl = path_list.first (); pl != path_list.last (); pl = pl.next) {- if (pl.data == p) {- path_list.remove_link (pl);- return;- }- }- - if (path_list.last ().data == p) {- path_list.remove_link (path_list.last ());- }+ public void delete_path (Path p) requires (path_list.size > 0) {+ path_list.remove (p); } public string get_svg_data () {@@ -613,7 +587,7 @@ public class Glyph : FontDisplay { MainWindow.get_current_glyph ().add_active_path (path); } - if (remaining_points.paths.length () > 0) {+ if (remaining_points.paths.size > 0) { delete_path (p); return true; }@@ -723,19 +697,9 @@ public class Glyph : FontDisplay { /** Add new points to this path. */ public void set_active_path (Path p) {- unowned List<Path> pl;- for (int i = 0; i < path_list.length (); i++) {- pl = path_list.nth (i);- if (pl.data == p) {- path_list.remove_link (pl);- break;- }- }- - path_list.append (p);+ path_list.remove (p);+ path_list.add (p); p.reopen ();- - warn_if_fail (path_list.last ().data == p); } /** Insert new edit point for current path on the appropriate zoom@@ -955,16 +919,12 @@ public class Glyph : FontDisplay { } // a path without any editpoints- if (path_list.length () > 0) {- return path_list.first ().data;+ if (path_list.size > 0) {+ return path_list.get (0); } if (unlikely (min_distance == double.MAX)) {- warning (@"No path found in path_list. Length: $(path_list.length ())");- - if (path_list.length () > 0) {- stderr.printf (@"p.points.length () $(path_list.first ().data.points.length ()) \n");- }+ warning (@"No path found in path_list. Length: $(path_list.size)"); } return min_point;@@ -975,22 +935,22 @@ public class Glyph : FontDisplay { Path np; EditPoint inserted; - if (path_list.length () == 0) {+ if (path_list.size == 0) { np = new Path ();- path_list.append (np);+ path_list.add (np); } xt = path_coordinate_x (x); yt = path_coordinate_y (y); - return_val_if_fail (path_list.length () > 0, new PointSelection.empty ());+ return_val_if_fail (path_list.size > 0, new PointSelection.empty ()); - if (path_list.last ().data.is_open ()) {- np = path_list.last().data;+ if (path_list.get (path_list.size - 1).is_open ()) {+ np = path_list.get (path_list.size - 1); np.add (xt, yt); } else { np = new Path ();- path_list.append (np);+ path_list.add (np); np.add (xt, yt); if (DrawingTools.pen_tool.is_selected ()) {@@ -1062,7 +1022,7 @@ public class Glyph : FontDisplay { double xc = (allocation.width / 2.0); - if (active_paths.length () == 0) {+ if (active_paths.size == 0) { return; } @@ -1096,12 +1056,12 @@ public class Glyph : FontDisplay { public Path? get_last_path () ensures (result != null) {- return_val_if_fail (path_list.length () > 0, null);- return path_list.last ().data;+ return_val_if_fail (path_list.size > 0, null);+ return path_list.get (path_list.size - 1); } public bool has_active_path () {- return active_paths.length () > 0;+ return active_paths.size > 0; } public bool is_open () {@@ -1379,7 +1339,7 @@ public class Glyph : FontDisplay { if (is_open () && Path.fill_open_path) { cr.save (); cr.new_path ();- foreach (unowned Path p in path_list) {+ foreach (Path p in path_list) { if (p.stroke > 0) { draw_path_list (StrokeTool.get_stroke (p, p.stroke), cr, get_path_fill_color ()); }@@ -1393,7 +1353,7 @@ public class Glyph : FontDisplay { if (is_open ()) { cr.save (); cr.new_path ();- foreach (unowned Path p in path_list) {+ foreach (Path p in path_list) { if (p.stroke > 0) { draw_outline_for_paths (StrokeTool.get_stroke (p, p.stroke), cr); }@@ -1410,7 +1370,7 @@ public class Glyph : FontDisplay { cr.save (); cr.new_path ();- foreach (unowned Path p in path_list) {+ foreach (Path p in path_list) { if (p.stroke == 0) { p.draw_path (cr, Color.black ()); } else {@@ -1421,7 +1381,7 @@ public class Glyph : FontDisplay { cr.fill (); cr.restore (); - foreach (unowned Path p in active_paths) {+ foreach (Path p in active_paths) { cr.save (); cr.new_path (); if (p.stroke == 0) {@@ -1500,7 +1460,7 @@ public class Glyph : FontDisplay { } if (unlikely (Preferences.draw_boundaries)) {- foreach (unowned Path p in path_list) {+ foreach (Path p in path_list) { p.draw_boundaries (cr); } }@@ -1596,7 +1556,7 @@ public class Glyph : FontDisplay { } foreach (Path p in active_paths) {- g.active_paths.append (p);+ g.active_paths.add (p); } if (background_image != null) {@@ -1638,9 +1598,7 @@ public class Glyph : FontDisplay { } void set_glyph_data (Glyph g) {- while (path_list.length () > 0) {- path_list.remove_link (path_list.last ());- }+ path_list.clear (); foreach (Path p in g.path_list) { add_path (p);@@ -1739,7 +1697,7 @@ public class Glyph : FontDisplay { public void merge_all () { store_undo_state (); - if (active_paths.length () < 2) {+ if (active_paths.size < 2) { return; } @@ -1768,17 +1726,17 @@ public class Glyph : FontDisplay { path_list = Path.merge (p1, p0); - if (path_list.paths.length () == 0) {+ if (path_list.paths.size == 0) { p0 = p1; continue; } - mp = path_list.paths.first ().data;+ mp = path_list.get_first_path (); delete_path (p0); delete_path (p1); - // add new path + it's counter paths+ // add new path + its counter paths foreach (Path p in path_list.paths) { p.close (); add_path (p.copy ());@@ -1786,8 +1744,8 @@ public class Glyph : FontDisplay { add_active_path (mp); - active_paths.remove_all (p0);- active_paths.remove_all (p1);+ active_paths.remove (p0);+ active_paths.remove (p1); p0 = mp; @@ -81,9 +81,7 @@ class MoveTool : Tool { g.update_view (); } - while (g.active_paths.length () > 0) {- g.active_paths.remove_link (g.active_paths.first ());- }+ g.active_paths.clear (); } if (is_arrow_key (keyval)) {@@ -154,7 +152,7 @@ class MoveTool : Tool { last_x = x; last_y = y; - if (glyph.active_paths.length () == 0) {+ if (glyph.active_paths.size == 0) { group_selection = true; selection_x = x; selection_y = y; @@ -206,7 +206,7 @@ public class GlyfTable : Table { g.remove_empty_paths (); glyf_data = new GlyfData (g); - if (g.path_list.length () == 0 || glyf_data.paths.length () == 0 || glyf_data.get_ncontours () == 0) {+ if (g.path_list.size == 0 || glyf_data.paths.length () == 0 || glyf_data.get_ncontours () == 0) { // location_offsets will be equal to location_offset + 1 for // all empty glyphs g.set_empty_ttf (true);@@ -768,9 +768,9 @@ public class GlyfTable : Table { if (ixmax <= ixmin) { warning (@"Bounding box is bad. (xmax == xmin) ($xmax == $xmin)"); - if (glyph.path_list.length () > 0) {+ if (glyph.path_list.size > 0) { - Path ps = ((!) glyph.path_list.first ()).data;+ Path ps = glyph.path_list.get (0); ps.update_region_boundaries (); xmin = ps.xmin;@@ -1956,7 +1956,7 @@ public class Path { ep.set_reflective_handles (false); ep.get_left_handle ().type = PenTool.to_line (ep.type); ep.type = PenTool.to_curve (ep.type);- path_list.paths.append (current_path);+ path_list.add (current_path); if (!is_null (current_path.points.last ())) { ep = current_path.points.last ().data;@@ -1972,7 +1972,7 @@ public class Path { ep.get_left_handle ().type = PenTool.to_line (ep.type); ep.type = PenTool.to_curve (ep.type); set_new_start (current_path.points.first ().data);- path_list.paths.append (current_path);+ path_list.add (current_path); if (!is_null (current_path.points.last ())) { ep = current_path.points.last ().data;@@ -1986,7 +1986,7 @@ public class Path { remaining_points.points.first ().data.set_reflective_handles (false); remaining_points.points.first ().data.type = remaining_points.points.first ().data.type; set_new_start (remaining_points.points.first ().data);- path_list.paths.append (remaining_points);+ path_list.add (remaining_points); if (!is_null (current_path.points.last ())) { ep = current_path.points.last ().data;@@ -2068,8 +2068,7 @@ public class Path { IntersectionList il; int i; Path np;- - unowned List<Path> pi;+ Path pi; il = IntersectionList.create_intersection_list (p0, p1); @@ -2119,7 +2118,7 @@ public class Path { foreach (Intersection inter in il.points) { p0.set_new_start (inter.editpoint_a); get_merge_part (il, p0, p1, out np);- path_list.paths.append (np);+ path_list.add (np); } foreach (Path pp in path_list.paths) {@@ -2127,21 +2126,21 @@ public class Path { } // remove duplicate paths- for (i = 0; i < path_list.paths.length (); i++) {- pi = path_list.paths.nth (i);+ for (i = 0; i < path_list.paths.size; i++) {+ pi = path_list.paths.get (i); - if (is_duplicated (path_list, pi.data)) {- path_list.paths.remove_link (pi);+ if (is_duplicated (path_list, pi)) {+ path_list.paths.remove (pi); --i; } } // remove paths contained in other paths- for (i = 0; i < path_list.paths.length (); i++) {- pi = path_list.paths.nth (i);+ for (i = 0; i < path_list.paths.size; i++) {+ pi = path_list.paths.get (i); - if (pi.data.is_clockwise () && is_clasped (path_list, pi.data)) {- path_list.paths.remove_link (pi);+ if (pi.is_clockwise () && is_clasped (path_list, pi)) {+ path_list.paths.remove (pi); i--; } }@@ -15,35 +15,33 @@ namespace BirdFont { public class PathList : GLib.Object {- public List<Path> paths;+ public Gee.ArrayList<Path> paths; public PathList () {- paths = new List<Path> ();+ paths = new Gee.ArrayList<Path> (); } public void add (Path p) {- paths.append (p);+ paths.add (p); } public void append (PathList pl) { foreach (Path p in pl.paths) {- paths.append (p);+ paths.add (p); } } public void clear () {- while (paths.length () > 0) {- paths.remove_link (paths.first ());- }+ paths.clear (); } public Path get_first_path () {- if (unlikely (paths.length () == 0)) {+ if (unlikely (paths.size == 0)) { warning ("No path"); return new Path (); } - return paths.first ().data;+ return paths.get (0); } } @@ -546,7 +546,7 @@ public class PenTool : Tool { PathList pl = new PathList (); foreach (Path p in g.path_list) {- pl.paths.append (p);+ pl.add (p); } return Path.is_clasped (pl, path);@@ -681,7 +681,7 @@ public class PenTool : Tool { EditPoint last_point, first_point; EditPointHandle last_rh, fist_rh; - if (glyph.path_list.length () < 1) {+ if (glyph.path_list.size < 1) { return; } @@ -1089,8 +1089,10 @@ public class PenTool : Tool { new_point.point.set_selected (true); selected_point = new_point.point;- active_edit_point = new_point.point; - add_selected_point (selected_point, glyph.active_paths.last ().data);+ active_edit_point = new_point.point;+ + return_if_fail (glyph.active_paths.size > 0); + add_selected_point (selected_point, glyph.active_paths.get (glyph.active_paths.size - 1)); move_selected = true; }@@ -118,7 +118,7 @@ class ResizeTool : Tool { cr.paint (); } - if (g.active_paths.length () > 0) {+ if (g.active_paths.size > 0) { draw_rotate_handle (cr); } @@ -176,7 +176,7 @@ public class SvgParser { if (attr_name == "points") { p = parse_polygon_data (attr_content, glyph);- pl.paths.append (p);+ pl.add (p); } } }@@ -579,11 +579,11 @@ class TestCases { g.close_path (); - warn_if_fail (g.active_paths.length () == 0);+ warn_if_fail (g.active_paths.size == 0); g.select_path (50, 50); - warn_if_fail (g.active_paths.length () == 1);+ warn_if_fail (g.active_paths.size == 1); p.add (-10, 10); p.add (10, 10);@@ -656,9 +656,9 @@ class TestCases { g = MainWindow.get_current_glyph (); foreach (Path p in n.path_list) { pn = p.copy ().get_quadratic_points ();- g.path_list.append (pn);+ g.path_list.add (pn); pn.move (50, 0);- g.path_list.append (p.copy ());+ g.path_list.add (p.copy ()); } } @@ -184,12 +184,12 @@ public class TrackTool : Tool { glyph = MainWindow.get_current_glyph (); - if (glyph.path_list.length () == 0) {+ if (glyph.path_list.size == 0) { warning ("No path."); return; } - p = glyph.path_list.last ().data;+ p = glyph.path_list.get (glyph.path_list.size - 1); draw_freehand = false; convert_points_to_line ();@@ -220,7 +220,7 @@ public class TrackTool : Tool { p.create_list (); - if (glyph.path_list.length () < 2) {+ if (glyph.path_list.size < 2) { warning ("Less than two points"); return; }@@ -328,12 +328,12 @@ public class TrackTool : Tool { glyph = MainWindow.get_current_glyph (); - if (glyph.path_list.length () == 0) {+ if (glyph.path_list.size == 0) { warning ("No path."); return; } - p = glyph.path_list.last ().data;+ p = glyph.path_list.get (glyph.path_list.size - 1); p.reopen (); px = Glyph.path_coordinate_x (x); py = Glyph.path_coordinate_y (y);@@ -414,12 +414,12 @@ public class TrackTool : Tool { Path get_active_path () { Glyph glyph = MainWindow.get_current_glyph (); - if (glyph.path_list.length () == 0) {+ if (glyph.path_list.size == 0) { warning ("No path."); return new Path (); } - return glyph.path_list.last ().data; + return glyph.path_list.get (glyph.path_list.size - 1); } /** Delete all points close to the pixel at x,y. */@@ -466,12 +466,12 @@ public class TrackTool : Tool { glyph = MainWindow.get_current_glyph (); - if (glyph.path_list.length () == 0) {+ if (glyph.path_list.size == 0) { warning ("No path."); return new EditPoint (); } - p = glyph.path_list.last ().data;+ p = glyph.path_list.get (glyph.path_list.size - 1); if (unlikely (p.points.length () < added_points)) { warning ("Missing point.");