OLD | NEW |
1 /* | 1 /* |
2 * Copyright © 2011,2012 Google, Inc. | 2 * Copyright © 2011,2012 Google, Inc. |
3 * | 3 * |
4 * This is part of HarfBuzz, a text shaping library. | 4 * This is part of HarfBuzz, a text shaping library. |
5 * | 5 * |
6 * Permission is hereby granted, without written agreement and without | 6 * Permission is hereby granted, without written agreement and without |
7 * license or royalty fees, to use, copy, modify, and distribute this | 7 * license or royalty fees, to use, copy, modify, and distribute this |
8 * software and its documentation for any purpose, provided that the | 8 * software and its documentation for any purpose, provided that the |
9 * above copyright notice and the following two paragraphs appear in | 9 * above copyright notice and the following two paragraphs appear in |
10 * all copies of this software. | 10 * all copies of this software. |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 USHORT languageID; /* Language ID. */ | 67 USHORT languageID; /* Language ID. */ |
68 USHORT nameID; /* Name ID. */ | 68 USHORT nameID; /* Name ID. */ |
69 USHORT length; /* String length (in bytes). */ | 69 USHORT length; /* String length (in bytes). */ |
70 USHORT offset; /* String offset from start of storage area (in
bytes). */ | 70 USHORT offset; /* String offset from start of storage area (in
bytes). */ |
71 public: | 71 public: |
72 DEFINE_SIZE_STATIC (12); | 72 DEFINE_SIZE_STATIC (12); |
73 }; | 73 }; |
74 | 74 |
75 struct name | 75 struct name |
76 { | 76 { |
77 static const hb_tag_t Tag» = HB_OT_TAG_name; | 77 static const hb_tag_t tableTag» = HB_OT_TAG_name; |
78 | 78 |
79 inline unsigned int get_name (unsigned int platform_id, | 79 inline unsigned int get_name (unsigned int platform_id, |
80 unsigned int encoding_id, | 80 unsigned int encoding_id, |
81 unsigned int language_id, | 81 unsigned int language_id, |
82 unsigned int name_id, | 82 unsigned int name_id, |
83 void *buffer, | 83 void *buffer, |
84 unsigned int buffer_length) const | 84 unsigned int buffer_length) const |
85 { | 85 { |
86 NameRecord key; | 86 NameRecord key; |
87 key.platformID.set (platform_id); | 87 key.platformID.set (platform_id); |
88 key.encodingID.set (encoding_id); | 88 key.encodingID.set (encoding_id); |
89 key.languageID.set (language_id); | 89 key.languageID.set (language_id); |
90 key.nameID.set (name_id); | 90 key.nameID.set (name_id); |
91 NameRecord *match = (NameRecord *) bsearch (&key, nameRecord, count, sizeof
(nameRecord[0]), (hb_compare_func_t) NameRecord::cmp); | 91 NameRecord *match = (NameRecord *) bsearch (&key, nameRecord, count, sizeof
(nameRecord[0]), (hb_compare_func_t) NameRecord::cmp); |
92 | 92 |
93 if (!match) | 93 if (!match) |
94 return 0; | 94 return 0; |
95 | 95 |
96 unsigned int length = MIN (buffer_length, (unsigned int) match->length); | 96 unsigned int length = MIN (buffer_length, (unsigned int) match->length); |
97 memcpy (buffer, (char *) this + stringOffset + match->offset, length); | 97 memcpy (buffer, (char *) this + stringOffset + match->offset, length); |
98 return length; | 98 return length; |
99 } | 99 } |
100 | 100 |
| 101 inline unsigned int get_size (void) const |
| 102 { return min_size + count * nameRecord[0].min_size; } |
| 103 |
101 inline bool sanitize_records (hb_sanitize_context_t *c) { | 104 inline bool sanitize_records (hb_sanitize_context_t *c) { |
102 TRACE_SANITIZE (this); | 105 TRACE_SANITIZE (this); |
103 char *string_pool = (char *) this + stringOffset; | 106 char *string_pool = (char *) this + stringOffset; |
104 unsigned int _count = count; | 107 unsigned int _count = count; |
105 for (unsigned int i = 0; i < _count; i++) | 108 for (unsigned int i = 0; i < _count; i++) |
106 if (!nameRecord[i].sanitize (c, string_pool)) return TRACE_RETURN (false); | 109 if (!nameRecord[i].sanitize (c, string_pool)) return TRACE_RETURN (false); |
107 return TRACE_RETURN (true); | 110 return TRACE_RETURN (true); |
108 } | 111 } |
109 | 112 |
110 inline bool sanitize (hb_sanitize_context_t *c) { | 113 inline bool sanitize (hb_sanitize_context_t *c) { |
111 TRACE_SANITIZE (this); | 114 TRACE_SANITIZE (this); |
112 return TRACE_RETURN (c->check_struct (this) && | 115 return TRACE_RETURN (c->check_struct (this) && |
113 likely (format == 0 || format == 1) && | 116 likely (format == 0 || format == 1) && |
114 c->check_array (nameRecord, nameRecord[0].static_size,
count) && | 117 c->check_array (nameRecord, nameRecord[0].static_size,
count) && |
115 sanitize_records (c)); | 118 sanitize_records (c)); |
116 } | 119 } |
117 | 120 |
118 /* We only implement format 0 for now. */ | 121 /* We only implement format 0 for now. */ |
119 protected: | |
120 USHORT format; /* Format selector (=0/1). */ | 122 USHORT format; /* Format selector (=0/1). */ |
121 USHORT count; /* Number of name records. */ | 123 USHORT count; /* Number of name records. */ |
122 Offset stringOffset; /* Offset to start of string storage (fr
om start of table). */ | 124 Offset stringOffset; /* Offset to start of string storage (fr
om start of table). */ |
123 NameRecord nameRecord[VAR]; /* The name records where count is the n
umber of records. */ | 125 NameRecord nameRecord[VAR]; /* The name records where count is the n
umber of records. */ |
124 public: | 126 public: |
125 DEFINE_SIZE_ARRAY (6, nameRecord); | 127 DEFINE_SIZE_ARRAY (6, nameRecord); |
126 }; | 128 }; |
127 | 129 |
128 | 130 |
129 } /* namespace OT */ | 131 } /* namespace OT */ |
130 | 132 |
131 | 133 |
132 #endif /* HB_OT_NAME_TABLE_HH */ | 134 #endif /* HB_OT_NAME_TABLE_HH */ |
OLD | NEW |