summaryrefslogtreecommitdiff
path: root/rsvg-shapes.c
diff options
context:
space:
mode:
authorCaleb Michael Moore <cmoore@src.gnome.org>2004-08-22 08:17:56 +0000
committerCaleb Michael Moore <cmoore@src.gnome.org>2004-08-22 08:17:56 +0000
commitacb32218018c0a8d677c0e379570e29c3b96d60f (patch)
tree12d88528b68d532ec499c9448dd23fb225924c47 /rsvg-shapes.c
parent977a33d58ccaaea00ec25fbf1d55aff088b130a2 (diff)
downloadlibrsvg-acb32218018c0a8d677c0e379570e29c3b96d60f.tar.gz
images and preparsing
Diffstat (limited to 'rsvg-shapes.c')
-rw-r--r--rsvg-shapes.c157
1 files changed, 95 insertions, 62 deletions
diff --git a/rsvg-shapes.c b/rsvg-shapes.c
index c20b874c..d9351467 100644
--- a/rsvg-shapes.c
+++ b/rsvg-shapes.c
@@ -652,7 +652,7 @@ rsvg_defs_drawable_group_pack (RsvgDefsDrawableGroup *self, RsvgDefsDrawable *ch
g_ptr_array_add(z->children, child);
}
-static RsvgDefsDrawable *
+RsvgDefsDrawable *
rsvg_push_part_def_group (RsvgHandle *ctx, const char * id)
{
RsvgDefsDrawableGroup *group;
@@ -705,8 +705,6 @@ void
rsvg_handle_path (RsvgHandle *ctx, const char * d, const char * id)
{
RsvgDefsDrawablePath *path;
- if (!ctx->in_defs)
- rsvg_render_path (ctx, d);
path = g_new (RsvgDefsDrawablePath, 1);
path->d = g_strdup(d);
@@ -1773,69 +1771,32 @@ rsvg_clip_image(GdkPixbuf *intermediate, ArtSVP *path)
}
}
-void
-rsvg_start_image (RsvgHandle *ctx, RsvgPropertyBag *atts)
+static void
+rsvg_defs_drawable_image_free (RsvgDefVal * self)
{
- double x = 0., y = 0., w = -1., h = -1.;
- const char * href = NULL;
- const char * klazz = NULL, * id = NULL, *value;
- int aspect_ratio = RSVG_ASPECT_RATIO_NONE;
+ RsvgDefsDrawableImage *z = (RsvgDefsDrawableImage *)self;
+ rsvg_state_finalize (&z->super.state);
+ g_object_unref (G_OBJECT (z->img));
+ g_free (z);
+}
+
+static void
+rsvg_defs_drawable_image_draw (RsvgDefsDrawable * self, RsvgHandle *ctx,
+ int dominate)
+{
+ RsvgDefsDrawableImage *z = (RsvgDefsDrawableImage *)self;
+ double x = z->x, y = z->y, w = z->w, h = z->h;
+ int aspect_ratio = z->preserve_aspect_ratio;
ArtIRect temprect;
- GdkPixbuf *img;
- GError *err = NULL;
+ GdkPixbuf *img = z->img;
int i, j;
double tmp_affine[6];
double tmp_tmp_affine[6];
- RsvgState *state;
+ RsvgState *state = rsvg_state_current(ctx);
GdkPixbuf *intermediate;
double basex, basey;
- /* skip over defs entries for now */
- if (ctx->in_defs) return;
-
- state = rsvg_state_current (ctx);
-
- if (rsvg_property_bag_size (atts))
- {
- if ((value = rsvg_property_bag_lookup (atts, "x")))
- x = rsvg_css_parse_normalized_length (value, ctx->dpi_x, (gdouble)ctx->width, state->font_size);
- if ((value = rsvg_property_bag_lookup (atts, "y")))
- y = rsvg_css_parse_normalized_length (value, ctx->dpi_y, (gdouble)ctx->height, state->font_size);
- if ((value = rsvg_property_bag_lookup (atts, "width")))
- w = rsvg_css_parse_normalized_length (value, ctx->dpi_x, (gdouble)ctx->width, state->font_size);
- if ((value = rsvg_property_bag_lookup (atts, "height")))
- h = rsvg_css_parse_normalized_length (value, ctx->dpi_y, (gdouble)ctx->height, state->font_size);
- /* path is used by some older adobe illustrator versions */
- if ((value = rsvg_property_bag_lookup (atts, "path")) || (value = rsvg_property_bag_lookup (atts, "xlink:href")))
- href = value;
- if ((value = rsvg_property_bag_lookup (atts, "class")))
- klazz = value;
- if ((value = rsvg_property_bag_lookup (atts, "id")))
- id = value;
- if ((value = rsvg_property_bag_lookup (atts, "preserveAspectRatio")))
- aspect_ratio = rsvg_css_parse_aspect_ratio (value);
-
- rsvg_parse_style_attrs (ctx, state, "image", klazz, id, atts);
- }
-
- if (!href || w <= 0. || h <= 0.)
- return;
-
- /* figure out if image is visible or not */
- if (!state->visible || !state->cond_true)
- return;
- /*hmm, passing the error thingie into the next thing makes it screw up when using vfs*/
- img = rsvg_pixbuf_new_from_href (href, rsvg_handle_get_base_uri (ctx), NULL);
-
- if (!img)
- {
- if (err)
- {
- g_warning (_("Couldn't load image: %s\n"), err->message);
- g_error_free (err);
- }
- return;
- }
+ rsvg_state_reinherit_top(ctx, &self->state, dominate);
if (aspect_ratio)
{
@@ -1877,8 +1838,6 @@ rsvg_start_image (RsvgHandle *ctx, RsvgPropertyBag *atts)
rsvg_affine_image(img, intermediate, tmp_affine, w, h);
- g_object_unref (G_OBJECT (img));
-
rsvg_push_discrete_layer(ctx);
if (state->clippath)
@@ -1916,6 +1875,82 @@ rsvg_start_image (RsvgHandle *ctx, RsvgPropertyBag *atts)
g_object_unref (G_OBJECT (intermediate));
}
+void
+rsvg_start_image (RsvgHandle *ctx, RsvgPropertyBag *atts)
+{
+ double x = 0., y = 0., w = -1., h = -1.;
+ const char * href = NULL;
+ const char * klazz = NULL, * id = NULL, *value;
+ int aspect_ratio = RSVG_ASPECT_RATIO_NONE;
+ GdkPixbuf *img;
+ GError *err = NULL;
+ RsvgState *state;
+ RsvgDefsDrawableImage *image;
+
+ state = rsvg_state_current (ctx);
+
+ if (rsvg_property_bag_size (atts))
+ {
+ if ((value = rsvg_property_bag_lookup (atts, "x")))
+ x = rsvg_css_parse_normalized_length (value, ctx->dpi_x, (gdouble)ctx->width, state->font_size);
+ if ((value = rsvg_property_bag_lookup (atts, "y")))
+ y = rsvg_css_parse_normalized_length (value, ctx->dpi_y, (gdouble)ctx->height, state->font_size);
+ if ((value = rsvg_property_bag_lookup (atts, "width")))
+ w = rsvg_css_parse_normalized_length (value, ctx->dpi_x, (gdouble)ctx->width, state->font_size);
+ if ((value = rsvg_property_bag_lookup (atts, "height")))
+ h = rsvg_css_parse_normalized_length (value, ctx->dpi_y, (gdouble)ctx->height, state->font_size);
+ /* path is used by some older adobe illustrator versions */
+ if ((value = rsvg_property_bag_lookup (atts, "path")) || (value = rsvg_property_bag_lookup (atts, "xlink:href")))
+ href = value;
+ if ((value = rsvg_property_bag_lookup (atts, "class")))
+ klazz = value;
+ if ((value = rsvg_property_bag_lookup (atts, "id")))
+ id = value;
+ if ((value = rsvg_property_bag_lookup (atts, "preserveAspectRatio")))
+ aspect_ratio = rsvg_css_parse_aspect_ratio (value);
+
+ rsvg_parse_style_attrs (ctx, state, "image", klazz, id, atts);
+ }
+
+ if (!href || w <= 0. || h <= 0.)
+ return;
+
+ /* figure out if image is visible or not */
+ if (!state->visible || !state->cond_true)
+ return;
+ /*hmm, passing the error thingie into the next thing makes it screw up when using vfs*/
+ img = rsvg_pixbuf_new_from_href (href, rsvg_handle_get_base_uri (ctx), NULL);
+
+ if (!img)
+ {
+ if (err)
+ {
+ g_warning (_("Couldn't load image: %s\n"), err->message);
+ g_error_free (err);
+ }
+ return;
+ }
+
+ image = g_new (RsvgDefsDrawableImage, 1);
+ image->img = img;
+ image->preserve_aspect_ratio = aspect_ratio;
+ image->x = x;
+ image->y = y;
+ image->w = w;
+ image->h = h;
+ rsvg_state_clone (&image->super.state, rsvg_state_current (ctx));
+ image->super.super.type = RSVG_DEF_PATH;
+ image->super.super.free = rsvg_defs_drawable_image_free;
+ image->super.draw = rsvg_defs_drawable_image_draw;
+ rsvg_defs_set (ctx->defs, id, &image->super.super);
+
+ image->super.parent = (RsvgDefsDrawable *)ctx->current_defs_group;
+ if (image->super.parent != NULL)
+ rsvg_defs_drawable_group_pack((RsvgDefsDrawableGroup *)image->super.parent,
+ &image->super);
+
+}
+
void
rsvg_start_use (RsvgHandle *ctx, RsvgPropertyBag *atts)
{
@@ -1982,8 +2017,6 @@ rsvg_start_use (RsvgHandle *ctx, RsvgPropertyBag *atts)
rsvg_defs_drawable_group_pack((RsvgDefsDrawableGroup *)use->super.parent,
&use->super);
- if (!ctx->in_defs)
- rsvg_defs_drawable_draw (&use->super, ctx, 0);
break;
}
default: