From a5d76beb238d47e3f488877c98b472ac9772c9df Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Fri, 11 Jul 2014 15:03:54 +0200 Subject: [PATCH] Move the default xsl file to the resources --- src/ag-chart.c | 30 +- src/ag.gresource.xml | 1 + src/resources/ui/chart-default.xsl | 704 +++++++++++++++++++++++++++++ 3 files changed, 724 insertions(+), 11 deletions(-) create mode 100644 src/resources/ui/chart-default.xsl diff --git a/src/ag-chart.c b/src/ag-chart.c index d457f8c..ef8de0c 100644 --- a/src/ag-chart.c +++ b/src/ag-chart.c @@ -1009,8 +1009,8 @@ ag_chart_create_svg(AgChart *chart, gsize *length, GError **err) xmlNodePtr antiscia_node = NULL; xmlNodePtr node = NULL; gchar *value; - gchar *stylesheet_path; gchar *save_content = NULL; + const gchar *xslt_content; GList *houses; GList *house; GList *planet; @@ -1024,6 +1024,8 @@ ag_chart_create_svg(AgChart *chart, gsize *length, GError **err) gint save_length; xsltStylesheetPtr xslt_proc; locale_t current_locale; + GBytes *xslt_data; + gsize xslt_length; root_node = xmlDocGetRootElement(doc); @@ -1222,16 +1224,25 @@ ag_chart_create_svg(AgChart *chart, gsize *length, GError **err) // Now, doc contains the generated XML tree - stylesheet_path = g_strdup_printf("%s/%s", PKGDATADIR, "chart.xsl"); - g_debug("Opening %s as a stylesheet", stylesheet_path); - if ((xslt_doc = xmlReadFile(stylesheet_path, "UTF-8", 0)) == NULL) { + xslt_data = g_resources_lookup_data( + "/eu/polonkai/gergely/Astrognome/ui/chart-default.xsl", + G_RESOURCE_LOOKUP_FLAGS_NONE, + NULL + ); + xslt_content = g_bytes_get_data(xslt_data, &xslt_length); + + if ((xslt_doc = xmlReadMemory( + xslt_content, + xslt_length, + "file://" PKGDATADIR "/astrognome", + "UTF-8", + 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 + "Built in style sheet can not be parsed as a stylesheet file." ); - g_free(stylesheet_path); xmlFreeDoc(doc); return NULL; @@ -1247,10 +1258,8 @@ ag_chart_create_svg(AgChart *chart, gsize *length, GError **err) g_set_error( err, AG_CHART_ERROR, AG_CHART_ERROR_CORRUPT_FILE, - "File '%s' can not be parsed as a stylesheet file.", - stylesheet_path + "Built in style sheet can not be parsed as a stylesheet file." ); - g_free(stylesheet_path); xmlFreeDoc(xslt_doc); xmlFreeDoc(doc); @@ -1264,7 +1273,6 @@ ag_chart_create_svg(AgChart *chart, gsize *length, GError **err) current_locale = uselocale(newlocale(LC_ALL, "C", 0)); svg_doc = xsltApplyStylesheet(xslt_proc, doc, NULL); uselocale(current_locale); - g_free(stylesheet_path); xsltFreeStylesheet(xslt_proc); xmlFreeDoc(doc); diff --git a/src/ag.gresource.xml b/src/ag.gresource.xml index ce38542..b86f699 100644 --- a/src/ag.gresource.xml +++ b/src/ag.gresource.xml @@ -5,6 +5,7 @@ ui/ag-window.ui ui/ag-preferences.ui ui/chart-default.css + ui/chart-default.xsl default-icons/planet-sun.svg diff --git a/src/resources/ui/chart-default.xsl b/src/resources/ui/chart-default.xsl new file mode 100644 index 0000000..4211509 --- /dev/null +++ b/src/resources/ui/chart-default.xsl @@ -0,0 +1,704 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + point_vertex + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +