~inkscape.dev/inkscape/trunk

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
/** @file
 * @solid color class.
 */
/* Authors:
 *   Tavmjong Bah <tavjong@free.fr>
 *
 * Copyright (C) 2014 Tavmjong Bah
 *
 * Released under GNU GPL, read the file 'COPYING' for more information
 */
#include <cairo.h>

#include "sp-solid-color.h"

#include "attributes.h"
#include "style.h"


/*
 * Solid Color
 */
SPSolidColor::SPSolidColor() : SPPaintServer() {
}

SPSolidColor::~SPSolidColor() {
}

void SPSolidColor::build(SPDocument* doc, Inkscape::XML::Node* repr) {
    SPPaintServer::build(doc, repr);

    this->readAttr( "style" );
    this->readAttr( "solid-color" );
    this->readAttr( "solid-opacity" );
}

/**
 * Virtual build: set solidcolor attributes from its associated XML node.
 */

void SPSolidColor::set(unsigned int key, const gchar* value) {

    if (SP_ATTRIBUTE_IS_CSS(key)) {
        style->readFromObject( this );
        this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG);
    } else {
        SPPaintServer::set(key, value);
    }
}

/**
 * Virtual set: set attribute to value.
 */

Inkscape::XML::Node* SPSolidColor::write(Inkscape::XML::Document* xml_doc, Inkscape::XML::Node* repr, guint flags) {
    if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) {
        repr = xml_doc->createElement("svg:solidColor");
    }

    SPObject::write(xml_doc, repr, flags);

    return repr;
}

cairo_pattern_t* SPSolidColor::pattern_new(cairo_t * /*ct*/, Geom::OptRect const & /*bbox*/, double opacity) {

    SPIColor *c = &(this->style->solid_color);
    cairo_pattern_t *cp = cairo_pattern_create_rgba ( c->value.color.v.c[0], c->value.color.v.c[1], c->value.color.v.c[2], SP_SCALE24_TO_FLOAT(this->style->solid_opacity.value) * opacity );

    return cp;
}


/**
 * Virtual write: write object attributes to repr.
 */

/*
  Local Variables:
  mode:c++
  c-file-style:"stroustrup"
  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
  indent-tabs-mode:nil
  fill-column:99
  End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :