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 self intersecting stroke
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 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 public void set_unassigned (bool a) { 43 unassigned = a; 44 } 45 46 public bool is_unassigned () { 47 return unassigned; 48 } 49 50 public void add_glyph (Glyph g) { 51 get_version_list ().add_glyph (g); 52 } 53 54 public VersionList get_version_list () { 55 return versions; 56 } 57 58 public Glyph get_current () { 59 return versions.get_current (); 60 } 61 62 public void insert_glyph (Glyph g, bool selected) { 63 versions.add_glyph (g, selected); 64 assert (versions.glyphs.size > 0); 65 } 66 67 public uint length () { 68 return versions.glyphs.size; 69 } 70 71 public string get_unicode () { 72 StringBuilder unicode = new StringBuilder (); 73 unicode.append_unichar (unicode_character); 74 return unicode.str; 75 } 76 77 public void set_unicode_character (unichar c) { 78 unicode_character = c; 79 } 80 81 public unichar get_unicode_character () { 82 return unicode_character; 83 } 84 85 public string get_name () { 86 return name; 87 } 88 89 public void set_name (string n) { 90 name = n; 91 } 92 93 public int get_selected_id () { 94 return versions.get_current ().version_id; 95 } 96 97 public int get_last_id () { 98 return versions.get_last_id (); 99 } 100 101 public void set_selected_version (int version_id) { 102 versions.set_selected_version (version_id); 103 } 104 105 /** Create a copy of this list. This method will copy the list data but 106 * keep pointers to the original glyphs. 107 * @return a new list with copies of pointers to the glyphs 108 */ 109 public GlyphCollection copy () { 110 GlyphCollection n = new GlyphCollection (unicode_character, name); 111 112 foreach (Glyph g in versions.glyphs) { 113 n.insert_glyph (g, false); 114 } 115 116 n.versions.set_selected_version (versions.current_version_id); 117 n.unassigned = unassigned; 118 119 return n; 120 } 121 } 122 123 } 124