修复因场景模式修改为绝对坐标引起的打印补全、蜂鸣器报警改为常响、添加相位故障关闭回收槽功能、取消翻转上下颠倒,与莱宾格行为同步、修改场景模式默认字体为7点、取消变量占位图设计
This commit is contained in:
+15
-10
@@ -552,10 +552,12 @@ QImage ItemUtils::txtToImage(const QString &txt, const QFont &font, const QColor
|
||||
return QImage();
|
||||
}
|
||||
|
||||
QString targetTxt = txt.left(400);
|
||||
|
||||
// 用 QFontMetrics 计算给定字体下文本的水平推进宽度和单行高度,
|
||||
// 这样初始画布刚好能容纳整段文本,避免后续裁剪时出现截断
|
||||
QFontMetrics fm(font);
|
||||
int width = fm.horizontalAdvance(txt);
|
||||
int width = fm.horizontalAdvance(targetTxt);
|
||||
int height = fm.height();
|
||||
|
||||
// 优先使用字体名中后缀标识的字体高度
|
||||
@@ -568,17 +570,21 @@ QImage ItemUtils::txtToImage(const QString &txt, const QFont &font, const QColor
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!numStr.isEmpty()) {
|
||||
height = numStr.toInt();
|
||||
if(height < 5 || height > 32)
|
||||
if (!numStr.isEmpty()) {
|
||||
int h = numStr.toInt();
|
||||
if (h >= 5 && h <= 32) {
|
||||
height = h;
|
||||
} else {
|
||||
height = fm.height();
|
||||
}
|
||||
}
|
||||
|
||||
if (width <= 0 || height <= 0) {
|
||||
return QImage();
|
||||
}
|
||||
|
||||
QImage img(width, height, QImage::Format_ARGB32);
|
||||
int letterSpace = (int)(font.letterSpacing());
|
||||
QImage img(width - letterSpace, height, QImage::Format_ARGB32);
|
||||
|
||||
QRgb bgRgb = bgColor.rgba();
|
||||
img.fill(bgRgb);
|
||||
@@ -587,11 +593,10 @@ QImage ItemUtils::txtToImage(const QString &txt, const QFont &font, const QColor
|
||||
painter.begin(&img);
|
||||
painter.setFont(font);
|
||||
painter.setPen(fgColor);
|
||||
painter.drawText(img.rect(), txt);
|
||||
painter.end();
|
||||
|
||||
// 使用基线坐标绘制单行文本,确保 glyph 间距按字体度量精确排列
|
||||
int baselineY = fm.ascent();
|
||||
painter.drawText(QPoint(0, baselineY), targetTxt);
|
||||
painter.end();
|
||||
return img;
|
||||
|
||||
// 按背景色裁剪,使输出图像紧贴文字像素的最小包围盒(详见函数注释)
|
||||
return clipTxtImage(img, bgRgb);
|
||||
}
|
||||
Reference in New Issue
Block a user