/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 | 0 | { |
40 | 0 | clips = 0; |
41 | 0 | bounded = true; |
42 | 0 | groups.clear (); |
43 | 0 | } |
44 | | |
45 | | hb_paint_bounded_context_t () |
46 | 0 | { |
47 | 0 | clear (); |
48 | 0 | } |
49 | | |
50 | | bool is_bounded () |
51 | 0 | { |
52 | 0 | return bounded; |
53 | 0 | } |
54 | | |
55 | | void push_clip () |
56 | 0 | { |
57 | 0 | clips++; |
58 | 0 | } |
59 | | |
60 | | void pop_clip () |
61 | 0 | { |
62 | 0 | if (clips == 0) return; |
63 | 0 | clips--; |
64 | 0 | } |
65 | | |
66 | | void push_group () |
67 | 0 | { |
68 | 0 | groups.push (bounded); |
69 | 0 | bounded = true; |
70 | 0 | } |
71 | | |
72 | | void pop_group (hb_paint_composite_mode_t mode) |
73 | 0 | { |
74 | 0 | const bool src_bounded = bounded; |
75 | 0 | bounded = groups.pop (); |
76 | 0 | bool &backdrop_bounded = bounded; |
77 | | |
78 | | // https://learn.microsoft.com/en-us/typography/opentype/spec/colr#format-32-paintcomposite |
79 | 0 | switch ((int) mode) |
80 | 0 | { |
81 | 0 | case HB_PAINT_COMPOSITE_MODE_CLEAR: |
82 | 0 | backdrop_bounded = true; |
83 | 0 | break; |
84 | 0 | case HB_PAINT_COMPOSITE_MODE_SRC: |
85 | 0 | case HB_PAINT_COMPOSITE_MODE_SRC_OUT: |
86 | 0 | backdrop_bounded = src_bounded; |
87 | 0 | break; |
88 | 0 | case HB_PAINT_COMPOSITE_MODE_DEST: |
89 | 0 | case HB_PAINT_COMPOSITE_MODE_DEST_OUT: |
90 | 0 | break; |
91 | 0 | case HB_PAINT_COMPOSITE_MODE_SRC_IN: |
92 | 0 | case HB_PAINT_COMPOSITE_MODE_DEST_IN: |
93 | 0 | backdrop_bounded = backdrop_bounded && src_bounded; |
94 | 0 | break; |
95 | 0 | default: |
96 | 0 | backdrop_bounded = backdrop_bounded || src_bounded; |
97 | 0 | break; |
98 | 0 | } |
99 | 0 | } |
100 | | |
101 | | void paint () |
102 | 0 | { |
103 | 0 | if (!clips) |
104 | 0 | bounded = false; |
105 | 0 | } |
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 */ |