From d77542730779700df5855e88a5a5498f6d27d533 Mon Sep 17 00:00:00 2001 From: Byons Date: Fri, 31 Jul 2026 09:48:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=96=87=E6=9C=AC=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E4=B8=8B=E9=9D=A2=E6=80=BB=E6=98=AF=E5=A4=9A=E4=B8=80?= =?UTF-8?q?=E8=A1=8C=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=8C=E5=90=8C=E6=97=B6?= =?UTF-8?q?=E5=8F=96=E6=B6=88=E9=99=90=E5=88=B6item=E9=AB=98=E5=BA=A6?= =?UTF-8?q?=E5=8A=A01?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scene/ItemCommon.cpp | 17 +++++++++++++++++ scene/pictextitem.cpp | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/scene/ItemCommon.cpp b/scene/ItemCommon.cpp index b80ff2a..ad9d1a4 100644 --- a/scene/ItemCommon.cpp +++ b/scene/ItemCommon.cpp @@ -557,6 +557,23 @@ QImage ItemUtils::txtToImage(const QString &txt, const QFont &font, const QColor QFontMetrics fm(font); int width = fm.horizontalAdvance(txt); int height = fm.height(); + + // 优先使用字体名中后缀标识的字体高度 + QString fontname = font.family(); + QString numStr = ""; + for(int i = fontname.length() - 1; i >= 0; --i) { + if(fontname[i].isDigit()) { + numStr.prepend(fontname[i]); + } else { + break; + } + } + if(!numStr.isEmpty()) { + height = numStr.toInt(); + if(height < 5 || height > 32) + height = fm.height(); + } + if (width <= 0 || height <= 0) { return QImage(); } diff --git a/scene/pictextitem.cpp b/scene/pictextitem.cpp index 9d2eee5..195000e 100644 --- a/scene/pictextitem.cpp +++ b/scene/pictextitem.cpp @@ -404,7 +404,7 @@ QImage PicTextItem::strToImage(const QString &str) QPointF PicTextItem::clampItemPos(const QPointF &p) { return QPointF (std::min(qreal(scene()->width() - boundingRect().width()), std::max(0.0, p.x())), - std::min((qreal(scene()->height() + 1) - boundingRect().height()), std::max(0.0, p.y()))); + std::min((qreal(scene()->height()) - boundingRect().height()), std::max(0.0, p.y()))); } TextItemModel TextItemModel::fromItem(PicTextItem *item)