The Birdfont Source Code


All Repositories / birdfont.git / blob – RSS feed

KernSubtable.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

Revisions

View the latest version of libbirdfont/OpenFontFormat/KernSubtable.vala.
Cache overview items
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 namespace BirdFont { 16 17 public class KernSubtable : GLib.Object { 18 19 public delegate void KernIterator (Kern k); 20 public delegate void PairFormat1Iterator (PairFormat1 k); 21 22 public Gee.ArrayList<PairFormat1> pairs; 23 public uint num_pairs; 24 25 public KernSubtable () { 26 pairs = new Gee.ArrayList<PairFormat1> (); 27 num_pairs = 0; 28 } 29 30 public void add (PairFormat1 kerning_pair) { 31 num_pairs += kerning_pair.pairs.size; 32 pairs.add (kerning_pair); 33 } 34 35 /** @return the number of glyphs that is kerned on the left side in 36 * pair pos format 1. 37 */ 38 public uint get_length_left () { 39 return pairs.size; 40 } 41 42 /** @return the total number of pairs. */ 43 public uint get_length () { 44 return num_pairs; 45 } 46 47 public void all_kern (KernIterator iter, int limit) { 48 int i = 0; 49 foreach (PairFormat1 p in pairs) { 50 foreach (Kern k in p.pairs) { 51 if (unlikely (i >= limit)) { 52 warning (@"Too many pairs. Limit: $limit"); 53 return; 54 } 55 56 iter (k); 57 i++; 58 } 59 } 60 } 61 62 public void all_pairs_format1 (PairFormat1Iterator iter, int limit = -1) { 63 uint i = 0; 64 65 foreach (PairFormat1 p in pairs) { 66 if (unlikely (i >= limit && limit != -1)) { 67 warning (@"Too many pairs. Limit: $limit"); 68 return; 69 } 70 71 iter (p); 72 73 i++; 74 } 75 } 76 77 public uint get_pairs_set_length () { 78 uint len = 0; 79 80 all_pairs_format1 ((p) => { 81 len += 2 + 4 * p.pairs.size; 82 }); 83 84 return len; 85 } 86 87 public uint get_pairs_offset_length () { 88 return 2 * pairs.size; 89 } 90 91 public uint get_bytes_used () { 92 return get_pairs_set_length () + get_pairs_offset_length (); 93 } 94 95 public void remove_last () { 96 return_if_fail (pairs.size > 0); 97 pairs.remove_at (pairs.size - 1); 98 } 99 } 100 101 } 102