Coverage Report

Created: 2025-07-07 10:01

/work/workdir/UnpackedTarball/harfbuzz/src/hb-paint-extents.hh
Line
Count
Source (jump to first uncovered line)
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
44
0
    transforms.push (hb_transform_t{});
45
0
    clips.push (hb_bounds_t{hb_bounds_t::UNBOUNDED});
46
0
    groups.push (hb_bounds_t{hb_bounds_t::EMPTY});
47
0
  }
48
49
  hb_paint_extents_context_t ()
50
0
  {
51
0
    clear ();
52
0
  }
53
54
  hb_extents_t get_extents ()
55
0
  {
56
0
    return groups.tail().extents;
57
0
  }
58
59
  bool is_bounded ()
60
0
  {
61
0
    return groups.tail().status != hb_bounds_t::UNBOUNDED;
62
0
  }
63
64
  void push_transform (const hb_transform_t &trans)
65
0
  {
66
0
    hb_transform_t t = transforms.tail ();
67
0
    t.multiply (trans);
68
0
    transforms.push (t);
69
0
  }
70
71
  void pop_transform ()
72
0
  {
73
0
    transforms.pop ();
74
0
  }
75
76
  void push_clip (hb_extents_t extents)
77
0
  {
78
    /* Transform extents and push a new clip. */
79
0
    const hb_transform_t &t = transforms.tail ();
80
0
    t.transform_extents (extents);
81
82
0
    auto bounds = hb_bounds_t {extents};
83
0
    bounds.intersect (clips.tail ());
84
85
0
    clips.push (bounds);
86
0
  }
87
88
  void pop_clip ()
89
0
  {
90
0
    clips.pop ();
91
0
  }
92
93
  void push_group ()
94
0
  {
95
0
    groups.push (hb_bounds_t {hb_bounds_t::EMPTY});
96
0
  }
97
98
  void pop_group (hb_paint_composite_mode_t mode)
99
0
  {
100
0
    const hb_bounds_t src_bounds = groups.pop ();
101
0
    hb_bounds_t &backdrop_bounds = groups.tail ();
102
103
    // https://learn.microsoft.com/en-us/typography/opentype/spec/colr#format-32-paintcomposite
104
0
    switch ((int) mode)
105
0
    {
106
0
      case HB_PAINT_COMPOSITE_MODE_CLEAR:
107
0
  backdrop_bounds.status = hb_bounds_t::EMPTY;
108
0
  break;
109
0
      case HB_PAINT_COMPOSITE_MODE_SRC:
110
0
      case HB_PAINT_COMPOSITE_MODE_SRC_OUT:
111
0
  backdrop_bounds = src_bounds;
112
0
  break;
113
0
      case HB_PAINT_COMPOSITE_MODE_DEST:
114
0
      case HB_PAINT_COMPOSITE_MODE_DEST_OUT:
115
0
  break;
116
0
      case HB_PAINT_COMPOSITE_MODE_SRC_IN:
117
0
      case HB_PAINT_COMPOSITE_MODE_DEST_IN:
118
0
  backdrop_bounds.intersect (src_bounds);
119
0
  break;
120
0
      default:
121
0
  backdrop_bounds.union_ (src_bounds);
122
0
  break;
123
0
     }
124
0
  }
125
126
  void paint ()
127
0
  {
128
0
    const hb_bounds_t &clip = clips.tail ();
129
0
    hb_bounds_t &group = groups.tail ();
130
131
0
    group.union_ (clip);
132
0
  }
133
134
  protected:
135
  hb_vector_t<hb_transform_t> transforms;
136
  hb_vector_t<hb_bounds_t> clips;
137
  hb_vector_t<hb_bounds_t> groups;
138
};
139
140
HB_INTERNAL hb_paint_funcs_t *
141
hb_paint_extents_get_funcs ();
142
143
144
#endif /* HB_PAINT_EXTENTS_HH */