The Birdfont Source Code


All Repositories / birdfont.git / blob – RSS feed

Lookup.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
Add *nix as OS tag heads/master
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 15 namespace BirdFont { 16 17 /** Representation of one lookup in gsub and gpos tables. */ 18 public class Lookup : GLib.Object { 19 public uint16 type; 20 public uint16 flags; 21 public Gee.ArrayList<FontData> subtables; 22 public string token; 23 24 public uint subtable_offset = 0; 25 public uint entry_offset = 0; 26 27 // the token is used for obtaining index in lookup list, an empty 28 // string ensures that the subtable can't be directly used by 29 // a table, chaining context use that feature. 30 // 31 // Lookups.find is used to obtain index in the lookup list for 32 // a token. 33 public Lookup (uint16 type, uint16 flags, string token = "") { 34 this.type = type; 35 this.flags = flags; 36 subtables = new Gee.ArrayList<FontData> (); 37 this.token = token; 38 subtable_offset = 0; 39 } 40 41 public void add_subtable (FontData subtable) { 42 subtables.add (subtable); 43 } 44 45 public uint get_lookup_entry_size () throws GLib.Error { 46 return get_lookup_entry (0).length_with_padding (); 47 } 48 49 public uint get_subtable_size () throws GLib.Error { 50 uint size = 0; 51 uint s; 52 53 foreach (FontData subtable in subtables) { 54 s = subtable.length_with_padding (); 55 56 if (s == 0) { 57 warning ("Zero size in subtable."); 58 } 59 60 size += s; 61 } 62 63 warn_if_fail (size != 0); 64 65 return size; 66 } 67 68 public FontData get_lookup_entry (uint offset) 69 throws GLib.Error { 70 FontData fd = new FontData (); 71 72 return_val_if_fail (subtables.size > 0, fd); 73 74 fd.add_ushort (type); // lookup type 75 fd.add_ushort (flags); // lookup flags 76 fd.add_ushort ((uint16) subtables.size); // number of subtables 77 78 // array of offsets to subtable 79 uint s; 80 81 foreach (FontData subtable in subtables) { 82 fd.add_ushort ((uint16) offset); 83 s = subtable.length_with_padding (); 84 85 if (s == 0) { 86 warning ("Zero size in subtable."); 87 } 88 89 offset += 2 + s; 90 } 91 92 return fd; 93 } 94 } 95 96 } 97