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