The Birdfont Source Code


All Repositories / birdfont.git / blob – RSS feed

FeatureList.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) 2015 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 FeatureList : GLib.Object { 18 19 public Gee.ArrayList<Feature> features = new Gee.ArrayList<Feature> (); 20 21 public FeatureList () { 22 } 23 24 public void add (Feature f) { 25 features.add (f); 26 } 27 28 public FontData generate_feature_tags () throws GLib.Error { 29 FontData fd = new FontData (); 30 31 features.sort ((fa, fb) => { 32 Feature a = (Feature) fa; 33 Feature b = (Feature) fb; 34 return strcmp (a.tag, b.tag); 35 }); 36 37 fd.add_ushort ((uint16) features.size); // number of features 38 39 uint offset = 2 + 6 * features.size; 40 foreach (Feature feature in features) { 41 // feature tag: aalt, clig etc. 42 fd.add_tag (feature.tag); 43 44 // offset to feature from beginning of this table 45 fd.add_ushort ((uint16) offset); 46 47 offset += 4 + 2 * feature.get_public_lookups (); 48 49 if (feature.get_public_lookups () == 0) { 50 warning (@"No lookups for $(feature.tag)"); 51 } 52 } 53 54 foreach (Feature feature in features) { 55 // feature prameters (null) 56 fd.add_ushort (0); 57 58 // number of lookups 59 fd.add_ushort ((uint16) feature.public_lookups.size); 60 61 foreach (string p in feature.public_lookups) { 62 // reference to a lookup table (lookup index) 63 fd.add_ushort (feature.lookups.find (p)); 64 } 65 } 66 67 return fd; 68 } 69 } 70 71 } 72