Summary: | Monospace fonts are not working in QtWebKit 2.3.0 | ||
---|---|---|---|
Product: | WebKit | Reporter: | Dmitry Shachnev <mitya57> |
Component: | WebKit Qt | Assignee: | Nobody <webkit-unassigned> |
Status: | RESOLVED INVALID | ||
Severity: | Major | CC: | allan.jensen, anonymous, thiago |
Priority: | P2 | ||
Version: | 528+ (Nightly build) | ||
Hardware: | PC | ||
OS: | Linux | ||
Bug Depends on: | |||
Bug Blocks: | 88186 |
Description
Dmitry Shachnev
2013-04-15 04:36:13 PDT
It works fine here. Perhaps you are missing the default monospace font, so it falls back to sans-serif? Note, that the web-inspector is also rendered using webkit and correctly uses a monospace font. The default monospace font can be set by the application, but if your test example is failing it means the default default is not working in your case. The default fonts in qtwebkit is set using this code: QFont defaultFont; defaultFont.setStyleHint(QFont::Serif); d->fontFamilies.insert(QWebSettings::StandardFont, defaultFont.defaultFamily()); d->fontFamilies.insert(QWebSettings::SerifFont, defaultFont.defaultFamily()); defaultFont.setStyleHint(QFont::Fantasy); d->fontFamilies.insert(QWebSettings::FantasyFont, defaultFont.defaultFamily()); defaultFont.setStyleHint(QFont::Cursive); d->fontFamilies.insert(QWebSettings::CursiveFont, defaultFont.defaultFamily()); defaultFont.setStyleHint(QFont::SansSerif); d->fontFamilies.insert(QWebSettings::SansSerifFont, defaultFont.defaultFamily()); defaultFont.setStyleHint(QFont::Monospace); d->fontFamilies.insert(QWebSettings::FixedFont, defaultFont.defaultFamily()); Could you test what font you get on your machine with a QFont::setStyleHint(QFont::Monospace) and QFont::defaultFamily() ? It sounds like an issue in Qt, fontconfig, or probably their configuration on Ubuntu 13.04. defaultFamily() of QFont::Monospace is "Courier New", but that font doesn't exist in the system, so probably this is the issue. But, for some reason, monospace font works in Web Inspector and other widgets. In example, this works OK (and the font is really monospace): QFont font; QTextEdit edit; font.setFamily ("monospace"); edit.setFont (font); I tested this on Kubuntu 13.04 live image, will test on my home PC tomorrow. Oh, I just found this in qfont_x11.cpp: QString QFont::defaultFamily() const { ... case QFont::Monospace: return QString::fromLatin1("Courier New"); ... } If (for some reasons) Qt doesn't use font from system settings, maybe it'll make sense to use "monospace" instead of "Courier New", that works in GNOME, KDE and Windows (at least). (In reply to comment #4) > Oh, I just found this in qfont_x11.cpp: > > QString QFont::defaultFamily() const > { > ... > case QFont::Monospace: > return QString::fromLatin1("Courier New"); > ... > } > > If (for some reasons) Qt doesn't use font from system settings, maybe it'll make sense to use "monospace" instead of "Courier New", that works in GNOME, KDE and Windows (at least). Yes. Is that the same in the official Qt 4.8 release? If so, I would suggest opening a bug report on it at qt-project.org Probably this should fix the issue: --- a/src/plugins/platforms/fontdatabases/fontconfig/qfontconfigdatabase.cpp +++ b/src/plugins/platforms/fontdatabases/fontconfig/qfontconfigdatabase.cpp @@ -285,6 +285,7 @@ static const char *getFcFamilyForStyleHint(const QFont::StyleHint style) stylehint = "serif"; break; case QFont::TypeWriter: + case QFont::Monospace: stylehint = "monospace"; break; default: Not tested yet, will test and submit to codereview later. (In reply to comment #6) > Probably this should fix the issue: No, it didn’t help :( I have now reported https://bugreports.qt-project.org/browse/QTBUG-30785. After some debugging, I would say that this is *not* a Qt issue. Though there is no “Courier New” font in my system, FontConfig considers it as an alias for “Liberation Mono” font, using the rule defined in /etc/fonts/conf.d/30-metric-aliases.conf. If I create a QFont with family “Courier New” and apply it to a widget (i.e. QTextEdit), it will work properly. Even more, if I create an HTML block with “font-family: 'Courier New'” style, QtWebKit *will render it properly*. So, I believe it is a bug in QtWebKit. To be precise, QtWebKit is able to render that font properly (as we can see in the web inspector), but doesn’t do that. Sorry for the noise, I’m going to correct an error in my previous comment:
> Even more, if I create an HTML block with “font-family: 'Courier New'” style, QtWebKit *will render it properly*.
That’s not true. QTextEdit will render it, but QtWebKit won’t (which again indicates that it is a bug in QtWebKit).
Allan, do you have any further ideas? I can confirm this bug. Marking INVALID, as Qt port no longer exists in WebKit trunk. |