Coverage Report

Created: 2026-09-28 10:59

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/work/workdir/UnpackedTarball/harfbuzz/src/hb-paint-extents.hh
Line
Count
Source
1
/*
2
 * Copyright © 2022 Behdad Esfahbod
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
25
#ifndef HB_PAINT_EXTENTS_HH
26
#define HB_PAINT_EXTENTS_HH
27
28
#include "hb.hh"
29
#include "hb-paint.h"
30
31
#include "hb-geometry.hh"
32
33
34
typedef struct  hb_paint_extents_context_t hb_paint_extents_context_t;
35
36
struct hb_paint_extents_context_t
37
{
38
  void clear ()
39
0
  {
40
0
    transforms.clear ();
41
0
    clips.clear ();
42
0
    groups.clear ();
43
    /* COLR scratch storage is zero-allocated and reused without running
44
     * constructors.  Distinguish that state from an explicitly requested
45
     * zero budget. */
46
0
    if (unlikely (!budget_initialized))
47
0
    {
48
0
      budget = HB_BUDGET_DEFAULT;
49
0
      budget_initialized = true;
50
0
    }
51
0
    recharge_budget ();
52
53
0
    transforms.push (hb_transform_t<>{});
54
0
    clips.push (hb_bounds_t<>{hb_bounds_t<>::UNBOUNDED});
55
0
    groups.push (hb_bounds_t<>{hb_bounds_t<>::EMPTY});
56
0
  }
57
58
  hb_paint_extents_context_t ()
59
0
  {
60
0
    clear ();
61
0
  }
62
63
  hb_extents_t<> get_extents ()
64
0
  {
65
0
    return groups.tail().extents;
66
0
  }
67
68
  bool is_bounded ()
69
0
  {
70
0
    return groups.tail().status != hb_bounds_t<>::UNBOUNDED;
71
0
  }
72
73
  void push_transform (const hb_transform_t<> &trans)
74
0
  {
75
0
    hb_transform_t<> t = transforms.tail ();
76
0
    t.multiply (trans);
77
0
    transforms.push (t);
78
0
  }
79
80
  void pop_transform ()
81
0
  {
82
0
    transforms.pop ();
83
0
  }
84
85
  void push_clip (hb_extents_t<> extents)
86
0
  {
87
    /* Transform extents and push a new clip. */
88
0
    const hb_transform_t<> &t = transforms.tail ();
89
0
    t.transform_extents (extents);
90
91
0
    auto bounds = hb_bounds_t<> {extents};
92
0
    bounds.intersect (clips.tail ());
93
94
0
    clips.push (bounds);
95
0
  }
96
97
  void pop_clip ()
98
0
  {
99
0
    clips.pop ();
100
0
  }
101
102
  void push_group ()
103
0
  {
104
0
    groups.push (hb_bounds_t<> {hb_bounds_t<>::EMPTY});
105
0
  }
106
107
  void pop_group (hb_paint_composite_mode_t mode)
108
0
  {
109
0
    const hb_bounds_t<> src_bounds = groups.pop ();
110
0
    hb_bounds_t<> &backdrop_bounds = groups.tail ();
111
112
    // https://learn.microsoft.com/en-us/typography/opentype/spec/colr#format-32-paintcomposite
113
0
    switch ((int) mode)
114
0
    {
115
0
      case HB_PAINT_COMPOSITE_MODE_CLEAR:
116
0
  backdrop_bounds.status = hb_bounds_t<>::EMPTY;
117
0
  break;
118
0
      case HB_PAINT_COMPOSITE_MODE_SRC:
119
0
      case HB_PAINT_COMPOSITE_MODE_SRC_OUT:
120
0
  backdrop_bounds = src_bounds;
121
0
  break;
122
0
      case HB_PAINT_COMPOSITE_MODE_DEST:
123
0
      case HB_PAINT_COMPOSITE_MODE_DEST_OUT:
124
0
  break;
125
0
      case HB_PAINT_COMPOSITE_MODE_SRC_IN:
126
0
      case HB_PAINT_COMPOSITE_MODE_DEST_IN:
127
0
  backdrop_bounds.intersect (src_bounds);
128
0
  break;
129
0
      default:
130
0
  backdrop_bounds.union_ (src_bounds);
131
0
  break;
132
0
     }
133
0
  }
134
135
  void paint ()
136
0
  {
137
0
    const hb_bounds_t<> &clip = clips.tail ();
138
0
    hb_bounds_t<> &group = groups.tail ();
139
140
0
    group.union_ (clip);
141
0
  }
142
143
  /* Cumulative work budget for the current session; reset by clear().
144
   * Outline traversal and consumed segments charge the same live
145
   * counter. */
146
  int64_t budget = HB_BUDGET_DEFAULT;
147
  bool budget_initialized = true;
148
  int64_t budget_remaining = HB_BUDGET_GLYPH;
149
150
  void recharge_budget ()
151
0
  {
152
0
    budget_remaining = budget == HB_BUDGET_DEFAULT ?
153
0
           HB_BUDGET_GLYPH : budget;
154
0
  }
155
156
  protected:
157
  hb_vector_t<hb_transform_t<>> transforms;
158
  hb_vector_t<hb_bounds_t<>> clips;
159
  hb_vector_t<hb_bounds_t<>> groups;
160
};
161
162
HB_INTERNAL hb_paint_funcs_t *
163
hb_paint_extents_get_funcs ();
164
165
166
#endif /* HB_PAINT_EXTENTS_HH */