| 1 |
// -*- related-file-name: "../include/efont/otfos2.hh" -*- |
| 2 |
|
| 3 |
/* otfos2.{cc,hh} -- OpenType OS/2 table |
| 4 |
* |
| 5 |
* Copyright (c) 2005-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/otfos2.hh> |
| 20 |
#include <lcdf/error.hh> |
| 21 |
#include <errno.h> |
| 22 |
#include <stdlib.h> |
| 23 |
#include <string.h> |
| 24 |
|
| 25 |
namespace Efont { namespace OpenType { |
| 26 |
|
| 27 |
Os2::Os2(const Data &data, ErrorHandler *errh) |
| 28 |
: _data(data) |
| 29 |
{ |
| 30 |
_error = parse_header(errh ? errh : ErrorHandler::silent_handler()); |
| 31 |
if (_error < 0) |
| 32 |
_data = Data(); |
| 33 |
} |
| 34 |
|
| 35 |
int |
| 36 |
Os2::parse_header(ErrorHandler *errh) |
| 37 |
{ |
| 38 |
// HEADER FORMAT: |
| 39 |
// USHORT version |
| 40 |
if (HEADER_SIZE > _data.length()) |
| 41 |
return errh->error("OTF OS/2 table too small"), -EFAULT; |
| 42 |
if (_data.u16(0) > 5) |
| 43 |
return errh->error("unexpected OS/2 version number %d", _data.u16(0)), -ERANGE; |
| 44 |
return 0; |
| 45 |
} |
| 46 |
|
| 47 |
}} |