Logo Search packages:      
Sourcecode: inkscape version File versions

bool Inkscape::UI::ClipboardManagerImpl::pasteSize ( bool  separately,
bool  apply_x,
bool  apply_y 
) [virtual]

Resize the selection or each object in the selection to match the clipboard's size.

separately Whether to scale each object in the selection separately
apply_x Whether to scale the width of objects / selection
apply_y Whether to scale the height of objects / selection

Implements Inkscape::UI::ClipboardManager.

Definition at line 415 of file clipboard.cpp.

References _getScale(), _retrieveClipboard(), _userWarn(), Inkscape::Selection::bounds(), Inkscape::Selection::isEmpty(), Inkscape::Selection::itemList(), and sp_repr_lookup_name().

    if(!apply_x && !apply_y) return false; // pointless parameters

    SPDesktop *desktop = SP_ACTIVE_DESKTOP;
    if ( desktop == NULL ) return false;
    Inkscape::Selection *selection = sp_desktop_selection(desktop);
    if (selection->isEmpty()) {
        _userWarn(desktop, _("Select <b>object(s)</b> to paste size to."));
        return false;

    // FIXME: actually, this should accept arbitrary documents
    SPDocument *tempdoc = _retrieveClipboard("image/x-inkscape-svg");
    if ( tempdoc == NULL ) {
        _userWarn(desktop, _("No size on the clipboard."));
        return false;

    // retrieve size ifomration from the clipboard
    Inkscape::XML::Node *root = sp_document_repr_root(tempdoc);
    Inkscape::XML::Node *clipnode = sp_repr_lookup_name(root, "inkscape:clipboard", 1);
    bool pasted = false;
    if (clipnode) {
        Geom::Point min, max;
        sp_repr_get_point(clipnode, "min", &min);
        sp_repr_get_point(clipnode, "max", &max);

        // resize each object in the selection
        if (separately) {
            for (GSList *i = const_cast<GSList*>(selection->itemList()) ; i ; i = i->next) {
                SPItem *item = SP_ITEM(i->data);
                Geom::OptRect obj_size = sp_item_bbox_desktop(item);
                if ( !obj_size ) continue;
                sp_item_scale_rel(item, _getScale(min, max, *obj_size, apply_x, apply_y));
        // resize the selection as a whole
        else {
            Geom::OptRect sel_size = selection->bounds();
            if ( sel_size ) {
                sp_selection_scale_relative(selection, sel_size->midpoint(),
                    _getScale(min, max, *sel_size, apply_x, apply_y));
        pasted = true;
    return pasted;

Generated by  Doxygen 1.6.0   Back to index