Fix path for just created font by description

Fix for issue #64 - linux loading windows font
This commit is contained in:
Filip Sykala - NTB T15p 2022-08-15 12:04:22 +02:00
parent 64728feec3
commit e631d3999c
3 changed files with 22 additions and 17 deletions

View file

@ -2621,23 +2621,25 @@ EmbossDataBase GLGizmoEmboss::create_emboss_data_base() {
bool GLGizmoEmboss::load_configuration(ModelVolume *volume)
{
if (volume == nullptr) return false;
if (!volume->text_configuration.has_value()) return false;
const std::optional<TextConfiguration> tc_opt = volume->text_configuration;
if (!tc_opt.has_value()) return false;
const TextConfiguration &tc = *tc_opt;
const EmbossStyle &style = tc.style;
TextConfiguration &tc = *volume->text_configuration;
EmbossStyle &tc_es = tc.style;
auto has_same_name = [&tc_es](const EmbossStyleManager::Item &style) -> bool {
const EmbossStyle &es = style.style;
return es.name == tc_es.name;
auto has_same_name = [&style](const EmbossStyleManager::Item &style_item) -> bool {
const EmbossStyle &es = style_item.style;
return es.name == style.name;
};
std::optional<wxFont> wx_font_opt;
if (tc_es.type == WxFontUtils::get_actual_type())
wx_font_opt = WxFontUtils::load_wxFont(tc_es.path);
if (style.type == WxFontUtils::get_actual_type())
wx_font_opt = WxFontUtils::load_wxFont(style.path);
bool is_path_changed = false;
if (!wx_font_opt.has_value()) {
create_notification_not_valid_font(tc);
// Try create similar wx font
wx_font_opt = WxFontUtils::create_wxFont(tc_es);
wx_font_opt = WxFontUtils::create_wxFont(style);
is_path_changed = wx_font_opt.has_value();
}
const auto& styles = m_style_manager.get_styles();
@ -2645,22 +2647,25 @@ bool GLGizmoEmboss::load_configuration(ModelVolume *volume)
if (it == styles.end()) {
// style was not found
if (wx_font_opt.has_value())
m_style_manager.load_style(tc_es, *wx_font_opt);
m_style_manager.load_style(style, *wx_font_opt);
} else {
size_t style_index = it - styles.begin();
if (!m_style_manager.load_style(style_index)) {
// can`t load stored style
m_style_manager.erase(style_index);
if (wx_font_opt.has_value())
m_style_manager.load_style(tc_es, *wx_font_opt);
m_style_manager.load_style(style, *wx_font_opt);
} else {
// stored style is loaded, now set modification of style
m_style_manager.get_style() = tc_es;
m_style_manager.get_style() = style;
m_style_manager.set_wx_font(*wx_font_opt);
}
}
if (is_path_changed)
m_style_manager.get_style().path = WxFontUtils::store_wxFont(*wx_font_opt);
m_text = tc.text;
m_volume = volume;
return true;

View file

@ -194,10 +194,10 @@ const TypeToWeight WxFontUtils::type_to_weight =
(wxFONTWEIGHT_HEAVY, "heavy")
(wxFONTWEIGHT_EXTRAHEAVY, "extraHeavy");
std::optional<wxFont> WxFontUtils::create_wxFont(const EmbossStyle &fi)
std::optional<wxFont> WxFontUtils::create_wxFont(const EmbossStyle &style)
{
const FontProp &fp = fi.prop;
double point_size = static_cast<double>(fp.size_in_mm);
const FontProp &fp = style.prop;
double point_size = static_cast<double>(fp.size_in_mm);
wxFontInfo info(point_size);
if (fp.family.has_value()) {
auto it = type_to_family.right.find(*fp.style);

View file

@ -36,7 +36,7 @@ public:
static std::optional<wxFont> load_wxFont(const std::string &font_descriptor);
// Try to create similar font, loaded from 3mf from different Computer
static std::optional<wxFont> create_wxFont(const EmbossStyle &fi);
static std::optional<wxFont> create_wxFont(const EmbossStyle &style);
// update font property by wxFont
static void update_property(FontProp &font_prop, const wxFont &font);