=== modified file 'src/helper/stock-items.cpp' --- src/helper/stock-items.cpp 2012-08-04 02:20:42 +0000 +++ src/helper/stock-items.cpp 2012-08-08 02:29:25 +0000 @@ -173,7 +173,7 @@ // if necessary it will import the object. Copes with name clashes through use of the inkscape:stockid property // This should be set to be the same as the id in the libary file. -SPObject *get_stock_item(gchar const *urn) +SPObject *get_stock_item(gchar const *urn, gboolean stock) { g_assert(urn != NULL); @@ -202,7 +202,7 @@ return NULL; } SPObject *object = NULL; - if (!strcmp(base, "marker")) { + if (!strcmp(base, "marker") && !stock) { for ( SPObject *child = defs->firstChild(); child; child = child->getNext() ) { if (child->getRepr()->attribute("inkscape:stockid") && @@ -214,7 +214,7 @@ } } - else if (!strcmp(base,"pattern")) { + else if (!strcmp(base,"pattern") && !stock) { for ( SPObject *child = defs->firstChild() ; child; child = child->getNext() ) { if (child->getRepr()->attribute("inkscape:stockid") && @@ -226,7 +226,7 @@ } } - else if (!strcmp(base,"gradient")) { + else if (!strcmp(base,"gradient") && !stock) { for ( SPObject *child = defs->firstChild(); child; child = child->getNext() ) { if (child->getRepr()->attribute("inkscape:stockid") && @@ -255,6 +255,10 @@ g_free(base); g_free(name); + if (object) { + object->getRepr()->setAttribute("inkscape:isstock", "true"); + } + return object; } @@ -264,6 +268,10 @@ SPDocument *doc = sp_desktop_document(desktop); SPObject *object = doc->getObjectById(urn); + if (object) { + object->getRepr()->setAttribute("inkscape:isstock", "false"); + } + return object; } } === modified file 'src/helper/stock-items.h' --- src/helper/stock-items.h 2011-12-08 11:53:54 +0000 +++ src/helper/stock-items.h 2012-08-08 02:29:03 +0000 @@ -17,6 +17,6 @@ class SPObject; -SPObject *get_stock_item(gchar const *urn); +SPObject *get_stock_item(gchar const *urn, gboolean stock=FALSE); #endif // SEEN_INK_STOCK_ITEMS_H === modified file 'src/ui/dialog/inkscape-preferences.cpp' --- src/ui/dialog/inkscape-preferences.cpp 2012-07-23 18:34:01 +0000 +++ src/ui/dialog/inkscape-preferences.cpp 2012-08-07 23:54:56 +0000 @@ -1066,6 +1066,15 @@ _page_behavior.add_line( false, _("Simplification threshold:"), _misc_simpl, "", _("How strong is the Node tool's Simplify command by default. If you invoke this command several times in quick succession, it will act more and more aggressively; invoking it again after a pause restores the default threshold."), false); + _markers_color_stock.init ( _("Color stock markers the same color as object"), "/options/markers/colorStockMarkers", true); + _markers_color_custom.init ( _("Color custom markers the same color as object"), "/options/markers/colorCustomMarkers", false); + + _page_behavior.add_group_header( _("Markers")); + _page_behavior.add_line( true, "", _markers_color_stock, "", + _("Stroke color same as object, fill color either object fill color or marker fill color")); + _page_behavior.add_line( true, "", _markers_color_custom, "", + _("Stroke color same as object, fill color either object fill color or marker fill color")); + // Selecting options _sel_all.init ( _("Select in all layers"), "/options/kbselection/inlayer", PREFS_SELECTION_ALL, false, 0); _sel_current.init ( _("Select only within current layer"), "/options/kbselection/inlayer", PREFS_SELECTION_LAYER, true, &_sel_all); === modified file 'src/ui/dialog/inkscape-preferences.h' --- src/ui/dialog/inkscape-preferences.h 2012-07-23 18:34:01 +0000 +++ src/ui/dialog/inkscape-preferences.h 2012-08-07 23:55:09 +0000 @@ -281,6 +281,9 @@ UI::Widget::PrefCheckButton _sel_layer_deselects; UI::Widget::PrefCheckButton _sel_cycle; + UI::Widget::PrefCheckButton _markers_color_stock; + UI::Widget::PrefCheckButton _markers_color_custom; + UI::Widget::PrefSpinButton _importexport_export_res; UI::Widget::PrefSpinButton _importexport_import_res; UI::Widget::PrefSlider _snap_delay; === modified file 'src/widgets/stroke-marker-selector.cpp' --- src/widgets/stroke-marker-selector.cpp 2012-08-07 13:35:25 +0000 +++ src/widgets/stroke-marker-selector.cpp 2012-08-08 06:18:14 +0000 @@ -40,6 +40,8 @@ #include #include "ui/widget/spinbutton.h" +#include "stroke-style.h" +#include "gradient-chemistry.h" static Inkscape::UI::Cache::SvgPreview svg_preview_cache; @@ -205,20 +207,8 @@ updating = true; if (marker != NULL) { - bool mark_is_stock = false; - if (marker->getRepr()->attribute("inkscape:stockid")) { - mark_is_stock = true; - } - - gchar *markname = 0; - if (mark_is_stock) { - markname = g_strdup(marker->getRepr()->attribute("inkscape:stockid")); - } else { - markname = g_strdup(marker->getRepr()->attribute("id")); - } - + gchar *markname = g_strdup(marker->getRepr()->attribute("id")); set_selected(markname); - g_free (markname); } else { @@ -253,7 +243,7 @@ { markurn = g_strdup(markid); } - SPObject *mark = get_stock_item(markurn); + SPObject *mark = get_stock_item(markurn, stockid); g_free(markurn); if (mark) { Inkscape::XML::Node *repr = mark->getRepr(); @@ -268,7 +258,16 @@ void MarkerComboBox::set_active_history() { - set_selected(get_active()->get_value(marker_columns.marker)); + + const gchar *markid = get_active()->get_value(marker_columns.marker); + + // If forked from a stockid, add the stockid + SPObject const *marker = doc->getObjectById(markid); + if (marker && marker->getRepr()->attribute("inkscape:stockid")) { + markid = marker->getRepr()->attribute("inkscape:stockid"); + } + + set_selected(markid); } @@ -399,10 +398,10 @@ for (; marker_list != NULL; marker_list = marker_list->next) { Inkscape::XML::Node *repr = reinterpret_cast(marker_list->data)->getRepr(); - gchar const *markid = repr->attribute("id"); + gchar const *markid = repr->attribute("inkscape:stockid") ? repr->attribute("inkscape:stockid") : repr->attribute("id"); // generate preview - Gtk::Image *prv = create_marker_image (22, markid, source, drawing, visionkey); + Gtk::Image *prv = create_marker_image (22, repr->attribute("id"), source, drawing, visionkey); prv->show(); // Add history before separator, others after @@ -413,8 +412,10 @@ row = *(marker_store->append()); row[marker_columns.label] = gr_ellipsize_text(markid, 20); + // Non "stock" markers can also have "inkscape:stockid" (when using extension ColorMarkers), + // So use !is_history instead to determine is it is "stock" (ie in the markers.svg file) row[marker_columns.stock] = !history; - row[marker_columns.marker] = g_strdup(markid); + row[marker_columns.marker] = repr->attribute("id"); row[marker_columns.image] = prv; row[marker_columns.history] = history; row[marker_columns.separator] = false; @@ -456,6 +457,38 @@ Inkscape::GC::release(mrepr); + // If the marker color is a url link to a pattern or gradient copy that too + SPObject *mk = source->getObjectById(mname); + SPCSSAttr *css_marker = sp_css_attr_from_object(mk->firstChild(), SP_STYLE_FLAG_ALWAYS); + //const char *mfill = sp_repr_css_property(css_marker, "fill", "none"); + const char *mstroke = sp_repr_css_property(css_marker, "fill", "none"); + + if (!strncmp (mstroke, "url(", 4)) { + SPObject *linkObj = getMarkerObj(mstroke, source); + if (linkObj) { + Inkscape::XML::Node *grepr = linkObj->getRepr()->duplicate(xml_doc); + SPObject *oldmarker = sandbox->getObjectById(linkObj->getId()); + if (oldmarker) { + oldmarker->deleteObject(false); + } + defsrepr->appendChild(grepr); + Inkscape::GC::release(grepr); + + if (SP_IS_GRADIENT(linkObj)) { + SPGradient *vector = sp_gradient_get_forked_vector_if_necessary (SP_GRADIENT(linkObj), false); + if (vector) { + Inkscape::XML::Node *grepr = vector->getRepr()->duplicate(xml_doc); + SPObject *oldmarker = sandbox->getObjectById(vector->getId()); + if (oldmarker) { + oldmarker->deleteObject(false); + } + defsrepr->appendChild(grepr); + Inkscape::GC::release(grepr); + } + } + } + } + // Uncomment this to get the sandbox documents saved (useful for debugging) //FILE *fp = fopen (g_strconcat(combo_id, mname, ".svg", NULL), "w"); //sp_repr_save_stream(sandbox->getReprDoc(), fp); === modified file 'src/widgets/stroke-style.cpp' --- src/widgets/stroke-style.cpp 2012-08-04 02:20:42 +0000 +++ src/widgets/stroke-style.cpp 2012-08-08 03:44:55 +0000 @@ -45,6 +45,42 @@ } } + +/** + * Extract the actual name of the link + * e.g. get mTriangle from url(#mTriangle). + * \return Buffer containing the actual name, allocated from GLib; + * the caller should free the buffer when they no longer need it. + */ +SPObject* getMarkerObj(gchar const *n, SPDocument *doc) +{ + gchar const *p = n; + while (*p != '\0' && *p != '#') { + p++; + } + + if (*p == '\0' || p[1] == '\0') { + return NULL; + } + + p++; + int c = 0; + while (p[c] != '\0' && p[c] != ')') { + c++; + } + + if (p[c] == '\0') { + return NULL; + } + + gchar* b = g_strdup(p); + b[c] = '\0'; + + // FIXME: get the document from the object and let the caller pass it in + SPObject *marker = doc->getObjectById(b); + return marker; +} + namespace Inkscape { /** @@ -331,7 +367,6 @@ tb->show(); tb->set_mode(false); hb->pack_start(*tb, false, false, 0); - // TODO set_data(icon, tb); tb->set_data(key, (gpointer*)data); @@ -359,6 +394,8 @@ return; } + spw->update = true; + SPDocument *document = sp_desktop_document(spw->desktop); if (!document) { return; @@ -367,6 +404,7 @@ /* Get Marker */ gchar const *marker = marker_combo->get_active_marker_uri(); + SPCSSAttr *css = sp_repr_css_attr_new(); gchar const *combo_id = marker_combo->get_id(); sp_repr_css_set_property(css, combo_id, marker); @@ -386,7 +424,9 @@ Inkscape::XML::Node *selrepr = item->getRepr(); if (selrepr) { sp_repr_css_change_recursive(selrepr, css, "style"); + spw->setMarkerColor(item, getMarkerObj(marker, document), combo_id); } + item->requestModified(SP_OBJECT_MODIFIED_FLAG); item->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG); } @@ -397,6 +437,8 @@ DocumentUndo::done(document, SP_VERB_DIALOG_FILL_STROKE, _("Set markers")); + spw->update = false; + }; void @@ -519,6 +561,109 @@ } /** + * Change the color of the marker to match the color of the item. + * Marker stroke color is set to item stroke color. + * Fill color : + * 1. If the item has fill, use that for the marker fill, + * 2. If the marker has same fill and stroke assume its solid, use item stroke for both fill and stroke the line stroke + * 3. If the marker has fill color, use the marker fill color + * + */ +void +StrokeStyle::setMarkerColor(SPItem *item, SPObject *marker, gchar const *combo_id) +{ + + if (!item || !marker) { + return; + } + + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + gboolean colorStock = prefs->getBool("/options/markers/colorStockMarkers", true); + gboolean colorCustom = prefs->getBool("/options/markers/colorCustomMarkers", false); + const gchar *stock = marker->getRepr()->attribute("inkscape:isstock"); + gboolean isStock = (!stock || !strcmp(stock,"true")); + + if (isStock ? !colorStock : !colorCustom) { + return; + } + + Inkscape::XML::Node *repr = marker->getRepr()->firstChild(); + if (repr) { + + // Current line style + SPCSSAttr *css_item = sp_css_attr_from_object(item, SP_STYLE_FLAG_ALWAYS); + const char *lstroke = sp_repr_css_property(css_item, "stroke", "none"); + const char *lstroke_opacity = sp_repr_css_property(css_item, "stroke-opacity", "1"); + const char *lfill = sp_repr_css_property(css_item, "fill", "none"); + const char *lfill_opacity = sp_repr_css_property(css_item, "fill-opacity", "1"); + + // Current marker style + SPCSSAttr *css_marker = sp_css_attr_from_object(marker->firstChild(), SP_STYLE_FLAG_ALWAYS); + const char *mfill = sp_repr_css_property(css_marker, "fill", "none"); + const char *mstroke = sp_repr_css_property(css_marker, "fill", "none"); + + gboolean needFork = false; + + // Create new marker style with the lines stroke + SPCSSAttr *css = sp_repr_css_attr_new(); + + sp_repr_css_set_property(css, "stroke", lstroke); + sp_repr_css_set_property(css, "stroke-opacity", lstroke_opacity); + + if (strcmp(lstroke, mstroke) ) { + needFork = true; + } + + if (strcmp(lfill, "none") ) { + // 1. If the line has fill, use that for the marker fill + sp_repr_css_set_property(css, "fill", lfill); + sp_repr_css_set_property(css, "fill-opacity", lfill_opacity); + needFork = true; + } + else if (mfill && mstroke && !strcmp(mfill, mstroke) && mfill[0] == '#' && strcmp(mfill, "#ffffff")) { + // 2. If the marker has same fill and stroke assume its solid. use line stroke for both fill and stroke the line stroke + sp_repr_css_set_property(css, "fill", lstroke); + sp_repr_css_set_property(css, "fill-opacity", lstroke_opacity); + needFork = true; + } + else if (mfill && mfill[0] == '#' && strcmp(mfill, "#000000")) { + // 3. If the marker has fill color, use the marker fill color + sp_repr_css_set_property(css, "fill", mfill); + //sp_repr_css_set_property(css, "fill-opacity", mfill_opacity); + needFork = true; + + } + if (needFork) { + SPDocument *doc = SP_ACTIVE_DOCUMENT; + SPDefs *defs = doc->getDefs(); + Inkscape::XML::Document *xml_doc = doc->getReprDoc(); + Inkscape::XML::Node *mark_repr = marker->getRepr()->duplicate(xml_doc); + defs->getRepr()->addChild(mark_repr, NULL); + gchar const *markid = marker->getRepr()->attribute("inkscape:stockid") ? marker->getRepr()->attribute("inkscape:stockid") : marker->getRepr()->attribute("id"); + mark_repr->setAttribute("inkscape:stockid", markid); + //object = doc->getObjectByRepr(mark_repr); + //repr = mark_repr; + + sp_repr_css_change_recursive(mark_repr->firstChild(), css, "style"); + // privates are garbage-collectable + mark_repr->firstChild()->setAttribute("inkscape:collect", "always"); + + // Update the items url to new marker + SPCSSAttr *css_item = sp_repr_css_attr_new(); + sp_repr_css_set_property(css_item, combo_id, g_strconcat("url(#", mark_repr->attribute("id"), ")", NULL)); + sp_repr_css_change_recursive(item->getRepr(), css_item, "style"); + + g_message("New marker %s %s", mark_repr->attribute("id"), markid); + Inkscape::GC::release(mark_repr); + } + } + + marker->requestModified(SP_OBJECT_MODIFIED_FLAG); + marker->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG); + +} + +/** * Sets selector widgets' dash style from an SPStyle object. */ void @@ -602,7 +747,6 @@ Inkscape::Selection *sel = desktop ? sp_desktop_selection(desktop) : NULL; - // TODO FillOrStroke kind = GPOINTER_TO_INT(get_data("kind")) ? FILL : STROKE; // create temporary style @@ -882,7 +1026,6 @@ if (tb->get_active()) { - // TODO gchar const *join = static_cast(tb->get_data("join")); gchar const *cap @@ -988,7 +1131,7 @@ // If the object has this type of markers, // Extract the name of the marker that the object uses - SPObject *marker = getMarkerName(object->style->marker[keyloc[i].loc].value, object->document); + SPObject *marker = getMarkerObj(object->style->marker[keyloc[i].loc].value, object->document); // Scroll the combobox to that marker combo->set_current(marker); @@ -1000,41 +1143,6 @@ } -/** - * Extract the actual name of the link - * e.g. get mTriangle from url(#mTriangle). - * \return Buffer containing the actual name, allocated from GLib; - * the caller should free the buffer when they no longer need it. - */ -SPObject* -StrokeStyle::getMarkerName(gchar const *n, SPDocument *doc) -{ - gchar const *p = n; - while (*p != '\0' && *p != '#') { - p++; - } - - if (*p == '\0' || p[1] == '\0') { - return NULL; - } - - p++; - int c = 0; - while (p[c] != '\0' && p[c] != ')') { - c++; - } - - if (p[c] == '\0') { - return NULL; - } - - gchar* b = g_strdup(p); - b[c] = '\0'; - - // FIXME: get the document from the object and let the caller pass it in - SPObject *marker = doc->getObjectById(b); - return marker; -} } // namespace Inkscape === modified file 'src/widgets/stroke-style.h' --- src/widgets/stroke-style.h 2012-08-04 01:55:39 +0000 +++ src/widgets/stroke-style.h 2012-08-08 03:41:26 +0000 @@ -35,6 +35,7 @@ #include "inkscape.h" #include "io/sys.h" #include "marker.h" +#include "preferences.h" #include "path-prefix.h" #include "selection.h" #include "sp-linear-gradient.h" @@ -81,6 +82,8 @@ */ void sp_stroke_style_widget_set_desktop(Gtk::Widget *widget, SPDesktop *desktop); +SPObject *getMarkerObj(gchar const *n, SPDocument *doc); + namespace Inkscape { class StrokeStyle : public Gtk::VBox @@ -92,7 +95,7 @@ private: - SPObject *getMarkerName(gchar const *n, SPDocument *doc); + void updateLine(); void updateAllMarkers(GSList const *objects); void updateMarkerHist(SPMarkerLoc const which); @@ -103,6 +106,8 @@ void setCapButtons(Gtk::ToggleButton *active); void scaleLine(); void setScaledDash(SPCSSAttr *css, int ndash, double *dash, double offset, double scale); + void setMarkerColor(SPItem *item, SPObject *marker, gchar const *combo_id); + Gtk::RadioButton * makeRadioButton(Gtk::RadioButton *tb, char const *icon, Gtk::HBox *hb, gchar const *key, gchar const *data); static gboolean setStrokeWidthUnit(SPUnitSelector *,