Commit 23b106eb authored by Dom Lachowicz's avatar Dom Lachowicz

start on preserveAspectRatio for images

parent 6a59cbd6
2004-06-10 Dom Lachowicz <cinamod@hotmail.com>
* rsvg-css.c: Parse preserveAspectRatio
* rsvg-shapes.c: Honoe preserveAspectRatio to some extent
2004-06-10 Caleb Moore <c.moore@student.unsw.edu.au>
* rsvg-filter.c: fixed overlay filter
......
......@@ -848,3 +848,31 @@ rsvg_css_parse_number_optional_number(const char * str,
else
*y = *x;
}
int rsvg_css_parse_aspect_ratio(const char * str)
{
int ratio = RSVG_ASPECT_RATIO_NONE;
/* TODO: better detection code, handle meet|slice */
if (strstr (str, "xMinYMin") != NULL)
ratio = RSVG_ASPECT_RATIO_XMIN_YMIN;
else if (strstr (str, "xMidYMin") != NULL)
ratio = RSVG_ASPECT_RATIO_XMID_YMIN;
else if (strstr (str, "xMaxYMin") != NULL)
ratio = RSVG_ASPECT_RATIO_XMAX_YMIN;
else if (strstr (str, "xMinYMid") != NULL)
ratio = RSVG_ASPECT_RATIO_XMIN_YMID;
else if (strstr (str, "xMidYMid") != NULL)
ratio = RSVG_ASPECT_RATIO_XMIN_YMID;
else if (strstr (str, "xMaxYMid") != NULL)
ratio = RSVG_ASPECT_RATIO_XMAX_YMID;
else if (strstr (str, "xMinYMax") != NULL)
ratio = RSVG_ASPECT_RATIO_XMIN_YMAX;
else if (strstr (str, "xMidYMax") != NULL)
ratio = RSVG_ASPECT_RATIO_XMID_YMAX;
else if (strstr (str, "xMaxYMax") != NULL)
ratio = RSVG_ASPECT_RATIO_XMAX_YMAX;
return ratio;
}
......@@ -30,9 +30,22 @@
G_BEGIN_DECLS
#define RSVG_ASPECT_RATIO_NONE (0)
#define RSVG_ASPECT_RATIO_XMIN_YMIN (1 << 0)
#define RSVG_ASPECT_RATIO_XMID_YMIN (1 << 1)
#define RSVG_ASPECT_RATIO_XMAX_YMIN (1 << 2)
#define RSVG_ASPECT_RATIO_XMIN_YMID (1 << 3)
#define RSVG_ASPECT_RATIO_XMID_YMID (1 << 4)
#define RSVG_ASPECT_RATIO_XMAX_YMID (1 << 5)
#define RSVG_ASPECT_RATIO_XMIN_YMAX (1 << 6)
#define RSVG_ASPECT_RATIO_XMID_YMAX (1 << 7)
#define RSVG_ASPECT_RATIO_XMAX_YMAX (1 << 8)
int rsvg_css_parse_aspect_ratio(const char * str);
double
rsvg_css_parse_length (const char *str, gdouble pixels_per_inch,
gint *percent, gint *em, gint *ex);
gint *percent, gint *em, gint *ex);
double
rsvg_css_parse_normalized_length(const char *str, gdouble pixels_per_inch,
......
......@@ -1535,6 +1535,7 @@ rsvg_start_image (RsvgHandle *ctx, RsvgPropertyBag *atts)
const char * href = NULL;
const char * klazz = NULL, * id = NULL, *value;
gboolean has_alpha;
int aspect_ratio = RSVG_ASPECT_RATIO_NONE;
GdkPixbuf *img;
GError *err = NULL;
......@@ -1566,6 +1567,8 @@ rsvg_start_image (RsvgHandle *ctx, RsvgPropertyBag *atts)
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);
}
......@@ -1580,8 +1583,12 @@ rsvg_start_image (RsvgHandle *ctx, RsvgPropertyBag *atts)
w *= state->affine[0];
h *= state->affine[3];
img = rsvg_pixbuf_new_from_href (href, w, h, FALSE, &err);
img = rsvg_pixbuf_new_from_href (href, w, h, (aspect_ratio != RSVG_ASPECT_RATIO_NONE), &err);
/* w & h might've been adjusted by preserveAspectRatio */
w = gdk_pixbuf_get_width (img);
h = gdk_pixbuf_get_height (img);
if (!img)
{
if (err)
......@@ -1593,7 +1600,7 @@ rsvg_start_image (RsvgHandle *ctx, RsvgPropertyBag *atts)
}
has_alpha = gdk_pixbuf_get_has_alpha (img);
if(0 /* has_alpha */)
if(0 /* !has_alpha */)
{
GdkPixbuf *tmp_pixbuf;
......
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