Coverage Report

Created: 2025-07-23 07:04

/src/harfbuzz/src/hb-paint-bounded.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_BOUNDED_HH
26
#define HB_PAINT_BOUNDED_HH
27
28
#include "hb.hh"
29
#include "hb-paint.h"
30
31
#include "hb-geometry.hh"
32
33
34
typedef struct  hb_paint_bounded_context_t hb_paint_bounded_context_t;
35
36
struct hb_paint_bounded_context_t
37
{
38
  void clear ()
39
7.15k
  {
40
7.15k
    clips = 0;
41
7.15k
    bounded = true;
42
7.15k
    groups.clear ();
43
7.15k
  }
44
45
  hb_paint_bounded_context_t ()
46
0
  {
47
0
    clear ();
48
0
  }
49
50
  bool is_bounded ()
51
7.15k
  {
52
7.15k
    return bounded;
53
7.15k
  }
54
55
  void push_clip ()
56
64.3k
  {
57
64.3k
    clips++;
58
64.3k
  }
59
60
  void pop_clip ()
61
64.3k
  {
62
64.3k
    if (clips == 0) return;
63
64.3k
    clips--;
64
64.3k
  }
65
66
  void push_group ()
67
614k
  {
68
614k
    groups.push (bounded);
69
614k
    bounded = true;
70
614k
  }
71
72
  void pop_group (hb_paint_composite_mode_t mode)
73
614k
  {
74
614k
    const bool src_bounded = bounded;
75
614k
    bounded = groups.pop ();
76
614k
    bool &backdrop_bounded = bounded;
77
78
    // https://learn.microsoft.com/en-us/typography/opentype/spec/colr#format-32-paintcomposite
79
614k
    switch ((int) mode)
80
614k
    {
81
7.43k
      case HB_PAINT_COMPOSITE_MODE_CLEAR:
82
7.43k
  backdrop_bounded = true;
83
7.43k
  break;
84
1.82k
      case HB_PAINT_COMPOSITE_MODE_SRC:
85
2.66k
      case HB_PAINT_COMPOSITE_MODE_SRC_OUT:
86
2.66k
  backdrop_bounded = src_bounded;
87
2.66k
  break;
88
915
      case HB_PAINT_COMPOSITE_MODE_DEST:
89
1.27k
      case HB_PAINT_COMPOSITE_MODE_DEST_OUT:
90
1.27k
  break;
91
2.70k
      case HB_PAINT_COMPOSITE_MODE_SRC_IN:
92
4.47k
      case HB_PAINT_COMPOSITE_MODE_DEST_IN:
93
4.47k
  backdrop_bounded = backdrop_bounded && src_bounded;
94
4.47k
  break;
95
598k
      default:
96
598k
  backdrop_bounded = backdrop_bounded || src_bounded;
97
598k
  break;
98
614k
     }
99
614k
  }
100
101
  void paint ()
102
82.2k
  {
103
82.2k
    if (!clips)
104
29.1k
      bounded = false;
105
82.2k
  }
106
107
  protected:
108
  bool bounded; // true if current drawing bounded
109
  unsigned clips; // number of active clips
110
  hb_vector_t<bool> groups; // true if group bounded
111
};
112
113
HB_INTERNAL hb_paint_funcs_t *
114
hb_paint_bounded_get_funcs ();
115
116
117
#endif /* HB_PAINT_BOUNDED_HH */