Changes to support MSVC
authorProjectitis <peter@projectitis.com>
Wed, 29 Sep 2021 02:08:43 +0000 (15:08 +1300)
committerJunsuChoi <jsuya.choi@samsung.com>
Tue, 5 Oct 2021 03:01:23 +0000 (12:01 +0900)
src/bindings/capi/thorvg_capi.h
src/loaders/tvg/tvgTvgBinInterpreter.cpp
src/savers/tvg/tvgTvgSaver.cpp
test/capi/capiLinearGradient.cpp
test/capi/capiRadialGradient.cpp

index ea57c1a..e8dbe1e 100644 (file)
 #endif
 
 #ifdef TVG_BUILD
-    #define TVG_EXPORT __attribute__ ((visibility ("default")))
+    #ifdef _WIN32
+        #define TVG_EXPORT __declspec(dllexport)
+    #else
+        #define TVG_EXPORT __attribute__ ((visibility ("default")))
+    #endif
 #else
     #define TVG_EXPORT
 #endif
 
-
 #ifdef __cplusplus
 extern "C" {
 #endif
index 6dc2043..62d01b2 100644 (file)
  * SOFTWARE.
  */
 #include <memory.h>
+
+#ifdef _WIN32
+    #include <malloc.h>
+#else
+    #include <alloca.h>
+#endif
+
 #include "tvgTvgCommon.h"
 
 
@@ -139,7 +146,7 @@ static bool _parseShapePath(const char *ptr, const char *end, Shape *shape)
     if (ptr > end) return false;
 
     /* Recover to PathCommand(4 bytes) from TvgBinFlag(1 byte) */
-    PathCommand inCmds[cmdCnt];
+    PathCommand* inCmds = (PathCommand*)alloca(sizeof(PathCommand) * cmdCnt);
     for (uint32_t i = 0; i < cmdCnt; ++i) {
         inCmds[i] = static_cast<PathCommand>(cmds[i]);
     }
@@ -206,7 +213,7 @@ static unique_ptr<Fill> _parseShapeFill(const char *ptr, const char *end)
                 if (block.length == 0 || block.length & 0x07) return nullptr;
                 uint32_t stopsCnt = block.length >> 3; // 8 bytes per ColorStop
                 if (stopsCnt > 1023) return nullptr;
-                Fill::ColorStop stops[stopsCnt];
+                Fill::ColorStop* stops = (Fill::ColorStop*)alloca(sizeof(Fill::ColorStop) * stopsCnt);
                 auto p = block.data;
                 for (uint32_t i = 0; i < stopsCnt; i++, p += 8) {
                     READ_FLOAT(&stops[i].offset, p);
index 2d37319..4c97966 100644 (file)
 #include "tvgTvgSaver.h"
 #include "tvgLzw.h"
 
+#ifdef _WIN32
+    #include <malloc.h>
+#else
+    #include <alloca.h>
+#endif
+
 #define SIZE(A) sizeof(A)
 
 /************************************************************************/
@@ -497,7 +503,7 @@ TvgBinCounter TvgSaver::serializePath(const Shape* shape, const Matrix* transfor
 
     /* Reduce the binary size.
        Convert PathCommand(4 bytes) to TvgBinFlag(1 byte) */
-    TvgBinFlag outCmds[cmdCnt];
+    TvgBinFlag* outCmds = (TvgBinFlag*)alloca(SIZE(TvgBinFlag) * cmdCnt);
     for (uint32_t i = 0; i < cmdCnt; ++i) {
         outCmds[i] = static_cast<TvgBinFlag>(cmds[i]);
     }
index f5d2a25..5c21b2a 100644 (file)
@@ -78,8 +78,8 @@ TEST_CASE("Linear Gradient color stops", "[capiLinearGradient]")
 
     Tvg_Color_Stop color_stops[2] =
     {
-        {.offset=0.0, .r=0, .g=0,   .b=0, .a=255},
-        {.offset=1,   .r=0, .g=255, .b=0, .a=255},
+        {0.0, 0, 0,   0, 255},
+        {1.0, 0, 255, 0, 255},
     };
 
     const Tvg_Color_Stop *color_stops_ret;
@@ -105,8 +105,8 @@ TEST_CASE("Linear Gradient clear data", "[capiLinearGradient]")
 
     Tvg_Color_Stop color_stops[2] =
     {
-        {.offset=0.0, .r=0, .g=0,   .b=0, .a=255},
-        {.offset=1,   .r=0, .g=255, .b=0, .a=255},
+        {0.0, 0, 0,   0, 255},
+        {1.0, 0, 255, 0, 255},
     };
 
     const Tvg_Color_Stop *color_stops_ret = NULL;
@@ -150,8 +150,8 @@ TEST_CASE("Stroke Linear Gradient", "[capiLinearGradient]")
 
     Tvg_Color_Stop color_stops[2] =
     {
-        {.offset=0.0, .r=0, .g=0,   .b=0, .a=255},
-        {.offset=1,   .r=0, .g=255, .b=0, .a=255},
+        {0.0, 0, 0,   0, 255},
+        {1.0, 0, 255, 0, 255},
     };
 
     Tvg_Gradient *gradient_ret = NULL;
index ca31721..09bcefd 100644 (file)
@@ -75,8 +75,8 @@ TEST_CASE("Set/Get color stops", "[capiRadialGradient]")
     REQUIRE(gradient);
 
     Tvg_Color_Stop color_stops[2] = {
-        {.offset=0.0, .r=0, .g=0,   .b=0, .a=255},
-        {.offset=1,   .r=0, .g=255, .b=0, .a=255},
+        {0.0, 0, 0,   0, 255},
+        {1.0, 0, 255, 0, 255},
     };
 
     const Tvg_Color_Stop *color_stops_ret;
@@ -102,8 +102,8 @@ TEST_CASE("Clear gradient data", "[capiRadialGradient]")
     REQUIRE(gradient);
 
     Tvg_Color_Stop color_stops[2] = {
-        {.offset=0.0, .r=0, .g=0,   .b=0, .a=255},
-        {.offset=1,   .r=0, .g=255, .b=0, .a=255},
+        {0.0, 0, 0,   0, 255},
+        {1.0, 0, 255, 0, 255},
     };
 
     const Tvg_Color_Stop *color_stops_ret;
@@ -148,10 +148,9 @@ TEST_CASE("Stroke Radial Gradient", "[capiRadialGradient]")
 
     REQUIRE(tvg_radial_gradient_set(gradient, 10.0, 15.0, 30.0) == TVG_RESULT_SUCCESS);
 
-    Tvg_Color_Stop color_stops[2] =
-    {
-        {.offset=0.0, .r=0, .g=0,   .b=0, .a=255},
-        {.offset=1,   .r=0, .g=255, .b=0, .a=255},
+    Tvg_Color_Stop color_stops[2] = {
+        {0.0, 0, 0,   0, 255},
+        {1.0, 0, 255, 0, 255},
     };
 
     Tvg_Gradient *gradient_ret = NULL;