1/*
2 * Copyright (c) 2020 - 2023 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#include "tvgFill.h"
24
25/************************************************************************/
26/* Internal Class Implementation */
27/************************************************************************/
28
29
30/************************************************************************/
31/* External Class Implementation */
32/************************************************************************/
33
34Fill::Fill():pImpl(new Impl())
35{
36}
37
38
39Fill::~Fill()
40{
41 delete(pImpl);
42}
43
44
45Result Fill::colorStops(const ColorStop* colorStops, uint32_t cnt) noexcept
46{
47 if ((!colorStops && cnt > 0) || (colorStops && cnt == 0)) return Result::InvalidArguments;
48
49 if (cnt == 0) {
50 if (pImpl->colorStops) {
51 free(pImpl->colorStops);
52 pImpl->colorStops = nullptr;
53 pImpl->cnt = 0;
54 }
55 return Result::Success;
56 }
57
58 if (pImpl->cnt != cnt) {
59 pImpl->colorStops = static_cast<ColorStop*>(realloc(pImpl->colorStops, cnt * sizeof(ColorStop)));
60 }
61
62 pImpl->cnt = cnt;
63 memcpy(pImpl->colorStops, colorStops, cnt * sizeof(ColorStop));
64
65 return Result::Success;
66}
67
68
69uint32_t Fill::colorStops(const ColorStop** colorStops) const noexcept
70{
71 if (colorStops) *colorStops = pImpl->colorStops;
72
73 return pImpl->cnt;
74}
75
76
77Result Fill::spread(FillSpread s) noexcept
78{
79 pImpl->spread = s;
80
81 return Result::Success;
82}
83
84
85FillSpread Fill::spread() const noexcept
86{
87 return pImpl->spread;
88}
89
90
91Result Fill::transform(const Matrix& m) noexcept
92{
93 if (!pImpl->transform) {
94 pImpl->transform = static_cast<Matrix*>(malloc(sizeof(Matrix)));
95 }
96 *pImpl->transform = m;
97 return Result::Success;
98}
99
100
101Matrix Fill::transform() const noexcept
102{
103 if (pImpl->transform) return *pImpl->transform;
104 return {1, 0, 0, 0, 1, 0, 0, 0, 1};
105}
106
107
108Fill* Fill::duplicate() const noexcept
109{
110 return pImpl->duplicate();
111}
112
113uint32_t Fill::identifier() const noexcept
114{
115 return pImpl->id;
116}
117