From 93739df7cf41e2d05aaca80dca6f4de1c58eaa31 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 31125985a..5314f3ebb 100644 --- a/thirdparty/README.md +++ b/thirdparty/README.md @@ -329,13 +329,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 3e8e86c79..584be53bf 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 78fbe78a0..be3fc7f28 100644 --- a/thirdparty/nanosvg/nanosvg.h +++ b/thirdparty/nanosvg/nanosvg.h @@ -189,6 +189,7 @@ void nsvgDelete(NSVGimage* image); #include #include +#include #include #define NSVG_PI (3.14159265358979323846264338327f) @@ -1228,10 +1229,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 a0f3d2a98..12e2cba29 100644 --- a/thirdparty/nanosvg/nanosvgrast.h +++ b/thirdparty/nanosvg/nanosvgrast.h @@ -79,6 +79,8 @@ void nsvgDeleteRasterizer(NSVGrasterizer*); #ifdef NANOSVGRAST_IMPLEMENTATION #include +#include +#include #define NSVG__SUBSAMPLES 5 #define NSVG__FIXSHIFT 10 @@ -958,7 +960,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) @@ -1408,7 +1410,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); @@ -1434,7 +1437,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);