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 String s; 36 Gee.ArrayList<string> c = new Gee.ArrayList<string> (); 37 38 connections.clear (); 39 40 add_connections (glyph); 41 42 foreach (String t in connections) { 43 c.add (t.data.dup ()); 44 } 45 46 connections.clear (); 47 48 return c; 49 } 50 51 bool has_connection (string s) { 52 foreach (String t in connections) { 53 if (t.data == s) { 54 return true; 55 } 56 } 57 58 return false; 59 } 60 61 public void add_connections (string glyph) { 62 String sb = new String (glyph); 63 64 connections.add (sb); 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 s = new SpacingClass (first, next); 87 s.updated.connect (update_all_rows); 88 s.updated.connect (update_kerning); 89 classes.add (s); 90 update_kerning (s); 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 != "?") { 103 kerning_classes.update_space_class (s.next); 104 g = font.get_glyph_collection (s.next); 105 if (g != null) { 106 gc = (!) g; 107 gc.get_current ().update_spacing_class (); 108 } 109 } 110 111 if (s.first != "?") { 112 kerning_classes.update_space_class (s.first); 113 g = font.get_glyph_collection (s.first); 114 if (g != null) { 115 gc = (!) g; 116 gc.get_current ().update_spacing_class (); 117 } 118 } 119 120 KerningTools.update_spacing_classes (); 121 } 122 123 class String : GLib.Object { 124 125 public string data; 126 127 public String (string s) { 128 data = s.dup (); 129 } 130 } 131 } 132 133 } 134