From c28b1f91cca7faac7bc54e24b7b9ab45f24247cd Mon Sep 17 00:00:00 2001 From: Jean-Francois Dockes Date: Mon, 1 Dec 2014 14:08:13 +0100 Subject: [PATCH] compensate for off-by-3 error when setting webkit font size with QWebSettings. Experiment (ifndefed) with using css instead --- src/qtgui/reslist.cpp | 26 ++++++++++++++++++++++++-- src/qtgui/uiprefs_w.cpp | 10 +++++++--- src/query/reslistpager.cpp | 8 ++++---- 3 files changed, 35 insertions(+), 9 deletions(-) diff --git a/src/qtgui/reslist.cpp b/src/qtgui/reslist.cpp index e2bc418d..96ae5073 100644 --- a/src/qtgui/reslist.cpp +++ b/src/qtgui/reslist.cpp @@ -70,6 +70,13 @@ static const QKeySequence closeKeySeq("Ctrl+w"); #include #endif +// Decide if we set font family and style with a css section in the +// html or with qwebsettings setfont... calls. We currently do +// it with websettings because this gives an instant redisplay, and +// the css has a tendancy to not find some system fonts. Otoh, +// SetFontSize() needs a strange offset of 3, not needed with css. +#undef SETFONT_WITH_HEADSTYLE + class QtGuiResListPager : public ResListPager { public: QtGuiResListPager(ResList *p, int ps) @@ -175,7 +182,18 @@ string QtGuiResListPager::prevUrl() string QtGuiResListPager::headerContent() { - return (const char *)prefs.reslistheadertext.toUtf8(); + string out; +#ifdef SETFONT_WITH_HEADSTYLE + out = "\n"); +#endif + out += qs2utf8s(prefs.reslistheadertext); + return out; } void QtGuiResListPager::suggest(const vectoruterms, @@ -378,10 +396,13 @@ void ResList::setFont() QTextBrowser::setFont(QFont()); } #else +#ifndef SETFONT_WITH_HEADSTYLE QWebSettings *websettings = settings(); if (prefs.reslistfontfamily.length()) { + // For some reason there is (12-2014) an offset of 3 between what + // we request from webkit and what we get. websettings->setFontSize(QWebSettings::DefaultFontSize, - prefs.reslistfontsize); + prefs.reslistfontsize + 3); websettings->setFontFamily(QWebSettings::StandardFont, prefs.reslistfontfamily); } else { @@ -389,6 +410,7 @@ void ResList::setFont() websettings->resetFontFamily(QWebSettings::StandardFont); } #endif +#endif } int ResList::newListId() diff --git a/src/qtgui/uiprefs_w.cpp b/src/qtgui/uiprefs_w.cpp index 4ba0f6e5..ec49ea0f 100644 --- a/src/qtgui/uiprefs_w.cpp +++ b/src/qtgui/uiprefs_w.cpp @@ -377,10 +377,14 @@ void UIPrefsDialog::showFontDialog() font = QFontDialog::getFont(&ok, font, this); if (ok) { - // Check if the default font was set, in which case we - // erase the preference + // We used to check if the default font was set, in which case + // we erased the preference, but this would result in letting + // webkit make a choice of default font which it usually seems + // to do wrong. So now always set the font. There is still a + // way for the user to let webkit choose the default though: + // click reset, then the font name and size will be empty. QString s; - if (font.family().compare(this->font().family()) || + if (1 || font.family().compare(this->font().family()) || font.pointSize() != this->font().pointSize()) { reslistFontFamily = font.family(); reslistFontSize = font.pointSize(); diff --git a/src/query/reslistpager.cpp b/src/query/reslistpager.cpp index c8519c82..5f31fac6 100644 --- a/src/query/reslistpager.cpp +++ b/src/query/reslistpager.cpp @@ -38,8 +38,8 @@ using std::list; #include "mimehandler.h" // Default highlighter. No need for locking, this is query-only. -static const string cstr_hlfontcolor(""); -static const string cstr_hlendfont(""); +static const string cstr_hlfontcolor(""); +static const string cstr_hlendfont(""); class PlainToRichHtReslist : public PlainToRich { public: virtual string startMatch(unsigned int) @@ -361,9 +361,9 @@ void ResListPager::displayPage(RclConfig *config) << headerContent() << "" << endl << pageTop() - << "

" + << "

" << m_docSource->title() - << "   "; + << "   "; if (pageEmpty()) { chunk << trans("

No results found
");