From 1aef9f275857a1b5942d8b2cbdc077df6b5942fb Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Wed, 17 Dec 2014 12:12:53 -0500 Subject: [PATCH] #1065 Show progress dialog while building font cache --- src/FontCache.cc | 13 ++++++++++++- src/FontCache.h | 6 ++++++ src/Polygon2d-CGAL.cc | 1 + src/openscad.cc | 21 +++++++++++++++++++++ 4 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/FontCache.cc b/src/FontCache.cc index 29599e32..c4b9a9dc 100644 --- a/src/FontCache.cc +++ b/src/FontCache.cc @@ -81,6 +81,9 @@ const std::string &FontInfo::get_file() const } FontCache * FontCache::self = NULL; +FontCache::ProgressHandlerFunc *FontCache::start_cb = NULL; +FontCache::ProgressHandlerFunc *FontCache::end_cb = NULL; +void *FontCache::cb_userdata = NULL; const std::string FontCache::DEFAULT_FONT("XXX"); FontCache::FontCache() @@ -131,8 +134,9 @@ FontCache::FontCache() } } - // FIXME: Caching happens here. This would be a good place to notify the user + if (FontCache::start_cb) FontCache::start_cb(FontCache::cb_userdata); FcConfigBuildFonts(this->config); + if (FontCache::end_cb) FontCache::end_cb(FontCache::cb_userdata); // For use by LibraryInfo FcStrList *dirs = FcConfigGetFontDirs(this->config); @@ -162,6 +166,13 @@ FontCache * FontCache::instance() return self; } +void FontCache::registerProgressHandler(ProgressHandlerFunc *start, ProgressHandlerFunc *end, void *userdata) +{ + FontCache::start_cb = start; + FontCache::end_cb = end; + FontCache::cb_userdata = userdata; +} + void FontCache::register_font_file(const std::string &path) { if (!FcConfigAppFontAddFile(this->config, reinterpret_cast (path.c_str()))) { diff --git a/src/FontCache.h b/src/FontCache.h index 2633c04d..e8dd318a 100644 --- a/src/FontCache.h +++ b/src/FontCache.h @@ -75,11 +75,17 @@ public: FontInfoList *list_fonts() const; static FontCache *instance(); + + typedef void (ProgressHandlerFunc)(void *userdata); + static void registerProgressHandler(ProgressHandlerFunc *start, ProgressHandlerFunc *end, void *userdata = NULL); private: typedef std::pair cache_entry_t; typedef std::map cache_t; static FontCache *self; + static ProgressHandlerFunc *start_cb; + static ProgressHandlerFunc *end_cb; + static void *cb_userdata; bool init_ok; cache_t cache; diff --git a/src/Polygon2d-CGAL.cc b/src/Polygon2d-CGAL.cc index cd322d99..b6f2f663 100644 --- a/src/Polygon2d-CGAL.cc +++ b/src/Polygon2d-CGAL.cc @@ -105,6 +105,7 @@ mark_domains(CDT &cdt) */ PolySet *Polygon2d::tessellate() const { + PRINTDB("Polygon2d::tessellate(): %d outlines", this->outlines().size()); PolySet *polyset = new PolySet(*this); Polygon2DCGAL::CDT cdt; // Uses a constrained Delaunay triangulator. diff --git a/src/openscad.cc b/src/openscad.cc index 54349f7f..621ea7b1 100644 --- a/src/openscad.cc +++ b/src/openscad.cc @@ -41,6 +41,7 @@ #include "nodedumper.h" #include "stackcheck.h" #include "CocoaUtils.h" +#include "FontCache.h" #include #include @@ -577,6 +578,22 @@ bool QtUseGUI() return useGUI; } + +#include +QProgressDialog *fontCacheProgress = NULL; + +void fontCacheStart(void *userdata) +{ + fontCacheProgress = new QProgressDialog("Fontconfig needs to update its font cache.\nThis can take up to a couple of minutes.", QString(), 0, 0); + fontCacheProgress->show(); +} + +void fontCacheEnd(void *userdata) +{ + delete fontCacheProgress; + fontCacheProgress = NULL; +} + int gui(vector &inputFiles, const fs::path &original_path, int argc, char ** argv) { #ifdef Q_OS_MACX @@ -607,6 +624,10 @@ int gui(vector &inputFiles, const fs::path &original_path, int argc, cha const QString &app_path = app.applicationDirPath(); PlatformUtils::registerApplicationPath(app_path.toLocal8Bit().constData()); + FontCache::registerProgressHandler(fontCacheStart, fontCacheEnd); + + + parser_init(); QSettings settings;