diff options
| author | Tavmjong Bah <tavmjong@free.fr> | 2014-07-31 14:31:01 +0000 |
|---|---|---|
| committer | tavmjong-free <tavmjong@free.fr> | 2014-07-31 14:31:01 +0000 |
| commit | 291925ef62d1068af1c4b7f3614c96d46f3c20f2 (patch) | |
| tree | 909ddb2084eae4b02ff42fcd3860c97efb505cbd /src | |
| parent | Limit the number of paths to be used as snap targets, to keep Inkscape respon... (diff) | |
| download | inkscape-291925ef62d1068af1c4b7f3614c96d46f3c20f2.tar.gz inkscape-291925ef62d1068af1c4b7f3614c96d46f3c20f2.zip | |
Basic support for <solidColor> element (rendering only as a paint server).
(bzr r13484)
Diffstat (limited to 'src')
| -rw-r--r-- | src/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | src/Makefile_insert | 1 | ||||
| -rw-r--r-- | src/attributes.cpp | 2 | ||||
| -rw-r--r-- | src/attributes.h | 2 | ||||
| -rw-r--r-- | src/sp-solid-color.cpp | 97 | ||||
| -rw-r--r-- | src/sp-solid-color.h | 46 | ||||
| -rw-r--r-- | src/style.cpp | 23 | ||||
| -rw-r--r-- | src/style.h | 5 |
8 files changed, 178 insertions, 0 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d40aad802..4a792af6b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -63,6 +63,7 @@ set(sp_SRC sp-root.cpp sp-script.cpp sp-shape.cpp + sp-solid-color.cpp sp-spiral.cpp sp-star.cpp sp-stop.cpp @@ -147,6 +148,7 @@ set(sp_SRC sp-root.h sp-script.h sp-shape.h + sp-solid-color.h sp-spiral.h sp-star.h sp-stop.h diff --git a/src/Makefile_insert b/src/Makefile_insert index 6d0d6b08c..f191839a1 100644 --- a/src/Makefile_insert +++ b/src/Makefile_insert @@ -192,6 +192,7 @@ ink_common_sources += \ sp-root.cpp sp-root.h \ sp-script.cpp sp-script.h \ sp-shape.cpp sp-shape.h \ + sp-solid-color.cpp sp-solid-color.h \ sp-spiral.cpp sp-spiral.h \ sp-star.cpp sp-star.h \ sp-stop.cpp sp-stop.h \ diff --git a/src/attributes.cpp b/src/attributes.cpp index ee2a80fd3..da7b25f03 100644 --- a/src/attributes.cpp +++ b/src/attributes.cpp @@ -475,6 +475,8 @@ static SPStyleProp const props[] = { {SP_PROP_MARKER_START, "marker-start"}, {SP_PROP_PAINT_ORDER, "paint-order" }, {SP_PROP_SHAPE_RENDERING, "shape-rendering"}, + {SP_PROP_SOLID_COLOR, "solid-color"}, + {SP_PROP_SOLID_OPACITY, "solid-opacity"}, {SP_PROP_STROKE, "stroke"}, {SP_PROP_STROKE_DASHARRAY, "stroke-dasharray"}, {SP_PROP_STROKE_DASHOFFSET, "stroke-dashoffset"}, diff --git a/src/attributes.h b/src/attributes.h index b8843fcb7..82e7ca8a6 100644 --- a/src/attributes.h +++ b/src/attributes.h @@ -476,6 +476,8 @@ enum SPAttributeEnum { SP_PROP_MARKER_START, SP_PROP_PAINT_ORDER, /* SVG2 */ SP_PROP_SHAPE_RENDERING, + SP_PROP_SOLID_COLOR, + SP_PROP_SOLID_OPACITY, SP_PROP_STROKE, SP_PROP_STROKE_DASHARRAY, SP_PROP_STROKE_DASHOFFSET, diff --git a/src/sp-solid-color.cpp b/src/sp-solid-color.cpp new file mode 100644 index 000000000..1f606d176 --- /dev/null +++ b/src/sp-solid-color.cpp @@ -0,0 +1,97 @@ +/** @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 "sp-solid-color.h" + +#include "attributes.h" +#include "style.h" +#include "xml/repr.h" + +#include "sp-factory.h" +#include "sp-item.h" +#include "style-internal.h" + +namespace { + SPObject* createSolidColor() { + return new SPSolidColor(); + } + + bool solidColorRegistered = SPFactory::instance().registerObject("svg:solidColor", createSolidColor); +} + + +/* + * 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)) { + sp_style_read_from_object(this->style, 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 : diff --git a/src/sp-solid-color.h b/src/sp-solid-color.h new file mode 100644 index 000000000..0ff09762e --- /dev/null +++ b/src/sp-solid-color.h @@ -0,0 +1,46 @@ +#ifndef SEEN_SP_SOLIDCOLOR_H +#define SEEN_SP_SOLIDCOLOR_H + +/** \file + * SPSolidColor: SVG <solidColor> implementation. + */ +/* + * Authors: Tavmjong Bah + * Copyright (C) 2012 Tavmjong Bah + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include <glib.h> +#include "color.h" +#include "sp-paint-server.h" + +#define SP_SOLIDCOLOR(obj) (dynamic_cast<SPSolidColor*>((SPObject*)obj)) +#define SP_IS_SOLIDCOLOR(obj) (dynamic_cast<const SPSolidColor*>((SPObject*)obj) != NULL) + +/** Gradient SolidColor. */ +class SPSolidColor : public SPPaintServer { +public: + SPSolidColor(); + virtual ~SPSolidColor(); + + virtual cairo_pattern_t* pattern_new(cairo_t *ct, Geom::OptRect const &bbox, double opacity); + +protected: + virtual void build(SPDocument* doc, Inkscape::XML::Node* repr); + virtual void set(unsigned int key, const gchar* value); + virtual Inkscape::XML::Node* write(Inkscape::XML::Document* doc, Inkscape::XML::Node* repr, guint flags); +}; + +#endif /* !SEEN_SP_SOLIDCOLOR_H */ + +/* + 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 : diff --git a/src/style.cpp b/src/style.cpp index 222155a0c..f0710e404 100644 --- a/src/style.cpp +++ b/src/style.cpp @@ -153,6 +153,10 @@ SPStyle::SPStyle(SPDocument *document_in, SPObject *object_in) : color_interpolation( "color-interpolation", enum_color_interpolation, SP_CSS_COLOR_INTERPOLATION_SRGB), color_interpolation_filters("color-interpolation-filters", enum_color_interpolation, SP_CSS_COLOR_INTERPOLATION_LINEARRGB), + // Solid color properties + solid_color( "solid-color" ), // SPIColor + solid_opacity( "solid-opacity", SP_SCALE24_MAX ), + // Fill properties fill( "fill" ), // SPIPaint fill_opacity( "fill-opacity", SP_SCALE24_MAX ), @@ -306,6 +310,9 @@ SPStyle::SPStyle(SPDocument *document_in, SPObject *object_in) : _properties.push_back( &color_interpolation ); _properties.push_back( &color_interpolation_filters ); + _properties.push_back( &solid_color ); + _properties.push_back( &solid_opacity ); + _properties.push_back( &fill ); _properties.push_back( &fill_opacity ); _properties.push_back( &fill_rule ); @@ -385,10 +392,14 @@ SPStyle::SPStyle(SPDocument *document_in, SPObject *object_in) : // _propmap.insert( std::make_pair( color_interpolation.name, reinterpret_cast<SPIBasePtr>(&SPStyle::color_interpolation ) ) ); // _propmap.insert( std::make_pair( color_interpolation_filters.name, reinterpret_cast<SPIBasePtr>(&SPStyle::color_interpolation_filters ) ) ); + // _propmap.insert( std::make_pair( solid_color.name, reinterpret_cast<SPIBasePtr>(&SPStyle::solid_color ) ) ); + // _propmap.insert( std::make_pair( solid_opacity.name, reinterpret_cast<SPIBasePtr>(&SPStyle::solid_opacity ) ) ); + // _propmap.insert( std::make_pair( fill.name, reinterpret_cast<SPIBasePtr>(&SPStyle::fill ) ) ); // _propmap.insert( std::make_pair( fill_opacity.name, reinterpret_cast<SPIBasePtr>(&SPStyle::fill_opacity ) ) ); // _propmap.insert( std::make_pair( fill_rule.name, reinterpret_cast<SPIBasePtr>(&SPStyle::fill_rule ) ) ); + // _propmap.insert( std::make_pair( stroke.name, reinterpret_cast<SPIBasePtr>(&SPStyle::stroke ) ) ); // _propmap.insert( std::make_pair( stroke_width.name, reinterpret_cast<SPIBasePtr>(&SPStyle::stroke_width ) ) ); // _propmap.insert( std::make_pair( stroke_linecap.name, reinterpret_cast<SPIBasePtr>(&SPStyle::stroke_linecap ) ) ); @@ -779,6 +790,12 @@ SPStyle::readIfUnset( gint id, gchar const *val ) { case SP_PROP_COLOR_RENDERING: color_rendering.readIfUnset( val ); break; + case SP_PROP_SOLID_COLOR: + solid_color.readIfUnset( val ); + break; + case SP_PROP_SOLID_OPACITY: + solid_opacity.readIfUnset( val ); + break; case SP_PROP_FILL: fill.readIfUnset( val ); break; @@ -1546,6 +1563,12 @@ sp_style_unset_property_attrs(SPObject *o) if (style->color_interpolation_filters.set) { repr->setAttribute("color-interpolation-filters", NULL); } + if (style->solid_color.set) { + repr->setAttribute("solid-color", NULL); + } + if (style->solid_opacity.set) { + repr->setAttribute("solid-opacity", NULL); + } if (style->fill.set) { repr->setAttribute("fill", NULL); } diff --git a/src/style.h b/src/style.h index 931dcc90e..eb8a3ed91 100644 --- a/src/style.h +++ b/src/style.h @@ -180,6 +180,11 @@ public: /** color-interpolation-filters */ SPIEnum color_interpolation_filters; + /** solid-color */ + SPIColor solid_color; + /** solid-opacity */ + SPIScale24 solid_opacity; + /** fill */ SPIPaint fill; /** fill-opacity */ |
