From 8e12c755d1d16249de2b951de97187e96963e0dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Tue, 17 May 2022 16:32:20 +0200 Subject: [PATCH] nanosvg: Sync with upstream 4c8f013 --- thirdparty/README.md | 9 ++++++--- thirdparty/nanosvg/nanosvg.cc | 3 --- thirdparty/nanosvg/nanosvg.h | 6 ++++-- thirdparty/nanosvg/nanosvgrast.h | 10 +++++++--- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/thirdparty/README.md b/thirdparty/README.md index 3401b9db9bb..f28e208e133 100644 --- a/thirdparty/README.md +++ b/thirdparty/README.md @@ -392,13 +392,16 @@ Collection of single-file libraries used in Godot components. ## nanosvg - Upstream: https://github.com/memononen/nanosvg -- Version: git (ccdb1995134d340a93fb20e3a3d323ccb3838dd0, 2021) +- Version: git (4c8f0139b62c6e7faa3b67ce1fbe6e63590ed148, 2022) - License: zlib Files extracted from the upstream source: -- All .h files in `src/` -- LICENSE.txt +- All `.h` files in `src/` +- `LICENSE.txt` + +`nanosvg.cc` is a custom file added to configure the build of the header only +library. ## oidn diff --git a/thirdparty/nanosvg/nanosvg.cc b/thirdparty/nanosvg/nanosvg.cc index 3e8e86c7922..584be53bf56 100644 --- a/thirdparty/nanosvg/nanosvg.cc +++ b/thirdparty/nanosvg/nanosvg.cc @@ -1,6 +1,3 @@ -#include "stdio.h" -#include "string.h" -#include "math.h" #define NANOSVG_ALL_COLOR_KEYWORDS #define NANOSVG_IMPLEMENTATION #include "nanosvg.h" diff --git a/thirdparty/nanosvg/nanosvg.h b/thirdparty/nanosvg/nanosvg.h index f5058b179a2..0c586161609 100644 --- a/thirdparty/nanosvg/nanosvg.h +++ b/thirdparty/nanosvg/nanosvg.h @@ -187,6 +187,7 @@ void nsvgDelete(NSVGimage* image); #include #include +#include #include #define NSVG_PI (3.14159265358979323846264338327f) @@ -1226,10 +1227,11 @@ static unsigned int nsvg__parseColorHex(const char* str) static unsigned int nsvg__parseColorRGB(const char* str) { unsigned int r=0, g=0, b=0; + float rf=0, gf=0, bf=0; if (sscanf(str, "rgb(%u, %u, %u)", &r, &g, &b) == 3) // decimal integers return NSVG_RGB(r, g, b); - if (sscanf(str, "rgb(%u%%, %u%%, %u%%)", &r, &g, &b) == 3) // decimal integer percentage - return NSVG_RGB(r*255/100, g*255/100, b*255/100); + if (sscanf(str, "rgb(%f%%, %f%%, %f%%)", &rf, &gf, &bf) == 3) // decimal integer percentage + return NSVG_RGB(roundf(rf*2.55f), roundf(gf*2.55f), roundf(bf*2.55f)); // (255 / 100.0f) return NSVG_RGB(128, 128, 128); } diff --git a/thirdparty/nanosvg/nanosvgrast.h b/thirdparty/nanosvg/nanosvgrast.h index b740c316ca2..029043e6eb3 100644 --- a/thirdparty/nanosvg/nanosvgrast.h +++ b/thirdparty/nanosvg/nanosvgrast.h @@ -77,6 +77,8 @@ void nsvgDeleteRasterizer(NSVGrasterizer*); #ifdef NANOSVGRAST_IMPLEMENTATION #include +#include +#include #define NSVG__SUBSAMPLES 5 #define NSVG__FIXSHIFT 10 @@ -956,7 +958,7 @@ static float nsvg__clampf(float a, float mn, float mx) { return a < mn ? mn : (a static unsigned int nsvg__RGBA(unsigned char r, unsigned char g, unsigned char b, unsigned char a) { - return (r) | (g << 8) | (b << 16) | (a << 24); + return ((unsigned int)r) | ((unsigned int)g << 8) | ((unsigned int)b << 16) | ((unsigned int)a << 24); } static unsigned int nsvg__lerpRGBA(unsigned int c0, unsigned int c1, float u) @@ -1406,7 +1408,8 @@ void nsvgRasterize(NSVGrasterizer* r, } // Rasterize edges - qsort(r->edges, r->nedges, sizeof(NSVGedge), nsvg__cmpEdge); + if (r->nedges != 0) + qsort(r->edges, r->nedges, sizeof(NSVGedge), nsvg__cmpEdge); // now, traverse the scanlines and find the intersections on each scanline, use non-zero rule nsvg__initPaint(&cache, &shape->fill, shape->opacity); @@ -1432,7 +1435,8 @@ void nsvgRasterize(NSVGrasterizer* r, } // Rasterize edges - qsort(r->edges, r->nedges, sizeof(NSVGedge), nsvg__cmpEdge); + if (r->nedges != 0) + qsort(r->edges, r->nedges, sizeof(NSVGedge), nsvg__cmpEdge); // now, traverse the scanlines and find the intersections on each scanline, use non-zero rule nsvg__initPaint(&cache, &shape->stroke, shape->opacity);