feat(text): 实现文本垂直居中对齐功能

- 修改TextElement类中的Y坐标计算逻辑
- 新增总文本高度计算和垂直偏移量
- 调整起始Y坐标以支持垂直居中对齐
- 保持原有逐行绘制逻辑不变
This commit is contained in:
2025-11-20 23:10:50 +08:00
parent 27e58d36d0
commit d458f918ed

View File

@@ -141,8 +141,12 @@ public class TextElement extends BaseElement {
? textConfig.getTextAlign().toUpperCase()
: "LEFT";
// 起始Y坐标
int y = position.getY() + fm.getAscent();
// 计算总文本高度并实现垂直居中
int totalTextHeight = lineHeight * actualLines;
int verticalOffset = (position.getHeight() - totalTextHeight) / 2;
// 起始Y坐标(垂直居中)
int y = position.getY() + verticalOffset + fm.getAscent();
// 逐行绘制
for (int i = 0; i < actualLines; i++) {