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