mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-15 19:05:55 +08:00
Clean process of initialization of style images, do not use manager pointer(could be released)
This commit is contained in:
parent
501f6f021f
commit
05b6d3578d
@ -13,9 +13,14 @@ using namespace Slic3r;
|
|||||||
using namespace Slic3r::GUI;
|
using namespace Slic3r::GUI;
|
||||||
|
|
||||||
|
|
||||||
CreateFontStyleImagesJob::CreateFontStyleImagesJob(StyleImagesData &&input)
|
CreateFontStyleImagesJob::CreateFontStyleImagesJob(
|
||||||
|
FontManager::StyleImagesData &&input)
|
||||||
: m_input(std::move(input))
|
: m_input(std::move(input))
|
||||||
{}
|
{
|
||||||
|
assert(m_input.result != nullptr);
|
||||||
|
assert(!m_input.styles.empty());
|
||||||
|
assert(m_input.max_width > 1);
|
||||||
|
}
|
||||||
|
|
||||||
void CreateFontStyleImagesJob::process(Ctl &ctl)
|
void CreateFontStyleImagesJob::process(Ctl &ctl)
|
||||||
{
|
{
|
||||||
@ -24,7 +29,7 @@ void CreateFontStyleImagesJob::process(Ctl &ctl)
|
|||||||
std::vector<double> scales(m_input.styles.size());
|
std::vector<double> scales(m_input.styles.size());
|
||||||
images = std::vector<FontManager::StyleImage>(m_input.styles.size());
|
images = std::vector<FontManager::StyleImage>(m_input.styles.size());
|
||||||
|
|
||||||
for (StyleImagesData::Item &item : m_input.styles) {
|
for (auto &item : m_input.styles) {
|
||||||
size_t index = &item - &m_input.styles.front();
|
size_t index = &item - &m_input.styles.front();
|
||||||
ExPolygons &shapes = name_shapes[index];
|
ExPolygons &shapes = name_shapes[index];
|
||||||
shapes = Emboss::text2shapes(item.font, item.text.c_str(), item.prop);
|
shapes = Emboss::text2shapes(item.font, item.text.c_str(), item.prop);
|
||||||
@ -124,20 +129,12 @@ void CreateFontStyleImagesJob::finalize(bool canceled, std::exception_ptr &)
|
|||||||
|
|
||||||
// set up texture id
|
// set up texture id
|
||||||
void *texture_id = (void *) (intptr_t) tex_id;
|
void *texture_id = (void *) (intptr_t) tex_id;
|
||||||
for (FontManager::StyleImage &image : images) {
|
for (FontManager::StyleImage &image : images)
|
||||||
image.texture_id = texture_id;
|
image.texture_id = texture_id;
|
||||||
size_t index = &image - &images.front();
|
|
||||||
StyleImagesData::Item &style = m_input.styles[index];
|
|
||||||
|
|
||||||
// find manager image and copy to it
|
// move to result
|
||||||
for (auto& it: m_input.mng->m_font_list) {
|
m_input.result->styles = std::move(m_input.styles);
|
||||||
if (it.font_item.name != style.text ||
|
m_input.result->images = std::move(images);
|
||||||
!(it.font_item.prop == style.prop))
|
|
||||||
continue;
|
|
||||||
it.image = image;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// bind default texture
|
// bind default texture
|
||||||
GLuint no_texture_id = 0;
|
GLuint no_texture_id = 0;
|
||||||
|
@ -9,29 +9,6 @@
|
|||||||
|
|
||||||
namespace Slic3r::GUI {
|
namespace Slic3r::GUI {
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Data needed to create Font Style Images
|
|
||||||
/// </summary>
|
|
||||||
struct StyleImagesData
|
|
||||||
{
|
|
||||||
struct Item
|
|
||||||
{
|
|
||||||
Emboss::FontFileWithCache font;
|
|
||||||
std::string text;
|
|
||||||
FontProp prop;
|
|
||||||
};
|
|
||||||
using Items = std::vector<Item>;
|
|
||||||
|
|
||||||
// Keep styles to render
|
|
||||||
Items styles;
|
|
||||||
|
|
||||||
// maximal width in pixels of image
|
|
||||||
int max_width;
|
|
||||||
|
|
||||||
// is used in finalize to set result
|
|
||||||
// and I Can't proof of alive
|
|
||||||
FontManager *mng;
|
|
||||||
};
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create texture with name of styles written by its style
|
/// Create texture with name of styles written by its style
|
||||||
@ -39,7 +16,7 @@ struct StyleImagesData
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
class CreateFontStyleImagesJob : public Job
|
class CreateFontStyleImagesJob : public Job
|
||||||
{
|
{
|
||||||
StyleImagesData m_input;
|
FontManager::StyleImagesData m_input;
|
||||||
|
|
||||||
// Output data
|
// Output data
|
||||||
// texture size
|
// texture size
|
||||||
@ -50,7 +27,7 @@ class CreateFontStyleImagesJob : public Job
|
|||||||
std::vector<FontManager::StyleImage> images;
|
std::vector<FontManager::StyleImage> images;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CreateFontStyleImagesJob(StyleImagesData &&input);
|
CreateFontStyleImagesJob(FontManager::StyleImagesData &&input);
|
||||||
void process(Ctl &ctl) override;
|
void process(Ctl &ctl) override;
|
||||||
void finalize(bool canceled, std::exception_ptr &) override;
|
void finalize(bool canceled, std::exception_ptr &) override;
|
||||||
};
|
};
|
||||||
|
@ -15,6 +15,7 @@ FontManager::FontManager(const ImWchar *language_glyph_range)
|
|||||||
: m_imgui_init_glyph_range(language_glyph_range)
|
: m_imgui_init_glyph_range(language_glyph_range)
|
||||||
, m_font_selected(std::numeric_limits<size_t>::max())
|
, m_font_selected(std::numeric_limits<size_t>::max())
|
||||||
, m_exist_style_images(false)
|
, m_exist_style_images(false)
|
||||||
|
, m_temp_style_images(nullptr)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
FontManager::~FontManager() {
|
FontManager::~FontManager() {
|
||||||
@ -382,6 +383,36 @@ void FontManager::init_style_images(int max_width) {
|
|||||||
// check already initialized
|
// check already initialized
|
||||||
if (m_exist_style_images) return;
|
if (m_exist_style_images) return;
|
||||||
|
|
||||||
|
// check is initializing
|
||||||
|
if (m_temp_style_images != nullptr) {
|
||||||
|
// is initialization finished
|
||||||
|
if (!m_temp_style_images->styles.empty()) {
|
||||||
|
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){
|
||||||
|
size_t index = &image - &m_temp_style_images->images.front();
|
||||||
|
StyleImagesData::Item &style = m_temp_style_images->styles[index];
|
||||||
|
|
||||||
|
// find style in font list and copy to it
|
||||||
|
for (auto &it : m_font_list) {
|
||||||
|
if (it.font_item.name != style.text ||
|
||||||
|
!(it.font_item.prop == style.prop))
|
||||||
|
continue;
|
||||||
|
it.image = image;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m_temp_style_images = nullptr;
|
||||||
|
m_exist_style_images = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// in process of initialization inside of job
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// create job for init images
|
||||||
|
m_temp_style_images = std::make_shared<StyleImagesData::StyleImages>();
|
||||||
StyleImagesData::Items styles;
|
StyleImagesData::Items styles;
|
||||||
styles.reserve(m_font_list.size());
|
styles.reserve(m_font_list.size());
|
||||||
for (Item &item : m_font_list) {
|
for (Item &item : m_font_list) {
|
||||||
@ -396,10 +427,8 @@ void FontManager::init_style_images(int max_width) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto &worker = wxGetApp().plater()->get_ui_job_worker();
|
auto &worker = wxGetApp().plater()->get_ui_job_worker();
|
||||||
StyleImagesData data{styles, max_width, this};
|
StyleImagesData data{std::move(styles), max_width, m_temp_style_images};
|
||||||
queue_job(worker, std::make_unique<CreateFontStyleImagesJob>(std::move(data)));
|
queue_job(worker, std::make_unique<CreateFontStyleImagesJob>(std::move(data)));
|
||||||
|
|
||||||
m_exist_style_images = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FontManager::free_style_images() {
|
void FontManager::free_style_images() {
|
||||||
|
@ -17,7 +17,7 @@ namespace Slic3r::GUI {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
class FontManager
|
class FontManager
|
||||||
{
|
{
|
||||||
friend class CreateFontStyleImagesJob;
|
friend class CreateFontStyleImagesJob; // access to StyleImagesData
|
||||||
|
|
||||||
public:
|
public:
|
||||||
FontManager(const ImWchar *language_glyph_range);
|
FontManager(const ImWchar *language_glyph_range);
|
||||||
@ -196,6 +196,40 @@ private:
|
|||||||
std::vector<Item> m_font_list;
|
std::vector<Item> m_font_list;
|
||||||
size_t m_font_selected; // index to m_font_list
|
size_t m_font_selected; // index to m_font_list
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Keep data needed to create Font Style Images in Job
|
||||||
|
/// </summary>
|
||||||
|
struct StyleImagesData
|
||||||
|
{
|
||||||
|
struct Item
|
||||||
|
{
|
||||||
|
Emboss::FontFileWithCache font;
|
||||||
|
std::string text;
|
||||||
|
FontProp prop;
|
||||||
|
};
|
||||||
|
using Items = std::vector<Item>;
|
||||||
|
|
||||||
|
// Keep styles to render
|
||||||
|
Items styles;
|
||||||
|
|
||||||
|
// Maximal width in pixels of image
|
||||||
|
int max_width;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Result of job
|
||||||
|
/// </summary>
|
||||||
|
struct StyleImages
|
||||||
|
{
|
||||||
|
// vector of inputs
|
||||||
|
StyleImagesData::Items styles;
|
||||||
|
// job output
|
||||||
|
std::vector<FontManager::StyleImage> images;
|
||||||
|
};
|
||||||
|
|
||||||
|
// place to store result in main thread in Finalize
|
||||||
|
std::shared_ptr<StyleImages> result;
|
||||||
|
};
|
||||||
|
std::shared_ptr<StyleImagesData::StyleImages> m_temp_style_images;
|
||||||
bool m_exist_style_images;
|
bool m_exist_style_images;
|
||||||
|
|
||||||
// store all font GLImages
|
// store all font GLImages
|
||||||
|
Loading…
x
Reference in New Issue
Block a user