example: just renamed the svg file.
[platform/core/graphics/tizenvg.git] / src / lib / tvgPicture.cpp
1 /*
2  * Copyright (c) 2020 - 2022 Samsung Electronics Co., Ltd. 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 "tvgPictureImpl.h"
24
25 /************************************************************************/
26 /* External Class Implementation                                        */
27 /************************************************************************/
28
29 Picture::Picture() : pImpl(new Impl)
30 {
31     Paint::pImpl->id = TVG_CLASS_ID_PICTURE;
32     Paint::pImpl->method(new PaintMethod<Picture::Impl>(pImpl));
33 }
34
35
36 Picture::~Picture()
37 {
38     delete(pImpl);
39 }
40
41
42 unique_ptr<Picture> Picture::gen() noexcept
43 {
44     return unique_ptr<Picture>(new Picture);
45 }
46
47
48 uint32_t Picture::identifier() noexcept
49 {
50     return TVG_CLASS_ID_PICTURE;
51 }
52
53
54 Result Picture::load(const std::string& path) noexcept
55 {
56     if (path.empty()) return Result::InvalidArguments;
57
58     return pImpl->load(path);
59 }
60
61
62 Result Picture::load(const char* data, uint32_t size, const string& mimeType, bool copy) noexcept
63 {
64     if (!data || size <= 0) return Result::InvalidArguments;
65
66     return pImpl->load(data, size, mimeType, copy);
67 }
68
69
70 TVG_DEPRECATED Result Picture::load(const char* data, uint32_t size, bool copy) noexcept
71 {
72     return load(data, size, "", copy);
73 }
74
75
76 Result Picture::load(uint32_t* data, uint32_t w, uint32_t h, bool copy) noexcept
77 {
78     if (!data || w <= 0 || h <= 0) return Result::InvalidArguments;
79
80     return pImpl->load(data, w, h, copy);
81 }
82
83
84 Result Picture::viewbox(float* x, float* y, float* w, float* h) const noexcept
85 {
86     if (pImpl->viewbox(x, y, w, h)) return Result::Success;
87     return Result::InsufficientCondition;
88 }
89
90
91 Result Picture::size(float w, float h) noexcept
92 {
93     if (pImpl->size(w, h)) return Result::Success;
94     return Result::InsufficientCondition;
95 }
96
97
98 Result Picture::size(float* w, float* h) const noexcept
99 {
100     if (!pImpl->loader) return Result::InsufficientCondition;
101     if (w) *w = pImpl->w;
102     if (h) *h = pImpl->h;
103     return Result::Success;
104 }
105
106
107 const uint32_t* Picture::data(uint32_t* w, uint32_t* h) const noexcept
108 {
109     //Try it, If not loaded yet.
110     pImpl->reload();
111
112     if (pImpl->loader) {
113         if (w) *w = static_cast<uint32_t>(pImpl->loader->w);
114         if (h) *h = static_cast<uint32_t>(pImpl->loader->h);
115     } else {
116         if (w) *w = 0;
117         if (h) *h = 0;
118     }
119     if (pImpl->surface) return pImpl->surface->buffer;
120     else return nullptr;
121 }