Skip to content

Commit

Permalink
Merge pull request #5794 from AntonioBL/boldfont
Browse files Browse the repository at this point in the history
fix #281601 and fix #284218 [workaround]: broken on-screen rendering …
  • Loading branch information
anatoly-os authored Jun 6, 2020
2 parents 4a1d51b + 1cf3237 commit eb33bfa
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 1 deletion.
69 changes: 69 additions & 0 deletions libmscore/textbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -519,8 +519,77 @@ void TextFragment::draw(QPainter* p, const TextBase* t) const
{
QFont f(font(t));
f.setPointSizeF(f.pointSizeF() * MScore::pixelRatio);
#ifndef Q_OS_MACOS
qreal mm = p->worldTransform().m11();
if (!(MScore::pdfPrinting) && (mm < 1.0) && f.bold()) {
// workaround for https://musescore.org/en/node/284218
// and https://musescore.org/en/node/281601
// only needed for certain artificially emboldened fonts
// see https://musescore.org/en/node/281601#comment-900261
// in Qt 5.12.x this workaround should be no more necessary if
// env variable QT_MAX_CACHED_GLYPH_SIZE is set to 1
p->save();
qreal dx = p->worldTransform().dx();
qreal dy = p->worldTransform().dy();
// diagonal elements will now be changed to 1.0
p->setMatrix(QMatrix(1.0, 0.0, 0.0, 1.0, dx, dy));
// correction factor for bold text drawing, due to the change of the diagonal elements
qreal factor = 1.0 / mm;
QFont fnew(f, p->device());
fnew.setPointSizeF(f.pointSizeF() / factor);
QRawFont fRaw = QRawFont::fromFont(fnew);
QTextLayout textLayout(text, f, p->device());
textLayout.beginLayout();
while (true) {
QTextLine line = textLayout.createLine();
if (!line.isValid())
break;
}
textLayout.endLayout();
// glyphruns with correct positions, but potentially wrong glyphs
// (see bug https://musescore.org/en/node/117191 regarding positions and DPI)
QList<QGlyphRun> glyphruns = textLayout.glyphRuns();
qreal offset = 0;
// glyphrun drawing has an offset equal to the max ascent of the text fragment
for (int i = 0; i < glyphruns.length(); i++) {
qreal value = glyphruns.at(i).rawFont().ascent() / factor;
if (value > offset)
offset = value;
}
for (int i = 0; i < glyphruns.length(); i++) {
QVector<QPointF> positions1 = glyphruns.at(i).positions();
QVector<QPointF> positions2;
// calculate the new positions for the scaled geometry
for (int j = 0; j < positions1.length(); j++) {
QPointF newPoint = positions1.at(j) / factor;
positions2.append(newPoint);
}
QGlyphRun glyphrun2 = glyphruns.at(i);
glyphrun2.setPositions(positions2);
// change the glyphs with the correct glyphs
// and account for glyph substitution
if (glyphrun2.rawFont().familyName() != fnew.family()) {
QFont f2(fnew);
f2.setFamily(glyphrun2.rawFont().familyName());
glyphrun2.setRawFont(QRawFont::fromFont(f2));
}
else
glyphrun2.setRawFont(fRaw);
p->drawGlyphRun(QPointF(pos.x() / factor, pos.y() / factor - offset),glyphrun2);
positions2.clear();
}
// Restore the QPainter to its former state
p->setMatrix(QMatrix(mm, 0.0, 0.0, mm, dx, dy));
p->restore();
}
else {
p->setFont(f);
p->drawText(pos, text);
}
#else
p->setFont(f);
p->drawText(pos, text);
#endif
}

//---------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion mscore/preferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ void Preferences::init(bool storeInMemoryOnly)
{PREF_EXPORT_MP3_BITRATE, new IntPreference(128, false)},
{PREF_EXPORT_MUSICXML_EXPORTBREAKS, new EnumPreference(QVariant::fromValue(MusicxmlExportBreaks::ALL), false)},
{PREF_EXPORT_MUSICXML_EXPORTLAYOUT, new BoolPreference(true, false)},
{PREF_EXPORT_PDF_DPI, new IntPreference(300, false)},
{PREF_EXPORT_PDF_DPI, new IntPreference(DPI, false)},
{PREF_EXPORT_PNG_RESOLUTION, new DoublePreference(DPI, false)},
{PREF_EXPORT_PNG_USETRANSPARENCY, new BoolPreference(true, false)},
{PREF_IMPORT_GUITARPRO_CHARSET, new StringPreference("UTF-8", false)},
Expand Down

1 comment on commit eb33bfa

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an automatic message. This commit appears to change some of the visual tests.
Please carefully review the new visual test results in the uploaded artifact that can be found
here

Please sign in to comment.