修复文本垂直方向对齐问题

This commit is contained in:
2025-07-01 14:34:39 +08:00
parent b6979749f8
commit b0f9d92750
3 changed files with 7 additions and 7 deletions

View File

@@ -63,9 +63,9 @@ void text_layout_t::line_t::format(const font_face_ptr& in_primary_font, float i
g->position.x() = cursor_x + kerning + g_metrics.offset.x();
const float size_y_diff = g_metrics.rect.size().y() - static_cast<float>(g->region->rect.size().y());
const float baseline_y = position_y + metrics.ascent;
const float baseline_y = position_y + line_height + metrics.descent;
// g->position.y() = baseline_y + g_metrics.offset.y() + size_y_diff;
g->position.y() = baseline_y + g_metrics.offset.y() + size_y_diff - metrics.descent;
g->position.y() = baseline_y + g_metrics.offset.y() + size_y_diff;
cursor_x += kerning + g_metrics.advance.x();
@@ -139,5 +139,5 @@ float text_layout_t::get_empty_line_height() const {
return 0.0f; // 如果没有主字体返回0
}
font->set_font_size(font_size);
return font->get_metrics().line_height * line_spacing;
return font->get_metrics().line_height; // 空行高度不需要line_spacing
}

View File

@@ -59,15 +59,15 @@ void meditable_text_box::on_paint(mirage_paint_context& in_context) {
if (is_focus()) {
const auto& last_line = layout_.get_last_line();
const float line_height = last_line.get_line_height() * line_spacing_;
const float line_height = last_line.get_line_height();
const auto glyph_pos = layout_.get_glyph(cursor_pos_.y(), cursor_pos_.x());
const float cursor_width = glyph_pos ? glyph_pos->region->rect.width() : 0;
const auto cursor_width = glyph_pos ? glyph_pos->region->rect.width() : 0;
const auto& cursor_pos = layout_.get_glyph_pos(cursor_pos_.y(), cursor_pos_.x(), true);
// 绘制光标
in_context.drawer().make_rounded_rect(
cursor_pos + Eigen::Vector2f(round_ + cursor_width, round_),
cursor_pos + Eigen::Vector2f(round_, round_),
Eigen::Vector2f(2, line_height),
in_context.geo(),
draw_effect::none,

View File

@@ -51,7 +51,7 @@ private:
text_layout_t layout_{};
Eigen::Vector2f no_warp_size_{};
float font_size_ = .0f;
float line_spacing_ = 1.f;
float line_spacing_ = 1.2f;
bool warp_text_ = false;
font_face_ptr font_;
};