2626
2727#include " FontCache.h"
2828
29+ #include < cassert>
30+ #include < cstdlib>
2931#include < cstdint>
32+ #include < ctime>
33+ #include < filesystem>
3034#include < iostream>
35+ #include < string>
36+ #include < utility>
3137#include < vector>
3238
33- #include < filesystem>
3439#include < boost/algorithm/string.hpp>
35- #include < string>
36- #include < utility>
40+ #include < hb.h>
41+ #include < fontconfig/fontconfig.h>
42+ #include < ft2build.h>
43+ #include FT_FREETYPE_H
44+ #include FT_TYPES_H
45+ #include FT_TRUETYPE_IDS_H
3746
3847#include " platform/PlatformUtils.h"
3948#include " utils/printutils.h"
4049#include " utils/version_helper.h"
4150
4251extern std::vector<std::string> librarypath;
43-
4452std::vector<std::string> fontpath;
4553
4654namespace fs = std::filesystem;
4755
48- const std::string get_fontconfig_version ()
56+ std::string get_fontconfig_version ()
4957{
5058 const unsigned int version = FcGetVersion ();
5159
@@ -54,7 +62,7 @@ const std::string get_fontconfig_version()
5462 return OpenSCAD::get_version_string (header_version, runtime_version);
5563}
5664
57- const std::string get_harfbuzz_version ()
65+ std::string get_harfbuzz_version ()
5866{
5967 unsigned int major, minor, micro;
6068 hb_version (&major, &minor, µ);
@@ -64,7 +72,7 @@ const std::string get_harfbuzz_version()
6472 return OpenSCAD::get_version_string (header_version, runtime_version);
6573}
6674
67- const std::string get_freetype_version ()
75+ std::string get_freetype_version ()
6876{
6977 return FontCache::instance ()->get_freetype_version ();
7078}
@@ -128,7 +136,7 @@ FontCache::FontCache()
128136 // If we've got a bundled fonts.conf, initialize fontconfig with our own config
129137 // by overriding the built-in fontconfig path.
130138 // For system installs and dev environments, we leave this alone
131- fs::path fontdir (PlatformUtils::resourcePath (" fonts" ));
139+ const fs::path fontdir (PlatformUtils::resourcePath (" fonts" ));
132140 if (fs::is_regular_file (fontdir / " fonts.conf" )) {
133141 auto abspath = fontdir.empty () ? fs::current_path () : fs::absolute (fontdir);
134142 PlatformUtils::setenv (" FONTCONFIG_PATH" , (abspath.generic_string ()).c_str (), 0 );
@@ -167,7 +175,7 @@ FontCache::FontCache()
167175 for (string_split_iterator it = boost::make_split_iterator (paths, boost::first_finder (sep, boost::is_iequal ())); it != string_split_iterator (); ++it) {
168176 const fs::path p (boost::copy_range<std::string>(*it));
169177 if (fs::exists (p) && fs::is_directory (p)) {
170- std::string path = fs::absolute (p).string ();
178+ const std::string path = fs::absolute (p).string ();
171179 add_font_dir (path);
172180 }
173181 }
@@ -243,7 +251,7 @@ std::vector<uint32_t> FontCache::filter(const std::u32string& str) const
243251 FcPattern *pattern = FcPatternCreate ();
244252 init_pattern (pattern);
245253 FcCharSet *charSet = FcCharSetCreate ();
246- for (char32_t a : str) {
254+ for (const char32_t a : str) {
247255 FcCharSetAddChar (charSet, a);
248256 }
249257 FcValue charSetValue;
@@ -287,11 +295,11 @@ FontInfoList *FontCache::list_fonts() const
287295 FcValue style_value;
288296 FcPatternGet (p, FC_STYLE, 0 , &style_value);
289297
290- std::string family ((const char *) family_value.u .s );
291- std::string style ((const char *) style_value.u .s );
292- std::string file ((const char *) file_value.u .s );
298+ const std::string family ((const char *) family_value.u .s );
299+ const std::string style ((const char *) style_value.u .s );
300+ const std::string file ((const char *) file_value.u .s );
293301
294- list->push_back ( FontInfo ( family, style, file, FcPatternHash (p) ));
302+ list->emplace_back ( family, style, file, FcPatternHash (p));
295303 }
296304 FcFontSetDestroy (font_set);
297305
@@ -405,7 +413,7 @@ FT_Face FontCache::find_face_fontconfig(const std::string& font) const
405413 }
406414
407415 FT_Face face;
408- FT_Error error = FT_New_Face (this ->library , (const char *) file_value.u .s , font_index.u .i , &face);
416+ const FT_Error error = FT_New_Face (this ->library , (const char *) file_value.u .s , font_index.u .i , &face);
409417
410418 FcPatternDestroy (pattern);
411419 FcPatternDestroy (match);
@@ -460,7 +468,7 @@ bool FontCache::is_windows_symbol_font(const FT_Face& face) const
460468 }
461469
462470 FT_UInt gindex;
463- FT_ULong charcode = FT_Get_First_Char (face, &gindex);
471+ const FT_ULong charcode = FT_Get_First_Char (face, &gindex);
464472 if ((gindex == 0 ) || (charcode < 0xf000 )) {
465473 return false ;
466474 }
0 commit comments