1 /*
2  * Copyright (c) 2023 - 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 #include "../../lv_conf_internal.h"
24 #if LV_USE_THORVG_INTERNAL
25 
26 
27 #include "tvgText.h"
28 
29 
30 /************************************************************************/
31 /* Internal Class Implementation                                        */
32 /************************************************************************/
33 
34 
35 
36 /************************************************************************/
37 /* External Class Implementation                                        */
38 /************************************************************************/
39 
40 
Text()41 Text::Text() : pImpl(new Impl(this))
42 {
43 }
44 
45 
~Text()46 Text::~Text()
47 {
48     delete(pImpl);
49 }
50 
51 
text(const char * text)52 Result Text::text(const char* text) noexcept
53 {
54     return pImpl->text(text);
55 }
56 
57 
font(const char * name,float size,const char * style)58 Result Text::font(const char* name, float size, const char* style) noexcept
59 {
60     return pImpl->font(name, size, style);
61 }
62 
63 
load(const std::string & path)64 Result Text::load(const std::string& path) noexcept
65 {
66     bool invalid; //invalid path
67     if (!LoaderMgr::loader(path, &invalid)) {
68         if (invalid) return Result::InvalidArguments;
69         else return Result::NonSupport;
70     }
71 
72     return Result::Success;
73 }
74 
75 
load(const char * name,const char * data,uint32_t size,const string & mimeType,bool copy)76 Result Text::load(const char* name, const char* data, uint32_t size, const string& mimeType, bool copy) noexcept
77 {
78     if (!name || (size == 0 && data)) return Result::InvalidArguments;
79 
80     //unload font
81     if (!data) {
82         if (LoaderMgr::retrieve(name)) return Result::Success;
83         return Result::InsufficientCondition;
84     }
85 
86     if (!LoaderMgr::loader(name, data, size, mimeType, copy)) return Result::NonSupport;
87     return Result::Success;
88 }
89 
90 
unload(const std::string & path)91 Result Text::unload(const std::string& path) noexcept
92 {
93     if (LoaderMgr::retrieve(path)) return Result::Success;
94     return Result::InsufficientCondition;
95 }
96 
97 
fill(uint8_t r,uint8_t g,uint8_t b)98 Result Text::fill(uint8_t r, uint8_t g, uint8_t b) noexcept
99 {
100     return pImpl->shape->fill(r, g, b);
101 }
102 
103 
fill(unique_ptr<Fill> f)104 Result Text::fill(unique_ptr<Fill> f) noexcept
105 {
106     return pImpl->shape->fill(std::move(f));
107 }
108 
109 
gen()110 unique_ptr<Text> Text::gen() noexcept
111 {
112     return unique_ptr<Text>(new Text);
113 }
114 
115 
type() const116 Type Text::type() const noexcept
117 {
118     return Type::Text;
119 }
120 
121 #endif /* LV_USE_THORVG_INTERNAL */
122 
123