From 060eb63ce86c9df8f6c13a40344fab84cd9a1a38 Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Sun, 29 May 2022 02:04:38 +0400 Subject: [PATCH] Get rid of qtextitemint.cpp All the variables are public, so there's no need to use non-exported constructor --- CMakeLists.txt | 4 ---- ui/text/qtextitemint.cpp | 48 ---------------------------------------- ui/text/text.cpp | 38 ++++++++++++++++++++++++++----- 3 files changed, 33 insertions(+), 57 deletions(-) delete mode 100644 ui/text/qtextitemint.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 9df509c..00ef694 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -262,10 +262,6 @@ PRIVATE emoji_suggestions/emoji_suggestions_helper.h ) -if (DESKTOP_APP_USE_PACKAGED) - nice_target_sources(lib_ui ${src_loc} PRIVATE ui/text/qtextitemint.cpp) -endif() - if (NOT DESKTOP_APP_USE_PACKAGED_FONTS) nice_target_sources(lib_ui ${src_loc} PRIVATE fonts/fonts.qrc) endif() diff --git a/ui/text/qtextitemint.cpp b/ui/text/qtextitemint.cpp deleted file mode 100644 index 20e9473..0000000 --- a/ui/text/qtextitemint.cpp +++ /dev/null @@ -1,48 +0,0 @@ -// This file is part of Desktop App Toolkit, -// a set of libraries for developing nice desktop applications. -// -// For license and copyright information please follow this link: -// https://github.com/desktop-app/legal/blob/master/LEGAL -// -#include - -QTextItemInt::QTextItemInt( - const QGlyphLayout &g, - QFont *font, - const QChar *chars_, - int numChars, - QFontEngine *fe, - const QTextCharFormat &format) -: charFormat(format) -, num_chars(numChars) -, chars(chars_) -, f(font) -, glyphs(g) -, fontEngine(fe) { -} - -void QTextItemInt::initWithScriptItem(const QScriptItem &si) { - // explicitly initialize flags so that initFontAttributes can be called - // multiple times on the same TextItem - flags = { }; - if (si.analysis.bidiLevel %2) - flags |= QTextItem::RightToLeft; - ascent = si.ascent; - descent = si.descent; - - if (charFormat.hasProperty(QTextFormat::TextUnderlineStyle)) { - underlineStyle = charFormat.underlineStyle(); - } else if (charFormat.boolProperty(QTextFormat::FontUnderline) - || f->d->underline) { - underlineStyle = QTextCharFormat::SingleUnderline; - } - - // compat - if (underlineStyle == QTextCharFormat::SingleUnderline) - flags |= QTextItem::Underline; - - if (f->d->overline || charFormat.fontOverline()) - flags |= QTextItem::Overline; - if (f->d->strikeOut || charFormat.fontStrikeOut()) - flags |= QTextItem::StrikeOut; -} diff --git a/ui/text/text.cpp b/ui/text/text.cpp index 97c9a0a..06e1073 100644 --- a/ui/text/text.cpp +++ b/ui/text/text.cpp @@ -142,6 +142,32 @@ bool IsBad(QChar ch) { || (Platform::IsMac() && ch == 6158); } +void InitTextItemWithScriptItem(QTextItemInt &ti, const QScriptItem &si) { + // explicitly initialize flags so that initFontAttributes can be called + // multiple times on the same TextItem + ti.flags = { }; + if (si.analysis.bidiLevel %2) + ti.flags |= QTextItem::RightToLeft; + ti.ascent = si.ascent; + ti.descent = si.descent; + + if (ti.charFormat.hasProperty(QTextFormat::TextUnderlineStyle)) { + ti.underlineStyle = ti.charFormat.underlineStyle(); + } else if (ti.charFormat.boolProperty(QTextFormat::FontUnderline) + || ti.f->underline()) { + ti.underlineStyle = QTextCharFormat::SingleUnderline; + } + + // compat + if (ti.underlineStyle == QTextCharFormat::SingleUnderline) + ti.flags |= QTextItem::Underline; + + if (ti.f->overline() || ti.charFormat.fontOverline()) + ti.flags |= QTextItem::Overline; + if (ti.f->strikeOut() || ti.charFormat.fontStrikeOut()) + ti.flags |= QTextItem::StrikeOut; +} + } // namespace } // namespace Text } // namespace Ui @@ -1706,14 +1732,16 @@ private: } return false; } else if (_p) { - QTextCharFormat format; - QTextItemInt gf(glyphs.mid(glyphsStart, glyphsEnd - glyphsStart), - &_e->fnt, engine.layoutData->string.unicode() + itemStart, - itemEnd - itemStart, engine.fontEngine(si), format); + QTextItemInt gf; + gf.glyphs = glyphs.mid(glyphsStart, glyphsEnd - glyphsStart); + gf.f = &_e->fnt; + gf.chars = engine.layoutData->string.unicode() + itemStart; + gf.num_chars = itemEnd - itemStart; + gf.fontEngine = engine.fontEngine(si); gf.logClusters = logClusters + itemStart - si.position; gf.width = itemWidth; gf.justified = false; - gf.initWithScriptItem(si); + InitTextItemWithScriptItem(gf, si); auto hasSelected = false; auto hasNotSelected = true;