FLTK logo

[master] 1d43ae0 - Move nanosvg to a separate file, don't use 'roundf()' (#937)

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 All Forums  |  Back to fltk.commit  ]
 
Previous Message ]Next Message ]

[master] 1d43ae0 - Move nanosvg to a separate file, don't use 'roundf()' (#937) "Albrecht Schlosser" 12:17 Mar 18  
 
commit 1d43ae0b0a01fdd90486c616d5dddd318a8fb9f0
Author:     Albrecht Schlosser <albrechts.fltk@online.de>
AuthorDate: Mon Mar 18 18:15:06 2024 +0100
Commit:     Albrecht Schlosser <albrechts.fltk@online.de>
CommitDate: Mon Mar 18 19:36:16 2024 +0100

    Move nanosvg to a separate file, don't use 'roundf()' (#937)
    
    Replacement of roundf() with nsvg__roundf() fixes one aspect of
    issue #937.
    
    Having the nanosvg implementation in its own module was planned anyway.

 src/CMakeLists.txt   |  1 +
 src/Fl_SVG_Image.cxx | 21 +-----------------
 src/Makefile         |  1 +
 src/nanosvg.cxx      | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 63 insertions(+), 20 deletions(-)

diff --git src/CMakeLists.txt src/CMakeLists.txt
index 00cd2d4..062078e 100644
--- src/CMakeLists.txt
+++ src/CMakeLists.txt
@@ -507,6 +507,7 @@ set(IMGCPPFILES
   Fl_PNM_Image.cxx
   Fl_Image_Reader.cxx
   Fl_SVG_Image.cxx
+  nanosvg.cxx
   drivers/SVG/Fl_SVG_File_Surface.cxx
 )
 
diff --git src/Fl_SVG_Image.cxx src/Fl_SVG_Image.cxx
index 3df44ad..1e3a05d 100644
--- src/Fl_SVG_Image.cxx
+++ src/Fl_SVG_Image.cxx
@@ -1,7 +1,7 @@
 //
 // SVG image code for the Fast Light Tool Kit (FLTK).
 //
-// Copyright 2017-2022 by Bill Spitzak and others.
+// Copyright 2017-2024 by Bill Spitzak and others.
 //
 // This library is free software. Distribution and use rights are outlined in
 // the file "COPYING" which should have been included with this file.  If this
@@ -28,28 +28,9 @@
 #include <stdio.h>
 #include <stdlib.h>
 
-#if !defined(HAVE_LONG_LONG)
-static double strtoll(const char *str, char **endptr, int base) {
-  return (double)strtol(str, endptr, base);
-}
-#endif
-
-#ifdef _MSC_VER
-#pragma warning (push)                  // Save #pragma warning status
-#pragma warning (disable: 4244)         // Switch off conversion warnings
-#endif
-
-#define NANOSVG_ALL_COLOR_KEYWORDS      // Include full list of color keywords.
-#define NANOSVG_IMPLEMENTATION          // Expands implementation
 #include "../nanosvg/nanosvg.h"
-
-#define NANOSVGRAST_IMPLEMENTATION      // Expands implementation
 #include "../nanosvg/nanosvgrast.h"
 
-#ifdef _MSC_VER
-#pragma warning (pop)                  // Restore #pragma warning status
-#endif
-
 #if defined(HAVE_LIBZ)
 #include <zlib.h>
 #endif
diff --git src/Makefile src/Makefile
index 4bed068..9fc2090 100644
--- src/Makefile
+++ src/Makefile
@@ -241,6 +241,7 @@ IMGCPPFILES = \
 	Fl_PNM_Image.cxx \
 	Fl_Image_Reader.cxx \
 	Fl_SVG_Image.cxx \
+	nanosvg.cxx \
 	drivers/SVG/Fl_SVG_File_Surface.cxx
 
 CFILES = flstring.c numericsort.c vsnprintf.c
diff --git src/nanosvg.cxx src/nanosvg.cxx
new file mode 100644
index 0000000..abb9831
--- /dev/null
+++ src/nanosvg.cxx
@@ -0,0 +1,60 @@
+//
+// Implementation of the nanosvg library for the Fast Light Tool Kit (FLTK).
+//
+// Copyright 2017-2024 by Bill Spitzak and others.
+//
+// This library is free software. Distribution and use rights are outlined in
+// the file "COPYING" which should have been included with this file.  If this
+// file is missing or damaged, see the license at:
+//
+//     https://www.fltk.org/COPYING.php
+//
+// Please see the following page on how to report bugs and issues:
+//
+//     https://www.fltk.org/bugs.php
+//
+
+// This code includes the header-only nanosvg library and builds a
+// separate object file comprised of the nanosvg library and nothing
+// else. Moved here from Fl_SVG_Image.cxx for better code separation.
+
+#include <config.h>
+
+#if defined(FLTK_USE_SVG) || defined(FL_DOXYGEN)
+
+// GitHub Issue #937: "Support for HP-UX" (version 11.11, Dec. 2000)
+//
+// C90 does not provide roundf() but nanosvg.h uses it although
+// nanosvgrast.h has a replacement function: nsvg__roundf()
+//
+// Solution: use nsvg_roundf() instead.
+// Advantage: we don't need to check system macros.
+//
+// Note: using nsvg__roundf() in nanosvg.h should be applied upstream.
+//       Once this is available we can remove this comment block and
+//       the following 3-line "fix":
+
+#include <math.h>                       // must be before #define below !
+static float nsvg__roundf(float x);     // prototype (see nanosvgrast.h)
+#define roundf nsvg__roundf             // redefinition (#937)
+
+// End of GitHub Issue #937. Remove this entire block when upstream is patched.
+
+#if !defined(HAVE_LONG_LONG)
+static double strtoll(const char *str, char **endptr, int base) {
+  return (double)strtol(str, endptr, base);
+}
+#endif
+
+#ifdef _MSC_VER
+#pragma warning (disable: 4244)         // Switch off conversion warnings
+#endif
+
+#define NANOSVG_ALL_COLOR_KEYWORDS      // include full list of color keywords
+#define NANOSVG_IMPLEMENTATION          // use nanosvg.h implementation
+#define NANOSVGRAST_IMPLEMENTATION      // use nanosvgrast.h implementation
+
+#include "../nanosvg/nanosvg.h"
+#include "../nanosvg/nanosvgrast.h"
+
+#endif // FLTK_USE_SVG
Direct Link to Message ]
 
     
Previous Message ]Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2024 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.