Skip to content

Commit

Permalink
fix for musescore#14435 and possibly musescore#12714 : use a differen…
Browse files Browse the repository at this point in the history
…t workaround for artificially emboldened text
  • Loading branch information
AntonioBL committed Jul 3, 2023
1 parent dd35365 commit d1fe90a
Show file tree
Hide file tree
Showing 13 changed files with 10 additions and 119 deletions.
10 changes: 10 additions & 0 deletions src/app/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ int App::run(int argc, char** argv)
qputenv("QT_STYLE_OVERRIDE", "Fusion");
qputenv("QML_DISABLE_DISK_CACHE", "true");

//! NOTE 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
//! after Qt 5.12.x the use of env variable QT_MAX_CACHED_GLYPH_SIZE
//! set to 1 is a workaround to avoid the bug
#ifndef Q_OS_MACOS
qputenv("QT_MAX_CACHED_GLYPH_SIZE", "1");
#endif

#ifdef Q_OS_LINUX
if (qEnvironmentVariable("QT_QPA_PLATFORM") != "offscreen") {
qputenv("QT_QPA_PLATFORMTHEME", "gtk3");
Expand Down
5 changes: 0 additions & 5 deletions src/engraving/infrastructure/paintdebugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,6 @@ void PaintDebugger::drawText(const RectF& rect, int flags, const String& text)
m_real->drawText(rect, flags, text);
}

void PaintDebugger::drawTextWorkaround(const Font& f, const PointF& pos, const String& text)
{
m_real->drawTextWorkaround(f, pos, text);
}

void PaintDebugger::drawSymbol(const PointF& point, char32_t ucs4Code)
{
m_real->drawSymbol(point, ucs4Code);
Expand Down
1 change: 0 additions & 1 deletion src/engraving/infrastructure/paintdebugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ class PaintDebugger : public draw::IPaintProvider

void drawText(const PointF& point, const String& text) override;
void drawText(const RectF& rect, int flags, const String& text) override;
void drawTextWorkaround(const draw::Font& f, const PointF& pos, const String& text) override;

void drawSymbol(const PointF& point, char32_t ucs4Code) override;

Expand Down
4 changes: 0 additions & 4 deletions src/engraving/libmscore/harmony.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1299,12 +1299,8 @@ void Harmony::draw(mu::draw::Painter* painter) const
for (const TextSegment* ts : m_textList) {
mu::draw::Font f(ts->m_font);
f.setPointSizeF(f.pointSizeF() * MScore::pixelRatio);
#ifndef Q_OS_MACOS
TextBase::drawTextWorkaround(painter, f, ts->pos(), ts->text);
#else
painter->setFont(f);
painter->drawText(ts->pos(), ts->text);
#endif
}
}

Expand Down
19 changes: 0 additions & 19 deletions src/engraving/libmscore/textbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -765,27 +765,8 @@ void TextFragment::draw(mu::draw::Painter* p, const TextBase* t) const
{
mu::draw::Font f(font(t));
f.setPointSizeF(f.pointSizeF() * MScore::pixelRatio);
#ifndef Q_OS_MACOS
TextBase::drawTextWorkaround(p, f, pos, text);
#else
p->setFont(f);
p->drawText(pos, text);
#endif
}

//---------------------------------------------------------
// drawTextWorkaround
//---------------------------------------------------------

void TextBase::drawTextWorkaround(mu::draw::Painter* p, mu::draw::Font& f, const mu::PointF& pos, const String& text)
{
double mm = p->worldTransform().m11();
if (!(MScore::pdfPrinting) && (mm < 1.0) && f.bold() && !(f.underline() || f.strike())) {
p->drawTextWorkaround(f, pos, text);
} else {
p->setFont(f);
p->drawText(pos, text);
}
}

//---------------------------------------------------------
Expand Down
1 change: 0 additions & 1 deletion src/engraving/libmscore/textbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,6 @@ class TextBase : public EngravingItem

virtual void draw(mu::draw::Painter*) const override;
virtual void drawEditMode(mu::draw::Painter* p, EditData& ed, double currentViewScaling) override;
static void drawTextWorkaround(mu::draw::Painter* p, mu::draw::Font& f, const mu::PointF& pos, const String& text);

Align align() const { return m_align; }
void setAlign(Align a) { m_align = a; }
Expand Down
6 changes: 0 additions & 6 deletions src/framework/draw/bufferedpaintprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,12 +300,6 @@ void BufferedPaintProvider::drawText(const RectF& rect, int flags, const String&
editableData().texts.push_back(DrawText { DrawText::Rect, rect, flags, text });
}

