The Birdfont Source Code


All Repositories / birdfont.git / blob – RSS feed

GlyphCollection.vala in libbirdfont

This file is a part of the Birdfont project.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git

Revisions

View the latest version of libbirdfont/GlyphCollection.vala.
Fix memory leak
1 /* 2 Copyright (C) 2012, 2014 Johan Mattsson 3 4 This library is free software; you can redistribute it and/or modify 5 it under the terms of the GNU Lesser General Public License as 6 published by the Free Software Foundation; either version 3 of the 7 License, or (at your option) any later version. 8 9 This library is distributed in the hope that it will be useful, but 10 WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 Lesser General Public License for more details. 13 */ 14 15 using Cairo; 16 using Math; 17 18 namespace BirdFont { 19 20 public class GlyphCollection : GLib.Object { 21 public VersionList versions; 22 unichar unicode_character; 23 string name; 24 bool unassigned = false; 25 26 public GlyphCollection (unichar unicode_character, string name) { 27 this.unicode_character = unicode_character; 28 this.name = name; 29 versions = new VersionList (null, this); 30 } 31 32 public GlyphCollection.with_glyph (unichar unicode_character, string name) { 33 Glyph g; 34 35 this.unicode_character = unicode_character; 36 this.name = name; 37 38 g = new Glyph (name, unicode_character); 39 versions = new VersionList (g, this); 40 } 41 42 ~GlyphCollection () { 43 versions.glyphs.clear (); 44 } 45 46 public void set_unassigned (bool a) { 47 unassigned = a; 48 } 49 50 public bool is_unassigned () { 51 return unassigned; 52 } 53 54 public void add_glyph (Glyph g) { 55 get_version_list ().add_glyph (g); 56 } 57 58 public VersionList get_version_list () { 59 return versions; 60 } 61 62 public Glyph get_current () { 63 return versions.get_current (); 64 } 65 66 public void insert_glyph (Glyph g, bool selected) { 67 versions.add_glyph (g, selected); 68 assert (versions.glyphs.size > 0); 69 } 70 71 public uint length () { 72 return versions.glyphs.size; 73 } 74 75 public string get_unicode () { 76 StringBuilder unicode = new StringBuilder (); 77 unicode.append_unichar (unicode_character); 78 return unicode.str; 79 } 80 81 public void set_unicode_character (unichar c) { 82 unicode_character = c; 83 } 84 85 public unichar get_unicode_character () { 86 return unicode_character; 87 } 88 89 public string get_name () { 90 return name; 91 } 92 93 public void set_name (string n) { 94 name = n; 95 } 96 97 public int get_selected_id () { 98 return versions.get_current ().version_id; 99 } 100 101 public int get_last_id () { 102 return versions.get_last_id (); 103 } 104 105 public void set_selected_version (int version_id) { 106 versions.set_selected_version (version_id); 107 } 108 109 /** Create a copy of this list. This method will copy the list data but 110 * keep pointers to the original glyphs. 111 * @return a new list with copies of pointers to the glyphs 112 */ 113 public GlyphCollection copy () { 114 GlyphCollection n = new GlyphCollection (unicode_character, name); 115 116 foreach (Glyph g in versions.glyphs) { 117 n.insert_glyph (g, false); 118 } 119 120 n.versions.set_selected_version (versions.current_version_id); 121 n.unassigned = unassigned; 122 123 return n; 124 } 125 } 126 127 } 128