The Birdfont Source Code


All Repositories / birdfont.git / blob – RSS feed

KerningPair.vala in libbirdfont/OpenFontFormat

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
Add *nix as OS tag 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 15 using Cairo; 16 using B; 17 18 namespace BirdFont { 19 20 /** A list of all kerning pairs for one glyph. */ 21 public class KerningPair : GLib.Object { 22 public Glyph character; 23 public Gee.ArrayList<Kerning> kerning; 24 public Gee.ArrayList<Glyph> right; 25 26 public KerningPair (Glyph left) { 27 character = left; 28 right = new Gee.ArrayList<Glyph> (); 29 kerning = new Gee.ArrayList<Kerning> (); 30 } 31 32 public void add_unique (Glyph g, double k) { 33 if (!right.contains ((!) g)) { 34 right.add ((!) g); 35 kerning.add (new Kerning.for_glyph (g, k)); 36 } 37 } 38 39 public void sort () { 40 kerning.sort ((a, b) => { 41 Kerning first, next; 42 first = (Kerning) a; 43 next = (Kerning) b; 44 return strcmp (((!)first.glyph).get_unichar_string (), ((!)next.glyph).get_unichar_string ()); 45 }); 46 } 47 48 public void print () { 49 if (kerning.size == 0) { 50 warning ("No pairs."); 51 } 52 53 foreach (Kerning k in kerning) { 54 if (k.glyph != null) { 55 stdout.printf (@"$(character.get_name ()) <-> $(((!) k.glyph).get_name ()): $(k.val)\n"); 56 } 57 } 58 } 59 } 60 61 } 62