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 static const int NONE = 0; 25 public static const int CHAINED_CONTEXT = 1; 26 public static const int LIGATURES = 1; 27 28 public Lookups () { 29 } 30 31 /** Subtables added in the proirity order for the substitution or 32 * spacing transformation. The first table will have highest 33 * priority. 34 */ 35 public void add_lookup (Lookup lookup) { 36 tables.add (lookup); 37 } 38 39 /** Find the lookup index for a particular lookup. */ 40 public uint16 find (int token) { 41 uint16 index = 0; 42 foreach (Lookup lookup in tables) { 43 if (lookup.token == token) { 44 return index; 45 } 46 47 index++; 48 } 49 50 warning (@"No lookup has been created with token $(token)"); 51 return 0; 52 } 53 54 public void append (Lookups lookups) { 55 foreach (Lookup lookup in lookups.tables) { 56 tables.add (lookup); 57 } 58 } 59 60 public FontData genrate_lookup_list () throws GLib.Error { 61 FontData fd = new FontData (); 62 uint lookup_offset; 63 uint tables_size; 64 uint entry_size; 65 uint total_entries_size; 66 FontData entry; 67 68 fd.add_ushort ((uint16) tables.size); // number of lookups 69 lookup_offset = 2 + 2 * tables.size; 70 total_entries_size = 0; 71 72 foreach (Lookup lookup in tables) { 73 fd.add_ushort ((uint16) lookup_offset); 74 entry_size = lookup.get_lookup_entry_size (); 75 return_val_if_fail (lookup.subtables.size != 0, fd); 76 return_val_if_fail (entry_size == 6 + 2 * lookup.subtables.size, fd); 77 lookup_offset += entry_size; 78 total_entries_size += entry_size; 79 } 80 81 tables_size = 0; 82 uint offset = total_entries_size; 83 84 foreach (Lookup lookup in tables) { 85 entry = lookup.get_lookup_entry (offset); 86 offset -= lookup.get_lookup_entry_size (); 87 offset += lookup.get_subtable_size (); 88 fd.append (entry); 89 } 90 91 return fd; 92 } 93 } 94 95 } 96