The Birdfont Source Code


All Repositories / birdfont.git / blob – RSS feed

SpacingData.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/SpacingData.vala.
Add a button for closing paths
1 /* 2 Copyright (C) 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 using Cairo; 15 using Math; 16 17 namespace BirdFont { 18 19 public class SpacingData : GLib.Object { 20 21 public KerningClasses kerning_classes; 22 23 public Gee.ArrayList<SpacingClass> classes = new Gee.ArrayList<SpacingClass> (); 24 Gee.ArrayList<string> connections = new Gee.ArrayList<string> (); 25 26 public SpacingData (KerningClasses kerning) { 27 kerning_classes = kerning; 28 } 29 30 public KerningClasses get_kerning_classes () { 31 return kerning_classes; 32 } 33 34 public Gee.ArrayList<string> get_all_connections (string glyph) { 35 Gee.ArrayList<string> c = new Gee.ArrayList<string> (); 36 37 connections.clear (); 38 39 add_connections (glyph); 40 41 foreach (string t in connections) { 42 c.add (t.dup ()); 43 } 44 45 connections.clear (); 46 47 return c; 48 } 49 50 bool has_connection (string s) { 51 foreach (string t in connections) { 52 if (t == s) { 53 return true; 54 } 55 } 56 57 return false; 58 } 59 60 public void add_connections (string glyph) { 61 connections.add (glyph); 62 63 foreach (SpacingClass s in classes) { 64 if (s.first == glyph) { 65 if (!has_connection (s.next)) { 66 add_connections (s.next); 67 } 68 } 69 70 if (s.next == glyph) { 71 if (!has_connection (s.first)) { 72 add_connections (s.first); 73 } 74 } 75 } 76 77 connections.sort ((a, b) => { 78 return strcmp ((string) a, (string) b); 79 }); 80 } 81 82 public void add_class (string first, string next) { 83 SpacingClass s = new SpacingClass (first, next); 84 s.updated.connect (update_all_rows); 85 s.updated.connect (update_kerning); 86 classes.add (s); 87 update_kerning (s); 88 } 89 90 void update_all_rows (SpacingClass s) { 91 MainWindow.get_spacing_class_tab ().update_rows (); 92 } 93 94 public void update_kerning (SpacingClass s) { 95 Font font = kerning_classes.font; 96 GlyphCollection? g; 97 GlyphCollection gc; 98 99 if (s.next != "?") { 100 kerning_classes.update_space_class (s.next); 101 g = font.get_glyph_collection (s.next); 102 if (g != null) { 103 gc = (!) g; 104 gc.get_current ().update_spacing_class (); 105 } 106 } 107 108 if (s.first != "?") { 109 kerning_classes.update_space_class (s.first); 110 g = font.get_glyph_collection (s.first); 111 if (g != null) { 112 gc = (!) g; 113 gc.get_current ().update_spacing_class (); 114 } 115 } 116 117 KerningTools.update_spacing_classes (); 118 } 119 } 120 121 } 122