QtBase  v6.3.1
hb-static.cc
Go to the documentation of this file.
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"
34 #include "hb-ot-layout-common.hh"
35 #include "hb-ot-cmap-table.hh"
36 #include "hb-ot-glyf-table.hh"
37 #include "hb-ot-head-table.hh"
38 #include "hb-ot-maxp-table.hh"
39 
40 #ifndef HB_NO_VISIBILITY
42 
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 
47 DEFINE_NULL_NAMESPACE_BYTES (OT, VarIdx) = {0xFF,0xFF,0xFF,0xFF};
48 DEFINE_NULL_NAMESPACE_BYTES (OT, LangSys) = {0x00,0x00, 0xFF,0xFF, 0x00,0x00};
49 DEFINE_NULL_NAMESPACE_BYTES (OT, RangeRecord) = {0x00,0x01, 0x00,0x00, 0x00, 0x00};
50 DEFINE_NULL_NAMESPACE_BYTES (OT, CmapSubtableLongGroup) = {0x00,0x00,0x00,0x01, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00};
51 DEFINE_NULL_NAMESPACE_BYTES (AAT, SettingName) = {0xFF,0xFF, 0xFF,0xFF};
52 /* Hand-coded because Lookup is a template. Sad. */
53 const unsigned char _hb_Null_AAT_Lookup[2] = {0xFF, 0xFF};
54 
55 
56 
57 /* hb_face_t */
58 
59 #ifndef HB_NO_BORING_EXPANSION
60 static inline unsigned
61 load_num_glyphs_from_loca (const hb_face_t *face)
62 {
63  unsigned ret = 0;
64 
65  unsigned indexToLocFormat = face->table.head->indexToLocFormat;
66 
67  if (indexToLocFormat <= 1)
68  {
69  bool short_offset = 0 == indexToLocFormat;
70  hb_blob_t *loca_blob = face->table.loca.get_blob ();
71  ret = hb_max (1u, loca_blob->length / (short_offset ? 2 : 4)) - 1;
72  }
73 
74  return ret;
75 }
76 #endif
77 
78 static inline unsigned
79 load_num_glyphs_from_maxp (const hb_face_t *face)
80 {
81  return face->table.maxp->get_num_glyphs ();
82 }
83 
84 unsigned int
85 hb_face_t::load_num_glyphs () const
86 {
87  unsigned ret = 0;
88 
89 #ifndef HB_NO_BORING_EXPANSION
90  ret = hb_max (ret, load_num_glyphs_from_loca (this));
91 #endif
92 
93  ret = hb_max (ret, load_num_glyphs_from_maxp (this));
94 
96  return ret;
97 }
98 
99 unsigned int
100 hb_face_t::load_upem () const
101 {
102  unsigned int ret = table.head->get_upem ();
103  upem.set_relaxed (ret);
104  return ret;
105 }
106 
107 
108 /* hb_user_data_array_t */
109 
110 bool
112  void * data,
114  hb_bool_t replace)
115 {
116  if (!key)
117  return false;
118 
119  if (replace) {
120  if (!data && !destroy) {
121  items.remove (key, lock);
122  return true;
123  }
124  }
126  bool ret = !!items.replace_or_insert (item, lock, (bool) replace);
127 
128  return ret;
129 }
130 
131 void *
133 {
134  hb_user_data_item_t item = {nullptr, nullptr, nullptr};
135 
136  return items.find (key, &item, lock) ? item.data : nullptr;
137 }
138 
139 
140 #endif
QVariant data(int key) const
#define HB_NULL_POOL_SIZE
Definition: hb-null.hh:40
const unsigned char _hb_Null_AAT_Lookup[2]
Definition: hb-static.cc:53
uint64_t const _hb_NullPool[(HB_NULL_POOL_SIZE+sizeof(uint64_t) - 1)/sizeof(uint64_t)]
Definition: hb-static.cc:43
uint64_t _hb_CrapPool[(HB_NULL_POOL_SIZE+sizeof(uint64_t) - 1)/sizeof(uint64_t)]
Definition: hb-static.cc:44
DEFINE_NULL_NAMESPACE_BYTES(OT, Index)
GLuint64 key
GLenum face
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLenum GLenum GLsizei void * table
Definition: qopenglext.h:2745
void(* hb_destroy_func_t)(void *user_data)
Definition: hb-common.h:771
HB_BEGIN_DECLS typedef int hb_bool_t
Definition: hb-common.h:97
HB_EXTERN hb_font_get_glyph_func_t void hb_destroy_func_t destroy
QGraphicsItem * item
void set_relaxed(int v_)
Definition: hb-atomic.hh:149
unsigned int length
Definition: hb-blob.hh:65
hb_atomic_int_t num_glyphs
Definition: hb-face.hh:57
hb_atomic_int_t upem
Definition: hb-face.hh:56
HB_INTERNAL void * get(hb_user_data_key_t *key)
Definition: hb-static.cc:132
hb_lockable_set_t< hb_user_data_item_t, hb_mutex_t > items
Definition: hb-object.hh:174
HB_INTERNAL bool set(hb_user_data_key_t *key, void *data, hb_destroy_func_t destroy, hb_bool_t replace)
Definition: hb-static.cc:111