mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-16 08:55:57 +08:00
Nicering of code
This commit is contained in:
parent
fdac21b807
commit
4a05973ea8
@ -796,8 +796,7 @@ const Glyph* priv::get_glyph(
|
|||||||
auto glyph_item = cache.find(unicode);
|
auto glyph_item = cache.find(unicode);
|
||||||
if (glyph_item != cache.end()) return &glyph_item->second;
|
if (glyph_item != cache.end()) return &glyph_item->second;
|
||||||
|
|
||||||
unsigned int font_index = font_prop.collection_number.has_value()?
|
unsigned int font_index = font_prop.collection_number.value_or(0);
|
||||||
*font_prop.collection_number : 0;
|
|
||||||
if (!is_valid(font, font_index)) return nullptr;
|
if (!is_valid(font, font_index)) return nullptr;
|
||||||
|
|
||||||
if (!font_info_opt.has_value()) {
|
if (!font_info_opt.has_value()) {
|
||||||
@ -835,11 +834,10 @@ const Glyph* priv::get_glyph(
|
|||||||
glyph_opt->shape = Slic3r::union_ex(offset_ex(glyph_opt->shape, delta));
|
glyph_opt->shape = Slic3r::union_ex(offset_ex(glyph_opt->shape, delta));
|
||||||
}
|
}
|
||||||
if (font_prop.skew.has_value()) {
|
if (font_prop.skew.has_value()) {
|
||||||
const float &ratio = *font_prop.skew;
|
double ratio = *font_prop.skew;
|
||||||
auto skew = [&ratio](Polygon &polygon) {
|
auto skew = [&ratio](Polygon &polygon) {
|
||||||
for (Slic3r::Point &p : polygon.points) {
|
for (Slic3r::Point &p : polygon.points)
|
||||||
p.x() += p.y() * ratio;
|
p.x() += static_cast<Point::coord_type>(std::round(p.y() * ratio));
|
||||||
}
|
|
||||||
};
|
};
|
||||||
for (ExPolygon &expolygon : glyph_opt->shape) {
|
for (ExPolygon &expolygon : glyph_opt->shape) {
|
||||||
skew(expolygon.contour);
|
skew(expolygon.contour);
|
||||||
@ -1363,10 +1361,9 @@ std::string Emboss::create_range_text(const std::string &text,
|
|||||||
|
|
||||||
double Emboss::get_shape_scale(const FontProp &fp, const FontFile &ff)
|
double Emboss::get_shape_scale(const FontProp &fp, const FontFile &ff)
|
||||||
{
|
{
|
||||||
const auto &cn = fp.collection_number;
|
size_t font_index = fp.collection_number.value_or(0);
|
||||||
unsigned int font_index = (cn.has_value()) ? *cn : 0;
|
const FontFile::Info &info = ff.infos[font_index];
|
||||||
int unit_per_em = ff.infos[font_index].unit_per_em;
|
double scale = fp.size_in_mm / (double) info.unit_per_em;
|
||||||
double scale = fp.size_in_mm / unit_per_em;
|
|
||||||
// Shape is scaled for store point coordinate as integer
|
// Shape is scaled for store point coordinate as integer
|
||||||
return scale * SHAPE_SCALE;
|
return scale * SHAPE_SCALE;
|
||||||
}
|
}
|
||||||
|
@ -430,16 +430,13 @@ TriangleMesh priv::try_create_mesh(DataBase &input, Fnc was_canceled)
|
|||||||
{
|
{
|
||||||
ExPolygons shapes = priv::create_shape(input, was_canceled);
|
ExPolygons shapes = priv::create_shape(input, was_canceled);
|
||||||
if (shapes.empty()) return {};
|
if (shapes.empty()) return {};
|
||||||
if (was_canceled()) return {};
|
if (was_canceled()) return {};
|
||||||
|
|
||||||
const FontProp &prop = input.text_configuration.style.prop;
|
const FontProp &prop = input.text_configuration.style.prop;
|
||||||
const std::optional<unsigned int> &cn = prop.collection_number;
|
const FontFile &ff = *input.font_file.font_file;
|
||||||
unsigned int font_index = (cn.has_value()) ? *cn : 0;
|
// NOTE: SHAPE_SCALE is applied in ProjectZ
|
||||||
const FontFileWithCache &font = input.font_file;
|
double scale = get_shape_scale(prop, ff) / SHAPE_SCALE;
|
||||||
assert(font_index < font.font_file->infos.size());
|
double depth = prop.emboss / scale;
|
||||||
int unit_per_em = font.font_file->infos[font_index].unit_per_em;
|
|
||||||
float scale = prop.size_in_mm / unit_per_em;
|
|
||||||
float depth = prop.emboss / scale;
|
|
||||||
auto projectZ = std::make_unique<ProjectZ>(depth);
|
auto projectZ = std::make_unique<ProjectZ>(depth);
|
||||||
ProjectScale project(std::move(projectZ), scale);
|
ProjectScale project(std::move(projectZ), scale);
|
||||||
if (was_canceled()) return {};
|
if (was_canceled()) return {};
|
||||||
|
@ -472,8 +472,7 @@ ImFont *StyleManager::create_imgui_font(const std::string &text, double scale)
|
|||||||
// TODO: start using merge mode
|
// TODO: start using merge mode
|
||||||
//font_config.MergeMode = true;
|
//font_config.MergeMode = true;
|
||||||
|
|
||||||
const auto &cn = font_prop.collection_number;
|
unsigned int font_index = font_prop.collection_number.value_or(0);
|
||||||
unsigned int font_index = (cn.has_value()) ? *cn : 0;
|
|
||||||
const auto &font_info = font_file.infos[font_index];
|
const auto &font_info = font_file.infos[font_index];
|
||||||
if (font_prop.char_gap.has_value()) {
|
if (font_prop.char_gap.has_value()) {
|
||||||
float coef = font_size / (double) font_info.unit_per_em;
|
float coef = font_size / (double) font_info.unit_per_em;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user