• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright © 2018  Google, Inc.
3  *
4  *  This is part of HarfBuzz, a text shaping library.
5  *
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.
11  *
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
16  * DAMAGE.
17  *
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.
23  *
24  * Google Author(s): Behdad Esfahbod
25  */
26 
27 #include "hb.hh"
28 
29 #include "hb-open-type.hh"
30 #include "hb-face.hh"
31 
32 #include "hb-aat-layout-common.hh"
33 #include "hb-aat-layout-feat-table.hh"
34 #include "hb-ot-layout-common.hh"
35 #include "hb-ot-cmap-table.hh"
36 #include "hb-ot-head-table.hh"
37 #include "hb-ot-maxp-table.hh"
38 
39 #ifndef HB_NO_VISIBILITY
40 #include "hb-ot-name-language-static.hh"
41 
42 #ifndef ENABLE_ICCARM
43 uint64_t const _hb_NullPool[(HB_NULL_POOL_SIZE + sizeof (uint64_t) - 1) / sizeof (uint64_t)] = {};
44 /*thread_local*/ uint64_t _hb_CrapPool[(HB_NULL_POOL_SIZE + sizeof (uint64_t) - 1) / sizeof (uint64_t)] = {};
45 #else
46 uint64_t const _hb_NullPool[(HB_NULL_POOL_SIZE + sizeof (uint64_t) - 1) / sizeof (uint64_t)] = {0};
47 /*thread_local*/ uint64_t _hb_CrapPool[(HB_NULL_POOL_SIZE + sizeof (uint64_t) - 1) / sizeof (uint64_t)] = {0};
48 #endif
49 
50 DEFINE_NULL_NAMESPACE_BYTES (OT, Index) =  {0xFF,0xFF};
51 DEFINE_NULL_NAMESPACE_BYTES (OT, VarIdx) =  {0xFF,0xFF,0xFF,0xFF};
52 DEFINE_NULL_NAMESPACE_BYTES (OT, LangSys) = {0x00,0x00, 0xFF,0xFF, 0x00,0x00};
53 DEFINE_NULL_NAMESPACE_BYTES (OT, RangeRecord) = {0x00,0x01, 0x00,0x00, 0x00, 0x00};
54 DEFINE_NULL_NAMESPACE_BYTES (OT, CmapSubtableLongGroup) = {0x00,0x00,0x00,0x01, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00};
55 DEFINE_NULL_NAMESPACE_BYTES (AAT, SettingName) = {0xFF,0xFF, 0xFF,0xFF};
56 /* Hand-coded because Lookup is a template.  Sad. */
57 const unsigned char _hb_Null_AAT_Lookup[2] = {0xFF, 0xFF};
58 
59 
60 
61 /* hb_face_t */
62 
63 unsigned int
load_num_glyphs() const64 hb_face_t::load_num_glyphs () const
65 {
66   hb_sanitize_context_t c = hb_sanitize_context_t ();
67   c.set_num_glyphs (0); /* So we don't recurse ad infinitum. */
68   hb_blob_t *maxp_blob = c.reference_table<OT::maxp> (this);
69   const OT::maxp *maxp_table = maxp_blob->as<OT::maxp> ();
70 
71   unsigned int ret = maxp_table->get_num_glyphs ();
72   num_glyphs.set_relaxed (ret);
73   hb_blob_destroy (maxp_blob);
74   return ret;
75 }
76 
77 unsigned int
load_upem() const78 hb_face_t::load_upem () const
79 {
80   unsigned int ret = table.head->get_upem ();
81   upem.set_relaxed (ret);
82   return ret;
83 }
84 
85 
86 /* hb_user_data_array_t */
87 
88 bool
set(hb_user_data_key_t * key,void * data,hb_destroy_func_t destroy,hb_bool_t replace)89 hb_user_data_array_t::set (hb_user_data_key_t *key,
90 			   void *              data,
91 			   hb_destroy_func_t   destroy,
92 			   hb_bool_t           replace)
93 {
94   if (!key)
95     return false;
96 
97   if (replace) {
98     if (!data && !destroy) {
99       items.remove (key, lock);
100       return true;
101     }
102   }
103   hb_user_data_item_t item = {key, data, destroy};
104   bool ret = !!items.replace_or_insert (item, lock, (bool) replace);
105 
106   return ret;
107 }
108 
109 void *
get(hb_user_data_key_t * key)110 hb_user_data_array_t::get (hb_user_data_key_t *key)
111 {
112   hb_user_data_item_t item = {nullptr, nullptr, nullptr};
113 
114   return items.find (key, &item, lock) ? item.data : nullptr;
115 }
116 
117 
118 #endif
119