The Birdfont Source Code


All Repositories / birdfont.git / blob – RSS feed

CligFeature.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/CligFeature.vala.
Fix zero length handles in Beziér tool
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 using Math; 15 16 namespace BirdFont { 17 18 public class CligFeature : GLib.Object { 19 public LigatureCollection clig; 20 public ContextualLigatureCollection contextual; 21 Lookups lookups; 22 GlyfTable glyf_table; 23 24 public CligFeature (GlyfTable glyf_table) throws GLib.Error { 25 this.glyf_table = glyf_table; 26 generate_feature (); 27 } 28 29 public bool has_regular_ligatures () { 30 return clig.ligature_sets.size > 0; 31 } 32 33 public Lookups get_lookups () { 34 return lookups; 35 } 36 37 private void generate_feature () throws GLib.Error { 38 Gee.ArrayList<FontData> chain_data; 39 FontData clig_subtable; 40 FontData fd; 41 Lookup lookup; 42 43 fd = new FontData (); 44 clig = new LigatureCollection.clig (glyf_table); 45 contextual = new ContextualLigatureCollection (glyf_table); 46 47 clig_subtable = clig.get_font_data (glyf_table); 48 clig_subtable.pad (); 49 50 chain_data = get_chaining_contextual_substition_subtable (contextual); 51 52 // lookup table 53 lookups = new Lookups (); 54 55 if (contextual.has_ligatures ()) { 56 foreach (LigatureCollection s in contextual.ligatures) { 57 lookup = new Lookup (4, 0, "chained data"); 58 lookup.add_subtable (s.get_font_data (glyf_table)); 59 lookups.add_lookup(lookup); 60 } 61 62 lookup = new Lookup (6, 0, "chain context"); 63 foreach (FontData d in chain_data) { 64 lookup.add_subtable (d); 65 } 66 lookups.add_lookup(lookup); 67 } 68 69 lookup = new Lookup (4, 0, "ligatures"); 70 lookup.add_subtable (clig_subtable); 71 lookups.add_lookup(lookup); 72 } 73 74 // chaining contextual substitution format3 75 Gee.ArrayList<FontData> get_chaining_contextual_substition_subtable (ContextualLigatureCollection contexts) throws GLib.Error { 76 Gee.ArrayList<FontData> fd = new Gee.ArrayList<FontData> (); 77 uint16 ligature_lookup_index = 0; 78 79 foreach (ContextualLigature context in contexts.ligature_context) { 80 fd.add (context.get_font_data (glyf_table, ligature_lookup_index)); 81 ligature_lookup_index++; 82 } 83 84 return fd; 85 } 86 } 87 88 } 89 90