This uses #4228 to find a monospace font for the qt rpcconsole.
(This replaces, thus closes #6781.)
462 | @@ -463,13 +463,15 @@ void RPCConsole::clear() 463 | 464 | // Set default style sheet 465 | ui->messagesWidget->document()->setDefaultStyleSheet( 466 | + QString::fromStdString(strprintf(
Please use Qt's formatting, instead of strprintf. e.g.
QString("....\1...." ).arg(...)
Binaries are here: https://bitcoin.jonasschnelli.ch/pulls/6864/
Would be good if we get some screenshot from HiDPI Ubuntu and retina OSX.
470 | "td.cmd-request { color: #006060; } "
471 | "td.cmd-error { color: red; } "
472 | "b { color: #006060; } "
473 | - );
474 | -
475 | + ).arg(QFont("Monospace").pointSize() * 4 / 5) // 0.8 em
QFont("Monospace").pointSize() * 4 / 5 is a float, so should this also include a call to QString & QString::setNum(float n, char format = 'g', int precision = 6)?
Also not sure if relevant, but as per the docs .pointSize():
Returns the point size of the font. Returns -1 if the font size was specified in pixels.
Perhaps you also could exchange Monospace with QFont::Monospace... I didn't try the code btw.
Thanks, I have alrady replaced the code with a version that should work on all platforms (and maybe even HiDPI).
850 | @@ -849,4 +851,4 @@ void RPCConsole::showOrHideBanTableIfRequired() 851 | bool visible = clientModel->getBanTableModel()->shouldShow(); 852 | ui->banlistWidget->setVisible(visible); 853 | ui->banHeading->setVisible(visible); 854 | -} 855 | \ No newline at end of file 856 | +}
Nit: Unwanted change
460 | @@ -461,15 +461,30 @@ void RPCConsole::clear() 461 | platformStyle->SingleColorImage(ICON_MAPPING[i].source).scaled(ICON_SIZE, Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); 462 | } 463 | 464 | + QFont fontMatch("Monospace");
What about the QFont::Monospace hint from a few minutes ago, seems clearer?
483 | "td.cmd-request { color: #006060; } "
484 | "td.cmd-error { color: red; } "
485 | "b { color: #006060; } "
486 | - );
487 | -
488 | + ).arg(fi.family(), "10pt")
IIRC the issue from #5898 was mainly the px based font size.
Switching back to "Monospace" could be possible, but needs broad testing and also acceptance.
@jonasschnelli Agree on your comment. Would you mind shooting up some new builds for this PR? =)
460 | @@ -461,15 +461,30 @@ void RPCConsole::clear() 461 | platformStyle->SingleColorImage(ICON_MAPPING[i].source).scaled(ICON_SIZE, Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); 462 | } 463 | 464 | + QFont fontMatch("Monospace"); 465 | + fontMatch.setStyleHint(QFont::TypeWriter); 466 | + QFontInfo fi(fontMatch); 467 | + assert(fi.fixedPitch());
I personally think using an assertion in non-consensus code is too "strong".
Just ignore everything i put in the {//Debug} block for code review. ;)
Looks good here. There used to be problems with (absurdly large) font size in Ubuntu with previous monospace patches, but I'm not seeing that now.
Can't test hidpi though...
Kicked the build server,... new builds should be available within the next 30mins: https://bitcoin.jonasschnelli.ch/pulls/6864/ (reminds me to finally complete my IRC-gitian-build-bot and collect some devs pub keys to allow dev-build-sig-checks)
Ubuntu/Linux HiDPI looks ugly,.. but not related to this PR. Fine for me: <img width="1302" alt="bildschirmfoto 2015-10-22 um 21 27 29" src="https://cloud.githubusercontent.com/assets/178464/10676095/44df62e2-7904-11e5-9976-5b8dad3c4bc3.png">
Crash on OSX:
jonasschnelli$ ~/Desktop/bitcoin-qt --regtest
Assertion failed: (fixedFontInfo.fixedPitch()), function clear, file qt/rpcconsole.cpp, line 470.
To properly support HiDPI, I think we need to do the switch to qt5.
Windows works now, as well. (Courier New 10pt)

To properly support HiDPI, I think we need to do the switch to qt5.
Supporting HiDPI is not a requirement for Qt4. All the distribution binaries are built with Qt5. We still support Qt4 in the same way as websites support IE6, e.g. bare-bones: functionality must work but it is allowed to be ugly.
Uh, Qt4 should remain a fully-supported platform until KDE has finished switching away from it... (this case would be an exception IMO since Qt4 itself lacks HiDPI support.)
@jonasschnelli Your OS X binaries are crashing for me, are you having any issue with them?
@fanquake: the crash is related to the PR. Monospace is not available on Mac (or something similar).
@fanquake: you probably picked an old build. Always check the git tip. Just re-started the build of the PR.
This is ready for review now. @fanquake and reviewers: Please use jonasschnelli's binaries for debug (send me stdout when no monospace font is found).
The code in this PR has the debug to stdout removed in 1d15e0e762cdfa83d4f98d96e532e35c0f8f6cf4 , was squashed and force pushed.
On the first glimpse (general UI, address manager, debug console) it looks good on Win10:

I don't have a fixed space font on OSX. Also the font is relatively small now.
This PR: <img width="1190" alt="bildschirmfoto 2015-10-26 um 17 16 46" src="https://cloud.githubusercontent.com/assets/178464/10734817/6c815072-7c05-11e5-8855-8fe3f0681257.png">
Current ~Master: <img width="1190" alt="bildschirmfoto 2015-10-26 um 09 26 24" src="https://cloud.githubusercontent.com/assets/178464/10734830/76316bc0-7c05-11e5-8124-bd25c9cc3dec.png">
Also the font is relatively small now.
In this case I wouldn't further increase the size, because then it probably gets too big on the other OS, but I agree, it looks too small.
While this doesn't seem to be an issue with fixed space font (especially since it's not available on OS X, as it seems), it may be worth to consider using a relative size based on a common, well sized font as reference, i.e. instead of using 10pt:
@dexX7 If there was a "reference font", you could as well just not set the pt size at all, I guess. Let's try this?
Latest changes have brought back my original issue with monospace console: childishly large letters on Ubuntu
(just compare with above screenshot, or the default terminal font in the background)
@MarcoFalke: If there was a "reference font", you could as well just not set the pt size at all, I guess. Let's try this?
I may be completely wrong, but font size and font type seems to be coupled, and a mono space font appears to be bigger than a "standard" font without explicit size, so we'd need to set a size nevertheless.
But there are several UI elements, which already look good on all OS, whether it's the timestamp in the RPC console, the balances on the overview tab, or other text elements.
So what if the actual size of the "reference font" is used explicitly?
I haven't tested the following, but just to give you an idea of what I was thinking about::
// Set default style sheet
+ QFontInfo fixedFontInfo(GUIUtil::fixedPitchFont());
ui->messagesWidget->document()->setDefaultStyleSheet(
+ QString(
"table { }"
"td.time { color: [#808080](/bitcoin-bitcoin/808080/); padding-top: 3px; } "
+ "td.message { font-family: %1; font-size: %2pt, white-space:pre-wrap; } "
"td.cmd-request { color: [#006060](/bitcoin-bitcoin/006060/); } "
"td.cmd-error { color: red; } "
"b { color: [#006060](/bitcoin-bitcoin/006060/); } "
- );
+ ).arg(fixedFontInfo.family()).arg(QFont().pointSize()) // size of "reference font"
+ );
QFont() may be replaced with something else, in case another font is used as "reference".
Hmm.. I'm just testing it on Ubuntu now, and it seems to work. However, there is quite a difference in the appearance depending on the actual font, even if the font size is similar.
When using QFont().family() (basically what was used before this PR):

