Commit c930cbd1 authored by Caleb Michael Moore's avatar Caleb Michael Moore

consistant node children and styles

parent 5f9f64c3
2005-07-20 Caleb Moore <c.moore@student.unsw.edu.au>
* rsvg.c: created a text node that isn't being used yet but is proving very useful for type checking
* rsvg-structure.c: created a default node initialiser function and destructor function, now everything has a style and children whether it needs to or not, adding to the memory footprint but increasing stability
* rsvg-filter.c: makeing objects safe for when their children are of the wrong type
2005-07-11 Caleb Moore <c.moore@student.unsw.edu.au>
* rsvg-structure.c: Bug 309885
......
......@@ -41,22 +41,34 @@
#include <math.h>
static ArtGradientStop *
rsvg_paint_art_stops_from_rsvg (GPtrArray *rstops,
rsvg_paint_art_stops_from_rsvg (GPtrArray *rstops, guint32 * nstops,
guint32 current_color)
{
ArtGradientStop *stops;
int n_stop = rstops->len;
int i;
unsigned int n_stop = rstops->len;
unsigned int i, j;
stops = g_new (ArtGradientStop, n_stop);
j = 0;
for (i = 0; i < n_stop; i++)
if (((RsvgNode *)g_ptr_array_index(rstops, i))->type == RSVG_NODE_STOP)
j++;
*nstops = j;
stops = g_new (ArtGradientStop, j);
j = 0;
for (i = 0; i < n_stop; i++)
{
RsvgGradientStop * stop;
RsvgNode * temp;
guint32 rgba;
guint32 r, g, b, a;
stop = (RsvgGradientStop *)g_ptr_array_index(rstops, i);
stops[i].offset = stop->offset;
temp = (RsvgNode *)g_ptr_array_index(rstops, i);
if (temp->type != RSVG_NODE_STOP)
continue;
stop = (RsvgGradientStop *)temp;
stops[j].offset = stop->offset;
if (!stop->is_current_color)
rgba = stop->rgba;
else
......@@ -69,10 +81,11 @@ rsvg_paint_art_stops_from_rsvg (GPtrArray *rstops,
g = (g + (g >> 8)) >> 8;
b = ((rgba >> 8) & 0xff) * a + 0x80;
b = (b + (b >> 8)) >> 8;
stops[i].color[0] = ART_PIX_MAX_FROM_8(r);
stops[i].color[1] = ART_PIX_MAX_FROM_8(g);
stops[i].color[2] = ART_PIX_MAX_FROM_8(b);
stops[i].color[3] = ART_PIX_MAX_FROM_8(a);
stops[j].color[0] = ART_PIX_MAX_FROM_8(r);
stops[j].color[1] = ART_PIX_MAX_FROM_8(g);
stops[j].color[2] = ART_PIX_MAX_FROM_8(b);
stops[j].color[3] = ART_PIX_MAX_FROM_8(a);
j++;
}
return stops;
}
......@@ -128,8 +141,8 @@ rsvg_art_paint_server_lin_grad_render (RsvgLinearGradient *rlg, ArtRender *ar,
}
agl = g_new (ArtGradientLinear, 1);
agl->n_stops = rlg->super.children->len;
agl->stops = rsvg_paint_art_stops_from_rsvg (rlg->super.children, current_color);
agl->stops = rsvg_paint_art_stops_from_rsvg (rlg->super.children,
&agl->n_stops, current_color);
if (rlg->obj_bbox) {
......@@ -260,8 +273,8 @@ rsvg_art_paint_server_rad_grad_render (RsvgRadialGradient *rrg, ArtRender *ar,
return;
}
agr = g_new (ArtGradientRadial, 1);
agr->n_stops = rrg->super.children->len;
agr->stops = rsvg_paint_art_stops_from_rsvg (rrg->super.children, current_color);
agr->stops = rsvg_paint_art_stops_from_rsvg (rrg->super.children,
&agr->n_stops, current_color);
_rsvg_affine_scale (aff1, rrg->r, rrg->r);
_rsvg_affine_translate (aff2, rrg->cx, rrg->cy);
......
This diff is collapsed.
......@@ -97,8 +97,7 @@ rsvg_new_marker (void)
{
RsvgMarker *marker;
marker = g_new (RsvgMarker, 1);
marker->super.state = g_new(RsvgState, 1);
rsvg_state_init(marker->super.state);
_rsvg_node_init(&marker->super);
marker->orient = 0;
marker->orientAuto = FALSE;
marker->overflow = FALSE;
......@@ -110,9 +109,6 @@ rsvg_new_marker (void)
marker->bbox = TRUE;
marker->vbox = FALSE;
marker->super.type = RSVG_NODE_MARKER;
marker->super.children = g_ptr_array_new();
marker->super.free = rsvg_node_free;
marker->super.draw = _rsvg_node_draw_nothing;
marker->super.set_atts = rsvg_node_marker_set_atts;
return &marker->super;
}
......
......@@ -96,18 +96,14 @@ rsvg_new_mask (void)
RsvgMask *mask;
mask = g_new (RsvgMask, 1);
_rsvg_node_init(&mask->super);
mask->maskunits = objectBoundingBox;
mask->contentunits = userSpaceOnUse;
mask->x = 0;
mask->y = 0;
mask->width = 1;
mask->height = 1;
mask->super.state = g_new(RsvgState, 1);
rsvg_state_init(mask->super.state);
mask->super.children = g_ptr_array_new ();
mask->super.type = RSVG_NODE_MASK;
mask->super.free = rsvg_node_free;
mask->super.draw = _rsvg_node_draw_nothing;
mask->super.set_atts = rsvg_mask_set_atts;
return &mask->super;
}
......@@ -181,12 +177,9 @@ rsvg_new_clip_path (void)
RsvgClipPath *clip_path;
clip_path = g_new (RsvgClipPath, 1);
clip_path->super.children = g_ptr_array_new ();
_rsvg_node_init(&clip_path->super);
clip_path->units = userSpaceOnUse;
clip_path->super.state = g_new(RsvgState, 1);
clip_path->super.type = RSVG_NODE_CLIP_PATH;
clip_path->super.free = rsvg_node_free;
clip_path->super.draw = _rsvg_node_draw_nothing;
clip_path->super.set_atts = rsvg_clip_path_set_atts;
return &clip_path->super;
}
......
......@@ -37,13 +37,6 @@
#include "rsvg-css.h"
static void
rsvg_pserver_free (RsvgNode *self)
{
g_ptr_array_free(self->children, TRUE);
g_free (self);
}
static RsvgPaintServer *
rsvg_paint_server_solid (guint32 rgb)
{
......@@ -242,21 +235,16 @@ rsvg_stop_set_atts (RsvgNode *self, RsvgHandle *ctx,
rsvg_state_finalize(&state);
}
static void
rsvg_stop_free(RsvgNode * self)
{
g_free(self);
}
RsvgNode *
rsvg_new_stop (void)
{
RsvgGradientStop * stop = g_new(RsvgGradientStop, 1);
stop->super.free = rsvg_stop_free;
_rsvg_node_init(&stop->super);
stop->super.set_atts = rsvg_stop_set_atts;
stop->offset = 0;
stop->rgba = 0;
stop->is_current_color = 0;
stop->super.type = RSVG_NODE_STOP;
return &stop->super;
}
......@@ -324,8 +312,8 @@ rsvg_new_linear_gradient (void)
{
RsvgLinearGradient *grad = NULL;
grad = g_new (RsvgLinearGradient, 1);
_rsvg_node_init(&grad->super);
grad->super.type = RSVG_NODE_LINGRAD;
grad->super.free = rsvg_pserver_free;
_rsvg_affine_identity(grad->affine);
grad->has_current_color = FALSE;
grad->x1 = 0;
......@@ -335,9 +323,7 @@ rsvg_new_linear_gradient (void)
grad->fallback = NULL;
grad->obj_bbox = TRUE;
grad->spread = RSVG_GRADIENT_PAD;
grad->super.children = g_ptr_array_new();
grad->super.set_atts = rsvg_linear_gradient_set_atts;
grad->super.draw = _rsvg_node_draw_nothing;
grad->hasx1 = grad->hasy1 = grad->hasx2 = grad->hasy2 = grad->hasbbox = grad->hasspread = grad->hastransform = FALSE;
return &grad->super;
}
......@@ -410,8 +396,8 @@ rsvg_new_radial_gradient (void)
{
RsvgRadialGradient * grad = g_new (RsvgRadialGradient, 1);
_rsvg_node_init(&grad->super);
grad->super.type = RSVG_NODE_RADGRAD;
grad->super.free = rsvg_pserver_free;
_rsvg_affine_identity(grad->affine);
grad->has_current_color = FALSE;
grad->obj_bbox = TRUE;
......@@ -422,10 +408,8 @@ rsvg_new_radial_gradient (void)
grad->r = 0.5;
grad->fx = 0.5;
grad->fy = 0.5;
grad->super.children = g_ptr_array_new();
grad->super.set_atts = rsvg_radial_gradient_set_atts;
grad->hascx = grad->hascy = grad->hasfx = grad->hasfy = grad->hasr = grad->hasbbox = grad->hasspread = grad->hastransform = FALSE;
grad->super.draw = _rsvg_node_draw_nothing;
return &grad->super;
}
......@@ -496,6 +480,7 @@ RsvgNode *
rsvg_new_pattern (void)
{
RsvgPattern *pattern = g_new (RsvgPattern, 1);
_rsvg_node_init(&pattern->super);
pattern->obj_bbox = TRUE;
pattern->obj_cbbox = FALSE;
pattern->x = 0;
......@@ -510,11 +495,6 @@ rsvg_new_pattern (void)
pattern->preserve_aspect_ratio = RSVG_ASPECT_RATIO_XMID_YMID;
pattern->vbox = FALSE;
_rsvg_affine_identity(pattern->affine);
pattern->super.draw = _rsvg_node_draw_nothing;
pattern->super.state = g_new(RsvgState, 1);
rsvg_state_init(pattern->super.state);
pattern->super.children = g_ptr_array_new();
pattern->super.free = rsvg_pserver_free;
pattern->super.set_atts = rsvg_pattern_set_atts;
pattern->super.type = RSVG_NODE_PATTERN;
pattern->hasx = pattern->hasy = pattern->haswidth = pattern->hasheight = pattern->hasvbox = pattern->hasbbox = pattern->hascbox = pattern->hasaspect = pattern->hastransform = pattern->hasaspect = FALSE;
......
......@@ -195,6 +195,7 @@ typedef enum {
RSVG_NODE_MARKER,
RSVG_NODE_SYMBOL,
RSVG_NODE_CLIP_PATH,
RSVG_NODE_STOP,
RSVG_NODE_CHARS
} RsvgNodeType;
......
......@@ -93,10 +93,8 @@ rsvg_new_path (void)
{
RsvgNodePath *path;
path = g_new (RsvgNodePath, 1);
_rsvg_node_init(&path->super);
path->d = NULL;
path->super.state = g_new(RsvgState, 1);
rsvg_state_init(path->super.state);
path->super.children = NULL;
path->super.type = RSVG_NODE_PATH;
path->super.free = rsvg_node_path_free;
path->super.draw = rsvg_node_path_draw;
......@@ -184,9 +182,7 @@ rsvg_new_any_poly(gboolean is_polyline)
{
RsvgNodePoly *poly;
poly = g_new (RsvgNodePoly, 1);
poly->super.children = NULL;
poly->super.state = g_new(RsvgState, 1);
rsvg_state_init(poly->super.state);
_rsvg_node_init(&poly->super);
poly->super.type = RSVG_NODE_PATH;
poly->super.free = _rsvg_node_poly_free;
poly->super.draw = _rsvg_node_poly_draw;
......@@ -281,11 +277,8 @@ rsvg_new_line (void)
{
RsvgNodeLine *line;
line = g_new (RsvgNodeLine, 1);
line->super.children = NULL;
line->super.state = g_new(RsvgState, 1);
rsvg_state_init(line->super.state);
_rsvg_node_init(&line->super);
line->super.type = RSVG_NODE_PATH;
line->super.free = rsvg_node_free;
line->super.draw = _rsvg_node_line_draw;
line->super.set_atts = _rsvg_node_line_set_atts;
line->x1 = line->x2 = line->y1 = line->y2 = 0;
......@@ -453,11 +446,8 @@ rsvg_new_rect (void)
{
RsvgNodeRect *rect;
rect = g_new (RsvgNodeRect, 1);
rect->super.children = NULL;
rect->super.state = g_new(RsvgState, 1);
rsvg_state_init(rect->super.state);
_rsvg_node_init(&rect->super);
rect->super.type = RSVG_NODE_PATH;
rect->super.free = rsvg_node_free;
rect->super.draw = _rsvg_node_rect_draw;
rect->super.set_atts = _rsvg_node_rect_set_atts;
rect->x = rect->y = rect->w = rect->h = rect->rx = rect->ry = 0;
......@@ -587,11 +577,8 @@ rsvg_new_circle (void)
{
RsvgNodeCircle *circle;
circle = g_new (RsvgNodeCircle, 1);
circle->super.children = NULL;
circle->super.state = g_new(RsvgState, 1);
rsvg_state_init(circle->super.state);
_rsvg_node_init(&circle->super);
circle->super.type = RSVG_NODE_PATH;
circle->super.free = rsvg_node_free;
circle->super.draw = _rsvg_node_circle_draw;
circle->super.set_atts = _rsvg_node_circle_set_atts;
circle->cx = circle->cy = circle->r = 0;
......@@ -718,11 +705,8 @@ rsvg_new_ellipse (void)
{
RsvgNodeEllipse *ellipse;
ellipse = g_new (RsvgNodeEllipse, 1);
ellipse->super.children = NULL;
ellipse->super.state = g_new(RsvgState, 1);
rsvg_state_init(ellipse->super.state);
_rsvg_node_init(&ellipse->super);
ellipse->super.type = RSVG_NODE_PATH;
ellipse->super.free = rsvg_node_free;
ellipse->super.draw = _rsvg_node_ellipse_draw;
ellipse->super.set_atts = _rsvg_node_ellipse_set_atts;
ellipse->cx = ellipse->cy = ellipse->rx = ellipse->ry = 0;
......
......@@ -70,18 +70,37 @@ _rsvg_node_draw_children (RsvgNode * self, RsvgDrawingCtx *ctx,
}
/* generic function that doesn't draw anything at all */
void
static void
_rsvg_node_draw_nothing (RsvgNode * self, RsvgDrawingCtx *ctx,
int dominate)
{
}
static void
_rsvg_node_dont_set_atts (RsvgNode * node, RsvgHandle * ctx, RsvgPropertyBag * atts)
{
}
void
_rsvg_node_init(RsvgNode *self)
{
self->children = g_ptr_array_new();
self->state = g_new(RsvgState, 1);
rsvg_state_init(self->state);
self->type = RSVG_NODE_PATH;
self->free = _rsvg_node_free;
self->draw = _rsvg_node_draw_nothing;
self->set_atts = _rsvg_node_dont_set_atts;
}
void
rsvg_node_free (RsvgNode *self)
_rsvg_node_free (RsvgNode *self)
{
rsvg_state_finalize (self->state);
if (self->state != NULL)
g_free(self->state);
{
rsvg_state_finalize (self->state);
g_free(self->state);
}
if (self->children != NULL)
g_ptr_array_free(self->children, TRUE);
g_free (self);
......@@ -111,11 +130,8 @@ rsvg_new_group (void)
{
RsvgNodeGroup *group;
group = g_new (RsvgNodeGroup, 1);
group->super.children = g_ptr_array_new();
group->super.state = g_new(RsvgState, 1);
rsvg_state_init(group->super.state);
_rsvg_node_init(&group->super);
group->super.type = RSVG_NODE_PATH;
group->super.free = rsvg_node_free;
group->super.draw = _rsvg_node_draw_children;
group->super.set_atts = rsvg_node_group_set_atts;
return &group->super;
......@@ -326,16 +342,13 @@ rsvg_new_svg (void)
{
RsvgNodeSvg * svg;
svg = g_new (RsvgNodeSvg, 1);
_rsvg_node_init(&svg->super);
svg->has_vbox = FALSE;
svg->preserve_aspect_ratio = RSVG_ASPECT_RATIO_XMID_YMID;
svg->x = 0; svg->y = 0; svg->w = -1; svg->h = -1;
svg->hasw = svg->hash = FALSE;
svg->vbx = 0; svg->vby = 0; svg->vbw = 0; svg->vbh = 0;
svg->super.children = g_ptr_array_new();
svg->super.state = g_new(RsvgState, 1);
rsvg_state_init(svg->super.state);
svg->super.type = RSVG_NODE_PATH;
svg->super.free = rsvg_node_free;
svg->super.draw = rsvg_node_svg_draw;
svg->super.set_atts = rsvg_node_svg_set_atts;
svg->overflow = FALSE;
......@@ -380,8 +393,7 @@ rsvg_new_use ()
{
RsvgNodeUse * use;
use = g_new (RsvgNodeUse, 1);
use->super.state = g_new(RsvgState, 1);
rsvg_state_init(use->super.state);
_rsvg_node_init(&use->super);
use->super.type = RSVG_NODE_PATH;
use->super.free = rsvg_node_use_free;
use->super.draw = rsvg_node_use_draw;
......@@ -438,14 +450,11 @@ rsvg_new_symbol(void)
{
RsvgNodeSymbol * symbol;
symbol = g_new (RsvgNodeSymbol, 1);
_rsvg_node_init(&symbol->super);
symbol->has_vbox = 0;
symbol->overflow = 0;
symbol->preserve_aspect_ratio = RSVG_ASPECT_RATIO_XMID_YMID;
symbol->super.children = g_ptr_array_new();
symbol->super.state = g_new(RsvgState, 1);
rsvg_state_init(symbol->super.state);
symbol->super.type = RSVG_NODE_SYMBOL;
symbol->super.free = rsvg_node_free;
symbol->super.draw = _rsvg_node_draw_nothing;
symbol->super.set_atts = rsvg_node_symbol_set_atts;
return &symbol->super;
......@@ -456,11 +465,8 @@ rsvg_new_defs ()
{
RsvgNodeGroup *group;
group = g_new (RsvgNodeGroup, 1);
group->super.children = g_ptr_array_new();
group->super.state = g_new(RsvgState, 1);
rsvg_state_init(group->super.state);
_rsvg_node_init(&group->super);
group->super.type = RSVG_NODE_PATH;
group->super.free = rsvg_node_free;
group->super.draw = _rsvg_node_draw_nothing;
group->super.set_atts = rsvg_node_group_set_atts;
return &group->super;
......@@ -498,11 +504,8 @@ rsvg_new_switch (void)
{
RsvgNodeGroup *group;
group = g_new (RsvgNodeGroup, 1);
group->super.children = g_ptr_array_new();
group->super.state = g_new(RsvgState, 1);
rsvg_state_init(group->super.state);
_rsvg_node_init(&group->super);
group->super.type = RSVG_NODE_PATH;
group->super.free = rsvg_node_free;
group->super.draw = _rsvg_node_switch_draw;
group->super.set_atts = rsvg_node_group_set_atts;
return &group->super;
......
......@@ -80,12 +80,10 @@ void rsvg_node_group_pack (RsvgNode *self, RsvgNode *child);
void rsvg_node_draw (RsvgNode * self, RsvgDrawingCtx *ctx,
int dominate);
void _rsvg_node_draw_nothing (RsvgNode * self, RsvgDrawingCtx *ctx,
int dominate);
void _rsvg_node_draw_children (RsvgNode * self, RsvgDrawingCtx *ctx,
int dominate);
void rsvg_node_free (RsvgNode *self);
void _rsvg_node_free (RsvgNode *self);
void _rsvg_node_init(RsvgNode *self);
G_END_DECLS
......
......@@ -617,28 +617,24 @@ rsvg_end_element (void *data, const xmlChar *name)
}
}
/*
static void
_rsvg_dont_set_atts (RsvgNode * node, RsvgHandle * ctx, RsvgPropertyBag * atts)
{
}
static void _rsvg_node_chars_free(RsvgNode * node)
{
RsvgNodeChars * self = (RsvgNodeChars *)node;
g_string_free(self->contents, TRUE);
g_free(node);
_rsvg_node_free(node);
}
*/
static void
rsvg_characters (void *data, const xmlChar *ch, int len)
{
RsvgHandle *ctx = (RsvgHandle *)data;
if (ctx->handler && ctx->handler->characters != NULL)
ctx->handler->characters (ctx->handler, ch, len);
/*
{
ctx->handler->characters (ctx->handler, ch, len);
return;
}
char * utf8 = NULL;
RsvgNodeChars * self;
GString * string;
......@@ -655,19 +651,15 @@ rsvg_characters (void *data, const xmlChar *ch, int len)
}
self = g_new(RsvgNodeChars, 1);
_rsvg_node_init(&self->super);
self->contents = string;
self->super.type = RSVG_NODE_CHARS;
self->super.free = _rsvg_node_chars_free;
self->super.draw = _rsvg_node_draw_nothing;
self->super.set_atts = _rsvg_dont_set_atts;
rsvg_defs_register_memory(ctx->defs, (RsvgNode *)self);
if (ctx->currentnode) {
if (ctx->currentnode)
rsvg_node_group_pack(ctx->currentnode, (RsvgNode *)self);
ctx->currentnode = (RsvgNode *)self;
}
*/
}
static xmlEntityPtr
......
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