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
Circle boundaries heads/master
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 string t; 36 Gee.ArrayList<string> c = new Gee.ArrayList<string> (); 37 38 connections.clear (); 39 40 add_connections (glyph); 41 42 for (int i = 0; i < connections.size; i++) { 43 return_val_if_fail (0 <= i < connections.size, c); 44 t = connections.get (i); 45 c.add (t.dup ()); 46 } 47 48 connections.clear (); 49 50 return c; 51 } 52 53 bool has_connection (string s) { 54 foreach (string t in connections) { 55 if (t == s) { 56 return true; 57 } 58 } 59 60 return false; 61 } 62 63 public void add_connections (string glyph) { 64 connections.add (glyph); 65 66 foreach (SpacingClass s in classes) { 67 if (s.first == glyph) { 68 if (!has_connection (s.next)) { 69 add_connections (s.next); 70 } 71 } 72 73 if (s.next == glyph) { 74 if (!has_connection (s.first)) { 75 add_connections (s.first); 76 } 77 } 78 } 79 80 connections.sort ((a, b) => { 81 return strcmp ((string) a, (string) b); 82 }); 83 } 84 85 public void add_class (string first, string next) { 86 SpacingClass spacing_class = new SpacingClass (first, next); 87 spacing_class.updated.connect (update_all_rows); 88 spacing_class.updated.connect (update_kerning); 89 classes.add (spacing_class); 90 update_kerning (spacing_class); 91 } 92 93 void update_all_rows (SpacingClass s) { 94 MainWindow.get_spacing_class_tab ().update_rows (); 95 } 96 97 public void update_kerning (SpacingClass s) { 98 Font font = kerning_classes.font; 99 GlyphCollection? g; 100 GlyphCollection gc; 101 102 if (s.next == "?" || s.first == "?") { 103 return; 104 } 105 106 if (s.next == "" || s.first == "") { 107 return; 108 } 109 110 kerning_classes.copy_single_kerning_pairs (s.first, s.next); 111 112 g = font.get_glyph_collection (s.next); 113 if (g != null) { 114 gc = (!) g; 115 gc.get_current ().update_spacing_class (); 116 } 117 118 g = font.get_glyph_collection (s.first); 119 if (g != null) { 120 gc = (!) g; 121 gc.get_current ().update_spacing_class (); 122 } 123 124 KerningTools.update_spacing_classes (); 125 } 126 } 127 128 } 129