diff --git a/src/libslic3r/Emboss.cpp b/src/libslic3r/Emboss.cpp index e7055e8105..81a9154e12 100644 --- a/src/libslic3r/Emboss.cpp +++ b/src/libslic3r/Emboss.cpp @@ -796,8 +796,7 @@ const Glyph* priv::get_glyph( auto glyph_item = cache.find(unicode); if (glyph_item != cache.end()) return &glyph_item->second; - unsigned int font_index = font_prop.collection_number.has_value()? - *font_prop.collection_number : 0; + unsigned int font_index = font_prop.collection_number.value_or(0); if (!is_valid(font, font_index)) return nullptr; if (!font_info_opt.has_value()) { @@ -835,11 +834,10 @@ const Glyph* priv::get_glyph( glyph_opt->shape = Slic3r::union_ex(offset_ex(glyph_opt->shape, delta)); } if (font_prop.skew.has_value()) { - const float &ratio = *font_prop.skew; - auto skew = [&ratio](Polygon &polygon) { - for (Slic3r::Point &p : polygon.points) { - p.x() += p.y() * ratio; - } + double ratio = *font_prop.skew; + auto skew = [&ratio](Polygon &polygon) { + for (Slic3r::Point &p : polygon.points) + p.x() += static_cast(std::round(p.y() * ratio)); }; for (ExPolygon &expolygon : glyph_opt->shape) { skew(expolygon.contour); @@ -1363,10 +1361,9 @@ std::string Emboss::create_range_text(const std::string &text, double Emboss::get_shape_scale(const FontProp &fp, const FontFile &ff) { - const auto &cn = fp.collection_number; - unsigned int font_index = (cn.has_value()) ? *cn : 0; - int unit_per_em = ff.infos[font_index].unit_per_em; - double scale = fp.size_in_mm / unit_per_em; + size_t font_index = fp.collection_number.value_or(0); + const FontFile::Info &info = ff.infos[font_index]; + double scale = fp.size_in_mm / (double) info.unit_per_em; // Shape is scaled for store point coordinate as integer return scale * SHAPE_SCALE; } diff --git a/src/slic3r/GUI/Jobs/EmbossJob.cpp b/src/slic3r/GUI/Jobs/EmbossJob.cpp index aa2c7590e4..6d41907c22 100644 --- a/src/slic3r/GUI/Jobs/EmbossJob.cpp +++ b/src/slic3r/GUI/Jobs/EmbossJob.cpp @@ -430,16 +430,13 @@ TriangleMesh priv::try_create_mesh(DataBase &input, Fnc was_canceled) { ExPolygons shapes = priv::create_shape(input, was_canceled); if (shapes.empty()) return {}; - if (was_canceled()) return {}; + if (was_canceled()) return {}; const FontProp &prop = input.text_configuration.style.prop; - const std::optional &cn = prop.collection_number; - unsigned int font_index = (cn.has_value()) ? *cn : 0; - const FontFileWithCache &font = input.font_file; - assert(font_index < font.font_file->infos.size()); - int unit_per_em = font.font_file->infos[font_index].unit_per_em; - float scale = prop.size_in_mm / unit_per_em; - float depth = prop.emboss / scale; + const FontFile &ff = *input.font_file.font_file; + // NOTE: SHAPE_SCALE is applied in ProjectZ + double scale = get_shape_scale(prop, ff) / SHAPE_SCALE; + double depth = prop.emboss / scale; auto projectZ = std::make_unique(depth); ProjectScale project(std::move(projectZ), scale); if (was_canceled()) return {}; diff --git a/src/slic3r/Utils/EmbossStyleManager.cpp b/src/slic3r/Utils/EmbossStyleManager.cpp index 100a532b89..4f066b9c85 100644 --- a/src/slic3r/Utils/EmbossStyleManager.cpp +++ b/src/slic3r/Utils/EmbossStyleManager.cpp @@ -472,8 +472,7 @@ ImFont *StyleManager::create_imgui_font(const std::string &text, double scale) // TODO: start using merge mode //font_config.MergeMode = true; - const auto &cn = font_prop.collection_number; - unsigned int font_index = (cn.has_value()) ? *cn : 0; + unsigned int font_index = font_prop.collection_number.value_or(0); const auto &font_info = font_file.infos[font_index]; if (font_prop.char_gap.has_value()) { float coef = font_size / (double) font_info.unit_per_em;