summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorkx <kx@radix-linux.su>2026-10-17 16:39:23 +0300
committerkx <kx@radix-linux.su>2026-10-17 16:39:23 +0300
commitec1891d58b9514b621725620453cec0e31e18389 (patch)
tree6721f92c0afae3d933343b4a573ac8e5389827c6 /examples
parent73d23259a690cd29c0ac74a4de963e23ecfebfac (diff)
downloadsvgc-trunk.tar.xz
Version 1.1.0HEAD1.1.0trunk
Diffstat (limited to 'examples')
-rw-r--r--examples/Makefile.am2
-rw-r--r--examples/css-file/Makefile.am27
-rw-r--r--examples/css-file/README18
-rw-r--r--examples/css-file/fonts.css8
-rw-r--r--examples/css-file/main.c47
-rw-r--r--examples/css-file/view.html9
-rw-r--r--examples/oscilator/Makefile.am23
-rw-r--r--examples/oscilator/README11
-rw-r--r--examples/oscilator/main.c441
-rw-r--r--examples/oscilator/view.html41
-rw-r--r--examples/script-file/Makefile.am27
-rw-r--r--examples/script-file/README24
-rw-r--r--examples/script-file/change-color.js13
-rw-r--r--examples/script-file/main.c51
-rw-r--r--examples/script-file/view.html13
15 files changed, 755 insertions, 0 deletions
diff --git a/examples/Makefile.am b/examples/Makefile.am
new file mode 100644
index 0000000..aba3ff4
--- /dev/null
+++ b/examples/Makefile.am
@@ -0,0 +1,2 @@
+
+SUBDIRS = css-file oscilator script-file
diff --git a/examples/css-file/Makefile.am b/examples/css-file/Makefile.am
new file mode 100644
index 0000000..fdabb9a
--- /dev/null
+++ b/examples/css-file/Makefile.am
@@ -0,0 +1,27 @@
+
+AM_CFLAGS = -Wall -Wextra -Werror -std=gnu23
+AM_CPPFLAGS = -I$(top_srcdir)/src
+
+noinst_PROGRAMS = main
+noinst_DATA = example.svg
+
+main_SOURCES = main.c
+main_LDADD = $(top_builddir)/src/.libs/libsvgc.la
+
+EXTRA_DIST = fonts.css view.html
+CLEANFILES = example.svg
+
+example.svg: main $(srcdir)/fonts.css
+ @if test "$(srcdir)" != "."; then \
+ cp "$(srcdir)/fonts.css" fonts.css; \
+ cp "$(srcdir)/view.html" view.html; \
+ fi
+ ./main
+ @if test "$(srcdir)" != "."; then \
+ rm -f fonts.css; \
+ fi
+
+clean-local:
+ @if test "$(srcdir)" != "."; then \
+ rm -f view.html; \
+ fi
diff --git a/examples/css-file/README b/examples/css-file/README
new file mode 100644
index 0000000..93c43e5
--- /dev/null
+++ b/examples/css-file/README
@@ -0,0 +1,18 @@
+CSS-FILE EXAMPLE
+================
+
+Run `make` using the installed SVGC and open `view.html`.
+The program includes `fonts.css` in the generated example.svg <defs>
+section.
+
+The CSS text is embedded in example.svg, but the font files are *not*
+embedded. Place a legitimately redistributable `Roboto-Regular.woff2`
+file in the `fonts/` subdirectory next to example.svg, or use a locally
+installed Roboto font. This package intentionally does not distribute
+font binaries.
+
+Relative url(...) paths in the embedded CSS are resolved against
+example.svg, not against the original fonts.css or view.html. Some
+browsers enforce security restrictions on local file:// font loading.
+Serving the example from a local HTTP server may be needed for reliable
+font rendering.
diff --git a/examples/css-file/fonts.css b/examples/css-file/fonts.css
new file mode 100644
index 0000000..022ac3b
--- /dev/null
+++ b/examples/css-file/fonts.css
@@ -0,0 +1,8 @@
+/* The URL is resolved relative to example.svg, not relative to fonts.css. */
+@font-face {
+ font-family: 'Roboto';
+ src: local('Roboto Regular'),
+ url('./fonts/Roboto-Regular.woff2') format('woff2');
+ font-weight: 400;
+ font-style: normal;
+}
diff --git a/examples/css-file/main.c b/examples/css-file/main.c
new file mode 100644
index 0000000..5f56cd1
--- /dev/null
+++ b/examples/css-file/main.c
@@ -0,0 +1,47 @@
+/***************************************************************
+ SVGC EXAMPLE: STYLESHEET FILE
+
+ This example reads CSS once and embeds its contents into SVG defs.
+ ***************************************************************/
+
+#include <stdio.h>
+#include <svgc.h>
+
+
+int
+main( void )
+{
+ struct __svg_sheet *sheet;
+ struct __svg_scene *scene;
+ struct __svg_node *text;
+
+ sheet = (struct __svg_sheet *)__svg_new_sheet( 640, 160, 16, 16, 16, 16 );
+ if( !sheet ) return( 1 );
+
+ /* File content is copied into the sheet; no external CSS is needed later. */
+ if( __svg_sheet_add_css_file( sheet, "fonts.css" ) != 1 )
+ {
+ __svg_free_node( sheet );
+ fprintf( stderr, "Cannot add fonts.css to the SVG sheet\n" );
+ return( 1 );
+ }
+
+ scene = __svg_new_scene( sheet );
+ if( !scene )
+ {
+ __svg_free_node( sheet );
+ return( 1 );
+ }
+
+ text = __svg_new_text( 36, 90, "SVG fonts from CSS", "Roboto", 28 );
+ if( !text || __svg_scene_add_node( scene, text ) != 1 )
+ {
+ if( text ) __svg_free_node( text );
+ __svg_free_scene( scene );
+ return( 1 );
+ }
+
+ __svg_paint_scene( scene, 0, "example.svg" );
+ __svg_free_scene( scene );
+ return( 0 );
+}
diff --git a/examples/css-file/view.html b/examples/css-file/view.html
new file mode 100644
index 0000000..e82c98d
--- /dev/null
+++ b/examples/css-file/view.html
@@ -0,0 +1,9 @@
+<!doctype html>
+<html lang="en">
+<head><meta charset="utf-8"><title>SVGC embedded CSS</title></head>
+<body>
+ <object type="image/svg+xml" data="example.svg" width="640" height="160">
+ SVG preview is not available.
+ </object>
+</body>
+</html>
diff --git a/examples/oscilator/Makefile.am b/examples/oscilator/Makefile.am
new file mode 100644
index 0000000..e77c704
--- /dev/null
+++ b/examples/oscilator/Makefile.am
@@ -0,0 +1,23 @@
+
+AM_CFLAGS = -Wall -Wextra -Werror -std=gnu23
+AM_CPPFLAGS = -I$(top_srcdir)/src
+
+noinst_PROGRAMS = main
+noinst_DATA = M.svg
+
+main_SOURCES = main.c
+main_LDADD = -lm $(top_builddir)/src/.libs/libsvgc.la
+
+EXTRA_DIST = view.html
+CLEANFILES = M.svg
+
+M.svg: main
+ @if test "$(srcdir)" != "."; then \
+ cp "$(srcdir)/view.html" view.html; \
+ fi
+ ./main
+
+clean-local:
+ @if test "$(srcdir)" != "."; then \
+ rm -f view.html; \
+ fi
diff --git a/examples/oscilator/README b/examples/oscilator/README
new file mode 100644
index 0000000..b519cac
--- /dev/null
+++ b/examples/oscilator/README
@@ -0,0 +1,11 @@
+
+BUILD:
+
+ $ make
+ $ ./main
+ $ view.html
+
+
+CLEAN:
+ $ make clean
+
diff --git a/examples/oscilator/main.c b/examples/oscilator/main.c
new file mode 100644
index 0000000..813f64f
--- /dev/null
+++ b/examples/oscilator/main.c
@@ -0,0 +1,441 @@
+
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <time.h>
+#include <unistd.h>
+
+#include <math.h>
+
+#include <svgc.h>
+
+struct __svg_sheet *sheet;
+struct __svg_line *line;
+struct __svg_rect *rect;
+struct __svg_circle *circle;
+struct __svg_ellipse *ellipse;
+struct __svg_text *text;
+
+struct __svg_points *points;
+struct __svg_polygon *polygon;
+struct __svg_polyline *polyline;
+
+struct __svg_cmd *cmd;
+struct __svg_cmds *cmds;
+struct __svg_path *path;
+
+
+struct __svg_scene *scene;
+
+void arrow( double sx0, double sy0, double f0 )
+{
+ double sx1, sy1, sx2, sy2, sx3, sy3, sx4, sy4;
+ double px1, py1, px2, py2, px3, py3, px4, py4;
+
+ sx1 = sx0 - 3.0;
+ sy1 = sy0 + 3.0;
+ sx2 = sx0;
+ sy2 = sy0 - 6.0;
+ sx3 = sx0 + 3.0;
+ sy3 = sy0 + 3.0;
+ sx4 = sx0;
+ sy4 = sy0 + 1.0;
+
+ px1 = sx0 + ( sx1 - sx0 )*cos( f0 ) - ( sy1 - sy0 )*sin( f0 );
+ py1 = sy0 + ( sx1 - sx0 )*sin( f0 ) + ( sy1 - sy0 )*cos( f0 );
+ px2 = sx0 + ( sx2 - sx0 )*cos( f0 ) - ( sy2 - sy0 )*sin( f0 );
+ py2 = sy0 + ( sx2 - sx0 )*sin( f0 ) + ( sy2 - sy0 )*cos( f0 );
+ px3 = sx0 + ( sx3 - sx0 )*cos( f0 ) - ( sy3 - sy0 )*sin( f0 );
+ py3 = sy0 + ( sx3 - sx0 )*sin( f0 ) + ( sy3 - sy0 )*cos( f0 );
+ px4 = sx0 + ( sx4 - sx0 )*cos( f0 ) - ( sy4 - sy0 )*sin( f0 );
+ py4 = sy0 + ( sx4 - sx0 )*sin( f0 ) + ( sy4 - sy0 )*cos( f0 );
+
+ cmds = __svg_new_cmds();
+ __svg_add_moveto_cmd( cmds, ABSOLUTE, px1, py1 );
+ __svg_add_lineto_cmd( cmds, ABSOLUTE, px2, py2 );
+ __svg_add_lineto_cmd( cmds, ABSOLUTE, px3, py3 );
+ __svg_add_short_curveto_cmd( cmds, ABSOLUTE, px4, py4, px1, py1 );
+ __svg_add_closepath_cmd( cmds, ABSOLUTE );
+ path = (struct __svg_path *)__svg_new_path( cmds );
+ (void)__svg_set_stroke_rgb( (struct __svg_node *)path, 0, 0, 0 );
+ (void)__svg_set_stroke_width( (struct __svg_node *)path, 1.0 );
+ (void)__svg_set_stroke_linecap( (struct __svg_node *)path, "square" );
+ (void)__svg_set_stroke_linejoin( (struct __svg_node *)path, "miter" );
+ (void)__svg_set_fill_rgb( (struct __svg_node *)path, 255, 255, 255 );
+
+ (void)__svg_scene_add_node( scene, (struct __svg_node *)path );
+}
+
+void small_arrow( double sx0, double sy0, double f0 )
+{
+ double sx1, sy1, sx2, sy2, sx3, sy3, sx4, sy4;
+ double px1, py1, px2, py2, px3, py3, px4, py4;
+
+ sx1 = sx0 - 2.0;
+ sy1 = sy0 + 2.0;
+ sx2 = sx0;
+ sy2 = sy0 - 4.0;
+ sx3 = sx0 + 2.0;
+ sy3 = sy0 + 2.0;
+ sx4 = sx0;
+ sy4 = sy0 + 1.0;
+
+ px1 = sx0 + ( sx1 - sx0 )*cos( f0 ) - ( sy1 - sy0 )*sin( f0 );
+ py1 = sy0 + ( sx1 - sx0 )*sin( f0 ) + ( sy1 - sy0 )*cos( f0 );
+ px2 = sx0 + ( sx2 - sx0 )*cos( f0 ) - ( sy2 - sy0 )*sin( f0 );
+ py2 = sy0 + ( sx2 - sx0 )*sin( f0 ) + ( sy2 - sy0 )*cos( f0 );
+ px3 = sx0 + ( sx3 - sx0 )*cos( f0 ) - ( sy3 - sy0 )*sin( f0 );
+ py3 = sy0 + ( sx3 - sx0 )*sin( f0 ) + ( sy3 - sy0 )*cos( f0 );
+ px4 = sx0 + ( sx4 - sx0 )*cos( f0 ) - ( sy4 - sy0 )*sin( f0 );
+ py4 = sy0 + ( sx4 - sx0 )*sin( f0 ) + ( sy4 - sy0 )*cos( f0 );
+
+ cmds = __svg_new_cmds();
+ __svg_add_moveto_cmd( cmds, ABSOLUTE, px1, py1 );
+ __svg_add_lineto_cmd( cmds, ABSOLUTE, px2, py2 );
+ __svg_add_lineto_cmd( cmds, ABSOLUTE, px3, py3 );
+ __svg_add_short_curveto_cmd( cmds, ABSOLUTE, px4, py4, px1, py1 );
+ __svg_add_closepath_cmd( cmds, ABSOLUTE );
+ path = (struct __svg_path *)__svg_new_path( cmds );
+ (void)__svg_set_stroke_rgb( (struct __svg_node *)path, 0, 0, 0 );
+ (void)__svg_set_stroke_width( (struct __svg_node *)path, 0.5 );
+ (void)__svg_set_stroke_linecap( (struct __svg_node *)path, "square" );
+ (void)__svg_set_stroke_linejoin( (struct __svg_node *)path, "miter" );
+ (void)__svg_set_fill_rgb( (struct __svg_node *)path, 255, 255, 255 );
+
+ (void)__svg_scene_add_node( scene, (struct __svg_node *)path );
+}
+
+
+int main( void )
+{
+ int i;
+ double x0 = 100.0,
+ y0 = 30.0,
+ r0 = 250.0,
+ a0 = 60.0 * M_PI / 180.0,
+ xM, yM;
+
+ sheet = (struct __svg_sheet *)__svg_new_sheet( 350, 380, 10, 10, 10, 10 );
+ if( !sheet )
+ {
+ printf( "Unable to create sheet\n" );
+ }
+ (void)__svg_set_stroke_width( (struct __svg_node *)sheet, 1024.1236 );
+
+ scene = __svg_new_scene( sheet );
+ if( !scene )
+ {
+ printf( "Unable to create scene\n" );
+ }
+
+ __svg_set_scene_stroke( "black" );
+ __svg_set_scene_stroke_width( 1.0 );
+ __svg_set_scene_stroke_linecap( LINECAP_SQUARE );
+
+
+ rect = (struct __svg_rect *)__svg_new_rect( x0-25.0, y0-1.0, 50, 2, 0, 0 );
+ (void)__svg_set_fill_rgb( (struct __svg_node *)rect, 0, 0, 0 );
+ (void)__svg_scene_add_node( scene, (struct __svg_node *)rect );
+
+ {
+ int x1 = x0-24.0, y1 = y0-1.0, x2 = x0-18.0, y2 = y0-7.0;
+
+ for( i = 0; i < 8; ++i )
+ {
+ line = (struct __svg_line *)__svg_new_line( x1, y1, x2, y2 );
+ (void)__svg_scene_add_node( scene, (struct __svg_node *)line );
+
+ x1 += 6; x2 += 6;
+ }
+ }
+
+
+ xM = x0 + r0 * cos( a0 );
+ yM = y0 + r0 * sin( a0 );
+
+ __svg_set_scene_stroke_width( 0.5 );
+
+ line = (struct __svg_line *)__svg_new_line( x0, y0, xM, yM );
+ (void)__svg_scene_add_node( scene, (struct __svg_node *)line );
+
+ /* Set current values for newest objects: */
+ __svg_set_scene_stroke_width( 0.5 );
+ __svg_set_scene_stroke_rgb( 99, 99, 99 );
+ __svg_set_scene_stroke_dasharray( "3,2" );
+
+ line = (struct __svg_line *)__svg_new_line( x0, y0, x0, y0+r0 );
+ (void)__svg_scene_add_node( scene, (struct __svg_node *)line );
+
+ {
+ double x1, y1, x2, y2, a1 = 45.0, a2 = 75.0;
+
+ a1 = a1 * M_PI / 180.0;
+ a2 = a2 * M_PI / 180.0;
+ x1 = x0 + r0 * cos(a1);
+ y1 = y0 + r0 * sin(a1);
+ x2 = x0 - r0 * cos(a2);
+ y2 = y0 + r0 * sin(a2);
+
+ cmds = __svg_new_cmds();
+ /* M x1,y1 */
+ __svg_add_moveto_cmd( cmds, ABSOLUTE, x1, y1 );
+
+ __svg_add_arc_cmd( cmds,
+ ABSOLUTE,
+ r0, r0, /* rx, ry */
+ 0.0, /* angle */
+ 0,1, /* lf, sf */
+ x2, y2 );
+
+ path = (struct __svg_path *)__svg_new_path( cmds );
+ (void)__svg_scene_add_node( scene, (struct __svg_node *)path );
+ }
+
+ {
+ double x1, y1, x2, y2, x3, y3, x4, y4, x5, y5, x6, y6,
+ x7, y7, x8, y8, x9, y9, x10, y10, x11, y11, x12, y12;
+
+ double x3_a, y3_a, x11_a, y11_a, x12_a, y12_a;
+
+ double r1 = 120.0,
+ r2 = 100.0,
+ r3 = 90.0,
+ r4 = 100.0,
+ r5 = 90.0,
+ r6 = 30.0,
+ r7 = 100.0,
+ r8 = 30.0,
+ r9 = 60.0,
+ r10 = 60.0,
+ r11, r12;
+
+ /* Set current values for newest objects: */
+ __svg_set_scene_stroke_rgb( 99, 99, 99 );
+ __svg_set_scene_stroke_width( 0.5 );
+ __svg_set_scene_stroke_dasharray( "3,2" );
+ __svg_set_scene_fill( "none" );
+
+ x1 = xM - r1 * sin( a0 );
+ y1 = yM + r1 * cos( a0 );
+
+ x2 = xM - r2 * sin( a0 );
+ y2 = yM + r2 * cos( a0 );
+
+ x3 = xM;
+ y3 = yM + r3;
+
+ x3_a = xM;
+ y3_a = yM + r3 + 6.0;
+
+ x4 = xM + r4 * cos( a0 );
+ y4 = yM + r4 * sin( a0 );
+
+ x5 = xM + r5 * sin( a0 );
+ y5 = yM - r5 * cos( a0 );
+
+ x6 = xM + r6 * sin( a0 );
+ y6 = yM - r6 * cos( a0 );
+
+ x7 = xM - r7 * cos( a0 );
+ y7 = yM - r7 * sin( a0 );
+
+ x8 = xM - r8 * cos( a0 );
+ y8 = yM - r8 * sin( a0 );
+
+ x9 = x0 + r9 * cos( a0 );
+ y9 = y0 + r9 * sin( a0 );
+
+ x10 = x0;
+ y10 = y0 + r10;
+
+ r11 = r3 * cos( a0 );
+ x11 = xM - r11 * sin( a0 );
+ y11 = yM + r11 * cos( a0 );
+ x11_a = xM - (r11+6.0) * sin( a0 );
+ y11_a = yM + (r11+6.0) * cos( a0 );
+
+
+ r12 = r3 * sin( a0 );
+ x12 = xM + r12 * cos( a0 );
+ y12 = yM + r12 * sin( a0 );
+ x12_a = xM + (r12+6.0) * cos( a0 );
+ y12_a = yM + (r12+6.0) * sin( a0 );
+
+ line = (struct __svg_line *)__svg_new_line( x1, y1, xM, yM );
+ (void)__svg_scene_add_node( scene, (struct __svg_node *)line );
+
+ line = (struct __svg_line *)__svg_new_line( x4, y4, xM, yM );
+ (void)__svg_scene_add_node( scene, (struct __svg_node *)line );
+
+ line = (struct __svg_line *)__svg_new_line( x3_a, y3_a, x11_a, y11_a );
+ (void)__svg_scene_add_node( scene, (struct __svg_node *)line );
+
+ line = (struct __svg_line *)__svg_new_line( x3_a, y3_a, x12_a, y12_a );
+ (void)__svg_scene_add_node( scene, (struct __svg_node *)line );
+
+ __svg_set_scene_stroke( "black" );
+ __svg_set_scene_stroke_width( 0.5 );
+ __svg_set_scene_stroke_dasharray( "none" );
+
+ cmds = __svg_new_cmds();
+ /* M x1,y1 */
+ __svg_add_moveto_cmd( cmds, ABSOLUTE, x9, y9 );
+
+ __svg_add_arc_cmd( cmds,
+ ABSOLUTE,
+ r10, r10, /* rx, ry */
+ 0.0, /* angle */
+ 0,1, /* lf, sf */
+ x10, y10 );
+
+ path = (struct __svg_path *)__svg_new_path( cmds );
+ (void)__svg_scene_add_node( scene, (struct __svg_node *)path );
+
+ __svg_set_scene_stroke_width( 1.0 );
+
+ line = (struct __svg_line *)__svg_new_line( x2, y2, xM, yM );
+ (void)__svg_scene_add_node( scene, (struct __svg_node *)line );
+
+ line = (struct __svg_line *)__svg_new_line( x5, y5, xM, yM );
+ (void)__svg_scene_add_node( scene, (struct __svg_node *)line );
+
+ line = (struct __svg_line *)__svg_new_line( x7, y7, xM, yM );
+ (void)__svg_scene_add_node( scene, (struct __svg_node *)line );
+
+ __svg_set_scene_stroke_width( 2.0 );
+
+ line = (struct __svg_line *)__svg_new_line( x3, y3, xM, yM );
+ (void)__svg_scene_add_node( scene, (struct __svg_node *)line );
+
+ line = (struct __svg_line *)__svg_new_line( x6, y6, xM, yM );
+ (void)__svg_scene_add_node( scene, (struct __svg_node *)line );
+
+ line = (struct __svg_line *)__svg_new_line( x8, y8, xM, yM );
+ (void)__svg_scene_add_node( scene, (struct __svg_node *)line );
+
+ line = (struct __svg_line *)__svg_new_line( x11, y11, xM, yM );
+ (void)__svg_scene_add_node( scene, (struct __svg_node *)line );
+
+ line = (struct __svg_line *)__svg_new_line( x12, y12, xM, yM );
+ (void)__svg_scene_add_node( scene, (struct __svg_node *)line );
+
+
+ /* стрелки */
+ arrow( x2, y2, M_PI + a0 );
+ arrow( x3, y3, M_PI );
+ arrow( x11, y11, M_PI + a0 );
+ arrow( x12, y12, M_PI - (M_PI / 2 - a0) );
+ arrow( x5, y5, a0 );
+ arrow( x6, y6, a0 );
+ arrow( x7, y7, -(M_PI /2 - a0) );
+ arrow( x8, y8, -(M_PI /2 - a0) );
+
+ {
+ double fx1, fy1;
+ fx1 = x9 - 4.0 * sin( a0 );
+ fy1 = y9 + 4.0 * cos( a0 );
+ small_arrow( fx1, fy1, a0 );
+ }
+
+ __svg_set_scene_text_fill_rgb( 0, 99, 99 );
+ text = (struct __svg_text *)__svg_new_text( x2, y2+15,
+ "<tspan font-style=\"oblique\">B</tspan>",
+ "Verdana", 0 );
+ (void)__svg_scene_add_node( scene, (struct __svg_node *)text );
+
+ text = (struct __svg_text *)__svg_new_text( x11+7, y11+15,
+ "<tspan font-style=\"oblique\">G<tspan dy=\"4\" font-family=\"Georgia\" font-size=\"10\">&#x3c4;</tspan></tspan>",
+ "Verdana", 0 );
+ (void)__svg_scene_add_node( scene, (struct __svg_node *)text );
+
+ text = (struct __svg_text *)__svg_new_text( x12+7, y12,
+ "<tspan font-style=\"oblique\">G<tspan dy=\"4\" font-family=\"Georgia\" font-size=\"10\">n</tspan></tspan>",
+ "Verdana", 0 );
+ (void)__svg_scene_add_node( scene, (struct __svg_node *)text );
+
+ text = (struct __svg_text *)__svg_new_text( x3, y3+20,
+ "<tspan font-style=\"oblique\">G</tspan>",
+ "Verdana", 0 );
+ (void)__svg_scene_add_node( scene, (struct __svg_node *)text );
+
+ text = (struct __svg_text *)__svg_new_text( xM-20, yM,
+ "<tspan font-weight=\"bold\" font-style=\"oblique\">M</tspan>",
+ "Verdana", 0 );
+ (void)__svg_scene_add_node( scene, (struct __svg_node *)text );
+
+ text = (struct __svg_text *)__svg_new_text( x6+5, y6+12,
+ "<tspan font-family=\"Georgia\" font-style=\"oblique\">&#x3c4;</tspan>",
+ "Verdana", 0 );
+ (void)__svg_scene_add_node( scene, (struct __svg_node *)text );
+
+ text = (struct __svg_text *)__svg_new_text( x8+5, y8-5,
+ "<tspan font-family=\"Georgia\" font-style=\"oblique\">n</tspan>",
+ "Verdana", 0 );
+ (void)__svg_scene_add_node( scene, (struct __svg_node *)text );
+
+ text = (struct __svg_text *)__svg_new_text( x5+5, y5+12,
+ "<tspan font-family=\"Georgia\" font-style=\"oblique\">&#x3bd;</tspan>",
+ "Verdana", 0 );
+ (void)__svg_scene_add_node( scene, (struct __svg_node *)text );
+
+ text = (struct __svg_text *)__svg_new_text( x7+5, y7-5,
+ "<tspan font-style=\"oblique\">N</tspan>",
+ "Verdana", 0 );
+ (void)__svg_scene_add_node( scene, (struct __svg_node *)text );
+
+ text = (struct __svg_text *)__svg_new_text( x0+10, y0+r9+10,
+ "<tspan font-family=\"Georgia\" font-style=\"oblique\">&#x3c6;</tspan>",
+ "Verdana", 0 );
+ (void)__svg_scene_add_node( scene, (struct __svg_node *)text );
+
+ text = (struct __svg_text *)__svg_new_text( x0-10, y0+r0+20,
+ "<tspan font-style=\"oblique\">O<tspan dy=\"4\" font-size=\"8\">1</tspan></tspan>",
+ "Verdana", 0 );
+ (void)__svg_scene_add_node( scene, (struct __svg_node *)text );
+
+ text = (struct __svg_text *)__svg_new_text( x0-15, y0+15,
+ "<tspan font-style=\"oblique\">O</tspan>",
+ "Verdana", 0 );
+ (void)__svg_scene_add_node( scene, (struct __svg_node *)text );
+
+ text = (struct __svg_text *)__svg_new_text( x0-15, y0+r0-5,
+ "<tspan font-style=\"oblique\">-</tspan>",
+ "Verdana", 0 );
+ (void)__svg_scene_add_node( scene, (struct __svg_node *)text );
+
+ text = (struct __svg_text *)__svg_new_text( x0+7, y0+r0-5,
+ "<tspan font-style=\"oblique\">+</tspan>",
+ "Verdana", 0 );
+ (void)__svg_scene_add_node( scene, (struct __svg_node *)text );
+
+ text = (struct __svg_text *)__svg_new_text( x0+40, y0+r0-10,
+ "<tspan font-style=\"oblique\">s</tspan>",
+ "Verdana", 0 );
+ (void)__svg_scene_add_node( scene, (struct __svg_node *)text );
+ }
+
+ /* Set current values for newest objects: */
+ __svg_set_scene_stroke( "black" );
+ __svg_set_scene_stroke_width( 1.0 );
+ __svg_set_scene_stroke_dasharray( "none" );
+ __svg_set_scene_fill_rgb( 255, 255, 255 );
+
+ circle = (struct __svg_circle *)__svg_new_circle( x0, y0, 3 );
+ (void)__svg_scene_add_node( scene, (struct __svg_node *)circle );
+
+ circle = (struct __svg_circle *)__svg_new_circle( xM, yM, 3 );
+ (void)__svg_scene_add_node( scene, (struct __svg_node *)circle );
+
+ circle = (struct __svg_circle *)__svg_new_circle( x0, y0+r0, 3 );
+ (void)__svg_scene_add_node( scene, (struct __svg_node *)circle );
+
+ __svg_set_scene_fill( "none" );
+
+ __svg_paint_scene( scene, 0, "M.svg" );
+
+ __svg_free_scene( scene );
+
+ return( 0 );
+}
+
diff --git a/examples/oscilator/view.html b/examples/oscilator/view.html
new file mode 100644
index 0000000..debe4eb
--- /dev/null
+++ b/examples/oscilator/view.html
@@ -0,0 +1,41 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+<head>
+ <meta http-equiv="content-type" content="text/html; charset=iso-8859-5">
+</head>
+<body link="#333333" vlink="#666666" alink="#000066">
+
+ <div
+ style="font-size: 12px; margin-left: 8px; margin-right: 4px; margin-top: 6px; margin-bottom: 8px; text-align: justify;">
+
+<p>
+Text:
+</p>
+
+
+<p>
+ <table border="0" cellspacing="0" cellpadding="0" style="width: 100%;">
+ <tbody>
+ <tr>
+ <td style="text-align: center;">
+<object type="image/svg+xml" data="M.svg" width="600" height="400">
+Your browser is currently unable to display SVG images.
+</object>
+ </td>
+ <td style="text-align: right; width: 20px;">
+<!-- index -->
+ </td>
+ </tr>
+ </tbody>
+ </table>
+</p>
+
+
+<p>
+End.
+</p>
+
+ </div>
+
+</body>
+</html>
diff --git a/examples/script-file/Makefile.am b/examples/script-file/Makefile.am
new file mode 100644
index 0000000..9c6cd12
--- /dev/null
+++ b/examples/script-file/Makefile.am
@@ -0,0 +1,27 @@
+
+AM_CFLAGS = -Wall -Wextra -Werror -std=gnu23
+AM_CPPFLAGS = -I$(top_srcdir)/src
+
+noinst_PROGRAMS = main
+noinst_DATA = example.svg
+
+main_SOURCES = main.c
+main_LDADD = $(top_builddir)/src/.libs/libsvgc.la
+
+EXTRA_DIST = change-color.js view.html
+CLEANFILES = example.svg
+
+example.svg: main $(srcdir)/change-color.js
+ @if test "$(srcdir)" != "."; then \
+ cp "$(srcdir)/change-color.js" change-color.js; \
+ cp "$(srcdir)/view.html" view.html; \
+ fi
+ ./main
+ @if test "$(srcdir)" != "."; then \
+ rm -f change-color.js; \
+ fi
+
+clean-local:
+ @if test "$(srcdir)" != "."; then \
+ rm -f view.html; \
+ fi
diff --git a/examples/script-file/README b/examples/script-file/README
new file mode 100644
index 0000000..8f10bdf
--- /dev/null
+++ b/examples/script-file/README
@@ -0,0 +1,24 @@
+SVGC interactive-script example
+===============================
+
+This example demonstrates __svg_sheet_add_script_file().
+
+The user writes only change-color.js as plain UTF-8 JavaScript source.
+The C application registers that file with the SVG sheet; SVGC reads and
+copies it into a <script type="text/javascript"><![CDATA[...]]></script>
+definition when serializing the SVG.
+
+After installing SVGC:
+
+ make
+
+Open example.svg directly as an SVG document, or use view.html, which
+embeds it with <object type="image/svg+xml">. Click the red circle: the
+script changes its fill to blue. Loading the SVG with <img> deliberately
+does not execute scripts in modern browsers. Opening local files may also
+be affected by browser security settings; a local HTTP server is an
+alternative for manual testing when the browser restricts file://.
+
+No binary scripts or external dependencies are bundled with the SVG.
+No JavaScript parser is part of the SVGC library; the viewer executes
+any embedded source in its normal security context.
diff --git a/examples/script-file/change-color.js b/examples/script-file/change-color.js
new file mode 100644
index 0000000..e831b22
--- /dev/null
+++ b/examples/script-file/change-color.js
@@ -0,0 +1,13 @@
+/* JavaScript source only: do NOT add <defs>, <script> or CDATA tags. */
+
+function changeColor(event)
+{
+ event.target.style.fill = 'blue';
+}
+
+document.addEventListener('DOMContentLoaded', function ()
+{
+ var circle = document.querySelector('circle');
+ if (circle)
+ circle.addEventListener('click', changeColor);
+});
diff --git a/examples/script-file/main.c b/examples/script-file/main.c
new file mode 100644
index 0000000..936916f
--- /dev/null
+++ b/examples/script-file/main.c
@@ -0,0 +1,51 @@
+
+/***************************************************************
+ SVGC EXAMPLE: EMBEDDED ECMASCRIPT
+
+ The file change-color.js contains only JavaScript source
+ text. Interactive script execution requires opening the SVG
+ as a document.
+ ***************************************************************/
+
+#include <stdio.h>
+#include <svgc.h>
+
+
+int
+main( void )
+{
+ struct __svg_sheet *sheet;
+ struct __svg_scene *scene;
+ struct __svg_node *circle;
+
+ sheet = (struct __svg_sheet *)__svg_new_sheet( 520, 220, 16, 16, 16, 16 );
+ if( !sheet ) return( 1 );
+
+ if( __svg_sheet_add_script_file( sheet, "change-color.js" ) != 1 )
+ {
+ __svg_free_node( sheet );
+ fprintf( stderr, "Cannot add change-color.js to the SVG sheet\n" );
+ return( 1 );
+ }
+
+ scene = __svg_new_scene( sheet );
+ if( !scene )
+ {
+ __svg_free_node( sheet );
+ return( 1 );
+ }
+
+ circle = __svg_new_circle( 260, 110, 72 );
+ if( !circle ||
+ __svg_set_fill( circle, "red" ) != 1 ||
+ __svg_scene_add_node( scene, circle ) != 1 )
+ {
+ if( circle ) __svg_free_node( circle );
+ __svg_free_scene( scene );
+ return( 1 );
+ }
+
+ __svg_paint_scene( scene, 0, "example.svg" );
+ __svg_free_scene( scene );
+ return( 0 );
+}
diff --git a/examples/script-file/view.html b/examples/script-file/view.html
new file mode 100644
index 0000000..5494951
--- /dev/null
+++ b/examples/script-file/view.html
@@ -0,0 +1,13 @@
+<!doctype html>
+<html lang="en">
+<head>
+ <meta charset="utf-8">
+ <title>SVGC: Embedded Script</title>
+</head>
+<body>
+ <p>Click the red circle to change it to blue.</p>
+ <object data="example.svg" type="image/svg+xml" width="520" height="220">
+ <p>Open example.svg as a standalone SVG document.</p>
+ </object>
+</body>
+</html>