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

Revisions

View the latest version of libbirdfont/OpenFontFormat/Lookup.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 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 int token; 23 24 public Lookup (uint16 type, uint16 flags, int token = Lookups.NONE) { 25 this.type = type; 26 this.flags = flags; 27 subtables = new Gee.ArrayList<FontData> (); 28 this.token = token; 29 } 30 31 public void add_subtable (FontData subtable) { 32 subtables.add (subtable); 33 } 34 35 public uint get_lookup_entry_size () throws GLib.Error { 36 return 6 + 2 * subtables.size; 37 } 38 39 public uint get_subtable_size () throws GLib.Error { 40 uint size = 0; 41 uint s; 42 43 foreach (FontData subtable in subtables) { 44 s = subtable.length_with_padding (); 45 46 if (s == 0) { 47 warning ("Zero size in subtable."); 48 } 49 50 size += s; 51 } 52 53 warn_if_fail (size != 0); 54 55 return size; 56 } 57 58 public FontData get_lookup_entry (uint lookup_offset) 59 throws GLib.Error { 60 FontData fd = new FontData (); 61 62 return_val_if_fail (subtables.size > 0, fd); 63 64 fd.add_ushort (type); // lookup type 65 fd.add_ushort (flags); // lookup flags 66 fd.add_ushort ((uint16) subtables.size); // number of subtables 67 68 // array of offsets to subtable 69 uint s; 70 foreach (FontData subtable in subtables) { 71 uint offset = lookup_offset; 72 fd.add_ushort ((uint16) offset); 73 subtable.offset = offset; 74 s = subtable.length_with_padding (); 75 76 if (s == 0) { 77 warning ("Zero size in subtable."); 78 } 79 80 lookup_offset += s; 81 } 82 83 return fd; 84 } 85 } 86 87 } 88