Now setting the CSS file path as a parameter
This will allow us to use separate CSS and XSLT files (e.g. themes) later
This commit is contained in:
parent
a154118b6f
commit
fcb75f672b
@ -16,7 +16,7 @@
|
||||
<xsl:variable name="r_aspect" select="240" />
|
||||
|
||||
<xsl:template match="/">
|
||||
<xsl:processing-instruction name="xml-stylesheet">href="test.css" type="text/css"</xsl:processing-instruction>
|
||||
<xsl:processing-instruction name="xml-stylesheet">href="<xsl:value-of select="$css_file"/>" type="text/css"</xsl:processing-instruction>
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:xlink="http://www.w3.org/1999/xlink"
|
||||
|
@ -671,8 +671,12 @@ ag_chart_create_svg(AgChart *chart, GError **err)
|
||||
node = NULL;
|
||||
gchar *value,
|
||||
*stylesheet_path,
|
||||
*css_path,
|
||||
*xslt,
|
||||
*save_content = NULL;
|
||||
*save_content = NULL,
|
||||
*css_uri,
|
||||
*css_final_uri,
|
||||
**params;
|
||||
GList *houses,
|
||||
*house,
|
||||
*planet,
|
||||
@ -685,7 +689,8 @@ ag_chart_create_svg(AgChart *chart, GError **err)
|
||||
*antiscia_class;
|
||||
guint xslt_length;
|
||||
gint save_length;
|
||||
GFile *xslt_file;
|
||||
GFile *xslt_file,
|
||||
*css_file;
|
||||
xsltStylesheetPtr xslt_proc;
|
||||
locale_t current_locale;
|
||||
|
||||
@ -838,9 +843,17 @@ ag_chart_create_svg(AgChart *chart, GError **err)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
css_path = g_strdup_printf("%s/%s", PKGDATADIR, "chart.css");
|
||||
g_debug("Using %s as a CSS stylesheet", css_path);
|
||||
css_file = g_file_new_for_path(css_path);
|
||||
css_uri = g_file_get_uri(css_file);
|
||||
|
||||
if ((xslt_doc = xmlReadMemory(xslt, xslt_length, "chart.xsl", NULL, 0)) == NULL) {
|
||||
g_set_error(err, AG_CHART_ERROR, AG_CHART_ERROR_CORRUPT_FILE, "File '%s' can not be parsed as a stylesheet file.", stylesheet_path);
|
||||
g_free(stylesheet_path);
|
||||
g_free(css_path);
|
||||
g_free(css_uri);
|
||||
g_object_unref(css_file);
|
||||
g_free(xslt);
|
||||
xmlFreeDoc(doc);
|
||||
|
||||
@ -850,21 +863,32 @@ ag_chart_create_svg(AgChart *chart, GError **err)
|
||||
if ((xslt_proc = xsltParseStylesheetDoc(xslt_doc)) == NULL) {
|
||||
g_set_error(err, AG_CHART_ERROR, AG_CHART_ERROR_CORRUPT_FILE, "File '%s' can not be parsed as a stylesheet file.", stylesheet_path);
|
||||
g_free(stylesheet_path);
|
||||
g_free(css_path);
|
||||
g_free(xslt);
|
||||
g_free(css_uri);
|
||||
g_object_unref(css_file);
|
||||
xmlFreeDoc(xslt_doc);
|
||||
xmlFreeDoc(doc);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
css_final_uri = g_strdup_printf("'%s'", css_uri);
|
||||
g_free(css_uri);
|
||||
params = g_new0(gchar *, 3);
|
||||
params[0] = "css_file";
|
||||
params[1] = css_final_uri;
|
||||
// libxml2 messes up the output, as it prints decimal floating point
|
||||
// numbers in a localized format. It is not good in locales that use a
|
||||
// character for decimal separator other than a dot. So let's just use the
|
||||
// C locale until the SVG is generated.
|
||||
current_locale = uselocale(newlocale(LC_ALL, "C", 0));
|
||||
svg_doc = xsltApplyStylesheet(xslt_proc, doc, NULL);
|
||||
svg_doc = xsltApplyStylesheet(xslt_proc, doc, (const char **)params);
|
||||
uselocale(current_locale);
|
||||
g_free(stylesheet_path);
|
||||
g_free(css_path);
|
||||
g_object_unref(css_file);
|
||||
g_free(params);
|
||||
xsltFreeStylesheet(xslt_proc);
|
||||
xmlFreeDoc(doc);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user