gfx/harfbuzz/src/hb-ot-name-table.hh

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

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

mercurial