Textline offset same as Vertical center of text

This commit is contained in:
Filip Sykala - NTB T15p 2023-08-10 08:55:43 +02:00
parent f51c0e651b
commit acb3e6dd37
3 changed files with 12 additions and 17 deletions

View File

@ -3152,17 +3152,6 @@ void GLGizmoEmboss::draw_advanced()
m_text_lines.reset();
m_imgui->disabled_end(); // !can_use_per_glyph
// Set offset of slice from base line
//m_imgui->disabled_begin(!per_glyph);
//ImGui::SameLine();
//ImGui::SetNextItemWidth(m_gui_cfg->input_width);
//if (m_imgui->slider_float("##base_line_y_offset", &m_text_lines.offset, -10.f, 10.f, "%f mm")) {
// reinit_text_lines(m_text_lines.get_lines().size());
// process();
//} else if (ImGui::IsItemHovered())
// ImGui::SetTooltip("TEST PURPOSE ONLY\nMove base line (up/down) for allign letters");
//m_imgui->disabled_end(); // !per_glyph
auto draw_align = [&align = font_prop.align, gui_cfg = m_gui_cfg, &icons = m_icons]() {
bool is_change = false;
ImGui::SameLine(gui_cfg->advanced_input_offset);
@ -3224,6 +3213,8 @@ void GLGizmoEmboss::draw_advanced()
}
// input gap between lines
bool is_multiline = m_text_lines.get_lines().size() > 1;
m_imgui->disabled_begin(!is_multiline);
auto def_line_gap = stored_style ?
&stored_style->prop.line_gap : nullptr;
int min_line_gap = -half_ascent, max_line_gap = half_ascent;
@ -3240,6 +3231,7 @@ void GLGizmoEmboss::draw_advanced()
exist_change = true;
}
}
m_imgui->disabled_end(); // !is_multiline
// input boldness
auto def_boldness = stored_style ?

View File

@ -255,7 +255,6 @@ bool get_line_height_offset(const FontProp &fp, const FontFile &ff, double &line
return true;
}
} // namespace
void TextLinesModel::init(const Transform3d &text_tr,
@ -286,7 +285,9 @@ void TextLinesModel::init(const Transform3d &text_tr,
m_model.reset();
m_lines.clear();
double first_line_center = this->offset + line_height_mm / 3 + get_align_y_offset_in_mm(align, count_lines, ff, fp);
// size_in_mm .. contain volume scale and should be ascent value in mm
double line_offset = fp.size_in_mm * ascent_ratio_offset;
double first_line_center = line_offset + get_align_y_offset_in_mm(align, count_lines, ff, fp);
std::vector<float> line_centers(count_lines);
for (size_t i = 0; i < count_lines; ++i)
line_centers[i] = static_cast<float>(first_line_center - i * line_height_mm);

View File

@ -17,9 +17,6 @@ namespace Slic3r::GUI {
class TextLinesModel
{
public:
// line offset in y direction (up/down)
float offset = 0;
/// <summary>
/// Initialize model and lines
/// </summary>
@ -41,6 +38,11 @@ private:
// Keep model for visualization text lines
GLModel m_model;
// Used to move slice (text line) on place where is approx vertical center of text
// When copy value const double ASCENT_CENTER from Emboss.cpp and Vertical align is center than
// text line will cross object center
const double ascent_ratio_offset = 1/3.;
};
} // namespace Slic3r::GUI