]> git.lyx.org Git - features.git/commitdiff
Try to make an educated guess about the logo extension on the banner
authorJuergen Spitzmueller <spitz@lyx.org>
Mon, 30 Apr 2018 10:59:54 +0000 (12:59 +0200)
committerJuergen Spitzmueller <spitz@lyx.org>
Mon, 30 Apr 2018 10:59:54 +0000 (12:59 +0200)
src/frontends/qt4/GuiView.cpp

index 10cc5e278c04aaf45e4e32f49b226a7f2d1cc1d0..a91928cde5bc045cbad34c16e3fbacb8c5ee1a64 100644 (file)
@@ -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);