# HG changeset patch # User Thinker K.F. Li # Date 1285416765 -28800 # Node ID a17c4e231e5410010ac1a02b2202c810288e1da9 # Parent ac3e8492ad747090441917b4458e630bbe25c226 Transform positions of radient paints. cx, cy of radial and x1, y1, x2, y2 of linear gradient paints must be transformed with aggregated matrix of painted shapes. Pattern to user space transformation maybe used to get more precise color. diff -r ac3e8492ad74 -r a17c4e231e54 include/mb_types.h --- a/include/mb_types.h Sat Sep 25 18:46:37 2010 +0800 +++ b/include/mb_types.h Sat Sep 25 20:12:45 2010 +0800 @@ -82,7 +82,7 @@ struct _paint { int pnt_type; int flags; - void (*prepare)(paint_t *paint, mbe_t *cr); + void (*prepare)(paint_t *paint, mbe_t *cr, shape_t *sh); void (*free)(struct _redraw_man *rdman, paint_t *paint); STAILQ(shnode_t) members; paint_t *pnt_next; /*!< \brief Collect all paints of a rdman. */ diff -r ac3e8492ad74 -r a17c4e231e54 nodejs/svg.js --- a/nodejs/svg.js Sat Sep 25 18:46:37 2010 +0800 +++ b/nodejs/svg.js Sat Sep 25 20:12:45 2010 +0800 @@ -1100,8 +1100,8 @@ y2 = hrefgr[3]; } - if(n.attr('gradientTransform')) { - parseTransform(mtx, n.attr('gradientTransform').value()); + if(n.attr("gradientTransform")) { + parseTransform(mtx, n.attr("gradientTransform").value()); xy = _pnt_transform(x1, y1, mtx); x1 = xy[0]; y1 = xy[1]; @@ -1150,9 +1150,12 @@ stops = this.stop_ref[href]; } - if(n.attr('gradientTransform')) { - parseTransform(mtx, n.attr('gradientTransform').value()); + if(n.attr("gradientTransform")) { + parseTransform(mtx, n.attr("gradientTransform").value()); xy = _pnt_transform(cx, cy, mtx); + sys.puts(mtx); + sys.puts(xy); + sys.puts([cx, cy]); cx = xy[0]; cy = xy[1]; } diff -r ac3e8492ad74 -r a17c4e231e54 src/paint.c --- a/src/paint.c Sat Sep 25 18:46:37 2010 +0800 +++ b/src/paint.c Sat Sep 25 20:12:45 2010 +0800 @@ -17,7 +17,7 @@ int _paint_color_size = sizeof(paint_color_t); -static void paint_color_prepare(paint_t *paint, mbe_t *cr) { +static void paint_color_prepare(paint_t *paint, mbe_t *cr, shape_t *sh) { paint_color_t *color = (paint_color_t *)paint; mbe_set_source_rgba(cr, color->r, color->g, color->b, color->a); @@ -84,17 +84,27 @@ int _paint_linear_size = sizeof(paint_linear_t); -static void paint_linear_prepare(paint_t *paint, mbe_t *cr) { +static void paint_linear_prepare(paint_t *paint, mbe_t *cr, shape_t *sh) { paint_linear_t *linear = (paint_linear_t *)paint; mbe_pattern_t *ptn; + co_aix x1, y1; + co_aix x2, y2; + co_aix *mtx; ptn = linear->ptn; if(linear->flags & LIF_DIRTY) { + mtx = sh_get_aggr_matrix(sh); + x1 = linear->x1; + y1 = linear->y1; + matrix_trans_pos(mtx, &x1, &y1); + x2 = linear->x2; + y2 = linear->y2; + matrix_trans_pos(mtx, &x2, &y2); + if(ptn) mbe_pattern_destroy(ptn); linear->flags &= ~LIF_DIRTY; - ptn = mbe_pattern_create_linear(linear->x1, linear->y1, - linear->x2, linear->y2, + ptn = mbe_pattern_create_linear(x1, y1, x2, y2, linear->stops, linear->n_stops); ASSERT(ptn != NULL); linear->ptn = ptn; @@ -174,13 +184,20 @@ int _paint_radial_size = sizeof(paint_radial_t); -static void paint_radial_prepare(paint_t *paint, mbe_t *cr) { +static void paint_radial_prepare(paint_t *paint, mbe_t *cr, shape_t *sh) { paint_radial_t *radial = (paint_radial_t *)paint; mbe_pattern_t *ptn; + co_aix cx, cy; + co_aix *mtx; if(radial->flags & RDF_DIRTY) { - ptn = mbe_pattern_create_radial(radial->cx, radial->cy, 0, - radial->cx, radial->cy, + mtx = sh_get_aggr_matrix(sh); + cx = radial->cx; + cy = radial->cy; + matrix_trans_pos(mtx, &cx, &cy); + + ptn = mbe_pattern_create_radial(cx, cy, 0, + cx, cy, radial->r, radial->stops, radial->n_stops); @@ -256,7 +273,7 @@ int _paint_image_size = sizeof(paint_image_t); static -void paint_image_prepare(paint_t *paint, mbe_t *cr) { +void paint_image_prepare(paint_t *paint, mbe_t *cr, shape_t *sh) { paint_image_t *paint_img = (paint_image_t *)paint; mb_img_data_t *img_data; diff -r ac3e8492ad74 -r a17c4e231e54 src/redraw_man.c --- a/src/redraw_man.c Sat Sep 25 18:46:37 2010 +0800 +++ b/src/redraw_man.c Sat Sep 25 20:12:45 2010 +0800 @@ -2168,7 +2168,7 @@ fill = shape->fill; if(shape->fill) { - fill->prepare(fill, cr); + fill->prepare(fill, cr, shape); if(shape->stroke) fill_path_preserve(rdman, cr); else @@ -2177,7 +2177,7 @@ stroke = shape->stroke; if(stroke) { - stroke->prepare(stroke, cr); + stroke->prepare(stroke, cr, shape); set_shape_stroke_param(shape, cr); stroke_path(rdman, cr); }