Fix icons.

Fix error message on uknown glyph in font
This commit is contained in:
Filip Sykala 2021-12-13 16:02:55 +01:00
parent 88523bceb6
commit 6a66436858
2 changed files with 9 additions and 6 deletions

View File

@ -56,9 +56,12 @@ std::optional<stbtt_fontinfo> Private::load_font_info(const Emboss::Font &font)
std::optional<Emboss::Glyph> Private::get_glyph(stbtt_fontinfo &font_info, int unicode_letter, float flatness) std::optional<Emboss::Glyph> Private::get_glyph(stbtt_fontinfo &font_info, int unicode_letter, float flatness)
{ {
int glyph_index = stbtt_FindGlyphIndex(&font_info, unicode_letter); int glyph_index = stbtt_FindGlyphIndex(&font_info, unicode_letter);
if (glyph_index == 0) { if (glyph_index == 0) {
std::cerr << "Character codepoint(" << unicode_letter wchar_t wchar = static_cast<wchar_t>(unicode_letter);
<< " = '" << (char) unicode_letter << "') is not defined in the font."; std::cerr << "Character unicode letter ("
<< "decimal value = " << std::dec << unicode_letter << ", "
<< "hexadecimal value = U+" << std::hex << unicode_letter << std::dec
<< ") is NOT defined inside of the font. \n";
return {}; return {};
} }
@ -522,7 +525,7 @@ std::optional<Emboss::Glyph> Emboss::letter2glyph(const Font &font,
{ {
auto font_info_opt = Private::load_font_info(font); auto font_info_opt = Private::load_font_info(font);
if (!font_info_opt.has_value()) return {}; if (!font_info_opt.has_value()) return {};
return Private::get_glyph(*font_info_opt, (int) letter, flatness); return Private::get_glyph(*font_info_opt, letter, flatness);
} }
ExPolygons Emboss::text2shapes(Font & font, ExPolygons Emboss::text2shapes(Font & font,

View File

@ -470,7 +470,7 @@ void GLGizmoEmboss::initialize()
// TODO: What to do when icon was NOT loaded? // TODO: What to do when icon was NOT loaded?
bool success = init_icons(); bool success = init_icons();
assert(success);
load_font_list(); load_font_list();
@ -1416,7 +1416,7 @@ std::string GLGizmoEmboss::create_volume_name()
bool GLGizmoEmboss::init_icons() bool GLGizmoEmboss::init_icons()
{ {
std::string path = resources_dir() + "/icons/white/"; std::string path = resources_dir() + "/icons/";
// icon order has to match the enum IconType // icon order has to match the enum IconType
std::vector<std::string> filenames = {path + "wrench.svg", std::vector<std::string> filenames = {path + "wrench.svg",