Commit 17c29849 authored by Caleb Michael Moore's avatar Caleb Michael Moore

cleaned up vbox handling a little

parent 63a60bbf
......@@ -1143,10 +1143,10 @@ rsvg_handle_get_dimensions(RsvgHandle * handle, RsvgDimensionData * output)
if (sself->w.factor == 'p' || sself->h.factor == 'p')
{
if (sself->has_vbox && sself->vbw > 0. && sself->vbh > 0.)
if (sself->vbox.active && sself->vbox.w > 0. && sself->vbox.h > 0.)
{
bbox.w = sself->vbw;
bbox.h = sself->vbh;
bbox.w = sself->vbox.w;
bbox.h = sself->vbox.h;
}
else
bbox = _rsvg_find_bbox(handle);
......
......@@ -279,7 +279,7 @@ _set_source_rsvg_pattern (RsvgDrawingCtx *ctx,
_rsvg_affine_multiply(affine, affine, rsvg_pattern->affine);
/* Create the pattern contents coordinate system */
if (rsvg_pattern->vbox) {
if (rsvg_pattern->vbox.active) {
/* If there is a vbox, use that */
double w, h, x, y;
w = patternw * bbwscale;
......@@ -287,19 +287,19 @@ _set_source_rsvg_pattern (RsvgDrawingCtx *ctx,
x = 0;
y = 0;
rsvg_preserve_aspect_ratio(rsvg_pattern->preserve_aspect_ratio,
rsvg_pattern->vbw, rsvg_pattern->vbh,
rsvg_pattern->vbox.w, rsvg_pattern->vbox.h,
&w, &h, &x, &y);
x -= rsvg_pattern->vbx * w / rsvg_pattern->vbw;
y -= rsvg_pattern->vby * h / rsvg_pattern->vbh;
x -= rsvg_pattern->vbox.x * w / rsvg_pattern->vbox.w;
y -= rsvg_pattern->vbox.y * h / rsvg_pattern->vbox.h;
caffine[0] = w / rsvg_pattern->vbw;
caffine[0] = w / rsvg_pattern->vbox.w;
caffine[1] = 0.;
caffine[2] = 0.;
caffine[3] = h / rsvg_pattern->vbh;
caffine[3] = h / rsvg_pattern->vbox.h;
caffine[4] = x;
caffine[5] = y;
_rsvg_push_view_box(ctx, rsvg_pattern->vbw, rsvg_pattern->vbh);
_rsvg_push_view_box(ctx, rsvg_pattern->vbox.w, rsvg_pattern->vbox.h);
}
else if (rsvg_pattern->obj_cbbox) {
/* If coords are in terms of the bounding box, use them */
......@@ -365,7 +365,7 @@ _set_source_rsvg_pattern (RsvgDrawingCtx *ctx,
cairo_pattern_destroy (pattern);
cairo_destroy (cr_pattern);
cairo_surface_destroy (surface);
if (rsvg_pattern->obj_cbbox || rsvg_pattern->vbox)
if (rsvg_pattern->obj_cbbox || rsvg_pattern->vbox.active)
_rsvg_pop_view_box(ctx);
}
......@@ -549,6 +549,7 @@ void rsvg_cairo_render_image (RsvgDrawingCtx *ctx, const GdkPixbuf * pixbuf,
gint width = gdk_pixbuf_get_width (pixbuf);
gint height = gdk_pixbuf_get_height (pixbuf);
double dwidth = width, dheight = height;
guchar *gdk_pixels = gdk_pixbuf_get_pixels (pixbuf);
int gdk_rowstride = gdk_pixbuf_get_rowstride (pixbuf);
int n_channels = gdk_pixbuf_get_n_channels (pixbuf);
......@@ -571,9 +572,9 @@ void rsvg_cairo_render_image (RsvgDrawingCtx *ctx, const GdkPixbuf * pixbuf,
cairo_save (render->cr);
_set_rsvg_affine (render->cr, state->affine);
cairo_scale (render->cr, w / width, h / height);
pixbuf_x *= width / w;
pixbuf_y *= height / h;
cairo_scale (render->cr, w / dwidth, h / dheight);
pixbuf_x *= dwidth / w;
pixbuf_y *= dheight / h;
if (n_channels == 3)
format = CAIRO_FORMAT_RGB24;
......
......@@ -52,31 +52,33 @@
* @w: The Width output
* @h: The Height output
*
* Returns: Success or failure
* Returns:
*/
gboolean
rsvg_css_parse_vbox (const char * vbox, double * x, double * y,
double * w, double * h)
RsvgViewBox
rsvg_css_parse_vbox (const char * vbox)
{
RsvgViewBox vb;
gdouble * list;
guint list_len;
vb.active = FALSE;
list = rsvg_css_parse_number_list(vbox, &list_len);
if(!(list && list_len))
return FALSE;
return vb;
else if(list_len != 4) {
g_free(list);
return FALSE;
return vb;
}
else {
*x = list[0];
*y = list[1];
*w = list[2];
*h = list[3];
vb.x = list[0];
vb.y = list[1];
vb.w = list[2];
vb.h = list[3];
vb.active = TRUE;
g_free(list);
return TRUE;
return vb;
}
}
......
......@@ -27,6 +27,7 @@
#include <glib/gtypes.h>
#include <pango/pango.h>
#include "rsvg-private.h"
G_BEGIN_DECLS
......@@ -80,9 +81,8 @@ rsvg_css_parse_font_stretch (const char * str, gboolean * inherit);
const char *
rsvg_css_parse_font_family (const char * str, gboolean * inherit);
gboolean
rsvg_css_parse_vbox (const char * vbox, double * x, double * y,
double * w, double * h);
RsvgViewBox
rsvg_css_parse_vbox (const char * vbox);
void
rsvg_css_parse_number_optional_number(const char * str,
......
......@@ -53,8 +53,7 @@ rsvg_node_marker_set_atts (RsvgNode * self, RsvgHandle *ctx, RsvgPropertyBag *at
if ((value = rsvg_property_bag_lookup (atts, "class")))
klazz = value;
if ((value = rsvg_property_bag_lookup (atts, "viewBox")))
marker->vbox = rsvg_css_parse_vbox (value, &marker->vbx, &marker->vby,
&marker->vbw, &marker->vbh);
marker->vbox = rsvg_css_parse_vbox (value);
if ((value = rsvg_property_bag_lookup (atts, "refX")))
marker->refX = _rsvg_css_parse_length (value);
if ((value = rsvg_property_bag_lookup (atts, "refY")))
......@@ -93,7 +92,7 @@ rsvg_new_marker (void)
marker->refX = marker->refY = _rsvg_css_parse_length ("0");
marker->width = marker->height = _rsvg_css_parse_length ("1");
marker->bbox = TRUE;
marker->vbox = FALSE;
marker->vbox.active = FALSE;
marker->super.set_atts = rsvg_node_marker_set_atts;
return &marker->super;
}
......@@ -122,7 +121,7 @@ rsvg_marker_render (RsvgMarker *self, gdouble x, gdouble y, gdouble orient, gdou
_rsvg_affine_multiply(affine, taffine, affine);
}
if (self->vbox) {
if (self->vbox.active) {
double w, h, x, y;
w = _rsvg_css_normalize_length(&self->width, ctx, 'h');
......@@ -131,20 +130,20 @@ rsvg_marker_render (RsvgMarker *self, gdouble x, gdouble y, gdouble orient, gdou
y = 0;
rsvg_preserve_aspect_ratio(self->preserve_aspect_ratio,
self->vbw, self->vbh,
self->vbox.w, self->vbox.h,
&w, &h, &x, &y);
x = -self->vbx * w / self->vbw;
y = -self->vby * h / self->vbh;
x = -self->vbox.x * w / self->vbox.w;
y = -self->vbox.y * h / self->vbox.h;
taffine[0] = w / self->vbw;
taffine[0] = w / self->vbox.w;
taffine[1] = 0.;
taffine[2] = 0.;
taffine[3] = h / self->vbh;
taffine[3] = h / self->vbox.h;
taffine[4] = x;
taffine[5] = y;
_rsvg_affine_multiply(affine, taffine, affine);
_rsvg_push_view_box(ctx, self->vbw, self->vbh);
_rsvg_push_view_box(ctx, self->vbox.w, self->vbox.h);
}
_rsvg_affine_translate(taffine,
-_rsvg_css_normalize_length(&self->refX, ctx, 'h'),
......@@ -167,8 +166,8 @@ rsvg_marker_render (RsvgMarker *self, gdouble x, gdouble y, gdouble orient, gdou
state = rsvg_state_current(ctx);
if (self->vbox)
rsvg_add_clipping_rect(ctx, self->vbx, self->vby, self->vbw, self->vbh);
if (self->vbox.active)
rsvg_add_clipping_rect(ctx, self->vbox.x, self->vbox.y, self->vbox.w, self->vbox.h);
else
rsvg_add_clipping_rect(ctx, 0, 0,
_rsvg_css_normalize_length(&self->width, ctx, 'h'),
......@@ -186,7 +185,7 @@ rsvg_marker_render (RsvgMarker *self, gdouble x, gdouble y, gdouble orient, gdou
rsvg_pop_discrete_layer(ctx);
rsvg_state_pop(ctx);
if (self->vbox)
if (self->vbox.active)
_rsvg_pop_view_box(ctx);
}
......
......@@ -35,9 +35,10 @@ struct _RsvgMarker {
RsvgNode super;
gboolean bbox;
RsvgLength refX, refY, width, height;
double vbx, vby, vbw, vbh, orient;
double orient;
gint preserve_aspect_ratio;
gboolean vbox, orientAuto;
gboolean orientAuto;
RsvgViewBox vbox;
};
RsvgNode *
......
......@@ -420,11 +420,7 @@ rsvg_pattern_set_atts (RsvgNode * self, RsvgHandle *ctx, RsvgPropertyBag *atts)
if ((value = rsvg_property_bag_lookup (atts, "id")))
rsvg_defs_register_name (ctx->defs, value, self);
if ((value = rsvg_property_bag_lookup (atts, "viewBox"))){
pattern->vbox = rsvg_css_parse_vbox (value,
&pattern->vbx,
&pattern->vby,
&pattern->vbw,
&pattern->vbh);
pattern->vbox = rsvg_css_parse_vbox (value);
pattern->hasvbox = TRUE;
}
if ((value = rsvg_property_bag_lookup (atts, "x"))){
......@@ -480,16 +476,12 @@ rsvg_new_pattern (void)
pattern->obj_cbbox = FALSE;
pattern->x = pattern->y = pattern->width = pattern->height =
_rsvg_css_parse_length("0");
pattern->vbx = 0;
pattern->vby = 0;
pattern->vbw = 1;
pattern->vbh = 1;
pattern->fallback = NULL;
pattern->preserve_aspect_ratio = RSVG_ASPECT_RATIO_XMID_YMID;
pattern->vbox = FALSE;
pattern->vbox.active = FALSE;
_rsvg_affine_identity(pattern->affine);
pattern->super.set_atts = rsvg_pattern_set_atts;
pattern->hasx = pattern->hasy = pattern->haswidth = pattern->hasheight = pattern->hasvbox = pattern->hasbbox = pattern->hascbox = pattern->hasaspect = pattern->hastransform = pattern->hasaspect = FALSE;
pattern->hasx = pattern->hasy = pattern->haswidth = pattern->hasheight = pattern->hasbbox = pattern->hascbox = pattern->hasvbox = pattern->hasaspect = pattern->hastransform = pattern->hasaspect = FALSE;
return &pattern->super;
}
......@@ -672,11 +664,6 @@ rsvg_pattern_fix_fallback(RsvgPattern * pattern)
pattern->affine[i] = fallback->affine[i];
}
if (!pattern->hasvbox && fallback->hasvbox){
pattern->hasvbox = TRUE;
pattern->vbx = fallback->vbx;
pattern->vby = fallback->vby;
pattern->vbw = fallback->vbw;
pattern->vbh = fallback->vbh;
pattern->vbox = fallback->vbox;
}
if (!pattern->hasaspect && fallback->hasaspect){
......
......@@ -95,16 +95,15 @@ struct _RsvgPattern {
RsvgNode super;
gboolean obj_cbbox;
gboolean obj_bbox;
gboolean vbox;
double affine[6]; /* user space to actual at time of gradient def */
RsvgLength x, y, width, height;
gdouble vbx, vby, vbh, vbw;
RsvgViewBox vbox;
unsigned int preserve_aspect_ratio;
int hasx : 1;
int hasy : 1;
int hasvbox : 1;
int haswidth : 1;
int hasheight : 1;
int hasvbox : 1;
int hasaspect : 1;
int hascbox : 1;
int hasbbox : 1;
......
......@@ -118,7 +118,8 @@ struct RsvgHandle {
};
typedef struct{
double w, h;
gboolean active;
double x, y, w, h;
} RsvgViewBox;
/*Contextual information for the drawing phase*/
......
......@@ -191,27 +191,27 @@ rsvg_node_use_draw (RsvgNode * self, RsvgDrawingCtx *ctx,
RsvgNodeSymbol *symbol =
(RsvgNodeSymbol*)child;
if (symbol->has_vbox){
if (symbol->vbox.active){
rsvg_preserve_aspect_ratio
(symbol->preserve_aspect_ratio,
symbol->vbw, symbol->vbh,
symbol->vbox.w, symbol->vbox.h,
&w, &h, &x, &y);
_rsvg_affine_translate(affine, x, y);
_rsvg_affine_multiply(state->affine, affine, state->affine);
_rsvg_affine_scale(affine, w / symbol->vbw,
h / symbol->vbh);
_rsvg_affine_scale(affine, w / symbol->vbox.w,
h / symbol->vbox.h);
_rsvg_affine_multiply(state->affine, affine, state->affine);
_rsvg_affine_translate(affine, -symbol->vbx,
-symbol->vby);
_rsvg_affine_translate(affine, -symbol->vbox.x,
-symbol->vbox.y);
_rsvg_affine_multiply(state->affine, affine, state->affine);
_rsvg_push_view_box(ctx, symbol->vbw, symbol->vbh);
_rsvg_push_view_box(ctx, symbol->vbox.w, symbol->vbox.h);
rsvg_push_discrete_layer (ctx);
if (!state->overflow ||
(!state->has_overflow && child->state->overflow))
rsvg_add_clipping_rect (ctx, symbol->vbx, symbol->vby,
symbol->vbw, symbol->vbh);
rsvg_add_clipping_rect (ctx, symbol->vbox.x, symbol->vbox.y,
symbol->vbox.w, symbol->vbox.h);
} else {
_rsvg_affine_translate(affine, x, y);
_rsvg_affine_multiply(state->affine, affine, state->affine);
......@@ -222,7 +222,7 @@ rsvg_node_use_draw (RsvgNode * self, RsvgDrawingCtx *ctx,
_rsvg_node_draw_children(child, ctx, 1);
rsvg_state_pop(ctx);
rsvg_pop_discrete_layer (ctx);
if (symbol->has_vbox)
if (symbol->vbox.active)
_rsvg_pop_view_box(ctx);
}
......@@ -251,21 +251,21 @@ rsvg_node_svg_draw (RsvgNode * self, RsvgDrawingCtx *ctx,
for (i = 0; i < 6; i++)
affine_old[i] = state->affine[i];
if (sself->has_vbox)
if (sself->vbox.active)
{
double x = nx, y = ny, w = nw, h = nh;
rsvg_preserve_aspect_ratio(sself->preserve_aspect_ratio,
sself->vbw, sself->vbh,
sself->vbox.w, sself->vbox.h,
&w, &h, &x, &y);
affine[0] = w / sself->vbw;
affine[0] = w / sself->vbox.w;
affine[1] = 0;
affine[2] = 0;
affine[3] = h / sself->vbh;
affine[4] = x - sself->vbx * w / sself->vbw;
affine[5] = y - sself->vby * h / sself->vbh;
affine[3] = h / sself->vbox.h;
affine[4] = x - sself->vbox.x * w / sself->vbox.w;
affine[5] = y - sself->vbox.y * h / sself->vbox.h;
_rsvg_affine_multiply(state->affine, affine,
state->affine);
_rsvg_push_view_box(ctx, sself->vbw, sself->vbh);
_rsvg_push_view_box(ctx, sself->vbox.w, sself->vbox.h);
}
else
{
......@@ -318,10 +318,7 @@ rsvg_node_svg_set_atts (RsvgNode * self, RsvgHandle *ctx, RsvgPropertyBag *atts)
if (rsvg_property_bag_size (atts))
{
if ((value = rsvg_property_bag_lookup (atts, "viewBox")))
svg->has_vbox = rsvg_css_parse_vbox (value, &svg->vbx,
&svg->vby,
&svg->vbw,
&svg->vbh);
svg->vbox = rsvg_css_parse_vbox (value);
if ((value = rsvg_property_bag_lookup (atts, "preserveAspectRatio")))
svg->preserve_aspect_ratio = rsvg_css_parse_aspect_ratio (value);
......@@ -347,13 +344,12 @@ rsvg_new_svg (void)
RsvgNodeSvg * svg;
svg = g_new (RsvgNodeSvg, 1);
_rsvg_node_init(&svg->super);
svg->has_vbox = FALSE;
svg->vbox.active = FALSE;
svg->preserve_aspect_ratio = RSVG_ASPECT_RATIO_XMID_YMID;
svg->x = _rsvg_css_parse_length ("0");
svg->y = _rsvg_css_parse_length ("0");
svg->w = _rsvg_css_parse_length ("100%");
svg->h = _rsvg_css_parse_length ("100%");
svg->vbx = 0; svg->vby = 0; svg->vbw = 0; svg->vbh = 0;
svg->super.draw = rsvg_node_svg_draw;
svg->super.set_atts = rsvg_node_svg_set_atts;
return &svg->super;
......@@ -423,11 +419,7 @@ rsvg_node_symbol_set_atts(RsvgNode *self, RsvgHandle *ctx, RsvgPropertyBag *atts
rsvg_defs_register_name (ctx->defs, value, &symbol->super);
}
if ((value = rsvg_property_bag_lookup (atts, "viewBox")))
symbol->has_vbox = rsvg_css_parse_vbox (value,
&symbol->vbx,
&symbol->vby,
&symbol->vbw,
&symbol->vbh);
symbol->vbox = rsvg_css_parse_vbox (value);
if ((value = rsvg_property_bag_lookup (atts, "preserveAspectRatio")))
symbol->preserve_aspect_ratio =
rsvg_css_parse_aspect_ratio (value);
......@@ -443,7 +435,7 @@ rsvg_new_symbol(void)
RsvgNodeSymbol * symbol;
symbol = g_new (RsvgNodeSymbol, 1);
_rsvg_node_init(&symbol->super);
symbol->has_vbox = 0;
symbol->vbox.active = FALSE;
symbol->preserve_aspect_ratio = RSVG_ASPECT_RATIO_XMID_YMID;
symbol->super.draw = _rsvg_node_draw_nothing;
symbol->super.set_atts = rsvg_node_symbol_set_atts;
......
......@@ -54,8 +54,7 @@ struct _RsvgNodeGroup {
struct _RsvgNodeSymbol {
RsvgNode super;
gint preserve_aspect_ratio;
gboolean has_vbox;
gdouble vbx, vby, vbw, vbh;
RsvgViewBox vbox;
};
struct _RsvgNodeUse {
......@@ -68,8 +67,7 @@ struct _RsvgNodeSvg {
RsvgNode super;
gint preserve_aspect_ratio;
RsvgLength x, y, w, h;
gdouble vbx, vby, vbw, vbh;
gboolean has_vbox;
RsvgViewBox vbox;
GdkPixbuf *img;
};
......
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