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 #include "../../lv_conf_internal.h" 24 #if LV_USE_THORVG_INTERNAL 25 26 #ifndef _TVG_COMMON_H_ 27 #define _TVG_COMMON_H_ 28 29 #include "config.h" 30 #include "thorvg.h" 31 32 using namespace std; 33 using namespace tvg; 34 35 //for MSVC Compat 36 #ifdef _MSC_VER 37 #define TVG_UNUSED 38 #define strncasecmp _strnicmp 39 #define strcasecmp _stricmp 40 #else 41 #define TVG_UNUSED __attribute__ ((__unused__)) 42 #endif 43 44 // Portable 'fallthrough' attribute 45 #if __has_cpp_attribute(fallthrough) 46 #ifdef _MSC_VER 47 #define TVG_FALLTHROUGH [[fallthrough]]; 48 #else 49 #define TVG_FALLTHROUGH __attribute__ ((fallthrough)); 50 #endif 51 #else 52 #define TVG_FALLTHROUGH 53 #endif 54 55 #if defined(_MSC_VER) && defined(__clang__) 56 #define strncpy strncpy_s 57 #define strdup _strdup 58 #endif 59 60 enum class FileType { Png = 0, Jpg, Webp, Tvg, Svg, Lottie, Ttf, Raw, Gif, Unknown }; 61 62 using Size = Point; 63 64 #ifdef THORVG_LOG_ENABLED 65 constexpr auto ErrorColor = "\033[31m"; //red 66 constexpr auto ErrorBgColor = "\033[41m";//bg red 67 constexpr auto LogColor = "\033[32m"; //green 68 constexpr auto LogBgColor = "\033[42m"; //bg green 69 constexpr auto GreyColor = "\033[90m"; //grey 70 constexpr auto ResetColors = "\033[0m"; //default 71 #define TVGERR(tag, fmt, ...) fprintf(stderr, "%s[E]%s %s" tag "%s (%s %d): %s" fmt "\n", ErrorBgColor, ResetColors, ErrorColor, GreyColor, __FILE__, __LINE__, ResetColors, ##__VA_ARGS__) 72 #define TVGLOG(tag, fmt, ...) fprintf(stdout, "%s[L]%s %s" tag "%s (%s %d): %s" fmt "\n", LogBgColor, ResetColors, LogColor, GreyColor, __FILE__, __LINE__, ResetColors, ##__VA_ARGS__) 73 #else 74 #define TVGERR(...) do {} while(0) 75 #define TVGLOG(...) do {} while(0) 76 #endif 77 78 uint16_t THORVG_VERSION_NUMBER(); 79 80 81 #define P(A) ((A)->pImpl) //Access to pimpl. 82 #define PP(A) (((Paint*)(A))->pImpl) //Access to pimpl. 83 84 85 //for debugging 86 #if 0 87 #include <sys/time.h> 88 static inline double THORVG_TIMESTAMP() 89 { 90 struct timeval tv; 91 gettimeofday(&tv, NULL); 92 return (tv.tv_sec + tv.tv_usec / 1000000.0); 93 } 94 #endif 95 96 #endif //_TVG_COMMON_H_ 97 98 #endif /* LV_USE_THORVG_INTERNAL */ 99 100