Debian Codegraph @

thirdparty/thorvg/src/renderer/tvgCommon.h

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