2 * Copyright © 2011,2012 Google, Inc.
4 * This is part of HarfBuzz, a text shaping library.
6 * Permission is hereby granted, without written agreement and without
7 * license or royalty fees, to use, copy, modify, and distribute this
8 * software and its documentation for any purpose, provided that the
9 * above copyright notice and the following two paragraphs appear in
10 * all copies of this software.
12 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
13 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
14 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
15 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
18 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
19 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20 * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
21 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
22 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
24 * Google Author(s): Behdad Esfahbod
27 #ifndef HB_OT_NAME_TABLE_HH
28 #define HB_OT_NAME_TABLE_HH
30 #include "hb-open-type-private.hh"
37 * name -- The Naming Table
40 #define HB_OT_TAG_name HB_TAG('n','a','m','e')
45 static int cmp (const NameRecord
*a
, const NameRecord
*b
)
48 ret
= b
->platformID
.cmp (a
->platformID
);
50 ret
= b
->encodingID
.cmp (a
->encodingID
);
52 ret
= b
->languageID
.cmp (a
->languageID
);
54 ret
= b
->nameID
.cmp (a
->nameID
);
59 inline bool sanitize (hb_sanitize_context_t
*c
, void *base
) {
60 TRACE_SANITIZE (this);
61 /* We can check from base all the way up to the end of string... */
62 return TRACE_RETURN (c
->check_struct (this) && c
->check_range ((char *) base
, (unsigned int) length
+ offset
));
65 USHORT platformID
; /* Platform ID. */
66 USHORT encodingID
; /* Platform-specific encoding ID. */
67 USHORT languageID
; /* Language ID. */
68 USHORT nameID
; /* Name ID. */
69 USHORT length
; /* String length (in bytes). */
70 USHORT offset
; /* String offset from start of storage area (in bytes). */
72 DEFINE_SIZE_STATIC (12);
77 static const hb_tag_t Tag
= HB_OT_TAG_name
;
79 inline unsigned int get_name (unsigned int platform_id
,
80 unsigned int encoding_id
,
81 unsigned int language_id
,
84 unsigned int buffer_length
) const
87 key
.platformID
.set (platform_id
);
88 key
.encodingID
.set (encoding_id
);
89 key
.languageID
.set (language_id
);
90 key
.nameID
.set (name_id
);
91 NameRecord
*match
= (NameRecord
*) bsearch (&key
, nameRecord
, count
, sizeof (nameRecord
[0]), (hb_compare_func_t
) NameRecord::cmp
);
96 unsigned int length
= MIN (buffer_length
, (unsigned int) match
->length
);
97 memcpy (buffer
, (char *) this + stringOffset
+ match
->offset
, length
);
101 inline bool sanitize_records (hb_sanitize_context_t
*c
) {
102 TRACE_SANITIZE (this);
103 char *string_pool
= (char *) this + stringOffset
;
104 unsigned int _count
= count
;
105 for (unsigned int i
= 0; i
< _count
; i
++)
106 if (!nameRecord
[i
].sanitize (c
, string_pool
)) return TRACE_RETURN (false);
107 return TRACE_RETURN (true);
110 inline bool sanitize (hb_sanitize_context_t
*c
) {
111 TRACE_SANITIZE (this);
112 return TRACE_RETURN (c
->check_struct (this) &&
113 likely (format
== 0 || format
== 1) &&
114 c
->check_array (nameRecord
, nameRecord
[0].static_size
, count
) &&
115 sanitize_records (c
));
118 /* We only implement format 0 for now. */
120 USHORT format
; /* Format selector (=0/1). */
121 USHORT count
; /* Number of name records. */
122 Offset stringOffset
; /* Offset to start of string storage (from start of table). */
123 NameRecord nameRecord
[VAR
]; /* The name records where count is the number of records. */
125 DEFINE_SIZE_ARRAY (6, nameRecord
);
132 #endif /* HB_OT_NAME_TABLE_HH */