void gr_apply_gradient_to_item( SPItem *item, SPGradient *gr, SPGradientType initialType, Inkscape::PaintTarget initialMode, Inkscape::PaintTarget mode ) { SPStyle *style = item->style; bool isFill = (mode == Inkscape::FOR_FILL); if (style && (isFill ? style->fill.isPaintserver() : style->stroke.isPaintserver()) //&& SP_IS_GRADIENT(isFill ? style->getFillPaintServer() : style->getStrokePaintServer()) ) { && (isFill ? SP_IS_GRADIENT(style->getFillPaintServer()) : SP_IS_GRADIENT(style->getStrokePaintServer())) ) { SPPaintServer *server = isFill ? style->getFillPaintServer() : style->getStrokePaintServer(); if ( SP_IS_LINEARGRADIENT(server) ) { sp_item_set_gradient(item, gr, SP_GRADIENT_TYPE_LINEAR, mode); } else if ( SP_IS_RADIALGRADIENT(server) ) { sp_item_set_gradient(item, gr, SP_GRADIENT_TYPE_RADIAL, mode); } } else if (initialMode == mode) { sp_item_set_gradient(item, gr, initialType, mode); } }
SPPaintSelector::Mode SPPaintSelector::getModeForStyle(SPStyle const & style, FillOrStroke kind) { Mode mode = MODE_UNSET; SPIPaint const & target = (kind == FILL) ? style.fill : style.stroke; if ( !target.set ) { mode = MODE_UNSET; } else if ( target.isPaintserver() ) { SPPaintServer const *server = (kind == FILL) ? style.getFillPaintServer() : style.getStrokePaintServer(); #ifdef SP_PS_VERBOSE g_message("SPPaintSelector::getModeForStyle(%p, %d)", &style, kind); g_message("==== server:%p %s grad:%s swatch:%s", server, server->getId(), (SP_IS_GRADIENT(server)?"Y":"n"), (SP_IS_GRADIENT(server) && SP_GRADIENT(server)->getVector()->isSwatch()?"Y":"n")); #endif // SP_PS_VERBOSE if (server && SP_IS_GRADIENT(server) && SP_GRADIENT(server)->getVector()->isSwatch()) { mode = MODE_SWATCH; } else if (SP_IS_LINEARGRADIENT(server)) { mode = MODE_GRADIENT_LINEAR; } else if (SP_IS_RADIALGRADIENT(server)) { mode = MODE_GRADIENT_RADIAL; } else if (SP_IS_PATTERN(server)) { mode = MODE_PATTERN; } else { g_warning( "file %s: line %d: Unknown paintserver", __FILE__, __LINE__ ); mode = MODE_NONE; } } else if ( target.isColor() ) { // TODO this is no longer a valid assertion: mode = MODE_COLOR_RGB; // so far only rgb can be read from svg } else if ( target.isNone() ) { mode = MODE_NONE; } else { g_warning( "file %s: line %d: Unknown paint type", __FILE__, __LINE__ ); mode = MODE_NONE; } return mode; }