59 auto root = document->createElement(
"paint");
60 document->appendChild(
root);
62 if (std::holds_alternative<NoColor>(paint)) {
63 auto node = document->createElement(
"nocolor");
70 auto &color = std::get<Color>(paint);
71 auto space = color.getSpace();
76 auto node = document->createElement(
"color");
81 if (
auto cms = std::dynamic_pointer_cast<Space::CMS>(space)) {
82 if (
auto profile = cms->getProfile()) {
88 if (color.hasOpacity()) {
92 auto components = space->getComponents();
93 for (
unsigned int i = 0; i < components.size() && i < color.size(); i++) {
106 for (; iter; ++iter) {
107 if (iter->name() &&
name == iter->name()) {
114 if (
auto const paint = get_node(xml,
"paint")) {
115 if (get_node(paint,
"nocolor")) {
118 if (
auto color_xml = get_node(paint,
"color")) {
119 auto space_name = color_xml->attribute(
"space");
122 throw ColorError(
"Invalid color data, no space specified.");
130 if (
auto icc_id = color_xml->attribute(
"icc")) {
134 auto cms = std::make_shared<Space::CMS>(profile);
139 if (
auto cms = std::dynamic_pointer_cast<Space::CMS>(space)) {
141 if (cms->getProfile()->getId() != icc_id) {
142 g_warning(
"Mismatched icc profiles in color data: '%s'", space_name);
148 throw ColorError(
"No color space available.");
152 std::vector<double> values;
153 for (
auto &comp : space->getComponents()) {
154 values.emplace_back(color_xml->getAttributeDouble(comp.id));
156 auto color =
Color(space, values);
158 if (color_xml->attribute(
"opacity")) {
159 color.setOpacity(color_xml->getAttributeDouble(
"opacity"));
161 if (
auto name = color_xml->attribute(
"name")) {
std::shared_ptr< Space::CMS > getSpace(std::string const &name) const
Get the specific color space from the list of available spaces.
std::shared_ptr< Space::AnySpace > find(Space::Type type) const
Finds the first global color space matching the given type.
Interface for refcounted XML nodes.
virtual void appendChild(Node *child)=0
Append a node as the last child of this node.
void setAttributeOrRemoveIfEmpty(Inkscape::Util::const_char_ptr key, Inkscape::Util::const_char_ptr value)
Change an attribute of this node.
void setAttribute(Util::const_char_ptr key, Util::const_char_ptr value)
Change an attribute of this node.
virtual Node * firstChild()=0
Get the first child of this node.
bool setAttributeCssDouble(Util::const_char_ptr key, double val)
Set a property attribute to val [slightly rounded], in the format required for CSS properties: in par...
bool setAttributeSvgDouble(Util::const_char_ptr key, double val)
For attributes where an exponent is allowed.
Typed SVG document implementation.
Inkscape::Colors::DocumentCMS & getDocumentCMS()
Access operating system wide information about color management.
Inkscape::XML::Node * node
A set of useful color modifying functions which do not fit as generic methods on the color class itse...
std::variant< NoColor, Color > Paint
Paint xml_to_paint(XML::Document const *xml, SPDocument *doc)
XML::Document * paint_to_xml(Paint const &paint)
Paint xml_string_to_paint(std::string const &xmls, SPDocument *doc)
Parse an xml document into a color.
std::string paint_to_xml_string(Paint const &paint)
Turn a color into a color xml document, used for drag and drop.
static R & release(R &r)
Decrements the reference count of a anchored object.
Authors: see git history.
Document * sp_repr_read_buf(const Glib::ustring &buf, const gchar *default_ns)
Reads and parses XML from a buffer, returning it as an Document.
Glib::ustring sp_repr_save_buf(Document *doc)
C facade to Inkscape::XML::Node.
Inkscape::XML::SimpleDocument - generic XML document implementation.
Interface for XML documents.