1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/harfbuzz/src/hb-ot-name-table.hh Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,134 @@ 1.4 +/* 1.5 + * Copyright © 2011,2012 Google, Inc. 1.6 + * 1.7 + * This is part of HarfBuzz, a text shaping library. 1.8 + * 1.9 + * Permission is hereby granted, without written agreement and without 1.10 + * license or royalty fees, to use, copy, modify, and distribute this 1.11 + * software and its documentation for any purpose, provided that the 1.12 + * above copyright notice and the following two paragraphs appear in 1.13 + * all copies of this software. 1.14 + * 1.15 + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR 1.16 + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 1.17 + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN 1.18 + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 1.19 + * DAMAGE. 1.20 + * 1.21 + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, 1.22 + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 1.23 + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS 1.24 + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO 1.25 + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 1.26 + * 1.27 + * Google Author(s): Behdad Esfahbod 1.28 + */ 1.29 + 1.30 +#ifndef HB_OT_NAME_TABLE_HH 1.31 +#define HB_OT_NAME_TABLE_HH 1.32 + 1.33 +#include "hb-open-type-private.hh" 1.34 + 1.35 + 1.36 +namespace OT { 1.37 + 1.38 + 1.39 +/* 1.40 + * name -- The Naming Table 1.41 + */ 1.42 + 1.43 +#define HB_OT_TAG_name HB_TAG('n','a','m','e') 1.44 + 1.45 + 1.46 +struct NameRecord 1.47 +{ 1.48 + static int cmp (const NameRecord *a, const NameRecord *b) 1.49 + { 1.50 + int ret; 1.51 + ret = b->platformID.cmp (a->platformID); 1.52 + if (ret) return ret; 1.53 + ret = b->encodingID.cmp (a->encodingID); 1.54 + if (ret) return ret; 1.55 + ret = b->languageID.cmp (a->languageID); 1.56 + if (ret) return ret; 1.57 + ret = b->nameID.cmp (a->nameID); 1.58 + if (ret) return ret; 1.59 + return 0; 1.60 + } 1.61 + 1.62 + inline bool sanitize (hb_sanitize_context_t *c, void *base) { 1.63 + TRACE_SANITIZE (this); 1.64 + /* We can check from base all the way up to the end of string... */ 1.65 + return TRACE_RETURN (c->check_struct (this) && c->check_range ((char *) base, (unsigned int) length + offset)); 1.66 + } 1.67 + 1.68 + USHORT platformID; /* Platform ID. */ 1.69 + USHORT encodingID; /* Platform-specific encoding ID. */ 1.70 + USHORT languageID; /* Language ID. */ 1.71 + USHORT nameID; /* Name ID. */ 1.72 + USHORT length; /* String length (in bytes). */ 1.73 + USHORT offset; /* String offset from start of storage area (in bytes). */ 1.74 + public: 1.75 + DEFINE_SIZE_STATIC (12); 1.76 +}; 1.77 + 1.78 +struct name 1.79 +{ 1.80 + static const hb_tag_t tableTag = HB_OT_TAG_name; 1.81 + 1.82 + inline unsigned int get_name (unsigned int platform_id, 1.83 + unsigned int encoding_id, 1.84 + unsigned int language_id, 1.85 + unsigned int name_id, 1.86 + void *buffer, 1.87 + unsigned int buffer_length) const 1.88 + { 1.89 + NameRecord key; 1.90 + key.platformID.set (platform_id); 1.91 + key.encodingID.set (encoding_id); 1.92 + key.languageID.set (language_id); 1.93 + key.nameID.set (name_id); 1.94 + NameRecord *match = (NameRecord *) bsearch (&key, nameRecord, count, sizeof (nameRecord[0]), (hb_compare_func_t) NameRecord::cmp); 1.95 + 1.96 + if (!match) 1.97 + return 0; 1.98 + 1.99 + unsigned int length = MIN (buffer_length, (unsigned int) match->length); 1.100 + memcpy (buffer, (char *) this + stringOffset + match->offset, length); 1.101 + return length; 1.102 + } 1.103 + 1.104 + inline unsigned int get_size (void) const 1.105 + { return min_size + count * nameRecord[0].min_size; } 1.106 + 1.107 + inline bool sanitize_records (hb_sanitize_context_t *c) { 1.108 + TRACE_SANITIZE (this); 1.109 + char *string_pool = (char *) this + stringOffset; 1.110 + unsigned int _count = count; 1.111 + for (unsigned int i = 0; i < _count; i++) 1.112 + if (!nameRecord[i].sanitize (c, string_pool)) return TRACE_RETURN (false); 1.113 + return TRACE_RETURN (true); 1.114 + } 1.115 + 1.116 + inline bool sanitize (hb_sanitize_context_t *c) { 1.117 + TRACE_SANITIZE (this); 1.118 + return TRACE_RETURN (c->check_struct (this) && 1.119 + likely (format == 0 || format == 1) && 1.120 + c->check_array (nameRecord, nameRecord[0].static_size, count) && 1.121 + sanitize_records (c)); 1.122 + } 1.123 + 1.124 + /* We only implement format 0 for now. */ 1.125 + USHORT format; /* Format selector (=0/1). */ 1.126 + USHORT count; /* Number of name records. */ 1.127 + Offset stringOffset; /* Offset to start of string storage (from start of table). */ 1.128 + NameRecord nameRecord[VAR]; /* The name records where count is the number of records. */ 1.129 + public: 1.130 + DEFINE_SIZE_ARRAY (6, nameRecord); 1.131 +}; 1.132 + 1.133 + 1.134 +} /* namespace OT */ 1.135 + 1.136 + 1.137 +#endif /* HB_OT_NAME_TABLE_HH */