| 1 |
// -*- related-file-name: "../../libefont/otfos2.cc" -*- |
| 2 |
#ifndef EFONT_OTFOS2_HH |
| 3 |
#define EFONT_OTFOS2_HH |
| 4 |
#include <efont/otf.hh> |
| 5 |
#include <efont/otfdata.hh> |
| 6 |
#include <lcdf/error.hh> |
| 7 |
namespace Efont { namespace OpenType { |
| 8 |
|
| 9 |
class Os2 { public: |
| 10 |
|
| 11 |
Os2(const Data &, ErrorHandler * = 0); |
| 12 |
// default destructor |
| 13 |
|
| 14 |
bool ok() const { return _error >= 0; } |
| 15 |
int error() const { return _error; } |
| 16 |
|
| 17 |
enum Offsets { O_AVGCHARWIDTH = 2, O_FSTYPE = 8, |
| 18 |
O_SUBSCRIPTXSIZE = 10, O_SUBSCRIPTYSIZE = 12, |
| 19 |
O_SUBSCRIPTXOFFSET = 14, O_SUBSCRIPTYOFFSET = 16, |
| 20 |
O_SUPERSCRIPTXSIZE = 18, O_SUPERSCRIPTYSIZE = 20, |
| 21 |
O_SUPERSCRIPTXOFFSET = 22, O_SUPERSCRIPTYOFFSET = 24, |
| 22 |
O_STRIKEOUTSIZE = 26, O_STRIKEOUTPOSITION = 28, |
| 23 |
O_VENDORID = 58, |
| 24 |
O_TYPOASCENDER = 68, O_TYPODESCENDER = 70, |
| 25 |
O_TYPOLINEGAP = 72, O_XHEIGHT = 86, O_CAPHEIGHT = 88, |
| 26 |
O_LOWEROPTICALPOINTSIZE = 96, O_UPPEROPTICALPOINTSIZE = 98 }; |
| 27 |
enum { HEADER_SIZE = 2 }; |
| 28 |
|
| 29 |
inline uint16_t type_flags() const; |
| 30 |
inline int16_t typo_ascender() const; |
| 31 |
inline int16_t typo_descender() const; |
| 32 |
inline int16_t typo_line_gap() const; |
| 33 |
inline int16_t x_height() const; |
| 34 |
inline int16_t cap_height() const; |
| 35 |
inline double lower_optical_point_size() const; |
| 36 |
inline double upper_optical_point_size() const; |
| 37 |
inline bool has_optical_point_size() const noexcept; |
| 38 |
inline String vendor_id() const noexcept; |
| 39 |
|
| 40 |
private: |
| 41 |
|
| 42 |
Data _data; |
| 43 |
int _error; |
| 44 |
|
| 45 |
int parse_header(ErrorHandler *); |
| 46 |
|
| 47 |
}; |
| 48 |
|
| 49 |
|
| 50 |
inline uint16_t Os2::type_flags() const |
| 51 |
{ |
| 52 |
return _data.u16(O_FSTYPE); |
| 53 |
} |
| 54 |
|
| 55 |
inline int16_t Os2::typo_ascender() const |
| 56 |
{ |
| 57 |
return _data.s16(O_TYPOASCENDER); |
| 58 |
} |
| 59 |
|
| 60 |
inline int16_t Os2::typo_descender() const |
| 61 |
{ |
| 62 |
return _data.s16(O_TYPODESCENDER); |
| 63 |
} |
| 64 |
|
| 65 |
inline int16_t Os2::typo_line_gap() const |
| 66 |
{ |
| 67 |
return _data.s16(O_TYPOLINEGAP); |
| 68 |
} |
| 69 |
|
| 70 |
inline int16_t Os2::x_height() const |
| 71 |
{ |
| 72 |
return _data.s16(O_XHEIGHT); |
| 73 |
} |
| 74 |
|
| 75 |
inline int16_t Os2::cap_height() const |
| 76 |
{ |
| 77 |
return _data.s16(O_CAPHEIGHT); |
| 78 |
} |
| 79 |
|
| 80 |
inline double Os2::lower_optical_point_size() const |
| 81 |
{ |
| 82 |
return _data.u16(O_LOWEROPTICALPOINTSIZE) / 20.; |
| 83 |
} |
| 84 |
|
| 85 |
inline double Os2::upper_optical_point_size() const |
| 86 |
{ |
| 87 |
return _data.u16(O_UPPEROPTICALPOINTSIZE) / 20.; |
| 88 |
} |
| 89 |
|
| 90 |
inline bool Os2::has_optical_point_size() const noexcept |
| 91 |
{ |
| 92 |
return _data.length() >= O_UPPEROPTICALPOINTSIZE + 2; |
| 93 |
} |
| 94 |
|
| 95 |
inline String Os2::vendor_id() const noexcept |
| 96 |
{ |
| 97 |
return _data.substring(O_VENDORID, 4).string(); |
| 98 |
} |
| 99 |
|
| 100 |
}} |
| 101 |
#endif |