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.
Fix zero length handles in Beziér tool
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 36 Lookups lookups = new Lookups (); 37 FeatureList features = new FeatureList (); 38 39 bool has_clig = clig_feature.contextual.has_ligatures () 40 || clig_feature.has_regular_ligatures (); 41 42 if (has_clig) { 43 Lookups clig_lookups = clig_feature.get_lookups (); 44 Feature clig_feature_lookup = new Feature ("clig", lookups); 45 46 if (clig_feature.contextual.has_ligatures ()) { 47 clig_feature_lookup.add_feature_lookup ("chain context"); 48 } 49 50 if (clig_feature.has_regular_ligatures ()) { 51 clig_feature_lookup.add_feature_lookup ("ligatures"); 52 } 53 54 features.add (clig_feature_lookup); 55 lookups.append (clig_lookups); 56 } 57 58 add_alternate_table (features, lookups, "swsh"); 59 add_alternate_table (features, lookups, "salt"); 60 add_alternate_table (features, lookups, "c2sc"); 61 add_alternate_table (features, lookups, "smcp"); 62 63 FontData feature_tags = features.generate_feature_tags (); 64 65 uint feature_list_offset = 28 + 2 * features.features.size; 66 uint lookup_list_offset = feature_list_offset + feature_tags.length_with_padding (); 67 68 fd.add_ulong (0x00010000); // table version 69 fd.add_ushort (10); // offset to script list 70 fd.add_ushort ((uint16) feature_list_offset); // offset to feature list 71 fd.add_ushort ((uint16) lookup_list_offset); // offset to lookup list 72 73 // script list 74 fd.add_ushort (1); // number of items in script list 75 fd.add_tag ("DFLT"); // default script 76 fd.add_ushort (8); // offset to script table from script list 77 78 // script table 79 fd.add_ushort (4); // offset to default language system 80 fd.add_ushort (0); // number of languages 81 82 // LangSys table 83 fd.add_ushort (0); // reserved 84 fd.add_ushort (0xFFFF); // required features (0xFFFF is none) 85 fd.add_ushort ((uint16) features.features.size); // number of features 86 87 // FIXME: double check this 88 for (int i = 0; i < features.features.size; i++) { 89 fd.add_ushort ((uint16) i); // feature index 90 } 91 92 // feature lookups with references to the lookup list 93 fd.append (feature_tags); 94 95 if (lookup_list_offset != fd.length_with_padding ()) { 96 warning (@"Bad offset to lookup list: $(lookup_list_offset) != $(fd.length_with_padding ())"); 97 } 98 99 // lookup list and the table data 100 FontData lookup_list = lookups.generate_lookup_list (); 101 fd.append (lookup_list); 102 103 fd.pad (); 104 105 this.font_data = fd; 106 } 107 108 /** Add alterate substitutions to lookups and features. */ 109 public void add_alternate_table (FeatureList features, Lookups lookups, string tag) 110 throws GLib.Error { 111 AlternateFeature alt = new AlternateFeature (glyf_table, tag); 112 if (alt.has_alternates ()) { 113 Lookups alt_lookup = alt.get_lookups (); 114 Feature alt_feature_lookup = new Feature (tag, lookups); 115 alt_feature_lookup.add_feature_lookup (tag); 116 features.add (alt_feature_lookup); 117 lookups.append (alt_lookup); 118 } 119 } 120 121 } 122 123 } 124