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.
Thread safety in text rendering
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 add_connections (glyph); 39 40 foreach (string t in connections) { 41 c.add (t); 42 } 43 44 connections.clear (); 45 46 return c; 47 } 48 49 public void add_connections (string glyph) { 50 connections.add (glyph); 51 52 foreach (SpacingClass s in classes) { 53 if (s.first == glyph) { 54 if (connections.index_of (s.next) == -1) { 55 add_connections (s.next); 56 } 57 } 58 59 if (s.next == glyph) { 60 if (connections.index_of (s.first) == -1) { 61 add_connections (s.first); 62 } 63 } 64 } 65 66 connections.sort ((a, b) => { 67 return strcmp ((string) a, (string) b); 68 }); 69 } 70 71 public void add_class (string first, string next) { 72 SpacingClass s = new SpacingClass (first, next); 73 s.updated.connect (update_all_rows); 74 s.updated.connect (update_kerning); 75 classes.add (s); 76 update_kerning (s); 77 } 78 79 void update_all_rows (SpacingClass s) { 80 MainWindow.get_spacing_class_tab ().update_rows (); 81 } 82 83 public void update_kerning (SpacingClass s) { 84 Font font = BirdFont.get_current_font (); 85 GlyphCollection? g; 86 GlyphCollection gc; 87 88 if (s.next != "?") { 89 kerning_classes.update_space_class (s.next); 90 g = font.get_glyph_collection (s.next); 91 if (g != null) { 92 gc = (!) g; 93 gc.get_current ().update_spacing_class (); 94 } 95 } 96 97 if (s.first != "?") { 98 kerning_classes.update_space_class (s.first); 99 g = font.get_glyph_collection (s.first); 100 if (g != null) { 101 gc = (!) g; 102 gc.get_current ().update_spacing_class (); 103 } 104 } 105 106 KerningTools.update_spacing_classes (); 107 } 108 } 109 110 } 111