Debian Codegraph @

thirdparty/thorvg/src/renderer/tvgFill.h

raw symbols SCIP
1 /*
2 * Copyright (c) 2020 - 2024 the ThorVG project. All rights reserved.
3
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10
11 * The above copyright notice and this permission notice shall be included in all
12 * copies or substantial portions of the Software.
13
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 */
22
23 #ifndef _TVG_FILL_H_
24 #define _TVG_FILL_H_
25
26 #include <cstdlib>
27 #include <cstring>
28 #include "tvgCommon.h"
29
30 template<typename T>
31 struct DuplicateMethod
32 {
33 virtual ~DuplicateMethod() {}
34 virtual T* duplicate() = 0;
35 };
36
37 template<class T>
38 struct FillDup : DuplicateMethod<Fill>
39 {
40 T* inst = nullptr;
41
42 FillDup(T* _inst) : inst(_inst) {}
43 ~FillDup() {}
44
45 Fill* duplicate() override
46 {
47 return inst->duplicate();
48 }
49 };
50
51 struct Fill::Impl
52 {
53 ColorStop* colorStops = nullptr;
54 Matrix* transform = nullptr;
55 uint32_t cnt = 0;
56 FillSpread spread;
57 DuplicateMethod<Fill>* dup = nullptr;
58
59 ~Impl()
60 {
61 delete(dup);
62 free(colorStops);
63 free(transform);
64 }
65
66 void method(DuplicateMethod<Fill>* dup)
67 {
68 this->dup = dup;
69 }
70
71 Fill* duplicate()
72 {
73 auto ret = dup->duplicate();
74 if (!ret) return nullptr;
75
76 ret->pImpl->cnt = cnt;
77 ret->pImpl->spread = spread;
78 ret->pImpl->colorStops = static_cast<ColorStop*>(malloc(sizeof(ColorStop) * cnt));
79 if (cnt > 0) memcpy(ret->pImpl->colorStops, colorStops, sizeof(ColorStop) * cnt);
80 if (transform) {
81 ret->pImpl->transform = static_cast<Matrix*>(malloc(sizeof(Matrix)));
82 *ret->pImpl->transform = *transform;
83 }
84 return ret;
85 }
86 };
87
88
89 struct RadialGradient::Impl
90 {
91 float cx = 0.0f, cy = 0.0f;
92 float fx = 0.0f, fy = 0.0f;
93 float r = 0.0f, fr = 0.0f;
94
95 Fill* duplicate();
96 Result radial(float cx, float cy, float r, float fx, float fy, float fr);
97 };
98
99
100 struct LinearGradient::Impl
101 {
102 float x1 = 0.0f;
103 float y1 = 0.0f;
104 float x2 = 0.0f;
105 float y2 = 0.0f;
106
107 Fill* duplicate();
108 };
109
110
111 #endif //_TVG_FILL_H_