Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
init.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * This is what gets executed to initialize all of the modules. For
4 * the internal modules this involves executing their initialization
5 * functions, for external ones it involves reading their .spmodule
6 * files and bringing them into Sodipodi.
7 *
8 * Authors:
9 * Ted Gould <ted@gould.cx>
10 *
11 * Copyright (C) 2002-2004 Authors
12 *
13 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
14 */
15
16#ifdef HAVE_CONFIG_H
17# include "config.h" // only include where actually required!
18#endif
19
20#include <algorithm>
21#include <iterator>
22#include <utility>
23#include <glibmm/fileutils.h>
24#include <glibmm/i18n.h>
25#include <glibmm/ustring.h>
26
27#include "db.h"
28#include "internal/emf-inout.h"
29#include "internal/emf-print.h"
30#include "internal/gif.h"
31#include "internal/svgz.h"
38#include "internal/wmf-inout.h"
39#include "internal/wmf-print.h"
40#include "system.h"
41
42#ifdef WITH_POPPLER
44#endif
45#ifdef WITH_CAPYPDF
47#endif
48#include <cairo.h>
49#ifdef CAIRO_HAS_PDF_SURFACE
51#endif
52#ifdef CAIRO_HAS_PS_SURFACE
54#endif
55#include "internal/png-output.h"
56#include "internal/pov-out.h"
57#include "internal/odf.h"
61#include "internal/bluredge.h"
62#include "internal/gimpgrad.h"
63#include "internal/grid.h"
64#ifdef WITH_LIBWPG
65#include "internal/wpg-input.h"
66#endif
67#ifdef WITH_LIBVISIO
68#include "internal/vsd-input.h"
69#endif
70#ifdef WITH_LIBCDR
71#include "internal/cdr-input.h"
72#endif
73#include "preferences.h"
74#include "io/resource.h"
75
76#ifdef WITH_MAGICK
77#include <Magick++.h>
110//#include "internal/bitmap/threshold.h"
112#include "internal/bitmap/wave.h"
113#endif /* WITH_MAGICK */
114
116
117#include "init.h"
118
119using namespace Inkscape::IO::Resource;
120
121namespace Inkscape {
122namespace Extension {
123
126#define SP_MODULE_EXTENSION "inx"
127
128static void check_extensions();
129
139static void
140update_pref(Glib::ustring const &pref_path,
141 gchar const *pref_default)
142{
143 Glib::ustring pref = Inkscape::Preferences::get()->getString(pref_path);
144 if (!Inkscape::Extension::db.get( pref.data() ) /*missing*/) {
145 Inkscape::Preferences::get()->setString(pref_path, pref_default);
146 }
147}
148
149// A list of user extensions loaded, used for refreshing
150static std::vector<std::string> user_extensions;
151static std::vector<std::string> shared_extensions;
152
159void
161{
162 /* TODO: Change to Internal */
165
172
173#ifdef WITH_CAPYPDF
175#endif
176#ifdef CAIRO_HAS_PDF_SURFACE
178#endif
179#ifdef CAIRO_HAS_PS_SURFACE
182#endif
183#ifdef WITH_POPPLER
185#endif
195#ifdef WITH_LIBWPG
197#endif
198#ifdef WITH_LIBVISIO
200#endif
201#ifdef WITH_LIBCDR
203#endif
205
206 /* Effects */
210
211 /* Raster Effects */
212#ifdef WITH_MAGICK
213 Magick::InitializeMagick(NULL);
214
247 //Internal::Bitmap::Threshold::init();
250#endif /* WITH_MAGICK */
251
253
254 // User extensions first so they can over-ride
257
258 for(auto &filename: get_filenames(SYSTEM, EXTENSIONS, {SP_MODULE_EXTENSION})) {
259 build_from_file(filename.c_str());
260 }
261
262 /* this is at the very end because it has several catch-alls
263 * that are possibly over-ridden by other extensions (such as
264 * svgz)
265 */
267
268 /* now we need to check and make sure everyone is happy */
270
271 /* This is a hack to deal with updating saved outdated module
272 * names in the prefs...
273 */
274 update_pref("/dialogs/save_as/default",
275 SP_MODULE_KEY_OUTPUT_SVG_INKSCAPE
276 // Inkscape::Extension::db.get_output_list()
277 );
278}
279
280// C++23: Just use std::ranges::contains().
281template <typename Range, typename Value>
282[[nodiscard]] static bool contains(Range &&range, Value const &value)
283{
284 using std::begin, std::end;
285 auto const first = begin(range), last = end(range);
286 return std::find(first, last, value) != last;
287}
288
289void
291{
292 // There's no need to ask for SYSTEM extensions, just ask for user extensions.
293 for (auto &&filename: get_filenames(USER, EXTENSIONS, {SP_MODULE_EXTENSION})) {
294 bool const exist = contains( user_extensions, filename) ||
295 contains(shared_extensions, filename);
296 if (!exist) {
297 build_from_file(filename.c_str());
298 user_extensions.push_back(std::move(filename));
299 }
300 }
301}
302
303void
305{
306 // There's no need to ask for SYSTEM extensions, just ask for user extensions.
307 for (auto &&filename: get_filenames(SHARED, EXTENSIONS, {SP_MODULE_EXTENSION})) {
308 bool const exist = contains(shared_extensions, filename) ||
309 contains( user_extensions, filename);
310 if (!exist) {
311 build_from_file(filename.c_str());
312 shared_extensions.push_back(std::move(filename));
313 }
314 }
315}
316
325void
331
332
333static void
334check_extensions_internal(Extension *in_plug, gpointer in_data)
335{
336 int *count = (int *)in_data;
337
338 if (in_plug == nullptr) return;
339 if (!in_plug->deactivated() && !in_plug->check()) {
340 in_plug->deactivate();
341 (*count)++;
342 }
343}
344
345static void check_extensions()
346{
347 int count = 1;
348
350 while (count != 0) {
351 count = 0;
352 db.foreach(check_extensions_internal, (gpointer)&count);
353 }
355}
356
357} } /* namespace Inkscape::Extension */
358
359
360/*
361 Local Variables:
362 mode:c++
363 c-file-style:"stroustrup"
364 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
365 indent-tabs-mode:nil
366 fill-column:99
367 End:
368*/
369// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
This code abstracts the libwpg interfaces into the Inkscape input extension interface.
void foreach(void(*in_func)(Extension *in_plug, gpointer in_data), gpointer in_data)
A function to execute another function with every entry in the database as a parameter.
Definition db.cpp:128
The object that is the basis for the Extension system.
Definition extension.h:133
static void error_file_open()
A function to open the error log file.
static void error_file_close()
A function to close the error log file.
static void init()
A function allocate a copy of this function.
static void init()
A function allocate a copy of this function.
static void init()
A function allocate a copy of this function.
static void init()
A function allocate a copy of this function.
static void init()
This is the definition of PovRay output.
Definition odf.cpp:2083
static void init()
Inkscape runtime startup call.
Definition pov-out.cpp:697
static void init()
What would an SVG editor be without loading/saving SVG files. This function sets that up.
Definition svg.cpp:59
static void init()
What would an SVG editor be without loading/saving SVG files. This function sets that up.
Definition svgz.cpp:39
Glib::ustring getString(Glib::ustring const &pref_path, Glib::ustring const &def="")
Retrieve an UTF-8 string.
static Preferences * get()
Access the singleton Preferences object.
void setString(Glib::ustring const &pref_path, Glib::ustring const &value)
Set an UTF-8 string value.
Enhanced Metafile Input/Output.
Enhanced Metafile printing - implementation.
TODO: insert short description here.
Geom::Point end
static std::vector< std::string > user_extensions
Definition init.cpp:150
static void update_pref(Glib::ustring const &pref_path, gchar const *pref_default)
Examines the given string preference and checks to see that at least one of the registered extensions...
Definition init.cpp:140
DB db
This is the actual database object.
Definition db.cpp:32
static void check_extensions()
Definition init.cpp:345
void load_shared_extensions()
Definition init.cpp:304
void init()
Invokes the init routines for internal modules.
Definition init.cpp:160
void refresh_user_extensions()
Refresh user extensions.
Definition init.cpp:326
static void check_extensions_internal(Extension *in_plug, gpointer in_data)
Definition init.cpp:334
static bool contains(Range &&range, Value const &value)
Definition init.cpp:282
static std::vector< std::string > shared_extensions
Definition init.cpp:151
void build_from_file(gchar const *filename)
This function creates a module from a filename of an XML description.
Definition system.cpp:432
void load_user_extensions()
Definition init.cpp:290
std::vector< std::string > get_filenames(Type type, std::vector< const char * > const &extensions, std::vector< const char * > const &exclusions)
Definition resource.cpp:267
Helper class to stream background task notifications as a series of messages.
OpenDocument (drawing) input and output.
Singleton class to access the preferences file in a convenient way.
Inkscape::IO::Resource - simple resource API.
This code abstracts the libwpg interfaces into the Inkscape input extension interface.
Windows Metafile Input/Output.
Windows Metafile printing - implementation.