Add a rendering parameter to ag_chart_create_svg()

Based upon this parameter a <rect> is included in the resulting SVG
document, providing a background color, and so is the chart CSS.
This commit is contained in:
Gergely Polonkai 2014-09-17 11:22:17 +02:00
parent 2cf75ede55
commit 7fe6a16401
5 changed files with 44 additions and 7 deletions

View File

@ -1393,7 +1393,11 @@ ag_chart_sort_planets_by_position(GswePlanetData *planet1,
}
gchar *
ag_chart_create_svg(AgChart *chart, gsize *length, GError **err)
ag_chart_create_svg(
AgChart *chart,
gsize *length,
gboolean rendering,
GError **err)
{
xmlDocPtr doc = create_save_doc(chart),
xslt_doc,
@ -1406,7 +1410,8 @@ ag_chart_create_svg(AgChart *chart, gsize *length, GError **err)
antiscia_node = NULL,
node = NULL;
gchar *value,
*save_content = NULL;
*save_content = NULL,
**params;
const gchar *xslt_content;
GList *houses,
*house,
@ -1710,15 +1715,22 @@ ag_chart_create_svg(AgChart *chart, gsize *length, GError **err)
return NULL;
}
params = g_new0(gchar *, 3);
params[0] = "rendering";
params[1] = (rendering) ? "'yes'" : "'no'";
// 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);
xsltFreeStylesheet(xslt_proc);
xmlFreeDoc(doc);
g_free(params);
// Now, svg_doc contains the generated SVG file
@ -1752,7 +1764,7 @@ ag_chart_export_svg_to_file(AgChart *chart, GFile *file, GError **err)
gchar *svg;
gsize length;
if ((svg = ag_chart_create_svg(chart, &length, err)) == NULL) {
if ((svg = ag_chart_create_svg(chart, &length, TRUE, err)) == NULL) {
return;
}

View File

@ -84,9 +84,10 @@ void ag_chart_set_city(AgChart *chart,
const gchar *ag_chart_get_city(AgChart *chart);
gchar *ag_chart_create_svg(AgChart *chart,
gsize *length,
GError **err);
gchar *ag_chart_create_svg(AgChart *chart,
gsize *length,
gboolean rendering,
GError **err);
GList *ag_chart_get_planets(AgChart *chart);

View File

@ -496,6 +496,7 @@ ag_window_redraw_chart(AgWindow *window)
gchar *svg_content = ag_chart_create_svg(
priv->chart,
&length,
FALSE,
&err
);

View File

@ -134,3 +134,7 @@ line.antiscion {
stroke: #000000;
stroke-dasharray: 20,10;
}
#background {
fill: #ffffff;
}

View File

@ -69,6 +69,15 @@
version="1.0">
<xsl:attribute name="width"><xsl:value-of select="$image_size"/></xsl:attribute>
<xsl:attribute name="height"><xsl:value-of select="$image_size"/></xsl:attribute>
<xsl:choose>
<xsl:when test="$rendering='yes'">
<style type="text/css">
<xi:include href="gres://ui/chart-default.css" parse="text"/>
</style>
</xsl:when>
</xsl:choose>
<title>
<xsl:value-of select="concat(
'Natal chart of ',
@ -116,6 +125,16 @@
<polygon points="0.0,0.0 7.0,-2.0 5.0,0.0 7.0,2.0" />
</marker>
</defs>
<xsl:choose>
<xsl:when test="$rendering='yes'">
<rect id="background" x="0" y="0">
<xsl:attribute name="width"><xsl:value-of select="$image_size"/></xsl:attribute>
<xsl:attribute name="height"><xsl:value-of select="$image_size"/></xsl:attribute>
</rect>
</xsl:when>
</xsl:choose>
<g id="chart">
<xsl:attribute name="transform"><xsl:value-of select="concat('translate(', $image_size div 2, ',', $image_size div 2, ')')" /></xsl:attribute>
<g id="moonless_chart">