Ejemplo n.º 1
0
static void gr_toggle_fillstroke (GtkWidget *button, gpointer data) {
    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
    GtkWidget *fill = (GtkWidget *) g_object_get_data (G_OBJECT(data), "fill");
    GtkWidget *stroke = (GtkWidget *) g_object_get_data (G_OBJECT(data), "stroke");
    if (button == fill && gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (fill))) {
        prefs->setBool("/tools/gradient/newfillorstroke", true);
        if (stroke) gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (stroke), FALSE);
    } else if (button == stroke && gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (stroke))) {
        prefs->setBool("/tools/gradient/newfillorstroke", false);
        if (fill) gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (fill), FALSE);
    }
}
void ColorNotebook::_picker_clicked(GtkWidget * /*widget*/, SPColorNotebook * /*colorbook*/)
{
    // Set the dropper into a "one click" mode, so it reverts to the previous tool after a click
    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
    prefs->setBool("/tools/dropper/onetimepick", true);
    Inkscape::UI::Tools::sp_toggle_dropper(SP_ACTIVE_DESKTOP);
}
Ejemplo n.º 3
0
/*  If the viewBox is missing, set one 
*/
void Metafile::setViewBoxIfMissing(SPDocument *doc) {

    if (doc && !doc->getRoot()->viewBox_set) {
        bool saved = Inkscape::DocumentUndo::getUndoSensitive(doc);
        Inkscape::DocumentUndo::setUndoSensitive(doc, false);
        
        doc->ensureUpToDate();
        
        // Set document unit
        Inkscape::XML::Node *repr = sp_document_namedview(doc, 0)->getRepr();
        Inkscape::SVGOStringStream os;
        Inkscape::Util::Unit const* doc_unit = doc->getWidth().unit;
        os << doc_unit->abbr;
        repr->setAttribute("inkscape:document-units", os.str().c_str());

        // Set viewBox
        doc->setViewBox(Geom::Rect::from_xywh(0, 0, doc->getWidth().value(doc_unit), doc->getHeight().value(doc_unit)));
        doc->ensureUpToDate();

        // Scale and translate objects
        double scale = Inkscape::Util::Quantity::convert(1, "px", doc_unit);
        Inkscape::UI::ShapeEditor::blockSetItem(true);
        double dh;
        if(SP_ACTIVE_DOCUMENT){ // for file menu open or import, or paste from clipboard
            dh = SP_ACTIVE_DOCUMENT->getHeight().value("px");
        }
        else { // for open via --file on command line
            dh = doc->getHeight().value("px");
        }

        // These should not affect input, but they do, so set them to a neutral state
        Inkscape::Preferences *prefs = Inkscape::Preferences::get();
        bool transform_stroke      = prefs->getBool("/options/transform/stroke", true);
        bool transform_rectcorners = prefs->getBool("/options/transform/rectcorners", true);
        bool transform_pattern     = prefs->getBool("/options/transform/pattern", true);
        bool transform_gradient    = prefs->getBool("/options/transform/gradient", true);
        prefs->setBool("/options/transform/stroke", true);
        prefs->setBool("/options/transform/rectcorners", true);
        prefs->setBool("/options/transform/pattern", true);
        prefs->setBool("/options/transform/gradient", true);
        
        doc->getRoot()->scaleChildItemsRec(Geom::Scale(scale), Geom::Point(0, dh), true);
        Inkscape::UI::ShapeEditor::blockSetItem(false);

        // restore options
        prefs->setBool("/options/transform/stroke",      transform_stroke);
        prefs->setBool("/options/transform/rectcorners", transform_rectcorners);
        prefs->setBool("/options/transform/pattern",     transform_pattern);
        prefs->setBool("/options/transform/gradient",    transform_gradient);

        Inkscape::DocumentUndo::setUndoSensitive(doc, saved);
    }
}
Ejemplo n.º 4
0
static void gr_linked_changed(GtkToggleAction *act, gpointer /*data*/)
{
    gboolean active = gtk_toggle_action_get_active( act );
    if ( active ) {
        g_object_set( G_OBJECT(act), "iconId", INKSCAPE_ICON("object-locked"), NULL );
    } else {
        g_object_set( G_OBJECT(act), "iconId", INKSCAPE_ICON("object-unlocked"), NULL );
    }

    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
    prefs->setBool("/options/forkgradientvectors/value", !active);
}
Ejemplo n.º 5
0
static void toggle_gradient( GtkToggleAction *act, gpointer data )
{
    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
    gboolean active = gtk_toggle_action_get_active(act);
    prefs->setBool("/options/transform/gradient", active);
    SPDesktop *desktop = static_cast<SPDesktop *>(data);
    if ( active ) {
        desktop->messageStack()->flash(Inkscape::INFORMATION_MESSAGE, _("Now <b>gradients</b> are <b>transformed</b> along with their objects when those are transformed (moved, scaled, rotated, or skewed)."));
    } else {
        desktop->messageStack()->flash(Inkscape::INFORMATION_MESSAGE, _("Now <b>gradients</b> remain <b>fixed</b> when objects are transformed (moved, scaled, rotated, or skewed)."));
    }
}
Ejemplo n.º 6
0
static void toggle_corners( GtkToggleAction* act, gpointer data)
{
    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
    gboolean active = gtk_toggle_action_get_active(act);
    prefs->setBool("/options/transform/rectcorners", active);
    SPDesktop *desktop = static_cast<SPDesktop *>(data);
    if ( active ) {
        desktop->messageStack()->flash(Inkscape::INFORMATION_MESSAGE, _("Now <b>rounded rectangle corners</b> are <b>scaled</b> when rectangles are scaled."));
    } else {
        desktop->messageStack()->flash(Inkscape::INFORMATION_MESSAGE, _("Now <b>rounded rectangle corners</b> are <b>not scaled</b> when rectangles are scaled."));
    }
}
Ejemplo n.º 7
0
static void toggle_stroke( GtkToggleAction* act, gpointer data )
{
    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
    gboolean active = gtk_toggle_action_get_active(act);
    prefs->setBool("/options/transform/stroke", active);
    SPDesktop *desktop = static_cast<SPDesktop *>(data);
    if ( active ) {
        desktop->messageStack()->flash(Inkscape::INFORMATION_MESSAGE, _("Now <b>stroke width</b> is <b>scaled</b> when objects are scaled."));
    } else {
        desktop->messageStack()->flash(Inkscape::INFORMATION_MESSAGE, _("Now <b>stroke width</b> is <b>not scaled</b> when objects are scaled."));
    }
}
Ejemplo n.º 8
0
static void sp_arctb_open_state_changed( EgeSelectOneAction *act, GObject *tbl )
{
    SPDesktop *desktop = static_cast<SPDesktop *>(g_object_get_data( tbl, "desktop" ));
    if (DocumentUndo::getUndoSensitive(desktop->getDocument())) {
        Inkscape::Preferences *prefs = Inkscape::Preferences::get();
        prefs->setBool("/tools/shapes/arc/open", ege_select_one_action_get_active(act) != 0);
    }

    // quit if run by the attr_changed listener
    if (g_object_get_data( tbl, "freeze" )) {
        return;
    }

    // in turn, prevent listener from responding
    g_object_set_data( tbl, "freeze", GINT_TO_POINTER(TRUE) );

    bool modmade = false;

    if ( ege_select_one_action_get_active(act) != 0 ) {
    	std::vector<SPItem*> itemlist=desktop->getSelection()->itemList();
        for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++){
            SPItem *item = *i;
            if (SP_IS_GENERICELLIPSE(item)) {
                Inkscape::XML::Node *repr = item->getRepr();
                repr->setAttribute("sodipodi:open", "true");
                item->updateRepr();
                modmade = true;
            }
        }
    } else {
    	std::vector<SPItem*> itemlist=desktop->getSelection()->itemList();
        for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++){
            SPItem *item = *i;
            if (SP_IS_GENERICELLIPSE(item)) {
                Inkscape::XML::Node *repr = item->getRepr();
                repr->setAttribute("sodipodi:open", NULL);
                item->updateRepr();
                modmade = true;
            }
        }
    }

    if (modmade) {
        DocumentUndo::done(desktop->getDocument(), SP_VERB_CONTEXT_ARC,
                           _("Arc: Change open/closed"));
    }

    g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) );
}
Ejemplo n.º 9
0
static void sp_erasertb_mode_changed( EgeSelectOneAction *act, GObject *tbl )
{
    SPDesktop *desktop = (SPDesktop *) g_object_get_data( tbl, "desktop" );
    bool eraserMode = ege_select_one_action_get_active( act ) != 0;
    if (DocumentUndo::getUndoSensitive(sp_desktop_document(desktop))) {
        Inkscape::Preferences *prefs = Inkscape::Preferences::get();
        prefs->setBool( "/tools/eraser/mode", eraserMode );
    }

    // only take action if run by the attr_changed listener
    if (!g_object_get_data( tbl, "freeze" )) {
        // in turn, prevent listener from responding
        g_object_set_data( tbl, "freeze", GINT_TO_POINTER(TRUE) );

        if ( eraserMode != 0 ) {
        } else {
        }
        // TODO finish implementation

        g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) );
    }
}
Ejemplo n.º 10
0
static void paintbucket_autogap_changed(EgeSelectOneAction* act, GObject * /*tbl*/)
{
    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
    prefs->setBool("/tools/paintbucket/autogap", ege_select_one_action_get_active( act ));
}
Ejemplo n.º 11
0
SPDocument *
GdkpixbufInput::open(Inkscape::Extension::Input *mod, char const *uri)
{
    // Determine whether the image should be embedded
    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
    bool ask = prefs->getBool("/dialogs/import/ask");
    Glib::ustring link  = prefs->getString("/dialogs/import/link");
    bool forcexdpi = prefs->getBool("/dialogs/import/forcexdpi");
    Glib::ustring scale = prefs->getString("/dialogs/import/scale");
    // std::cout << "GkdpixbufInput::open: "
    //           << " ask: " << ask
    //           << ", link: " << link
    //           << ", forcexdpi: " << forcexdpi
    //           << ", scale: " << scale << std::endl;
    // std::cout << "     in  preferences: "
    //           << " ask: " << !mod->get_param_bool("do_not_ask")
    //           << ", link: " << mod->get_param_optiongroup("link")
    //           << ", mod_dpi: " << mod->get_param_optiongroup("dpi")
    //           << ", scale: " << mod->get_param_optiongroup("scale") << std::endl;
    if( ask ) {
        Glib::ustring mod_link = mod->get_param_optiongroup("link");
        Glib::ustring mod_dpi = mod->get_param_optiongroup("dpi");
        bool mod_forcexdpi = ( mod_dpi.compare( "from_default" ) == 0 );
        Glib::ustring mod_scale = mod->get_param_optiongroup("scale");
        if( link.compare( mod_link ) != 0 ) {
            link = mod_link;
        }
        prefs->setString("/dialogs/import/link", link );
        if( forcexdpi != mod_forcexdpi ) {
            forcexdpi = mod_forcexdpi;
        }
        prefs->setBool("/dialogs/import/forcexdpi", forcexdpi );
        if( scale.compare( mod_scale ) != 0 ) {
            scale = mod_scale;
        }
        prefs->setString("/dialogs/import/scale", scale );
        prefs->setBool("/dialogs/import/ask", !mod->get_param_bool("do_not_ask") );
    }
    bool embed = ( link.compare( "embed" ) == 0 );

    SPDocument *doc = NULL;
    boost::scoped_ptr<Inkscape::Pixbuf> pb(Inkscape::Pixbuf::create_from_file(uri));

    // TODO: the pixbuf is created again from the base64-encoded attribute in SPImage.
    // Find a way to create the pixbuf only once.

    if (pb) {
        doc = SPDocument::createNewDoc(NULL, TRUE, TRUE);
        bool saved = DocumentUndo::getUndoSensitive(doc);
        DocumentUndo::setUndoSensitive(doc, false); // no need to undo in this temporary document

        double width = pb->width();
        double height = pb->height();
        double defaultxdpi = prefs->getDouble("/dialogs/import/defaultxdpi/value", Inkscape::Util::Quantity::convert(1, "in", "px"));
        //bool forcexdpi = prefs->getBool("/dialogs/import/forcexdpi");
        ImageResolution *ir = 0;
        double xscale = 1;
        double yscale = 1;


        if (!ir && !forcexdpi) {
            ir = new ImageResolution(uri);
        }
        if (ir && ir->ok()) {
            xscale = 900.0 / floor(10.*ir->x() + .5);  // round-off to 0.1 dpi
            yscale = 900.0 / floor(10.*ir->y() + .5);
        } else {
            xscale = 90.0 / defaultxdpi;
            yscale = 90.0 / defaultxdpi;
        }

        width *= xscale;
        height *= yscale;

        delete ir; // deleting NULL is safe

        // Create image node
        Inkscape::XML::Document *xml_doc = doc->getReprDoc();
        Inkscape::XML::Node *image_node = xml_doc->createElement("svg:image");
        sp_repr_set_svg_double(image_node, "width", width);
        sp_repr_set_svg_double(image_node, "height", height);

        // Added 11 Feb 2014 as we now honor "preserveAspectRatio" and this is
        // what Inkscaper's expect.
        image_node->setAttribute("preserveAspectRatio", "none");

        if( scale.compare( "auto" ) != 0 ) {
            SPCSSAttr *css = sp_repr_css_attr_new();
            sp_repr_css_set_property(css, "image-rendering", scale.c_str());
            sp_repr_css_set(image_node, css, "style");
            sp_repr_css_attr_unref( css );
        }

        if (embed) {
            sp_embed_image(image_node, pb.get());
        } else {
            // convert filename to uri
            gchar* _uri = g_filename_to_uri(uri, NULL, NULL);
            if(_uri) {
                image_node->setAttribute("xlink:href", _uri);
                g_free(_uri);
            } else {
                image_node->setAttribute("xlink:href", uri);
            }
        }

        // Add it to the current layer
        doc->getRoot()->appendChildRepr(image_node);
        Inkscape::GC::release(image_node);
        fit_canvas_to_drawing(doc);

        // Set viewBox if it doesn't exist
        if (!doc->getRoot()->viewBox_set) {
            //std::cout << "Viewbox not set, setting" << std::endl;
            doc->setViewBox(Geom::Rect::from_xywh(0, 0, doc->getWidth().value(doc->getDefaultUnit()), doc->getHeight().value(doc->getDefaultUnit())));
        }

        // restore undo, as now this document may be shown to the user if a bitmap was opened
        DocumentUndo::setUndoSensitive(doc, saved);
    } else {
        printf("GdkPixbuf loader failed\n");
    }

    return doc;
}
Ejemplo n.º 12
0
static void toggle_dropper_set_alpha( GtkToggleAction* act, gpointer tbl )
{
    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
    prefs->setBool( "/tools/dropper/setalpha", gtk_toggle_action_get_active( act ) );
    spinbutton_defocus(GTK_WIDGET(tbl));
}
Ejemplo n.º 13
0
static void sp_tweak_pressure_state_changed( GtkToggleAction *act, gpointer /*data*/ )
{
    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
    prefs->setBool("/tools/tweak/usepressure", gtk_toggle_action_get_active(act));
}
Ejemplo n.º 14
0
static void tweak_toggle_doo(GtkToggleAction *act, gpointer /*data*/) {
    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
    prefs->setBool("/tools/tweak/doo", gtk_toggle_action_get_active(act));
}