summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2020-10-28 14:35:42 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2020-10-28 14:35:42 (GMT)
commit085cde1d42e9a1a964a4ae5aeb9e186b698adc55 (patch)
tree3c6908c1b9f1f60c9be74a0035df0e77e297a894
parent5492992c1cdae510ac3ecf655e9d66daedd9ad3c (diff)
parent23f3f3d7286d69a47c993acf489b768f415cc664 (diff)
downloadtk-085cde1d42e9a1a964a4ae5aeb9e186b698adc55.zip
tk-085cde1d42e9a1a964a4ae5aeb9e186b698adc55.tar.gz
tk-085cde1d42e9a1a964a4ae5aeb9e186b698adc55.tar.bz2
Merge 8.7
-rw-r--r--.travis.yml28
-rw-r--r--doc/console.n9
-rw-r--r--doc/systray.n2
-rw-r--r--generic/nanosvg.h353
-rw-r--r--generic/nanosvgrast.h200
-rw-r--r--generic/tkCanvUtil.c2
-rw-r--r--generic/tkImgPhoto.c4
-rw-r--r--generic/tkScrollbar.c8
-rw-r--r--library/console.tcl4
-rw-r--r--library/tk.tcl6
-rw-r--r--library/ttk/ttk.tcl34
-rw-r--r--macosx/tkMacOSXDialog.c64
-rw-r--r--macosx/tkMacOSXSysTray.c2
-rw-r--r--macosx/tkMacOSXWm.c4
-rw-r--r--tests/visual_bb.test2
-rw-r--r--win/tkWinCursor.c2
-rw-r--r--win/tkWinDialog.c6
-rw-r--r--win/ttkWinXPTheme.c4
18 files changed, 371 insertions, 363 deletions
diff --git a/.travis.yml b/.travis.yml
index 19d92d4..f4fbbd4 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -195,43 +195,24 @@ jobs:
env:
- BUILD_DIR=unix
- CFGOPT="--with-tcl=/usr/local/opt/tcl-tk/lib CC=clang++ --enable-aqua CFLAGS=-I/usr/local/opt/tcl-tk/include CPPFLAGS=-D__private_extern__=extern"
- - name: "macOS/Xcode 12/Shared"
- os: osx
- osx_image: xcode12
- env:
- - BUILD_DIR=unix
- - CFGOPT="--with-tcl=/usr/local/opt/tcl-tk/lib --enable-aqua CFLAGS=-I/usr/local/opt/tcl-tk/include"
- install:
- - ./configure ${CFGOPT} "--prefix=$HOME" || (cat config.log && exit 1)
- script: &mactest
- - make all tktest
- name: "macOS/Xcode 12/Static"
os: osx
osx_image: xcode12
env:
- BUILD_DIR=unix
- CFGOPT="--with-tcl=/usr/local/opt/tcl-tk/lib --enable-aqua --disable-shared CFLAGS=-I/usr/local/opt/tcl-tk/include"
- install:
- - ./configure ${CFGOPT} "--prefix=$HOME" || (cat config.log && exit 1)
- script: *mactest
- name: "macOS/Xcode 12/Debug"
os: osx
osx_image: xcode12
env:
- BUILD_DIR=unix
- CFGOPT="--with-tcl=/usr/local/opt/tcl-tk/lib --enable-aqua --enable-symbols CFLAGS=-I/usr/local/opt/tcl-tk/include"
- install:
- - ./configure ${CFGOPT} "--prefix=$HOME" || (cat config.log && exit 1)
- script: *mactest
- name: "macOS/Xcode 12/Shared/XQuartz"
os: osx
osx_image: xcode12
env:
- BUILD_DIR=unix
- CFGOPT="--with-tcl=/usr/local/opt/tcl-tk/lib --disable-corefoundation --x-includes=/opt/X11/include --x-libraries=/opt/X11/lib CFLAGS=-I/usr/local/opt/tcl-tk/include"
- install:
- - ./configure ${CFGOPT} "--prefix=$HOME" || (cat config.log && exit 1)
- script: *mactest
# Older MacOS versions
- name: "macOS/Xcode 11/Shared"
os: osx
@@ -239,9 +220,6 @@ jobs:
env:
- BUILD_DIR=unix
- CFGOPT="--with-tcl=/usr/local/opt/tcl-tk/lib --enable-aqua CFLAGS=-I/usr/local/opt/tcl-tk/include CPPFLAGS=-mmacosx-version-min=10.14"
- install:
- - ./configure ${CFGOPT} "--prefix=$HOME" || (cat config.log && exit 1)
- script: *mactest
- name: "macOS/Xcode 10/Shared"
os: osx
osx_image: xcode10.3
@@ -253,9 +231,6 @@ jobs:
env:
- BUILD_DIR=unix
- CFGOPT="--with-tcl=/usr/local/opt/tcl-tk/lib --enable-aqua CFLAGS=-I/usr/local/opt/tcl-tk/include CPPFLAGS=-mmacosx-version-min=10.14"
- install:
- - ./configure ${CFGOPT} "--prefix=$HOME" || (cat config.log && exit 1)
- script: *mactest
- name: "macOS/Xcode 9/Shared"
os: osx
osx_image: xcode9.4
@@ -267,9 +242,6 @@ jobs:
env:
- BUILD_DIR=unix
- CFGOPT="--with-tcl=/usr/local/opt/tcl-tk/lib --enable-aqua CFLAGS=-I/usr/local/opt/tcl-tk/include CPPFLAGS=-mmacosx-version-min=10.13"
- install:
- - ./configure ${CFGOPT} "--prefix=$HOME" || (cat config.log && exit 1)
- script: *mactest
# Test on Windows with MSVC native
# - name: "Windows/MSVC/Shared"
# os: windows
diff --git a/doc/console.n b/doc/console.n
index d4d8a74..40b7426 100644
--- a/doc/console.n
+++ b/doc/console.n
@@ -25,9 +25,12 @@ the Tk library. Except for TkAqua, this command is not available when
Tk is loaded into a tclsh interpreter with
.QW "\fBpackage require Tk\fR" ,
as a conventional terminal is expected to be present in that case.
-In TkAqua, this command is only available when stdin is \fB/dev/null\fR
-(as is the case e.g. when the application embedding Tk is started
-from the Mac OS X Finder).
+In TkAqua, this command is disabled when there is a startup script
+and stdin is \fB/dev/null\fR (as is the case e.g. when a bundled application
+embedding Tk is started by the macOS Launcher). To enable the command
+in that case, define the environment variable \fBTK_CONSOLE\fR. This can be
+done by modifying the Info.plist file by adding the LSEnvironment key
+to the main dict and setting its value to be a dict with the key \fBTK_CONSOLE\fR.
.PP
.TP
\fBconsole eval \fIscript\fR
diff --git a/doc/systray.n b/doc/systray.n
index c0bc9ff..55fbb44 100644
--- a/doc/systray.n
+++ b/doc/systray.n
@@ -25,7 +25,7 @@ systray \- Creates an icon display in the platform-specific system tray.
.PP
The \fBtk systray\fP command creates an icon in the platform-specific tray.
The widget is configured with a Tk image for the icon display, a string
-for display in a tooltip, and callbacks that are bound to <Button-1> and
+for display in a tooltip, and callbacks that are bound to <Button-1> and
<Button-3>.
.SH EXAMPLE
.PP
diff --git a/generic/nanosvg.h b/generic/nanosvg.h
index d762f5a..3f3e38e 100644
--- a/generic/nanosvg.h
+++ b/generic/nanosvg.h
@@ -33,22 +33,23 @@
extern "C" {
#endif
-// NanoSVG is a simple stupid single-header-file SVG parse. The output of the parser is a list of cubic bezier shapes.
-//
-// The library suits well for anything from rendering scalable icons in your editor application to prototyping a game.
-//
-// NanoSVG supports a wide range of SVG features, but something may be missing, feel free to create a pull request!
-//
-// The shapes in the SVG images are transformed by the viewBox and converted to specified units.
-// That is, you should get the same looking data as your designed in your favorite app.
-//
-// NanoSVG can return the paths in few different units. For example if you want to render an image, you may choose
-// to get the paths in pixels, or if you are feeding the data into a CNC-cutter, you may want to use millimeters.
-//
-// The units passed to NanoSVG should be one of: 'px', 'pt', 'pc' 'mm', 'cm', or 'in'.
-// DPI (dots-per-inch) controls how the unit conversion is done.
-//
-// If you don't know or care about the units stuff, "px" and 96 should get you going.
+/* NanoSVG is a simple stupid single-header-file SVG parse. The output of the parser is a list of cubic bezier shapes.
+ *
+ * The library suits well for anything from rendering scalable icons in your editor application to prototyping a game.
+ *
+ * NanoSVG supports a wide range of SVG features, but something may be missing, feel free to create a pull request!
+ *
+ * The shapes in the SVG images are transformed by the viewBox and converted to specified units.
+ * That is, you should get the same looking data as your designed in your favorite app.
+ *
+ * NanoSVG can return the paths in few different units. For example if you want to render an image, you may choose
+ * to get the paths in pixels, or if you are feeding the data into a CNC-cutter, you may want to use millimeters.
+ *
+ * The units passed to NanoSVG should be one of: 'px', 'pt', 'pc' 'mm', 'cm', or 'in'.
+ * DPI (dots-per-inch) controls how the unit conversion is done.
+ *
+ * If you don't know or care about the units stuff, "px" and 96 should get you going.
+ */
/* Example Usage:
@@ -85,7 +86,7 @@ extern "C" {
#define NANOSVG_free free
#endif
-// float emulation for MS VC6++ compiler
+/* float emulation for MS VC6++ compiler */
#if defined(_MSC_VER) && (_MSC_VER == 1200)
#define tanf(a) (float)tan(a)
#define cosf(a) (float)cos(a)
@@ -98,7 +99,7 @@ extern "C" {
#define fmodf(a,b) (float)fmod(a,b)
#define floorf(a) (float)floor(a)
#endif
-// float emulation for MS VC8++ compiler
+/* float emulation for MS VC8++ compiler */
#if defined(_MSC_VER) && (_MSC_VER == 1400)
#define fabsf(a) (float)fabs(a)
#endif
@@ -160,55 +161,55 @@ typedef struct NSVGpaint {
typedef struct NSVGpath
{
- float* pts; // Cubic bezier points: x0,y0, [cpx1,cpx1,cpx2,cpy2,x1,y1], ...
- int npts; // Total number of bezier points.
- char closed; // Flag indicating if shapes should be treated as closed.
- float bounds[4]; // Tight bounding box of the shape [minx,miny,maxx,maxy].
- struct NSVGpath* next; // Pointer to next path, or NULL if last element.
+ float* pts; /* Cubic bezier points: x0,y0, [cpx1,cpx1,cpx2,cpy2,x1,y1], ... */
+ int npts; /* Total number of bezier points. */
+ char closed; /* Flag indicating if shapes should be treated as closed. */
+ float bounds[4]; /* Tight bounding box of the shape [minx,miny,maxx,maxy]. */
+ struct NSVGpath* next; /* Pointer to next path, or NULL if last element. */
} NSVGpath;
typedef struct NSVGshape
{
- char id[64]; // Optional 'id' attr of the shape or its group
- NSVGpaint fill; // Fill paint
- NSVGpaint stroke; // Stroke paint
- float opacity; // Opacity of the shape.
- float strokeWidth; // Stroke width (scaled).
- float strokeDashOffset; // Stroke dash offset (scaled).
- float strokeDashArray[8]; // Stroke dash array (scaled).
- char strokeDashCount; // Number of dash values in dash array.
- char strokeLineJoin; // Stroke join type.
- char strokeLineCap; // Stroke cap type.
- float miterLimit; // Miter limit
- char fillRule; // Fill rule, see NSVGfillRule.
- unsigned char flags; // Logical or of NSVG_FLAGS_* flags
- float bounds[4]; // Tight bounding box of the shape [minx,miny,maxx,maxy].
- NSVGpath* paths; // Linked list of paths in the image.
- struct NSVGshape* next; // Pointer to next shape, or NULL if last element.
+ char id[64]; /* Optional 'id' attr of the shape or its group */
+ NSVGpaint fill; /* Fill paint */
+ NSVGpaint stroke; /* Stroke paint */
+ float opacity; /* Opacity of the shape. */
+ float strokeWidth; /* Stroke width (scaled). */
+ float strokeDashOffset; /* Stroke dash offset (scaled). */
+ float strokeDashArray[8]; /* Stroke dash array (scaled). */
+ char strokeDashCount; /* Number of dash values in dash array. */
+ char strokeLineJoin; /* Stroke join type. */
+ char strokeLineCap; /* Stroke cap type. */
+ float miterLimit; /* Miter limit */
+ char fillRule; /* Fill rule, see NSVGfillRule. */
+ unsigned char flags; /* Logical or of NSVG_FLAGS_* flags */
+ float bounds[4]; /* Tight bounding box of the shape [minx,miny,maxx,maxy]. */
+ NSVGpath* paths; /* Linked list of paths in the image. */
+ struct NSVGshape* next; /* Pointer to next shape, or NULL if last element. */
} NSVGshape;
typedef struct NSVGimage
{
- float width; // Width of the image.
- float height; // Height of the image.
- NSVGshape* shapes; // Linked list of shapes in the image.
+ float width; /* Width of the image. */
+ float height; /* Height of the image. */
+ NSVGshape* shapes; /* Linked list of shapes in the image. */
} NSVGimage;
-// Parses SVG file from a file, returns SVG image as paths.
+/* Parses SVG file from a file, returns SVG image as paths. */
NANOSVG_SCOPE NSVGimage* nsvgParseFromFile(const char* filename, const char* units, float dpi);
-// Parses SVG file from a null terminated string, returns SVG image as paths.
-// Important note: changes the string.
+/* Parses SVG file from a null terminated string, returns SVG image as paths. */
+/* Important note: changes the string. */
NANOSVG_SCOPE NSVGimage* nsvgParse(char* input, const char* units, float dpi);
-// Deletes list of paths.
+/* Deletes list of paths. */
NANOSVG_SCOPE void nsvgDelete(NSVGimage* image);
#ifdef __cplusplus
}
#endif
-#endif // NANOSVG_H
+#endif /* NANOSVG_H */
#ifdef NANOSVG_IMPLEMENTATION
@@ -217,7 +218,7 @@ NANOSVG_SCOPE void nsvgDelete(NSVGimage* image);
#include <math.h>
#define NSVG_PI (3.14159265358979323846264338327f)
-#define NSVG_KAPPA90 (0.5522847493f) // Length proportional to radius of a cubic bezier handle for 90deg arcs.
+#define NSVG_KAPPA90 (0.5522847493f) /* Length proportional to radius of a cubic bezier handle for 90deg arcs. */
#define NSVG_ALIGN_MIN 0
#define NSVG_ALIGN_MID 1
@@ -230,14 +231,14 @@ NANOSVG_SCOPE void nsvgDelete(NSVGimage* image);
#define NSVG_RGB(r, g, b) (((unsigned int)r) | ((unsigned int)g << 8) | ((unsigned int)b << 16))
#ifdef _MSC_VER
- #pragma warning (disable: 4996) // Switch off security warnings
- #pragma warning (disable: 4100) // Switch off unreferenced formal parameter warnings
+ #pragma warning (disable: 4996) /* Switch off security warnings */
+ #pragma warning (disable: 4100) /* Switch off unreferenced formal parameter warnings */
#ifdef __cplusplus
#define NSVG_INLINE inline
#else
#define NSVG_INLINE
#endif
- #if !defined(strtoll) // old MSVC versions do not have strtoll()
+ #if !defined(strtoll) /* old MSVC versions do not have strtoll() */
#define strtoll _strtoi64
#endif
#else
@@ -259,7 +260,7 @@ static NSVG_INLINE float nsvg__minf(float a, float b) { return a < b ? a : b; }
static NSVG_INLINE float nsvg__maxf(float a, float b) { return a > b ? a : b; }
-// Simple XML parser
+/* Simple XML parser */
#define NSVG_XML_TAG 1
#define NSVG_XML_CONTENT 2
@@ -269,7 +270,7 @@ static void nsvg__parseContent(char* s,
void (*contentCb)(void* ud, const char* s),
void* ud)
{
- // Trim start white spaces
+ /* Trim start white spaces */
while (*s && nsvg__isspace(*s)) s++;
if (!*s) return;
@@ -289,10 +290,10 @@ static void nsvg__parseElement(char* s,
int end = 0;
char quote;
- // Skip white space after the '<'
+ /* Skip white space after the '<' */
while (*s && nsvg__isspace(*s)) s++;
- // Check if the tag is end tag
+ /* Check if the tag is end tag */
if (*s == '/') {
s++;
end = 1;
@@ -300,21 +301,21 @@ static void nsvg__parseElement(char* s,
start = 1;
}
- // Skip comments, data and preprocessor stuff.
+ /* Skip comments, data and preprocessor stuff. */
if (!*s || *s == '?' || *s == '!')
return;
- // Get tag name
+ /* Get tag name */
cbname = s;
while (*s && !nsvg__isspace(*s)) s++;
if (*s) { *s++ = '\0'; }
- // Get attribs
+ /* Get attribs */
while (!end && *s && nattr < NSVG_XML_MAX_ATTRIBS-3) {
char* name = NULL;
char* value = NULL;
- // Skip white space before the attrib name
+ /* Skip white space before the attrib name */
while (*s && nsvg__isspace(*s)) s++;
if (!*s) break;
if (*s == '/') {
@@ -322,31 +323,31 @@ static void nsvg__parseElement(char* s,
break;
}
name = s;
- // Find end of the attrib name.
+ /* Find end of the attrib name. */
while (*s && !nsvg__isspace(*s) && *s != '=') s++;
if (*s) { *s++ = '\0'; }
- // Skip until the beginning of the value.
+ /* Skip until the beginning of the value. */
while (*s && *s != '\"' && *s != '\'') s++;
if (!*s) break;
quote = *s;
s++;
- // Store value and find the end of it.
+ /* Store value and find the end of it. */
value = s;
while (*s && *s != quote) s++;
if (*s) { *s++ = '\0'; }
- // Store only well formed attributes
+ /* Store only well formed attributes */
if (name && value) {
attr[nattr++] = name;
attr[nattr++] = value;
}
}
- // List terminator
+ /* List terminator */
attr[nattr++] = 0;
attr[nattr++] = 0;
- // Call callbacks.
+ /* Call callbacks. */
if (start && startelCb)
(*startelCb)(ud, cbname, attr);
if (end && endelCb)
@@ -365,13 +366,13 @@ int nsvg__parseXML(char* input,
int state = NSVG_XML_CONTENT;
while (*s) {
if (*s == '<' && state == NSVG_XML_CONTENT) {
- // Start of a tag
+ /* Start of a tag */
*s++ = '\0';
nsvg__parseContent(mark, contentCb, ud);
mark = s;
state = NSVG_XML_TAG;
} else if (*s == '>' && state == NSVG_XML_TAG) {
- // Start of a content or new tag.
+ /* Start of a content or new tag. */
*s++ = '\0';
nsvg__parseContent(mark, contentCb, ud);
nsvg__parseElement(mark, startelCb, endelCb, ud);
@@ -615,18 +616,18 @@ static void nsvg__curveBounds(float* bounds, float* curve)
float* v2 = &curve[4];
float* v3 = &curve[6];
- // Start the bounding box by end points
+ /* Start the bounding box by end points */
bounds[0] = nsvg__minf(v0[0], v3[0]);
bounds[1] = nsvg__minf(v0[1], v3[1]);
bounds[2] = nsvg__maxf(v0[0], v3[0]);
bounds[3] = nsvg__maxf(v0[1], v3[1]);
- // Bezier curve fits inside the convex hull of it's control points.
- // If control points are inside the bounds, we're done.
+ /* Bezier curve fits inside the convex hull of it's control points. */
+ /* If control points are inside the bounds, we're done. */
if (nsvg__ptInBounds(v1, bounds) && nsvg__ptInBounds(v2, bounds))
return;
- // Add bezier curve inflection points in X and Y.
+ /* Add bezier curve inflection points in X and Y. */
for (i = 0; i < 2; i++) {
a = -3.0 * v0[i] + 9.0 * v1[i] - 9.0 * v2[i] + 3.0 * v3[i];
b = 6.0 * v0[i] - 12.0 * v1[i] + 6.0 * v2[i];
@@ -668,7 +669,7 @@ static NSVGparser* nsvg__createParser(void)
if (p->image == NULL) goto error;
memset(p->image, 0, sizeof(NSVGimage));
- // Init style
+ /* Init style */
nsvg__xformIdentity(p->attr[0].xform);
memset(p->attr[0].id, 0, sizeof p->attr[0].id);
p->attr[0].fillColor = NSVG_RGB(0,0,0);
@@ -854,7 +855,7 @@ static float nsvg__convertToPixels(NSVGparser* p, NSVGcoordinate c, float orig,
case NSVG_UNITS_CM: return c.value / 2.54f * p->dpi;
case NSVG_UNITS_IN: return c.value * p->dpi;
case NSVG_UNITS_EM: return c.value * attr->fontSize;
- case NSVG_UNITS_EX: return c.value * attr->fontSize * 0.52f; // x-height of Helvetica.
+ case NSVG_UNITS_EX: return c.value * attr->fontSize * 0.52f; /* x-height of Helvetica. */
case NSVG_UNITS_PERCENT: return orig + c.value / 100.0f * length;
default: return c.value;
}
@@ -888,7 +889,7 @@ static NSVGgradient* nsvg__createGradient(NSVGparser* p, const char* id, const f
data = nsvg__findGradientData(p, id);
if (data == NULL) return NULL;
- // TODO: use ref to fill in all unset values too.
+ /* TODO: use ref to fill in all unset values too. */
ref = data;
refIter = 0;
while (ref != NULL) {
@@ -899,17 +900,17 @@ static NSVGgradient* nsvg__createGradient(NSVGparser* p, const char* id, const f
break;
}
nextRef = nsvg__findGradientData(p, ref->ref);
- if (nextRef == ref) break; // prevent infite loops on malformed data
+ if (nextRef == ref) break; /* prevent infite loops on malformed data */
ref = nextRef;
refIter++;
- if (refIter > 32) break; // prevent infite loops on malformed data
+ if (refIter > 32) break; /* prevent infite loops on malformed data */
}
if (stops == NULL) return NULL;
grad = (NSVGgradient*)NANOSVG_malloc(sizeof(NSVGgradient) + sizeof(NSVGgradientStop)*(nstops-1));
if (grad == NULL) return NULL;
- // The shape width and height.
+ /* The shape width and height. */
if (data->units == NSVG_OBJECT_SPACE) {
ox = localBounds[0];
oy = localBounds[1];
@@ -929,7 +930,7 @@ static NSVGgradient* nsvg__createGradient(NSVGparser* p, const char* id, const f
y1 = nsvg__convertToPixels(p, data->linear.y1, oy, sh);
x2 = nsvg__convertToPixels(p, data->linear.x2, ox, sw);
y2 = nsvg__convertToPixels(p, data->linear.y2, oy, sh);
- // Calculate transform aligned to the line
+ /* Calculate transform aligned to the line */
dx = x2 - x1;
dy = y2 - y1;
grad->xform[0] = dy; grad->xform[1] = -dx;
@@ -942,7 +943,7 @@ static NSVGgradient* nsvg__createGradient(NSVGparser* p, const char* id, const f
fx = nsvg__convertToPixels(p, data->radial.fx, ox, sw);
fy = nsvg__convertToPixels(p, data->radial.fy, oy, sh);
r = nsvg__convertToPixels(p, data->radial.r, 0, sl);
- // Calculate transform aligned to the circle
+ /* Calculate transform aligned to the circle */
grad->xform[0] = r; grad->xform[1] = 0;
grad->xform[2] = 0; grad->xform[3] = r;
grad->xform[4] = cx; grad->xform[5] = cy;
@@ -1030,7 +1031,7 @@ static void nsvg__addShape(NSVGparser* p)
shape->paths = p->plist;
p->plist = NULL;
- // Calculate shape bounds
+ /* Calculate shape bounds */
shape->bounds[0] = shape->paths->bounds[0];
shape->bounds[1] = shape->paths->bounds[1];
shape->bounds[2] = shape->paths->bounds[2];
@@ -1042,7 +1043,7 @@ static void nsvg__addShape(NSVGparser* p)
shape->bounds[3] = nsvg__maxf(shape->bounds[3], path->bounds[3]);
}
- // Set fill
+ /* Set fill */
if (attr->hasFill == 0) {
shape->fill.type = NSVG_PAINT_NONE;
} else if (attr->hasFill == 1) {
@@ -1059,7 +1060,7 @@ static void nsvg__addShape(NSVGparser* p)
}
}
- // Set stroke
+ /* Set stroke */
if (attr->hasStroke == 0) {
shape->stroke.type = NSVG_PAINT_NONE;
} else if (attr->hasStroke == 1) {
@@ -1075,10 +1076,10 @@ static void nsvg__addShape(NSVGparser* p)
shape->stroke.type = NSVG_PAINT_NONE;
}
- // Set flags
+ /* Set flags */
shape->flags = ((attr->visible & NSVG_VIS_DISPLAY) && (attr->visible & NSVG_VIS_VISIBLE) ? NSVG_FLAGS_VISIBLE : 0x00);
- // Add to tail
+ /* Add to tail */
if (p->image->shapes == NULL)
p->image->shapes = shape;
else
@@ -1105,7 +1106,7 @@ static void nsvg__addPath(NSVGparser* p, char closed)
if (closed)
nsvg__lineTo(p, p->pts[0], p->pts[1]);
- // Expect 1 + N*3 points (N = number of cubic bezier segments).
+ /* Expect 1 + N*3 points (N = number of cubic bezier segments). */
if ((p->npts % 3) != 1)
return;
@@ -1118,11 +1119,11 @@ static void nsvg__addPath(NSVGparser* p, char closed)
path->closed = closed;
path->npts = p->npts;
- // Transform path.
+ /* Transform path. */
for (i = 0; i < p->npts; ++i)
nsvg__xformPoint(&path->pts[i*2], &path->pts[i*2+1], p->pts[i*2], p->pts[i*2+1], attr->xform);
- // Find bounds
+ /* Find bounds */
for (i = 0; i < path->npts-1; i += 3) {
curve = &path->pts[i*2];
nsvg__curveBounds(bounds, curve);
@@ -1151,7 +1152,7 @@ error:
}
}
-// We roll our own string to float because the std library one uses locale and messes things up.
+/* 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;
@@ -1164,7 +1165,7 @@ static double nsvg__atof(const char* s)
#endif
char hasIntPart = 0, hasFracPart = 0;
- // Parse optional sign
+ /* Parse optional sign */
if (*cur == '+') {
cur++;
} else if (*cur == '-') {
@@ -1172,9 +1173,9 @@ static double nsvg__atof(const char* s)
cur++;
}
- // Parse integer part
+ /* Parse integer part */
if (nsvg__isdigit(*cur)) {
- // Parse digit sequence
+ /* Parse digit sequence */
#if defined(_MSC_VER) && (_MSC_VER == 1200)
intPart = strtol(cur, &end, 10);
#else
@@ -1187,11 +1188,11 @@ static double nsvg__atof(const char* s)
}
}
- // Parse fractional part.
+ /* Parse fractional part. */
if (*cur == '.') {
- cur++; // Skip '.'
+ cur++; /* Skip '.' */
if (nsvg__isdigit(*cur)) {
- // Parse digit sequence
+ /* Parse digit sequence */
#if defined(_MSC_VER) && (_MSC_VER == 1200)
fracPart = strtol(cur, &end, 10);
#else
@@ -1205,15 +1206,15 @@ static double nsvg__atof(const char* s)
}
}
- // A valid number should have integer or fractional part.
+ /* A valid number should have integer or fractional part. */
if (!hasIntPart && !hasFracPart)
return 0.0;
- // Parse optional exponent
+ /* Parse optional exponent */
if (*cur == 'e' || *cur == 'E') {
int expPart = 0;
- cur++; // skip 'E'
- expPart = strtol(cur, &end, 10); // Parse digit sequence with sign
+ cur++; /* skip 'E' */
+ expPart = strtol(cur, &end, 10); /* Parse digit sequence with sign */
if (cur != end) {
res *= pow(10.0, (double)expPart);
}
@@ -1228,27 +1229,27 @@ static const char* nsvg__parseNumber(const char* s, char* it, const int size)
const int last = size-1;
int i = 0;
- // sign
+ /* sign */
if (*s == '-' || *s == '+') {
if (i < last) it[i++] = *s;
s++;
}
- // integer part
+ /* integer part */
while (*s && nsvg__isdigit(*s)) {
if (i < last) it[i++] = *s;
s++;
}
if (*s == '.') {
- // decimal point
+ /* decimal point */
if (i < last) it[i++] = *s;
s++;
- // fraction part
+ /* fraction part */
while (*s && nsvg__isdigit(*s)) {
if (i < last) it[i++] = *s;
s++;
}
}
- // exponent
+ /* exponent */
if (*s == 'e' || *s == 'E') {
if (i < last) it[i++] = *s;
s++;
@@ -1269,13 +1270,13 @@ static const char* nsvg__parseNumber(const char* s, char* it, const int size)
static const char* nsvg__getNextPathItem(const char* s, char* it)
{
it[0] = '\0';
- // Skip white spaces and commas
+ /* Skip white spaces and commas */
while (*s && (nsvg__isspace(*s) || *s == ',')) s++;
if (!*s) return s;
if (*s == '-' || *s == '+' || *s == '.' || nsvg__isdigit(*s)) {
s = nsvg__parseNumber(s, it, 64);
} else {
- // Parse command
+ /* Parse command */
it[0] = *s++;
it[1] = '\0';
return s;
@@ -1288,8 +1289,8 @@ static unsigned int nsvg__parseColorHex(const char* str)
{
unsigned int c = 0, r = 0, g = 0, b = 0;
int n = 0;
- str++; // skip #
- // Calculate number of characters.
+ str++; /* skip # */
+ /* Calculate number of characters. */
while(str[n] && !nsvg__isspace(str[n]))
n++;
if (n == 6) {
@@ -1543,10 +1544,10 @@ static int nsvg__parseUnits(const char* units)
static int nsvg__isCoordinate(const char* s)
{
- // optional sign
+ /* optional sign */
if (*s == '-' || *s == '+')
s++;
- // must have at least one digit
+ /* must have at least one digit */
return nsvg__isdigit(*s);
}
@@ -1723,7 +1724,7 @@ static void nsvg__parseTransform(float* xform, const char* str)
static void nsvg__parseUrl(char* id, const char* str)
{
int i = 0;
- str += 4; // "url(";
+ str += 4; /* "url("; */
if (*str == '#')
str++;
while (i < 63 && *str != ')') {
@@ -1741,7 +1742,7 @@ static char nsvg__parseLineCap(const char* str)
return NSVG_CAP_ROUND;
else if (strcmp(str, "square") == 0)
return NSVG_CAP_SQUARE;
- // TODO: handle inherit.
+ /* TODO: handle inherit. */
return NSVG_CAP_BUTT;
}
@@ -1753,7 +1754,7 @@ static char nsvg__parseLineJoin(const char* str)
return NSVG_JOIN_ROUND;
else if (strcmp(str, "bevel") == 0)
return NSVG_JOIN_BEVEL;
- // TODO: handle inherit.
+ /* TODO: handle inherit. */
return NSVG_JOIN_MITER;
}
@@ -1763,7 +1764,7 @@ static char nsvg__parseFillRule(const char* str)
return NSVG_FILLRULE_NONZERO;
else if (strcmp(str, "evenodd") == 0)
return NSVG_FILLRULE_EVENODD;
- // TODO: handle inherit.
+ /* TODO: handle inherit. */
return NSVG_FILLRULE_NONZERO;
}
@@ -1771,9 +1772,9 @@ static const char* nsvg__getNextDashItem(const char* s, char* it)
{
int n = 0;
it[0] = '\0';
- // Skip white spaces and commas
+ /* Skip white spaces and commas */
while (*s && (nsvg__isspace(*s) || *s == ',')) s++;
- // Advance until whitespace, comma or end.
+ /* Advance until whitespace, comma or end. */
while (*s && (!nsvg__isspace(*s) && *s != ',')) {
if (n < 63)
it[n++] = *s;
@@ -1789,11 +1790,11 @@ static int nsvg__parseStrokeDashArray(NSVGparser* p, const char* str, float* str
int count = 0, i;
float sum = 0.0f;
- // Handle "none"
+ /* Handle "none" */
if (str[0] == 'n')
return 0;
- // Parse dashes
+ /* Parse dashes */
while (*str) {
str = nsvg__getNextDashItem(str, item);
if (!*item) break;
@@ -1822,7 +1823,7 @@ static int nsvg__parseAttr(NSVGparser* p, const char* name, const char* value)
} else if (strcmp(name, "display") == 0) {
if (strcmp(value, "none") == 0)
attr->visible &= ~NSVG_VIS_DISPLAY;
- // Don't reset ->visible on display:inline, one display:none hides the whole subtree
+ /* Don't reset ->visible on display:inline, one display:none hides the whole subtree */
} else if (strcmp(name, "visibility") == 0) {
if (strcmp(value, "hidden") == 0) {
@@ -1914,7 +1915,7 @@ static int nsvg__parseNameValue(NSVGparser* p, const char* start, const char* en
val = str;
- // Right Trim
+ /* Right Trim */
while (str > start && (*str == ':' || nsvg__isspace(*str))) --str;
++str;
@@ -1939,13 +1940,13 @@ static void nsvg__parseStyle(NSVGparser* p, const char* str)
const char* end;
while (*str) {
- // Left Trim
+ /* Left Trim */
while(*str && nsvg__isspace(*str)) ++str;
start = str;
while(*str && *str != ';') ++str;
end = str;
- // Right Trim
+ /* Right Trim */
while (end > start && (*end == ';' || nsvg__isspace(*end))) --end;
++end;
@@ -2120,7 +2121,7 @@ static void nsvg__pathQuadBezTo(NSVGparser* p, float* cpx, float* cpy,
y2 = args[3];
}
- // Convert to cubic bezier
+ /* Convert to cubic bezier */
cx1 = x1 + 2.0f/3.0f*(cx - x1);
cy1 = y1 + 2.0f/3.0f*(cy - y1);
cx2 = x2 + 2.0f/3.0f*(cx - x2);
@@ -2153,7 +2154,7 @@ static void nsvg__pathQuadBezShortTo(NSVGparser* p, float* cpx, float* cpy,
cx = 2*x1 - *cpx2;
cy = 2*y1 - *cpy2;
- // Convert to cubix bezier
+ /* Convert to cubix bezier */
cx1 = x1 + 2.0f/3.0f*(cx - x1);
cy1 = y1 + 2.0f/3.0f*(cy - y1);
cx2 = x2 + 2.0f/3.0f*(cx - x2);
@@ -2185,7 +2186,7 @@ static float nsvg__vecang(float ux, float uy, float vx, float vy)
static void nsvg__pathArcTo(NSVGparser* p, float* cpx, float* cpy, float* args, int rel)
{
- // Ported from canvg (https://code.google.com/p/canvg/)
+ /* Ported from canvg (https://code.google.com/p/canvg/) */
float rx, ry, rotx;
float x1, y1, x2, y2, cx, cy, dx, dy, d;
float x1p, y1p, cxp, cyp, s, sa, sb;
@@ -2196,14 +2197,14 @@ static void nsvg__pathArcTo(NSVGparser* p, float* cpx, float* cpy, float* args,
int i, ndivs;
float hda, kappa;
- rx = fabsf(args[0]); // y radius
- ry = fabsf(args[1]); // x radius
- rotx = args[2] / 180.0f * NSVG_PI; // x rotation angle
- fa = fabsf(args[3]) > 1e-6 ? 1 : 0; // Large arc
- fs = fabsf(args[4]) > 1e-6 ? 1 : 0; // Sweep direction
- x1 = *cpx; // start point
+ rx = fabsf(args[0]); /* y radius */
+ ry = fabsf(args[1]); /* x radius */
+ rotx = args[2] / 180.0f * NSVG_PI; /* x rotation angle */
+ fa = fabsf(args[3]) > 1e-6 ? 1 : 0; /* Large arc */
+ fs = fabsf(args[4]) > 1e-6 ? 1 : 0; /* Sweep direction */
+ x1 = *cpx; /* start point */
y1 = *cpy;
- if (rel) { // end point
+ if (rel) { /* end point */
x2 = *cpx + args[5];
y2 = *cpy + args[6];
} else {
@@ -2215,7 +2216,7 @@ static void nsvg__pathArcTo(NSVGparser* p, float* cpx, float* cpy, float* args,
dy = y1 - y2;
d = sqrtf(dx*dx + dy*dy);
if (d < 1e-6f || rx < 1e-6f || ry < 1e-6f) {
- // The arc degenerates to a line
+ /* The arc degenerates to a line */
nsvg__lineTo(p, x2, y2);
*cpx = x2;
*cpy = y2;
@@ -2225,9 +2226,9 @@ static void nsvg__pathArcTo(NSVGparser* p, float* cpx, float* cpy, float* args,
sinrx = sinf(rotx);
cosrx = cosf(rotx);
- // Convert to center point parameterization.
- // http://www.w3.org/TR/SVG11/implnote.html#ArcImplementationNotes
- // 1) Compute x1', y1'
+ /* Convert to center point parameterization. */
+ /* http://www.w3.org/TR/SVG11/implnote.html#ArcImplementationNotes */
+ /* 1) Compute x1', y1' */
x1p = cosrx * dx / 2.0f + sinrx * dy / 2.0f;
y1p = -sinrx * dx / 2.0f + cosrx * dy / 2.0f;
d = nsvg__sqr(x1p)/nsvg__sqr(rx) + nsvg__sqr(y1p)/nsvg__sqr(ry);
@@ -2236,7 +2237,7 @@ static void nsvg__pathArcTo(NSVGparser* p, float* cpx, float* cpy, float* args,
rx *= d;
ry *= d;
}
- // 2) Compute cx', cy'
+ /* 2) Compute cx', cy' */
s = 0.0f;
sa = nsvg__sqr(rx)*nsvg__sqr(ry) - nsvg__sqr(rx)*nsvg__sqr(y1p) - nsvg__sqr(ry)*nsvg__sqr(x1p);
sb = nsvg__sqr(rx)*nsvg__sqr(y1p) + nsvg__sqr(ry)*nsvg__sqr(x1p);
@@ -2248,33 +2249,33 @@ static void nsvg__pathArcTo(NSVGparser* p, float* cpx, float* cpy, float* args,
cxp = s * rx * y1p / ry;
cyp = s * -ry * x1p / rx;
- // 3) Compute cx,cy from cx',cy'
+ /* 3) Compute cx,cy from cx',cy' */
cx = (x1 + x2)/2.0f + cosrx*cxp - sinrx*cyp;
cy = (y1 + y2)/2.0f + sinrx*cxp + cosrx*cyp;
- // 4) Calculate theta1, and delta theta.
+ /* 4) Calculate theta1, and delta theta. */
ux = (x1p - cxp) / rx;
uy = (y1p - cyp) / ry;
vx = (-x1p - cxp) / rx;
vy = (-y1p - cyp) / ry;
- a1 = nsvg__vecang(1.0f,0.0f, ux,uy); // Initial angle
- da = nsvg__vecang(ux,uy, vx,vy); // Delta angle
+ a1 = nsvg__vecang(1.0f,0.0f, ux,uy); /* Initial angle */
+ da = nsvg__vecang(ux,uy, vx,vy); /* Delta angle */
-// if (vecrat(ux,uy,vx,vy) <= -1.0f) da = NSVG_PI;
-// if (vecrat(ux,uy,vx,vy) >= 1.0f) da = 0;
+/* if (vecrat(ux,uy,vx,vy) <= -1.0f) da = NSVG_PI; */
+/* if (vecrat(ux,uy,vx,vy) >= 1.0f) da = 0; */
if (fs == 0 && da > 0)
da -= 2 * NSVG_PI;
else if (fs == 1 && da < 0)
da += 2 * NSVG_PI;
- // Approximate the arc using cubic spline segments.
+ /* Approximate the arc using cubic spline segments. */
t[0] = cosrx; t[1] = sinrx;
t[2] = -sinrx; t[3] = cosrx;
t[4] = cx; t[5] = cy;
- // Split arc into max 90 degree segments.
- // The loop assumes an iteration per end point (including start and end), this +1.
+ /* Split arc into max 90 degree segments. */
+ /* The loop assumes an iteration per end point (including start and end), this +1. */
ndivs = (int)(fabsf(da) / (NSVG_PI*0.5f) + 1.0f);
hda = (da / (float)ndivs) / 2.0f;
kappa = fabsf(4.0f / 3.0f * (1.0f - cosf(hda)) / sinf(hda));
@@ -2285,8 +2286,8 @@ static void nsvg__pathArcTo(NSVGparser* p, float* cpx, float* cpy, float* args,
a = a1 + da * ((float)i/(float)ndivs);
dx = cosf(a);
dy = sinf(a);
- nsvg__xformPoint(&x, &y, dx*rx, dy*ry, t); // position
- nsvg__xformVec(&tanx, &tany, -dy*rx * kappa, dx*ry * kappa, t); // tangent
+ nsvg__xformPoint(&x, &y, dx*rx, dy*ry, t); /* position */
+ nsvg__xformVec(&tanx, &tany, -dy*rx * kappa, dx*ry * kappa, t); /* tangent */
if (i > 0)
nsvg__cubicBezTo(p, px+ptanx,py+ptany, x-tanx, y-tany, x, y);
px = x;
@@ -2344,8 +2345,8 @@ static void nsvg__parsePath(NSVGparser* p, const char** attr)
case 'm':
case 'M':
nsvg__pathMoveTo(p, &cpx, &cpy, args, cmd == 'm' ? 1 : 0);
- // Moveto can be followed by multiple coordinate pairs,
- // which should be treated as linetos.
+ /* Moveto can be followed by multiple coordinate pairs, */
+ /* which should be treated as linetos. */
cmd = (cmd == 'm') ? 'l' : 'L';
rargs = nsvg__getArgsPerElement(cmd);
cpx2 = cpx; cpy2 = cpy;
@@ -2400,28 +2401,28 @@ static void nsvg__parsePath(NSVGparser* p, const char** attr)
} else {
cmd = item[0];
if (cmd == 'M' || cmd == 'm') {
- // Commit path.
+ /* Commit path. */
if (p->npts > 0)
nsvg__addPath(p, closedFlag);
- // Start new subpath.
+ /* Start new subpath. */
nsvg__resetPath(p);
closedFlag = 0;
nargs = 0;
} else if (initPoint == 0) {
- // Do not allow other commands until initial point has been set (moveTo called once).
+ /* Do not allow other commands until initial point has been set (moveTo called once). */
cmd = '\0';
}
if (cmd == 'Z' || cmd == 'z') {
closedFlag = 1;
- // Commit path.
+ /* Commit path. */
if (p->npts > 0) {
- // Move current point to first point
+ /* Move current point to first point */
cpx = p->pts[0];
cpy = p->pts[1];
cpx2 = cpx; cpy2 = cpy;
nsvg__addPath(p, closedFlag);
}
- // Start new subpath.
+ /* Start new subpath. */
nsvg__resetPath(p);
nsvg__moveTo(p, cpx, cpy);
closedFlag = 0;
@@ -2429,13 +2430,13 @@ static void nsvg__parsePath(NSVGparser* p, const char** attr)
}
rargs = nsvg__getArgsPerElement(cmd);
if (rargs == -1) {
- // Command not recognized
+ /* Command not recognized */
cmd = '\0';
rargs = 0;
}
}
}
- // Commit path.
+ /* Commit path. */
if (p->npts)
nsvg__addPath(p, closedFlag);
}
@@ -2449,7 +2450,7 @@ static void nsvg__parseRect(NSVGparser* p, const char** attr)
float y = 0.0f;
float w = 0.0f;
float h = 0.0f;
- float rx = -1.0f; // marks not set
+ float rx = -1.0f; /* marks not set */
float ry = -1.0f;
int i;
@@ -2480,7 +2481,7 @@ static void nsvg__parseRect(NSVGparser* p, const char** attr)
nsvg__lineTo(p, x+w, y+h);
nsvg__lineTo(p, x, y+h);
} else {
- // Rounded rectangle
+ /* Rounded rectangle */
nsvg__moveTo(p, x+rx, y);
nsvg__lineTo(p, x+w-rx, y);
nsvg__cubicBezTo(p, x+w-rx*(1-NSVG_KAPPA90), y, x+w, y+ry*(1-NSVG_KAPPA90), x+w, y+ry);
@@ -2637,24 +2638,24 @@ static void nsvg__parseSVG(NSVGparser* p, const char** attr)
sscanf(attr[i + 1], "%f%*[%%, \t]%f%*[%%, \t]%f%*[%%, \t]%f", &p->viewMinx, &p->viewMiny, &p->viewWidth, &p->viewHeight);
} else if (strcmp(attr[i], "preserveAspectRatio") == 0) {
if (strstr(attr[i + 1], "none") != 0) {
- // No uniform scaling
+ /* No uniform scaling */
p->alignType = NSVG_ALIGN_NONE;
} else {
- // Parse X align
+ /* Parse X align */
if (strstr(attr[i + 1], "xMin") != 0)
p->alignX = NSVG_ALIGN_MIN;
else if (strstr(attr[i + 1], "xMid") != 0)
p->alignX = NSVG_ALIGN_MID;
else if (strstr(attr[i + 1], "xMax") != 0)
p->alignX = NSVG_ALIGN_MAX;
- // Parse X align
+ /* Parse X align */
if (strstr(attr[i + 1], "yMin") != 0)
p->alignY = NSVG_ALIGN_MIN;
else if (strstr(attr[i + 1], "yMid") != 0)
p->alignY = NSVG_ALIGN_MID;
else if (strstr(attr[i + 1], "yMax") != 0)
p->alignY = NSVG_ALIGN_MAX;
- // Parse meet/slice
+ /* Parse meet/slice */
p->alignType = NSVG_ALIGN_MEET;
if (strstr(attr[i + 1], "slice") != 0)
p->alignType = NSVG_ALIGN_SLICE;
@@ -2749,7 +2750,7 @@ static void nsvg__parseGradientStop(NSVGparser* p, const char** attr)
nsvg__parseAttr(p, attr[i], attr[i + 1]);
}
- // Add stop to the last gradient.
+ /* Add stop to the last gradient. */
grad = p->gradients;
if (grad == NULL) return;
@@ -2757,7 +2758,7 @@ static void nsvg__parseGradientStop(NSVGparser* p, const char** attr)
grad->stops = (NSVGgradientStop*)NANOSVG_realloc(grad->stops, sizeof(NSVGgradientStop)*grad->nstops);
if (grad->stops == NULL) return;
- // Insert
+ /* Insert */
idx = grad->nstops-1;
for (i = 0; i < grad->nstops-1; i++) {
if (curAttr->stopOffset < grad->stops[i].offset) {
@@ -2781,7 +2782,7 @@ static void nsvg__startElement(void* ud, const char* el, const char** attr)
NSVGparser* p = (NSVGparser*)ud;
if (p->defsFlag) {
- // Skip everything but gradients in defs
+ /* Skip everything but gradients in defs */
if (strcmp(el, "linearGradient") == 0) {
nsvg__parseGradient(p, attr, NSVG_PAINT_LINEAR_GRADIENT);
} else if (strcmp(el, "radialGradient") == 0) {
@@ -2796,7 +2797,7 @@ static void nsvg__startElement(void* ud, const char* el, const char** attr)
nsvg__pushAttr(p);
nsvg__parseAttribs(p, attr);
} else if (strcmp(el, "path") == 0) {
- if (p->pathFlag) // Do not allow nested paths.
+ if (p->pathFlag) /* Do not allow nested paths. */
return;
nsvg__pushAttr(p);
nsvg__parsePath(p, attr);
@@ -2949,7 +2950,7 @@ static float nsvg__viewAlign(float content, float container, int type)
return 0;
else if (type == NSVG_ALIGN_MAX)
return container - content;
- // mid
+ /* mid */
return (container - content) * 0.5f;
}
@@ -2971,7 +2972,7 @@ static void nsvg__scaleToViewbox(NSVGparser* p, const char* units)
int i;
float* pt;
- // Guess image size if not set completely.
+ /* Guess image size if not set completely. */
nsvg__imageBounds(p, bounds);
if (p->viewWidth == 0) {
@@ -2999,23 +3000,23 @@ static void nsvg__scaleToViewbox(NSVGparser* p, const char* units)
ty = -p->viewMiny;
sx = p->viewWidth > 0 ? p->image->width / p->viewWidth : 0;
sy = p->viewHeight > 0 ? p->image->height / p->viewHeight : 0;
- // Unit scaling
+ /* Unit scaling */
us = 1.0f / nsvg__convertToPixels(p, nsvg__coord(1.0f, nsvg__parseUnits(units)), 0.0f, 1.0f);
- // Fix aspect ratio
+ /* Fix aspect ratio */
if (p->alignType == NSVG_ALIGN_MEET) {
- // fit whole image into viewbox
+ /* fit whole image into viewbox */
sx = sy = nsvg__minf(sx, sy);
tx += nsvg__viewAlign(p->viewWidth*sx, p->image->width, p->alignX) / sx;
ty += nsvg__viewAlign(p->viewHeight*sy, p->image->height, p->alignY) / sy;
} else if (p->alignType == NSVG_ALIGN_SLICE) {
- // fill whole viewbox with image
+ /* fill whole viewbox with image */
sx = sy = nsvg__maxf(sx, sy);
tx += nsvg__viewAlign(p->viewWidth*sx, p->image->width, p->alignX) / sx;
ty += nsvg__viewAlign(p->viewHeight*sy, p->image->height, p->alignY) / sy;
}
- // Transform
+ /* Transform */
sx *= us;
sy *= us;
avgs = (sx+sy) / 2.0f;
@@ -3068,7 +3069,7 @@ NSVGimage* nsvgParse(char* input, const char* units, float dpi)
nsvg__parseXML(input, nsvg__startElement, nsvg__endElement, nsvg__content, p);
- // Scale to viewBox
+ /* Scale to viewBox */
nsvg__scaleToViewbox(p, units);
ret = p->image;
@@ -3095,7 +3096,7 @@ NSVGimage* nsvgParseFromFile(const char* filename, const char* units, float dpi)
data = (char*)NANOSVG_malloc(size+1);
if (data == NULL) goto error;
if (fread(data, 1, size, fp) != size) goto error;
- data[size] = '\0'; // Must be null terminated.
+ data[size] = '\0'; /* Must be null terminated. */
fclose(fp);
image = nsvgParse(data, units, dpi);
NANOSVG_free(data);
diff --git a/generic/nanosvgrast.h b/generic/nanosvgrast.h
index 2720ce5..b288bcf 100644
--- a/generic/nanosvgrast.h
+++ b/generic/nanosvgrast.h
@@ -59,23 +59,24 @@ typedef struct NSVGrasterizer NSVGrasterizer;
nsvgRasterize(rast, image, 0,0,1, img, w, h, w*4);
*/
-// Allocated rasterizer context.
+/* Allocated rasterizer context. */
NANOSVG_SCOPE NSVGrasterizer* nsvgCreateRasterizer(void);
-// Rasterizes SVG image, returns RGBA image (non-premultiplied alpha)
-// r - pointer to rasterizer context
-// image - pointer to image to rasterize
-// tx,ty - image offset (applied after scaling)
-// scale - image scale
-// dst - pointer to destination image data, 4 bytes per pixel (RGBA)
-// w - width of the image to render
-// h - height of the image to render
-// stride - number of bytes per scaleline in the destination buffer
+/* Rasterizes SVG image, returns RGBA image (non-premultiplied alpha)
+ * r - pointer to rasterizer context
+ * image - pointer to image to rasterize
+ * tx,ty - image offset (applied after scaling)
+ * scale - image scale
+ * dst - pointer to destination image data, 4 bytes per pixel (RGBA)
+ * w - width of the image to render
+ * h - height of the image to render
+ * stride - number of bytes per scaleline in the destination buffer
NANOSVG_SCOPE void nsvgRasterize(NSVGrasterizer* r,
NSVGimage* image, float tx, float ty, float scale,
unsigned char* dst, int w, int h, int stride);
+ */
-// Deletes rasterizer context.
+/* Deletes rasterizer context. */
NANOSVG_SCOPE void nsvgDeleteRasterizer(NSVGrasterizer*);
@@ -83,7 +84,7 @@ NANOSVG_SCOPE void nsvgDeleteRasterizer(NSVGrasterizer*);
}
#endif
-#endif // NANOSVGRAST_H
+#endif /* NANOSVGRAST_H */
#ifdef NANOSVGRAST_IMPLEMENTATION
@@ -202,17 +203,17 @@ static NSVGmemPage* nsvg__nextPage(NSVGrasterizer* r, NSVGmemPage* cur)
{
NSVGmemPage *newp;
- // If using existing chain, return the next page in chain
+ /* If using existing chain, return the next page in chain */
if (cur != NULL && cur->next != NULL) {
return cur->next;
}
- // Alloc new page
+ /* Alloc new page */
newp = (NSVGmemPage*)NANOSVG_malloc(sizeof(NSVGmemPage));
if (newp == NULL) return NULL;
memset(newp, 0, sizeof(NSVGmemPage));
- // Add to linked list
+ /* Add to linked list */
if (cur != NULL)
cur->next = newp;
else
@@ -302,7 +303,7 @@ static void nsvg__addEdge(NSVGrasterizer* r, float x0, float y0, float x1, float
{
NSVGedge* e;
- // Skip horizontal edges
+ /* Skip horizontal edges */
if (y0 == y1)
return;
@@ -388,15 +389,15 @@ static void nsvg__flattenShape(NSVGrasterizer* r, NSVGshape* shape, float scale)
for (path = shape->paths; path != NULL; path = path->next) {
r->npoints = 0;
- // Flatten path
+ /* Flatten path */
nsvg__addPathPoint(r, path->pts[0]*scale, path->pts[1]*scale, 0);
for (i = 0; i < path->npts-1; i += 3) {
float* p = &path->pts[i*2];
nsvg__flattenCubicBez(r, p[0]*scale,p[1]*scale, p[2]*scale,p[3]*scale, p[4]*scale,p[5]*scale, p[6]*scale,p[7]*scale, 0, 0);
}
- // Close path
+ /* Close path */
nsvg__addPathPoint(r, path->pts[0]*scale, path->pts[1]*scale, 0);
- // Build edges
+ /* Build edges */
for (i = 0, j = r->npoints-1; i < r->npoints; j = i++)
nsvg__addEdge(r, r->points[j].x, r->points[j].y, r->points[i].x, r->points[i].y);
}
@@ -619,20 +620,20 @@ static int nsvg__curveDivs(float r, float arc, float tol)
static void nsvg__expandStroke(NSVGrasterizer* r, NSVGpoint* points, int npoints, int closed, int lineJoin, int lineCap, float lineWidth)
{
- int ncap = nsvg__curveDivs(lineWidth*0.5f, NSVG_PI, r->tessTol); // Calculate divisions per half circle.
+ int ncap = nsvg__curveDivs(lineWidth*0.5f, NSVG_PI, r->tessTol); /* Calculate divisions per half circle. */
NSVGpoint left = {0,0,0,0,0,0,0,0}, right = {0,0,0,0,0,0,0,0}, firstLeft = {0,0,0,0,0,0,0,0}, firstRight = {0,0,0,0,0,0,0,0};
NSVGpoint* p0, *p1;
int j, s, e;
- // Build stroke edges
+ /* Build stroke edges */
if (closed) {
- // Looping
+ /* Looping */
p0 = &points[npoints-1];
p1 = &points[0];
s = 0;
e = npoints;
} else {
- // Add cap
+ /* Add cap */
p0 = &points[0];
p1 = &points[1];
s = 1;
@@ -644,7 +645,7 @@ static void nsvg__expandStroke(NSVGrasterizer* r, NSVGpoint* points, int npoints
firstLeft = left;
firstRight = right;
} else {
- // Add cap
+ /* Add cap */
float dx = p1->x - p0->x;
float dy = p1->y - p0->y;
nsvg__normalize(&dx, &dy);
@@ -671,11 +672,11 @@ static void nsvg__expandStroke(NSVGrasterizer* r, NSVGpoint* points, int npoints
}
if (closed) {
- // Loop it
+ /* Loop it */
nsvg__addEdge(r, firstLeft.x, firstLeft.y, left.x, left.y);
nsvg__addEdge(r, right.x, right.y, firstRight.x, firstRight.y);
} else {
- // Add cap
+ /* Add cap */
float dx = p1->x - p0->x;
float dy = p1->y - p0->y;
nsvg__normalize(&dx, &dy);
@@ -696,15 +697,15 @@ static void nsvg__prepareStroke(NSVGrasterizer* r, float miterLimit, int lineJoi
p0 = &r->points[r->npoints-1];
p1 = &r->points[0];
for (i = 0; i < r->npoints; i++) {
- // Calculate segment direction and length
+ /* Calculate segment direction and length */
p0->dx = p1->x - p0->x;
p0->dy = p1->y - p0->y;
p0->len = nsvg__normalize(&p0->dx, &p0->dy);
- // Advance
+ /* Advance */
p0 = p1++;
}
- // calculate joins
+ /* calculate joins */
p0 = &r->points[r->npoints-1];
p1 = &r->points[0];
for (j = 0; j < r->npoints; j++) {
@@ -713,7 +714,7 @@ static void nsvg__prepareStroke(NSVGrasterizer* r, float miterLimit, int lineJoi
dly0 = -p0->dx;
dlx1 = p1->dy;
dly1 = -p1->dx;
- // Calculate extrusions
+ /* Calculate extrusions */
p1->dmx = (dlx0 + dlx1) * 0.5f;
p1->dmy = (dly0 + dly1) * 0.5f;
dmr2 = p1->dmx*p1->dmx + p1->dmy*p1->dmy;
@@ -726,15 +727,15 @@ static void nsvg__prepareStroke(NSVGrasterizer* r, float miterLimit, int lineJoi
p1->dmy *= s2;
}
- // Clear flags, but keep the corner.
+ /* Clear flags, but keep the corner. */
p1->flags = (p1->flags & NSVG_PT_CORNER) ? NSVG_PT_CORNER : 0;
- // Keep track of left turns.
+ /* Keep track of left turns. */
cross = p1->dx * p0->dy - p0->dx * p1->dy;
if (cross > 0.0f)
p1->flags |= NSVG_PT_LEFT;
- // Check to see if the corner needs to be beveled.
+ /* Check to see if the corner needs to be beveled. */
if (p1->flags & NSVG_PT_CORNER) {
if ((dmr2 * miterLimit*miterLimit) < 1.0f || lineJoin == NSVG_JOIN_BEVEL || lineJoin == NSVG_JOIN_ROUND) {
p1->flags |= NSVG_PT_BEVEL;
@@ -756,7 +757,7 @@ static void nsvg__flattenShapeStroke(NSVGrasterizer* r, NSVGshape* shape, float
float lineWidth = shape->strokeWidth * scale;
for (path = shape->paths; path != NULL; path = path->next) {
- // Flatten path
+ /* Flatten path */
r->npoints = 0;
nsvg__addPathPoint(r, path->pts[0]*scale, path->pts[1]*scale, NSVG_PT_CORNER);
for (i = 0; i < path->npts-1; i += 3) {
@@ -768,7 +769,7 @@ static void nsvg__flattenShapeStroke(NSVGrasterizer* r, NSVGshape* shape, float
closed = path->closed;
- // If the first and last points are the same, remove the last, mark as closed path.
+ /* If the first and last points are the same, remove the last, mark as closed path. */
p0 = &r->points[r->npoints-1];
p1 = &r->points[0];
if (nsvg__ptEquals(p0->x,p0->y, p1->x,p1->y, r->distTol)) {
@@ -785,20 +786,20 @@ static void nsvg__flattenShapeStroke(NSVGrasterizer* r, NSVGshape* shape, float
if (closed)
nsvg__appendPathPoint(r, r->points[0]);
- // Duplicate points -> points2.
+ /* Duplicate points -> points2. */
nsvg__duplicatePoints(r);
r->npoints = 0;
cur = r->points2[0];
nsvg__appendPathPoint(r, cur);
- // Figure out dash offset.
+ /* Figure out dash offset. */
allDashLen = 0;
for (j = 0; j < shape->strokeDashCount; j++)
allDashLen += shape->strokeDashArray[j];
if (shape->strokeDashCount & 1)
allDashLen *= 2.0f;
- // Find location inside pattern
+ /* Find location inside pattern */
dashOffset = fmodf(shape->strokeDashOffset, allDashLen);
if (dashOffset < 0.0f)
dashOffset += allDashLen;
@@ -815,22 +816,22 @@ static void nsvg__flattenShapeStroke(NSVGrasterizer* r, NSVGshape* shape, float
float dist = sqrtf(dx*dx + dy*dy);
if ((totalDist + dist) > dashLen) {
- // Calculate intermediate point
+ /* Calculate intermediate point */
float d = (dashLen - totalDist) / dist;
float x = cur.x + dx * d;
float y = cur.y + dy * d;
nsvg__addPathPoint(r, x, y, NSVG_PT_CORNER);
- // Stroke
+ /* Stroke */
if (r->npoints > 1 && dashState) {
nsvg__prepareStroke(r, miterLimit, lineJoin);
nsvg__expandStroke(r, r->points, r->npoints, 0, lineJoin, lineCap, lineWidth);
}
- // Advance dash pattern
+ /* Advance dash pattern */
dashState = !dashState;
idash = (idash+1) % shape->strokeDashCount;
dashLen = shape->strokeDashArray[idash] * scale;
- // Restart
+ /* Restart */
cur.x = x;
cur.y = y;
cur.flags = NSVG_PT_CORNER;
@@ -844,7 +845,7 @@ static void nsvg__flattenShapeStroke(NSVGrasterizer* r, NSVGshape* shape, float
j++;
}
}
- // Stroke any leftover path
+ /* Stroke any leftover path */
if (r->npoints > 1 && dashState)
nsvg__expandStroke(r, r->points, r->npoints, 0, lineJoin, lineCap, lineWidth);
} else {
@@ -871,24 +872,24 @@ static NSVGactiveEdge* nsvg__addActive(NSVGrasterizer* r, NSVGedge* e, float sta
float dxdy;
if (r->freelist != NULL) {
- // Restore from freelist.
+ /* Restore from freelist. */
z = r->freelist;
r->freelist = z->next;
} else {
- // Alloc new edge.
+ /* Alloc new edge. */
z = (NSVGactiveEdge*)nsvg__alloc(r, sizeof(NSVGactiveEdge));
if (z == NULL) return NULL;
}
dxdy = (e->x1 - e->x0) / (e->y1 - e->y0);
-// STBTT_assert(e->y0 <= start_point);
- // round dx down to avoid going too far
+/* STBTT_assert(e->y0 <= start_point); */
+ /* round dx down to avoid going too far */
if (dxdy < 0)
z->dx = (int)(-floorf(NSVG__FIX * -dxdy));
else
z->dx = (int)floorf(NSVG__FIX * dxdy);
z->x = (int)floorf(NSVG__FIX * (e->x0 + dxdy * (startPoint - e->y0)));
-// z->x -= off_x * FIX;
+/* z->x -= off_x * FIX; */
z->ey = e->y1;
z->next = 0;
z->dir = e->dir;
@@ -910,52 +911,53 @@ static void nsvg__fillScanline(unsigned char* scanline, int len, int x0, int x1,
if (j > *xmax) *xmax = j;
if (i < len && j >= 0) {
if (i == j) {
- // x0,x1 are the same pixel, so compute combined coverage
+ /* x0,x1 are the same pixel, so compute combined coverage */
scanline[i] = (unsigned char)(scanline[i] + ((x1 - x0) * maxWeight >> NSVG__FIXSHIFT));
} else {
- if (i >= 0) // add antialiasing for x0
+ if (i >= 0) /* add antialiasing for x0 */
scanline[i] = (unsigned char)(scanline[i] + (((NSVG__FIX - (x0 & NSVG__FIXMASK)) * maxWeight) >> NSVG__FIXSHIFT));
else
- i = -1; // clip
+ i = -1; /* clip */
- if (j < len) // add antialiasing for x1
+ if (j < len) /* add antialiasing for x1 */
scanline[j] = (unsigned char)(scanline[j] + (((x1 & NSVG__FIXMASK) * maxWeight) >> NSVG__FIXSHIFT));
else
- j = len; // clip
+ j = len; /* clip */
- for (++i; i < j; ++i) // fill pixels between x0 and x1
+ for (++i; i < j; ++i) /* fill pixels between x0 and x1 */
scanline[i] = (unsigned char)(scanline[i] + maxWeight);
}
}
}
-// note: this routine clips fills that extend off the edges... ideally this
-// wouldn't happen, but it could happen if the truetype glyph bounding boxes
-// are wrong, or if the user supplies a too-small bitmap
+/* note: this routine clips fills that extend off the edges... ideally this
+ * wouldn't happen, but it could happen if the truetype glyph bounding boxes
+ * are wrong, or if the user supplies a too-small bitmap
+ */
static void nsvg__fillActiveEdges(unsigned char* scanline, int len, NSVGactiveEdge* e, int maxWeight, int* xmin, int* xmax, char fillRule)
{
- // non-zero winding fill
+ /* non-zero winding fill */
int x0 = 0, w = 0;
if (fillRule == NSVG_FILLRULE_NONZERO) {
- // Non-zero
+ /* Non-zero */
while (e != NULL) {
if (w == 0) {
- // if we're currently at zero, we need to record the edge start point
+ /* if we're currently at zero, we need to record the edge start point */
x0 = e->x; w += e->dir;
} else {
int x1 = e->x; w += e->dir;
- // if we went to zero, we need to draw
+ /* if we went to zero, we need to draw */
if (w == 0)
nsvg__fillScanline(scanline, len, x0, x1, maxWeight, xmin, xmax);
}
e = e->next;
}
} else if (fillRule == NSVG_FILLRULE_EVENODD) {
- // Even-odd
+ /* Even-odd */
while (e != NULL) {
if (w == 0) {
- // if we're currently at zero, we need to record the edge start point
+ /* if we're currently at zero, we need to record the edge start point */
x0 = e->x; w = 1;
} else {
int x1 = e->x; w = 0;
@@ -1013,12 +1015,12 @@ static void nsvg__scanlineSolid(unsigned char* dst, int count, unsigned char* co
int r,g,b;
int a = nsvg__div255((int)cover[0] * ca);
int ia = 255 - a;
- // Premultiply
+ /* Premultiply */
r = nsvg__div255(cr * a);
g = nsvg__div255(cg * a);
b = nsvg__div255(cb * a);
- // Blend over
+ /* Blend over */
r += nsvg__div255(ia * (int)dst[0]);
g += nsvg__div255(ia * (int)dst[1]);
b += nsvg__div255(ia * (int)dst[2]);
@@ -1033,8 +1035,8 @@ static void nsvg__scanlineSolid(unsigned char* dst, int count, unsigned char* co
dst += 4;
}
} else if (cache->type == NSVG_PAINT_LINEAR_GRADIENT) {
- // TODO: spread modes.
- // TODO: plenty of opportunities to optimize.
+ /* TODO: spread modes. */
+ /* TODO: plenty of opportunities to optimize. */
float fx, fy, dx, gy;
float* t = cache->xform;
int i, cr, cg, cb, ca;
@@ -1056,12 +1058,12 @@ static void nsvg__scanlineSolid(unsigned char* dst, int count, unsigned char* co
a = nsvg__div255((int)cover[0] * ca);
ia = 255 - a;
- // Premultiply
+ /* Premultiply */
r = nsvg__div255(cr * a);
g = nsvg__div255(cg * a);
b = nsvg__div255(cb * a);
- // Blend over
+ /* Blend over */
r += nsvg__div255(ia * (int)dst[0]);
g += nsvg__div255(ia * (int)dst[1]);
b += nsvg__div255(ia * (int)dst[2]);
@@ -1077,9 +1079,9 @@ static void nsvg__scanlineSolid(unsigned char* dst, int count, unsigned char* co
fx += dx;
}
} else if (cache->type == NSVG_PAINT_RADIAL_GRADIENT) {
- // TODO: spread modes.
- // TODO: plenty of opportunities to optimize.
- // TODO: focus (fx,fy)
+ /* TODO: spread modes. */
+ /* TODO: plenty of opportunities to optimize. */
+ /* TODO: focus (fx,fy) */
float fx, fy, dx, gx, gy, gd;
float* t = cache->xform;
int i, cr, cg, cb, ca;
@@ -1103,12 +1105,12 @@ static void nsvg__scanlineSolid(unsigned char* dst, int count, unsigned char* co
a = nsvg__div255((int)cover[0] * ca);
ia = 255 - a;
- // Premultiply
+ /* Premultiply */
r = nsvg__div255(cr * a);
g = nsvg__div255(cg * a);
b = nsvg__div255(cb * a);
- // Blend over
+ /* Blend over */
r += nsvg__div255(ia * (int)dst[0]);
g += nsvg__div255(ia * (int)dst[1]);
b += nsvg__div255(ia * (int)dst[2]);
@@ -1131,7 +1133,7 @@ static void nsvg__rasterizeSortedEdges(NSVGrasterizer *r, float tx, float ty, fl
NSVGactiveEdge *active = NULL;
int y, s;
int e = 0;
- int maxWeight = (255 / NSVG__SUBSAMPLES); // weight per vertical scanline
+ int maxWeight = (255 / NSVG__SUBSAMPLES); /* weight per vertical scanline */
int xmin, xmax;
for (y = 0; y < r->height; y++) {
@@ -1139,25 +1141,25 @@ static void nsvg__rasterizeSortedEdges(NSVGrasterizer *r, float tx, float ty, fl
xmin = r->width;
xmax = 0;
for (s = 0; s < NSVG__SUBSAMPLES; ++s) {
- // find center of pixel for this scanline
+ /* find center of pixel for this scanline */
float scany = (float)(y*NSVG__SUBSAMPLES + s) + 0.5f;
NSVGactiveEdge **step = &active;
- // update all active edges;
- // remove all active edges that terminate before the center of this scanline
+ /* update all active edges; */
+ /* remove all active edges that terminate before the center of this scanline */
while (*step) {
NSVGactiveEdge *z = *step;
if (z->ey <= scany) {
- *step = z->next; // delete from list
-// NSVG__assert(z->valid);
+ *step = z->next; /* delete from list */
+/* NSVG__assert(z->valid); */
nsvg__freeActive(r, z);
} else {
- z->x += z->dx; // advance to position for current scanline
- step = &((*step)->next); // advance through list
+ z->x += z->dx; /* advance to position for current scanline */
+ step = &((*step)->next); /* advance through list */
}
}
- // resort the list if needed
+ /* resort the list if needed */
for (;;) {
int changed = 0;
step = &active;
@@ -1175,24 +1177,24 @@ static void nsvg__rasterizeSortedEdges(NSVGrasterizer *r, float tx, float ty, fl
if (!changed) break;
}
- // insert all edges that start before the center of this scanline -- omit ones that also end on this scanline
+ /* insert all edges that start before the center of this scanline -- omit ones that also end on this scanline */
while (e < r->nedges && r->edges[e].y0 <= scany) {
if (r->edges[e].y1 > scany) {
NSVGactiveEdge* z = nsvg__addActive(r, &r->edges[e], scany);
if (z == NULL) break;
- // find insertion point
+ /* find insertion point */
if (active == NULL) {
active = z;
} else if (z->x < active->x) {
- // insert at front
+ /* insert at front */
z->next = active;
active = z;
} else {
- // find thing to insert AFTER
+ /* find thing to insert AFTER */
NSVGactiveEdge* p = active;
while (p->next && p->next->x < z->x)
p = p->next;
- // at this point, p->next->x is NOT < z->x
+ /* at this point, p->next->x is NOT < z->x */
z->next = p->next;
p->next = z;
}
@@ -1200,11 +1202,11 @@ static void nsvg__rasterizeSortedEdges(NSVGrasterizer *r, float tx, float ty, fl
e++;
}
- // now process all active edges in non-zero fashion
+ /* now process all active edges in non-zero fashion */
if (active != NULL)
nsvg__fillActiveEdges(r->scanline, r->width, active, maxWeight, &xmin, &xmax, fillRule);
}
- // Blit
+ /* Blit */
if (xmin < 0) xmin = 0;
if (xmax > r->width-1) xmax = r->width-1;
if (xmin <= xmax) {
@@ -1218,7 +1220,7 @@ static void nsvg__unpremultiplyAlpha(unsigned char* image, int w, int h, int str
{
int x,y;
- // Unpremultiply
+ /* Unpremultiply */
for (y = 0; y < h; y++) {
unsigned char *row = &image[y*stride];
for (x = 0; x < w; x++) {
@@ -1232,7 +1234,7 @@ static void nsvg__unpremultiplyAlpha(unsigned char* image, int w, int h, int str
}
}
- // Defringe
+ /* Defringe */
for (y = 0; y < h; y++) {
unsigned char *row = &image[y*stride];
for (x = 0; x < w; x++) {
@@ -1411,7 +1413,7 @@ void nsvgRasterize(NSVGrasterizer* r,
nsvg__flattenShape(r, shape, scale);
- // Scale and translate edges
+ /* Scale and translate edges */
for (i = 0; i < r->nedges; i++) {
e = &r->edges[i];
e->x0 = tx + e->x0;
@@ -1420,10 +1422,10 @@ void nsvgRasterize(NSVGrasterizer* r,
e->y1 = (ty + e->y1) * NSVG__SUBSAMPLES;
}
- // Rasterize edges
+ /* Rasterize edges */
qsort(r->edges, r->nedges, sizeof(NSVGedge), nsvg__cmpEdge);
- // now, traverse the scanlines and find the intersections on each scanline, use non-zero rule
+ /* now, traverse the scanlines and find the intersections on each scanline, use non-zero rule */
nsvg__initPaint(&cache, &shape->fill, shape->opacity);
nsvg__rasterizeSortedEdges(r, tx,ty,scale, &cache, shape->fillRule);
@@ -1435,9 +1437,9 @@ void nsvgRasterize(NSVGrasterizer* r,
nsvg__flattenShapeStroke(r, shape, scale);
-// dumpEdges(r, "edge.svg");
+/* dumpEdges(r, "edge.svg"); */
- // Scale and translate edges
+ /* Scale and translate edges */
for (i = 0; i < r->nedges; i++) {
e = &r->edges[i];
e->x0 = tx + e->x0;
@@ -1446,10 +1448,10 @@ void nsvgRasterize(NSVGrasterizer* r,
e->y1 = (ty + e->y1) * NSVG__SUBSAMPLES;
}
- // Rasterize edges
+ /* Rasterize edges */
qsort(r->edges, r->nedges, sizeof(NSVGedge), nsvg__cmpEdge);
- // now, traverse the scanlines and find the intersections on each scanline, use non-zero rule
+ /* now, traverse the scanlines and find the intersections on each scanline, use non-zero rule */
nsvg__initPaint(&cache, &shape->stroke, shape->opacity);
nsvg__rasterizeSortedEdges(r, tx,ty,scale, &cache, NSVG_FILLRULE_NONZERO);
diff --git a/generic/tkCanvUtil.c b/generic/tkCanvUtil.c
index a1fe265..b092df6 100644
--- a/generic/tkCanvUtil.c
+++ b/generic/tkCanvUtil.c
@@ -774,7 +774,7 @@ TkSmoothParseProc(
}
/*
- * Backward compatability hack.
+ * Backward compatibility hack.
*/
if (strncmp(value, "bezier", length) == 0) {
diff --git a/generic/tkImgPhoto.c b/generic/tkImgPhoto.c
index 51083e6..89dbb4c 100644
--- a/generic/tkImgPhoto.c
+++ b/generic/tkImgPhoto.c
@@ -4082,7 +4082,7 @@ ImgPhotoPostscript(
*
* Tk_PhotoPutBlock_NoComposite, Tk_PhotoPutZoomedBlock_NoComposite --
*
- * These backward-compatability functions just exist to fill slots in stubs
+ * These backward-compatibility functions just exist to fill slots in stubs
* table. For the behaviour of *_NoComposite, refer to the corresponding
* function without the extra suffix, except that the compositing rule is
* always "overlay" and the function always panics on memory-allocation
@@ -4123,7 +4123,7 @@ Tk_PhotoPutZoomedBlock_NoComposite(
* Tk_PhotoExpand_Panic, Tk_PhotoPutBlock_Panic,
* Tk_PhotoPutZoomedBlock_Panic, Tk_PhotoSetSize_Panic
*
- * Backward compatability functions for preserving the old behaviour (i.e.
+ * Backward compatibility functions for preserving the old behaviour (i.e.
* panic on memory allocation failure) so that extensions do not need to be
* significantly updated to take account of TIP #116. These call the new
* interface (i.e. the interface without the extra suffix), but panic if an
diff --git a/generic/tkScrollbar.c b/generic/tkScrollbar.c
index 86ec25a..d646434 100644
--- a/generic/tkScrollbar.c
+++ b/generic/tkScrollbar.c
@@ -226,8 +226,8 @@ ScrollbarWidgetObjCmd(
Tcl_Obj *const objv[]) /* Argument strings. */
{
TkScrollbar *scrollPtr = (TkScrollbar *)clientData;
- int result = TCL_OK, cmdIndex;
- TkSizeT length;
+ int result = TCL_OK, cmdIndex, length;
+ TkSizeT len;
static const char *const commandNames[] = {
"activate", "cget", "configure", "delta", "fraction",
"get", "identify", "set", NULL
@@ -271,13 +271,13 @@ ScrollbarWidgetObjCmd(
Tcl_WrongNumArgs(interp, 1, objv, "activate element");
goto error;
}
- c = TkGetStringFromObj(objv[2], &length)[0];
+ c = TkGetStringFromObj(objv[2], &len)[0];
oldActiveField = scrollPtr->activeField;
if ((c == 'a') && (strcmp(Tcl_GetString(objv[2]), "arrow1") == 0)) {
scrollPtr->activeField = TOP_ARROW;
} else if ((c == 'a') && (strcmp(Tcl_GetString(objv[2]), "arrow2") == 0)) {
scrollPtr->activeField = BOTTOM_ARROW;
- } else if ((c == 's') && (strncmp(Tcl_GetString(objv[2]), "slider", length) == 0)) {
+ } else if ((c == 's') && (strncmp(Tcl_GetString(objv[2]), "slider", len) == 0)) {
scrollPtr->activeField = SLIDER;
} else {
scrollPtr->activeField = OUTSIDE;
diff --git a/library/console.tcl b/library/console.tcl
index 1763584..1da85be 100644
--- a/library/console.tcl
+++ b/library/console.tcl
@@ -215,7 +215,7 @@ proc ::tk::ConsoleSource {} {
[list [mc "Tcl Scripts"] .tcl] \
[list [mc "All Files"] *]]]
if {$filename ne ""} {
- set cmd [list source $filename]
+ set cmd [list source -encoding utf-8 $filename]
if {[catch {consoleinterp eval $cmd} result]} {
ConsoleOutput stderr "$result\n"
}
@@ -592,7 +592,7 @@ proc ::tk::ConsoleBind {w} {
}
bind Console <F9> {
eval destroy [winfo child .]
- source [file join $tk_library console.tcl]
+ source -encoding utf-8 [file join $tk_library console.tcl]
}
if {[tk windowingsystem] eq "aqua"} {
bind Console <Command-q> {
diff --git a/library/tk.tcl b/library/tk.tcl
index 895dccf..adcb364 100644
--- a/library/tk.tcl
+++ b/library/tk.tcl
@@ -493,7 +493,7 @@ switch -exact -- [tk windowingsystem] {
if {$::tk_library ne ""} {
proc ::tk::SourceLibFile {file} {
- namespace eval :: [list source [file join $::tk_library $file.tcl]]
+ namespace eval :: [list source -encoding utf-8 [file join $::tk_library $file.tcl]]
}
namespace eval ::tk {
SourceLibFile icons
@@ -693,7 +693,7 @@ if {[tk windowingsystem] eq "aqua"} {
#stub procedures to respond to "do script" Apple Events
proc ::tk::mac::DoScriptFile {file} {
uplevel #0 $file
- source $file
+ source -encoding utf-8 $file
}
proc ::tk::mac::DoScriptText {script} {
uplevel #0 $script
@@ -708,7 +708,7 @@ set ::tk::Priv(IMETextMark) [dict create]
# Run the Ttk themed widget set initialization
if {$::ttk::library ne ""} {
- uplevel \#0 [list source $::ttk::library/ttk.tcl]
+ uplevel \#0 [list source -encoding utf-8 $::ttk::library/ttk.tcl]
}
# Local Variables:
diff --git a/library/ttk/ttk.tcl b/library/ttk/ttk.tcl
index 665222d..73ee3d9 100644
--- a/library/ttk/ttk.tcl
+++ b/library/ttk/ttk.tcl
@@ -12,9 +12,9 @@ namespace eval ::ttk {
}
}
-source [file join $::ttk::library fonts.tcl]
-source [file join $::ttk::library cursors.tcl]
-source [file join $::ttk::library utils.tcl]
+source -encoding utf-8 [file join $::ttk::library fonts.tcl]
+source -encoding utf-8 [file join $::ttk::library cursors.tcl]
+source -encoding utf-8 [file join $::ttk::library utils.tcl]
## ttk::deprecated $old $new --
# Define $old command as a deprecated alias for $new command
@@ -97,18 +97,18 @@ proc ::ttk::setTheme {theme} {
### Load widget bindings.
#
-source [file join $::ttk::library button.tcl]
-source [file join $::ttk::library menubutton.tcl]
-source [file join $::ttk::library scrollbar.tcl]
-source [file join $::ttk::library scale.tcl]
-source [file join $::ttk::library progress.tcl]
-source [file join $::ttk::library notebook.tcl]
-source [file join $::ttk::library panedwindow.tcl]
-source [file join $::ttk::library entry.tcl]
-source [file join $::ttk::library combobox.tcl] ;# dependency: entry.tcl
-source [file join $::ttk::library spinbox.tcl] ;# dependency: entry.tcl
-source [file join $::ttk::library treeview.tcl]
-source [file join $::ttk::library sizegrip.tcl]
+source -encoding utf-8 [file join $::ttk::library button.tcl]
+source -encoding utf-8 [file join $::ttk::library menubutton.tcl]
+source -encoding utf-8 [file join $::ttk::library scrollbar.tcl]
+source -encoding utf-8 [file join $::ttk::library scale.tcl]
+source -encoding utf-8 [file join $::ttk::library progress.tcl]
+source -encoding utf-8 [file join $::ttk::library notebook.tcl]
+source -encoding utf-8 [file join $::ttk::library panedwindow.tcl]
+source -encoding utf-8 [file join $::ttk::library entry.tcl]
+source -encoding utf-8 [file join $::ttk::library combobox.tcl] ;# dependency: entry.tcl
+source -encoding utf-8 [file join $::ttk::library spinbox.tcl] ;# dependency: entry.tcl
+source -encoding utf-8 [file join $::ttk::library treeview.tcl]
+source -encoding utf-8 [file join $::ttk::library sizegrip.tcl]
## Label and Labelframe bindings:
# (not enough to justify their own file...)
@@ -122,7 +122,7 @@ proc ttk::LoadThemes {} {
variable library
# "default" always present:
- uplevel #0 [list source [file join $library defaults.tcl]]
+ uplevel #0 [list source -encoding utf-8 [file join $library defaults.tcl]]
set builtinThemes [style theme names]
foreach {theme scripts} {
@@ -135,7 +135,7 @@ proc ttk::LoadThemes {} {
} {
if {[lsearch -exact $builtinThemes $theme] >= 0} {
foreach script $scripts {
- uplevel #0 [list source [file join $library $script]]
+ uplevel #0 [list source -encoding utf-8 [file join $library $script]]
}
}
}
diff --git a/macosx/tkMacOSXDialog.c b/macosx/tkMacOSXDialog.c
index d9f098c..478da71 100644
--- a/macosx/tkMacOSXDialog.c
+++ b/macosx/tkMacOSXDialog.c
@@ -23,7 +23,7 @@
#define modalOK NSModalResponseOK
#define modalCancel NSModalResponseCancel
#endif // MAC_OS_X_VERSION_MIN_REQUIRED < 1090
-#define modalOther -1
+#define modalOther -1 // indicates that the -command option was used.
#define modalError -2
/*
@@ -52,6 +52,10 @@ typedef struct {
* filter. */
} filepanelFilterInfo;
+/*
+ * Only one of these is needed for the application, so they can be static.
+ */
+
static filepanelFilterInfo filterInfo;
static NSOpenPanel *openpanel;
static NSSavePanel *savepanel;
@@ -250,13 +254,13 @@ getFileURL(
} else if (returnCode == modalCancel) {
Tcl_ResetResult(callbackInfo->interp);
}
- if (panel == [NSApp modalWindow]) {
- [NSApp stopModalWithCode:returnCode];
- }
if (callbackInfo->cmdObj) {
Tcl_DecrRefCount(callbackInfo->cmdObj);
+ }
+ if (callbackInfo) {
ckfree(callbackInfo);
}
+ [NSApp stopModalWithCode:returnCode];
}
- (void) tkAlertDidEnd: (NSAlert *) alert returnCode: (NSInteger) returnCode
@@ -346,26 +350,52 @@ static NSInteger showOpenSavePanel(
NSWindow *parent,
FilePanelCallbackInfo *callbackInfo)
{
- __block NSInteger modalReturnCode = modalOther;
+ NSInteger modalReturnCode;
if (parent && ![parent attachedSheet]) {
[panel beginSheetModalForWindow:parent
- completionHandler:^(NSModalResponse result) {
- [NSApp tkFilePanelDidEnd:panel
- returnCode:result
- contextInfo:callbackInfo ];
- modalReturnCode = result;
+ completionHandler:^(NSModalResponse returnCode) {
+ [NSApp tkFilePanelDidEnd:panel
+ returnCode:returnCode
+ contextInfo:callbackInfo ];
}];
+
+ /*
+ * The sheet has been prepared, so now we have to run it as a modal
+ * window. Using [NSApp runModalForWindow:] on macOS 10.15 or later
+ * generates warnings on stderr. But using [NSOpenPanel runModal] or
+ * [NSSavePanel runModal] on 10.14 or earler does not cause the
+ * completion handler to run when the panel is closed.
+ */
+
+ if ([NSApp macOSVersion] > 101400) {
+ modalReturnCode = [panel runModal];
+ } else {
+ modalReturnCode = [NSApp runModalForWindow:panel];
+ }
} else {
- [panel beginWithCompletionHandler:^(NSModalResponse result) {
- [NSApp tkFilePanelDidEnd:panel
- returnCode:result
- contextInfo:callbackInfo ];
- modalReturnCode = result;
+
+ /*
+ * For the standalone file dialog, completion handlers do not work
+ * at all on macOS 10.14 and earlier.
+ */
+
+ if ([NSApp macOSVersion] > 101400) {
+ [panel beginWithCompletionHandler:^(NSModalResponse returnCode) {
+ [NSApp tkFilePanelDidEnd:panel
+ returnCode:returnCode
+ contextInfo:callbackInfo ];
}];
+ modalReturnCode = [panel runModal];
+ } else {
+ modalReturnCode = [panel runModal];
+ [NSApp tkFilePanelDidEnd:panel
+ returnCode:modalReturnCode
+ contextInfo:callbackInfo ];
+ [panel close];
+ }
}
- [panel runModal];
- return modalReturnCode;
+ return callbackInfo->cmdObj ? modalOther : modalReturnCode;
}
/*
diff --git a/macosx/tkMacOSXSysTray.c b/macosx/tkMacOSXSysTray.c
index 64a86f3..6fb607d 100644
--- a/macosx/tkMacOSXSysTray.c
+++ b/macosx/tkMacOSXSysTray.c
@@ -434,7 +434,7 @@ MacSystrayDestroy(
*
* SysNotifyObjCmd --
*
- * Create system notification.
+ * Create system notification.
*
* Results:
* System notification created.
diff --git a/macosx/tkMacOSXWm.c b/macosx/tkMacOSXWm.c
index 95b84bf..77da97d 100644
--- a/macosx/tkMacOSXWm.c
+++ b/macosx/tkMacOSXWm.c
@@ -1803,7 +1803,7 @@ WmColormapwindowsCmd(
wmPtr->cmapCount = windowObjc;
/*
- * On the Macintosh all of this is just an excercise in compatability as
+ * On the Macintosh all of this is just an excercise in compatibility as
* we don't support colormaps. If we did they would be installed here.
*/
@@ -5184,7 +5184,7 @@ TkWmAddToColormapWindows(
topPtr->wmInfoPtr->cmapCount = count+1;
/*
- * On the Macintosh all of this is just an excercise in compatability as
+ * On the Macintosh all of this is just an excercise in compatibility as
* we don't support colormaps. If we did they would be installed here.
*/
}
diff --git a/tests/visual_bb.test b/tests/visual_bb.test
index eda67e4..36612a9 100644
--- a/tests/visual_bb.test
+++ b/tests/visual_bb.test
@@ -23,7 +23,7 @@ proc runTest {file} {
global testNum
test "2.$testNum" "testing $file" {userInteraction} {
- uplevel \#0 source [file join [testsDirectory] $file]
+ uplevel #0 [list source -encoding utf-8 [file join [testsDirectory] $file]]
concat ""
} {}
incr testNum
diff --git a/win/tkWinCursor.c b/win/tkWinCursor.c
index 63f3add..a8abb77 100644
--- a/win/tkWinCursor.c
+++ b/win/tkWinCursor.c
@@ -104,7 +104,7 @@ TkGetCursorByName(
/*
* All cursor names are valid lists of one element (for
- * Unix-compatability), even unadorned system cursor names.
+ * Unix-compatibility), even unadorned system cursor names.
*/
if (Tcl_SplitList(interp, string, &argc, &argv) != TCL_OK) {
diff --git a/win/tkWinDialog.c b/win/tkWinDialog.c
index 4c56760..54fb4d0 100644
--- a/win/tkWinDialog.c
+++ b/win/tkWinDialog.c
@@ -1086,7 +1086,7 @@ ParseOFNOptions(
}
ZeroMemory(optsPtr, sizeof(*optsPtr));
- // optsPtr->forceXPStyle = 1;
+ /* optsPtr->forceXPStyle = 1; */
optsPtr->tkwin = (Tk_Window)clientData;
optsPtr->confirmOverwrite = 1; /* By default we ask for confirmation */
Tcl_DStringInit(&optsPtr->utfDirString);
@@ -2711,10 +2711,10 @@ ChooseDirectoryValidateProc(
if (SHGetPathFromIDListW((LPITEMIDLIST) lParam, selDir)) {
SendMessageW(hwnd, BFFM_SETSTATUSTEXTW, 0, (LPARAM) selDir);
- // enable the OK button
+ /* enable the OK button */
SendMessageW(hwnd, BFFM_ENABLEOK, 0, (LPARAM) 1);
} else {
- // disable the OK button
+ /* disable the OK button */
SendMessageW(hwnd, BFFM_ENABLEOK, 0, (LPARAM) 0);
}
UpdateWindow(hwnd);
diff --git a/win/ttkWinXPTheme.c b/win/ttkWinXPTheme.c
index 99e523b..df04d86 100644
--- a/win/ttkWinXPTheme.c
+++ b/win/ttkWinXPTheme.c
@@ -847,7 +847,7 @@ static void TextElementSize(
Ttk_StateTableLookup(elementData->info->statemap, 0),
Tcl_UtfToWCharDString(src, len, &ds),
-1,
- DT_LEFT,// | DT_BOTTOM | DT_NOPREFIX,
+ DT_LEFT /* | DT_BOTTOM | DT_NOPREFIX */,
NULL,
&rc);
@@ -886,7 +886,7 @@ static void TextElementDraw(
Ttk_StateTableLookup(elementData->info->statemap, state),
Tcl_UtfToWCharDString(src, len, &ds),
-1,
- DT_LEFT,// | DT_BOTTOM | DT_NOPREFIX,
+ DT_LEFT /* | DT_BOTTOM | DT_NOPREFIX */,
(state & TTK_STATE_DISABLED) ? DTT_GRAYED : 0,
&rc);