mirror of https://github.com/vitalif/openscad
Set default font and add loading of additional fontconfig config file.
parent
cac3de5461
commit
ffeae16728
|
@ -0,0 +1,22 @@
|
|||
<?xml version="1.0"?>
|
||||
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
|
||||
<fontconfig>
|
||||
<alias>
|
||||
<family>sans-serif</family>
|
||||
<prefer>
|
||||
<family>Liberation Sans</family>
|
||||
</prefer>
|
||||
</alias>
|
||||
<alias>
|
||||
<family>serif</family>
|
||||
<prefer>
|
||||
<family>Liberation Serif</family>
|
||||
</prefer>
|
||||
</alias>
|
||||
<alias>
|
||||
<family>monospace</family>
|
||||
<prefer>
|
||||
<family>Liberation Mono</family>
|
||||
</prefer>
|
||||
</alias>
|
||||
</fontconfig>
|
|
@ -32,6 +32,7 @@
|
|||
|
||||
#include "FontCache.h"
|
||||
#include "parsersettings.h"
|
||||
|
||||
extern std::vector<std::string> librarypath;
|
||||
|
||||
namespace fs = boost::filesystem;
|
||||
|
@ -76,7 +77,8 @@ std::string FontInfo::get_file() const
|
|||
}
|
||||
|
||||
FontCache * FontCache::self = NULL;
|
||||
|
||||
const std::string FontCache::DEFAULT_FONT("Liberation Sans:style=Regular");
|
||||
|
||||
FontCache::FontCache()
|
||||
{
|
||||
init_ok = false;
|
||||
|
@ -92,6 +94,11 @@ FontCache::FontCache()
|
|||
if (fs::exists(fontpath) && fs::is_directory(fontpath)) {
|
||||
fs::path path = boosty::canonical(fontpath);
|
||||
add_font_dir(path.string());
|
||||
|
||||
fs::path fontconf = fontpath / "fonts.conf";
|
||||
if (fs::exists(fontconf) && fs::is_regular(fontconf)) {
|
||||
FcConfigParseAndLoad(config, (unsigned char *)fontconf.string().c_str(), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -226,10 +233,14 @@ FT_Face FontCache::get_font(const std::string font)
|
|||
|
||||
FT_Face FontCache::find_face(const std::string font)
|
||||
{
|
||||
FT_Face face;
|
||||
|
||||
face = find_face_fontconfig(font);
|
||||
return face ? face : find_face_in_path_list(font);
|
||||
std::string trimmed(font);
|
||||
boost::algorithm::trim(trimmed);
|
||||
|
||||
const std::string lookup = trimmed.empty() ? DEFAULT_FONT : trimmed;
|
||||
FT_Face face = find_face_fontconfig(lookup);
|
||||
face = face ? face : find_face_in_path_list(font);
|
||||
PRINTDB("font = \"%s\", lookup = \"%s\" -> result = \"%s\", style = \"%s\"", font % lookup % face->family_name % face->style_name);
|
||||
return face;
|
||||
}
|
||||
|
||||
FT_Face FontCache::find_face_in_path_list(const std::string font)
|
||||
|
|
|
@ -60,6 +60,7 @@ typedef std::vector<FontInfo> FontInfoList;
|
|||
|
||||
class FontCache {
|
||||
public:
|
||||
const static std::string DEFAULT_FONT;
|
||||
const static unsigned int MAX_NR_OF_CACHE_ENTRIES = 3;
|
||||
|
||||
FontCache();
|
||||
|
|
Loading…
Reference in New Issue