The Birdfont Source Code


All Repositories / birdfont.git / blob – RSS feed

Lookups.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/Lookups.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 // Contextual substitutions uses this table for chained substitutions, 19 // the order is not arbitrary. 20 21 public class Lookups : GLib.Object { 22 public Gee.ArrayList<Lookup> tables = new Gee.ArrayList<Lookup> (); 23 24 public Lookups () { 25 } 26 27 /** Subtables added in the proirity order for the substitution or 28 * spacing transformation. The first table will have highest 29 * priority. 30 */ 31 public void add_lookup (Lookup lookup) { 32 tables.add (lookup); 33 } 34 35 public void append (Lookups lookups) { 36 foreach (Lookup lookup in lookups.tables) { 37 tables.add (lookup); 38 } 39 } 40 41 public FontData genrate_lookup_list () throws GLib.Error { 42 FontData fd = new FontData (); 43 uint lookup_offset; 44 uint tables_size; 45 uint entry_size; 46 uint total_entries_size; 47 FontData entry; 48 49 fd.add_ushort ((uint16) tables.size); // number of lookups 50 lookup_offset = 2 + 2 * tables.size; 51 total_entries_size = 0; 52 53 foreach (Lookup lookup in tables) { 54 fd.add_ushort ((uint16) lookup_offset); 55 entry_size = lookup.get_lookup_entry_size (); 56 return_val_if_fail (lookup.subtables.size != 0, fd); 57 return_val_if_fail (entry_size == 6 + 2 * lookup.subtables.size, fd); 58 lookup_offset += entry_size; 59 total_entries_size += entry_size; 60 } 61 62 tables_size = 0; 63 uint offset = total_entries_size; 64 65 foreach (Lookup lookup in tables) { 66 entry = lookup.get_lookup_entry (offset); 67 offset -= lookup.get_lookup_entry_size (); 68 offset += lookup.get_subtable_size (); 69 fd.append (entry); 70 } 71 72 return fd; 73 } 74 } 75 76 } 77