Logo Search packages:      
Sourcecode: inkscape version File versions  Download package

static SPPainter * sp_lineargradient_painter_new ( SPPaintServer *  ps,
NR::Matrix const &  full_transform,
NR::Matrix const &  ,
NRRect const *  bbox 
) [static]

Create linear gradient context.

Basically we have to deal with transformations

1) color2norm - maps point in (0,NCOLORS) vector to (0,1) vector 2) norm2pos - maps (0,1) vector to x1,y1 - x2,y2 2) gradientTransform 3) bbox2user 4) ctm == userspace to pixel grid

See also (*) in sp-pattern about why we may need parent_transform.

Todo:
(point 1 above) fixme: I do not know how to deal with start > 0 and end < 1.

Todo:
Technically speaking, we map NCOLORS on line [start,end] onto line [0,1]. I almost think we should fill color array start and end in that case. The alternative would be to leave these just empty garbage or something similar. Originally I had 1023.9999 here - not sure whether we have really to cut out ceil int (Lauris).

Definition at line 1473 of file sp-gradient.cpp.

References SPGradient::color, NR::Matrix::copyto(), SPGradient::gradientTransform, NR::identity(), SPLGPainter::lg, SPLGPainter::lgr, SPLGPainter::painter, sp_gradient_ensure_colors(), sp_gradient_get_spread(), sp_lg_fill(), SPGradient::units, SPLinearGradient::x1, SPLinearGradient::x2, SPLinearGradient::y1, and SPLinearGradient::y2.

Referenced by sp_lineargradient_class_init().

{
    SPLinearGradient *lg = SP_LINEARGRADIENT(ps);
    SPGradient *gr = SP_GRADIENT(ps);

    if (!gr->color) sp_gradient_ensure_colors(gr);

    SPLGPainter *lgp = g_new(SPLGPainter, 1);

    lgp->painter.type = SP_PAINTER_IND;
    lgp->painter.fill = sp_lg_fill;

    lgp->lg = lg;

    /** \todo
     * Technically speaking, we map NCOLORS on line [start,end] onto line
     * [0,1].  I almost think we should fill color array start and end in
     * that case. The alternative would be to leave these just empty garbage
     * or something similar. Originally I had 1023.9999 here - not sure
     * whether we have really to cut out ceil int (Lauris).
     */
    NR::Matrix color2norm(NR::identity());
    NR::Matrix color2px;
    if (gr->units == SP_GRADIENT_UNITS_OBJECTBOUNDINGBOX) {
        NR::Matrix norm2pos(NR::identity());

        /* BBox to user coordinate system */
        NR::Matrix bbox2user(bbox->x1 - bbox->x0, 0, 0, bbox->y1 - bbox->y0, bbox->x0, bbox->y0);

        NR::Matrix color2pos = color2norm * norm2pos;
        NR::Matrix color2tpos = color2pos * gr->gradientTransform;
        NR::Matrix color2user = color2tpos * bbox2user;
        color2px = color2user * full_transform;

    } else {
        /* Problem: What to do, if we have mixed lengths and percentages? */
        /* Currently we do ignore percentages at all, but that is not good (lauris) */

        NR::Matrix norm2pos(NR::identity());
        NR::Matrix color2pos = color2norm * norm2pos;
        NR::Matrix color2tpos = color2pos * gr->gradientTransform;
        color2px = color2tpos * full_transform;

    }

    NRMatrix v2px;
    color2px.copyto(&v2px);

    nr_lgradient_renderer_setup(&lgp->lgr, gr->color, sp_gradient_get_spread(gr), &v2px,
                                lg->x1.computed, lg->y1.computed,
                                lg->x2.computed, lg->y2.computed);

    return (SPPainter *) lgp;
}


Generated by  Doxygen 1.6.0   Back to index