summaryrefslogtreecommitdiff
path: root/examples/css-file
diff options
context:
space:
mode:
Diffstat (limited to 'examples/css-file')
-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
5 files changed, 109 insertions, 0 deletions
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>