From 4144d6b4ff2641c89ef5a26ca34ce5bef0da40ce Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Fri, 11 Jul 2014 14:32:24 +0200 Subject: [PATCH 1/5] Remove CSS from the xsl file and the SVG generating code --- data/chart.xsl | 1 - src/ag-chart.c | 26 +------------------------- 2 files changed, 1 insertion(+), 26 deletions(-) diff --git a/data/chart.xsl b/data/chart.xsl index 3a15447..4211509 100644 --- a/data/chart.xsl +++ b/data/chart.xsl @@ -17,7 +17,6 @@ - href="" type="text/css" Date: Fri, 11 Jul 2014 15:03:54 +0200 Subject: [PATCH 2/5] 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 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From c31ddb6fe751077d29026ac7bc05333a9a02994a Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Sat, 12 Jul 2014 10:27:11 +0200 Subject: [PATCH 3/5] Add gres:// type links support for libxml2 --- src/astrognome.c | 108 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) diff --git a/src/astrognome.c b/src/astrognome.c index 658f3a4..ba4797d 100644 --- a/src/astrognome.c +++ b/src/astrognome.c @@ -20,6 +20,7 @@ GtkBuilder *builder; GtkFileFilter *filter_all = NULL; GtkFileFilter *filter_chart = NULL; +GHashTable *xinclude_positions; const char *moonStateName[] = { "New Moon", @@ -47,6 +48,100 @@ init_filters(void) g_object_ref_sink(filter_chart); } +static int +xml_match_gresource(const char *uri) +{ + if ((uri != NULL) && (!strncmp("gres://", uri, 7))) { + g_debug("Matched gres:// type link."); + + return 1; + } else { + return 0; + } +} + +static void * +xml_open_gresource(const gchar *uri) +{ + gchar *path; + GBytes *res_location; + gsize *position; + + if ((uri == NULL) || (strncmp("gres://", uri, 7))) { + return NULL; + } + + path = g_strdup_printf("/eu/polonkai/gergely/Astrognome/%s", uri + 7); + g_debug("Opening gresource %s", path); + + res_location = g_resources_lookup_data( + path, + G_RESOURCE_LOOKUP_FLAGS_NONE, + NULL + ); + g_free(path); + + if ((position = g_hash_table_lookup(xinclude_positions, res_location)) == NULL) { + g_hash_table_insert(xinclude_positions, res_location, g_new0(gsize, 1)); + } else { + g_warning("Reopening gres:// link?"); + *position = 0; + } + + return res_location; +} + +static int +xml_close_gresource(void *context) +{ + if (context == NULL) { + return -1; + } + + g_debug("Closing gres:// link"); + + g_hash_table_remove(xinclude_positions, context); + g_bytes_unref((GBytes *)context); + + return 0; +} + +static int +xml_read_gresource(void *context, char *buffer, int len) +{ + const gchar *data; + gsize max_length; + GBytes *data_holder = (GBytes *)context; + gsize *position; + + if ((context == NULL) || (buffer == NULL) || (len < 0)) { + return -1; + } + + data = g_bytes_get_data(data_holder, &max_length); + position = g_hash_table_lookup(xinclude_positions, data_holder); + + if (position == NULL) { + g_warning("Trying to read non-opened gres:// link!"); + + return -1; + } + + if (*position >= max_length) { + return 0; + } + + if (len > max_length - *position) { + len = max_length - *position; + } + + memcpy(buffer, data + *position, len); + g_debug("Read %d bytes", len); + *position += len; + + return len; +} + int main(int argc, char *argv[]) { @@ -89,10 +184,22 @@ main(int argc, char *argv[]) LIBXML_TEST_VERSION; xmlSubstituteEntitiesDefault(1); xmlLoadExtDtdDefaultValue = 1; + xmlRegisterInputCallbacks( + xml_match_gresource, + xml_open_gresource, + xml_read_gresource, + xml_close_gresource + ); xsltInit(); xsltSetXIncludeDefault(1); exsltRegisterAll(); gswe_init(); + xinclude_positions = g_hash_table_new_full( + g_bytes_hash, + g_bytes_equal, + (GDestroyNotify)g_bytes_unref, + (GDestroyNotify)g_free + ); memset(&options, 0, sizeof(AstrognomeOptions)); @@ -135,6 +242,7 @@ main(int argc, char *argv[]) status = g_application_run(G_APPLICATION(app), argc, argv); + g_hash_table_destroy(xinclude_positions); g_object_unref(app); return status; From 5ac17cd8be51e2d83b3a8bb474c24ad3556fb3ed Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Sat, 12 Jul 2014 10:45:38 +0200 Subject: [PATCH 4/5] Move default sign symbols to the resource list --- src/ag.gresource.xml | 12 ++++++++++ src/resources/default-icons/sign-aquarius.xml | 4 ++++ src/resources/default-icons/sign-aries.xml | 4 ++++ src/resources/default-icons/sign-cancer.xml | 4 ++++ .../default-icons/sign-capricorn.xml | 4 ++++ src/resources/default-icons/sign-gemini.xml | 4 ++++ src/resources/default-icons/sign-leo.xml | 4 ++++ src/resources/default-icons/sign-libra.xml | 4 ++++ src/resources/default-icons/sign-pisces.xml | 4 ++++ .../default-icons/sign-sagittarius.xml | 4 ++++ src/resources/default-icons/sign-scorpio.xml | 5 ++++ src/resources/default-icons/sign-taurus.xml | 4 ++++ src/resources/default-icons/sign-virgo.xml | 4 ++++ src/resources/ui/chart-default.xsl | 24 +++++++++---------- 14 files changed, 73 insertions(+), 12 deletions(-) create mode 100644 src/resources/default-icons/sign-aquarius.xml create mode 100644 src/resources/default-icons/sign-aries.xml create mode 100644 src/resources/default-icons/sign-cancer.xml create mode 100644 src/resources/default-icons/sign-capricorn.xml create mode 100644 src/resources/default-icons/sign-gemini.xml create mode 100644 src/resources/default-icons/sign-leo.xml create mode 100644 src/resources/default-icons/sign-libra.xml create mode 100644 src/resources/default-icons/sign-pisces.xml create mode 100644 src/resources/default-icons/sign-sagittarius.xml create mode 100644 src/resources/default-icons/sign-scorpio.xml create mode 100644 src/resources/default-icons/sign-taurus.xml create mode 100644 src/resources/default-icons/sign-virgo.xml diff --git a/src/ag.gresource.xml b/src/ag.gresource.xml index b86f699..cd06124 100644 --- a/src/ag.gresource.xml +++ b/src/ag.gresource.xml @@ -7,6 +7,18 @@ ui/chart-default.css ui/chart-default.xsl + default-icons/sign-aries.xml + default-icons/sign-taurus.xml + default-icons/sign-gemini.xml + default-icons/sign-cancer.xml + default-icons/sign-leo.xml + default-icons/sign-virgo.xml + default-icons/sign-libra.xml + default-icons/sign-scorpio.xml + default-icons/sign-sagittarius.xml + default-icons/sign-capricorn.xml + default-icons/sign-aquarius.xml + default-icons/sign-pisces.xml default-icons/planet-sun.svg diff --git a/src/resources/default-icons/sign-aquarius.xml b/src/resources/default-icons/sign-aquarius.xml new file mode 100644 index 0000000..1a0efc0 --- /dev/null +++ b/src/resources/default-icons/sign-aquarius.xml @@ -0,0 +1,4 @@ + diff --git a/src/resources/default-icons/sign-aries.xml b/src/resources/default-icons/sign-aries.xml new file mode 100644 index 0000000..daacabe --- /dev/null +++ b/src/resources/default-icons/sign-aries.xml @@ -0,0 +1,4 @@ + diff --git a/src/resources/default-icons/sign-cancer.xml b/src/resources/default-icons/sign-cancer.xml new file mode 100644 index 0000000..5a8b5b2 --- /dev/null +++ b/src/resources/default-icons/sign-cancer.xml @@ -0,0 +1,4 @@ + diff --git a/src/resources/default-icons/sign-capricorn.xml b/src/resources/default-icons/sign-capricorn.xml new file mode 100644 index 0000000..d8e1d7b --- /dev/null +++ b/src/resources/default-icons/sign-capricorn.xml @@ -0,0 +1,4 @@ + diff --git a/src/resources/default-icons/sign-gemini.xml b/src/resources/default-icons/sign-gemini.xml new file mode 100644 index 0000000..3fa5532 --- /dev/null +++ b/src/resources/default-icons/sign-gemini.xml @@ -0,0 +1,4 @@ + diff --git a/src/resources/default-icons/sign-leo.xml b/src/resources/default-icons/sign-leo.xml new file mode 100644 index 0000000..12bd158 --- /dev/null +++ b/src/resources/default-icons/sign-leo.xml @@ -0,0 +1,4 @@ + diff --git a/src/resources/default-icons/sign-libra.xml b/src/resources/default-icons/sign-libra.xml new file mode 100644 index 0000000..ef4e4fb --- /dev/null +++ b/src/resources/default-icons/sign-libra.xml @@ -0,0 +1,4 @@ + diff --git a/src/resources/default-icons/sign-pisces.xml b/src/resources/default-icons/sign-pisces.xml new file mode 100644 index 0000000..023cf9f --- /dev/null +++ b/src/resources/default-icons/sign-pisces.xml @@ -0,0 +1,4 @@ + diff --git a/src/resources/default-icons/sign-sagittarius.xml b/src/resources/default-icons/sign-sagittarius.xml new file mode 100644 index 0000000..a63cdbb --- /dev/null +++ b/src/resources/default-icons/sign-sagittarius.xml @@ -0,0 +1,4 @@ + diff --git a/src/resources/default-icons/sign-scorpio.xml b/src/resources/default-icons/sign-scorpio.xml new file mode 100644 index 0000000..d88d823 --- /dev/null +++ b/src/resources/default-icons/sign-scorpio.xml @@ -0,0 +1,5 @@ + diff --git a/src/resources/default-icons/sign-taurus.xml b/src/resources/default-icons/sign-taurus.xml new file mode 100644 index 0000000..c188ed9 --- /dev/null +++ b/src/resources/default-icons/sign-taurus.xml @@ -0,0 +1,4 @@ + diff --git a/src/resources/default-icons/sign-virgo.xml b/src/resources/default-icons/sign-virgo.xml new file mode 100644 index 0000000..a5b6acb --- /dev/null +++ b/src/resources/default-icons/sign-virgo.xml @@ -0,0 +1,4 @@ + diff --git a/src/resources/ui/chart-default.xsl b/src/resources/ui/chart-default.xsl index 4211509..ca4c3d9 100644 --- a/src/resources/ui/chart-default.xsl +++ b/src/resources/ui/chart-default.xsl @@ -30,18 +30,18 @@ )"/> - - - - - - - - - - - - + + + + + + + + + + + + From 84cab9b91068c34ccfbfd097e59bf344cd0700c8 Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Sat, 12 Jul 2014 10:50:36 +0200 Subject: [PATCH 5/5] Clean up data directory Remove old sign icons --- data/Makefile.am | 18 ------------------ data/sign_aquarius.xml | 4 ---- data/sign_aries.xml | 4 ---- data/sign_cancer.xml | 4 ---- data/sign_capricorn.xml | 4 ---- data/sign_gemini.xml | 4 ---- data/sign_leo.xml | 4 ---- data/sign_libra.xml | 4 ---- data/sign_pisces.xml | 4 ---- data/sign_sagittarius.xml | 4 ---- data/sign_scorpio.xml | 5 ----- data/sign_taurus.xml | 4 ---- data/sign_virgo.xml | 4 ---- 13 files changed, 67 deletions(-) delete mode 100644 data/sign_aquarius.xml delete mode 100644 data/sign_aries.xml delete mode 100644 data/sign_cancer.xml delete mode 100644 data/sign_capricorn.xml delete mode 100644 data/sign_gemini.xml delete mode 100644 data/sign_leo.xml delete mode 100644 data/sign_libra.xml delete mode 100644 data/sign_pisces.xml delete mode 100644 data/sign_sagittarius.xml delete mode 100644 data/sign_scorpio.xml delete mode 100644 data/sign_taurus.xml delete mode 100644 data/sign_virgo.xml diff --git a/data/Makefile.am b/data/Makefile.am index 1f86f04..f9838e9 100644 --- a/data/Makefile.am +++ b/data/Makefile.am @@ -1,22 +1,5 @@ SUBDIRS = icons geonames -chartdatadir = $(pkgdatadir) -chartdata_DATA = chart.xsl \ - chart.css \ - sign_aries.xml \ - sign_taurus.xml \ - sign_gemini.xml \ - sign_cancer.xml \ - sign_leo.xml \ - sign_virgo.xml \ - sign_libra.xml \ - sign_scorpio.xml \ - sign_sagittarius.xml \ - sign_capricorn.xml \ - sign_aquarius.xml \ - sign_pisces.xml \ - $(NULL) - gsettings_SCHEMAS = \ eu.polonkai.gergely.astrognome.gschema.xml \ $(NULL) @@ -29,7 +12,6 @@ desktop_in_files = astrognome.desktop.in desktop_DATA = $(desktop_in_files:.desktop.in=.desktop) EXTRA_DIST = \ - $(chartdata_DATA) \ $(desktop_in_files) \ $(gsettings_SCHEMAS) \ $(NULL) diff --git a/data/sign_aquarius.xml b/data/sign_aquarius.xml deleted file mode 100644 index 1a0efc0..0000000 --- a/data/sign_aquarius.xml +++ /dev/null @@ -1,4 +0,0 @@ - diff --git a/data/sign_aries.xml b/data/sign_aries.xml deleted file mode 100644 index daacabe..0000000 --- a/data/sign_aries.xml +++ /dev/null @@ -1,4 +0,0 @@ - diff --git a/data/sign_cancer.xml b/data/sign_cancer.xml deleted file mode 100644 index 5a8b5b2..0000000 --- a/data/sign_cancer.xml +++ /dev/null @@ -1,4 +0,0 @@ - diff --git a/data/sign_capricorn.xml b/data/sign_capricorn.xml deleted file mode 100644 index d8e1d7b..0000000 --- a/data/sign_capricorn.xml +++ /dev/null @@ -1,4 +0,0 @@ - diff --git a/data/sign_gemini.xml b/data/sign_gemini.xml deleted file mode 100644 index 3fa5532..0000000 --- a/data/sign_gemini.xml +++ /dev/null @@ -1,4 +0,0 @@ - diff --git a/data/sign_leo.xml b/data/sign_leo.xml deleted file mode 100644 index 12bd158..0000000 --- a/data/sign_leo.xml +++ /dev/null @@ -1,4 +0,0 @@ - diff --git a/data/sign_libra.xml b/data/sign_libra.xml deleted file mode 100644 index ef4e4fb..0000000 --- a/data/sign_libra.xml +++ /dev/null @@ -1,4 +0,0 @@ - diff --git a/data/sign_pisces.xml b/data/sign_pisces.xml deleted file mode 100644 index 023cf9f..0000000 --- a/data/sign_pisces.xml +++ /dev/null @@ -1,4 +0,0 @@ - diff --git a/data/sign_sagittarius.xml b/data/sign_sagittarius.xml deleted file mode 100644 index a63cdbb..0000000 --- a/data/sign_sagittarius.xml +++ /dev/null @@ -1,4 +0,0 @@ - diff --git a/data/sign_scorpio.xml b/data/sign_scorpio.xml deleted file mode 100644 index d88d823..0000000 --- a/data/sign_scorpio.xml +++ /dev/null @@ -1,5 +0,0 @@ - diff --git a/data/sign_taurus.xml b/data/sign_taurus.xml deleted file mode 100644 index c188ed9..0000000 --- a/data/sign_taurus.xml +++ /dev/null @@ -1,4 +0,0 @@ - diff --git a/data/sign_virgo.xml b/data/sign_virgo.xml deleted file mode 100644 index a5b6acb..0000000 --- a/data/sign_virgo.xml +++ /dev/null @@ -1,4 +0,0 @@ -