void BufferedPaintProvider::drawTextWorkaround(const Font& f, const PointF& pos, const String& text)
{
setFont(f);
drawText(pos, text);
}

void BufferedPaintProvider::drawSymbol(const PointF& point, char32_t ucs4Code)
{
drawText(point, String::fromUcs4(&ucs4Code, 1));
Expand Down
1 change: 0 additions & 1 deletion src/framework/draw/bufferedpaintprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ class BufferedPaintProvider : public IPaintProvider

void drawText(const PointF& point, const String& text) override;
void drawText(const RectF& rect, int flags, const String& text) override;
void drawTextWorkaround(const Font& f, const PointF& pos, const String& text) override;

void drawSymbol(const PointF& point, char32_t ucs4Code) override;

Expand Down
61 changes: 0 additions & 61 deletions src/framework/draw/internal/qpainterprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,67 +240,6 @@ void QPainterProvider::drawText(const RectF& rect, int flags, const String& text
m_painter->drawText(rect.toQRectF(), flags, text);
}

void QPainterProvider::drawTextWorkaround(const Font& f, const PointF& pos, const String& text)
{
m_painter->save();
double mm = m_painter->worldTransform().m11();
double dx = m_painter->worldTransform().dx();
double dy = m_painter->worldTransform().dy();
// diagonal elements will now be changed to 1.0
m_painter->setWorldTransform(QTransform(1.0, 0.0, 0.0, 1.0, dx, dy));

// correction factor for bold text drawing, due to the change of the diagonal elements
double factor = 1.0 / mm;
QFont fnew(f.toQFont(), m_painter->device());
fnew.setPointSizeF(f.pointSizeF() / factor);
QRawFont fRaw = QRawFont::fromFont(fnew);
QTextLayout textLayout(text, f.toQFont(), m_painter->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();
double offset = 0;
// glyphrun drawing has an offset equal to the max ascent of the text fragment
for (int i = 0; i < glyphruns.length(); i++) {
double 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);
}
m_painter->drawGlyphRun(QPointF(pos.x() / factor, pos.y() / factor - offset), glyphrun2);
positions2.clear();
}
// Restore the QPainter to its former state
m_painter->setWorldTransform(QTransform(mm, 0.0, 0.0, mm, dx, dy));
m_painter->restore();
}

void QPainterProvider::drawSymbol(const PointF& point, char32_t ucs4Code)
{
static QHash<char32_t, QString> cache;
Expand Down
1 change: 0 additions & 1 deletion src/framework/draw/internal/qpainterprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ class QPainterProvider : public IPaintProvider

void drawText(const PointF& point, const String& text) override;
void drawText(const RectF& rect, int flags, const String& text) override;
void drawTextWorkaround(const Font& f, const PointF& pos, const String& text) override;

void drawSymbol(const PointF& point, char32_t ucs4Code) override;

Expand Down
1 change: 0 additions & 1 deletion src/framework/draw/ipaintprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ class IPaintProvider

virtual void drawText(const PointF& point, const String& text) = 0;
virtual void drawText(const RectF& rect, int flags, const String& text) = 0;
virtual void drawTextWorkaround(const Font& f, const PointF& pos, const String& text) = 0; // see Painter::drawTextWorkaround .h file

virtual void drawSymbol(const PointF& point, char32_t ucs4Code) = 0;

Expand Down
8 changes: 0 additions & 8 deletions src/framework/draw/painter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -436,14 +436,6 @@ void Painter::drawText(const RectF& rect, int flags, const String& text)
}
}

void Painter::drawTextWorkaround(Font& f, const PointF pos, const String& text)
{
m_provider->drawTextWorkaround(f, pos, text);
if (extended) {
extended->drawTextWorkaround(f, pos, text);
}
}

void Painter::drawSymbol(const PointF& point, char32_t ucs4Code)
{
m_provider->drawSymbol(point, ucs4Code);
Expand Down
11 changes: 0 additions & 11 deletions src/framework/draw/painter.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,17 +144,6 @@ class Painter
//! Fractions are also passed to this method, and, accordingly, the fractional part is discarded.
inline void drawText(int x, int y, const String& text);

//! NOTE 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.
//! The workaround works badly if the text is at the same time
//! bold and underlined or struck out.
//! (moved from TextBase::drawTextWorkaround)
void drawTextWorkaround(Font& f, const PointF pos, const String& text);

void drawSymbol(const PointF& point, char32_t ucs4Code);

void fillRect(const RectF& rect, const Brush& brush);
Expand Down

0 comments on commit d1fe90a

Please sign in to comment.