Commit ec441166 authored by Dom Lachowicz's avatar Dom Lachowicz

beginnings of <switch> support

parent a9b49cb2
2004-06-18 Dom Lachowicz <cinamod@hotmail.com>
* rsvg.c: Beginnings of <switch> support
* rsvg-cond.c, rsvg-private.h, rsvg-shapes.c, rsvg-styles.c,
rsvg-styles.h: Ditto
2004-06-17 Dom Lachowicz <cinamod@hotmail.com>
* rsvg-css.c (rsvg_css_parse_list): Fix memory leak
......
......@@ -33,8 +33,6 @@
#include <stdlib.h>
#include <locale.h>
gboolean rsvg_eval_switch_attributes (RsvgPropertyBag *atts);
static const char * implemented_features [] =
{
"http://www.w3.org/TRr/SVG11/feature#BasicText",
......@@ -126,12 +124,11 @@ rsvg_cond_parse_required_extensions (const char * value)
return permitted;
}
/* http://www.w3.org/TR/SVG/struct.html#SystemLanguageAttribute */
static gboolean
rsvg_locale_compare (const char * a, const char * b)
{
const char * hyphen;
/* http://www.w3.org/TR/SVG/struct.html#SystemLanguageAttribute */
const char * hyphen;
/* check for an exact-ish match first */
if(!g_ascii_strncasecmp (a, b, strlen(b)))
......@@ -193,23 +190,33 @@ rsvg_cond_parse_system_language (const char * value)
/* returns TRUE if this element should be processed according to <switch> semantics
http://www.w3.org/TR/SVG/struct.html#SwitchElement */
gboolean
rsvg_eval_switch_attributes (RsvgPropertyBag *atts)
rsvg_eval_switch_attributes (RsvgPropertyBag *atts, gboolean * p_has_cond)
{
gboolean permitted = TRUE;
gboolean has_cond = FALSE;
if (atts && rsvg_property_bag_size (atts))
{
const char * value;
if ((value = rsvg_property_bag_lookup (atts, "requiredFeatures")))
if ((value = rsvg_property_bag_lookup (atts, "requiredFeatures"))) {
permitted = rsvg_cond_parse_required_features (value);
has_cond = TRUE;
}
if (permitted && (value = rsvg_property_bag_lookup (atts, "requiredExtensions")))
if (permitted && (value = rsvg_property_bag_lookup (atts, "requiredExtensions"))) {
permitted = rsvg_cond_parse_required_extensions (value);
has_cond = TRUE;
}
if (permitted && (value = rsvg_property_bag_lookup (atts, "systemLanguage")))
if (permitted && (value = rsvg_property_bag_lookup (atts, "systemLanguage"))) {
permitted = rsvg_cond_parse_system_language (value);
has_cond = TRUE;
}
}
if (p_has_cond)
*p_has_cond = has_cond;
return permitted;
}
......@@ -69,6 +69,8 @@ struct RsvgHandle {
guint nest_level;
void *current_defs_group;
guint in_switch;
GHashTable *css_props;
/* not a handler stack. each nested handler keeps
......@@ -173,6 +175,9 @@ rsvg_handle_get_base_uri (RsvgHandle *handle);
void rsvg_handle_set_base_uri (RsvgHandle *handle,
const char *base_uri);
gboolean
rsvg_eval_switch_attributes (RsvgPropertyBag *atts, gboolean * p_has_cond);
G_END_DECLS
#endif
......@@ -231,7 +231,7 @@ rsvg_render_bpath (RsvgHandle *ctx, const ArtBpath *bpath)
/* todo: handle visibility stuff earlier for performance benefits
* handles all path based shapes. will handle text and images separately
*/
if (!state->visible)
if (!state->visible || !state->cond_true)
return;
affine_bpath = art_bpath_affine_transform (bpath,
......@@ -1679,7 +1679,7 @@ rsvg_start_image (RsvgHandle *ctx, RsvgPropertyBag *atts)
return;
/* figure out if image is visible or not */
if (!state->visible)
if (!state->visible || !state->cond_true)
return;
w *= state->affine[0];
......
......@@ -38,8 +38,6 @@
#define RSVG_DEFAULT_FONT "Times New Roman"
#define ENABLE_ADOBE_EXTENSIONS 1
static guint32
rsvg_state_current_color (RsvgState * cur_state, RsvgState * parent_state)
{
......@@ -92,6 +90,7 @@ rsvg_state_init (RsvgState *state)
state->unicode_bidi = UNICODE_BIDI_NORMAL;
state->text_anchor = TEXT_ANCHOR_START;
state->visible = TRUE;
state->cond_true = TRUE;
state->filter = NULL;
state->startMarker = NULL;
state->middleMarker = NULL;
......@@ -109,6 +108,7 @@ rsvg_state_init (RsvgState *state)
state->has_join = FALSE;
state->has_dash = FALSE;
state->has_visible = FALSE;
state->has_cond = FALSE;
state->has_stop_color = FALSE;
state->has_stop_opacity = FALSE;
state->has_font_size = FALSE;
......@@ -186,6 +186,8 @@ rsvg_state_reinherit (RsvgState *dst, const RsvgState *src)
dst->stop_opacity = src->stop_opacity;
if (!dst->has_visible)
dst->visible = src->visible;
if (!dst->has_cond)
dst->cond_true = src->cond_true;
if (!dst->has_font_size)
dst->font_size = src->font_size;
if (!dst->has_font_style)
......@@ -266,8 +268,8 @@ rsvg_state_dominate (RsvgState *dst, const RsvgState *src)
dst->stop_color = src->stop_color;
if (!dst->has_stop_opacity || src->has_stop_opacity)
dst->stop_opacity = src->stop_opacity;
if (!dst->has_visible || src->has_visible)
dst->visible = src->visible;
if (!dst->has_cond || src->has_cond)
dst->cond_true = src->cond_true;
if (!dst->has_font_size || src->has_font_size)
dst->font_size = src->font_size;
if (!dst->has_font_style || src->has_font_style)
......@@ -362,7 +364,6 @@ rsvg_parse_style_arg (RsvgHandle *ctx, RsvgState *state, const char *str)
}
else if (rsvg_css_param_match (str, "filter"))
state->filter = rsvg_filter_parse(ctx->defs, str + arg_off);
#if ENABLE_ADOBE_EXTENSIONS
else if (rsvg_css_param_match (str, "a:adobe-blending-mode"))
{
if (!strcmp (str + arg_off, "normal"))
......@@ -392,7 +393,6 @@ rsvg_parse_style_arg (RsvgHandle *ctx, RsvgState *state, const char *str)
else
state->adobe_blend = 0;
}
#endif
else if (rsvg_css_param_match (str, "mask"))
state->mask = rsvg_mask_parse(ctx->defs, str + arg_off);
else if (rsvg_css_param_match (str, "enable-background"))
......@@ -741,44 +741,54 @@ void
rsvg_parse_style_pairs (RsvgHandle *ctx, RsvgState *state,
RsvgPropertyBag *atts)
{
#if ENABLE_ADOBE_EXTENSIONS
rsvg_lookup_parse_style_pair (ctx, state, "a:adobe-blending-mode", atts);
#endif
rsvg_lookup_parse_style_pair (ctx, state, "color", atts);
rsvg_lookup_parse_style_pair (ctx, state, "direction", atts);
rsvg_lookup_parse_style_pair (ctx, state, "display", atts);
rsvg_lookup_parse_style_pair (ctx, state, "enable-background", atts);
rsvg_lookup_parse_style_pair (ctx, state, "fill", atts);
rsvg_lookup_parse_style_pair (ctx, state, "fill-opacity", atts);
rsvg_lookup_parse_style_pair (ctx, state, "fill-rule", atts);
rsvg_lookup_parse_style_pair (ctx, state, "filter", atts);
rsvg_lookup_parse_style_pair (ctx, state, "font-family", atts);
rsvg_lookup_parse_style_pair (ctx, state, "font-size", atts);
rsvg_lookup_parse_style_pair (ctx, state, "font-stretch", atts);
rsvg_lookup_parse_style_pair (ctx, state, "font-style", atts);
rsvg_lookup_parse_style_pair (ctx, state, "font-variant", atts);
rsvg_lookup_parse_style_pair (ctx, state, "font-weight", atts);
rsvg_lookup_parse_style_pair (ctx, state, "marker-end", atts);
rsvg_lookup_parse_style_pair (ctx, state, "mask", atts);
rsvg_lookup_parse_style_pair (ctx, state, "marker-mid", atts);
rsvg_lookup_parse_style_pair (ctx, state, "marker-start", atts);
rsvg_lookup_parse_style_pair (ctx, state, "opacity", atts);
rsvg_lookup_parse_style_pair (ctx, state, "stop-color", atts);
rsvg_lookup_parse_style_pair (ctx, state, "stop-opacity", atts);
rsvg_lookup_parse_style_pair (ctx, state, "stroke", atts);
rsvg_lookup_parse_style_pair (ctx, state, "stroke-dasharray", atts);
rsvg_lookup_parse_style_pair (ctx, state, "stroke-dashoffset", atts);
rsvg_lookup_parse_style_pair (ctx, state, "stroke-linecap", atts);
rsvg_lookup_parse_style_pair (ctx, state, "stroke-linejoin", atts);
rsvg_lookup_parse_style_pair (ctx, state, "stroke-miterlimit", atts);
rsvg_lookup_parse_style_pair (ctx, state, "stroke-opacity", atts);
rsvg_lookup_parse_style_pair (ctx, state, "stroke-width", atts);
rsvg_lookup_parse_style_pair (ctx, state, "text-anchor", atts);
rsvg_lookup_parse_style_pair (ctx, state, "text-decoration", atts);
rsvg_lookup_parse_style_pair (ctx, state, "unicode-bidi", atts);
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, "a:adobe-blending-mode", atts);
rsvg_lookup_parse_style_pair (ctx, state, "color", atts);
rsvg_lookup_parse_style_pair (ctx, state, "direction", atts);
rsvg_lookup_parse_style_pair (ctx, state, "display", atts);
rsvg_lookup_parse_style_pair (ctx, state, "enable-background", atts);
rsvg_lookup_parse_style_pair (ctx, state, "fill", atts);
rsvg_lookup_parse_style_pair (ctx, state, "fill-opacity", atts);
rsvg_lookup_parse_style_pair (ctx, state, "fill-rule", atts);
rsvg_lookup_parse_style_pair (ctx, state, "filter", atts);
rsvg_lookup_parse_style_pair (ctx, state, "font-family", atts);
rsvg_lookup_parse_style_pair (ctx, state, "font-size", atts);
rsvg_lookup_parse_style_pair (ctx, state, "font-stretch", atts);
rsvg_lookup_parse_style_pair (ctx, state, "font-style", atts);
rsvg_lookup_parse_style_pair (ctx, state, "font-variant", atts);
rsvg_lookup_parse_style_pair (ctx, state, "font-weight", atts);
rsvg_lookup_parse_style_pair (ctx, state, "marker-end", atts);
rsvg_lookup_parse_style_pair (ctx, state, "mask", atts);
rsvg_lookup_parse_style_pair (ctx, state, "marker-mid", atts);
rsvg_lookup_parse_style_pair (ctx, state, "marker-start", atts);
rsvg_lookup_parse_style_pair (ctx, state, "opacity", atts);
rsvg_lookup_parse_style_pair (ctx, state, "stop-color", atts);
rsvg_lookup_parse_style_pair (ctx, state, "stop-opacity", atts);
rsvg_lookup_parse_style_pair (ctx, state, "stroke", atts);
rsvg_lookup_parse_style_pair (ctx, state, "stroke-dasharray", atts);
rsvg_lookup_parse_style_pair (ctx, state, "stroke-dashoffset", atts);
rsvg_lookup_parse_style_pair (ctx, state, "stroke-linecap", atts);
rsvg_lookup_parse_style_pair (ctx, state, "stroke-linejoin", atts);
rsvg_lookup_parse_style_pair (ctx, state, "stroke-miterlimit", atts);
rsvg_lookup_parse_style_pair (ctx, state, "stroke-opacity", atts);
rsvg_lookup_parse_style_pair (ctx, state, "stroke-width", atts);
rsvg_lookup_parse_style_pair (ctx, state, "text-anchor", atts);
rsvg_lookup_parse_style_pair (ctx, state, "text-decoration", atts);
rsvg_lookup_parse_style_pair (ctx, state, "unicode-bidi", atts);
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);
{
/* TODO: this conditional behavior isn't quite correct, and i'm not sure it should reside here */
gboolean cond_true, has_cond;
cond_true = rsvg_eval_switch_attributes (atts, &has_cond);
if (has_cond) {
state->cond_true = cond_true;
state->has_cond = TRUE;
}
}
}
/* Split a CSS2 style into individual style arguments, setting attributes
......
......@@ -127,6 +127,9 @@ struct _RsvgState {
gboolean visible;
gboolean has_visible;
gboolean has_cond;
gboolean cond_true;
ArtVpathDash dash;
gboolean has_dash;
......
......@@ -1226,6 +1226,10 @@ rsvg_start_element (void *data, const xmlChar *name,
ctx->in_defs++;
rsvg_start_marker (ctx, bag);
}
else if (!strcmp ((char *)name, "switch"))
{
ctx->in_switch++;
}
/* see conicalGradient discussion above */
else if (!strcmp ((char *)name, "linearGradient"))
rsvg_start_linear_gradient (ctx, bag);
......@@ -1283,6 +1287,10 @@ rsvg_end_element (void *data, const xmlChar *name)
rsvg_pop_def_group(ctx);
ctx->in_defs--;
}
else if (!strcmp ((char *)name, "switch"))
{
ctx->in_switch--;
}
else if (!strcmp ((char *)name, "pattern")) {
ctx->in_defs--;
rsvg_pop_def_group(ctx);
......
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