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 text rendering
1 /* 2 Copyright (C) 2012, 2014 2015 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 unichar unicode_character; 22 string name; 23 bool unassigned = false; 24 public Gee.ArrayList<Glyph> glyphs = new Gee.ArrayList<Glyph> (); 25 int selected; 26 27 public GlyphCollection (unichar unicode_character, string name) { 28 this.unicode_character = unicode_character; 29 this.name = name; 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 glyphs.add (g); 40 } 41 42 public void remove (int index) { 43 return_if_fail (0 <= index < glyphs.size); 44 45 if (selected >= index) { 46 selected--; 47 } 48 49 glyphs.remove_at (index); 50 } 51 52 public void set_selected (Glyph g) { 53 int i = 0; 54 55 foreach (Glyph gl in glyphs) { 56 if (gl == g) { 57 selected = i; 58 return; 59 } 60 i++; 61 } 62 63 selected = 0; 64 warning ("Glyph is not a part of the collection."); 65 } 66 67 public void set_unassigned (bool a) { 68 unassigned = a; 69 } 70 71 public bool is_unassigned () { 72 return unassigned; 73 } 74 75 public void add_glyph (Glyph g) { 76 glyphs.add (g); 77 } 78 79 public Glyph get_current () { 80 if (0 <= selected < glyphs.size) { 81 return glyphs.get (selected); 82 } 83 84 return new Glyph ("", '\0'); 85 } 86 87 public void insert_glyph (Glyph g, bool selected_glyph) { 88 glyphs.add (g); 89 90 if (selected_glyph) { 91 selected = glyphs.size - 1; 92 } 93 } 94 95 public uint length () { 96 return glyphs.size; 97 } 98 99 public string get_unicode () { 100 StringBuilder unicode = new StringBuilder (); 101 unicode.append_unichar (unicode_character); 102 return unicode.str; 103 } 104 105 public void set_unicode_character (unichar c) { 106 unicode_character = c; 107 } 108 109 public unichar get_unicode_character () { 110 return unicode_character; 111 } 112 113 public string get_name () { 114 return name; 115 } 116 117 public void set_name (string n) { 118 name = n; 119 } 120 121 public void set_selected_version (int version_id) { 122 int i = 0; 123 foreach (Glyph g in glyphs) { 124 if (g.version_id == version_id) { 125 selected = i; 126 break; 127 } 128 i++; 129 } 130 } 131 132 /** Create a copy of this list. This method will copy the list data but 133 * keep pointers to the original glyphs. 134 * @return a new list with copies of pointers to the glyphs 135 */ 136 public GlyphCollection copy () { 137 GlyphCollection n = new GlyphCollection (unicode_character, name); 138 139 foreach (Glyph g in glyphs) { 140 n.insert_glyph (g, false); 141 } 142 143 n.selected = selected; 144 n.unassigned = unassigned; 145 146 return n; 147 } 148 149 public int get_last_id () { 150 return_val_if_fail (glyphs.size > 0, 0); 151 return glyphs.get (glyphs.size - 1).version_id; 152 } 153 } 154 155 } 156