mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-13 15:59:00 +08:00
Remove dependency on main app in job
This commit is contained in:
parent
934da5592c
commit
88af7762fc
@ -2,11 +2,6 @@
|
||||
|
||||
// rasterization of ExPoly
|
||||
#include "libslic3r/SLA/AGGRaster.hpp"
|
||||
|
||||
// for get DPI
|
||||
#include "slic3r/GUI/GUI_App.hpp"
|
||||
#include "slic3r/GUI/MainFrame.hpp"
|
||||
|
||||
#include "slic3r/GUI/3DScene.hpp" // ::glsafe
|
||||
|
||||
// ability to request new frame after finish rendering
|
||||
@ -20,15 +15,15 @@ using namespace Slic3r::GUI;
|
||||
using namespace Slic3r::GUI::Emboss;
|
||||
|
||||
|
||||
CreateFontStyleImagesJob::CreateFontStyleImagesJob(
|
||||
StyleManager::StyleImagesData &&input)
|
||||
: m_input(std::move(input))
|
||||
CreateFontStyleImagesJob::CreateFontStyleImagesJob(StyleManager::StyleImagesData &&input)
|
||||
: m_input(std::move(input)), m_width(0), m_height(0)
|
||||
{
|
||||
assert(m_input.result != nullptr);
|
||||
assert(!m_input.styles.empty());
|
||||
assert(!m_input.text.empty());
|
||||
assert(m_input.max_size.x() > 1);
|
||||
assert(m_input.max_size.y() > 1);
|
||||
assert(m_input.ppm > 1e-5);
|
||||
}
|
||||
|
||||
void CreateFontStyleImagesJob::process(Ctl &ctl)
|
||||
@ -36,7 +31,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<StyleManager::StyleImage>(m_input.styles.size());
|
||||
m_images = std::vector<StyleManager::StyleImage>(m_input.styles.size());
|
||||
|
||||
for (auto &item : m_input.styles) {
|
||||
size_t index = &item - &m_input.styles.front();
|
||||
@ -44,21 +39,17 @@ void CreateFontStyleImagesJob::process(Ctl &ctl)
|
||||
shapes = text2shapes(item.font, m_input.text.c_str(), item.prop);
|
||||
|
||||
// create image description
|
||||
StyleManager::StyleImage &image = images[index];
|
||||
StyleManager::StyleImage &image = m_images[index];
|
||||
BoundingBox &bounding_box = image.bounding_box;
|
||||
for (ExPolygon &shape : shapes)
|
||||
bounding_box.merge(BoundingBox(shape.contour.points));
|
||||
for (ExPolygon &shape : shapes) shape.translate(-bounding_box.min);
|
||||
|
||||
// calculate conversion from FontPoint to screen pixels by size of font
|
||||
auto mf = wxGetApp().mainframe;
|
||||
// dot per inch for monitor
|
||||
int dpi = get_dpi_for_window(mf);
|
||||
double ppm = dpi / 25.4; // pixel per milimeter
|
||||
const auto &cn = item.prop.collection_number;
|
||||
unsigned int font_index = (cn.has_value()) ? *cn : 0;
|
||||
double unit_per_em = item.font.font_file->infos[font_index].unit_per_em;
|
||||
double scale = item.prop.size_in_mm / unit_per_em * SHAPE_SCALE * ppm;
|
||||
double scale = item.prop.size_in_mm / unit_per_em * SHAPE_SCALE * m_input.ppm;
|
||||
scales[index] = scale;
|
||||
|
||||
//double scale = font_prop.size_in_mm * SCALING_FACTOR;
|
||||
@ -78,30 +69,30 @@ void CreateFontStyleImagesJob::process(Ctl &ctl)
|
||||
|
||||
// arrange bounding boxes
|
||||
int offset_y = 0;
|
||||
width = 0;
|
||||
for (StyleManager::StyleImage &image : images) {
|
||||
m_width = 0;
|
||||
for (StyleManager::StyleImage &image : m_images) {
|
||||
image.offset.y() = offset_y;
|
||||
offset_y += image.tex_size.y+1;
|
||||
if (width < image.tex_size.x)
|
||||
width = image.tex_size.x;
|
||||
if (m_width < image.tex_size.x)
|
||||
m_width = image.tex_size.x;
|
||||
}
|
||||
height = offset_y;
|
||||
for (StyleManager::StyleImage &image : images) {
|
||||
m_height = offset_y;
|
||||
for (StyleManager::StyleImage &image : m_images) {
|
||||
const Point &o = image.offset;
|
||||
const ImVec2 &s = image.tex_size;
|
||||
image.uv0 = ImVec2(o.x() / (double) width,
|
||||
o.y() / (double) height);
|
||||
image.uv1 = ImVec2((o.x() + s.x) / (double) width,
|
||||
(o.y() + s.y) / (double) height);
|
||||
image.uv0 = ImVec2(o.x() / (double) m_width,
|
||||
o.y() / (double) m_height);
|
||||
image.uv1 = ImVec2((o.x() + s.x) / (double) m_width,
|
||||
(o.y() + s.y) / (double) m_height);
|
||||
}
|
||||
|
||||
// Set up result
|
||||
pixels = std::vector<unsigned char>(4*width * height, {255});
|
||||
m_pixels = std::vector<unsigned char>(4 * m_width * m_height, {255});
|
||||
|
||||
// upload sub textures
|
||||
for (StyleManager::StyleImage &image : images) {
|
||||
for (StyleManager::StyleImage &image : m_images) {
|
||||
sla::Resolution resolution(image.tex_size.x, image.tex_size.y);
|
||||
size_t index = &image - &images.front();
|
||||
size_t index = &image - &m_images.front();
|
||||
double pixel_dim = SCALING_FACTOR / scales[index];
|
||||
sla::PixelDim dim(pixel_dim, pixel_dim);
|
||||
double gamma = 1.;
|
||||
@ -110,7 +101,7 @@ void CreateFontStyleImagesJob::process(Ctl &ctl)
|
||||
for (const ExPolygon &shape : name_shapes[index]) r->draw(shape);
|
||||
|
||||
// copy rastered data to pixels
|
||||
sla::RasterEncoder encoder = [&offset = image.offset, &pix = pixels, w=width,h=height]
|
||||
sla::RasterEncoder encoder = [&offset = image.offset, &pix = m_pixels, w=m_width,h=m_height]
|
||||
(const void *ptr, size_t width, size_t height, size_t num_components) {
|
||||
// bigger value create darker image
|
||||
unsigned char gray_level = 5;
|
||||
@ -142,18 +133,18 @@ void CreateFontStyleImagesJob::finalize(bool canceled, std::exception_ptr &)
|
||||
glsafe(::glBindTexture(target, tex_id));
|
||||
glsafe(::glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST));
|
||||
glsafe(::glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST));
|
||||
GLint w = width, h=height;
|
||||
GLint w = m_width, h = m_height;
|
||||
glsafe(::glTexImage2D(target, level, GL_RGBA, w, h, border, format, type,
|
||||
(const void *) pixels.data()));
|
||||
(const void *) m_pixels.data()));
|
||||
|
||||
// set up texture id
|
||||
void *texture_id = (void *) (intptr_t) tex_id;
|
||||
for (StyleManager::StyleImage &image : images)
|
||||
for (StyleManager::StyleImage &image : m_images)
|
||||
image.texture_id = texture_id;
|
||||
|
||||
// move to result
|
||||
m_input.result->styles = std::move(m_input.styles);
|
||||
m_input.result->images = std::move(images);
|
||||
m_input.result->images = std::move(m_images);
|
||||
|
||||
// bind default texture
|
||||
GLuint no_texture_id = 0;
|
||||
|
@ -19,11 +19,11 @@ class CreateFontStyleImagesJob : public Job
|
||||
|
||||
// Output data
|
||||
// texture size
|
||||
int width, height;
|
||||
int m_width, m_height;
|
||||
// texture data
|
||||
std::vector<unsigned char> pixels;
|
||||
std::vector<unsigned char> m_pixels;
|
||||
// descriptors of sub textures
|
||||
std::vector<StyleManager::StyleImage> images;
|
||||
std::vector<StyleManager::StyleImage> m_images;
|
||||
|
||||
public:
|
||||
CreateFontStyleImagesJob(StyleManager::StyleImagesData &&input);
|
||||
|
@ -304,12 +304,15 @@ void StyleManager::init_trunc_names(float max_width) {
|
||||
}
|
||||
}
|
||||
|
||||
#include "slic3r/GUI/Jobs/CreateFontStyleImagesJob.hpp"
|
||||
|
||||
// for access to worker
|
||||
#include "slic3r/GUI/GUI_App.hpp"
|
||||
#include "slic3r/GUI/Plater.hpp"
|
||||
|
||||
// for get DPI
|
||||
#include "slic3r/GUI/GUI_App.hpp"
|
||||
#include "slic3r/GUI/MainFrame.hpp"
|
||||
#include "slic3r/GUI/GUI_ObjectManipulation.hpp"
|
||||
|
||||
void StyleManager::init_style_images(const Vec2i &max_size,
|
||||
const std::string &text)
|
||||
{
|
||||
@ -361,8 +364,15 @@ void StyleManager::init_style_images(const Vec2i &max_size,
|
||||
style.prop
|
||||
});
|
||||
}
|
||||
|
||||
auto mf = wxGetApp().mainframe;
|
||||
// dot per inch for monitor
|
||||
int dpi = get_dpi_for_window(mf);
|
||||
// pixel per milimeter
|
||||
double ppm = dpi / ObjectManipulation::in_to_mm;
|
||||
|
||||
auto &worker = wxGetApp().plater()->get_ui_job_worker();
|
||||
StyleImagesData data{std::move(styles), max_size, text, m_temp_style_images};
|
||||
StyleImagesData data{std::move(styles), max_size, text, m_temp_style_images, ppm};
|
||||
queue_job(worker, std::make_unique<CreateFontStyleImagesJob>(std::move(data)));
|
||||
}
|
||||
|
||||
|
@ -277,6 +277,9 @@ private:
|
||||
|
||||
// place to store result in main thread in Finalize
|
||||
std::shared_ptr<StyleImages> result;
|
||||
|
||||
// pixel per milimeter (scaled DPI)
|
||||
double ppm;
|
||||
};
|
||||
std::shared_ptr<StyleImagesData::StyleImages> m_temp_style_images;
|
||||
bool m_exist_style_images;
|
||||
|
Loading…
x
Reference in New Issue
Block a user