// SPDX-License-Identifier: GPL-2.0-or-later /* * Factory for SPObject tree * * Authors: * Markus Engel * PBS * * Copyright (C) 2022 Authors * Released under GNU GPL v2+, read the file 'COPYING' for more information. */ #include "sp-factory.h" // primary #include "box3d.h" #include "box3d-side.h" #include "color-profile.h" #include "persp3d.h" #include "sp-anchor.h" #include "sp-clippath.h" #include "sp-defs.h" #include "sp-desc.h" #include "sp-ellipse.h" #include "sp-filter.h" #include "sp-flowdiv.h" #include "sp-flowregion.h" #include "sp-flowtext.h" #include "sp-font.h" #include "sp-font-face.h" #include "sp-glyph.h" #include "sp-glyph-kerning.h" #include "sp-grid.h" #include "sp-guide.h" #include "sp-hatch.h" #include "sp-hatch-path.h" #include "sp-image.h" #include "sp-line.h" #include "sp-linear-gradient.h" #include "sp-marker.h" #include "sp-mask.h" #include "sp-mesh-gradient.h" #include "sp-mesh-patch.h" #include "sp-mesh-row.h" #include "sp-metadata.h" #include "sp-missing-glyph.h" #include "sp-namedview.h" #include "sp-offset.h" #include "sp-page.h" #include "sp-path.h" #include "sp-pattern.h" #include "sp-polyline.h" #include "sp-radial-gradient.h" #include "sp-rect.h" #include "sp-root.h" #include "sp-script.h" #include "sp-solid-color.h" #include "sp-spiral.h" #include "sp-star.h" #include "sp-stop.h" #include "sp-string.h" #include "sp-style-elem.h" #include "sp-switch.h" #include "sp-symbol.h" #include "sp-tag.h" #include "sp-tag-use.h" #include "sp-text.h" #include "sp-textpath.h" #include "sp-title.h" #include "sp-tref.h" #include "sp-tspan.h" #include "sp-use.h" #include "live_effects/lpeobject.h" // filters #include "filters/blend.h" #include "filters/colormatrix.h" #include "filters/componenttransfer.h" #include "filters/componenttransfer-funcnode.h" #include "filters/composite.h" #include "filters/convolvematrix.h" #include "filters/diffuselighting.h" #include "filters/displacementmap.h" #include "filters/distantlight.h" #include "filters/flood.h" #include "filters/gaussian-blur.h" #include "filters/image.h" #include "filters/merge.h" #include "filters/mergenode.h" #include "filters/morphology.h" #include "filters/offset.h" #include "filters/pointlight.h" #include "filters/specularlighting.h" #include "filters/spotlight.h" #include "filters/tile.h" #include "filters/turbulence.h" #include namespace { class Factory { public: SPObject *create(std::string const &id) const { auto it = map.find(id); if (it == map.end()) { std::cerr << "WARNING: unknown type: " << id << std::endl; return nullptr; } return it->second(); } bool supportsId(std::string const &id) const { return map.find(id) != map.end(); } static Factory const &get() { static Factory const singleton; return singleton; } private: using Func = SPObject*(*)(); template static Func constexpr make = [] () -> SPObject* { return new T; }; static Func constexpr null = [] () -> SPObject* { return nullptr; }; std::unordered_map const map = { // primary { "inkscape:box3d", make }, { "inkscape:box3dside", make }, { "svg:color-profile", make }, { "inkscape:persp3d", make }, { "svg:a", make }, { "svg:clipPath", make }, { "svg:defs", make }, { "svg:desc", make }, { "svg:ellipse", [] () -> SPObject* { auto e = new SPGenericEllipse; e->type = SP_GENERIC_ELLIPSE_ELLIPSE; return e; }}, { "svg:circle", [] () -> SPObject* { auto c = new SPGenericEllipse; c->type = SP_GENERIC_ELLIPSE_CIRCLE; return c; }}, { "arc", [] () -> SPObject* { auto a = new SPGenericEllipse; a->type = SP_GENERIC_ELLIPSE_ARC; return a; }}, { "svg:filter", make }, { "svg:flowDiv", make }, { "svg:flowSpan", make }, { "svg:flowPara", make }, { "svg:flowLine", make }, { "svg:flowRegionBreak", make }, { "svg:flowRegion", make }, { "svg:flowRegionExclude", make }, { "svg:flowRoot", make }, { "svg:font", make }, { "svg:font-face", make }, { "svg:glyph", make }, { "svg:hkern", make }, { "svg:vkern", make }, { "sodipodi:guide", make }, { "inkscape:page", make }, { "svg:hatch", make }, { "svg:hatchpath", make }, { "svg:hatchPath", [] () -> SPObject* { std::cerr << "Warning: has been renamed " << std::endl; return new SPHatchPath; }}, { "svg:image", make }, { "svg:g", make }, { "svg:line", make }, { "svg:linearGradient", make }, { "svg:marker", make }, { "svg:mask", make }, { "svg:mesh", [] () -> SPObject* { // SVG 2 old std::cerr << "Warning: has been renamed ." << std::endl; std::cerr << "Warning: has been repurposed as a shape that tightly wraps a ." << std::endl; return new SPMeshGradient; }}, { "svg:meshGradient", [] () -> SPObject* { // SVG 2 old std::cerr << "Warning: has been renamed " << std::endl; return new SPMeshGradient; }}, { "svg:meshgradient", [] () -> SPObject* { // SVG 2 return new SPMeshGradient; }}, { "svg:meshPatch", [] () -> SPObject* { std::cerr << "Warning: and have been renamed and " << std::endl; return new SPMeshpatch; }}, { "svg:meshpatch", make }, { "svg:meshRow", make }, { "svg:meshrow", make }, { "svg:metadata", make }, { "svg:missing-glyph", make }, { "sodipodi:namedview", make }, { "inkscape:offset", make }, { "svg:path", make }, { "svg:pattern", make }, { "svg:polygon", make }, { "svg:polyline", make }, { "svg:radialGradient", make }, { "svg:rect", make }, { "rect", make }, // LPE rect; { "svg:svg", make }, { "svg:script", make }, { "svg:solidColor", [] () -> SPObject* { std::cerr << "Warning: has been renamed " << std::endl; return new SPSolidColor; }}, { "svg:solidColor", [] () -> SPObject* { std::cerr << "Warning: has been renamed " << std::endl; return new SPSolidColor; }}, { "svg:solidcolor", make }, { "spiral", make }, { "star", make }, { "svg:stop", make }, { "string", make }, { "svg:style", make }, { "svg:switch", make }, { "svg:symbol", make }, { "inkscape:tag", make }, { "inkscape:tagref", make }, { "svg:text", make }, { "svg:title", make }, { "svg:tref", make }, { "svg:tspan", make }, { "svg:textPath", make }, { "svg:use", make }, { "inkscape:path-effect", make }, // filters { "svg:feBlend", make }, { "svg:feColorMatrix", make }, { "svg:feComponentTransfer", make }, { "svg:feFuncR", [] () -> SPObject* { return new SPFeFuncNode(SPFeFuncNode::R); }}, { "svg:feFuncG", [] () -> SPObject* { return new SPFeFuncNode(SPFeFuncNode::G); }}, { "svg:feFuncB", [] () -> SPObject* { return new SPFeFuncNode(SPFeFuncNode::B); }}, { "svg:feFuncA", [] () -> SPObject* { return new SPFeFuncNode(SPFeFuncNode::A); }}, { "svg:feComposite", make }, { "svg:feConvolveMatrix", make }, { "svg:feDiffuseLighting", make }, { "svg:feDisplacementMap", make }, { "svg:feDistantLight", make }, { "svg:feFlood", make }, { "svg:feGaussianBlur", make }, { "svg:feImage", make }, { "svg:feMerge", make }, { "svg:feMergeNode", make }, { "svg:feMorphology", make }, { "svg:feOffset", make }, { "svg:fePointLight", make }, { "svg:feSpecularLighting", make }, { "svg:feSpotLight", make }, { "svg:feTile", make }, { "svg:feTurbulence", make }, { "inkscape:grid", make }, // ignore { "rdf:RDF", null }, // no SP node yet { "inkscape:clipboard", null }, // SP node not necessary { "inkscape:templateinfo", null }, // metadata for templates { "inkscape:_templateinfo", null }, // metadata for templates { "", null } // comments }; }; } // namespace SPObject *SPFactory::createObject(std::string const &id) { return Factory::get().create(id); } bool SPFactory::supportsType(std::string const &id) { return Factory::get().supportsId(id); } std::string NodeTraits::get_type_string(Inkscape::XML::Node const &node) { switch (node.type()) { case Inkscape::XML::NodeType::TEXT_NODE: return "string"; case Inkscape::XML::NodeType::ELEMENT_NODE: if (auto sptype = node.attribute("sodipodi:type")) { return sptype; } return node.name(); default: return ""; } } /* 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 :