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.
Create lookups in arbitrary order
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 Lookups get_lookups () { 30 return lookups; 31 } 32 33 private void generate_feature () throws GLib.Error { 34 Gee.ArrayList<FontData> chain_data; 35 FontData clig_subtable; 36 FontData fd; 37 Lookup lookup; 38 39 fd = new FontData (); 40 clig = new LigatureCollection.clig (glyf_table); 41 contextual = new ContextualLigatureCollection (glyf_table); 42 43 clig_subtable = clig.get_font_data (glyf_table); 44 clig_subtable.pad (); 45 46 chain_data = get_chaining_contextual_substition_subtable (contextual); 47 48 // lookup table 49 lookups = new Lookups (); 50 51 if (contextual.has_ligatures ()) { 52 foreach (LigatureCollection s in contextual.ligatures) { 53 lookup = new Lookup (4, 0); 54 lookup.add_subtable (s.get_font_data (glyf_table)); 55 lookups.add_lookup(lookup); 56 } 57 58 lookup = new Lookup (6, 0); 59 foreach (FontData d in chain_data) { 60 lookup.add_subtable (d); 61 } 62 lookups.add_lookup(lookup); 63 } 64 65 lookup = new Lookup (4, 0); 66 lookup.add_subtable (clig_subtable); 67 lookups.add_lookup(lookup); 68 } 69 70 // chaining contextual substitution format3 71 Gee.ArrayList<FontData> get_chaining_contextual_substition_subtable (ContextualLigatureCollection contexts) throws GLib.Error { 72 Gee.ArrayList<FontData> fd = new Gee.ArrayList<FontData> (); 73 uint16 ligature_lookup_index = 0; 74 75 foreach (ContextualLigature context in contexts.ligature_context) { 76 fd.add (context.get_font_data (glyf_table, ligature_lookup_index)); 77 ligature_lookup_index++; 78 } 79 80 return fd; 81 } 82 } 83 84 } 85 86