sp-linear-gradient.cpp revision 6afde8674707ca6bde7835c5a6e4f182daf789af
0N/A#include <cairo.h>
0N/A
0N/A#include "sp-linear-gradient.h"
0N/A
0N/A#include "attributes.h"
0N/A#include "xml/repr.h"
0N/A
0N/A/*
0N/A * Linear Gradient
0N/A */
0N/ASPLinearGradient::SPLinearGradient() : SPGradient() {
0N/A this->x1.unset(SVGLength::PERCENT, 0.0, 0.0);
0N/A this->y1.unset(SVGLength::PERCENT, 0.0, 0.0);
0N/A this->x2.unset(SVGLength::PERCENT, 1.0, 1.0);
0N/A this->y2.unset(SVGLength::PERCENT, 0.0, 0.0);
0N/A}
0N/A
0N/ASPLinearGradient::~SPLinearGradient() {
0N/A}
0N/A
0N/Avoid SPLinearGradient::build(SPDocument *document, Inkscape::XML::Node *repr) {
0N/A SPGradient::build(document, repr);
0N/A
0N/A this->readAttr( "x1" );
0N/A this->readAttr( "y1" );
0N/A this->readAttr( "x2" );
0N/A this->readAttr( "y2" );
0N/A}
0N/A
0N/A/**
0N/A * Callback: set attribute.
0N/A */
0N/Avoid SPLinearGradient::set(unsigned int key, const gchar* value) {
0N/A switch (key) {
0N/A case SP_ATTR_X1:
0N/A this->x1.readOrUnset(value, SVGLength::PERCENT, 0.0, 0.0);
1657N/A this->requestModified(SP_OBJECT_MODIFIED_FLAG);
1657N/A break;
1657N/A
1657N/A case SP_ATTR_Y1:
0N/A this->y1.readOrUnset(value, SVGLength::PERCENT, 0.0, 0.0);
1657N/A this->requestModified(SP_OBJECT_MODIFIED_FLAG);
0N/A break;
0N/A
0N/A case SP_ATTR_X2:
0N/A this->x2.readOrUnset(value, SVGLength::PERCENT, 1.0, 1.0);
0N/A this->requestModified(SP_OBJECT_MODIFIED_FLAG);
0N/A break;
0N/A
0N/A case SP_ATTR_Y2:
0N/A this->y2.readOrUnset(value, SVGLength::PERCENT, 0.0, 0.0);
0N/A this->requestModified(SP_OBJECT_MODIFIED_FLAG);
0N/A break;
0N/A
0N/A default:
0N/A SPGradient::set(key, value);
0N/A break;
0N/A }
0N/A}
0N/A
0N/A/**
0N/A * Callback: write attributes to associated repr.
0N/A */
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;
}
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;
}