Nicering of code

This commit is contained in:
Filip Sykala - NTB T15p 2023-04-18 13:06:58 +02:00
parent fdac21b807
commit 4a05973ea8
3 changed files with 14 additions and 21 deletions

View file

@ -796,8 +796,7 @@ const Glyph* priv::get_glyph(
auto glyph_item = cache.find(unicode);
if (glyph_item != cache.end()) return &glyph_item->second;
unsigned int font_index = font_prop.collection_number.has_value()?
*font_prop.collection_number : 0;
unsigned int font_index = font_prop.collection_number.value_or(0);
if (!is_valid(font, font_index)) return nullptr;
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));
}
if (font_prop.skew.has_value()) {
const float &ratio = *font_prop.skew;
auto skew = [&ratio](Polygon &polygon) {
for (Slic3r::Point &p : polygon.points) {
p.x() += p.y() * ratio;
}
double ratio = *font_prop.skew;
auto skew = [&ratio](Polygon &polygon) {
for (Slic3r::Point &p : polygon.points)
p.x() += static_cast<Point::coord_type>(std::round(p.y() * ratio));
};
for (ExPolygon &expolygon : glyph_opt->shape) {
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)
{
const auto &cn = fp.collection_number;
unsigned int font_index = (cn.has_value()) ? *cn : 0;
int unit_per_em = ff.infos[font_index].unit_per_em;
double scale = fp.size_in_mm / unit_per_em;
size_t font_index = fp.collection_number.value_or(0);
const FontFile::Info &info = ff.infos[font_index];
double scale = fp.size_in_mm / (double) info.unit_per_em;
// Shape is scaled for store point coordinate as integer
return scale * SHAPE_SCALE;
}

View file

@ -430,16 +430,13 @@ TriangleMesh priv::try_create_mesh(DataBase &input, Fnc was_canceled)
{
ExPolygons shapes = priv::create_shape(input, was_canceled);
if (shapes.empty()) return {};
if (was_canceled()) return {};
if (was_canceled()) return {};
const FontProp &prop = input.text_configuration.style.prop;
const std::optional<unsigned int> &cn = prop.collection_number;
unsigned int font_index = (cn.has_value()) ? *cn : 0;
const FontFileWithCache &font = input.font_file;
assert(font_index < font.font_file->infos.size());
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;
const FontFile &ff = *input.font_file.font_file;
// NOTE: SHAPE_SCALE is applied in ProjectZ
double scale = get_shape_scale(prop, ff) / SHAPE_SCALE;
double depth = prop.emboss / scale;
auto projectZ = std::make_unique<ProjectZ>(depth);
ProjectScale project(std::move(projectZ), scale);
if (was_canceled()) return {};

View file

@ -472,8 +472,7 @@ ImFont *StyleManager::create_imgui_font(const std::string &text, double scale)
// TODO: start using merge mode
//font_config.MergeMode = true;
const auto &cn = font_prop.collection_number;
unsigned int font_index = (cn.has_value()) ? *cn : 0;
unsigned int font_index = font_prop.collection_number.value_or(0);
const auto &font_info = font_file.infos[font_index];
if (font_prop.char_gap.has_value()) {
float coef = font_size / (double) font_info.unit_per_em;