From 694800cf3c0abfa1a91dd0c94af0796ddf79340a Mon Sep 17 00:00:00 2001 From: Arin Alexander Date: Fri, 18 Dec 2020 00:32:09 +0300 Subject: [PATCH] Font adaptation has been optimized --- limereport/items/lrtextitem.cpp | 16 ++++++++++++---- limereport/items/lrtextitem.h | 3 ++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/limereport/items/lrtextitem.cpp b/limereport/items/lrtextitem.cpp index 50de9d5..73d78f6 100644 --- a/limereport/items/lrtextitem.cpp +++ b/limereport/items/lrtextitem.cpp @@ -59,7 +59,7 @@ namespace LimeReport{ TextItem::TextItem(QObject *owner, QGraphicsItem *parent) : ContentItemDesignIntf(xmlTag,owner,parent), m_angle(Angle0), m_trimValue(true), m_allowHTML(false), m_allowHTMLInFields(false), m_replaceCarriageReturns(false), m_followTo(""), m_follower(0), m_textIndent(0), - m_textLayoutDirection(Qt::LayoutDirectionAuto), m_hideIfEmpty(false), m_fontLetterSpacing(0) + m_textLayoutDirection(Qt::LayoutDirectionAuto), m_hideIfEmpty(false), m_fontLetterSpacing(0), m_adaptedFont(0) { PageItemDesignIntf* pageItem = dynamic_cast(parent); BaseDesignIntf* parentItem = dynamic_cast(parent); @@ -75,7 +75,7 @@ TextItem::TextItem(QObject *owner, QGraphicsItem *parent) Init(); } -TextItem::~TextItem(){} +TextItem::~TextItem(){if (m_adaptedFont) delete m_adaptedFont;} int TextItem::fakeMarginSize() const{ return marginSize()+5; @@ -385,7 +385,7 @@ void TextItem::setTextFont(TextPtr text, const QFont& value) const { } } -void TextItem::adaptFontSize(TextPtr text) const{ +QFont TextItem::adaptFontSize(TextPtr text) const{ QFont _font = transformToSceneFont(font()); do{ setTextFont(text,_font); @@ -393,6 +393,7 @@ void TextItem::adaptFontSize(TextPtr text) const{ _font.setPixelSize(_font.pixelSize()-1); else break; } while(text->size().height()>this->height() || text->size().width()>(this->width()) - fakeMarginSize() * 2); + return _font; } int TextItem::underlineLineSize() const @@ -522,7 +523,14 @@ TextItem::TextPtr TextItem::textDocument() const QFont _font = transformToSceneFont(font()); if (m_adaptFontToSize && (!(m_autoHeight || m_autoWidth))){ - adaptFontSize(text); + if (!m_adaptedFont){ + m_adaptedFont = new QFont(adaptFontSize(text)); + } else { + setTextFont(text,*m_adaptedFont); + if (text->size().height()>this->height() || text->size().width()>(this->width())){ + m_adaptedFont = new QFont(adaptFontSize(text)); + } + } } else { setTextFont(text,_font); } diff --git a/limereport/items/lrtextitem.h b/limereport/items/lrtextitem.h index fbd2bfd..0aa8e4d 100644 --- a/limereport/items/lrtextitem.h +++ b/limereport/items/lrtextitem.h @@ -200,7 +200,7 @@ protected: private: void initTextSizes() const; void setTextFont(TextPtr text, const QFont &value) const; - void adaptFontSize(TextPtr text) const; + QFont adaptFontSize(TextPtr text) const; QString formatDateTime(const QDateTime &value); QString formatNumber(const double value); QString formatFieldValue(); @@ -232,6 +232,7 @@ private: Qt::LayoutDirection m_textLayoutDirection; bool m_hideIfEmpty; int m_fontLetterSpacing; + mutable QFont* m_adaptedFont; }; }