Merge pull request #84 from gergelypolonkai/bug-82

Set display theme for saved images
This commit is contained in:
Gergely Polonkai 2014-09-21 23:14:26 +02:00
commit 34b58e39fb
6 changed files with 67 additions and 25 deletions

View File

@ -1395,11 +1395,11 @@ ag_chart_sort_planets_by_position(GswePlanetData *planet1,
} }
gchar * gchar *
ag_chart_create_svg( ag_chart_create_svg(AgChart *chart,
AgChart *chart, gsize *length,
gsize *length, gboolean rendering,
gboolean rendering, AgDisplayTheme *theme,
GError **err) GError **err)
{ {
xmlDocPtr doc = create_save_doc(chart), xmlDocPtr doc = create_save_doc(chart),
xslt_doc, xslt_doc,
@ -1412,6 +1412,7 @@ ag_chart_create_svg(
antiscia_node = NULL, antiscia_node = NULL,
node = NULL; node = NULL;
gchar *value, gchar *value,
*css,
*save_content = NULL, *save_content = NULL,
**params; **params;
const gchar *xslt_content; const gchar *xslt_content;
@ -1717,9 +1718,21 @@ ag_chart_create_svg(
return NULL; return NULL;
} }
params = g_new0(gchar *, 3); params = g_new0(gchar *, 5);
params[0] = "rendering"; params[0] = "rendering";
params[1] = (rendering) ? "'yes'" : "'no'"; 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 // 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 // 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); uselocale(current_locale);
xsltFreeStylesheet(xslt_proc); xsltFreeStylesheet(xslt_proc);
xmlFreeDoc(doc); xmlFreeDoc(doc);
g_free(params[3]);
g_free(params); g_free(params);
// Now, svg_doc contains the generated SVG file // Now, svg_doc contains the generated SVG file
@ -1761,12 +1775,15 @@ ag_chart_get_planets(AgChart *chart)
} }
void 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; gchar *svg;
gsize length; 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; return;
} }
@ -1784,7 +1801,10 @@ ag_chart_export_svg_to_file(AgChart *chart, GFile *file, GError **err)
} }
void 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, gchar *svg,
*jpg; *jpg;
@ -1793,7 +1813,13 @@ ag_chart_export_jpg_to_file(AgChart *chart, GFile *file, GError **err)
RsvgHandle *svg_handle; RsvgHandle *svg_handle;
GdkPixbuf *pixbuf; 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; return;
} }

View File

@ -6,6 +6,7 @@
#include <swe-glib.h> #include <swe-glib.h>
#include "ag-db.h" #include "ag-db.h"
#include "ag-display-theme.h"
G_BEGIN_DECLS G_BEGIN_DECLS
@ -44,7 +45,7 @@ struct _AgChartClass {
GsweMomentClass parent_class; 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; GType ag_chart_get_type(void) G_GNUC_CONST;
@ -66,13 +67,15 @@ void ag_chart_save_to_file(AgChart *chart,
GFile *file, GFile *file,
GError **err); GError **err);
void ag_chart_export_svg_to_file(AgChart *chart, void ag_chart_export_svg_to_file(AgChart *chart,
GFile *file, GFile *file,
GError **err); AgDisplayTheme *theme,
GError **err);
void ag_chart_export_jpg_to_file(AgChart *chart, void ag_chart_export_jpg_to_file(AgChart *chart,
GFile *file, GFile *file,
GError **err); AgDisplayTheme *theme,
GError **err);
void ag_chart_set_name(AgChart *chart, void ag_chart_set_name(AgChart *chart,
const gchar *name); const gchar *name);
@ -89,10 +92,11 @@ void ag_chart_set_city(AgChart *chart,
const gchar *ag_chart_get_city(AgChart *chart); const gchar *ag_chart_get_city(AgChart *chart);
gchar *ag_chart_create_svg(AgChart *chart, gchar *ag_chart_create_svg(AgChart *chart,
gsize *length, gsize *length,
gboolean rendering, gboolean rendering,
GError **err); AgDisplayTheme *theme,
GError **err);
GList *ag_chart_get_planets(AgChart *chart); GList *ag_chart_get_planets(AgChart *chart);

View File

@ -54,6 +54,11 @@ ag_display_theme_to_css(AgDisplayTheme *theme)
gchar *ret; gchar *ret;
GString *css = NULL; GString *css = NULL;
// Null themes are possible, deal with it!
if (theme == NULL) {
return g_strdup("");
}
if (theme->planets_include) { if (theme->planets_include) {
css = g_string_new(planet_none); css = g_string_new(planet_none);
} else { } else {

View File

@ -498,6 +498,7 @@ ag_window_redraw_chart(AgWindow *window)
priv->chart, priv->chart,
&length, &length,
FALSE, FALSE,
NULL,
&err &err
); );
@ -1034,7 +1035,7 @@ ag_window_export_image(AgWindow *window, GError **err)
if (can_save) { if (can_save) {
g_clear_error(&local_err); g_clear_error(&local_err);
save_func(priv->chart, file, &local_err); save_func(priv->chart, file, priv->theme, &local_err);
if (local_err) { if (local_err) {
ag_app_message_dialog( ag_app_message_dialog(
@ -1394,12 +1395,15 @@ ag_window_update_style_sheets(AgWindow *window)
static void static void
ag_window_set_theme(AgWindow *window, AgDisplayTheme *theme) ag_window_set_theme(AgWindow *window, AgDisplayTheme *theme)
{ {
gchar *css, gchar *css,
*css_final; *css_final;
AgWindowPrivate *priv = ag_window_get_instance_private(window);
g_debug("Setting theme to %s", (theme) ? theme->name : "no theme"); g_debug("Setting theme to %s", (theme) ? theme->name : "no theme");
ag_window_clear_style_sheets(window); ag_window_clear_style_sheets(window);
priv->theme = theme;
// Add the default style sheet // Add the default style sheet
ag_window_add_style_sheet( ag_window_add_style_sheet(
window, window,

View File

@ -84,7 +84,7 @@ line.aspect-conjuction {
} }
line.aspect-sextile { line.aspect-sextile {
stroke-width: 1 stroke-width: 1;
stroke: #00cc00; stroke: #00cc00;
stroke-dasharray: none; stroke-dasharray: none;
} }

View File

@ -75,6 +75,9 @@
<style type="text/css"> <style type="text/css">
<xi:include href="gres://ui/chart-default.css" parse="text"/> <xi:include href="gres://ui/chart-default.css" parse="text"/>
</style> </style>
<style type="text/css">
<xsl:value-of select="$additional-css"/>
</style>
</xsl:when> </xsl:when>
</xsl:choose> </xsl:choose>