compensate for off-by-3 error when setting webkit font size with QWebSettings. Experiment (ifndefed) with using css instead
This commit is contained in:
parent
7714de2cac
commit
c28b1f91cc
@ -70,6 +70,13 @@ static const QKeySequence closeKeySeq("Ctrl+w");
|
|||||||
#include <QWebSettings>
|
#include <QWebSettings>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Decide if we set font family and style with a css section in the
|
||||||
|
// html <head> 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 {
|
class QtGuiResListPager : public ResListPager {
|
||||||
public:
|
public:
|
||||||
QtGuiResListPager(ResList *p, int ps)
|
QtGuiResListPager(ResList *p, int ps)
|
||||||
@ -175,7 +182,18 @@ string QtGuiResListPager::prevUrl()
|
|||||||
|
|
||||||
string QtGuiResListPager::headerContent()
|
string QtGuiResListPager::headerContent()
|
||||||
{
|
{
|
||||||
return (const char *)prefs.reslistheadertext.toUtf8();
|
string out;
|
||||||
|
#ifdef SETFONT_WITH_HEADSTYLE
|
||||||
|
out = "<style type=\"text/css\">\nbody,table,select,input {\n";
|
||||||
|
char ftsz[30];
|
||||||
|
sprintf(ftsz, "%d", prefs.reslistfontsize);
|
||||||
|
out += string("font-family: \"") + qs2utf8s(prefs.reslistfontfamily)
|
||||||
|
+ "\";\n";
|
||||||
|
out += string("font-size: ") + ftsz + "pt;\n";
|
||||||
|
out += string("}\n</style>\n");
|
||||||
|
#endif
|
||||||
|
out += qs2utf8s(prefs.reslistheadertext);
|
||||||
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtGuiResListPager::suggest(const vector<string>uterms,
|
void QtGuiResListPager::suggest(const vector<string>uterms,
|
||||||
@ -378,10 +396,13 @@ void ResList::setFont()
|
|||||||
QTextBrowser::setFont(QFont());
|
QTextBrowser::setFont(QFont());
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
#ifndef SETFONT_WITH_HEADSTYLE
|
||||||
QWebSettings *websettings = settings();
|
QWebSettings *websettings = settings();
|
||||||
if (prefs.reslistfontfamily.length()) {
|
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,
|
websettings->setFontSize(QWebSettings::DefaultFontSize,
|
||||||
prefs.reslistfontsize);
|
prefs.reslistfontsize + 3);
|
||||||
websettings->setFontFamily(QWebSettings::StandardFont,
|
websettings->setFontFamily(QWebSettings::StandardFont,
|
||||||
prefs.reslistfontfamily);
|
prefs.reslistfontfamily);
|
||||||
} else {
|
} else {
|
||||||
@ -389,6 +410,7 @@ void ResList::setFont()
|
|||||||
websettings->resetFontFamily(QWebSettings::StandardFont);
|
websettings->resetFontFamily(QWebSettings::StandardFont);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
int ResList::newListId()
|
int ResList::newListId()
|
||||||
|
|||||||
@ -377,10 +377,14 @@ void UIPrefsDialog::showFontDialog()
|
|||||||
|
|
||||||
font = QFontDialog::getFont(&ok, font, this);
|
font = QFontDialog::getFont(&ok, font, this);
|
||||||
if (ok) {
|
if (ok) {
|
||||||
// Check if the default font was set, in which case we
|
// We used to check if the default font was set, in which case
|
||||||
// erase the preference
|
// 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;
|
QString s;
|
||||||
if (font.family().compare(this->font().family()) ||
|
if (1 || font.family().compare(this->font().family()) ||
|
||||||
font.pointSize() != this->font().pointSize()) {
|
font.pointSize() != this->font().pointSize()) {
|
||||||
reslistFontFamily = font.family();
|
reslistFontFamily = font.family();
|
||||||
reslistFontSize = font.pointSize();
|
reslistFontSize = font.pointSize();
|
||||||
|
|||||||
@ -38,8 +38,8 @@ using std::list;
|
|||||||
#include "mimehandler.h"
|
#include "mimehandler.h"
|
||||||
|
|
||||||
// Default highlighter. No need for locking, this is query-only.
|
// Default highlighter. No need for locking, this is query-only.
|
||||||
static const string cstr_hlfontcolor("<font color=\"blue\">");
|
static const string cstr_hlfontcolor("<span style='color: blue;'>");
|
||||||
static const string cstr_hlendfont("</font>");
|
static const string cstr_hlendfont("</span>");
|
||||||
class PlainToRichHtReslist : public PlainToRich {
|
class PlainToRichHtReslist : public PlainToRich {
|
||||||
public:
|
public:
|
||||||
virtual string startMatch(unsigned int)
|
virtual string startMatch(unsigned int)
|
||||||
@ -361,9 +361,9 @@ void ResListPager::displayPage(RclConfig *config)
|
|||||||
<< headerContent()
|
<< headerContent()
|
||||||
<< "</head><body>" << endl
|
<< "</head><body>" << endl
|
||||||
<< pageTop()
|
<< pageTop()
|
||||||
<< "<p><font size=+1><b>"
|
<< "<p><span style=\"font-size:110%;\"><b>"
|
||||||
<< m_docSource->title()
|
<< m_docSource->title()
|
||||||
<< "</b></font> ";
|
<< "</b></span> ";
|
||||||
|
|
||||||
if (pageEmpty()) {
|
if (pageEmpty()) {
|
||||||
chunk << trans("<p><b>No results found</b><br>");
|
chunk << trans("<p><b>No results found</b><br>");
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user