21#include <glibmm/fileutils.h>
37 auto files = get_filenames(SYSTEM, PAINT, {
".svg"});
38 auto share = get_filenames(SHARED, PAINT, {
".svg"});
39 auto user = get_filenames(USER, PAINT, {
".svg"});
40 files.insert(files.end(), user.begin(), user.end());
41 files.insert(files.end(), share.begin(), share.end());
42 for (
auto const &file : files) {
43 if (Glib::file_test(file, Glib::FileTest::IS_REGULAR)) {
45 doc->ensureUpToDate();
48 g_warning(
"File %s not loaded.", file.c_str());
56 std::vector<SPDocument *> out;
59 if (filter(doc.get())) {
60 out.push_back(doc.get());
71 for (
Domain const domain : {SYSTEM, CREATE}) {
72 auto const filename = get_path_string(domain, type, basename);
73 if (Glib::file_test(filename, Glib::FileTest::IS_REGULAR)) {
75 doc->ensureUpToDate();
103 if (!is<SPMarker>(obj)) {
107 auto defs = current_doc->
getDefs();
109 auto repr = obj->getRepr()->
duplicate(xml_doc);
110 defs->getRepr()->
addChild(repr,
nullptr);
118 if (!current_doc || !source_doc) {
143 if (!is<SPGradient>(obj)) {
147 auto defs = current_doc->
getDefs();
149 auto repr = obj->getRepr()->
duplicate(xml_doc);
150 defs->getRepr()->
addChild(repr,
nullptr);
163 g_assert(urn !=
nullptr);
166 if (!strncmp (urn,
"urn:inkscape:", 13)) {
168 gchar
const *e = urn + 13;
170 gchar *
name = g_strdup(e);
171 gchar *name_p =
name;
172 while (*name_p !=
':' && *name_p !=
'\0'){
181 gchar * base = g_strndup(e, a);
190 if (!strcmp(base,
"marker") && !stock) {
193 if (
child.getRepr()->attribute(
"inkscape:stockid") &&
194 !strcmp(name_p,
child.getRepr()->attribute(
"inkscape:stockid")) &&
195 is<SPMarker>(&
child))
201 else if (!strcmp(base,
"pattern") && !stock) {
204 if (
child.getRepr()->attribute(
"inkscape:stockid") &&
205 !strcmp(name_p,
child.getRepr()->attribute(
"inkscape:stockid")) &&
206 is<SPPattern>(&
child))
212 else if (!strcmp(base,
"gradient") && !stock) {
215 if (
child.getRepr()->attribute(
"inkscape:stockid") &&
216 !strcmp(name_p,
child.getRepr()->attribute(
"inkscape:stockid")) &&
217 is<SPGradient>(&
child))
224 if (
object ==
nullptr) {
226 if (!strcmp(base,
"marker")) {
229 else if (!strcmp(base,
"pattern")) {
232 object->getRepr()->setAttribute(
"inkscape:collect",
"always");
235 else if (!strcmp(base,
"gradient")) {
244 object->setAttribute(
"inkscape:isstock",
"true");
virtual void addChild(Node *child, Node *after)=0
Insert another node as a child of this node.
Typed SVG document implementation.
SPObject * getObjectById(std::string const &id) const
SPDefs * getDefs()
Return the main defs object for the document.
static std::unique_ptr< SPDocument > createNewDoc(char const *filename, bool keepalive, bool make_new=false, SPDocument *parent=nullptr)
Fetches document from filename, or creates new, if NULL; public document appears in document list.
Inkscape::XML::Document * getReprDoc()
Our Inkscape::XML::Document.
SPObject * getObjectByRepr(Inkscape::XML::Node *repr) const
SPObject is an abstract base class of all of the document nodes at the SVG document level.
std::vector< SPDocument * > get_paint_documents(std::function< bool(SPDocument *)> const &filter)
std::vector< std::unique_ptr< SPDocument > > documents
SPObject * sp_copy_resource(const SPObject *source, SPDocument *dest_document)
Copy source resource form one document into another destination document.
static R & release(R &r)
Decrements the reference count of a anchored object.
SPDocument * cache_static_doc(F &&f)
Wrapper for a static SPDocument to ensure it is destroyed early enough.
Inkscape::IO::Resource - simple resource API.
SVG <pattern> implementation.
static SPObject * sp_marker_load_from_svg(char const *name, SPDocument *current_doc)
static SPObject * sp_gradient_load_from_svg(char const *name, SPDocument *current_doc)
SPObject * get_stock_item(gchar const *urn, bool stock, SPDocument *stock_doc)
static SPObject * sp_pattern_load_from_svg(gchar const *name, SPDocument *current_doc, SPDocument *source_doc)
static std::unique_ptr< SPDocument > load_paint_doc(char const *basename, Inkscape::IO::Resource::Type type=Inkscape::IO::Resource::PAINT)
TODO: insert short description here.
Document * duplicate(Document *doc) const override=0
Create a duplicate of this node.