Rename FontManager to EmbossStyleManager

This commit is contained in:
Filip Sykala - NTB T15p 2022-08-03 09:11:00 +02:00
parent ef3a2e2744
commit 4267af64e5
6 changed files with 68 additions and 68 deletions

View File

@ -1131,11 +1131,11 @@ void GLGizmoEmboss::draw_text_input()
append_warning(_u8L("Line gap"),
_u8L("Unsupported visualization of gap between lines inside text input."));
auto &ff = m_style_manager.get_font_file_with_cache();
float imgui_size = FontManager::get_imgui_font_size(prop, *ff.font_file);
if (imgui_size > FontManager::max_imgui_font_size)
float imgui_size = EmbossStyleManager::get_imgui_font_size(prop, *ff.font_file);
if (imgui_size > EmbossStyleManager::max_imgui_font_size)
append_warning(_u8L("To tall"),
_u8L("Diminished font height inside text input."));
if (imgui_size < FontManager::min_imgui_font_size)
if (imgui_size < EmbossStyleManager::min_imgui_font_size)
append_warning(_u8L("To small"),
_u8L("Enlarged font height inside text input."));
if (!who.empty())
@ -1779,7 +1779,7 @@ void GLGizmoEmboss::discard_changes_in_style()
void GLGizmoEmboss::draw_revert_all_styles_button() {
if (draw_button(IconType::revert_all)) {
m_style_manager = FontManager(m_imgui->get_glyph_ranges());
m_style_manager = EmbossStyleManager(m_imgui->get_glyph_ranges());
m_style_manager.init(nullptr, create_default_font_list());
assert(m_style_manager.get_font_file_with_cache().has_value());
process();
@ -1808,7 +1808,7 @@ void GLGizmoEmboss::draw_style_list() {
m_style_manager.init_style_images(m_gui_cfg->max_style_image_size, m_text);
m_style_manager.init_trunc_names(max_style_name_width);
std::optional<std::pair<size_t,size_t>> swap_indexes;
const std::vector<FontManager::Item> &styles = m_style_manager.get_styles();
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;
@ -1817,7 +1817,7 @@ void GLGizmoEmboss::draw_style_list() {
bool is_selected = (&fi == &actual_font_item);
ImVec2 select_size(0,m_gui_cfg->max_style_image_size.y()); // 0,0 --> calculate in draw
const std::optional<FontManager::StyleImage> img = item.image;
const std::optional<EmbossStyleManager::StyleImage> img = item.image;
// allow click delete button
ImGuiSelectableFlags_ flags = ImGuiSelectableFlags_AllowItemOverlap;
if (ImGui::Selectable(item.truncated_name.c_str(), is_selected, flags, select_size)) {
@ -2653,7 +2653,7 @@ bool GLGizmoEmboss::load_configuration(ModelVolume *volume)
TextConfiguration &tc = *volume->text_configuration;
FontItem &tc_fi = tc.font_item;
auto has_same_name = [&tc_fi](const FontManager::Item &font_item) -> bool {
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;
};

View File

@ -215,7 +215,7 @@ private:
std::optional<ImVec2> m_set_window_offset;
bool m_is_advanced_edit_style = false;
FontManager m_style_manager;
EmbossStyleManager m_style_manager;
// Keep sorted list of loadable face names
struct Facenames

View File

@ -14,7 +14,7 @@ using namespace Slic3r::GUI;
CreateFontStyleImagesJob::CreateFontStyleImagesJob(
FontManager::StyleImagesData &&input)
EmbossStyleManager::StyleImagesData &&input)
: m_input(std::move(input))
{
assert(m_input.result != nullptr);
@ -29,7 +29,7 @@ void CreateFontStyleImagesJob::process(Ctl &ctl)
// create shapes and calc size (bounding boxes)
std::vector<ExPolygons> name_shapes(m_input.styles.size());
std::vector<double> scales(m_input.styles.size());
images = std::vector<FontManager::StyleImage>(m_input.styles.size());
images = std::vector<EmbossStyleManager::StyleImage>(m_input.styles.size());
for (auto &item : m_input.styles) {
size_t index = &item - &m_input.styles.front();
@ -37,7 +37,7 @@ void CreateFontStyleImagesJob::process(Ctl &ctl)
shapes = Emboss::text2shapes(item.font, m_input.text.c_str(), item.prop);
// create image description
FontManager::StyleImage &image = images[index];
EmbossStyleManager::StyleImage &image = images[index];
BoundingBox &bounding_box = image.bounding_box;
for (ExPolygon &shape : shapes)
bounding_box.merge(BoundingBox(shape.contour.points));
@ -72,14 +72,14 @@ void CreateFontStyleImagesJob::process(Ctl &ctl)
// arrange bounding boxes
int offset_y = 0;
width = 0;
for (FontManager::StyleImage &image : images) {
for (EmbossStyleManager::StyleImage &image : images) {
image.offset.y() = offset_y;
offset_y += image.tex_size.y+1;
if (width < image.tex_size.x)
width = image.tex_size.x;
}
height = offset_y;
for (FontManager::StyleImage &image : images) {
for (EmbossStyleManager::StyleImage &image : images) {
const Point &o = image.offset;
const ImVec2 &s = image.tex_size;
image.uv0 = ImVec2(o.x() / (double) width,
@ -92,7 +92,7 @@ void CreateFontStyleImagesJob::process(Ctl &ctl)
pixels = std::vector<unsigned char>(width * height, {0});
// upload sub textures
for (FontManager::StyleImage &image : images) {
for (EmbossStyleManager::StyleImage &image : images) {
sla::Resolution resolution(image.tex_size.x, image.tex_size.y);
size_t index = &image - &images.front();
double pixel_dim = SCALING_FACTOR / scales[index];
@ -140,7 +140,7 @@ void CreateFontStyleImagesJob::finalize(bool canceled, std::exception_ptr &)
// set up texture id
void *texture_id = (void *) (intptr_t) tex_id;
for (FontManager::StyleImage &image : images)
for (EmbossStyleManager::StyleImage &image : images)
image.texture_id = texture_id;
// move to result

View File

@ -15,7 +15,7 @@ namespace Slic3r::GUI {
/// </summary>
class CreateFontStyleImagesJob : public Job
{
FontManager::StyleImagesData m_input;
EmbossStyleManager::StyleImagesData m_input;
// Output data
// texture size
@ -23,10 +23,10 @@ class CreateFontStyleImagesJob : public Job
// texture data
std::vector<unsigned char> pixels;
// descriptors of sub textures
std::vector<FontManager::StyleImage> images;
std::vector<EmbossStyleManager::StyleImage> images;
public:
CreateFontStyleImagesJob(FontManager::StyleImagesData &&input);
CreateFontStyleImagesJob(EmbossStyleManager::StyleImagesData &&input);
void process(Ctl &ctl) override;
void finalize(bool canceled, std::exception_ptr &) override;
};

View File

@ -14,7 +14,7 @@
using namespace Slic3r;
using namespace Slic3r::GUI;
FontManager::FontManager(const ImWchar *language_glyph_range)
EmbossStyleManager::EmbossStyleManager(const ImWchar *language_glyph_range)
: m_imgui_init_glyph_range(language_glyph_range)
, m_exist_style_images(false)
, m_change_order(false)
@ -22,12 +22,12 @@ FontManager::FontManager(const ImWchar *language_glyph_range)
, m_temp_style_images(nullptr)
{}
FontManager::~FontManager() {
EmbossStyleManager::~EmbossStyleManager() {
clear_imgui_font();
free_style_images();
}
void FontManager::init(const AppConfig *cfg, const FontList &default_font_list)
void EmbossStyleManager::init(const AppConfig *cfg, const FontList &default_font_list)
{
FontList font_list = (cfg != nullptr) ?
FontListSerializable::load_font_list(*cfg) :
@ -69,7 +69,7 @@ void FontManager::init(const AppConfig *cfg, const FontList &default_font_list)
}
}
bool FontManager::store_font_list_to_app_config(AppConfig *cfg)
bool EmbossStyleManager::store_font_list_to_app_config(AppConfig *cfg)
{
assert(cfg != nullptr);
if (cfg == nullptr) return false;
@ -95,7 +95,7 @@ bool FontManager::store_font_list_to_app_config(AppConfig *cfg)
return true;
}
void FontManager::store_style(const std::string &name) {
void EmbossStyleManager::store_style(const std::string &name) {
FontItem& fi = m_style_cache.font_item;
fi.name = name;
make_unique_name(fi.name);
@ -105,7 +105,7 @@ void FontManager::store_style(const std::string &name) {
m_style_items.push_back({fi});
}
void FontManager::swap(size_t i1, size_t i2) {
void EmbossStyleManager::swap(size_t i1, size_t i2) {
if (i1 >= m_style_items.size() ||
i2 >= m_style_items.size()) return;
std::swap(m_style_items[i1], m_style_items[i2]);
@ -119,13 +119,13 @@ void FontManager::swap(size_t i1, size_t i2) {
}
}
bool FontManager::is_style_order_changed() const { return m_change_order; }
bool FontManager::is_activ_style_changed() const {
bool EmbossStyleManager::is_style_order_changed() const { return m_change_order; }
bool EmbossStyleManager::is_activ_style_changed() const {
if (m_stored_activ_index == std::numeric_limits<size_t>::max())
return true;
return m_style_cache.font_index != m_stored_activ_index;
};
void FontManager::erase(size_t index) {
void EmbossStyleManager::erase(size_t index) {
if (index >= m_style_items.size()) return;
// fix selected index
@ -138,7 +138,7 @@ void FontManager::erase(size_t index) {
m_style_items.erase(m_style_items.begin() + index);
}
void FontManager::rename(const std::string& name) {
void EmbossStyleManager::rename(const std::string& name) {
m_style_cache.font_item.name = name;
m_style_cache.truncated_name.clear();
if (exist_stored_style()) {
@ -148,7 +148,7 @@ void FontManager::rename(const std::string& name) {
}
}
bool FontManager::wx_font_changed(std::unique_ptr<Emboss::FontFile> font_file)
bool EmbossStyleManager::wx_font_changed(std::unique_ptr<Emboss::FontFile> font_file)
{
if (!is_activ_font()) return false;
auto &wx_font = get_wx_font();
@ -167,7 +167,7 @@ bool FontManager::wx_font_changed(std::unique_ptr<Emboss::FontFile> font_file)
return true;
}
bool FontManager::load_font(size_t font_index)
bool EmbossStyleManager::load_font(size_t font_index)
{
if (font_index >= m_style_items.size()) return false;
if (!load_font(m_style_items[font_index].font_item)) return false;
@ -176,7 +176,7 @@ bool FontManager::load_font(size_t font_index)
return true;
}
bool FontManager::load_font(const FontItem &fi) {
bool EmbossStyleManager::load_font(const FontItem &fi) {
if (fi.type == FontItem::Type::file_path) {
std::unique_ptr<Emboss::FontFile> font_ptr =
Emboss::create_font_file(fi.path.c_str());
@ -195,7 +195,7 @@ bool FontManager::load_font(const FontItem &fi) {
return load_font(fi, *wx_font_opt);
}
bool FontManager::load_font(const FontItem &fi, const wxFont &font)
bool EmbossStyleManager::load_font(const FontItem &fi, const wxFont &font)
{
if (!set_wx_font(font)) return false;
m_style_cache.font_item = fi; // copy
@ -205,9 +205,9 @@ bool FontManager::load_font(const FontItem &fi, const wxFont &font)
return true;
}
bool FontManager::is_activ_font() { return m_style_cache.font_file.has_value(); }
bool EmbossStyleManager::is_activ_font() { return m_style_cache.font_file.has_value(); }
bool FontManager::load_first_valid_font() {
bool EmbossStyleManager::load_first_valid_font() {
while (!m_style_items.empty()) {
if (load_font(0)) return true;
// can't load so erase it from list
@ -216,36 +216,36 @@ bool FontManager::load_first_valid_font() {
return false;
}
const FontItem* FontManager::get_stored_font_item() const
const FontItem* 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;
}
const std::optional<wxFont> &FontManager::get_stored_wx_font() const { return m_style_cache.stored_wx_font; }
const std::optional<wxFont> &EmbossStyleManager::get_stored_wx_font() const { return m_style_cache.stored_wx_font; }
const FontItem &FontManager::get_font_item() const { return m_style_cache.font_item; }
FontItem &FontManager::get_font_item() { return m_style_cache.font_item; }
const FontProp &FontManager::get_font_prop() const { return get_font_item().prop; }
FontProp &FontManager::get_font_prop() { return get_font_item().prop; }
const std::optional<wxFont> &FontManager::get_wx_font() const { return m_style_cache.wx_font; }
std::optional<wxFont> &FontManager::get_wx_font() { return m_style_cache.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 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; }
std::optional<wxFont> &EmbossStyleManager::get_wx_font() { return m_style_cache.wx_font; }
bool FontManager::exist_stored_style() const { return m_style_cache.font_index != std::numeric_limits<size_t>::max(); }
size_t FontManager::get_style_index() const { return m_style_cache.font_index; }
Emboss::FontFileWithCache &FontManager::get_font_file_with_cache() { return m_style_cache.font_file; }
std::string &FontManager::get_truncated_name() { return m_style_cache.truncated_name; }
bool EmbossStyleManager::exist_stored_style() const { return m_style_cache.font_index != std::numeric_limits<size_t>::max(); }
size_t EmbossStyleManager::get_style_index() const { return m_style_cache.font_index; }
Emboss::FontFileWithCache &EmbossStyleManager::get_font_file_with_cache() { return m_style_cache.font_file; }
std::string &EmbossStyleManager::get_truncated_name() { return m_style_cache.truncated_name; }
void FontManager::clear_glyphs_cache()
void EmbossStyleManager::clear_glyphs_cache()
{
Emboss::FontFileWithCache &ff = m_style_cache.font_file;
if (!ff.has_value()) return;
ff.cache = std::make_shared<Emboss::Glyphs>();
}
void FontManager::clear_imgui_font() { m_style_cache.atlas.Clear(); }
void EmbossStyleManager::clear_imgui_font() { m_style_cache.atlas.Clear(); }
ImFont *FontManager::get_imgui_font()
ImFont *EmbossStyleManager::get_imgui_font()
{
if (!is_activ_font()) return nullptr;
@ -265,16 +265,16 @@ ImFont *FontManager::get_imgui_font()
return font;
}
const std::vector<FontManager::Item> &FontManager::get_styles() const{ return m_style_items; }
const std::vector<EmbossStyleManager::Item> &EmbossStyleManager::get_styles() const{ return m_style_items; }
ImFont* FontManager::extend_imgui_font_range(size_t index, const std::string& text)
ImFont* EmbossStyleManager::extend_imgui_font_range(size_t index, const std::string& text)
{
// TODO: start using merge mode
// ImFontConfig::MergeMode = true;
return create_imgui_font(text);
}
void FontManager::make_unique_name(std::string &name)
void EmbossStyleManager::make_unique_name(std::string &name)
{
auto is_unique = [&](const std::string &name) -> bool {
for (const Item &it : m_style_items)
@ -299,7 +299,7 @@ void FontManager::make_unique_name(std::string &name)
name = new_name;
}
void FontManager::init_trunc_names(float max_width) {
void EmbossStyleManager::init_trunc_names(float max_width) {
for (auto &s : m_style_items)
if (s.truncated_name.empty())
s.truncated_name = ImGuiWrapper::trunc(s.font_item.name, max_width);
@ -311,7 +311,7 @@ void FontManager::init_trunc_names(float max_width) {
#include "slic3r/GUI/GUI_App.hpp"
#include "slic3r/GUI/Plater.hpp"
void FontManager::init_style_images(const Vec2i &max_size,
void EmbossStyleManager::init_style_images(const Vec2i &max_size,
const std::string &text)
{
// check already initialized
@ -324,7 +324,7 @@ void FontManager::init_style_images(const Vec2i &max_size,
assert(m_temp_style_images->images.size() ==
m_temp_style_images->styles.size());
// copy images into styles
for (FontManager::StyleImage &image : m_temp_style_images->images){
for (EmbossStyleManager::StyleImage &image : m_temp_style_images->images){
size_t index = &image - &m_temp_style_images->images.front();
StyleImagesData::Item &style = m_temp_style_images->styles[index];
@ -367,7 +367,7 @@ void FontManager::init_style_images(const Vec2i &max_size,
queue_job(worker, std::make_unique<CreateFontStyleImagesJob>(std::move(data)));
}
void FontManager::free_style_images() {
void EmbossStyleManager::free_style_images() {
if (!m_exist_style_images) return;
if (!is_activ_font()) return;
@ -383,9 +383,9 @@ void FontManager::free_style_images() {
m_exist_style_images = false;
}
float FontManager::min_imgui_font_size = 18.f;
float FontManager::max_imgui_font_size = 60.f;
float FontManager::get_imgui_font_size(const FontProp &prop,
float EmbossStyleManager::min_imgui_font_size = 18.f;
float EmbossStyleManager::max_imgui_font_size = 60.f;
float EmbossStyleManager::get_imgui_font_size(const FontProp &prop,
const Emboss::FontFile &file)
{
const auto &cn = prop.collection_number;
@ -400,7 +400,7 @@ float FontManager::get_imgui_font_size(const FontProp &prop,
return c1 * std::abs(prop.size_in_mm) / 0.3528f;
}
ImFont *FontManager::create_imgui_font(const std::string &text)
ImFont *EmbossStyleManager::create_imgui_font(const std::string &text)
{
auto& ff = m_style_cache.font_file;
if (!ff.has_value()) return nullptr;
@ -477,7 +477,7 @@ ImFont *FontManager::create_imgui_font(const std::string &text)
return font;
}
bool FontManager::set_wx_font(const wxFont &wx_font) {
bool EmbossStyleManager::set_wx_font(const wxFont &wx_font) {
std::unique_ptr<Emboss::FontFile> font_file =
WxFontUtils::create_font_file(wx_font);
if (font_file == nullptr) return false;

View File

@ -1,5 +1,5 @@
#ifndef slic3r_FontManager_hpp_
#define slic3r_FontManager_hpp_
#ifndef slic3r_EmbossStyleManager_hpp_
#define slic3r_EmbossStyleManager_hpp_
#include <memory>
#include <optional>
@ -18,13 +18,13 @@ namespace Slic3r::GUI {
/// Keep file data of TTF files
/// Cache wx font objects
/// </summary>
class FontManager
class EmbossStyleManager
{
friend class CreateFontStyleImagesJob; // access to StyleImagesData
public:
FontManager(const ImWchar *language_glyph_range);
~FontManager();
EmbossStyleManager(const ImWchar *language_glyph_range);
~EmbossStyleManager();
/// <summary>
/// Load font style list from config
@ -274,7 +274,7 @@ private:
// vector of inputs
StyleImagesData::Items styles;
// job output
std::vector<FontManager::StyleImage> images;
std::vector<EmbossStyleManager::StyleImage> images;
};
// place to store result in main thread in Finalize
@ -290,4 +290,4 @@ private:
} // namespace Slic3r
#endif // slic3r_FontManager_hpp_
#endif // slic3r_EmbossStyleManager_hpp_