The Birdfont Source Code


All Repositories / birdfont.git / blob – RSS feed

OffsetTable.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/OffsetTable.vala.
Cache overview items
1 /* 2 Copyright (C) 2012, 2013 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 public class OffsetTable : OtfTable { 18 DirectoryTable directory_table; 19 20 public uint16 num_tables = 0; 21 uint16 search_range = 0; 22 uint16 entry_selector = 0; 23 uint16 range_shift = 0; 24 25 public OffsetTable (DirectoryTable t) { 26 id = "Offset table"; 27 directory_table = t; 28 } 29 30 public override void parse (FontData dis) throws Error { 31 Fixed version; 32 33 dis.seek (offset); 34 35 version = dis.read_fixed (); 36 num_tables = dis.read_ushort (); 37 search_range = dis.read_ushort (); 38 entry_selector = dis.read_ushort (); 39 range_shift = dis.read_ushort (); 40 41 printd (@"Font file version $(version.get_string ())\n"); 42 printd (@"Number of tables $num_tables\n"); 43 } 44 45 public void process () throws GLib.Error { 46 FontData fd = new FontData (); 47 Fixed version = 0x00010000; // sfnt version 1.0 for TTF CFF else use OTTO 48 49 50 num_tables = (uint16) directory_table.get_tables ().size - 2; // number of tables, skip DirectoryTable and OffsetTable 51 52 search_range = max_pow_2_less_than_i (num_tables) * 16; 53 entry_selector = max_log_2_less_than_i (num_tables); 54 range_shift = 16 * num_tables - search_range; 55 56 fd.add_fixed (version); 57 fd.add_u16 (num_tables); 58 fd.add_u16 (search_range); 59 fd.add_u16 (entry_selector); 60 fd.add_u16 (range_shift); 61 62 // skip padding for offset table 63 64 this.font_data = fd; 65 } 66 } 67 68 } 69