| 1 |
// -*- related-file-name: "../../libefont/otfname.cc" -*- |
| 2 |
#ifndef EFONT_OTFNAME_HH |
| 3 |
#define EFONT_OTFNAME_HH |
| 4 |
#include <efont/otf.hh> |
| 5 |
#include <efont/otfdata.hh> // for ntohl() |
| 6 |
#include <lcdf/error.hh> |
| 7 |
namespace Efont { namespace OpenType { |
| 8 |
|
| 9 |
class Name { public: |
| 10 |
|
| 11 |
Name(const String &, ErrorHandler * = 0); |
| 12 |
// default destructor |
| 13 |
|
| 14 |
bool ok() const { return _error >= 0; } |
| 15 |
int error() const { return _error; } |
| 16 |
|
| 17 |
enum NameID { N_COPYRIGHT = 0, N_FAMILY = 1, N_SUBFAMILY = 2, |
| 18 |
N_UNIQUEID = 3, N_FULLNAME = 4, N_VERSION = 5, |
| 19 |
N_POSTSCRIPT = 6, N_TRADEMARK = 7, N_MANUFACTURER = 8, |
| 20 |
N_DESIGNER = 9, N_DESCRIPTION = 10, N_VENDOR_URL = 11, |
| 21 |
N_DESIGNER_URL = 12, N_LICENSE_DESCRIPTION = 13, |
| 22 |
N_LICENSE_URL = 14, N_PREF_FAMILY = 16, |
| 23 |
N_PREF_SUBFAMILY = 17, N_MAC_COMPAT_FULLNAME = 18, |
| 24 |
N_SAMPLE_TEXT = 19, N_POSTSCRIPT_CID = 20 }; |
| 25 |
enum Platform { P_UNICODE = 0, P_MACINTOSH = 1, P_MICROSOFT = 3, |
| 26 |
E_MS_UNICODE_BMP = 1, E_MS_UNICODE_FULL = 10, |
| 27 |
E_MAC_ROMAN = 0, |
| 28 |
L_MS_ENGLISH_AMERICAN = 0x409 }; |
| 29 |
enum { HEADER_SIZE = 6, NAMEREC_SIZE = 12 }; |
| 30 |
|
| 31 |
typedef uint8_t namerecord_t[NAMEREC_SIZE]; |
| 32 |
typedef const namerecord_t *const_iterator; |
| 33 |
|
| 34 |
inline static int nameid(const namerecord_t&); |
| 35 |
inline static int platform(const namerecord_t&); |
| 36 |
inline static int encoding(const namerecord_t&); |
| 37 |
inline static int language(const namerecord_t&); |
| 38 |
|
| 39 |
inline const_iterator begin() const; |
| 40 |
inline const_iterator end() const; |
| 41 |
String name(const_iterator) const; |
| 42 |
String utf8_name(const_iterator) const; |
| 43 |
String english_name(int nameid) const; |
| 44 |
|
| 45 |
// check version string for backwards compatibility |
| 46 |
bool version_chaincontext_reverse_backtrack() const; |
| 47 |
|
| 48 |
struct PlatformPred { |
| 49 |
inline PlatformPred(int nameid, int platform = -1, int encoding = -1, int language = -1); |
| 50 |
inline bool operator()(const namerecord_t&) const; |
| 51 |
private: |
| 52 |
int _nameid, _platform, _encoding, _language; |
| 53 |
}; |
| 54 |
|
| 55 |
struct EnglishPlatformPred { |
| 56 |
EnglishPlatformPred(int nameid) : _nameid(nameid) { } |
| 57 |
inline bool operator()(const namerecord_t&) const; |
| 58 |
private: |
| 59 |
int _nameid; |
| 60 |
}; |
| 61 |
|
| 62 |
private: |
| 63 |
|
| 64 |
String _str; |
| 65 |
int _error; |
| 66 |
|
| 67 |
int parse_header(ErrorHandler *); |
| 68 |
|
| 69 |
}; |
| 70 |
|
| 71 |
|
| 72 |
inline int Name::nameid(const namerecord_t& nr) { |
| 73 |
return Data::u16_aligned(reinterpret_cast<const unsigned char*>(&nr) + 6); |
| 74 |
} |
| 75 |
|
| 76 |
inline int Name::platform(const namerecord_t& nr) { |
| 77 |
return Data::u16_aligned(reinterpret_cast<const unsigned char*>(&nr)); |
| 78 |
} |
| 79 |
|
| 80 |
inline int Name::encoding(const namerecord_t& nr) { |
| 81 |
return Data::u16_aligned(reinterpret_cast<const unsigned char*>(&nr) + 2); |
| 82 |
} |
| 83 |
|
| 84 |
inline int Name::language(const namerecord_t& nr) { |
| 85 |
return Data::u16_aligned(reinterpret_cast<const unsigned char*>(&nr) + 4); |
| 86 |
} |
| 87 |
|
| 88 |
inline Name::const_iterator Name::begin() const { |
| 89 |
return reinterpret_cast<const_iterator>(_str.udata() + HEADER_SIZE); |
| 90 |
} |
| 91 |
|
| 92 |
inline Name::const_iterator Name::end() const { |
| 93 |
if (_error >= 0) { |
| 94 |
int count = Data::u16_aligned(_str.udata() + 2); |
| 95 |
return reinterpret_cast<const_iterator>(_str.udata() + HEADER_SIZE + NAMEREC_SIZE * count); |
| 96 |
} else |
| 97 |
return reinterpret_cast<const_iterator>(_str.udata() + HEADER_SIZE); |
| 98 |
} |
| 99 |
|
| 100 |
|
| 101 |
inline Name::PlatformPred::PlatformPred(int nid, int p, int e, int l) |
| 102 |
: _nameid(nid), _platform(p), _encoding(e), _language(l) { |
| 103 |
} |
| 104 |
|
| 105 |
inline bool Name::PlatformPred::operator()(const namerecord_t& i) const { |
| 106 |
return (_nameid == nameid(i)) |
| 107 |
&& (_platform < 0 || _platform == platform(i)) |
| 108 |
&& (_encoding < 0 || _encoding == encoding(i)) |
| 109 |
&& (_language < 0 || _language == language(i)); |
| 110 |
} |
| 111 |
|
| 112 |
inline bool Name::EnglishPlatformPred::operator()(const namerecord_t& i) const { |
| 113 |
if (_nameid == nameid(i)) { |
| 114 |
int p = platform(i), e = encoding(i), l = language(i); |
| 115 |
return (p == P_MACINTOSH && e == E_MAC_ROMAN && l == 0) |
| 116 |
|| (p == P_MICROSOFT && e == E_MS_UNICODE_BMP && l == L_MS_ENGLISH_AMERICAN) |
| 117 |
|| (p == P_MICROSOFT && e == E_MS_UNICODE_FULL && l == L_MS_ENGLISH_AMERICAN); |
| 118 |
} else |
| 119 |
return false; |
| 120 |
} |
| 121 |
|
| 122 |
} // namespace Efont::OpenType |
| 123 |
} // namespace Efont |
| 124 |
#endif |