| 1 |
// -*- related-file-name: "../include/efont/otffvar.hh" -*- |
| 2 |
|
| 3 |
/* otffvar.{cc,hh} -- OpenType fvar table |
| 4 |
* |
| 5 |
* Copyright (c) 2002-2023 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/otffvar.hh> |
| 20 |
#include <lcdf/error.hh> |
| 21 |
#include <errno.h> |
| 22 |
#include <stdlib.h> |
| 23 |
#include <string.h> |
| 24 |
#include <efont/otfdata.hh> // for ntohl() |
| 25 |
|
| 26 |
namespace Efont { namespace OpenType { |
| 27 |
|
| 28 |
Fvar::Fvar(Data d) |
| 29 |
: _id(nullptr) |
| 30 |
{ |
| 31 |
d.align_long(); |
| 32 |
_d = d.udata(); |
| 33 |
// USHORT majorVersion |
| 34 |
// USHORT minorVersion |
| 35 |
// OFFSET16 axesArrayOffset |
| 36 |
// USHORT reserved |
| 37 |
// USHORT axisCount |
| 38 |
// USHORT axisSize |
| 39 |
// USHORT instanceCount |
| 40 |
// USHORT instanceSize |
| 41 |
if (d.length() == 0) |
| 42 |
throw BlankTable("fvar"); |
| 43 |
if (d.length() < HEADER_SIZE |
| 44 |
|| d.u16(0) != 1) |
| 45 |
throw Format("fvar"); |
| 46 |
int axoff = d.u16(X_AXISOFF), nax = d.u16(X_AXISCOUNT), |
| 47 |
axsz = d.u16(X_AXISSIZE); |
| 48 |
if (axoff < HEADER_SIZE |
| 49 |
|| (axoff % 2) != 0 |
| 50 |
|| nax == 0 |
| 51 |
|| axsz < AXIS_SIZE |
| 52 |
|| (axsz % 2) != 0 |
| 53 |
|| axoff + nax * axsz > d.length()) |
| 54 |
throw Format("fvar"); |
| 55 |
int nin = d.u16(X_INSTANCECOUNT), insz = d.u16(X_INSTANCESIZE); |
| 56 |
if (insz >= 4 + nax * 4 |
| 57 |
&& (insz % 2) == 0 |
| 58 |
&& axoff + axsz * nax + insz * nin <= d.length()) |
| 59 |
_id = _d + axoff + axsz * nax; |
| 60 |
} |
| 61 |
|
| 62 |
}} |