From 3c5582d5e238757cd239bc8732ec111fcb78125a Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Sun, 21 Sep 2014 22:55:28 +0200 Subject: [PATCH 1/4] Fix CSS bug in chart-default.css .aspect-sextile was missing a semicolon --- src/resources/ui/chart-default.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/resources/ui/chart-default.css b/src/resources/ui/chart-default.css index dd3413f..bd6da08 100644 --- a/src/resources/ui/chart-default.css +++ b/src/resources/ui/chart-default.css @@ -84,7 +84,7 @@ line.aspect-conjuction { } line.aspect-sextile { - stroke-width: 1 + stroke-width: 1; stroke: #00cc00; stroke-dasharray: none; } From c36ef5894688874f1d3a56c591ccb5b23ff1a8f8 Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Sun, 21 Sep 2014 23:04:53 +0200 Subject: [PATCH 2/4] Fix ag_window_set_theme() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It didn’t actually set the display theme in the AgWindow object --- src/ag-window.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/ag-window.c b/src/ag-window.c index 962b34d..cbacae6 100644 --- a/src/ag-window.c +++ b/src/ag-window.c @@ -1394,12 +1394,15 @@ ag_window_update_style_sheets(AgWindow *window) static void ag_window_set_theme(AgWindow *window, AgDisplayTheme *theme) { - gchar *css, - *css_final; + gchar *css, + *css_final; + AgWindowPrivate *priv = ag_window_get_instance_private(window); g_debug("Setting theme to %s", (theme) ? theme->name : "no theme"); ag_window_clear_style_sheets(window); + priv->theme = theme; + // Add the default style sheet ag_window_add_style_sheet( window, From 4fd2215360b8abaa1a3d2333e3c0210ae9c18ba6 Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Sun, 21 Sep 2014 22:56:14 +0200 Subject: [PATCH 3/4] Make ag_display_theme_to_css() handle the NULL theme --- src/ag-display-theme.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/ag-display-theme.c b/src/ag-display-theme.c index 94f2f36..1c1935f 100644 --- a/src/ag-display-theme.c +++ b/src/ag-display-theme.c @@ -54,6 +54,11 @@ ag_display_theme_to_css(AgDisplayTheme *theme) gchar *ret; GString *css = NULL; + // Null themes are possible, deal with it! + if (theme == NULL) { + return g_strdup(""); + } + if (theme->planets_include) { css = g_string_new(planet_none); } else { From 8a4eb378e938773c9ca730e0732d5860b51311c7 Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Sun, 21 Sep 2014 23:00:45 +0200 Subject: [PATCH 4/4] Add a theme parameter to the SVG/image generating functions This is needed for image generation to include display themes. Fixes #82 --- src/ag-chart.c | 46 +++++++++++++++++++++++------- src/ag-chart.h | 26 ++++++++++------- src/ag-window.c | 3 +- src/resources/ui/chart-default.xsl | 3 ++ 4 files changed, 56 insertions(+), 22 deletions(-) diff --git a/src/ag-chart.c b/src/ag-chart.c index e25cf7e..bdbb5e1 100644 --- a/src/ag-chart.c +++ b/src/ag-chart.c @@ -1395,11 +1395,11 @@ ag_chart_sort_planets_by_position(GswePlanetData *planet1, } gchar * -ag_chart_create_svg( - AgChart *chart, - gsize *length, - gboolean rendering, - GError **err) +ag_chart_create_svg(AgChart *chart, + gsize *length, + gboolean rendering, + AgDisplayTheme *theme, + GError **err) { xmlDocPtr doc = create_save_doc(chart), xslt_doc, @@ -1412,6 +1412,7 @@ ag_chart_create_svg( antiscia_node = NULL, node = NULL; gchar *value, + *css, *save_content = NULL, **params; const gchar *xslt_content; @@ -1717,9 +1718,21 @@ ag_chart_create_svg( return NULL; } - params = g_new0(gchar *, 3); + params = g_new0(gchar *, 5); params[0] = "rendering"; params[1] = (rendering) ? "'yes'" : "'no'"; + css = ag_display_theme_to_css(theme); + + // This seems to be a dirty hack, but it should do for a while + if (strlen(css) == 0) { + params[2] = NULL; + params[3] = NULL; + } else { + params[2] = "additional-css"; + params[3] = g_strdup_printf("\"%s\"", css); + } + + g_free(css); // 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 @@ -1732,6 +1745,7 @@ ag_chart_create_svg( uselocale(current_locale); xsltFreeStylesheet(xslt_proc); xmlFreeDoc(doc); + g_free(params[3]); g_free(params); // Now, svg_doc contains the generated SVG file @@ -1761,12 +1775,15 @@ ag_chart_get_planets(AgChart *chart) } void -ag_chart_export_svg_to_file(AgChart *chart, GFile *file, GError **err) +ag_chart_export_svg_to_file(AgChart *chart, + GFile *file, + AgDisplayTheme *theme, + GError **err) { gchar *svg; gsize length; - if ((svg = ag_chart_create_svg(chart, &length, TRUE, err)) == NULL) { + if ((svg = ag_chart_create_svg(chart, &length, TRUE, theme, err)) == NULL) { return; } @@ -1784,7 +1801,10 @@ ag_chart_export_svg_to_file(AgChart *chart, GFile *file, GError **err) } void -ag_chart_export_jpg_to_file(AgChart *chart, GFile *file, GError **err) +ag_chart_export_jpg_to_file(AgChart *chart, + GFile *file, + AgDisplayTheme *theme, + GError **err) { gchar *svg, *jpg; @@ -1793,7 +1813,13 @@ ag_chart_export_jpg_to_file(AgChart *chart, GFile *file, GError **err) RsvgHandle *svg_handle; GdkPixbuf *pixbuf; - if ((svg = ag_chart_create_svg(chart, &svg_length, TRUE, err)) == NULL) { + if ((svg = ag_chart_create_svg( + chart, + &svg_length, + TRUE, + theme, + err + )) == NULL) { return; } diff --git a/src/ag-chart.h b/src/ag-chart.h index 517ae43..216f5e3 100644 --- a/src/ag-chart.h +++ b/src/ag-chart.h @@ -6,6 +6,7 @@ #include #include "ag-db.h" +#include "ag-display-theme.h" G_BEGIN_DECLS @@ -44,7 +45,7 @@ struct _AgChartClass { GsweMomentClass parent_class; }; -typedef void (*AgChartSaveImageFunc)(AgChart *, GFile *, GError **); +typedef void (*AgChartSaveImageFunc)(AgChart *, GFile *, AgDisplayTheme *, GError **); GType ag_chart_get_type(void) G_GNUC_CONST; @@ -66,13 +67,15 @@ void ag_chart_save_to_file(AgChart *chart, GFile *file, GError **err); -void ag_chart_export_svg_to_file(AgChart *chart, - GFile *file, - GError **err); +void ag_chart_export_svg_to_file(AgChart *chart, + GFile *file, + AgDisplayTheme *theme, + GError **err); -void ag_chart_export_jpg_to_file(AgChart *chart, - GFile *file, - GError **err); +void ag_chart_export_jpg_to_file(AgChart *chart, + GFile *file, + AgDisplayTheme *theme, + GError **err); void ag_chart_set_name(AgChart *chart, const gchar *name); @@ -89,10 +92,11 @@ void ag_chart_set_city(AgChart *chart, const gchar *ag_chart_get_city(AgChart *chart); -gchar *ag_chart_create_svg(AgChart *chart, - gsize *length, - gboolean rendering, - GError **err); +gchar *ag_chart_create_svg(AgChart *chart, + gsize *length, + gboolean rendering, + AgDisplayTheme *theme, + GError **err); GList *ag_chart_get_planets(AgChart *chart); diff --git a/src/ag-window.c b/src/ag-window.c index cbacae6..e33d231 100644 --- a/src/ag-window.c +++ b/src/ag-window.c @@ -498,6 +498,7 @@ ag_window_redraw_chart(AgWindow *window) priv->chart, &length, FALSE, + NULL, &err ); @@ -1034,7 +1035,7 @@ ag_window_export_image(AgWindow *window, GError **err) if (can_save) { g_clear_error(&local_err); - save_func(priv->chart, file, &local_err); + save_func(priv->chart, file, priv->theme, &local_err); if (local_err) { ag_app_message_dialog( diff --git a/src/resources/ui/chart-default.xsl b/src/resources/ui/chart-default.xsl index 552d744..b14380b 100644 --- a/src/resources/ui/chart-default.xsl +++ b/src/resources/ui/chart-default.xsl @@ -75,6 +75,9 @@ +