1 // -*- related-file-name: "../include/efont/ttfhead.hh" -*- 2 3 /* ttfhead.{cc,hh} -- TrueType head table 4 * 5 * Copyright (c) 2007-2019 Eddie Kohler 6 * 7 * This program is free software; you can redistribute it and/or modify it 8 * under the terms of the GNU General Public License as published by the Free 9 * Software Foundation; either version 2 of the License, or (at your option) 10 * any later version. This program is distributed in the hope that it will be 11 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General 13 * Public License for more details. 14 */ 15 16 #ifdef HAVE_CONFIG_H 17 # include <config.h> 18 #endif 19 #include <efont/ttfhead.hh> 20 #include <lcdf/error.hh> 21 #include <lcdf/straccum.hh> 22 #include <errno.h> 23 #include <stdlib.h> 24 #include <string.h> 25 #include <algorithm> 26 27 namespace Efont { namespace OpenType { 28 Head(const String & s,ErrorHandler * errh)29Head::Head(const String &s, ErrorHandler *errh) 30 : _d(s) 31 { 32 _error = parse_header(errh ? errh : ErrorHandler::silent_handler()); 33 } 34 35 int parse_header(ErrorHandler * errh)36Head::parse_header(ErrorHandler *errh) 37 { 38 // HEAD format: 39 // 0 Fixed Table version number 0x00010000 (ver. 1.0) 40 // 4 Fixed fontRevision 41 // 8 ULONG checkSumAdjustment 42 // 12 ULONG magicNumber Set to 0x5F0F3CF5 43 // 16 USHORT flags 44 // 18 USHORT unitsPerEm 45 // 20 LONGDATETIME created 46 // 28 LONGDATETIME modified 47 // 36 USHORT xMin 48 // 38 SHORT yMin 49 // 40 SHORT xMax 50 // 42 SHORT yMax 51 // 44 USHORT macStyle 52 // 46 USHORT lowestRecPPEM 53 // 48 SHORT fontDirectionHint 54 // 50 SHORT indexToLocFormat 55 // 52 SHORT glyphDataFormat 56 int len = _d.length(); 57 const uint8_t *data = _d.udata(); 58 if (len == 0) 59 return errh->error("font has no 'head' table"), -EFAULT; 60 if (54 > len) 61 return errh->error("'head' table too small"), -EFAULT; 62 if (!(data[0] == '\000' && data[1] == '\001')) 63 return errh->error("bad 'head' version number"), -ERANGE; 64 if (_d.u32(12) != 0x5F0F3CF5) 65 return errh->error("bad 'head' magic number"), -ERANGE; 66 return 0; 67 } 68 69 }} 70