diff options
| author | Eduard Braun <eduard.braun2@gmx.de> | 2017-10-19 21:41:25 +0000 |
|---|---|---|
| committer | Eduard Braun <eduard.braun2@gmx.de> | 2017-10-20 21:23:55 +0000 |
| commit | d6c5424f69aeb91cf1cfeba262b5466a42dd95a5 (patch) | |
| tree | b74ee32b4919cd1cfbedfd87d55e5c25595ce7e3 /src/libnrtype | |
| parent | Merge branch 'smartpointer_refactor' of gitlab.com:jali/inkscape (diff) | |
| download | inkscape-d6c5424f69aeb91cf1cfeba262b5466a42dd95a5.tar.gz inkscape-d6c5424f69aeb91cf1cfeba262b5466a42dd95a5.zip | |
FontFactory: Add function to add additional font directories
Diffstat (limited to 'src/libnrtype')
| -rw-r--r-- | src/libnrtype/FontFactory.cpp | 32 | ||||
| -rw-r--r-- | src/libnrtype/FontFactory.h | 3 |
2 files changed, 35 insertions, 0 deletions
diff --git a/src/libnrtype/FontFactory.cpp b/src/libnrtype/FontFactory.cpp index bf4cbc56f..677b8abe7 100644 --- a/src/libnrtype/FontFactory.cpp +++ b/src/libnrtype/FontFactory.cpp @@ -17,8 +17,11 @@ #endif #include <glibmm/i18n.h> +#include <fontconfig/fontconfig.h> +#include <pango/pangofc-fontmap.h> #include <pango/pangoft2.h> #include <pango/pango-ot.h> +#include "io/sys.h" #include "libnrtype/FontFactory.h" #include "libnrtype/font-instance.h" #include "util/unordered-containers.h" @@ -914,6 +917,35 @@ void font_factory::AddInCache(font_instance *who) nbEnt++; } +void font_factory::AddFontsDir(char const *utf8dir) +{ +#ifdef USE_PANGO_WIN32 + g_info("Adding additional font directories only supported for fontconfig backend."); +#else + if (!Inkscape::IO::file_test(utf8dir, G_FILE_TEST_IS_DIR)) { + g_warning("Fonts dir '%s' does not exist and will be ignored.", utf8dir); + return; + } + + gchar *dir; +# ifdef WIN32 + dir = g_win32_locale_filename_from_utf8(utf8dir); +# else + dir = g_filename_from_utf8(utf8dir, -1, NULL, NULL, NULL); +# endif + + FcConfig *conf = pango_fc_font_map_get_config(PANGO_FC_FONT_MAP(fontServer)); + FcBool res = FcConfigAppFontAddDir(conf, (FcChar8 const *)dir); + if (res = FcTrue) { + g_info("Fonts dir '%s' added successfully.", utf8dir); + } else { + g_warning("Could not add fonts dir '%s'.", utf8dir); + } + + g_free(dir); +#endif +} + /* Local Variables: mode:c++ diff --git a/src/libnrtype/FontFactory.h b/src/libnrtype/FontFactory.h index 41c4cb6eb..c273be2f4 100644 --- a/src/libnrtype/FontFactory.h +++ b/src/libnrtype/FontFactory.h @@ -136,6 +136,9 @@ public: // internal void AddInCache(font_instance *who); + /// Add a directory from which to include additional fonts + void AddFontsDir(char const *utf8dir); + private: void* loadedPtr; |
