Musescore 3 FreeSans bold text rendering is bad
Reported version
3.0
Priority
P2 - Medium
Type
Functional
Frequency
Once
Severity
S3 - Major
Reproducibility
Always
Status
closed
Regression
Yes
Workaround
No
Project
Came up in https://musescore.org/en/node/281541
The reason most probably is that we don't package a Bold (nor Italic or BoldItalic) version of FreeSans (but do for FreeSerif) and that converting a normal font to Bold generally gives rather bad results (not so much for Italic, IIRC)
As per https://www.fontspace.com/gnu-freefont/freesans, https://en.wikipedia.org/wiki/GNU_FreeFont and https://www.gnu.org/software/freefont/ there is a FreeSans Bold and a FreeSans Oblique and a FreeSans BoldOblique (Oblique rather than Italic, but seems to be the same thing), and also a Free Mono family.
So the fix would be quite easy(?): add those fonts to the package.
Fix version
3.5.0
Comments
It happens to all Sans-serif fonts. From top to bottom: "EngraversGothic BT" "Freehand591" and "Arial"
All text is rendered right when zoomed in.
Came up again https://musescore.org/en/node/282300
I found an easy way to reproduce this bug using a Kubuntu 18.04.1 live CD/USB image. The bug also happens on my KDE neon installation and probably also happens with Kubuntu 18.10, but I haven't tested this. Here are the steps:
Also note the following:
In Windows the problem disappears if freetype is not used as the font rendering engine, i.e. if the lines
[Platforms]
WindowsArguments = fontengine=freetype
are removed from bin/qt.conf (it can be done with any text editor).
These were added to solve #276566: [Windows] underline too close to (lyrics) letters, but apparently freetype engine has some problems for some settings, since the bug appears also under Linux.
Is there maybe a way to disable such setting also under Windows, or to force MuseScore to not use the anti-aliasing for its font drawing?
In reply to In Windows the problem… by ABL
Tested now in the latest Nightly, removing the line in QT.conf seems to solve the ugly bold caracters.
Looks better for now, with various fonts.
OS: Windows 7 SP 1 (6.1), Arch.: x86_64, MuseScore version (64-bit): 3.0.2.5171, revision: bafeb45
I found another interesting clue. In my post above, compare the words "arco" and "pizz" between the two screenshots and you'll notice a difference in the italics rendering, particularly with the letters "a" and "z". The first screenshot appears to be using the designated italics glyphs from the font, whereas the second screenshot seems to be creating the italics effect by slanting the standard glyphs. Here is how the FreeSerif font renders in LibreOffice for normal, italics and bold text:
Notice how the italic "a" and "z" have distinctly different style than the normal font.
So, it would appear that this bug is causing a "fake" italic and bold effect to be applied to the font rather than using the style provided by the font.
In reply to I found another interesting… by s.chriscollins
So, I think I know what is happening here. The wonky bold text occurs under KDE Plasma desktops in Linux if the ~/.config/kdeglobals file contains a font= line in the [General] section (in my case, the line is "font=Noto Sans,10,-1,5,50,0,0,0,0,0,Regular", which is the Kubuntu default). In a fresh install, this line is not present in ~/.config/kdeglobals, but will be written (along with fixed=, menuFont= lines and a few others) if the user customizes anything in the KDE System Settings fonts panel.
After removing the font= line, MuseScore's fonts again look correct. However, this is not a good workaround, as it might cause issues with visual consistency among other Qt-based applications. Perhaps MuseScore could either ignore by default or at least provide the option to ignore ~/.config/kdeglobals altogether?
Okay, so I found some more information on why this is happening. Check out the following bug reports:
As a workaround, KDE users can edit the following files to remove the text ",Regular" (without quotes, notice the comma) from the end of font definition lines. Just search for and delete all instances of the text ",Regular":
So, for example, the following line:
font=Noto Sans,9,-1,5,50,0,0,0,0,0,Regular
...should be changed to:
font=Noto Sans,9,-1,5,50,0,0,0,0,0
Please note that you will need to repeat this action any time you make changes in the KDE System Settings fonts panel.
I don't know if the Linux one is the same as the Windows bug.
I managed to use the debug version of Qt libraries and found that in the Windows case the different behavior at different scale magnifications is caused by using or not using cached font shapes.
Indeed, the "bad" bold font case has the following backtrace: (line numbers are off by 1 because of using release with forced debug info for the Qt libraries)
Qt5Gui.dll!QRasterPaintEngine::drawCachedGlyphs(int numGlyphs, const unsigned int * glyphs, const QFixedPoint * positions, QFontEngine * fontEngine) qpaintengine_raster.cpp(2912)
Qt5Gui.dll!QRasterPaintEngine::drawTextItem(const QPointF & p, const QTextItem & textItem) qpaintengine_raster.cpp(3191)
Qt5Gui.dll!QPainterPrivate::drawTextItem(const QPointF & p, const QTextItem & _ti, QTextEngine * textEngine) qpainter.cpp(6531)
Qt5Gui.dll!QPainter::drawTextItem(const QPointF & p, const QTextItem &) qpainter.cpp(6398)
Qt5Gui.dll!QPainter::drawText(const QPointF & p, const QString & str, int tf, int justificationPadding) qpainter.cpp(5933)
Qt5Gui.dll!QPainter::drawText(const QPointF & p, const QString & str) qpainter.cpp(5710)
MuseScore3.exe!Ms::TextFragment::draw(QPainter * p, const Ms::TextBase * t) musescore\libmscore\textbase.cpp(490)
while in the case of "good" bold font:
Qt5Gui.dll!QPaintEngineEx::drawStaticTextItem(QStaticTextItem * staticTextItem) qpaintengineex.cpp(1062)
Qt5Gui.dll!QRasterPaintEngine::drawTextItem(const QPointF & p, const QTextItem & textItem) qpaintengine_raster.cpp(3218)
Qt5Gui.dll!QPainterPrivate::drawTextItem(const QPointF & p, const QTextItem & _ti, QTextEngine * textEngine) qpainter.cpp(6531)
Qt5Gui.dll!QPainter::drawTextItem(const QPointF & p, const QTextItem &) qpainter.cpp(6398)
Qt5Gui.dll!QPainter::drawText(const QPointF & p, const QString & str, int tf, int justificationPadding) qpainter.cpp(5933)
Qt5Gui.dll!QPainter::drawText(const QPointF & p, const QString & str) qpainter.cpp(5710)
MuseScore3.exe!Ms::TextFragment::draw(QPainter * p, const Ms::TextBase * t) musescore\libmscore\textbase.cpp(490)
The use or not of cached glyphs is determined by function QPaintEngineEx::shouldDrawCachedGlyphs (here: https://code.woboq.org/qt5/qtbase/src/gui/painting/qpaintengineex.cpp.h… ), which ends with these lines:
qreal pixelSize = fontEngine->fontDef.pixelSize;
return (pixelSize * pixelSize * qAbs(m.determinant())) < maxCachedGlyphSizeSquared;
Now, in my system for FreeSans I see:
maxCachedGlyphSizeSquared = 4096
pixelSize = 120
and m is a square 2x2 matrix which for 100% zoom is [0.27974195 0; 0 0.27974195] and it scales accordingly to the zoom level. For these values then the switch between the two behavior happens at zoom value:
sqrt(4096/120^2)/0.27974195*100 ~ 190.65%
which is what I see: for zoom >=191% the bold is good, for zoom <191% the bold is bad.
I tried, but I don't know how to force freetype engine not to use the cached glyphs (or if this is even possible).
Is it possible to somehow rescale the zoom matrix m?
I found that it is possible to reduce the cached glyph size by using an environment variable.
Indeed, in a command line prompt by doing
set QT_MAX_CACHED_GLYPH_SIZE=1
and then launching (from the same command prompt) MuseScore3, no glyph is cached and the bug is apparently solved.
However, this probably introduces a slowing down of text rendering, and it is not clear to me if we can define such env variable when starting MuseScore (maybe with qputenv ?)
See https://github.com/musescore/MuseScore/pull/5794
probaby with setenv or putenv very early in main before calling the first Qt function or instantiating the first Qt object (which means before constructors of local variables run), but we're not going to require qt 5.12 for a loooong time
Fixed in branch 3.x, commit d5e7249f9a
fix #281601 and fix #284218 [workaround]: broken on-screen rendering of synthetically emboldened fonts
Fixed in branch 3.x, commit eb33bfa833
_Merge pull request #5794 from AntonioBL/boldfont
fix #281601 and fix #284218 [workaround]: broken on-screen rendering …_
Automatically closed -- issue fixed for 2 weeks with no activity.