25 */
26
27 #ifndef HB_OT_NAME_TABLE_HH
28 #define HB_OT_NAME_TABLE_HH
29
30 #include "hb-open-type-private.hh"
31
32
33 namespace OT {
34
35
36 /*
37 * name -- The Naming Table
38 */
39
40 #define HB_OT_TAG_name HB_TAG('n','a','m','e')
41
42
43 struct NameRecord
44 {
45 static int cmp (const NameRecord *a, const NameRecord *b)
46 {
47 int ret;
48 ret = b->platformID.cmp (a->platformID);
49 if (ret) return ret;
50 ret = b->encodingID.cmp (a->encodingID);
51 if (ret) return ret;
52 ret = b->languageID.cmp (a->languageID);
53 if (ret) return ret;
54 ret = b->nameID.cmp (a->nameID);
55 if (ret) return ret;
56 return 0;
57 }
58
59 inline bool sanitize (hb_sanitize_context_t *c, const void *base) const
60 {
61 TRACE_SANITIZE (this);
62 /* We can check from base all the way up to the end of string... */
63 return_trace (c->check_struct (this) && c->check_range ((char *) base, (unsigned int) length + offset));
64 }
65
66 USHORT platformID; /* Platform ID. */
72 public:
73 DEFINE_SIZE_STATIC (12);
74 };
75
76 struct name
77 {
78 static const hb_tag_t tableTag = HB_OT_TAG_name;
79
80 inline unsigned int get_name (unsigned int platform_id,
81 unsigned int encoding_id,
82 unsigned int language_id,
83 unsigned int name_id,
84 void *buffer,
85 unsigned int buffer_length) const
86 {
87 NameRecord key;
88 key.platformID.set (platform_id);
89 key.encodingID.set (encoding_id);
90 key.languageID.set (language_id);
91 key.nameID.set (name_id);
92 NameRecord *match = (NameRecord *) bsearch (&key, nameRecord, count, sizeof (nameRecord[0]), (hb_compare_func_t) NameRecord::cmp);
93
94 if (!match)
95 return 0;
96
97 unsigned int length = MIN (buffer_length, (unsigned int) match->length);
98 memcpy (buffer, (char *) this + stringOffset + match->offset, length);
99 return length;
100 }
101
102 inline unsigned int get_size (void) const
103 { return min_size + count * nameRecord[0].min_size; }
104
105 inline bool sanitize_records (hb_sanitize_context_t *c) const {
106 TRACE_SANITIZE (this);
107 char *string_pool = (char *) this + stringOffset;
108 unsigned int _count = count;
109 for (unsigned int i = 0; i < _count; i++)
110 if (!nameRecord[i].sanitize (c, string_pool)) return_trace (false);
111 return_trace (true);
112 }
|
25 */
26
27 #ifndef HB_OT_NAME_TABLE_HH
28 #define HB_OT_NAME_TABLE_HH
29
30 #include "hb-open-type-private.hh"
31
32
33 namespace OT {
34
35
36 /*
37 * name -- The Naming Table
38 */
39
40 #define HB_OT_TAG_name HB_TAG('n','a','m','e')
41
42
43 struct NameRecord
44 {
45 static int cmp (const void *pa, const void *pb)
46 {
47 const NameRecord *a = (const NameRecord *) pa;
48 const NameRecord *b = (const NameRecord *) pb;
49 int ret;
50 ret = b->platformID.cmp (a->platformID);
51 if (ret) return ret;
52 ret = b->encodingID.cmp (a->encodingID);
53 if (ret) return ret;
54 ret = b->languageID.cmp (a->languageID);
55 if (ret) return ret;
56 ret = b->nameID.cmp (a->nameID);
57 if (ret) return ret;
58 return 0;
59 }
60
61 inline bool sanitize (hb_sanitize_context_t *c, const void *base) const
62 {
63 TRACE_SANITIZE (this);
64 /* We can check from base all the way up to the end of string... */
65 return_trace (c->check_struct (this) && c->check_range ((char *) base, (unsigned int) length + offset));
66 }
67
68 USHORT platformID; /* Platform ID. */
74 public:
75 DEFINE_SIZE_STATIC (12);
76 };
77
78 struct name
79 {
80 static const hb_tag_t tableTag = HB_OT_TAG_name;
81
82 inline unsigned int get_name (unsigned int platform_id,
83 unsigned int encoding_id,
84 unsigned int language_id,
85 unsigned int name_id,
86 void *buffer,
87 unsigned int buffer_length) const
88 {
89 NameRecord key;
90 key.platformID.set (platform_id);
91 key.encodingID.set (encoding_id);
92 key.languageID.set (language_id);
93 key.nameID.set (name_id);
94 NameRecord *match = (NameRecord *) bsearch (&key, nameRecord, count, sizeof (nameRecord[0]), NameRecord::cmp);
95
96 if (!match)
97 return 0;
98
99 unsigned int length = MIN (buffer_length, (unsigned int) match->length);
100 memcpy (buffer, (char *) this + stringOffset + match->offset, length);
101 return length;
102 }
103
104 inline unsigned int get_size (void) const
105 { return min_size + count * nameRecord[0].min_size; }
106
107 inline bool sanitize_records (hb_sanitize_context_t *c) const {
108 TRACE_SANITIZE (this);
109 char *string_pool = (char *) this + stringOffset;
110 unsigned int _count = count;
111 for (unsigned int i = 0; i < _count; i++)
112 if (!nameRecord[i].sanitize (c, string_pool)) return_trace (false);
113 return_trace (true);
114 }
|