1/*
2 * Copyright (c) 2020 - 2023 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
29using namespace std;
30using 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//TVG class identifier values
58#define TVG_CLASS_ID_UNDEFINED 0
59#define TVG_CLASS_ID_SHAPE 1
60#define TVG_CLASS_ID_SCENE 2
61#define TVG_CLASS_ID_PICTURE 3
62#define TVG_CLASS_ID_LINEAR 4
63#define TVG_CLASS_ID_RADIAL 5
64
65enum class FileType { Tvg = 0, Svg, Lottie, Raw, Png, Jpg, Webp, Unknown };
66
67using Size = Point;
68
69#ifdef THORVG_LOG_ENABLED
70 constexpr auto ErrorColor = "\033[31m"; //red
71 constexpr auto ErrorBgColor = "\033[41m";//bg red
72 constexpr auto LogColor = "\033[32m"; //green
73 constexpr auto LogBgColor = "\033[42m"; //bg green
74 constexpr auto GreyColor = "\033[90m"; //grey
75 constexpr auto ResetColors = "\033[0m"; //default
76 #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__)
77 #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__)
78#else
79 #define TVGERR(...)
80 #define TVGLOG(...)
81#endif
82
83uint16_t THORVG_VERSION_NUMBER();
84
85#endif //_TVG_COMMON_H_
86