1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
#include "sp-linear-gradient.h"
#include "attributes.h"
#include "xml/repr.h"
#include "sp-factory.h"
namespace {
SPObject* createLinearGradient() {
return new SPLinearGradient();
}
bool linearGradientRegistered = SPFactory::instance().registerObject("svg:linearGradient", createLinearGradient);
}
/*
* Linear Gradient
*/
SPLinearGradient::SPLinearGradient() : SPGradient() {
this->x1.unset(SVGLength::PERCENT, 0.0, 0.0);
this->y1.unset(SVGLength::PERCENT, 0.0, 0.0);
this->x2.unset(SVGLength::PERCENT, 1.0, 1.0);
this->y2.unset(SVGLength::PERCENT, 0.0, 0.0);
}
SPLinearGradient::~SPLinearGradient() {
}
void SPLinearGradient::build(SPDocument *document, Inkscape::XML::Node *repr) {
SPGradient::build(document, repr);
this->readAttr( "x1" );
this->readAttr( "y1" );
this->readAttr( "x2" );
this->readAttr( "y2" );
}
/**
* Callback: set attribute.
*/
void SPLinearGradient::set(unsigned int key, const gchar* value) {
switch (key) {
case SP_ATTR_X1:
this->x1.readOrUnset(value, SVGLength::PERCENT, 0.0, 0.0);
this->requestModified(SP_OBJECT_MODIFIED_FLAG);
break;
case SP_ATTR_Y1:
this->y1.readOrUnset(value, SVGLength::PERCENT, 0.0, 0.0);
this->requestModified(SP_OBJECT_MODIFIED_FLAG);
break;
case SP_ATTR_X2:
this->x2.readOrUnset(value, SVGLength::PERCENT, 1.0, 1.0);
this->requestModified(SP_OBJECT_MODIFIED_FLAG);
break;
case SP_ATTR_Y2:
this->y2.readOrUnset(value, SVGLength::PERCENT, 0.0, 0.0);
this->requestModified(SP_OBJECT_MODIFIED_FLAG);
break;
default:
SPGradient::set(key, value);
break;
}
}
/**
* Callback: write attributes to associated repr.
*/
Inkscape::XML::Node* SPLinearGradient::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) {
if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) {
repr = xml_doc->createElement("svg:linearGradient");
}
if ((flags & SP_OBJECT_WRITE_ALL) || this->x1._set) {
sp_repr_set_svg_double(repr, "x1", this->x1.computed);
}
if ((flags & SP_OBJECT_WRITE_ALL) || this->y1._set) {
sp_repr_set_svg_double(repr, "y1", this->y1.computed);
}
if ((flags & SP_OBJECT_WRITE_ALL) || this->x2._set) {
sp_repr_set_svg_double(repr, "x2", this->x2.computed);
}
if ((flags & SP_OBJECT_WRITE_ALL) || this->y2._set) {
sp_repr_set_svg_double(repr, "y2", this->y2.computed);
}
SPGradient::write(xml_doc, repr, flags);
return repr;
}
/**
* Directly set properties of linear gradient and request modified.
*/
void
sp_lineargradient_set_position(SPLinearGradient *lg,
gdouble x1, gdouble y1,
gdouble x2, gdouble y2)
{
g_return_if_fail(lg != NULL);
g_return_if_fail(SP_IS_LINEARGRADIENT(lg));
/* fixme: units? (Lauris) */
lg->x1.set(SVGLength::NONE, x1, x1);
lg->y1.set(SVGLength::NONE, y1, y1);
lg->x2.set(SVGLength::NONE, x2, x2);
lg->y2.set(SVGLength::NONE, y2, y2);
lg->requestModified(SP_OBJECT_MODIFIED_FLAG);
}
cairo_pattern_t* SPLinearGradient::pattern_new(cairo_t *ct, Geom::OptRect const &bbox, double opacity) {
this->ensureVector();
cairo_pattern_t *cp = cairo_pattern_create_linear(
this->x1.computed, this->y1.computed,
this->x2.computed, this->y2.computed);
sp_gradient_pattern_common_setup(cp, this, bbox, opacity);
return cp;
}
|