The Birdfont Source Code


All Repositories / birdfont.git / blob – RSS feed

GlyphTable.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
Circle boundaries heads/master
1 /* 2 Copyright (C) 2012 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 Gee; 16 17 namespace BirdFont { 18 19 /** A sorted table of glyphs with search index. */ 20 public class GlyphTable : GLib.Object { 21 22 TreeMap<string, GlyphCollection> map; 23 24 public GlyphTable () { 25 map = new TreeMap<string, GlyphCollection> (); 26 } 27 28 public void remove_all () { 29 map.clear (); 30 } 31 32 public void @for_each (Func<GlyphCollection> func) { 33 if (unlikely (is_null (map))) { 34 warning ("No data in table"); 35 return; 36 } 37 38 foreach (var entry in map.entries) { 39 func (entry.value); 40 } 41 } 42 43 public bool has_key (string n) { 44 return map.has_key (n); 45 } 46 47 public void remove (string name) { 48 map.unset (name); 49 } 50 51 public uint length () { 52 return map.size; 53 } 54 55 public new GlyphCollection? @get (string name) { 56 return map.get (name); 57 } 58 59 public new GlyphCollection? nth (uint index) { 60 uint i = 0; 61 62 foreach (var k in map.keys) { 63 if (i == index) { 64 return map.get (k); 65 } 66 i++; 67 } 68 69 return null; 70 } 71 72 public bool insert (string key, GlyphCollection g) { 73 map.set (key, g); 74 return true; 75 } 76 } 77 78 } 79