Commit 7e612ef
Fix memory leak
Changed files (7)
modifiedlibbirdfont/DefaultCharactersSet.valamodifiedlibbirdfont/Glyph.valamodifiedlibbirdfont/GlyphSequence.valamodifiedlibbirdfont/KerningDisplay.valamodifiedlibbirdfont/LanguageSelectionTab.valamodifiedlibbirdfont/Path.valamodifiedlibbirdfont/TabBar.vala
Diff
@@ -42,9 +42,9 @@ public class DefaultCharacterSet { * See the functions for chinese and japanese. */ public static void add_language (string language, string language_code, string characters) {- DefaultLanguages.names.append (language);- DefaultLanguages.codes.append (language_code);- DefaultLanguages.characters.append (characters);+ DefaultLanguages.names.add (language);+ DefaultLanguages.codes.add (language_code);+ DefaultLanguages.characters.add (characters); } /** Add all glyphs for the current locale settings to this glyph range. */@@ -84,9 +84,9 @@ public class DefaultCharacterSet { int i = 0; string characters = ""; - foreach (unowned string code in DefaultLanguages.codes) {+ foreach (string code in DefaultLanguages.codes) { if (lang.has_prefix (code)) {- characters = DefaultLanguages.characters.nth (i).data;+ characters = DefaultLanguages.characters.get (i); } i++; }@@ -277,27 +277,27 @@ public class DefaultCharacterSet { } public class DefaultLanguages {- public static List<string> names;- public static List<string> codes;- public static List<string> characters;+ public static Gee.ArrayList<string> names;+ public static Gee.ArrayList<string> codes;+ public static Gee.ArrayList<string> characters; public DefaultLanguages () {- names = new List<string> ();- codes = new List<string> ();- characters = new List<string> (); + names = new Gee.ArrayList<string> ();+ codes = new Gee.ArrayList<string> ();+ characters = new Gee.ArrayList<string> (); } public string? get_name (int index) {- if (0 <= index < names.length ()) {- return names.nth (index).data;+ if (0 <= index < names.size) {+ return names.get (index); } return null; } public string? get_code (int index) {- if (0 <= index < codes.length ()) {- return codes.nth (index).data;+ if (0 <= index < codes.size) {+ return codes.get (index); } return null;@@ -126,7 +126,7 @@ public class Glyph : FontDisplay { if (g == null) { warning ("Glyph for $(s.str) does not exsist."); } else {- gs.glyph.append (g);+ gs.glyph.add (g); } } @@ -16,14 +16,14 @@ namespace BirdFont { public class GlyphSequence { /** A list of all glyphs */- public List <Glyph?> glyph;+ public Gee.ArrayList<Glyph?> glyph; /** A list of corresponding glyph ranges if applicable. */ - public List <GlyphRange?> ranges;+ public Gee.ArrayList<GlyphRange?> ranges; public GlyphSequence () {- glyph = new List <Glyph?> ();- ranges = new List <GlyphRange?> ();+ glyph = new Gee.ArrayList<Glyph?> ();+ ranges = new Gee.ArrayList<GlyphRange?> (); } /** Do ligature substitution.@@ -38,11 +38,11 @@ public class GlyphSequence { bool has_range = false; foreach (Glyph? g in glyph) {- ligatures.glyph.append (g);+ ligatures.glyph.add (g); } foreach (GlyphRange? r in ranges) { - ligatures.ranges.append (r);+ ligatures.ranges.add (r); if (r != null) { has_range = true; }@@ -75,9 +75,9 @@ public class GlyphSequence { void replace (GlyphSequence old, Glyph replacement) { int i = 0;- while (i < glyph.length ()) {+ while (i < glyph.size) { if (starts_with (old, i)) {- substitute (i, old.glyph.length (), replacement);+ substitute (i, old.glyph.size, replacement); i = 0; } else { i++;@@ -86,16 +86,16 @@ public class GlyphSequence { } bool starts_with (GlyphSequence old, uint index) {- unowned List<Glyph?>? gl;- + Glyph? gl;+ foreach (Glyph? g in old.glyph) {- gl = glyph.nth (index);- - if (gl == null) {+ if (index >= glyph.size) { return false; } - if (g != ((!) gl).data) {+ gl = glyph.get ((int) index);+ + if (g != gl) { return false; } @@ -106,32 +106,22 @@ public class GlyphSequence { } void substitute (uint index, uint length, Glyph substitute) {- List<Glyph?> new_list = new List<Glyph?> ();+ Gee.ArrayList<Glyph?> new_list = new Gee.ArrayList<Glyph?> (); int i = 0; foreach (Glyph? g in glyph) { if (i == index) {- new_list.append (substitute);+ new_list.add (substitute); } if (!(i >= index && i < index + length)) {- new_list.append (g);+ new_list.add (g); } i++; } - // remove all links in order to prevent the g_list to delete all items- // when the list is deleted.- while (glyph.length () > 0) { - glyph.remove_link (glyph.first ());- }- - glyph = new_list.copy ();- - while (new_list.length () > 0) {- new_list.remove_link (new_list.first ());- }+ glyph = new_list; } }@@ -21,7 +21,7 @@ public class KerningDisplay : FontDisplay { public bool suppress_input = false; - List <GlyphSequence> row;+ Gee.ArrayList <GlyphSequence> row; int active_handle = -1; int selected_handle = -1; bool moving = false;@@ -36,8 +36,8 @@ public class KerningDisplay : FontDisplay { public KerningDisplay () { GlyphSequence w = new GlyphSequence ();- row = new List <GlyphSequence> ();- row.append (w);+ row = new Gee.ArrayList <GlyphSequence> ();+ row.add (w); } public override string get_label () {@@ -141,11 +141,11 @@ public class KerningDisplay : FontDisplay { if (prev == null || wi == 0) { kern = 0; } else {- return_if_fail (wi < word_with_ligatures.ranges.length ());+ return_if_fail (wi < word_with_ligatures.ranges.size); return_if_fail (wi - 1 >= 0); - gr_left = word_with_ligatures.ranges.nth (wi - 1).data;- gr_right = word_with_ligatures.ranges.nth (wi).data;+ gr_left = word_with_ligatures.ranges.get (wi - 1);+ gr_right = word_with_ligatures.ranges.get (wi); kern = get_kerning_for_pair (((!)prev).get_name (), ((!)g).get_name (), gr_left, gr_right); }@@ -249,7 +249,7 @@ public class KerningDisplay : FontDisplay { double kern = get_kerning_for_handle (h); active_handle = h; - if (1 <= active_handle < row.first ().data.glyph.length ()) {+ if (1 <= active_handle < row.get (0).glyph.size) { display_kerning_value (kern); } }@@ -310,19 +310,19 @@ public class KerningDisplay : FontDisplay { b = ((!) g).get_name (); if (handle == wi && row_index == 0) {- if (wi >= word_with_ligatures.ranges.length ()) {- warning (@"$wi > $(word_with_ligatures.ranges.length ()) Number of glyphs: $(word_with_ligatures.glyph.length ())");+ if (wi >= word_with_ligatures.ranges.size) {+ warning (@"$wi > $(word_with_ligatures.ranges.size) Number of glyphs: $(word_with_ligatures.glyph.size)"); return false; } return_val_if_fail (wi - 1 >= 0, false); - if (word_with_ligatures.ranges.length () != word_with_ligatures.glyph.length ()) {- warning (@"ranges and glyphs does not match. $(word_with_ligatures.ranges.length ()) != $(word_with_ligatures.glyph.length ())");+ if (word_with_ligatures.ranges.size != word_with_ligatures.glyph.size) {+ warning (@"ranges and glyphs does not match. $(word_with_ligatures.ranges.size) != $(word_with_ligatures.glyph.size)"); return false; } - gr_left = word_with_ligatures.ranges.nth (wi - 1).data;- gr_right = word_with_ligatures.ranges.nth (wi).data;+ gr_left = word_with_ligatures.ranges.get (wi - 1);+ gr_right = word_with_ligatures.ranges.get (wi); left = a; right = b;@@ -453,17 +453,14 @@ public class KerningDisplay : FontDisplay { g = MainWindow.get_current_glyph (); s.append_unichar (g.get_unichar ()); - r = row;- return_if_fail (r != null);-- if (row.length () == 0) {+ if (row.size == 0) { append_char = true; } if (append_char) { w = new GlyphSequence ();- row.append (w);- w.glyph.prepend (font.get_glyph (s.str));+ row.add (w);+ w.glyph.insert (0, font.get_glyph (s.str)); } } @@ -482,8 +479,8 @@ public class KerningDisplay : FontDisplay { return; } - row.first ().data.glyph.append ((!) glyph);- row.first ().data.ranges.append (range);+ row.get (0).glyph.add ((!) glyph);+ row.get (0).ranges.add (range); GlyphCanvas.redraw (); }@@ -495,8 +492,8 @@ public class KerningDisplay : FontDisplay { selected_handle = 1; } - if (selected_handle >= row.first ().data.glyph.length ()) {- selected_handle = (int) row.first ().data.glyph.length () - 1;+ if (selected_handle >= row.get (0).glyph.size) {+ selected_handle = (int) row.get (0).glyph.size - 1; } GlyphCanvas.redraw ();@@ -547,12 +544,12 @@ public class KerningDisplay : FontDisplay { } if (KeyBindings.modifier == NONE || KeyBindings.modifier == SHIFT) { - if (keyval == Key.BACK_SPACE && row.length () > 0) { - row.first ().data.glyph.remove_link (row.first ().data.glyph.last ());- row.first ().data.ranges.remove_link (row.first ().data.ranges.last ());+ if (keyval == Key.BACK_SPACE && row.size > 0 && row.get (0).glyph.size > 0) {+ row.get (0).glyph.remove_at (row.get (0).glyph.size - 1);+ row.get (0).ranges.remove_at (row.get (0).ranges.size - 1); } - if (row.length () == 0 || c == Key.ENTER) {+ if (row.size == 0 || c == Key.ENTER) { new_line (); } @@ -563,7 +560,7 @@ public class KerningDisplay : FontDisplay { } public void new_line () {- row.prepend (new GlyphSequence ());+ row.insert (0, new GlyphSequence ()); } void add_character (unichar c) {@@ -579,10 +576,10 @@ public class KerningDisplay : FontDisplay { name = f.get_name_for_character (c); g = f.get_glyph_by_name (name); if (g != null) {- row.first ().data.glyph.append (g);- row.first ().data.ranges.append (null);+ row.get (0).glyph.add (g);+ row.get (0).ranges.add (null); - selected_handle = (int) row.first ().data.glyph.length () - 1;+ selected_handle = (int) row.get (0).glyph.size - 1; set_active_handle_index (selected_handle); } }@@ -653,11 +650,11 @@ public class KerningDisplay : FontDisplay { if (prev == null || col_index == 0) { kern = 0; } else {- return_if_fail (col_index < word_with_ligatures.ranges.length ());+ return_if_fail (col_index < word_with_ligatures.ranges.size); return_if_fail (col_index - 1 >= 0); - gr_left = word_with_ligatures.ranges.nth (col_index - 1).data;- gr_right = word_with_ligatures.ranges.nth (col_index).data;+ gr_left = word_with_ligatures.ranges.get (col_index - 1);+ gr_right = word_with_ligatures.ranges.get (col_index); kern = get_kerning_for_pair (((!)prev).get_name (), ((!)g).get_name (), gr_left, gr_right); }@@ -672,7 +669,7 @@ public class KerningDisplay : FontDisplay { GlyphCanvas.redraw (); } - if (col_index == word.glyph.length () || col_index == 0) {+ if (col_index == word.glyph.size || col_index == 0) { set_active_handle_index (-1); } else { set_active_handle_index (active_handle + row_index);@@ -30,9 +30,9 @@ public class LanguageSelectionTab : FontDisplay { string iso_code; TabBar tb = MainWindow.get_tab_bar (); - return_if_fail (0 <= row < DefaultLanguages.codes.length ());+ return_if_fail (0 <= row < DefaultLanguages.codes.size); - iso_code = DefaultLanguages.codes.nth (row).data;+ iso_code = DefaultLanguages.codes.get (row); Preferences.set ("language", iso_code); tb.close_display (this); Toolbox.select_tool_by_name ("custom_character_set");@@ -40,7 +40,7 @@ public class LanguageSelectionTab : FontDisplay { public override void button_release (int button, double ex, double ey) { int r = (int) rint ((ey - 17) / 18.0);- if (button == 1 && 0 <= r < DefaultLanguages.codes.length ()) {+ if (button == 1 && 0 <= r < DefaultLanguages.codes.size) { select_language (r + scroll); } }@@ -101,7 +101,7 @@ public class LanguageSelectionTab : FontDisplay { } public override void scroll_wheel_down (double x, double y) {- uint rows = DefaultLanguages.names.length ();+ uint rows = DefaultLanguages.names.size; scroll += 3; if (scroll + visible_rows > rows) {@@ -133,7 +133,7 @@ public class LanguageSelectionTab : FontDisplay { } public void update_scrollbar () {- uint rows = DefaultLanguages.names.length ();+ uint rows = DefaultLanguages.names.size; if (rows == 0 || visible_rows == 0) { MainWindow.set_scrollbar_size (0);@@ -145,7 +145,7 @@ public class LanguageSelectionTab : FontDisplay { } public override void scroll_to (double percent) {- uint rows = DefaultLanguages.names.length ();+ uint rows = DefaultLanguages.names.size; scroll = (int) (percent * rows); if (scroll > rows - visible_rows) {@@ -613,86 +613,6 @@ public class Path { return open; } - /*- // FIXME:DELETE - private bool direction_x (EditPoint start, EditPoint stop) {- return (start.x < stop.x);- }-- private bool direction_y (EditPoint start, EditPoint stop) {- return (start.y < stop.y);- }- - public void thinner (double ratio) - requires (points.length () > 2)- { - update_region_boundaries ();- - double w = Math.fabs(xmax - xmin);- double h = Math.fabs(ymax - ymin);- double cx = w / 2 + xmin; - double cy = h / 2 + ymin;- - ratio = 1 - ratio;-- unowned List<EditPoint> i = points.first ();- unowned List<EditPoint> prev = points.last ();- - bool dirx = true;- bool ldirx = direction_x (prev.data, i.data);- bool ndirx;-- bool diry = true;- bool ldiry = direction_y (prev.data, i.data);- bool ndiry;- - while (true) {- ndirx = direction_x (prev.data, i.data);- - if (ndirx != ldirx) {- dirx = !dirx;- }- - ldirx = ndirx;-- ndiry = direction_y (prev.data, i.data);- - if (ndiry != ldiry) {- diry = !diry;- }- - ldiry = ndiry;- - EditPoint p = i.data;- - if (dirx) {- if (p.x < cx)- p.x += (cx - p.x) * ratio;- else- p.x -= (p.x - cx) * ratio;- } else {- if (p.x < cx)- p.x += (cx - p.x) * ratio * 2;- else- p.x -= (p.x - cx) * ratio * 2;- }-- // err borde vara -y- if (p.y < cy && diry || p.y > cy && ! diry)- p.y += (cy - p.y) * ratio;- else- p.y -= (p.y - cy) * ratio; - - if (i == points.last ()) {- break;- }- - prev = i;- i = i.next;- }- }- */- /** Resize path relative to bottom left coordinates. */ public void resize (double ratio) { foreach (EditPoint p in points) {@@ -21,7 +21,7 @@ public class TabBar : GLib.Object { int width = 0; int height = 0; - public List<Tab> tabs;+ public Gee.ArrayList<Tab> tabs; static const int NO_TAB = -1; static const int NEXT_TAB = -2;@@ -61,7 +61,7 @@ public class TabBar : GLib.Object { double wheel_rotation = 0; public TabBar () {- tabs = new List<Tab> ();+ tabs = new Gee.ArrayList<Tab> (); tab1_left = Icons.get_icon ("tab1_left.png"); tab1_right = Icons.get_icon ("tab1_right.png");@@ -202,7 +202,7 @@ public class TabBar : GLib.Object { open = selected_open_tab (t); if (!open) {- select_tab ((int) tabs.length () - 1);+ select_tab ((int) tabs.size - 1); } } @@ -214,7 +214,7 @@ public class TabBar : GLib.Object { return; } - if (tabs.length () > 1) {+ if (tabs.size > 1) { foreach (var t in tabs) { ++i; @@ -241,8 +241,7 @@ public class TabBar : GLib.Object { } } - public bool close_tab (int index, bool background_tab = false, bool select_new_tab = true) { - unowned List<Tab?>? lt;+ public bool close_tab (int index, bool background_tab = false, bool select_new_tab = true) { Tab t; EmptyTab empty_tab_canvas; Tab empty_tab;@@ -252,33 +251,27 @@ public class TabBar : GLib.Object { return false; } - if (!(0 <= index < tabs.length ())) {+ if (!(0 <= index < tabs.size)) { return false; } - if (tabs.length () == 1) {+ if (tabs.size == 1) { empty_tab_canvas = new EmptyTab ("", ""); MainWindow.get_glyph_canvas ().set_current_glyph (empty_tab_canvas); empty_tab = new Tab (empty_tab_canvas, 0, false); signal_tab_selected (empty_tab); } - lt = tabs.nth(index);- - if (lt == null || ((!) lt).data == null) {- return false;- }+ t = tabs.get (index); if (first_tab > 0) { first_tab--; } - t = (!) ((!) lt).data;- if (t.has_close_button ()) { t.get_display ().close (); - tabs.delete_link (tabs.nth(index));+ tabs.remove_at (index); if (!background_tab && select_new_tab) { select_previous_tab ();@@ -348,7 +341,7 @@ public class TabBar : GLib.Object { return null; } - return tabs.nth (i).data;+ return tabs.get (i); } public Tab? get_tab (string name) {@@ -383,8 +376,8 @@ public class TabBar : GLib.Object { public Tab get_selected_tab () { int s = get_selected ();- if (0 <= s < tabs.length ()) {- return tabs.nth (get_selected ()).data;+ if (0 <= s < tabs.size) {+ return tabs.get (get_selected ()); } warning ("No tab selected.");@@ -392,7 +385,7 @@ public class TabBar : GLib.Object { } public uint get_length () {- return tabs.length ();+ return tabs.size; } public int get_selected () {@@ -413,8 +406,8 @@ public class TabBar : GLib.Object { if (index == NEXT_TAB) { selected++; - if (selected >= tabs.length ()) {- selected = (int) tabs.length () - 1;+ if (selected >= tabs.size) {+ selected = (int) tabs.size - 1; } scroll_to_tab (selected);@@ -431,16 +424,13 @@ public class TabBar : GLib.Object { return; } - if (!(0 <= index < tabs.length ())) {+ if (!(0 <= index < tabs.size)) { return; } selected = index; - unowned List<Tab?>? lt = tabs.nth(index);- - return_if_fail(lt != null);- t = (!) ((!) lt).data;+ t = tabs.get (index); previous_tab = current_tab; current_tab = t;@@ -477,13 +467,9 @@ public class TabBar : GLib.Object { } private void signal_selected (int index) {- unowned List<Tab?>? lt; Tab t; - lt = tabs.nth (index);- return_if_fail (lt != null); - t = (!) ((!) lt).data;- + t = tabs.get (index); signal_tab_selected (t); } @@ -558,7 +544,7 @@ public class TabBar : GLib.Object { public void add_tab (FontDisplay display_item, bool signal_selected = true) { double tab_width = -1; bool always_open = false;- int s = (tabs.length () == 0) ? 0 : selected + 1;+ int s = (tabs.size == 0) ? 0 : selected + 1; if (MenuTab.suppress_event) { warn_if_test ("Event suppressed");@@ -570,7 +556,7 @@ public class TabBar : GLib.Object { tab_width += 36; } - tabs.insert (new Tab (display_item, tab_width, always_open), s);+ tabs.insert (s, new Tab (display_item, tab_width, always_open)); select_tab (s, signal_selected); }