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.
Remove debug info
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 print (@"GlyphCollection: $(ref_count)\n"); 30 versions = new VersionList (null, this); 31 print (@"Afer version list GlyphCollection: $(ref_count)\n"); 32 } 33 34 public GlyphCollection.with_glyph (unichar unicode_character, string name) { 35 Glyph g; 36 37 this.unicode_character = unicode_character; 38 this.name = name; 39 40 g = new Glyph (name, unicode_character); 41 42 print (@"GlyphCollection: $(ref_count)\n"); 43 versions = new VersionList (g, this); 44 print (@"Afer version list GlyphCollection: $(ref_count)\n"); 45 } 46 47 ~GlyphCollection () { 48 versions.glyphs.clear (); 49 } 50 51 public void set_unassigned (bool a) { 52 unassigned = a; 53 } 54 55 public bool is_unassigned () { 56 return unassigned; 57 } 58 59 public void add_glyph (Glyph g) { 60 get_version_list ().add_glyph (g); 61 } 62 63 public VersionList get_version_list () { 64 return versions; 65 } 66 67 public Glyph get_current () { 68 return versions.get_current (); 69 } 70 71 public void insert_glyph (Glyph g, bool selected) { 72 print (@"Before VersionList $(g.ref_count)\n"); 73 versions.add_glyph (g, selected); 74 print (@"After VersionList $(g.ref_count)\n"); 75 assert (versions.glyphs.size > 0); 76 } 77 78 public uint length () { 79 return versions.glyphs.size; 80 } 81 82 public string get_unicode () { 83 StringBuilder unicode = new StringBuilder (); 84 unicode.append_unichar (unicode_character); 85 return unicode.str; 86 } 87 88 public void set_unicode_character (unichar c) { 89 unicode_character = c; 90 } 91 92 public unichar get_unicode_character () { 93 return unicode_character; 94 } 95 96 public string get_name () { 97 return name; 98 } 99 100 public void set_name (string n) { 101 name = n; 102 } 103 104 public int get_selected_id () { 105 return versions.get_current ().version_id; 106 } 107 108 public int get_last_id () { 109 return versions.get_last_id (); 110 } 111 112 public void set_selected_version (int version_id) { 113 versions.set_selected_version (version_id); 114 } 115 116 /** Create a copy of this list. This method will copy the list data but 117 * keep pointers to the original glyphs. 118 * @return a new list with copies of pointers to the glyphs 119 */ 120 public GlyphCollection copy () { 121 GlyphCollection n = new GlyphCollection (unicode_character, name); 122 123 foreach (Glyph g in versions.glyphs) { 124 n.insert_glyph (g, false); 125 } 126 127 n.versions.set_selected_version (versions.current_version_id); 128 n.unassigned = unassigned; 129 130 return n; 131 } 132 } 133 134 } 135