Commit 68fa4f8c authored by Dominic Lachowicz's avatar Dominic Lachowicz Committed by Dom Lachowicz

Handle xml:space="prserve" (#353609)

2008-02-24  Dominic Lachowicz <domlachowicz@gmail.com>

	* rsvg-text.c:
	* rsvg-styles.h:
	* rsvg-styles.c: Handle xml:space="prserve" (#353609)


svn path=/trunk/; revision=1156
parent 1cebcf35
2008-02-24 Dominic Lachowicz <domlachowicz@gmail.com>
* rsvg-text.c:
* rsvg-styles.h:
* rsvg-styles.c: Handle xml:space="prserve" (#353609)
2008-02-24 Dominic Lachowicz <domlachowicz@gmail.com>
* rsvg-path.c (rsvg_parse_path_do_cmd): If a moveto is followed by
multiple pairs of coordinates, the subsequent pairs are treated as
implicit lineto commands. (#482787)
......
......@@ -246,6 +246,12 @@ rsvg_state_inherit_run (RsvgState * dst, const RsvgState * src,
dst->font_family = g_strdup (src->font_family);
}
if (function (dst->has_space_preserve, src->has_space_preserve))
dst->space_preserve = src->space_preserve;
if (function (dst->has_visible, src->has_visible))
dst->visible = src->visible;
if (function (dst->has_lang, src->has_lang)) {
if (dst->has_lang)
g_free (dst->lang);
......@@ -479,6 +485,14 @@ rsvg_parse_style_arg (RsvgHandle * ctx, RsvgState * state, const char *str)
state->visible = TRUE;
else
state->has_visible = FALSE;
} else if (rsvg_css_param_match (str, "xml:space")) {
state->has_space_preserve = TRUE;
if (!strcmp (str + arg_off, "default"))
state->space_preserve = FALSE;
else if (strcmp (str + arg_off, "preserve") == 0)
state->space_preserve = TRUE;
else
state->space_preserve = FALSE;
} else if (rsvg_css_param_match (str, "visibility")) {
state->has_visible = TRUE;
if (!strcmp (str + arg_off, "visible"))
......@@ -789,6 +803,7 @@ rsvg_parse_style_pairs (RsvgHandle * ctx, RsvgState * state, RsvgPropertyBag * a
rsvg_lookup_parse_style_pair (ctx, state, "visibility", atts);
rsvg_lookup_parse_style_pair (ctx, state, "writing-mode", atts);
rsvg_lookup_parse_style_pair (ctx, state, "xml:lang", atts);
rsvg_lookup_parse_style_pair (ctx, state, "xml:space", atts);
{
/* TODO: this conditional behavior isn't quite correct, and i'm not sure it should reside here */
......
......@@ -201,6 +201,9 @@ struct _RsvgState {
gboolean visible;
gboolean has_visible;
gboolean space_preserve;
gboolean has_space_preserve;
gboolean has_cond;
gboolean cond_true;
......
......@@ -90,34 +90,36 @@ rsvg_make_valid_utf8 (const char *str, int len)
}
static GString *
_rsvg_text_chomp (GString * in, gboolean * lastwasspace)
_rsvg_text_chomp (RsvgState *state, GString * in, gboolean * lastwasspace)
{
GString *out;
guint i;
out = g_string_new (in->str);
for (i = 0; i < out->len;) {
if (out->str[i] == '\n')
g_string_erase (out, i, 1);
else
i++;
}
for (i = 0; i < out->len; i++)
if (out->str[i] == '\t')
out->str[i] = ' ';
for (i = 0; i < out->len;) {
if (out->str[i] == ' ' && *lastwasspace)
g_string_erase (out, i, 1);
else {
if (out->str[i] == ' ')
*lastwasspace = TRUE;
else
*lastwasspace = FALSE;
i++;
}
}
if (!state->space_preserve) {
for (i = 0; i < out->len;) {
if (out->str[i] == '\n')
g_string_erase (out, i, 1);
else
i++;
}
for (i = 0; i < out->len; i++)
if (out->str[i] == '\t')
out->str[i] = ' ';
for (i = 0; i < out->len;) {
if (out->str[i] == ' ' && *lastwasspace)
g_string_erase (out, i, 1);
else {
if (out->str[i] == ' ')
*lastwasspace = TRUE;
else
*lastwasspace = FALSE;
i++;
}
}
}
return out;
}
......@@ -172,7 +174,7 @@ _rsvg_node_text_type_children (RsvgNode * self, RsvgDrawingCtx * ctx,
RsvgNode *node = g_ptr_array_index (self->children, i);
if (!strcmp (node->type->str, "RSVG_NODE_CHARS")) {
RsvgNodeChars *chars = (RsvgNodeChars *) node;
GString *str = _rsvg_text_chomp (chars->contents, lastwasspace);
GString *str = _rsvg_text_chomp (rsvg_state_current (ctx), chars->contents, lastwasspace);
rsvg_text_render_text (ctx, str->str, x, y);
g_string_free (str, TRUE);
} else if (!strcmp (node->type->str, "tspan")) {
......@@ -208,7 +210,7 @@ _rsvg_node_text_length_children (RsvgNode * self, RsvgDrawingCtx * ctx,
RsvgNode *node = g_ptr_array_index (self->children, i);
if (!strcmp (node->type->str, "RSVG_NODE_CHARS")) {
RsvgNodeChars *chars = (RsvgNodeChars *) node;
GString *str = _rsvg_text_chomp (chars->contents, lastwasspace);
GString *str = _rsvg_text_chomp (rsvg_state_current (ctx), chars->contents, lastwasspace);
*x += rsvg_text_length_text_as_string (ctx, str->str);
g_string_free (str, TRUE);
} else if (!strcmp (node->type->str, "tspan")) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment