mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-10 04:49:02 +08:00
Rename FontItem to EmbossStyle
This commit is contained in:
parent
ee03ed6d07
commit
003c7fc54f
@ -30,7 +30,7 @@ public:
|
||||
static const Emboss::Glyph* get_glyph(int unicode, const Emboss::FontFile &font, const FontProp &font_prop,
|
||||
Emboss::Glyphs &cache, std::optional<stbtt_fontinfo> &font_info_opt);
|
||||
|
||||
static FontItem create_font_item(std::wstring name, std::wstring path);
|
||||
static EmbossStyle create_style(std::wstring name, std::wstring path);
|
||||
|
||||
/// <summary>
|
||||
/// TODO: move to ExPolygon utils
|
||||
@ -202,10 +202,10 @@ const Emboss::Glyph* Private::get_glyph(
|
||||
return &it.first->second;
|
||||
}
|
||||
|
||||
FontItem Private::create_font_item(std::wstring name, std::wstring path) {
|
||||
EmbossStyle Private::create_style(std::wstring name, std::wstring path) {
|
||||
return { boost::nowide::narrow(name.c_str()),
|
||||
boost::nowide::narrow(path.c_str()),
|
||||
FontItem::Type::file_path, FontProp() };
|
||||
EmbossStyle::Type::file_path, FontProp() };
|
||||
}
|
||||
|
||||
ExPolygons Private::dilate_to_unique_points(ExPolygons &expolygons)
|
||||
@ -347,15 +347,15 @@ std::optional<std::wstring> Emboss::get_font_path(const std::wstring &font_face_
|
||||
return wsFontFile;
|
||||
}
|
||||
|
||||
FontList Emboss::get_font_list()
|
||||
EmbossStyles Emboss::get_font_list()
|
||||
{
|
||||
//FontList list1 = get_font_list_by_enumeration();
|
||||
//FontList list2 = get_font_list_by_register();
|
||||
//FontList list3 = get_font_list_by_folder();
|
||||
//EmbossStyles list1 = get_font_list_by_enumeration();
|
||||
//EmbossStyles list2 = get_font_list_by_register();
|
||||
//EmbossStyles list3 = get_font_list_by_folder();
|
||||
return get_font_list_by_register();
|
||||
}
|
||||
|
||||
FontList Emboss::get_font_list_by_register() {
|
||||
EmbossStyles Emboss::get_font_list_by_register() {
|
||||
static const LPWSTR fontRegistryPath = L"Software\\Microsoft\\Windows NT\\CurrentVersion\\Fonts";
|
||||
HKEY hKey;
|
||||
LONG result;
|
||||
@ -383,7 +383,7 @@ FontList Emboss::get_font_list_by_register() {
|
||||
GetWindowsDirectory(winDir, MAX_PATH);
|
||||
std::wstring font_path = std::wstring(winDir) + L"\\Fonts\\";
|
||||
|
||||
FontList font_list;
|
||||
EmbossStyles font_list;
|
||||
DWORD valueIndex = 0;
|
||||
// Look for a matching font name
|
||||
LPWSTR font_name = new WCHAR[maxValueNameSize];
|
||||
@ -406,7 +406,7 @@ FontList Emboss::get_font_list_by_register() {
|
||||
if (pos >= font_name_w.size()) continue;
|
||||
// remove TrueType text from name
|
||||
font_name_w = std::wstring(font_name_w, 0, pos);
|
||||
font_list.emplace_back(Private::create_font_item(font_name_w, path_w));
|
||||
font_list.emplace_back(Private::create_style(font_name_w, path_w));
|
||||
} while (result != ERROR_NO_MORE_ITEMS);
|
||||
delete[] font_name;
|
||||
delete[] fileTTF_name;
|
||||
@ -432,22 +432,22 @@ bool CALLBACK EnumFamCallBack(LPLOGFONT lplf,
|
||||
UNREFERENCED_PARAMETER(lpntm);
|
||||
}
|
||||
|
||||
FontList Emboss::get_font_list_by_enumeration() {
|
||||
EmbossStyles Emboss::get_font_list_by_enumeration() {
|
||||
|
||||
HDC hDC = GetDC(NULL);
|
||||
std::vector<std::wstring> font_names;
|
||||
EnumFontFamilies(hDC, (LPCTSTR) NULL, (FONTENUMPROC) EnumFamCallBack,
|
||||
(LPARAM) &font_names);
|
||||
|
||||
FontList font_list;
|
||||
EmbossStyles font_list;
|
||||
for (const std::wstring &font_name : font_names) {
|
||||
font_list.emplace_back(Private::create_font_item(font_name, L""));
|
||||
font_list.emplace_back(Private::create_style(font_name, L""));
|
||||
}
|
||||
return font_list;
|
||||
}
|
||||
|
||||
FontList Emboss::get_font_list_by_folder() {
|
||||
FontList result;
|
||||
EmbossStyles Emboss::get_font_list_by_folder() {
|
||||
EmbossStyles result;
|
||||
WCHAR winDir[MAX_PATH];
|
||||
UINT winDir_size = GetWindowsDirectory(winDir, MAX_PATH);
|
||||
std::wstring search_dir = std::wstring(winDir, winDir_size) + L"\\Fonts\\";
|
||||
@ -463,7 +463,7 @@ FontList Emboss::get_font_list_by_folder() {
|
||||
if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue;
|
||||
std::wstring file_name(fd.cFileName);
|
||||
// TODO: find font name instead of filename
|
||||
result.emplace_back(Private::create_font_item(file_name, search_dir + file_name));
|
||||
result.emplace_back(Private::create_style(file_name, search_dir + file_name));
|
||||
} while (::FindNextFile(hFind, &fd));
|
||||
::FindClose(hFind);
|
||||
}
|
||||
@ -471,7 +471,7 @@ FontList Emboss::get_font_list_by_folder() {
|
||||
}
|
||||
|
||||
#else
|
||||
FontList Emboss::get_font_list() {
|
||||
EmbossStyles Emboss::get_font_list() {
|
||||
// not implemented
|
||||
return {};
|
||||
}
|
||||
|
@ -28,11 +28,11 @@ public:
|
||||
/// Collect fonts registred inside OS
|
||||
/// </summary>
|
||||
/// <returns>OS registred TTF font files(full path) with names</returns>
|
||||
static FontList get_font_list();
|
||||
static EmbossStyles get_font_list();
|
||||
#ifdef _WIN32
|
||||
static FontList get_font_list_by_register();
|
||||
static FontList get_font_list_by_enumeration();
|
||||
static FontList get_font_list_by_folder();
|
||||
static EmbossStyles get_font_list_by_register();
|
||||
static EmbossStyles get_font_list_by_enumeration();
|
||||
static EmbossStyles get_font_list_by_folder();
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
|
@ -148,7 +148,7 @@ static constexpr const char* MESH_STAT_BACKWARDS_EDGES = "backwards_edges";
|
||||
// Store / load of TextConfiguration
|
||||
static constexpr const char *TEXT_TAG = "emboss";
|
||||
static constexpr const char *TEXT_DATA_ATTR = "text";
|
||||
// TextConfiguration::FontItem
|
||||
// TextConfiguration::EmbossStyle
|
||||
static constexpr const char *STYLE_NAME_ATTR = "style_name";
|
||||
static constexpr const char *FONT_DESCRIPTOR_ATTR = "font_descriptor";
|
||||
static constexpr const char *FONT_DESCRIPTOR_TYPE_ATTR = "font_descriptor_type";
|
||||
@ -1832,17 +1832,17 @@ namespace Slic3r {
|
||||
public:
|
||||
TextConfigurationSerialization() = delete;
|
||||
|
||||
static const boost::bimap<FontItem::Type, std::string_view> type_to_name;
|
||||
static const boost::bimap<EmbossStyle::Type, std::string_view> type_to_name;
|
||||
|
||||
static FontItem::Type get_type(std::string_view type) {
|
||||
static EmbossStyle::Type get_type(std::string_view type) {
|
||||
const auto& to_type = TextConfigurationSerialization::type_to_name.right;
|
||||
auto type_item = to_type.find(type);
|
||||
assert(type_item != to_type.end());
|
||||
if (type_item == to_type.end()) return FontItem::Type::undefined;
|
||||
if (type_item == to_type.end()) return EmbossStyle::Type::undefined;
|
||||
return type_item->second;
|
||||
}
|
||||
|
||||
static std::string_view get_name(FontItem::Type type) {
|
||||
static std::string_view get_name(EmbossStyle::Type type) {
|
||||
const auto& to_name = TextConfigurationSerialization::type_to_name.left;
|
||||
auto type_name = to_name.find(type);
|
||||
assert(type_name != to_name.end());
|
||||
@ -3334,13 +3334,13 @@ bool store_3mf(const char* path, Model* model, const DynamicPrintConfig* config,
|
||||
/// <summary>
|
||||
/// TextConfiguration serialization
|
||||
/// </summary>
|
||||
using TypeToName = boost::bimap<FontItem::Type, std::string_view>;
|
||||
using TypeToName = boost::bimap<EmbossStyle::Type, std::string_view>;
|
||||
const TypeToName TextConfigurationSerialization::type_to_name =
|
||||
boost::assign::list_of<TypeToName::relation>
|
||||
(FontItem::Type::file_path, "file_name")
|
||||
(FontItem::Type::wx_win_font_descr, "wxFontDescriptor_Windows")
|
||||
(FontItem::Type::wx_lin_font_descr, "wxFontDescriptor_Linux")
|
||||
(FontItem::Type::wx_mac_font_descr, "wxFontDescriptor_MacOsX");
|
||||
(EmbossStyle::Type::file_path, "file_name")
|
||||
(EmbossStyle::Type::wx_win_font_descr, "wxFontDescriptor_Windows")
|
||||
(EmbossStyle::Type::wx_lin_font_descr, "wxFontDescriptor_Linux")
|
||||
(EmbossStyle::Type::wx_mac_font_descr, "wxFontDescriptor_MacOsX");
|
||||
|
||||
void TextConfigurationSerialization::to_xml(std::stringstream &stream, const TextConfiguration &tc)
|
||||
{
|
||||
@ -3348,13 +3348,13 @@ void TextConfigurationSerialization::to_xml(std::stringstream &stream, const Tex
|
||||
|
||||
stream << TEXT_DATA_ATTR << "=\"" << xml_escape_double_quotes_attribute_value(tc.text) << "\" ";
|
||||
// font item
|
||||
const FontItem &fi = tc.font_item;
|
||||
const EmbossStyle &fi = tc.style;
|
||||
stream << STYLE_NAME_ATTR << "=\"" << xml_escape_double_quotes_attribute_value(fi.name) << "\" ";
|
||||
stream << FONT_DESCRIPTOR_ATTR << "=\"" << xml_escape_double_quotes_attribute_value(fi.path) << "\" ";
|
||||
stream << FONT_DESCRIPTOR_TYPE_ATTR << "=\"" << TextConfigurationSerialization::get_name(fi.type) << "\" ";
|
||||
|
||||
// font property
|
||||
const FontProp &fp = tc.font_item.prop;
|
||||
const FontProp &fp = tc.style.prop;
|
||||
if (fp.char_gap.has_value())
|
||||
stream << CHAR_GAP_ATTR << "=\"" << *fp.char_gap << "\" ";
|
||||
if (fp.line_gap.has_value())
|
||||
@ -3469,8 +3469,8 @@ std::optional<TextConfiguration> TextConfigurationSerialization::read(const char
|
||||
std::string style_name = get_attribute_value_string(attributes, num_attributes, STYLE_NAME_ATTR);
|
||||
std::string font_descriptor = get_attribute_value_string(attributes, num_attributes, FONT_DESCRIPTOR_ATTR);
|
||||
std::string type_str = get_attribute_value_string(attributes, num_attributes, FONT_DESCRIPTOR_TYPE_ATTR);
|
||||
FontItem::Type type = TextConfigurationSerialization::get_type(type_str);
|
||||
FontItem fi{ style_name, std::move(font_descriptor), type, std::move(fp) };
|
||||
EmbossStyle::Type type = TextConfigurationSerialization::get_type(type_str);
|
||||
EmbossStyle fi{ style_name, std::move(font_descriptor), type, std::move(fp) };
|
||||
|
||||
std::string text = get_attribute_value_string(attributes, num_attributes, TEXT_DATA_ATTR);
|
||||
|
||||
|
@ -10,42 +10,11 @@
|
||||
#include <cereal/archives/binary.hpp>
|
||||
#include "Point.hpp" // Transform3d
|
||||
|
||||
// Serialization through the Cereal library
|
||||
//namespace cereal {
|
||||
// // Eigen Matrix 4x4 serialization
|
||||
// template <class Archive> void serialize(Archive &ar, ::Slic3r::Matrix4d &m){
|
||||
// ar(binary_data(m.data(), 4*4*sizeof(double)));
|
||||
// }
|
||||
//
|
||||
// // !!! create duplicit implementation
|
||||
// // General solution for Eigen matrix serialization
|
||||
// //template <class Archive, class Derived> inline typename std::enable_if<traits::is_output_serializable<BinaryData<typename Derived::Scalar>, Archive>::value, void>::type
|
||||
// //save(Archive & ar, Eigen::PlainObjectBase<Derived> const & m){
|
||||
// // typedef Eigen::PlainObjectBase<Derived> ArrT;
|
||||
// // if(ArrT::RowsAtCompileTime==Eigen::Dynamic) ar(m.rows());
|
||||
// // if(ArrT::ColsAtCompileTime==Eigen::Dynamic) ar(m.cols());
|
||||
// // ar(binary_data(m.data(),m.size()*sizeof(typename Derived::Scalar)));
|
||||
// //}
|
||||
// //template <class Archive, class Derived> inline typename std::enable_if<traits::is_input_serializable<BinaryData<typename Derived::Scalar>, Archive>::value, void>::type
|
||||
// //load(Archive & ar, Eigen::PlainObjectBase<Derived> & m){
|
||||
// // typedef Eigen::PlainObjectBase<Derived> ArrT;
|
||||
// // Eigen::Index rows=ArrT::RowsAtCompileTime, cols=ArrT::ColsAtCompileTime;
|
||||
// // if(rows==Eigen::Dynamic) ar(rows);
|
||||
// // if(cols==Eigen::Dynamic) ar(cols);
|
||||
// // m.resize(rows,cols);
|
||||
// // ar(binary_data(m.data(),static_cast<std::size_t>(rows*cols*sizeof(typename Derived::Scalar))));
|
||||
// //}
|
||||
//
|
||||
// // Eigen Transformation serialization
|
||||
// template<class Archive, class T, int N> inline void
|
||||
// serialize(Archive & ar, Eigen::Transform<T, N, Eigen::Affine, Eigen::DontAlign>& t){ ar(t.matrix()); }
|
||||
//}
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
/// <summary>
|
||||
/// User modifiable property of text style
|
||||
/// NOTE: OnEdit fix serializations: FontListSerializable, TextConfigurationSerialization
|
||||
/// NOTE: OnEdit fix serializations: EmbossStylesSerializable, TextConfigurationSerialization
|
||||
/// </summary>
|
||||
struct FontProp
|
||||
{
|
||||
@ -178,9 +147,9 @@ struct FontProp
|
||||
/// <summary>
|
||||
/// Style of embossed text
|
||||
/// (Path + Type) must define how to open font for using on different OS
|
||||
/// NOTE: OnEdit fix serializations: FontListSerializable, TextConfigurationSerialization
|
||||
/// NOTE: OnEdit fix serializations: EmbossStylesSerializable, TextConfigurationSerialization
|
||||
/// </summary>
|
||||
struct FontItem
|
||||
struct EmbossStyle
|
||||
{
|
||||
// Human readable name of style it is shown in GUI
|
||||
std::string name;
|
||||
@ -214,7 +183,8 @@ struct FontItem
|
||||
file_path
|
||||
};
|
||||
|
||||
bool operator==(const FontItem &other) const {
|
||||
bool operator==(const EmbossStyle &other) const
|
||||
{
|
||||
return
|
||||
type == other.type &&
|
||||
prop == other.prop &&
|
||||
@ -229,10 +199,10 @@ struct FontItem
|
||||
}
|
||||
};
|
||||
|
||||
// Font item name inside list is unique
|
||||
// FontList is not map beacuse items order matters (view of list)
|
||||
// It is stored into AppConfig by FontListSerializable
|
||||
using FontList = std::vector<FontItem>;
|
||||
// Emboss style name inside vector is unique
|
||||
// It is not map beacuse items has own order (view inside of slect)
|
||||
// It is stored into AppConfig by EmbossStylesSerializable
|
||||
using EmbossStyles = std::vector<EmbossStyle>;
|
||||
|
||||
/// <summary>
|
||||
/// Define how to create 'Text volume'
|
||||
@ -242,7 +212,7 @@ using FontList = std::vector<FontItem>;
|
||||
struct TextConfiguration
|
||||
{
|
||||
// Style of embossed text
|
||||
FontItem font_item;
|
||||
EmbossStyle style;
|
||||
|
||||
// Embossed text value
|
||||
std::string text = "None";
|
||||
@ -255,11 +225,11 @@ struct TextConfiguration
|
||||
|
||||
// undo / redo stack recovery
|
||||
template<class Archive> void save(Archive &ar) const{
|
||||
ar(text, font_item);
|
||||
ar(text, style);
|
||||
cereal::save(ar, fix_3mf_tr);
|
||||
}
|
||||
template<class Archive> void load(Archive &ar){
|
||||
ar(text, font_item);
|
||||
ar(text, style);
|
||||
cereal::load(ar, fix_3mf_tr);
|
||||
}
|
||||
};
|
||||
|
@ -240,12 +240,12 @@ set(SLIC3R_GUI_SOURCES
|
||||
Utils/Duet.hpp
|
||||
Utils/EmbossStyleManager.cpp
|
||||
Utils/EmbossStyleManager.hpp
|
||||
Utils/EmbossStylesSerializable.cpp
|
||||
Utils/EmbossStylesSerializable.hpp
|
||||
Utils/FlashAir.cpp
|
||||
Utils/FlashAir.hpp
|
||||
Utils/FontConfigHelp.cpp
|
||||
Utils/FontConfigHelp.hpp
|
||||
Utils/FontListSerializable.cpp
|
||||
Utils/FontListSerializable.hpp
|
||||
Utils/AstroBox.cpp
|
||||
Utils/AstroBox.hpp
|
||||
Utils/Repetier.cpp
|
||||
|
@ -204,7 +204,7 @@ bool GLGizmoEmboss::on_mouse_for_rotation(const wxMouseEvent &mouse_event)
|
||||
|
||||
static std::optional<float> start_angle;
|
||||
if (mouse_event.Dragging()) {
|
||||
auto &angle_opt = m_volume->text_configuration->font_item.prop.angle;
|
||||
auto &angle_opt = m_volume->text_configuration->style.prop.angle;
|
||||
if (!start_angle.has_value()) {
|
||||
start_angle = angle_opt.has_value() ? *angle_opt : 0.f;
|
||||
}
|
||||
@ -343,7 +343,7 @@ bool GLGizmoEmboss::on_mouse_for_translate(const wxMouseEvent &mouse_event)
|
||||
// Calculate temporary position
|
||||
Transform3d object_trmat = m_raycast_manager.get_transformation(hit->tr_key);
|
||||
Transform3d trmat = Emboss::create_transformation_onto_surface(hit->position, hit->normal);
|
||||
const FontProp& font_prop = tc.font_item.prop;
|
||||
const FontProp& font_prop = tc.style.prop;
|
||||
Emboss::apply_transformation(font_prop, trmat);
|
||||
|
||||
// fix baked transformation from .3mf store process
|
||||
@ -372,7 +372,7 @@ bool GLGizmoEmboss::on_mouse_for_translate(const wxMouseEvent &mouse_event)
|
||||
m_dragging_mouse_offset = {};
|
||||
|
||||
// Update surface by new position
|
||||
if (m_volume->text_configuration->font_item.prop.use_surface) {
|
||||
if (m_volume->text_configuration->style.prop.use_surface) {
|
||||
// need actual position
|
||||
m_volume->set_transformation(volume_trmat);
|
||||
process();
|
||||
@ -731,28 +731,29 @@ void GLGizmoEmboss::initialize()
|
||||
|
||||
// initialize text styles
|
||||
const AppConfig *app_cfg = wxGetApp().app_config;
|
||||
m_style_manager.init(app_cfg, create_default_font_list());
|
||||
m_style_manager.init(app_cfg, create_default_styles());
|
||||
set_default_text();
|
||||
}
|
||||
|
||||
FontList GLGizmoEmboss::create_default_font_list()
|
||||
EmbossStyles GLGizmoEmboss::create_default_styles()
|
||||
{
|
||||
// https://docs.wxwidgets.org/3.0/classwx_font.html
|
||||
// Predefined objects/pointers: wxNullFont, wxNORMAL_FONT, wxSMALL_FONT, wxITALIC_FONT, wxSWISS_FONT
|
||||
return {
|
||||
WxFontUtils::get_font_item(*wxNORMAL_FONT, _u8L("NORMAL")), // wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT)
|
||||
WxFontUtils::get_font_item(*wxSMALL_FONT, _u8L("SMALL")), // A font using the wxFONTFAMILY_SWISS family and 2 points smaller than wxNORMAL_FONT.
|
||||
WxFontUtils::get_font_item(*wxITALIC_FONT, _u8L("ITALIC")), // A font using the wxFONTFAMILY_ROMAN family and wxFONTSTYLE_ITALIC style and of the same size of wxNORMAL_FONT.
|
||||
WxFontUtils::get_font_item(*wxSWISS_FONT, _u8L("SWISS")), // A font identic to wxNORMAL_FONT except for the family used which is wxFONTFAMILY_SWISS.
|
||||
WxFontUtils::get_font_item(wxFont(10, wxFONTFAMILY_MODERN, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD), _u8L("MODERN"))
|
||||
WxFontUtils::create_emboss_style(*wxNORMAL_FONT, _u8L("NORMAL")), // wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT)
|
||||
WxFontUtils::create_emboss_style(*wxSMALL_FONT, _u8L("SMALL")), // A font using the wxFONTFAMILY_SWISS family and 2 points smaller than wxNORMAL_FONT.
|
||||
WxFontUtils::create_emboss_style(*wxITALIC_FONT, _u8L("ITALIC")), // A font using the wxFONTFAMILY_ROMAN family and wxFONTSTYLE_ITALIC style and of the same size of wxNORMAL_FONT.
|
||||
WxFontUtils::create_emboss_style(*wxSWISS_FONT, _u8L("SWISS")), // A font identic to wxNORMAL_FONT except for the family used which is wxFONTFAMILY_SWISS.
|
||||
WxFontUtils::create_emboss_style(wxFont(10, wxFONTFAMILY_MODERN, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD), _u8L("MODERN"))
|
||||
//, WxFontUtils::get_os_font() == wxNORMAL_FONT
|
||||
};
|
||||
}
|
||||
|
||||
FontItem GLGizmoEmboss::create_default_font() {
|
||||
std::string font_path = Slic3r::resources_dir() + "/fonts/NotoSans-Regular.ttf";
|
||||
return FontItem{"Default font", font_path, FontItem::Type::file_path};
|
||||
}
|
||||
// Could exist systems without installed font so last chance is used own file
|
||||
//EmbossStyle GLGizmoEmboss::create_default_style() {
|
||||
// std::string font_path = Slic3r::resources_dir() + "/fonts/NotoSans-Regular.ttf";
|
||||
// return EmbossStyle{"Default font", font_path, EmbossStyle::Type::file_path};
|
||||
//}
|
||||
|
||||
void GLGizmoEmboss::set_default_text(){ m_text = _u8L("Embossed text"); }
|
||||
|
||||
@ -917,7 +918,7 @@ bool GLGizmoEmboss::process()
|
||||
|
||||
// check cutting from source mesh
|
||||
const TextConfiguration &tc = data.text_configuration;
|
||||
if (tc.font_item.prop.use_surface) {
|
||||
if (tc.style.prop.use_surface) {
|
||||
// Model to cut surface from.
|
||||
UseSurfaceData::ModelSources sources = UseSurfaceData::create_sources(m_volume);
|
||||
if (sources.empty()) return false;
|
||||
@ -1443,7 +1444,7 @@ void GLGizmoEmboss::draw_model_type()
|
||||
m_volume->set_type(*new_type);
|
||||
|
||||
// Update volume position when switch from part or into part
|
||||
if (m_volume->text_configuration->font_item.prop.use_surface) {
|
||||
if (m_volume->text_configuration->style.prop.use_surface) {
|
||||
// move inside
|
||||
bool is_volume_move_inside = (type == part);
|
||||
bool is_volume_move_outside = (*new_type == part);
|
||||
@ -1477,10 +1478,10 @@ void GLGizmoEmboss::draw_style_rename_popup() {
|
||||
|
||||
bool is_unique = true;
|
||||
for (const auto &item : m_style_manager.get_styles()) {
|
||||
const FontItem &fi = item.font_item;
|
||||
if (&fi == &m_style_manager.get_font_item())
|
||||
const EmbossStyle &style = item.font_item;
|
||||
if (&style == &m_style_manager.get_font_item())
|
||||
continue; // could be same as original name
|
||||
if (fi.name == new_name) is_unique = false;
|
||||
if (style.name == new_name) is_unique = false;
|
||||
}
|
||||
bool allow_change = false;
|
||||
if (new_name.empty()) {
|
||||
@ -1507,14 +1508,14 @@ void GLGizmoEmboss::draw_style_rename_popup() {
|
||||
for (ModelObject *mo :wxGetApp().plater()->model().objects) {
|
||||
for (ModelVolume *mv : mo->volumes) {
|
||||
if (!mv->text_configuration.has_value()) continue;
|
||||
std::string& name = mv->text_configuration->font_item.name;
|
||||
std::string& name = mv->text_configuration->style.name;
|
||||
if (name != old_name) continue;
|
||||
name = new_name;
|
||||
}
|
||||
}
|
||||
|
||||
m_style_manager.rename(new_name);
|
||||
m_style_manager.store_font_list_to_app_config(wxGetApp().app_config);
|
||||
m_style_manager.store_styles_to_app_config(wxGetApp().app_config);
|
||||
ImGui::CloseCurrentPopup();
|
||||
}
|
||||
}
|
||||
@ -1541,12 +1542,12 @@ void GLGizmoEmboss::draw_style_rename_button()
|
||||
void GLGizmoEmboss::draw_style_save_button()
|
||||
{
|
||||
bool is_stored_style = m_style_manager.exist_stored_style();
|
||||
const FontItem *stored_fi = nullptr;
|
||||
const EmbossStyle *stored_syle = nullptr;
|
||||
if (is_stored_style)
|
||||
stored_fi = m_style_manager.get_stored_font_item();
|
||||
stored_syle = m_style_manager.get_stored_font_item();
|
||||
|
||||
const FontItem &fi = m_style_manager.get_font_item();
|
||||
bool is_changed = (stored_fi)? !(*stored_fi == fi) : true;
|
||||
const EmbossStyle &style = m_style_manager.get_font_item();
|
||||
bool is_changed = (stored_syle)? !(*stored_syle == style) : true;
|
||||
|
||||
bool is_style_order_changed = m_style_manager.is_style_order_changed();
|
||||
bool is_activ_style_changed = m_style_manager.is_activ_style_changed();
|
||||
@ -1555,7 +1556,7 @@ void GLGizmoEmboss::draw_style_save_button()
|
||||
|
||||
if (draw_button(IconType::save, !can_save)) {
|
||||
// save styles to app config
|
||||
m_style_manager.store_font_list_to_app_config(wxGetApp().app_config);
|
||||
m_style_manager.store_styles_to_app_config(wxGetApp().app_config);
|
||||
}else if (ImGui::IsItemHovered()) {
|
||||
if (!is_stored_style) {
|
||||
ImGui::SetTooltip("%s", _u8L("First Add style to be able save.").c_str());
|
||||
@ -1575,7 +1576,7 @@ void GLGizmoEmboss::draw_style_save_as_popup() {
|
||||
ImGui::Text("%s", _u8L("New name of style: ").c_str());
|
||||
|
||||
// use name inside of volume configuration as temporary new name
|
||||
std::string &new_name = m_volume->text_configuration->font_item.name;
|
||||
std::string &new_name = m_volume->text_configuration->style.name;
|
||||
|
||||
bool is_unique = true;
|
||||
for (const auto &item : m_style_manager.get_styles())
|
||||
@ -1608,7 +1609,7 @@ void GLGizmoEmboss::draw_style_save_as_popup() {
|
||||
|
||||
if (save_style && allow_change) {
|
||||
m_style_manager.store_style(new_name);
|
||||
m_style_manager.store_font_list_to_app_config(wxGetApp().app_config);
|
||||
m_style_manager.store_styles_to_app_config(wxGetApp().app_config);
|
||||
ImGui::CloseCurrentPopup();
|
||||
}
|
||||
}
|
||||
@ -1620,7 +1621,7 @@ void GLGizmoEmboss::draw_style_add_button()
|
||||
if (only_add_style &&
|
||||
m_volume &&
|
||||
m_volume->text_configuration.has_value() &&
|
||||
m_volume->text_configuration->font_item.type != WxFontUtils::get_actual_type())
|
||||
m_volume->text_configuration->style.type != WxFontUtils::get_actual_type())
|
||||
can_add = false;
|
||||
|
||||
std::string title = _u8L("Save as new style");
|
||||
@ -1629,7 +1630,7 @@ void GLGizmoEmboss::draw_style_add_button()
|
||||
ImGui::SameLine();
|
||||
if (draw_button(IconType::add, !can_add)) {
|
||||
if (!m_style_manager.exist_stored_style()) {
|
||||
m_style_manager.store_font_list_to_app_config(wxGetApp().app_config);
|
||||
m_style_manager.store_styles_to_app_config(wxGetApp().app_config);
|
||||
} else {
|
||||
ImGui::OpenPopup(popup_id);
|
||||
}
|
||||
@ -1650,12 +1651,12 @@ void GLGizmoEmboss::draw_style_add_button()
|
||||
}
|
||||
|
||||
void GLGizmoEmboss::draw_style_undo_button() {
|
||||
const FontItem *stored_fi = nullptr;
|
||||
const EmbossStyle *stored_style = nullptr;
|
||||
bool is_stored = m_style_manager.exist_stored_style();
|
||||
if (is_stored)
|
||||
stored_fi = m_style_manager.get_stored_font_item();
|
||||
const FontItem &fi = m_style_manager.get_font_item();
|
||||
bool is_changed = (stored_fi)? !(*stored_fi == fi) : true;
|
||||
stored_style = m_style_manager.get_stored_font_item();
|
||||
const EmbossStyle &style = m_style_manager.get_font_item();
|
||||
bool is_changed = (stored_style)? !(*stored_style == style) : true;
|
||||
bool can_undo = is_stored && is_changed;
|
||||
if (draw_button(IconType::undo, !can_undo)) {
|
||||
discard_changes_in_style();
|
||||
@ -1720,7 +1721,7 @@ void GLGizmoEmboss::draw_delete_style_button() {
|
||||
size_t activ_index = m_style_manager.get_style_index();
|
||||
m_style_manager.load_font(next_style_index);
|
||||
m_style_manager.erase(activ_index);
|
||||
m_style_manager.store_font_list_to_app_config(wxGetApp().app_config);
|
||||
m_style_manager.store_styles_to_app_config(wxGetApp().app_config);
|
||||
ImGui::CloseCurrentPopup();
|
||||
process();
|
||||
}
|
||||
@ -1735,20 +1736,20 @@ void GLGizmoEmboss::discard_changes_in_style()
|
||||
{
|
||||
if (!m_style_manager.exist_stored_style()) return;
|
||||
|
||||
FontItem &font_item = m_style_manager.get_font_item();
|
||||
const FontItem* stored_fi = m_style_manager.get_stored_font_item();
|
||||
assert(stored_fi != nullptr);
|
||||
EmbossStyle &emboss_style = m_style_manager.get_font_item();
|
||||
const EmbossStyle* stored_style = m_style_manager.get_stored_font_item();
|
||||
assert(stored_style != nullptr);
|
||||
|
||||
// is rotation changed
|
||||
auto &angle = font_item.prop.angle;
|
||||
const auto &angle_ = stored_fi->prop.angle;
|
||||
auto &angle = emboss_style.prop.angle;
|
||||
const auto &angle_ = stored_style->prop.angle;
|
||||
// TODO: compare with approx
|
||||
if (angle.has_value() != angle_.has_value() ||
|
||||
(angle.has_value() && !is_approx(*angle, *angle_))) {
|
||||
auto &tc = m_volume->text_configuration;
|
||||
if (m_volume != nullptr && tc.has_value()) {
|
||||
// change actual text configuration
|
||||
tc->font_item.prop.angle = angle_;
|
||||
tc->style.prop.angle = angle_;
|
||||
float act_angle = angle_.has_value() ? *angle_ : .0f;
|
||||
float prev_angle = angle.has_value() ? *angle : .0f;
|
||||
do_rotate(act_angle - prev_angle);
|
||||
@ -1756,23 +1757,23 @@ void GLGizmoEmboss::discard_changes_in_style()
|
||||
}
|
||||
|
||||
// is distance changed
|
||||
auto &distance = font_item.prop.distance;
|
||||
const auto &distance_ = stored_fi->prop.distance;
|
||||
auto &distance = emboss_style.prop.distance;
|
||||
const auto &distance_ = stored_style->prop.distance;
|
||||
if (distance.has_value() != distance_.has_value() ||
|
||||
(distance.has_value() && !is_approx(*distance, *distance_))) {
|
||||
auto &tc = m_volume->text_configuration;
|
||||
if (m_volume != nullptr && tc.has_value()) {
|
||||
tc->font_item.prop.distance = distance_;
|
||||
tc->style.prop.distance = distance_;
|
||||
float act_distance = distance_.has_value() ? *distance_ : .0f;
|
||||
float prev_distance = distance.has_value() ? *distance : .0f;
|
||||
do_translate(Vec3d::UnitZ() * (act_distance - prev_distance));
|
||||
}
|
||||
}
|
||||
|
||||
if (font_item.path != stored_fi->path) {
|
||||
if (emboss_style.path != stored_style->path) {
|
||||
// NOTE: load font file again
|
||||
m_style_manager.load_font(m_style_manager.get_style_index());
|
||||
//m_style_manager.get_wx_font() = WxFontUtils::load_wxFont(font_item.path);
|
||||
//m_style_manager.get_wx_font() = WxFontUtils::load_wxFont(emboss_style.path);
|
||||
//m_style_manager.wx_font_changed();
|
||||
}
|
||||
}
|
||||
@ -1780,7 +1781,7 @@ void GLGizmoEmboss::discard_changes_in_style()
|
||||
void GLGizmoEmboss::draw_revert_all_styles_button() {
|
||||
if (draw_button(IconType::revert_all)) {
|
||||
m_style_manager = EmbossStyleManager(m_imgui->get_glyph_ranges());
|
||||
m_style_manager.init(nullptr, create_default_font_list());
|
||||
m_style_manager.init(nullptr, create_default_styles());
|
||||
assert(m_style_manager.get_font_file_with_cache().has_value());
|
||||
process();
|
||||
} else if (ImGui::IsItemHovered())
|
||||
@ -1790,7 +1791,7 @@ void GLGizmoEmboss::draw_revert_all_styles_button() {
|
||||
void GLGizmoEmboss::draw_style_list() {
|
||||
if (!m_style_manager.is_activ_font()) return;
|
||||
const float &max_style_name_width = m_gui_cfg->max_style_name_width;
|
||||
const FontItem &actual_font_item = m_style_manager.get_font_item();
|
||||
const EmbossStyle &actual_font_item = m_style_manager.get_font_item();
|
||||
std::string &trunc_name = m_style_manager.get_truncated_name();
|
||||
if (trunc_name.empty()) {
|
||||
// generate trunc name
|
||||
@ -1811,10 +1812,10 @@ void GLGizmoEmboss::draw_style_list() {
|
||||
const std::vector<EmbossStyleManager::Item> &styles = m_style_manager.get_styles();
|
||||
for (const auto &item : styles) {
|
||||
size_t index = &item - &styles.front();
|
||||
const FontItem & fi = item.font_item;
|
||||
const std::string &actual_style_name = fi.name;
|
||||
const EmbossStyle &es = item.font_item;
|
||||
const std::string &actual_style_name = es.name;
|
||||
ImGui::PushID(actual_style_name.c_str());
|
||||
bool is_selected = (&fi == &actual_font_item);
|
||||
bool is_selected = (&es == &actual_font_item);
|
||||
|
||||
ImVec2 select_size(0,m_gui_cfg->max_style_image_size.y()); // 0,0 --> calculate in draw
|
||||
const std::optional<EmbossStyleManager::StyleImage> img = item.image;
|
||||
@ -2049,33 +2050,33 @@ void GLGizmoEmboss::draw_style_edit() {
|
||||
const GuiCfg::Translations &tr = m_gui_cfg->translations;
|
||||
|
||||
std::optional<wxFont> &wx_font = m_style_manager.get_wx_font();
|
||||
FontItem &fi = m_style_manager.get_font_item();
|
||||
EmbossStyle &style = m_style_manager.get_font_item();
|
||||
assert(wx_font.has_value());
|
||||
|
||||
// TODO: should not be there
|
||||
// when actual font not loaded try to load
|
||||
if (!wx_font.has_value() && fi.type == WxFontUtils::get_actual_type())
|
||||
wx_font = WxFontUtils::load_wxFont(fi.path);
|
||||
if (!wx_font.has_value() && style.type == WxFontUtils::get_actual_type())
|
||||
wx_font = WxFontUtils::load_wxFont(style.path);
|
||||
|
||||
bool exist_stored_style = m_style_manager.exist_stored_style();
|
||||
bool is_font_changed = false;
|
||||
if (exist_stored_style &&
|
||||
wx_font.has_value()) {
|
||||
const FontItem *stored_fi = m_style_manager.get_stored_font_item();
|
||||
assert(stored_fi != nullptr);
|
||||
const EmbossStyle *stored_style = m_style_manager.get_stored_font_item();
|
||||
assert(stored_style != nullptr);
|
||||
const std::optional<wxFont> &stored_wx = m_style_manager.get_stored_wx_font();
|
||||
assert(stored_wx.has_value());
|
||||
bool is_font_face_changed = stored_wx->GetFaceName() != wx_font->GetFaceName();
|
||||
|
||||
const std::optional<float> &skew = m_style_manager.get_font_prop().skew;
|
||||
bool is_italic = skew.has_value() || WxFontUtils::is_italic(*wx_font);
|
||||
const std::optional<float> &skew_stored = stored_fi->prop.skew;
|
||||
const std::optional<float> &skew_stored = stored_style->prop.skew;
|
||||
bool is_stored_italic = skew_stored.has_value() || WxFontUtils::is_italic(*stored_wx);
|
||||
bool is_italic_changed = is_italic != is_stored_italic;
|
||||
|
||||
const std::optional<float> &boldness = m_style_manager.get_font_prop().boldness;
|
||||
bool is_bold = boldness.has_value() || WxFontUtils::is_bold(*wx_font);
|
||||
const std::optional<float> &boldness_stored = stored_fi->prop.boldness;
|
||||
const std::optional<float> &boldness_stored = stored_style->prop.boldness;
|
||||
bool is_stored_bold = boldness_stored.has_value() || WxFontUtils::is_bold(*stored_wx);
|
||||
bool is_bold_changed = is_bold != is_stored_bold;
|
||||
|
||||
@ -2101,12 +2102,12 @@ void GLGizmoEmboss::draw_style_edit() {
|
||||
if (is_font_changed) {
|
||||
ImGui::SameLine(ImGui::GetStyle().FramePadding.x);
|
||||
if (draw_button(IconType::undo)) {
|
||||
const FontItem *stored_fi = m_style_manager.get_stored_font_item();
|
||||
fi.path = stored_fi->path;
|
||||
fi.prop.boldness = stored_fi->prop.boldness;
|
||||
fi.prop.skew = stored_fi->prop.skew;
|
||||
const EmbossStyle *stored_style = m_style_manager.get_stored_font_item();
|
||||
style.path = stored_style->path;
|
||||
style.prop.boldness = stored_style->prop.boldness;
|
||||
style.prop.skew = stored_style->prop.skew;
|
||||
|
||||
wx_font = WxFontUtils::load_wxFont(fi.path);
|
||||
wx_font = WxFontUtils::load_wxFont(style.path);
|
||||
m_style_manager.wx_font_changed();
|
||||
exist_change = true;
|
||||
} else if (ImGui::IsItemHovered())
|
||||
@ -2118,7 +2119,7 @@ void GLGizmoEmboss::draw_style_edit() {
|
||||
process();
|
||||
}
|
||||
|
||||
FontProp &font_prop = fi.prop;
|
||||
FontProp &font_prop = style.prop;
|
||||
const float * def_size = exist_stored_style?
|
||||
&m_style_manager.get_stored_font_item()->prop.size_in_mm : nullptr;
|
||||
if (rev_input(tr.size, font_prop.size_in_mm, def_size,
|
||||
@ -2129,10 +2130,10 @@ void GLGizmoEmboss::draw_style_edit() {
|
||||
// only different value need process
|
||||
if (m_volume != nullptr &&
|
||||
m_volume->text_configuration.has_value() &&
|
||||
!is_approx(font_prop.size_in_mm, m_volume->text_configuration->font_item.prop.size_in_mm)) {
|
||||
!is_approx(font_prop.size_in_mm, m_volume->text_configuration->style.prop.size_in_mm)) {
|
||||
|
||||
// store font size into path
|
||||
if (fi.type == WxFontUtils::get_actual_type()) {
|
||||
if (style.type == WxFontUtils::get_actual_type()) {
|
||||
if (wx_font.has_value()) {
|
||||
wx_font->SetPointSize(
|
||||
static_cast<int>(font_prop.size_in_mm));
|
||||
@ -2309,16 +2310,16 @@ void GLGizmoEmboss::draw_advanced()
|
||||
bool exist_change = false;
|
||||
auto &tr = m_gui_cfg->translations;
|
||||
|
||||
const FontItem *stored_fi = nullptr;
|
||||
const EmbossStyle *stored_style = nullptr;
|
||||
if (m_style_manager.exist_stored_style())
|
||||
stored_fi = m_style_manager.get_stored_font_item();
|
||||
stored_style = m_style_manager.get_stored_font_item();
|
||||
|
||||
bool can_use_surface = (m_volume==nullptr)? false :
|
||||
(font_prop.use_surface)? true : // already used surface must have option to uncheck
|
||||
(m_volume->get_object()->volumes.size() > 1);
|
||||
m_imgui->disabled_begin(!can_use_surface);
|
||||
const bool *def_use_surface = stored_fi ?
|
||||
&stored_fi->prop.use_surface : nullptr;
|
||||
const bool *def_use_surface = stored_style ?
|
||||
&stored_style->prop.use_surface : nullptr;
|
||||
if (rev_checkbox(tr.use_surface, font_prop.use_surface, def_use_surface,
|
||||
_u8L("Revert using of model surface."))) {
|
||||
if (font_prop.use_surface) {
|
||||
@ -2334,8 +2335,8 @@ void GLGizmoEmboss::draw_advanced()
|
||||
std::string units_fmt = "%.0f " + units;
|
||||
|
||||
// input gap between letters
|
||||
auto def_char_gap = stored_fi ?
|
||||
&stored_fi->prop.char_gap : nullptr;
|
||||
auto def_char_gap = stored_style ?
|
||||
&stored_style->prop.char_gap : nullptr;
|
||||
|
||||
int half_ascent = font_info.ascent / 2;
|
||||
int min_char_gap = -half_ascent, max_char_gap = half_ascent;
|
||||
@ -2348,8 +2349,8 @@ void GLGizmoEmboss::draw_advanced()
|
||||
}
|
||||
|
||||
// input gap between lines
|
||||
auto def_line_gap = stored_fi ?
|
||||
&stored_fi->prop.line_gap : nullptr;
|
||||
auto def_line_gap = stored_style ?
|
||||
&stored_style->prop.line_gap : nullptr;
|
||||
int min_line_gap = -half_ascent, max_line_gap = half_ascent;
|
||||
if (rev_slider(tr.line_gap, font_prop.line_gap, def_line_gap, _u8L("Revert gap between lines"),
|
||||
min_line_gap, max_line_gap, units_fmt, _L("Distance between lines"))){
|
||||
@ -2360,8 +2361,8 @@ void GLGizmoEmboss::draw_advanced()
|
||||
}
|
||||
|
||||
// input boldness
|
||||
auto def_boldness = stored_fi ?
|
||||
&stored_fi->prop.boldness : nullptr;
|
||||
auto def_boldness = stored_style ?
|
||||
&stored_style->prop.boldness : nullptr;
|
||||
if (rev_slider(tr.boldness, font_prop.boldness, def_boldness, _u8L("Undo boldness"),
|
||||
limits.boldness.gui.min, limits.boldness.gui.max, units_fmt, _L("Tiny / Wide glyphs"))){
|
||||
Limits::apply(font_prop.boldness, limits.boldness.values);
|
||||
@ -2369,8 +2370,8 @@ void GLGizmoEmboss::draw_advanced()
|
||||
}
|
||||
|
||||
// input italic
|
||||
auto def_skew = stored_fi ?
|
||||
&stored_fi->prop.skew : nullptr;
|
||||
auto def_skew = stored_style ?
|
||||
&stored_style->prop.skew : nullptr;
|
||||
if (rev_slider(tr.italic, font_prop.skew, def_skew, _u8L("Undo letter's skew"),
|
||||
limits.skew.gui.min, limits.skew.gui.max, "%.2f", _L("Italic strength ratio"))){
|
||||
Limits::apply(font_prop.skew, limits.skew.values);
|
||||
@ -2381,19 +2382,19 @@ void GLGizmoEmboss::draw_advanced()
|
||||
bool allowe_surface_distance =
|
||||
m_volume != nullptr &&
|
||||
m_volume->text_configuration.has_value() &&
|
||||
!m_volume->text_configuration->font_item.prop.use_surface &&
|
||||
!m_volume->text_configuration->style.prop.use_surface &&
|
||||
!is_text_object(m_volume);
|
||||
std::optional<float> &distance = font_prop.distance;
|
||||
float prev_distance = distance.has_value() ? *distance : .0f,
|
||||
min_distance = -2 * font_prop.emboss,
|
||||
max_distance = 2 * font_prop.emboss;
|
||||
auto def_distance = stored_fi ?
|
||||
&stored_fi->prop.distance : nullptr;
|
||||
auto def_distance = stored_style ?
|
||||
&stored_style->prop.distance : nullptr;
|
||||
m_imgui->disabled_begin(!allowe_surface_distance);
|
||||
if (rev_slider(tr.surface_distance, distance, def_distance, _u8L("Undo translation"),
|
||||
min_distance, max_distance, "%.2f mm", _L("Distance center of text from model surface")) &&
|
||||
m_volume != nullptr && m_volume->text_configuration.has_value()){
|
||||
m_volume->text_configuration->font_item.prop.distance = font_prop.distance;
|
||||
m_volume->text_configuration->style.prop.distance = font_prop.distance;
|
||||
float act_distance = font_prop.distance.has_value() ? *font_prop.distance : .0f;
|
||||
do_translate(Vec3d::UnitZ() * (act_distance - prev_distance));
|
||||
}
|
||||
@ -2408,9 +2409,9 @@ void GLGizmoEmboss::draw_advanced()
|
||||
float angle_deg = angle.has_value() ?
|
||||
static_cast<float>(-(*angle) * 180 / M_PI) : .0f;
|
||||
float def_angle_deg_val =
|
||||
(!stored_fi || !stored_fi->prop.angle.has_value()) ?
|
||||
0.f : (*stored_fi->prop.angle * -180 / M_PI);
|
||||
float* def_angle_deg = stored_fi ?
|
||||
(!stored_style || !stored_style->prop.angle.has_value()) ?
|
||||
0.f : (*stored_style->prop.angle * -180 / M_PI);
|
||||
float* def_angle_deg = stored_style ?
|
||||
&def_angle_deg_val : nullptr;
|
||||
if (rev_slider(tr.angle, angle_deg, def_angle_deg, _u8L("Undo rotation"),
|
||||
limits.angle.min, limits.angle.max, u8"%.2f °",
|
||||
@ -2425,7 +2426,7 @@ void GLGizmoEmboss::draw_advanced()
|
||||
angle.reset();
|
||||
|
||||
if (m_volume != nullptr && m_volume->text_configuration.has_value()) {
|
||||
m_volume->text_configuration->font_item.prop.angle = angle;
|
||||
m_volume->text_configuration->style.prop.angle = angle;
|
||||
float act_angle = angle.has_value() ? *angle : .0f;
|
||||
do_rotate(act_angle - prev_angle);
|
||||
}
|
||||
@ -2473,7 +2474,7 @@ void GLGizmoEmboss::draw_advanced()
|
||||
font_prop.weight->c_str() :
|
||||
" --- "));
|
||||
|
||||
std::string descriptor = fi.path;
|
||||
std::string descriptor = style.path;
|
||||
ImGui::Text("descriptor = %s", descriptor.c_str());
|
||||
#endif // ALLOW_DEBUG_MODE
|
||||
}
|
||||
@ -2505,7 +2506,7 @@ bool GLGizmoEmboss::choose_font_by_wxdialog()
|
||||
data.EnableEffects(false);
|
||||
data.RestrictSelection(wxFONTRESTRICT_SCALABLE);
|
||||
// set previous selected font
|
||||
FontItem &selected_font_item = m_style_manager.get_font_item();
|
||||
EmbossStyle &selected_font_item = m_style_manager.get_font_item();
|
||||
if (selected_font_item.type == WxFontUtils::get_actual_type()) {
|
||||
std::optional<wxFont> selected_font = WxFontUtils::load_wxFont(
|
||||
selected_font_item.path);
|
||||
@ -2518,7 +2519,7 @@ bool GLGizmoEmboss::choose_font_by_wxdialog()
|
||||
data = font_dialog.GetFontData();
|
||||
wxFont wx_font = data.GetChosenFont();
|
||||
size_t font_index = m_style_manager.get_fonts().size();
|
||||
FontItem font_item = WxFontUtils::get_font_item(wx_font);
|
||||
EmbossStyle emboss_style = WxFontUtils::create_emboss_style(wx_font);
|
||||
|
||||
// Check that deserialization NOT influence font
|
||||
// false - use direct selected wxFont in dialog
|
||||
@ -2527,11 +2528,11 @@ bool GLGizmoEmboss::choose_font_by_wxdialog()
|
||||
|
||||
// Try load and use new added font
|
||||
if ((use_deserialized_font && !m_style_manager.load_font(font_index)) ||
|
||||
(!use_deserialized_font && !m_style_manager.load_font(font_item, wx_font))) {
|
||||
(!use_deserialized_font && !m_style_manager.load_font(emboss_style, wx_font))) {
|
||||
m_style_manager.erase(font_index);
|
||||
wxString message = GUI::format_wxstr(
|
||||
_L("Font '%1%' can't be used. Please select another."),
|
||||
font_item.name);
|
||||
emboss_style.name);
|
||||
wxString title = _L("Selected font is NOT True-type.");
|
||||
MessageDialog not_loaded_font_message(nullptr, message, title, wxOK);
|
||||
not_loaded_font_message.ShowModal();
|
||||
@ -2568,8 +2569,8 @@ bool GLGizmoEmboss::choose_true_type_file()
|
||||
std::string name = get_file_name(path);
|
||||
//make_unique_name(name, m_font_list);
|
||||
const FontProp& prop = m_style_manager.get_font_prop();
|
||||
FontItem fi{ name, path, FontItem::Type::file_path, prop };
|
||||
m_style_manager.add_font(fi);
|
||||
EmbossStyle style{ name, path, EmbossStyle::Type::file_path, prop };
|
||||
m_style_manager.add_font(style);
|
||||
// set first valid added font as active
|
||||
if (m_style_manager.load_font(index)) return true;
|
||||
m_style_manager.erase(index);
|
||||
@ -2624,18 +2625,18 @@ EmbossDataBase GLGizmoEmboss::create_emboss_data_base() {
|
||||
auto create_configuration = [&]() -> TextConfiguration {
|
||||
if (!m_style_manager.is_activ_font()) {
|
||||
std::string default_text_for_emboss = _u8L("Embossed text");
|
||||
FontItem fi = m_style_manager.get_font_item();
|
||||
TextConfiguration tc{fi, default_text_for_emboss};
|
||||
EmbossStyle es = m_style_manager.get_font_item();
|
||||
TextConfiguration tc{es, default_text_for_emboss};
|
||||
// TODO: investigace how to initialize
|
||||
return tc;
|
||||
}
|
||||
|
||||
FontItem &fi = m_style_manager.get_font_item();
|
||||
EmbossStyle &es = m_style_manager.get_font_item();
|
||||
// actualize font path - during changes in gui it could be corrupted
|
||||
// volume must store valid path
|
||||
assert(m_style_manager.get_wx_font().has_value());
|
||||
fi.path = WxFontUtils::store_wxFont(*m_style_manager.get_wx_font());
|
||||
return TextConfiguration{fi, m_text};
|
||||
es.path = WxFontUtils::store_wxFont(*m_style_manager.get_wx_font());
|
||||
return TextConfiguration{es, m_text};
|
||||
};
|
||||
|
||||
return EmbossDataBase{
|
||||
@ -2651,20 +2652,20 @@ bool GLGizmoEmboss::load_configuration(ModelVolume *volume)
|
||||
if (!volume->text_configuration.has_value()) return false;
|
||||
|
||||
TextConfiguration &tc = *volume->text_configuration;
|
||||
FontItem &tc_fi = tc.font_item;
|
||||
EmbossStyle &tc_es = tc.style;
|
||||
|
||||
auto has_same_name = [&tc_fi](const EmbossStyleManager::Item &font_item) -> bool {
|
||||
const FontItem &fi = font_item.font_item;
|
||||
return fi.name == tc_fi.name;
|
||||
auto has_same_name = [&tc_es](const EmbossStyleManager::Item &font_item) -> bool {
|
||||
const EmbossStyle &es = font_item.font_item;
|
||||
return es.name == tc_es.name;
|
||||
};
|
||||
|
||||
std::optional<wxFont> wx_font_opt;
|
||||
if (tc_fi.type == WxFontUtils::get_actual_type())
|
||||
wx_font_opt = WxFontUtils::load_wxFont(tc_fi.path);
|
||||
if (tc_es.type == WxFontUtils::get_actual_type())
|
||||
wx_font_opt = WxFontUtils::load_wxFont(tc_es.path);
|
||||
if (!wx_font_opt.has_value()) {
|
||||
create_notification_not_valid_font(tc);
|
||||
// Try create similar wx font
|
||||
wx_font_opt = WxFontUtils::create_wxFont(tc_fi);
|
||||
wx_font_opt = WxFontUtils::create_wxFont(tc_es);
|
||||
}
|
||||
|
||||
const auto& styles = m_style_manager.get_styles();
|
||||
@ -2672,18 +2673,18 @@ bool GLGizmoEmboss::load_configuration(ModelVolume *volume)
|
||||
if (it == styles.end()) {
|
||||
// style was not found
|
||||
if (wx_font_opt.has_value())
|
||||
m_style_manager.load_font(tc_fi, *wx_font_opt);
|
||||
m_style_manager.load_font(tc_es, *wx_font_opt);
|
||||
} else {
|
||||
size_t style_index = it - styles.begin();
|
||||
if (!m_style_manager.load_font(style_index)) {
|
||||
// can`t load stored style
|
||||
m_style_manager.erase(style_index);
|
||||
if (wx_font_opt.has_value())
|
||||
m_style_manager.load_font(tc_fi, *wx_font_opt);
|
||||
m_style_manager.load_font(tc_es, *wx_font_opt);
|
||||
|
||||
} else {
|
||||
// stored style is loaded, now set modification of style
|
||||
m_style_manager.get_font_item() = tc_fi;
|
||||
m_style_manager.get_font_item() = tc_es;
|
||||
m_style_manager.set_wx_font(*wx_font_opt);
|
||||
}
|
||||
}
|
||||
@ -2704,16 +2705,16 @@ void GLGizmoEmboss::create_notification_not_valid_font(
|
||||
auto level =
|
||||
NotificationManager::NotificationLevel::WarningNotificationLevel;
|
||||
|
||||
const auto &fi = m_style_manager.get_font_item();
|
||||
const auto &origin_family = tc.font_item.prop.face_name;
|
||||
const auto &actual_family = fi.prop.face_name;
|
||||
const EmbossStyle &es = m_style_manager.get_font_item();
|
||||
const auto &origin_family = tc.style.prop.face_name;
|
||||
const auto &actual_family = es.prop.face_name;
|
||||
|
||||
const std::string &origin_font_name = origin_family.has_value() ?
|
||||
*origin_family :
|
||||
tc.font_item.path;
|
||||
tc.style.path;
|
||||
const std::string &actual_font_name = actual_family.has_value() ?
|
||||
*actual_family :
|
||||
fi.name;
|
||||
es.name;
|
||||
|
||||
std::string text =
|
||||
GUI::format(_L("Can't load exactly same font(\"%1%\"), "
|
||||
|
@ -82,9 +82,8 @@ protected:
|
||||
std::string get_action_snapshot_name() override { return _u8L("Embossing actions"); }
|
||||
private:
|
||||
void initialize();
|
||||
static FontList create_default_font_list();
|
||||
// Could exist systems without installed font so last chance is used own file
|
||||
static FontItem create_default_font();
|
||||
static EmbossStyles create_default_styles();
|
||||
// localized default text
|
||||
void set_default_text();
|
||||
|
||||
bool start_volume_creation(ModelVolumeType volume_type, const Vec2d &screen_coor);
|
||||
|
@ -124,7 +124,7 @@ void EmbossCreateVolumeJob::process(Ctl &ctl) {
|
||||
if (was_canceled()) return;
|
||||
|
||||
// Create new volume inside of object
|
||||
const FontProp &font_prop = m_input.text_configuration.font_item.prop;
|
||||
const FontProp &font_prop = m_input.text_configuration.style.prop;
|
||||
Transform3d surface_trmat = Emboss::create_transformation_onto_surface(
|
||||
m_input.hit.position, m_input.hit.normal);
|
||||
Emboss::apply_transformation(font_prop, surface_trmat);
|
||||
@ -234,7 +234,7 @@ void EmbossCreateObjectJob::process(Ctl &ctl)
|
||||
// mouse pose is out of build plate so create object in center of plate
|
||||
bed_coor = bed.centroid().cast<double>();
|
||||
|
||||
double z = m_input.text_configuration.font_item.prop.emboss / 2;
|
||||
double z = m_input.text_configuration.style.prop.emboss / 2;
|
||||
Vec3d offset(bed_coor.x(), bed_coor.y(), z);
|
||||
offset -= m_result.center();
|
||||
Transform3d::TranslationType tt(offset.x(), offset.y(), offset.z());
|
||||
@ -361,7 +361,7 @@ void UseSurfaceJob::process(Ctl &ctl) {
|
||||
|
||||
const TextConfiguration &tc = m_input.text_configuration;
|
||||
const char *text = tc.text.c_str();
|
||||
const FontProp &fp = tc.font_item.prop;
|
||||
const FontProp &fp = tc.style.prop;
|
||||
ExPolygons shapes = Emboss::text2shapes(m_input.font_file, text, fp);
|
||||
if (shapes.empty() || shapes.front().contour.empty())
|
||||
throw priv::EmbossJobException(
|
||||
@ -522,7 +522,7 @@ TriangleMesh priv::try_create_mesh(const EmbossDataBase &input, Emboss::FontFile
|
||||
{
|
||||
const TextConfiguration &tc = input.text_configuration;
|
||||
const char *text = tc.text.c_str();
|
||||
const FontProp &prop = tc.font_item.prop;
|
||||
const FontProp &prop = tc.style.prop;
|
||||
|
||||
assert(font.has_value());
|
||||
if (!font.has_value()) return {};
|
||||
|
@ -9,7 +9,7 @@
|
||||
#include "slic3r/GUI/Jobs/CreateFontStyleImagesJob.hpp"
|
||||
#include "slic3r/GUI/ImGuiWrapper.hpp" // check of font ranges
|
||||
|
||||
#include "slic3r/Utils/FontListSerializable.hpp"
|
||||
#include "slic3r/Utils/EmbossStylesSerializable.hpp"
|
||||
|
||||
using namespace Slic3r;
|
||||
using namespace Slic3r::GUI;
|
||||
@ -27,19 +27,19 @@ EmbossStyleManager::~EmbossStyleManager() {
|
||||
free_style_images();
|
||||
}
|
||||
|
||||
void EmbossStyleManager::init(const AppConfig *cfg, const FontList &default_font_list)
|
||||
void EmbossStyleManager::init(const AppConfig *cfg, const EmbossStyles &default_styles)
|
||||
{
|
||||
FontList font_list = (cfg != nullptr) ?
|
||||
FontListSerializable::load_font_list(*cfg) :
|
||||
default_font_list;
|
||||
if (font_list.empty()) font_list = default_font_list;
|
||||
for (FontItem &fi : font_list) {
|
||||
make_unique_name(fi.name);
|
||||
m_style_items.push_back({fi});
|
||||
EmbossStyles styles = (cfg != nullptr) ?
|
||||
EmbossStylesSerializable::load_font_list(*cfg) :
|
||||
default_styles;
|
||||
if (styles.empty()) styles = default_styles;
|
||||
for (EmbossStyle &style : styles) {
|
||||
make_unique_name(style.name);
|
||||
m_style_items.push_back({style});
|
||||
}
|
||||
|
||||
std::optional<size_t> activ_index_opt = (cfg != nullptr) ?
|
||||
FontListSerializable::load_font_index(*cfg) :
|
||||
EmbossStylesSerializable::load_font_index(*cfg) :
|
||||
std::optional<size_t>{};
|
||||
|
||||
size_t activ_index = 0;
|
||||
@ -58,9 +58,9 @@ void EmbossStyleManager::init(const AppConfig *cfg, const FontList &default_font
|
||||
// no one style from config is loadable
|
||||
if (m_style_items.empty()) {
|
||||
// set up default font list
|
||||
for (FontItem fi : default_font_list) {
|
||||
make_unique_name(fi.name);
|
||||
m_style_items.push_back({std::move(fi)});
|
||||
for (EmbossStyle style : default_styles) {
|
||||
make_unique_name(style.name);
|
||||
m_style_items.push_back({std::move(style)});
|
||||
}
|
||||
// try to load first default font
|
||||
bool loaded = load_font(activ_index);
|
||||
@ -69,7 +69,7 @@ void EmbossStyleManager::init(const AppConfig *cfg, const FontList &default_font
|
||||
}
|
||||
}
|
||||
|
||||
bool EmbossStyleManager::store_font_list_to_app_config(AppConfig *cfg)
|
||||
bool EmbossStyleManager::store_styles_to_app_config(AppConfig *cfg)
|
||||
{
|
||||
assert(cfg != nullptr);
|
||||
if (cfg == nullptr) return false;
|
||||
@ -78,31 +78,31 @@ bool EmbossStyleManager::store_font_list_to_app_config(AppConfig *cfg)
|
||||
m_style_items[m_style_cache.font_index].font_item = m_style_cache.font_item;
|
||||
} else {
|
||||
// add new into stored list
|
||||
FontItem &fi = m_style_cache.font_item;
|
||||
make_unique_name(fi.name);
|
||||
EmbossStyle &style = m_style_cache.font_item;
|
||||
make_unique_name(style.name);
|
||||
m_style_cache.font_index = m_style_items.size();
|
||||
m_style_items.push_back({fi});
|
||||
m_style_items.push_back({style});
|
||||
m_style_cache.stored_wx_font = m_style_cache.wx_font;
|
||||
}
|
||||
|
||||
FontListSerializable::store_font_index(*cfg, m_style_cache.font_index);
|
||||
EmbossStylesSerializable::store_font_index(*cfg, m_style_cache.font_index);
|
||||
m_stored_activ_index = m_style_cache.font_index;
|
||||
FontList font_list;
|
||||
EmbossStyles font_list;
|
||||
font_list.reserve(m_style_items.size());
|
||||
for (const Item &item : m_style_items) font_list.push_back(item.font_item);
|
||||
FontListSerializable::store_font_list(*cfg, font_list);
|
||||
EmbossStylesSerializable::store_font_list(*cfg, font_list);
|
||||
m_change_order = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
void EmbossStyleManager::store_style(const std::string &name) {
|
||||
FontItem& fi = m_style_cache.font_item;
|
||||
fi.name = name;
|
||||
make_unique_name(fi.name);
|
||||
EmbossStyle& style = m_style_cache.font_item;
|
||||
style.name = name;
|
||||
make_unique_name(style.name);
|
||||
m_style_cache.font_index = m_style_items.size();
|
||||
m_style_cache.stored_wx_font = m_style_cache.wx_font;
|
||||
m_style_cache.truncated_name.clear();
|
||||
m_style_items.push_back({fi});
|
||||
m_style_items.push_back({style});
|
||||
}
|
||||
|
||||
void EmbossStyleManager::swap(size_t i1, size_t i2) {
|
||||
@ -159,9 +159,9 @@ bool EmbossStyleManager::wx_font_changed(std::unique_ptr<Emboss::FontFile> font_
|
||||
if (font_file == nullptr) return false;
|
||||
}
|
||||
m_style_cache.font_file = Emboss::FontFileWithCache(std::move(font_file));
|
||||
auto &fi = get_font_item();
|
||||
fi.type = WxFontUtils::get_actual_type();
|
||||
fi.path = WxFontUtils::store_wxFont(*wx_font);
|
||||
EmbossStyle &style = get_font_item();
|
||||
style.type = WxFontUtils::get_actual_type();
|
||||
style.path = WxFontUtils::store_wxFont(*wx_font);
|
||||
clear_imgui_font();
|
||||
free_style_images();
|
||||
return true;
|
||||
@ -176,8 +176,8 @@ bool EmbossStyleManager::load_font(size_t font_index)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool EmbossStyleManager::load_font(const FontItem &fi) {
|
||||
if (fi.type == FontItem::Type::file_path) {
|
||||
bool EmbossStyleManager::load_font(const EmbossStyle &fi) {
|
||||
if (fi.type == EmbossStyle::Type::file_path) {
|
||||
std::unique_ptr<Emboss::FontFile> font_ptr =
|
||||
Emboss::create_font_file(fi.path.c_str());
|
||||
if (font_ptr == nullptr) return false;
|
||||
@ -195,7 +195,7 @@ bool EmbossStyleManager::load_font(const FontItem &fi) {
|
||||
return load_font(fi, *wx_font_opt);
|
||||
}
|
||||
|
||||
bool EmbossStyleManager::load_font(const FontItem &fi, const wxFont &font)
|
||||
bool EmbossStyleManager::load_font(const EmbossStyle &fi, const wxFont &font)
|
||||
{
|
||||
if (!set_wx_font(font)) return false;
|
||||
m_style_cache.font_item = fi; // copy
|
||||
@ -216,7 +216,7 @@ bool EmbossStyleManager::load_first_valid_font() {
|
||||
return false;
|
||||
}
|
||||
|
||||
const FontItem* EmbossStyleManager::get_stored_font_item() const
|
||||
const EmbossStyle* EmbossStyleManager::get_stored_font_item() const
|
||||
{
|
||||
if (m_style_cache.font_index >= m_style_items.size()) return nullptr;
|
||||
return &m_style_items[m_style_cache.font_index].font_item;
|
||||
@ -224,8 +224,8 @@ const FontItem* EmbossStyleManager::get_stored_font_item() const
|
||||
|
||||
const std::optional<wxFont> &EmbossStyleManager::get_stored_wx_font() const { return m_style_cache.stored_wx_font; }
|
||||
|
||||
const FontItem &EmbossStyleManager::get_font_item() const { return m_style_cache.font_item; }
|
||||
FontItem &EmbossStyleManager::get_font_item() { return m_style_cache.font_item; }
|
||||
const EmbossStyle &EmbossStyleManager::get_font_item() const { return m_style_cache.font_item; }
|
||||
EmbossStyle &EmbossStyleManager::get_font_item() { return m_style_cache.font_item; }
|
||||
const FontProp &EmbossStyleManager::get_font_prop() const { return get_font_item().prop; }
|
||||
FontProp &EmbossStyleManager::get_font_prop() { return get_font_item().prop; }
|
||||
const std::optional<wxFont> &EmbossStyleManager::get_wx_font() const { return m_style_cache.wx_font; }
|
||||
@ -350,16 +350,16 @@ void EmbossStyleManager::init_style_images(const Vec2i &max_size,
|
||||
StyleImagesData::Items styles;
|
||||
styles.reserve(m_style_items.size());
|
||||
for (const Item &item : m_style_items) {
|
||||
const FontItem &fi = item.font_item;
|
||||
std::optional<wxFont> wx_font_opt = WxFontUtils::load_wxFont(fi.path);
|
||||
const EmbossStyle &style = item.font_item;
|
||||
std::optional<wxFont> wx_font_opt = WxFontUtils::load_wxFont(style.path);
|
||||
if (!wx_font_opt.has_value()) continue;
|
||||
std::unique_ptr<Emboss::FontFile> font_file =
|
||||
WxFontUtils::create_font_file(*wx_font_opt);
|
||||
if (font_file == nullptr) continue;
|
||||
styles.push_back({
|
||||
Emboss::FontFileWithCache(std::move(font_file)),
|
||||
fi.name,
|
||||
fi.prop
|
||||
style.name,
|
||||
style.prop
|
||||
});
|
||||
}
|
||||
auto &worker = wxGetApp().plater()->get_ui_job_worker();
|
||||
@ -484,8 +484,8 @@ bool EmbossStyleManager::set_wx_font(const wxFont &wx_font) {
|
||||
m_style_cache.font_file =
|
||||
Emboss::FontFileWithCache(std::move(font_file));
|
||||
m_style_cache.wx_font = wx_font; // copy
|
||||
FontItem &fi = m_style_cache.font_item;
|
||||
fi.type = WxFontUtils::get_actual_type();
|
||||
EmbossStyle &style = m_style_cache.font_item;
|
||||
style.type = WxFontUtils::get_actual_type();
|
||||
clear_imgui_font();
|
||||
return true;
|
||||
}
|
||||
|
@ -31,15 +31,15 @@ public:
|
||||
/// Also select actual activ font
|
||||
/// </summary>
|
||||
/// <param name="cfg">Application configuration loaded from file "PrusaSlicer.ini"</param>
|
||||
/// <param name="default_font_list">Used when list is not loadable from config</param>
|
||||
void init(const AppConfig *cfg, const FontList &default_font_list);
|
||||
/// <param name="default_styles">Used when list is not loadable from config</param>
|
||||
void init(const AppConfig *cfg, const EmbossStyles &default_styles);
|
||||
|
||||
/// <summary>
|
||||
/// Write font list into AppConfig
|
||||
/// </summary>
|
||||
/// <param name="cfg">Stor into this configuration</param>
|
||||
/// <param name="item_to_store">Configuration</param>
|
||||
bool store_font_list_to_app_config(AppConfig *cfg);
|
||||
bool store_styles_to_app_config(AppConfig *cfg);
|
||||
|
||||
/// <summary>
|
||||
/// Append actual style to style list and store
|
||||
@ -95,9 +95,9 @@ public:
|
||||
/// <returns>True on succes. False on fail load font</returns>
|
||||
bool load_font(size_t font_index);
|
||||
// load font style not stored in list
|
||||
bool load_font(const FontItem &fi);
|
||||
bool load_font(const EmbossStyle &fi);
|
||||
// fastering load font on index by wxFont, ignore type and descriptor
|
||||
bool load_font(const FontItem &fi, const wxFont &font);
|
||||
bool load_font(const EmbossStyle &fi, const wxFont &font);
|
||||
|
||||
// clear actual selected glyphs cache
|
||||
void clear_glyphs_cache();
|
||||
@ -109,15 +109,15 @@ public:
|
||||
// used at initialize phaze - fonts could be modified in appConfig file by user
|
||||
bool load_first_valid_font();
|
||||
|
||||
// getter on stored fontItem
|
||||
const FontItem *get_stored_font_item() const;
|
||||
// getter on stored EmbossStyle
|
||||
const EmbossStyle *get_stored_font_item() const;
|
||||
|
||||
// getter on stored wxFont
|
||||
const std::optional<wxFont> &get_stored_wx_font() const;
|
||||
|
||||
// getter on active font item for access to font property
|
||||
const FontItem &get_font_item() const;
|
||||
FontItem &get_font_item();
|
||||
const EmbossStyle &get_font_item() const;
|
||||
EmbossStyle &get_font_item();
|
||||
|
||||
// getter on active font property
|
||||
const FontProp &get_font_prop() const;
|
||||
@ -181,7 +181,7 @@ public:
|
||||
struct Item
|
||||
{
|
||||
// define font, style and other property of text
|
||||
FontItem font_item;
|
||||
EmbossStyle font_item;
|
||||
|
||||
// cache for view font name with maximal width in imgui
|
||||
std::string truncated_name;
|
||||
@ -224,7 +224,7 @@ private:
|
||||
std::string truncated_name;
|
||||
|
||||
// actual used font item
|
||||
FontItem font_item = {};
|
||||
EmbossStyle font_item = {};
|
||||
|
||||
// cache for stored wx font to not create every frame
|
||||
std::optional<wxFont> stored_wx_font;
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include "FontListSerializable.hpp"
|
||||
#include "EmbossStylesSerializable.hpp"
|
||||
|
||||
#include <libslic3r/AppConfig.hpp>
|
||||
#include "WxFontUtils.hpp"
|
||||
@ -6,28 +6,28 @@
|
||||
using namespace Slic3r;
|
||||
using namespace Slic3r::GUI;
|
||||
|
||||
const std::string FontListSerializable::APP_CONFIG_FONT_NAME = "name";
|
||||
const std::string FontListSerializable::APP_CONFIG_FONT_DESCRIPTOR = "descriptor";
|
||||
const std::string FontListSerializable::APP_CONFIG_FONT_LINE_HEIGHT = "line_height";
|
||||
const std::string FontListSerializable::APP_CONFIG_FONT_DEPTH = "depth";
|
||||
const std::string FontListSerializable::APP_CONFIG_FONT_USE_SURFACE = "use_surface";
|
||||
const std::string FontListSerializable::APP_CONFIG_FONT_BOLDNESS = "boldness";
|
||||
const std::string FontListSerializable::APP_CONFIG_FONT_SKEW = "skew";
|
||||
const std::string FontListSerializable::APP_CONFIG_FONT_DISTANCE = "distance";
|
||||
const std::string FontListSerializable::APP_CONFIG_FONT_ANGLE = "angle";
|
||||
const std::string FontListSerializable::APP_CONFIG_FONT_COLLECTION = "collection";
|
||||
const std::string FontListSerializable::APP_CONFIG_FONT_CHAR_GAP = "char_gap";
|
||||
const std::string FontListSerializable::APP_CONFIG_FONT_LINE_GAP = "line_gap";
|
||||
const std::string EmbossStylesSerializable::APP_CONFIG_FONT_NAME = "name";
|
||||
const std::string EmbossStylesSerializable::APP_CONFIG_FONT_DESCRIPTOR = "descriptor";
|
||||
const std::string EmbossStylesSerializable::APP_CONFIG_FONT_LINE_HEIGHT = "line_height";
|
||||
const std::string EmbossStylesSerializable::APP_CONFIG_FONT_DEPTH = "depth";
|
||||
const std::string EmbossStylesSerializable::APP_CONFIG_FONT_USE_SURFACE = "use_surface";
|
||||
const std::string EmbossStylesSerializable::APP_CONFIG_FONT_BOLDNESS = "boldness";
|
||||
const std::string EmbossStylesSerializable::APP_CONFIG_FONT_SKEW = "skew";
|
||||
const std::string EmbossStylesSerializable::APP_CONFIG_FONT_DISTANCE = "distance";
|
||||
const std::string EmbossStylesSerializable::APP_CONFIG_FONT_ANGLE = "angle";
|
||||
const std::string EmbossStylesSerializable::APP_CONFIG_FONT_COLLECTION = "collection";
|
||||
const std::string EmbossStylesSerializable::APP_CONFIG_FONT_CHAR_GAP = "char_gap";
|
||||
const std::string EmbossStylesSerializable::APP_CONFIG_FONT_LINE_GAP = "line_gap";
|
||||
|
||||
const std::string FontListSerializable::APP_CONFIG_ACTIVE_FONT = "activ_font";
|
||||
const std::string EmbossStylesSerializable::APP_CONFIG_ACTIVE_FONT = "activ_font";
|
||||
|
||||
std::string FontListSerializable::create_section_name(unsigned index)
|
||||
std::string EmbossStylesSerializable::create_section_name(unsigned index)
|
||||
{
|
||||
return AppConfig::SECTION_FONT + ':' + std::to_string(index);
|
||||
}
|
||||
|
||||
// check only existence of flag
|
||||
bool FontListSerializable::read(const std::map<std::string, std::string>& section, const std::string& key, bool& value){
|
||||
bool EmbossStylesSerializable::read(const std::map<std::string, std::string>& section, const std::string& key, bool& value){
|
||||
auto item = section.find(key);
|
||||
if (item == section.end()) return false;
|
||||
|
||||
@ -36,7 +36,7 @@ bool FontListSerializable::read(const std::map<std::string, std::string>& sectio
|
||||
}
|
||||
|
||||
#include "fast_float/fast_float.h"
|
||||
bool FontListSerializable::read(const std::map<std::string, std::string>& section, const std::string& key, float& value){
|
||||
bool EmbossStylesSerializable::read(const std::map<std::string, std::string>& section, const std::string& key, float& value){
|
||||
auto item = section.find(key);
|
||||
if (item == section.end()) return false;
|
||||
const std::string &data = item->second;
|
||||
@ -50,7 +50,7 @@ bool FontListSerializable::read(const std::map<std::string, std::string>& sectio
|
||||
return true;
|
||||
}
|
||||
|
||||
bool FontListSerializable::read(const std::map<std::string, std::string>& section, const std::string& key, std::optional<int>& value){
|
||||
bool EmbossStylesSerializable::read(const std::map<std::string, std::string>& section, const std::string& key, std::optional<int>& value){
|
||||
auto item = section.find(key);
|
||||
if (item == section.end()) return false;
|
||||
const std::string &data = item->second;
|
||||
@ -62,7 +62,7 @@ bool FontListSerializable::read(const std::map<std::string, std::string>& sectio
|
||||
return true;
|
||||
}
|
||||
|
||||
bool FontListSerializable::read(const std::map<std::string, std::string>& section, const std::string& key, std::optional<unsigned int>& value){
|
||||
bool EmbossStylesSerializable::read(const std::map<std::string, std::string>& section, const std::string& key, std::optional<unsigned int>& value){
|
||||
auto item = section.find(key);
|
||||
if (item == section.end()) return false;
|
||||
const std::string &data = item->second;
|
||||
@ -74,7 +74,7 @@ bool FontListSerializable::read(const std::map<std::string, std::string>& sectio
|
||||
return true;
|
||||
}
|
||||
|
||||
bool FontListSerializable::read(const std::map<std::string, std::string>& section, const std::string& key, std::optional<float>& value){
|
||||
bool EmbossStylesSerializable::read(const std::map<std::string, std::string>& section, const std::string& key, std::optional<float>& value){
|
||||
auto item = section.find(key);
|
||||
if (item == section.end()) return false;
|
||||
const std::string &data = item->second;
|
||||
@ -88,7 +88,7 @@ bool FontListSerializable::read(const std::map<std::string, std::string>& sectio
|
||||
return true;
|
||||
}
|
||||
|
||||
std::optional<FontItem> FontListSerializable::load_font_item(
|
||||
std::optional<EmbossStyle> EmbossStylesSerializable::load_font_item(
|
||||
const std::map<std::string, std::string> &app_cfg_section)
|
||||
{
|
||||
auto path_it = app_cfg_section.find(APP_CONFIG_FONT_DESCRIPTOR);
|
||||
@ -113,12 +113,12 @@ std::optional<FontItem> FontListSerializable::load_font_item(
|
||||
read(app_cfg_section, APP_CONFIG_FONT_CHAR_GAP, fp.char_gap);
|
||||
read(app_cfg_section, APP_CONFIG_FONT_LINE_GAP, fp.line_gap);
|
||||
|
||||
FontItem::Type type = WxFontUtils::get_actual_type();
|
||||
return FontItem{ name, path, type, fp };
|
||||
EmbossStyle::Type type = WxFontUtils::get_actual_type();
|
||||
return EmbossStyle{ name, path, type, fp };
|
||||
}
|
||||
|
||||
void FontListSerializable::store_font_item(AppConfig & cfg,
|
||||
const FontItem &fi,
|
||||
void EmbossStylesSerializable::store_font_item(AppConfig & cfg,
|
||||
const EmbossStyle &fi,
|
||||
unsigned index)
|
||||
{
|
||||
std::string section_name = create_section_name(index);
|
||||
@ -146,7 +146,7 @@ void FontListSerializable::store_font_item(AppConfig & cfg,
|
||||
cfg.set(section_name, APP_CONFIG_FONT_LINE_GAP, std::to_string(*fp.line_gap));
|
||||
}
|
||||
|
||||
void FontListSerializable::store_font_index(AppConfig &cfg, unsigned index) {
|
||||
void EmbossStylesSerializable::store_font_index(AppConfig &cfg, unsigned index) {
|
||||
// store actual font index
|
||||
cfg.clear_section(AppConfig::SECTION_FONT);
|
||||
// activ font first index is +1 to correspond with section name
|
||||
@ -154,7 +154,7 @@ void FontListSerializable::store_font_index(AppConfig &cfg, unsigned index) {
|
||||
cfg.set(AppConfig::SECTION_FONT, APP_CONFIG_ACTIVE_FONT, activ_font);
|
||||
}
|
||||
|
||||
std::optional<size_t> FontListSerializable::load_font_index(const AppConfig &cfg)
|
||||
std::optional<size_t> EmbossStylesSerializable::load_font_index(const AppConfig &cfg)
|
||||
{
|
||||
if (!cfg.has_section(AppConfig::SECTION_FONT)) return {};
|
||||
|
||||
@ -167,29 +167,29 @@ std::optional<size_t> FontListSerializable::load_font_index(const AppConfig &cfg
|
||||
return active_font - 1;
|
||||
}
|
||||
|
||||
FontList FontListSerializable::load_font_list(const AppConfig &cfg)
|
||||
EmbossStyles EmbossStylesSerializable::load_font_list(const AppConfig &cfg)
|
||||
{
|
||||
FontList result;
|
||||
EmbossStyles result;
|
||||
// human readable index inside of config starts from 1 !!
|
||||
unsigned index = 1;
|
||||
std::string section_name = create_section_name(
|
||||
index);
|
||||
while (cfg.has_section(section_name)) {
|
||||
std::optional<FontItem> fi = load_font_item(cfg.get_section(section_name));
|
||||
if (fi.has_value()) result.emplace_back(*fi);
|
||||
std::optional<EmbossStyle> style_opt = load_font_item(cfg.get_section(section_name));
|
||||
if (style_opt.has_value()) result.emplace_back(*style_opt);
|
||||
section_name = create_section_name(++index);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void FontListSerializable::store_font_list(AppConfig &cfg, const FontList font_list)
|
||||
void EmbossStylesSerializable::store_font_list(AppConfig &cfg, const EmbossStyles font_list)
|
||||
{
|
||||
// store styles
|
||||
unsigned index = 1;
|
||||
for (const FontItem &fi : font_list) {
|
||||
for (const EmbossStyle &fi : font_list) {
|
||||
// skip file paths + fonts from other OS(loaded from .3mf)
|
||||
assert(fi.type == WxFontUtils::get_actual_type());
|
||||
// if (fi.type != WxFontUtils::get_actual_type()) continue;
|
||||
// if (style_opt.type != WxFontUtils::get_actual_type()) continue;
|
||||
store_font_item(cfg, fi, index++);
|
||||
}
|
||||
|
@ -1,10 +1,10 @@
|
||||
#ifndef slic3r_FontListSerializable_hpp_
|
||||
#define slic3r_FontListSerializable_hpp_
|
||||
#ifndef slic3r_EmbossStylesSerializable_hpp_
|
||||
#define slic3r_EmbossStylesSerializable_hpp_
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <optional>
|
||||
#include <libslic3r/TextConfiguration.hpp> // FontList+FontItem
|
||||
#include <libslic3r/TextConfiguration.hpp> // EmbossStyles+EmbossStyle
|
||||
|
||||
namespace Slic3r {
|
||||
class AppConfig;
|
||||
@ -15,7 +15,7 @@ namespace Slic3r::GUI {
|
||||
/// <summary>
|
||||
/// For store/load font list to/from AppConfig
|
||||
/// </summary>
|
||||
class FontListSerializable
|
||||
class EmbossStylesSerializable
|
||||
{
|
||||
static const std::string APP_CONFIG_FONT_NAME;
|
||||
static const std::string APP_CONFIG_FONT_DESCRIPTOR;
|
||||
@ -32,18 +32,18 @@ class FontListSerializable
|
||||
|
||||
static const std::string APP_CONFIG_ACTIVE_FONT;
|
||||
public:
|
||||
FontListSerializable() = delete;
|
||||
EmbossStylesSerializable() = delete;
|
||||
|
||||
static void store_font_index(AppConfig &cfg, unsigned index);
|
||||
static std::optional<size_t> load_font_index(const AppConfig &cfg);
|
||||
|
||||
static FontList load_font_list(const AppConfig &cfg);
|
||||
static void store_font_list(AppConfig &cfg, const FontList font_list);
|
||||
static EmbossStyles load_font_list(const AppConfig &cfg);
|
||||
static void store_font_list(AppConfig &cfg, const EmbossStyles font_list);
|
||||
|
||||
private:
|
||||
static std::string create_section_name(unsigned index);
|
||||
static std::optional<FontItem> load_font_item(const std::map<std::string, std::string> &app_cfg_section);
|
||||
static void store_font_item(AppConfig &cfg, const FontItem &fi, unsigned index);
|
||||
static std::optional<EmbossStyle> load_font_item(const std::map<std::string, std::string> &app_cfg_section);
|
||||
static void store_font_item(AppConfig &cfg, const EmbossStyle &fi, unsigned index);
|
||||
|
||||
// TODO: move to app config like read from section
|
||||
static bool read(const std::map<std::string, std::string>& section, const std::string& key, bool& value);
|
||||
@ -54,5 +54,5 @@ private:
|
||||
};
|
||||
} // namespace Slic3r
|
||||
|
||||
#endif // #define slic3r_FontListSerializable_hpp_
|
||||
#endif // #define slic3r_EmbossStylesSerializable_hpp_
|
||||
|
@ -98,24 +98,24 @@ std::unique_ptr<Emboss::FontFile> WxFontUtils::create_font_file(const wxFont &fo
|
||||
#endif
|
||||
}
|
||||
|
||||
FontItem::Type WxFontUtils::get_actual_type()
|
||||
EmbossStyle::Type WxFontUtils::get_actual_type()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
return FontItem::Type::wx_win_font_descr;
|
||||
return EmbossStyle::Type::wx_win_font_descr;
|
||||
#elif defined(__APPLE__)
|
||||
return FontItem::Type::wx_mac_font_descr;
|
||||
return EmbossStyle::Type::wx_mac_font_descr;
|
||||
#elif defined(__linux__)
|
||||
return FontItem::Type::wx_lin_font_descr;
|
||||
return EmbossStyle::Type::wx_lin_font_descr;
|
||||
#else
|
||||
return FontItem::Type::undefined;
|
||||
return EmbossStyle::Type::undefined;
|
||||
#endif
|
||||
}
|
||||
|
||||
FontItem WxFontUtils::get_font_item(const wxFont &font, const std::string& name)
|
||||
EmbossStyle WxFontUtils::create_emboss_style(const wxFont &font, const std::string& name)
|
||||
{
|
||||
std::string name_item = name.empty()? get_human_readable_name(font) : name;
|
||||
std::string fontDesc = store_wxFont(font);
|
||||
FontItem::Type type = get_actual_type();
|
||||
EmbossStyle::Type type = get_actual_type();
|
||||
|
||||
// synchronize font property with actual font
|
||||
FontProp font_prop;
|
||||
@ -123,13 +123,13 @@ FontItem WxFontUtils::get_font_item(const wxFont &font, const std::string& name)
|
||||
return { name_item, fontDesc, type, font_prop };
|
||||
}
|
||||
|
||||
FontItem WxFontUtils::get_os_font()
|
||||
EmbossStyle WxFontUtils::get_os_font()
|
||||
{
|
||||
wxSystemFont system_font = wxSYS_DEFAULT_GUI_FONT;
|
||||
wxFont font = wxSystemSettings::GetFont(system_font);
|
||||
FontItem fi = get_font_item(font);
|
||||
fi.name += std::string(" (OS default)");
|
||||
return get_font_item(font);
|
||||
EmbossStyle es = create_emboss_style(font);
|
||||
es.name += std::string(" (OS default)");
|
||||
return create_emboss_style(font);
|
||||
}
|
||||
|
||||
std::string WxFontUtils::get_human_readable_name(const wxFont &font)
|
||||
@ -194,7 +194,7 @@ const TypeToWeight WxFontUtils::type_to_weight =
|
||||
(wxFONTWEIGHT_HEAVY, "heavy")
|
||||
(wxFONTWEIGHT_EXTRAHEAVY, "extraHeavy");
|
||||
|
||||
std::optional<wxFont> WxFontUtils::create_wxFont(const FontItem &fi)
|
||||
std::optional<wxFont> WxFontUtils::create_wxFont(const EmbossStyle &fi)
|
||||
{
|
||||
const FontProp &fp = fi.prop;
|
||||
double point_size = static_cast<double>(fp.size_in_mm);
|
||||
@ -217,12 +217,12 @@ std::optional<wxFont> WxFontUtils::create_wxFont(const FontItem &fi)
|
||||
}
|
||||
|
||||
// Improve: load descriptor instead of store to font property to 3mf
|
||||
// switch (fi.type) {
|
||||
// case FontItem::Type::wx_lin_font_descr:
|
||||
// case FontItem::Type::wx_win_font_descr:
|
||||
// case FontItem::Type::wx_mac_font_descr:
|
||||
// case FontItem::Type::file_path:
|
||||
// case FontItem::Type::undefined:
|
||||
// switch (es.type) {
|
||||
// case EmbossStyle::Type::wx_lin_font_descr:
|
||||
// case EmbossStyle::Type::wx_win_font_descr:
|
||||
// case EmbossStyle::Type::wx_mac_font_descr:
|
||||
// case EmbossStyle::Type::file_path:
|
||||
// case EmbossStyle::Type::undefined:
|
||||
// default:
|
||||
//}
|
||||
|
||||
|
@ -24,11 +24,11 @@ public:
|
||||
// os specific load of wxFont
|
||||
static std::unique_ptr<Slic3r::Emboss::FontFile> create_font_file(const wxFont &font);
|
||||
|
||||
static FontItem::Type get_actual_type();
|
||||
static FontItem get_font_item(const wxFont &font, const std::string& name = "");
|
||||
static EmbossStyle::Type get_actual_type();
|
||||
static EmbossStyle create_emboss_style(const wxFont &font, const std::string& name = "");
|
||||
|
||||
// load font used by Operating system as default GUI
|
||||
static FontItem get_os_font();
|
||||
static EmbossStyle get_os_font();
|
||||
static std::string get_human_readable_name(const wxFont &font);
|
||||
|
||||
// serialize / deserialize font
|
||||
@ -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 FontItem &fi);
|
||||
static std::optional<wxFont> create_wxFont(const EmbossStyle &fi);
|
||||
// update font property by wxFont
|
||||
static void update_property(FontProp &font_prop, const wxFont &font);
|
||||
|
||||
|
@ -136,7 +136,7 @@ TEST_CASE("CutSurface in 3mf", "[Emboss]")
|
||||
CHECK(mv_text->text_configuration.has_value());
|
||||
TextConfiguration &tc = *mv_text->text_configuration;
|
||||
/* // Need GUI to load font by wx
|
||||
std::optional<wxFont> wx_font = GUI::WxFontUtils::load_wxFont(tc.font_item.path);
|
||||
std::optional<wxFont> wx_font = GUI::WxFontUtils::load_wxFont(tc.style.path);
|
||||
CHECK(wx_font.has_value());
|
||||
Emboss::FontFileWithCache ff(GUI::WxFontUtils::create_font_file(*wx_font));
|
||||
CHECK(ff.font_file != nullptr);
|
||||
@ -157,7 +157,7 @@ TEST_CASE("CutSurface in 3mf", "[Emboss]")
|
||||
|
||||
std::pair<float, float> z_range{mesh_bb_tr.min.z(), mesh_bb_tr.max.z()};
|
||||
|
||||
FontProp fp = tc.font_item.prop;
|
||||
FontProp fp = tc.style.prop;
|
||||
ExPolygons shapes = Emboss::text2shapes(ff, tc.text.c_str(), fp);
|
||||
double shape_scale = Emboss::get_shape_scale(fp, *ff.font_file);
|
||||
|
||||
@ -165,7 +165,7 @@ TEST_CASE("CutSurface in 3mf", "[Emboss]")
|
||||
cut_projection_tr, shape_scale, get_extents(shapes), z_range);
|
||||
|
||||
float projection_ratio = -z_range.first / (z_range.second - z_range.first);
|
||||
SurfaceCut cut = cut_surface(shapes, its, projection, projection_ratio);
|
||||
SurfaceCut cut = cut_surface(shapes, its, projection, projection_ratio);
|
||||
its_write_obj(cut, "C:/data/temp/cutSurface/result_cut.obj");
|
||||
}
|
||||
|
||||
|
@ -346,11 +346,11 @@ TEST_CASE("UndoRedo serialization", "[Emboss]")
|
||||
{
|
||||
TextConfiguration tc;
|
||||
tc.text = "Dovede-li se člověk zasmát sám sobě, nevyjde ze smíchu po celý život.";
|
||||
FontItem& fi = tc.font_item;
|
||||
fi.name = "Seneca";
|
||||
fi.path = "Simply the best";
|
||||
fi.type = FontItem::Type::file_path;
|
||||
FontProp &fp = fi.prop;
|
||||
EmbossStyle& es = tc.style;
|
||||
es.name = "Seneca";
|
||||
es.path = "Simply the best";
|
||||
es.type = EmbossStyle::Type::file_path;
|
||||
FontProp &fp = es.prop;
|
||||
fp.angle = 100.;
|
||||
fp.distance = 10.;
|
||||
fp.char_gap = 1;
|
||||
@ -369,7 +369,7 @@ TEST_CASE("UndoRedo serialization", "[Emboss]")
|
||||
cereal::BinaryInputArchive iarchive(ss); // Create an input archive
|
||||
iarchive(tc_loaded);
|
||||
}
|
||||
CHECK(tc.font_item == tc_loaded.font_item);
|
||||
CHECK(tc.style == tc_loaded.style);
|
||||
CHECK(tc.text == tc_loaded.text);
|
||||
CHECK(tc.fix_3mf_tr.has_value() == tc_loaded.fix_3mf_tr.has_value());
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user