Inkscape
Vector Graphics Editor
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/svgz.h"
37#include "internal/wmf-inout.h"
38#include "internal/wmf-print.h"
39#include "system.h"
40
41#ifdef HAVE_POPPLER
43#endif
44#include <cairo.h>
45#ifdef CAIRO_HAS_PDF_SURFACE
47#endif
48#ifdef CAIRO_HAS_PS_SURFACE
50#endif
51#include "internal/png-output.h"
52#include "internal/pov-out.h"
53#include "internal/odf.h"
57#include "internal/bluredge.h"
58#include "internal/gimpgrad.h"
59#include "internal/grid.h"
60#ifdef WITH_LIBWPG
61#include "internal/wpg-input.h"
62#endif
63#ifdef WITH_LIBVISIO
64#include "internal/vsd-input.h"
65#endif
66#ifdef WITH_LIBCDR
67#include "internal/cdr-input.h"
68#endif
69#include "preferences.h"
70#include "io/resource.h"
71
72#ifdef WITH_MAGICK
73#include <Magick++.h>
106//#include "internal/bitmap/threshold.h"
108#include "internal/bitmap/wave.h"
109#endif /* WITH_MAGICK */
110
112
113#include "init.h"
114
115using namespace Inkscape::IO::Resource;
116
117namespace Inkscape {
118namespace Extension {
119
122#define SP_MODULE_EXTENSION "inx"
123
124static void check_extensions();
125
135static void
136update_pref(Glib::ustring const &pref_path,
137 gchar const *pref_default)
138{
139 Glib::ustring pref = Inkscape::Preferences::get()->getString(pref_path);
140 if (!Inkscape::Extension::db.get( pref.data() ) /*missing*/) {
141 Inkscape::Preferences::get()->setString(pref_path, pref_default);
142 }
143}
144
145// A list of user extensions loaded, used for refreshing
146static std::vector<std::string> user_extensions;
147static std::vector<std::string> shared_extensions;
148
155void
157{
158 /* TODO: Change to Internal */
161
168
169#ifdef CAIRO_HAS_PDF_SURFACE
171#endif
172#ifdef CAIRO_HAS_PS_SURFACE
175#endif
176#ifdef HAVE_POPPLER
178#endif
188#ifdef WITH_LIBWPG
190#endif
191#ifdef WITH_LIBVISIO
193#endif
194#ifdef WITH_LIBCDR
196#endif
197
198 /* Effects */
202
203 /* Raster Effects */
204#ifdef WITH_MAGICK
205 Magick::InitializeMagick(NULL);
206
239 //Internal::Bitmap::Threshold::init();
242#endif /* WITH_MAGICK */
243
245
246 // User extensions first so they can over-ride
249
250 for(auto &filename: get_filenames(SYSTEM, EXTENSIONS, {SP_MODULE_EXTENSION})) {
251 build_from_file(filename.c_str());
252 }
253
254 /* this is at the very end because it has several catch-alls
255 * that are possibly over-ridden by other extensions (such as
256 * svgz)
257 */
259
260 /* now we need to check and make sure everyone is happy */
262
263 /* This is a hack to deal with updating saved outdated module
264 * names in the prefs...
265 */
266 update_pref("/dialogs/save_as/default",
267 SP_MODULE_KEY_OUTPUT_SVG_INKSCAPE
268 // Inkscape::Extension::db.get_output_list()
269 );
270}
271
272// C++23: Just use std::ranges::contains().
273template <typename Range, typename Value>
274[[nodiscard]] static bool contains(Range &&range, Value const &value)
275{
276 using std::begin, std::end;
277 auto const first = begin(range), last = end(range);
278 return std::find(first, last, value) != last;
279}
280
281void
283{
284 // There's no need to ask for SYSTEM extensions, just ask for user extensions.
285 for (auto &&filename: get_filenames(USER, EXTENSIONS, {SP_MODULE_EXTENSION})) {
286 bool const exist = contains( user_extensions, filename) ||
287 contains(shared_extensions, filename);
288 if (!exist) {
289 build_from_file(filename.c_str());
290 user_extensions.push_back(std::move(filename));
291 }
292 }
293}
294
295void
297{
298 // There's no need to ask for SYSTEM extensions, just ask for user extensions.
299 for (auto &&filename: get_filenames(SHARED, EXTENSIONS, {SP_MODULE_EXTENSION})) {
300 bool const exist = contains(shared_extensions, filename) ||
301 contains( user_extensions, filename);
302 if (!exist) {
303 build_from_file(filename.c_str());
304 shared_extensions.push_back(std::move(filename));
305 }
306 }
307}
308
317void
319{
322}
323
324
325static void
326check_extensions_internal(Extension *in_plug, gpointer in_data)
327{
328 int *count = (int *)in_data;
329
330 if (in_plug == nullptr) return;
331 if (!in_plug->deactivated() && !in_plug->check()) {
332 in_plug->deactivate();
333 (*count)++;
334 }
335}
336
337static void check_extensions()
338{
339 int count = 1;
340
342 while (count != 0) {
343 count = 0;
344 db.foreach(check_extensions_internal, (gpointer)&count);
345 }
347}
348
349} } /* namespace Inkscape::Extension */
350
351
352/*
353 Local Variables:
354 mode:c++
355 c-file-style:"stroustrup"
356 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
357 indent-tabs-mode:nil
358 fill-column:99
359 End:
360*/
361// 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:130
static void error_file_open()
A function to open the error log file.
Definition: extension.cpp:908
static void error_file_close()
A function to close the error log file.
Definition: extension.cpp:919
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:2084
static void init()
Inkscape runtime startup call.
Definition: pov-out.cpp:705
static void init()
What would an SVG editor be without loading/saving SVG files. This function sets that up.
Definition: svg.cpp:70
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.
Definition: preferences.h:446
static Preferences * get()
Access the singleton Preferences object.
Definition: preferences.h:599
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:146
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:136
DB db
This is the actual database object.
Definition: db.cpp:32
static void check_extensions()
Definition: init.cpp:337
void load_shared_extensions()
Definition: init.cpp:296
void init()
Invokes the init routines for internal modules.
Definition: init.cpp:156
void refresh_user_extensions()
Refresh user extensions.
Definition: init.cpp:318
static void check_extensions_internal(Extension *in_plug, gpointer in_data)
Definition: init.cpp:326
static bool contains(Range &&range, Value const &value)
Definition: init.cpp:274
static std::vector< std::string > shared_extensions
Definition: init.cpp:147
void build_from_file(gchar const *filename)
This function creates a module from a filename of an XML description.
Definition: system.cpp:444
void load_user_extensions()
Definition: init.cpp:282
std::vector< std::string > get_filenames(Type type, std::vector< const char * > const &extensions, std::vector< const char * > const &exclusions)
Definition: resource.cpp:264
std::pair< gunichar, gunichar > Range
Definition: glyphs.cpp:205
static std::vector< T > range(int const steps, T start, T end)
CMYK to sRGB conversion routines.
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.