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