3
#include "sp-linear-gradient.h"
5
#include "attributes.h"
11
SPLinearGradient::SPLinearGradient() : SPGradient() {
12
this->x1.unset(SVGLength::PERCENT, 0.0, 0.0);
13
this->y1.unset(SVGLength::PERCENT, 0.0, 0.0);
14
this->x2.unset(SVGLength::PERCENT, 1.0, 1.0);
15
this->y2.unset(SVGLength::PERCENT, 0.0, 0.0);
18
SPLinearGradient::~SPLinearGradient() {
21
void SPLinearGradient::build(SPDocument *document, Inkscape::XML::Node *repr) {
22
SPGradient::build(document, repr);
24
this->readAttr( "x1" );
25
this->readAttr( "y1" );
26
this->readAttr( "x2" );
27
this->readAttr( "y2" );
31
* Callback: set attribute.
33
void SPLinearGradient::set(unsigned int key, const gchar* value) {
36
this->x1.readOrUnset(value, SVGLength::PERCENT, 0.0, 0.0);
37
this->requestModified(SP_OBJECT_MODIFIED_FLAG);
41
this->y1.readOrUnset(value, SVGLength::PERCENT, 0.0, 0.0);
42
this->requestModified(SP_OBJECT_MODIFIED_FLAG);
46
this->x2.readOrUnset(value, SVGLength::PERCENT, 1.0, 1.0);
47
this->requestModified(SP_OBJECT_MODIFIED_FLAG);
51
this->y2.readOrUnset(value, SVGLength::PERCENT, 0.0, 0.0);
52
this->requestModified(SP_OBJECT_MODIFIED_FLAG);
56
SPGradient::set(key, value);
62
* Callback: write attributes to associated repr.
64
Inkscape::XML::Node* SPLinearGradient::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) {
65
if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) {
66
repr = xml_doc->createElement("svg:linearGradient");
69
if ((flags & SP_OBJECT_WRITE_ALL) || this->x1._set) {
70
sp_repr_set_svg_double(repr, "x1", this->x1.computed);
73
if ((flags & SP_OBJECT_WRITE_ALL) || this->y1._set) {
74
sp_repr_set_svg_double(repr, "y1", this->y1.computed);
77
if ((flags & SP_OBJECT_WRITE_ALL) || this->x2._set) {
78
sp_repr_set_svg_double(repr, "x2", this->x2.computed);
81
if ((flags & SP_OBJECT_WRITE_ALL) || this->y2._set) {
82
sp_repr_set_svg_double(repr, "y2", this->y2.computed);
85
SPGradient::write(xml_doc, repr, flags);
90
cairo_pattern_t* SPLinearGradient::pattern_new(cairo_t * /*ct*/, Geom::OptRect const &bbox, double opacity) {
93
cairo_pattern_t *cp = cairo_pattern_create_linear(
94
this->x1.computed, this->y1.computed,
95
this->x2.computed, this->y2.computed);
97
sp_gradient_pattern_common_setup(cp, this, bbox, opacity);