hb-ot-name-table.hh revision b492299eb3c398701557e452f6c2c9bd370fbbf3
1b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod/* 2b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod * Copyright © 2011 Google, Inc. 3b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod * 4b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod * This is part of HarfBuzz, a text shaping library. 5b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod * 6b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod * Permission is hereby granted, without written agreement and without 7b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod * license or royalty fees, to use, copy, modify, and distribute this 8b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod * software and its documentation for any purpose, provided that the 9b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod * above copyright notice and the following two paragraphs appear in 10b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod * all copies of this software. 11b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod * 12b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR 13b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 14b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN 15b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 16b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod * DAMAGE. 17b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod * 18b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, 19b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS 21b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO 22b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 23b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod * 24b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod * Google Author(s): Behdad Esfahbod 25b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod */ 26b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod 27b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod#ifndef HB_OT_NAME_PRIVATE_HH 28b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod#define HB_OT_NAME_PRIVATE_HH 29b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod 30b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod#include "hb-open-type-private.hh" 31b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod 32b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod 33b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod 34b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod/* 35b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod * name 36b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod */ 37b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod 38b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod#define HB_OT_TAG_name HB_TAG('n','a','m','e') 39b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod 40b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbodstruct NameRecord 41b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod{ 42b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod inline bool sanitize (hb_sanitize_context_t *c, void *base) { 43b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod TRACE_SANITIZE (); 44b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod /* We can check from base all the way up to the end of string... */ 45b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod return c->check_struct (this) && 46b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod c->check_range ((char *) base, (unsigned int) length + offset); 47b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod } 48b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod 49b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod USHORT platformID; /* Platform ID. */ 50b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod USHORT encodingID; /* Platform-specific encoding ID. */ 51b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod USHORT languageID; /* Language ID. */ 52b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod USHORT nameID; /* Name ID. */ 53b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod USHORT length; /* String length (in bytes). */ 54b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod USHORT offset; /* String offset from start of storage area (in bytes). */ 55b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod public: 56b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod DEFINE_SIZE_STATIC (12); 57b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod}; 58b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod 59b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbodstruct name 60b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod{ 61b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod static const hb_tag_t Tag = HB_OT_TAG_name; 62b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod 63b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod inline bool sanitize_records (hb_sanitize_context_t *c) { 64b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod TRACE_SANITIZE (); 65b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod unsigned int _count = count; 66b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod for (unsigned int i = 0; i < _count; i++) 67b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod if (!nameRecord[i].sanitize (c, this + stringOffset)) return false; 68b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod return true; 69b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod } 70b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod 71b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod inline bool sanitize (hb_sanitize_context_t *c) { 72b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod TRACE_SANITIZE (); 73b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod return c->check_struct (this) && 74b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod likely (format == 0 || format == 1) && 75b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod c->check_array (nameRecord, nameRecord[0].static_size, count) && 76b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod sanitize_records (c); 77b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod } 78b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod 79b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod /* We only implement format 0 for now. */ 80b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod private: 81b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod USHORT format; /* Format selector (=0/1). */ 82b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod USHORT count; /* Number of name records. */ 83b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod Offset stringOffset; /* Offset to start of string storage (from start of table). */ 84b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod NameRecord nameRecord[VAR]; /* The name records where count is the number of records. */ 85b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod public: 86b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod DEFINE_SIZE_ARRAY (6, nameRecord); 87b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod}; 88b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod 89b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod 90b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod 91b492299eb3c398701557e452f6c2c9bd370fbbf3Behdad Esfahbod#endif /* HB_OT_NAME_PRIVATE_HH */ 92