The Birdfont Source Code


All Repositories / birdfont.git / blob – RSS feed

GsubTable.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/GsubTable.vala.
Save stylistic alternatives to bf fonts and make gsub features optional
1 /* 2 Copyright (C) 2012 2013 2014 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 using Math; 15 16 namespace BirdFont { 17 18 public class GsubTable : OtfTable { 19 20 GlyfTable glyf_table; 21 22 public GsubTable (GlyfTable glyf_table) { 23 this.glyf_table = glyf_table; 24 id = "GSUB"; 25 } 26 27 public override void parse (FontData dis) throws GLib.Error { 28 } 29 30 public void process () throws GLib.Error { 31 FontData fd; 32 33 fd = new FontData (); 34 CligFeature clig_feature = new CligFeature (glyf_table); 35 AlternateFeature alternate_feature = new AlternateFeature (glyf_table); 36 37 Lookups lookups = new Lookups (); 38 FeatureList features = new FeatureList (); 39 40 if (alternate_feature.has_alternates ()) { 41 Lookups aalt_lookup = alternate_feature.get_lookups (); 42 Feature aalt_feature_lookup = new Feature ("aalt", lookups); 43 aalt_feature_lookup.add_feature_lookup (Lookups.ALTERNATES); 44 features.add (aalt_feature_lookup); 45 lookups.append (aalt_lookup); 46 } 47 48 bool has_clig = clig_feature.contextual.has_ligatures () 49 || clig_feature.has_regular_ligatures (); 50 51 if (has_clig) { 52 Lookups clig_lookups = clig_feature.get_lookups (); 53 Feature clig_feature_lookup = new Feature ("clig", lookups); 54 55 if (clig_feature.contextual.has_ligatures ()) { 56 clig_feature_lookup.add_feature_lookup (Lookups.CHAINED_CONTEXT); 57 } 58 59 if (clig_feature.has_regular_ligatures ()) { 60 clig_feature_lookup.add_feature_lookup (Lookups.LIGATURES); 61 } 62 63 features.add (clig_feature_lookup); 64 lookups.append (clig_lookups); 65 } 66 67 FontData feature_tags = features.generate_feature_tags (); 68 69 uint lookup_list_offset = 30 + feature_tags.length_with_padding (); 70 71 fd.add_ulong (0x00010000); // table version 72 fd.add_ushort (10); // offset to script list 73 fd.add_ushort (30); // offset to feature list 74 fd.add_ushort ((uint16) lookup_list_offset); // offset to lookup list 75 76 // script list 77 fd.add_ushort (1); // number of items in script list 78 fd.add_tag ("DFLT"); // default script 79 fd.add_ushort (8); // offset to script table from script list 80 81 // script table 82 fd.add_ushort (4); // offset to default language system 83 fd.add_ushort (0); // number of languages 84 85 // LangSys table 86 fd.add_ushort (0); // reserved 87 fd.add_ushort (0); // required features (0xFFFF is none) 88 fd.add_ushort (1); // number of features 89 fd.add_ushort (0); // feature index 90 91 // feature lookups with references to the lookup list 92 fd.append (feature_tags); 93 94 if (lookup_list_offset != fd.length_with_padding ()) { 95 warning (@"Bad offset to lookup list: $(lookup_list_offset) != $(fd.length_with_padding ())"); 96 } 97 98 // lookup list 99 fd.append (lookups.generate_lookup_list ()); 100 101 // subtable data 102 foreach (Lookup lookup in lookups.tables) { 103 foreach (FontData subtable in lookup.subtables) { 104 fd.append (subtable); 105 } 106 } 107 108 fd.pad (); 109 110 this.font_data = fd; 111 } 112 } 113 114 } 115