Logo Search packages:      
Sourcecode: inkscape version File versions

int objects_query_strokewidth ( GSList *  objects,
SPStyle style_res 
)

Write to style_res the average stroke width of a list of objects.

Definition at line 637 of file desktop-style.cpp.

References SPILength::computed, NR::Matrix::expansion(), SPIPaint::isNone(), SPILength::set, SPStyle::stroke, and SPStyle::stroke_width.

Referenced by sp_desktop_query_style_from_list().

{
    if (g_slist_length(objects) == 0) {
        /* No objects, set empty */
        return QUERY_STYLE_NOTHING;
    }

    gdouble avgwidth = 0.0;

    gdouble prev_sw = -1;
    bool same_sw = true;

    int n_stroked = 0;

    for (GSList const *i = objects; i != NULL; i = i->next) {
        SPObject *obj = SP_OBJECT (i->data);
        if (!SP_IS_ITEM(obj)) continue;
        SPStyle *style = SP_OBJECT_STYLE (obj);
        if (!style) continue;

        if ( style->stroke.isNone() ) {
            continue;
        }

        n_stroked ++;

        NR::Matrix i2d = sp_item_i2d_affine (SP_ITEM(obj));
        double sw = style->stroke_width.computed * i2d.expansion();

        if (prev_sw != -1 && fabs(sw - prev_sw) > 1e-3)
            same_sw = false;
        prev_sw = sw;

        avgwidth += sw;
    }

    if (n_stroked > 1)
        avgwidth /= (n_stroked);

    style_res->stroke_width.computed = avgwidth;
    style_res->stroke_width.set = true;

    if (n_stroked == 0) {
        return QUERY_STYLE_NOTHING;
    } else if (n_stroked == 1) {
        return QUERY_STYLE_SINGLE;
    } else {
        if (same_sw)
            return QUERY_STYLE_MULTIPLE_SAME;
        else
            return QUERY_STYLE_MULTIPLE_AVERAGED;
    }
}


Generated by  Doxygen 1.6.0   Back to index