diff options
| author | kx <kx@radix-linux.su> | 2026-10-17 16:39:23 +0300 |
|---|---|---|
| committer | kx <kx@radix-linux.su> | 2026-10-17 16:39:23 +0300 |
| commit | ec1891d58b9514b621725620453cec0e31e18389 (patch) | |
| tree | 6721f92c0afae3d933343b4a573ac8e5389827c6 /examples/css-file | |
| parent | 73d23259a690cd29c0ac74a4de963e23ecfebfac (diff) | |
| download | svgc-trunk.tar.xz | |
Diffstat (limited to 'examples/css-file')
| -rw-r--r-- | examples/css-file/Makefile.am | 27 | ||||
| -rw-r--r-- | examples/css-file/README | 18 | ||||
| -rw-r--r-- | examples/css-file/fonts.css | 8 | ||||
| -rw-r--r-- | examples/css-file/main.c | 47 | ||||
| -rw-r--r-- | examples/css-file/view.html | 9 |
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> |
