Various Emboss improvements from PS (#4039)

* Fix: invalid distance from surface when load from 3mf

Cherry-picked from prusa3d/PrusaSlicer@e1d9393e51

Co-authored-by: YFilip Sykala - NTB T15p <Filip.Sykala@Prusa3D.cz>

* Apply rotation angle given by style for new text object
Turn off feature 'use_surface' for new text object

Cherry-picked from prusa3d/PrusaSlicer@1cb156c815

Co-authored-by: YFilip Sykala - NTB T15p <Filip.Sykala@Prusa3D.cz>

* Store/Load align and per_glyph in Slicer.ini for text style

Cherry-picked from prusa3d/PrusaSlicer@fe16f5bdd1

Co-authored-by: YFilip Sykala - NTB T15p <Filip.Sykala@Prusa3D.cz>

* Store undo/redo snap after stop input-sliding

Cherry-picked from prusa3d/PrusaSlicer@fb4e4710e7

Co-authored-by: YFilip Sykala - NTB T15p <Filip.Sykala@Prusa3D.cz>

* Initialize SvgFile object in optional different way.

Cherry-picked from prusa3d/PrusaSlicer@0ff255eadc

Co-authored-by: YFilip Sykala - NTB T15p <Filip.Sykala@Prusa3D.cz>

* SPE-2103
Make snap-shot to undo/redo stack only on release slider

Connected with attributes:
Text/advanced(char gap, line gap, boldness, skew ratio)
SVG(size)

Also change range for Boldness. VRT font-Ascent.
(different font may have different slider value range)

Fix line gap (it was denied when per glyph was false)

Cherry-picked from prusa3d/PrusaSlicer@ee3546b186

Co-authored-by: YFilip Sykala - NTB T15p <Filip.Sykala@Prusa3D.cz>

---------

Co-authored-by: YFilip Sykala - NTB T15p <Filip.Sykala@Prusa3D.cz>
Co-authored-by: SoftFever <softfeverever@gmail.com>
This commit is contained in:
Noisyfox 2024-02-13 23:56:48 +08:00 committed by GitHub
parent 291cfe1d4a
commit 2d140f92ff
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 217 additions and 72 deletions

View file

@ -14,6 +14,9 @@
#include "slic3r/GUI/Jobs/CreateFontStyleImagesJob.hpp"
#include "slic3r/GUI/ImGuiWrapper.hpp" // check of font ranges
#include <boost/assign.hpp>
#include <boost/bimap.hpp>
using namespace Slic3r;
using namespace Slic3r::Emboss;
using namespace Slic3r::GUI::Emboss;
@ -38,6 +41,20 @@ void store_style_index(AppConfig &cfg, size_t index);
StyleManager::Styles load_styles(const AppConfig &cfg);
void store_styles(AppConfig &cfg, const StyleManager::Styles &styles);
void make_unique_name(const StyleManager::Styles &styles, std::string &name);
// Enum map to string and vice versa
using HorizontalAlignToName = boost::bimap<FontProp::HorizontalAlign, std::string_view>;
const HorizontalAlignToName horizontal_align_to_name =
boost::assign::list_of<HorizontalAlignToName::relation>
(FontProp::HorizontalAlign::left, "left")
(FontProp::HorizontalAlign::center, "center")
(FontProp::HorizontalAlign::right, "right");
using VerticalAlignToName = boost::bimap<FontProp::VerticalAlign, std::string_view>;
const VerticalAlignToName vertical_align_to_name =
boost::assign::list_of<VerticalAlignToName::relation>
(FontProp::VerticalAlign::top, "top")
(FontProp::VerticalAlign::center, "middle")
(FontProp::VerticalAlign::bottom, "bottom");
} // namespace
void StyleManager::init(AppConfig *app_config)
@ -535,6 +552,9 @@ const std::string APP_CONFIG_FONT_DESCRIPTOR = "descriptor";
const std::string APP_CONFIG_FONT_LINE_HEIGHT = "line_height";
const std::string APP_CONFIG_FONT_DEPTH = "depth";
const std::string APP_CONFIG_FONT_USE_SURFACE = "use_surface";
const std::string APP_CONFIG_PER_GLYPH = "per_glyph";
const std::string APP_CONFIG_VERTICAL_ALIGN = "vertical_align";
const std::string APP_CONFIG_HORIZONTAL_ALIGN = "horizontal_align";
const std::string APP_CONFIG_FONT_BOLDNESS = "boldness";
const std::string APP_CONFIG_FONT_SKEW = "skew";
const std::string APP_CONFIG_FONT_DISTANCE = "distance";
@ -561,6 +581,36 @@ bool read(const Section &section, const std::string &key, bool &value)
return true;
}
bool read(const Section &section, const std::string &key, Slic3r::FontProp::HorizontalAlign &value) {
auto item = section.find(key);
if (item == section.end())
return false;
const std::string &data = item->second;
if (data.empty())
return false;
const auto& map = horizontal_align_to_name.right;
auto it = map.find(data);
value = (it != map.end()) ? it->second : Slic3r::FontProp::HorizontalAlign::center;
return true;
}
bool read(const Section &section, const std::string &key, Slic3r::FontProp::VerticalAlign &value) {
auto item = section.find(key);
if (item == section.end())
return false;
const std::string &data = item->second;
if (data.empty())
return false;
const auto &map = vertical_align_to_name.right;
auto it = map.find(data);
value = (it != map.end()) ? it->second : Slic3r::FontProp::VerticalAlign::center;
return true;
}
bool read(const Section &section, const std::string &key, float &value)
{
auto item = section.find(key);
@ -650,6 +700,9 @@ std::optional<StyleManager::Style> load_style(const Section &app_cfg_section)
read(app_cfg_section, APP_CONFIG_FONT_DEPTH, depth);
ep.depth = depth;
read(app_cfg_section, APP_CONFIG_FONT_USE_SURFACE, ep.use_surface);
read(app_cfg_section, APP_CONFIG_PER_GLYPH, fp.per_glyph);
read(app_cfg_section, APP_CONFIG_HORIZONTAL_ALIGN, fp.align.first);
read(app_cfg_section, APP_CONFIG_VERTICAL_ALIGN, fp.align.second);
read(app_cfg_section, APP_CONFIG_FONT_BOLDNESS, fp.boldness);
read(app_cfg_section, APP_CONFIG_FONT_SKEW, fp.skew);
read(app_cfg_section, APP_CONFIG_FONT_DISTANCE, s.distance);
@ -671,6 +724,12 @@ void store_style(AppConfig &cfg, const StyleManager::Style &s, unsigned index)
data[APP_CONFIG_FONT_DEPTH] = std::to_string(ep.depth);
if (ep.use_surface)
data[APP_CONFIG_FONT_USE_SURFACE] = "true";
if (fp.per_glyph)
data[APP_CONFIG_PER_GLYPH] = "true";
if (fp.align.first != FontProp::HorizontalAlign::center)
data[APP_CONFIG_HORIZONTAL_ALIGN] = horizontal_align_to_name.left.find(fp.align.first)->second;
if (fp.align.second != FontProp::VerticalAlign::center)
data[APP_CONFIG_VERTICAL_ALIGN] = vertical_align_to_name.left.find(fp.align.second)->second;
if (fp.boldness.has_value())
data[APP_CONFIG_FONT_BOLDNESS] = std::to_string(*fp.boldness);
if (fp.skew.has_value())