From: Juergen Spitzmueller Date: Mon, 30 Apr 2018 10:59:54 +0000 (+0200) Subject: Try to make an educated guess about the logo extension on the banner X-Git-Tag: lyx-2.4.0dev-acb2ca7b~3523 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=dd79338cffd744527f216704641fa780a64bc73d;p=features.git Try to make an educated guess about the logo extension on the banner --- diff --git a/src/frontends/qt4/GuiView.cpp b/src/frontends/qt4/GuiView.cpp index 10cc5e278c..a91928cde5 100644 --- a/src/frontends/qt4/GuiView.cpp +++ b/src/frontends/qt4/GuiView.cpp @@ -158,7 +158,7 @@ public: return; /// The text to be written on top of the pixmap QString const htext = qt_("The Document\nProcessor[[welcome banner]]"); - QString const htextsize = qt_("20[[possibly adjust the welcome banner text size; float value allowed]]"); + QString const htextsize = qt_("1.0[[possibly scale the welcome banner text size]]"); /// The text to be written on top of the pixmap QString const text = lyx_version ? qt_("version ") + lyx_version : qt_("unknown version"); @@ -182,9 +182,10 @@ public: pain.setPen(QColor(0, 0, 0)); qreal const fsize = fontSize(); bool ok; - qreal hfsize = htextsize.toFloat(&ok); + int hfsize = 20; + qreal locscale = htextsize.toFloat(&ok); if (!ok) - hfsize = 20; + locscale = 1.0; QPointF const position = textPosition(false); QPointF const hposition = textPosition(true); QRectF const hrect(hposition, splashSize()); @@ -203,6 +204,30 @@ public: font.setStyleHint(QFont::SansSerif); font.setWeight(QFont::Normal); font.setPointSizeF(hfsize); + // Check how long the logo gets with the current font + // and adapt if the font is running wider than what + // we assume + QFontMetrics fm(font); + // Split the title into lines to measure the longest line + // in the current l7n. + QStringList titlesegs = htext.split('\n'); + int wline = 0; + int hline = fm.height(); + QStringList::const_iterator sit; + for (sit = titlesegs.constBegin(); sit != titlesegs.constEnd(); ++sit) { + if (fm.width(*sit) > wline) + wline = fm.width(*sit); + } + // The longest line in the reference font (for English) + // is 180. Calculate scale factor from that. + double const wscale = (180.0 / wline); + // Now do the same for the height (necessary for condensed fonts) + double const hscale = (34.0 / hline); + // take the lower of the two scale factors. + double const scale = min(wscale, hscale); + // Now rescale. Also consider l7n's offset factor. + font.setPointSizeF(hfsize * scale * locscale); + pain.setFont(font); pain.drawText(hrect, Qt::AlignLeft, htext); setFocusPolicy(Qt::StrongFocus);