summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--nanosvg/fl_nanosvg.diff74
-rw-r--r--nanosvg/fl_nanosvg.h67
-rw-r--r--src/Fl_SVG_Image.cxx16
3 files changed, 78 insertions, 79 deletions
diff --git a/nanosvg/fl_nanosvg.diff b/nanosvg/fl_nanosvg.diff
index 891379a1d..ffafb7d4d 100644
--- a/nanosvg/fl_nanosvg.diff
+++ b/nanosvg/fl_nanosvg.diff
@@ -1,76 +1,18 @@
-1,10d0
+1,9d0
< //
< // "$Id$"
< //
<
-< /* Modified by FLTK from original source file "nanosvg.h" to support compilation
-< with Visual Studio 7:
-< remove the implementation of function nsvg__atof() that uses
-< unsupported "long long" type and strtoll() function.
+< /* Modified for the FLTK library from original source file "nanosvg.h" to
+< support compilation with Visual Studio 7:
+< replace in function nsvg__atof() the "long long" type by "fl_nsvg_int".
< */
<
-1087a1078,1137
-> // We roll our own string to float because the std library one uses locale and messes things up.
-> static double nsvg__atof(const char* s)
-> {
-> char* cur = (char*)s;
-> char* end = NULL;
-> double res = 0.0, sign = 1.0;
+1093c1084
+< fl_nsvg_int intPart = 0, fracPart = 0;
+---
> long long intPart = 0, fracPart = 0;
-> char hasIntPart = 0, hasFracPart = 0;
->
-> // Parse optional sign
-> if (*cur == '+') {
-> cur++;
-> } else if (*cur == '-') {
-> sign = -1;
-> cur++;
-> }
->
-> // Parse integer part
-> if (nsvg__isdigit(*cur)) {
-> // Parse digit sequence
-> intPart = (double)strtoll(cur, &end, 10);
-> if (cur != end) {
-> res = (double)intPart;
-> hasIntPart = 1;
-> cur = end;
-> }
-> }
->
-> // Parse fractional part.
-> if (*cur == '.') {
-> cur++; // Skip '.'
-> if (nsvg__isdigit(*cur)) {
-> // Parse digit sequence
-> fracPart = strtoll(cur, &end, 10);
-> if (cur != end) {
-> res += (double)fracPart / pow(10.0, (double)(end - cur));
-> hasFracPart = 1;
-> cur = end;
-> }
-> }
-> }
->
-> // A valid number should have integer or fractional part.
-> if (!hasIntPart && !hasFracPart)
-> return 0.0;
->
-> // Parse optional exponent
-> if (*cur == 'e' || *cur == 'E') {
-> int expPart = 0;
-> cur++; // skip 'E'
-> expPart = strtol(cur, &end, 10); // Parse digit sequence with sign
-> if (cur != end) {
-> res *= pow(10.0, (double)expPart);
-> }
-> }
->
-> return res * sign;
-> }
->
->
-2876,2879d2925
+2935,2938d2925
<
< //
< // End of "$Id$".
diff --git a/nanosvg/fl_nanosvg.h b/nanosvg/fl_nanosvg.h
index 4ceef8443..4cecf0c11 100644
--- a/nanosvg/fl_nanosvg.h
+++ b/nanosvg/fl_nanosvg.h
@@ -2,10 +2,9 @@
// "$Id$"
//
-/* Modified by FLTK from original source file "nanosvg.h" to support compilation
- with Visual Studio 7:
- remove the implementation of function nsvg__atof() that uses
- unsupported "long long" type and strtoll() function.
+/* Modified for the FLTK library from original source file "nanosvg.h" to
+ support compilation with Visual Studio 7:
+ replace in function nsvg__atof() the "long long" type by "fl_nsvg_int".
*/
/*
@@ -1085,6 +1084,66 @@ error:
}
}
+// We roll our own string to float because the std library one uses locale and messes things up.
+static double nsvg__atof(const char* s)
+{
+ char* cur = (char*)s;
+ char* end = NULL;
+ double res = 0.0, sign = 1.0;
+ fl_nsvg_int intPart = 0, fracPart = 0;
+ char hasIntPart = 0, hasFracPart = 0;
+
+ // Parse optional sign
+ if (*cur == '+') {
+ cur++;
+ } else if (*cur == '-') {
+ sign = -1;
+ cur++;
+ }
+
+ // Parse integer part
+ if (nsvg__isdigit(*cur)) {
+ // Parse digit sequence
+ intPart = (double)strtoll(cur, &end, 10);
+ if (cur != end) {
+ res = (double)intPart;
+ hasIntPart = 1;
+ cur = end;
+ }
+ }
+
+ // Parse fractional part.
+ if (*cur == '.') {
+ cur++; // Skip '.'
+ if (nsvg__isdigit(*cur)) {
+ // Parse digit sequence
+ fracPart = strtoll(cur, &end, 10);
+ if (cur != end) {
+ res += (double)fracPart / pow(10.0, (double)(end - cur));
+ hasFracPart = 1;
+ cur = end;
+ }
+ }
+ }
+
+ // A valid number should have integer or fractional part.
+ if (!hasIntPart && !hasFracPart)
+ return 0.0;
+
+ // Parse optional exponent
+ if (*cur == 'e' || *cur == 'E') {
+ int expPart = 0;
+ cur++; // skip 'E'
+ expPart = strtol(cur, &end, 10); // Parse digit sequence with sign
+ if (cur != end) {
+ res *= pow(10.0, (double)expPart);
+ }
+ }
+
+ return res * sign;
+}
+
+
static const char* nsvg__parseNumber(const char* s, char* it, const int size)
{
const int last = size-1;
diff --git a/src/Fl_SVG_Image.cxx b/src/Fl_SVG_Image.cxx
index 87ea71a46..7723f56af 100644
--- a/src/Fl_SVG_Image.cxx
+++ b/src/Fl_SVG_Image.cxx
@@ -28,8 +28,13 @@
#include <locale.h>
#endif
-// the C locale is set in init_() before calling nsvgParse(), therefore plain atof() can be used
-#define nsvg__atof(s) atof(s)
+#ifdef HAVE_LONG_LONG
+ typedef long long fl_nsvg_int;
+#else
+ typedef long fl_nsvg_int;
+# define strtoll(a, b, c) strtol(a, b, c)
+#endif
+
#define NANOSVG_ALL_COLOR_KEYWORDS // Include full list of color keywords.
#define NANOSVG_IMPLEMENTATION // Expands implementation
@@ -104,14 +109,7 @@ void Fl_SVG_Image::init_(const char *filename, char *filedata, Fl_SVG_Image *cop
} else ld(ERR_FILE_ACCESS);
}
if (filedata) {
-#if HAVE_LOCALE_H
- char *saved_locale = setlocale(LC_NUMERIC, NULL);
- setlocale(LC_NUMERIC, "C");
-#endif
counted_svg_image_->svg_image = nsvgParse(filedata, "px", 96);
-#if HAVE_LOCALE_H
- setlocale(LC_NUMERIC, saved_locale);
-#endif
if (filename) free(filedata);
if (counted_svg_image_->svg_image->width == 0 || counted_svg_image_->svg_image->height == 0) {
d(-1);