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)