From 387858893a1a858e8205aae28a3609006c0c717d Mon Sep 17 00:00:00 2001 From: Thomas White Date: Fri, 20 Sep 2019 17:12:29 +0200 Subject: Parse emphasis blocks in Bison --- libstorycode/render_cairo_common.c | 97 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 libstorycode/render_cairo_common.c (limited to 'libstorycode/render_cairo_common.c') diff --git a/libstorycode/render_cairo_common.c b/libstorycode/render_cairo_common.c new file mode 100644 index 0000000..b3883c9 --- /dev/null +++ b/libstorycode/render_cairo_common.c @@ -0,0 +1,97 @@ +/* + * render_cairo_common.c + * + * Copyright © 2019 Thomas White + * + * This file is part of Colloquium. + * + * Colloquium is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include + +#include "storycode.h" + +int runs_to_pangolayout(PangoLayout *layout, struct text_run *runs, int n_runs) +{ + size_t total_len = 0; + int i; + char *text; + PangoAttrList *attrs; + + attrs = pango_layout_get_attributes(layout); + + /* Work out length of all text in item (paragraph) */ + for ( i=0; istart_index = pos; + attr->end_index = pos + run_len; + pango_attr_list_insert(attrs, attr); + } + + /* FIXME: Should check that each bit of text finishes on a character boundary */ + pos += run_len; + strcat(text, runs[i].text); + + } + pango_layout_set_text(layout, text, -1); + + return 0; +} -- cgit v1.2.3