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

SPPainter * SPLGPainter::painter_new ( SPPaintServer ps,
Geom::Matrix const &  full_transform,
Geom::Matrix const &  parent_transform,
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 1614 of file sp-gradient.cpp.

References SPGradient::color, SPGradient::ensureColors(), SPGradient::fetchSpread(), SPGradient::gradientTransform, Geom::identity(), sp_lg_fill(), and SPGradient::units.

Referenced by sp_lineargradient_class_init().

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

    if (!gr->color) {
        gr->ensureColors();
    }

    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).
     */
    Geom::Matrix color2norm(Geom::identity());
    Geom::Matrix color2px;
    if (gr->units == SP_GRADIENT_UNITS_OBJECTBOUNDINGBOX) {
        Geom::Matrix norm2pos(Geom::identity());

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

        Geom::Matrix color2pos = color2norm * norm2pos;
        Geom::Matrix color2tpos = color2pos * gr->gradientTransform;
        Geom::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) */

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

    }
    // TODO: remove color2px_nr after converting to 2geom
    NR::Matrix color2px_nr = from_2geom(color2px);
    nr_lgradient_renderer_setup(&lgp->lgr, gr->color, gr->fetchSpread(), &color2px_nr,
                                lg->x1.computed, lg->y1.computed,
                                lg->x2.computed, lg->y2.computed);

    return (SPPainter *) lgp;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Generated by  Doxygen 1.6.0   Back to index