diff options
| author | Tavmjong Bah <tavmjong@free.fr> | 2017-10-25 11:53:33 +0000 |
|---|---|---|
| committer | Tavmjong Bah <tavmjong@free.fr> | 2017-10-25 11:53:33 +0000 |
| commit | fd52c97cdbf621ea9e869611be4d5fb9bec90ff7 (patch) | |
| tree | 1477a90b80837fffbb956258b89d4096106b8ee5 /src | |
| parent | Give drawing a reasonable(?) default size if dimensions are in % and there is... (diff) | |
| download | inkscape-fd52c97cdbf621ea9e869611be4d5fb9bec90ff7.tar.gz inkscape-fd52c97cdbf621ea9e869611be4d5fb9bec90ff7.zip | |
Add limited support for CSS 'font-face' rule.
Basically, any ttf or otf file found will be loaded but no custom matching is
done nor is the 'font-family' menu updated.
Diffstat (limited to 'src')
| -rw-r--r-- | src/libnrtype/FontFactory.cpp | 32 | ||||
| -rw-r--r-- | src/libnrtype/FontFactory.h | 3 | ||||
| -rw-r--r-- | src/sp-style-elem.cpp | 54 |
3 files changed, 88 insertions, 1 deletions
diff --git a/src/libnrtype/FontFactory.cpp b/src/libnrtype/FontFactory.cpp index 95537734d..2b1087eec 100644 --- a/src/libnrtype/FontFactory.cpp +++ b/src/libnrtype/FontFactory.cpp @@ -949,6 +949,38 @@ void font_factory::AddFontsDir(char const *utf8dir) #endif } +void font_factory::AddFontFile(char const *utf8file) +{ +#ifdef USE_PANGO_WIN32 + g_info("Adding additional font only supported for fontconfig backend."); +#else + if (!Inkscape::IO::file_test(utf8file, G_FILE_TEST_IS_REGULAR)) { + g_warning("Font file '%s' does not exist and will be ignored.", utf8file); + return; + } + + gchar *file; +# ifdef WIN32 + file = g_win32_locale_filename_from_utf8(utf8file); +# else + file = g_filename_from_utf8(utf8file, -1, NULL, NULL, NULL); +# endif + + FcConfig *conf = NULL; +# if PANGO_VERSION_CHECK(1,38,0) + pango_fc_font_map_get_config(PANGO_FC_FONT_MAP(fontServer)); +# endif + FcBool res = FcConfigAppFontAddFile(conf, (FcChar8 const *)file); + if (res = FcTrue) { + g_info("Font file '%s' added successfully.", utf8file); + } else { + g_warning("Could not add font file '%s'.", utf8file); + } + + g_free(file); +#endif +} + /* Local Variables: mode:c++ diff --git a/src/libnrtype/FontFactory.h b/src/libnrtype/FontFactory.h index c273be2f4..12260f99a 100644 --- a/src/libnrtype/FontFactory.h +++ b/src/libnrtype/FontFactory.h @@ -139,6 +139,9 @@ public: /// Add a directory from which to include additional fonts void AddFontsDir(char const *utf8dir); + /// Add a an additional font. + void AddFontFile(char const *utf8file); + private: void* loadedPtr; diff --git a/src/sp-style-elem.cpp b/src/sp-style-elem.cpp index 2deaccad0..da02d4ef1 100644 --- a/src/sp-style-elem.cpp +++ b/src/sp-style-elem.cpp @@ -12,6 +12,9 @@ #include <iostream> #include <fstream> +// For font-rule +#include "libnrtype/FontFactory.h" + using Inkscape::XML::TEXT_NODE; SPStyleElem::SPStyleElem() : SPObject() { @@ -308,12 +311,61 @@ end_font_face_cb(CRDocHandler *a_handler) unsigned(font_face_rule->type)); } - std::cout << "end_font_face_cb: font face rule unsupported." << std::endl; + std::cout << "end_font_face_cb: font face rule limited support." << std::endl; cr_declaration_dump (font_face_rule->kind.font_face_rule->decl_list, stdout, 2, TRUE); printf ("\n"); + // Get document + SPDocument* document = parse_tmp.document; + if (!document) { + std::cerr << "end_font_face_cb: No document!" << std::endl; + return; + } + if (!document->getURI()) { + std::cerr << "end_font_face_cb: Document URI is NULL" << std::endl; + return; + } + + // Add ttf or otf fonts. + CRDeclaration const *cur = NULL; + for (cur = font_face_rule->kind.font_face_rule->decl_list; cur; cur = cur->next) { + if (cur->property && + cur->property->stryng && + cur->property->stryng->str && + strcmp(cur->property->stryng->str, "src") == 0 ) { + + if (cur->value && + cur->value->content.str && + cur->value->content.str->stryng && + cur->value->content.str->stryng->str) { + + Glib::ustring value = cur->value->content.str->stryng->str; + std::size_t found = value.find_last_of("ttf"); + + if (value.rfind("ttf") == (value.length() - 3) || + value.rfind("otf") == (value.length() - 3)) { + + // Get file + Glib::ustring ttf_file = + Inkscape::IO::Resource::get_filename (document->getURI(), value); + + if (!ttf_file.empty()) { + font_factory *factory = font_factory::Default(); + factory->AddFontFile( ttf_file.c_str() ); + std::cout << "end_font_face_cb: Added font: " << ttf_file << std::endl; + + // FIX ME: Need to refresh font list. + } else { + std::cout << "end_font_face_cb: Failed to add: " << value << std::endl; + } + } + } + } + } + parse_tmp.currStmt = NULL; parse_tmp.stmtType = NO_STMT; + } static void |
