Procházet zdrojové kódy

Update to nanosvg 706eb06

Brucey před 1 rokem
rodič
revize
5f4cec5c3b

+ 1 - 1
svg.mod/common.bmx

@@ -1,4 +1,4 @@
-' Copyright (c) 2022 Bruce A Henderson
+' Copyright (c) 2022-2023 Bruce A Henderson
 ' 
 ' 
 ' This software is provided 'as-is', without any express or implied
 ' This software is provided 'as-is', without any express or implied
 ' warranty. In no event will the authors be held liable for any damages
 ' warranty. In no event will the authors be held liable for any damages

+ 1 - 1
svg.mod/glue.c

@@ -1,5 +1,5 @@
 /*
 /*
-  Copyright (c) 2022 Bruce A Henderson
+  Copyright (c) 2022-2023 Bruce A Henderson
   
   
   This software is provided 'as-is', without any express or implied
   This software is provided 'as-is', without any express or implied
   warranty. In no event will the authors be held liable for any damages
   warranty. In no event will the authors be held liable for any damages

+ 75 - 0
svg.mod/nanosvg/CMakeLists.txt

@@ -0,0 +1,75 @@
+cmake_minimum_required(VERSION 3.10)
+
+project(NanoSVG C)
+
+# CMake needs *.c files to do something useful
+configure_file(src/nanosvg.h ${CMAKE_CURRENT_BINARY_DIR}/nanosvg.c)
+configure_file(src/nanosvgrast.h ${CMAKE_CURRENT_BINARY_DIR}/nanosvgrast.c)
+
+add_library(nanosvg ${CMAKE_CURRENT_BINARY_DIR}/nanosvg.c)
+
+find_library(MATH_LIBRARY m) # Business as usual
+if(MATH_LIBRARY)
+    target_link_libraries(nanosvg PUBLIC ${MATH_LIBRARY})
+endif()
+
+target_include_directories(nanosvg PUBLIC $<INSTALL_INTERFACE:include/nanosvg>)
+target_compile_definitions(nanosvg PRIVATE NANOSVG_IMPLEMENTATION)
+
+# Same for nanosvgrast
+add_library(nanosvgrast ${CMAKE_CURRENT_BINARY_DIR}/nanosvgrast.c)
+target_link_libraries(nanosvgrast PUBLIC nanosvg)
+target_include_directories(nanosvgrast PRIVATE src)
+target_compile_definitions(nanosvgrast PRIVATE NANOSVGRAST_IMPLEMENTATION)
+
+# Installation and export:
+
+include(CMakePackageConfigHelpers)
+
+write_basic_package_version_file(
+    "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
+    VERSION 1.0
+    COMPATIBILITY AnyNewerVersion
+)
+
+install(TARGETS nanosvg nanosvgrast
+        EXPORT ${PROJECT_NAME}Targets
+)
+
+export(EXPORT ${PROJECT_NAME}Targets 
+       FILE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Targets.cmake" 
+       NAMESPACE ${PROJECT_NAME}::
+)
+
+set(ConfigPackageLocation lib/cmake/${PROJECT_NAME})
+
+configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/Config.cmake.in
+  "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
+  INSTALL_DESTINATION ${ConfigPackageLocation}
+  NO_CHECK_REQUIRED_COMPONENTS_MACRO
+)
+
+install(
+    FILES
+      src/nanosvg.h
+      src/nanosvgrast.h
+    DESTINATION
+      include/nanosvg
+  )
+
+install(EXPORT ${PROJECT_NAME}Targets
+  FILE
+    ${PROJECT_NAME}Targets.cmake
+  NAMESPACE
+    ${PROJECT_NAME}::
+  DESTINATION
+    ${ConfigPackageLocation}
+)
+
+install(
+  FILES
+    "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
+    "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
+  DESTINATION
+    ${ConfigPackageLocation}
+)

+ 5 - 0
svg.mod/nanosvg/Config.cmake.in

@@ -0,0 +1,5 @@
+@PACKAGE_INIT@
+
+if (EXISTS ${CMAKE_CURRENT_LIST_DIR}/NanoSVGTargets.cmake)
+    include("${CMAKE_CURRENT_LIST_DIR}/NanoSVGTargets.cmake")
+endif ()

+ 5 - 4
svg.mod/nanosvg/src/nanosvgrast.h

@@ -331,6 +331,7 @@ static float nsvg__normalize(float *x, float* y)
 }
 }
 
 
 static float nsvg__absf(float x) { return x < 0 ? -x : x; }
 static float nsvg__absf(float x) { return x < 0 ? -x : x; }
+static float nsvg__roundf(float x) { return (x >= 0) ? floorf(x + 0.5) : ceilf(x - 0.5); }
 
 
 static void nsvg__flattenCubicBez(NSVGrasterizer* r,
 static void nsvg__flattenCubicBez(NSVGrasterizer* r,
 								  float x1, float y1, float x2, float y2,
 								  float x1, float y1, float x2, float y2,
@@ -872,10 +873,10 @@ static NSVGactiveEdge* nsvg__addActive(NSVGrasterizer* r, NSVGedge* e, float sta
 //	STBTT_assert(e->y0 <= start_point);
 //	STBTT_assert(e->y0 <= start_point);
 	// round dx down to avoid going too far
 	// round dx down to avoid going too far
 	if (dxdy < 0)
 	if (dxdy < 0)
-		z->dx = (int)(-floorf(NSVG__FIX * -dxdy));
+		z->dx = (int)(-nsvg__roundf(NSVG__FIX * -dxdy));
 	else
 	else
-		z->dx = (int)floorf(NSVG__FIX * dxdy);
-	z->x = (int)floorf(NSVG__FIX * (e->x0 + dxdy * (startPoint - e->y0)));
+		z->dx = (int)nsvg__roundf(NSVG__FIX * dxdy);
+	z->x = (int)nsvg__roundf(NSVG__FIX * (e->x0 + dxdy * (startPoint - e->y0)));
 //	z->x -= off_x * FIX;
 //	z->x -= off_x * FIX;
 	z->ey = e->y1;
 	z->ey = e->y1;
 	z->next = 0;
 	z->next = 0;
@@ -1282,7 +1283,7 @@ static void nsvg__initPaint(NSVGcachedPaint* cache, NSVGpaint* paint, float opac
 	if (grad->nstops == 0) {
 	if (grad->nstops == 0) {
 		for (i = 0; i < 256; i++)
 		for (i = 0; i < 256; i++)
 			cache->colors[i] = 0;
 			cache->colors[i] = 0;
-	} if (grad->nstops == 1) {
+	} else if (grad->nstops == 1) {
 		for (i = 0; i < 256; i++)
 		for (i = 0; i < 256; i++)
 			cache->colors[i] = nsvg__applyOpacity(grad->stops[i].color, opacity);
 			cache->colors[i] = nsvg__applyOpacity(grad->stops[i].color, opacity);
 	} else {
 	} else {

+ 11 - 1
svg.mod/svg.bmx

@@ -1,4 +1,4 @@
-' Copyright (c) 2022 Bruce A Henderson
+' Copyright (c) 2022-2023 Bruce A Henderson
 ' 
 ' 
 ' This software is provided 'as-is', without any express or implied
 ' This software is provided 'as-is', without any express or implied
 ' warranty. In no event will the authors be held liable for any damages
 ' warranty. In no event will the authors be held liable for any damages
@@ -25,6 +25,16 @@ The SVG loader module provides the ability to load SVG format #pixmaps.
 End Rem
 End Rem
 Module Image.SVG
 Module Image.SVG
 
 
+ModuleInfo "Version: 1.01"
+ModuleInfo "Author: 2013-14 Mikko Mononen"
+ModuleInfo "License: ZLib/PNG License"
+ModuleInfo "Credit: Adapted for BlitzMax by Bruce A Henderson"
+
+ModuleInfo "History: 1.01"
+ModuleInfo "History: Update to nanosvg 706eb06"
+ModuleInfo "History: 1.00"
+ModuleInfo "History: Initial Release. nanosvg"
+
 Import BRL.Pixmap
 Import BRL.Pixmap
 
 
 Import "common.bmx"
 Import "common.bmx"