When using GUIUtil::fixedPitchFont().family():

Here is another very interesting idea, which I stumbled upon while looking for a solution for OS X (via http://stackoverflow.com/a/1471899):
Instead of manually finding a monospaced font and size, what if the <pre> HTML tag is used instead? It should definitely work cross-plattform, and it should have the properties we want: a fixed-width font and preservation of white-spaces. As per default, line breaks are also preserved, which may, or may not be desired:
Without line breaks (http://pastebin.com/nmWbwYpT):

With line breaks (http://pastebin.com/4c29AdNL):

While this probably needs some tuning, I believe going the <pre></pre> route is more reliable and straight forward.
Unfortunately, pre seems to have a different font, but also very large font size on Ubuntu (looks even larger than what was tried before..).
Hmm... I question myself: is this worth the effort? Why not just using "Courier" which should be available on any OS and would be similar to browsers showing code.
Or, if more control is desirable: add a monospace otf font (one with Apache or MIT license) to the qrc file and add it to the QFontManager. Fonts are small, I'll guess ~30kb.
The default setting on Ubuntu for fixed-width fonts is Ubuntu Mono with a size of 13 (which is larger than the others with 11), if I'm not mistaken.
I guess it comes down to where this should go, and whether the font (and size) should be defined by the application or externally.
Why not just using "Courier" which should be available on any OS
This is pretty straight forward, and I tend to believe Bitcoin Core should look shiny out of the box, without messing with the underlying system, so +1, this is probably worth a try.
@jonasschnelli I agree this is getting too messy. But I'd rather not hard code a font or include one right now. If there is a problem with fixed font, qt and OSX this is a greater problem and should be addressed in a follow up PR.
Maybe you retrigger the builds once more and check if the font has the correct size. I will check the other OSs. If the size is ok, let's merge this. Otherwise I better close this and open a different PR with a new approach.
Looks good to me. Hopefully it works on OS X.
Windows 10:

Ubuntu:

Seems not to work on OSX: Console prints:
Error: No monospace font found! Please report!
family: Lucida Grande
pixelS: 12
pointS: 12
pointS: (QFont()) 13
2015-10-29 12:53:49
<img width="1190" alt="bildschirmfoto 2015-10-29 um 13 53 57" src="https://cloud.githubusercontent.com/assets/178464/10818809/88fc0cb0-7e44-11e5-916a-c8b1409f4811.png">
Ok, then. Can we try to tackle the OSX error: no monospace found in another PR?
At least it seems for all tested OS the font size is correct and the white space is preserved. Only OSX can't find a fixed pitch font but this is already the behavior bitcoin/master. So nothing gets worse if I squash the commits and this gets merged?
As soon as the std::out debug infos are gone (maybe remove entirely or LogPrintf) i would ACK this PR (improvement for Windows/Linux).
Also:
* Preserve white space
* Make fixed font as large as default font
@jonasschnelli Lucida Grande can be monospace. According to your screenshot it also looks monospace but I am not sure why QT does not detect it as such...
For reference the binaries were built with eb475c0.
I removed the logging again and force pushed a squash.
If no one complains, this should be merged.
More screenshots:






Still has a crazily big font on Ubuntu. Tending towards closing this, it's not worth the hassle.
@laanwj Unfortunately I can not reproduce the issue you mentioned. I did a fresh install of Ubuntu 15.10 and got the results below. Also, @dexX7 could not find an issue for Ubuntu. Maybe you changed the default settings for the system fonts accidentally?
$ gsettings list-recursively org.gnome.desktop.interface|egrep "(font|text-scaling)"
org.gnome.desktop.interface monospace-font-name 'Ubuntu Mono 13'
org.gnome.desktop.interface text-scaling-factor 1.0
org.gnome.desktop.interface font-name 'Ubuntu 11'
org.gnome.desktop.interface document-font-name 'Sans 11'


(screenshots from @jonasschnelli)
<img width="1190" alt="76316bc0-7c05-11e5-8124-bd25c9cc3dec" src="https://cloud.githubusercontent.com/assets/6399679/10882080/1eb2e6d6-8168-11e5-8a7f-dd7c6de3211d.png"> - This PR
<img width="1190" alt="88fc0cb0-7e44-11e5-916a-c8b1409f4811" src="https://cloud.githubusercontent.com/assets/6399679/10882082/26e5465a-8168-11e5-86df-8ffbc9931f42.png">
Looks like it's the same:
$ gsettings list-recursively org.gnome.desktop.interface|egrep "(font|text-scaling)"
org.gnome.desktop.interface monospace-font-name 'Ubuntu Mono 13'
org.gnome.desktop.interface text-scaling-factor 1.0
org.gnome.desktop.interface font-name 'Ubuntu 11'
org.gnome.desktop.interface document-font-name 'Sans 11'
Have tried it on two systems. I'm using Ubuntu 14.04 and Qt5. I compile using the system's Qt5 library and am not using depends. It is curious that 15.10 does display it in a normal font so maybe it's an Ubuntu issue that was fixed but not in LTS.
Edit: tried with Qt4, same problem. I'll try with a 15.10 VM.
15.10 - fresh install. What am I doing wrong?
Before:

After:

@laanwj Thank you for trying this. Would you mind to edit your posts to include the screenshots for the build without this PR?
Added for the 15.10 VM above: for the others the effect is exactly the same, except for the code changes as they were at the beginning of this pull request, there the fixed and proportional font were almost the same size.
[...] beginning of this pull request, there the fixed and proportional font were almost the same size.
Yes, it was "hard-coded" at 10pt but @jonasschnelli complained 10pt won't work in OS X, IIRC.
So it looks like Ubuntu consistently specifies a huge monospace default font. I guess that's simply the Ubuntu Mono 13 from qsettings? That's kind of annoying. I just never noticed on other programs - there are only few programs that use monospace besides the terminal, which seems to choose its own.
The only thing I don't understand is that you don't get the same.
Tested ACK.
Ubuntu: <img width="492" alt="bildschirmfoto 2015-11-03 um 10 05 54" src="https://cloud.githubusercontent.com/assets/178464/10904301/8580eee4-8212-11e5-816d-e392deec1920.png"> <img width="479" alt="bildschirmfoto 2015-11-03 um 10 05 44" src="https://cloud.githubusercontent.com/assets/178464/10904302/85be809c-8212-11e5-8c6e-fbfd6d46684b.png">
<img width="328" alt="bildschirmfoto 2015-11-03 um 10 08 58" src="https://cloud.githubusercontent.com/assets/178464/10904373/fe39946c-8212-11e5-8479-9d99e5f909cf.png">
Ubuntu HiDPI: <img width="1178" alt="bildschirmfoto 2015-11-03 um 10 03 39" src="https://cloud.githubusercontent.com/assets/178464/10904310/94e04362-8212-11e5-9cb3-def7d9e9ca23.png">
OSX: <img width="1190" alt="bildschirmfoto 2015-11-03 um 10 04 40" src="https://cloud.githubusercontent.com/assets/178464/10904315/9bb652da-8212-11e5-87d9-1f550404b344.png">
Maybe someone can test this over a Qt4 build? (@luke-jr)?
I've already tested Qt4. Works OK.
I guess that's simply the Ubuntu Mono 13 from qsettings?
No, qt selects "DejaVu Sans Mono 12", and I set the size to QFontInfo(QFont()).pointSize(), which is less than 12pt (e.g. 10pt or 9pt) but equal to the font height we had before for the rpc console.
the terminal, which seems to choose its own.
No, terminal chooses the default "Ubuntu Mono 13".
The only thing I don't understand is that you don't get the same.
Maybe, there is a difference when you use the gitian builds by jonasschnelli ( 9pt) and your own build (10pt). Probably, because gitian uses qt5 and you are using qt4?
@laanwj The monospace font appears larger than the non monospace font because it consumes way more horizontal space. The only thing I can do here is to scale the font's height by a hard coded factor (like ~95%).
I have added a commit to do just that. If a constant factor can't fix your concern (exact value up for bike shedding), you are welcome to close this PR.
Maybe, there is a difference when you use the gitian builds by jonasschnelli ( 9pt)
Right - the gitian build by jonasschelli uses static qt from the depends system, I build against the system's Qt5 library (this is what the Ubuntu PPA does). Fine with a fixed factor, seems an Ubuntu problem, don't want to bikeshed this further either.
As OS X was the only one getting it right, I expect the constant factor makes the font look smaller now on OS X. Hopefully such that it is still acceptable.
I think this is a improvement over the current version and the PR is pretty clean. Minor font size differences are an upstream issue IMO and still result in a adequate quality. Also the indent formatting increase readability.
@jonasschnelli So you are against 268b79e?
461 | @@ -462,13 +462,19 @@ void RPCConsole::clear() 462 | } 463 | 464 | // Set default style sheet 465 | + QFontInfo fixedFontInfo(GUIUtil::fixedPitchFont()); 466 | + // Try to make fixed font adequately large on different OS 467 | + QString ptSize = QString("%1pt").arg(QFontInfo(QFont()).pointSize() * 8.5 / 9);
This seems weird. Why is this not simply using fixedFontInfo.pointSize()?
I also preferred to non-* 8.5 / 9 solution. But i have ACKed this solution because it might slightly reduce the size of mostly-oversized monospace fonts. But a *0.95 instead a * 8.5/9 would be cleaner, right.
@luke-jr fixedFontInfo.pointSize() is 12, so way too large. Also, people were requesting that the fixed pitch font is exactly the same size as the previous default font.
@jonasschnelli QFontInfo(QFont()).pointSize() is 9, often. So we get a 8.5pt in this case instead of a longer float.
@MarcoFalke If fixedFontInfo.pointSize() is wrong, then that should be fixed instead. If people merely don't have their systems configured correctly, that isn't a problem we should try to workaround in the application.
@luke-jr Maybe you could do something like http://stackoverflow.com/a/12179548 to read the system default font. But I am not planning to do this within this PR, as this will likely change the text for the whole GUI.
I see only three options for this PR:
268b79ef0c54a3bff0b50e093b98b943e49a4939 looks fine to me, but it can be improved by using the fixed font for the input as well. This nit should at least get a comment explaining the rationale. Also, next time, please do the rename (bitcoinAddressFont -> fixedPitchFont) in a dedicated commit.
This is already bikeshedded to death, please let's not start another round. I personally couldn't care less if the console font is monospace or proportional but some people want this and it seems to work acceptably, so I'm going to merge it now.