From e5c7702870a1bddac6b46ae82c90864f94172ca9 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Sat, 25 Jan 2020 19:45:04 +0100 Subject: Implement loading stylesheets --- libstorycode/stylesheet.c | 17 +++++++++++++++++ libstorycode/stylesheet.h | 3 +++ 2 files changed, 20 insertions(+) (limited to 'libstorycode') diff --git a/libstorycode/stylesheet.c b/libstorycode/stylesheet.c index bc22852..16cf218 100644 --- a/libstorycode/stylesheet.c +++ b/libstorycode/stylesheet.c @@ -593,6 +593,23 @@ int stylesheet_set_from_storycode(Stylesheet *ss, const char *sc) } +int stylesheet_set_from_file(Stylesheet *ss, GFile *file) +{ + GBytes *bytes; + const char *text; + size_t len; + int r = 0; + + bytes = g_file_load_bytes(file, NULL, NULL, NULL); + if ( bytes == NULL ) return 0; + + text = g_bytes_get_data(bytes, &len); + r = stylesheet_set_from_storycode(ss, text); + g_bytes_unref(bytes); + return r; +} + + double lcalc(struct length l, double pd) { if ( l.unit == LENGTH_UNIT ) { diff --git a/libstorycode/stylesheet.h b/libstorycode/stylesheet.h index 82f90e8..4a8e58c 100644 --- a/libstorycode/stylesheet.h +++ b/libstorycode/stylesheet.h @@ -27,6 +27,8 @@ #include #endif +#include + typedef struct _stylesheet Stylesheet; enum alignment @@ -80,6 +82,7 @@ enum gradient extern Stylesheet *stylesheet_new(void); extern void stylesheet_free(Stylesheet *s); extern int stylesheet_set_from_storycode(Stylesheet *ss, const char *sc); +extern int stylesheet_set_from_file(Stylesheet *ss, GFile *file); extern int stylesheet_get_slide_default_size(Stylesheet *s, double *w, double *h); -- cgit v1.2.3