Coverage Report

Created: 2024-01-21 06:55

/src/harfbuzz/src/hb-subset-accelerator.hh
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright © 2022  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): Garret Rieger
25
 */
26
27
#ifndef HB_SUBSET_ACCELERATOR_HH
28
#define HB_SUBSET_ACCELERATOR_HH
29
30
31
#include "hb.hh"
32
33
#include "hb-map.hh"
34
#include "hb-multimap.hh"
35
#include "hb-set.hh"
36
37
extern HB_INTERNAL hb_user_data_key_t _hb_subset_accelerator_user_data_key;
38
39
namespace CFF {
40
struct cff_subset_accelerator_t;
41
}
42
43
namespace OT {
44
struct SubtableUnicodesCache;
45
};
46
47
struct hb_subset_accelerator_t
48
{
49
  static hb_user_data_key_t* user_data_key()
50
0
  {
51
0
    return &_hb_subset_accelerator_user_data_key;
52
0
  }
53
54
  static hb_subset_accelerator_t* create(const hb_map_t& unicode_to_gid_,
55
           const hb_multimap_t gid_to_unicodes_,
56
           const hb_set_t& unicodes_,
57
0
           bool has_seac_) {
58
0
    hb_subset_accelerator_t* accel =
59
0
        (hb_subset_accelerator_t*) hb_calloc (1, sizeof(hb_subset_accelerator_t));
60
0
61
0
    new (accel) hb_subset_accelerator_t (unicode_to_gid_,
62
0
           gid_to_unicodes_,
63
0
           unicodes_,
64
0
           has_seac_);
65
0
66
0
    return accel;
67
0
  }
68
69
  static void destroy (void* p)
70
0
  {
71
0
    if (!p) return;
72
0
73
0
    hb_subset_accelerator_t *accel = (hb_subset_accelerator_t *) p;
74
0
75
0
    accel->~hb_subset_accelerator_t ();
76
0
77
0
    hb_free (accel);
78
0
  }
79
80
  hb_subset_accelerator_t (const hb_map_t& unicode_to_gid_,
81
         const hb_multimap_t& gid_to_unicodes_,
82
         const hb_set_t& unicodes_,
83
         bool has_seac_) :
84
    unicode_to_gid(unicode_to_gid_),
85
    gid_to_unicodes (gid_to_unicodes_),
86
    unicodes(unicodes_),
87
    cmap_cache(nullptr),
88
    destroy_cmap_cache(nullptr),
89
    has_seac(has_seac_),
90
    cff_accelerator(nullptr),
91
0
    destroy_cff_accelerator(nullptr) {}
92
93
  ~hb_subset_accelerator_t ()
94
0
  {
95
0
    if (cff_accelerator && destroy_cff_accelerator)
96
0
      destroy_cff_accelerator ((void*) cff_accelerator);
97
0
98
0
    if (cmap_cache && destroy_cmap_cache)
99
0
      destroy_cmap_cache ((void*) cmap_cache);
100
0
  }
101
102
  // Generic
103
104
  mutable hb_mutex_t sanitized_table_cache_lock;
105
  mutable hb_hashmap_t<hb_tag_t, hb::unique_ptr<hb_blob_t>> sanitized_table_cache;
106
107
  const hb_map_t unicode_to_gid;
108
  const hb_multimap_t gid_to_unicodes;
109
  const hb_set_t unicodes;
110
111
  // cmap
112
  const OT::SubtableUnicodesCache* cmap_cache;
113
  hb_destroy_func_t destroy_cmap_cache;
114
115
  // CFF
116
  bool has_seac;
117
  const CFF::cff_subset_accelerator_t* cff_accelerator;
118
  hb_destroy_func_t destroy_cff_accelerator;
119
120
  // TODO(garretrieger): cumulative glyf checksum map
121
122
  bool in_error () const
123
0
  {
124
0
    return unicode_to_gid.in_error () ||
125
0
     gid_to_unicodes.in_error () ||
126
0
     unicodes.in_error () ||
127
0
     sanitized_table_cache.in_error ();
128
0
  }
129
};
130
131
132
#endif /* HB_SUBSET_ACCELERATOR_HH */