From fe3ec209e739a6d541f5530a85c43391905aa995 Mon Sep 17 00:00:00 2001 From: Casper Jeukendrup <48658420+cbjeukendrup@users.noreply.github.com> Date: Sun, 29 Aug 2021 18:12:36 +0200 Subject: [PATCH] Fixed SMuFL anchors --- src/engraving/engravingmodule.h | 2 +- src/engraving/libmscore/mscoreview.cpp | 2 +- src/engraving/libmscore/scorefont.cpp | 60 ++++++++----------- src/framework/fonts/fonts_Petaluma.qrc | 1 + .../internal/musicxml/importxmlfirstpass.cpp | 2 + 5 files changed, 29 insertions(+), 38 deletions(-) diff --git a/src/engraving/engravingmodule.h b/src/engraving/engravingmodule.h index 94a21b96e9ec6..3a851b07fcc7b 100644 --- a/src/engraving/engravingmodule.h +++ b/src/engraving/engravingmodule.h @@ -35,7 +35,7 @@ class EngravingModule : public modularity::IModuleSetup void registerResources() override; void registerUiTypes() override; void onInit(const framework::IApplication::RunMode& mode) override; - void onDeinit(); + void onDeinit() override; }; } diff --git a/src/engraving/libmscore/mscoreview.cpp b/src/engraving/libmscore/mscoreview.cpp index abc8155fe5da8..df83e04b40cab 100644 --- a/src/engraving/libmscore/mscoreview.cpp +++ b/src/engraving/libmscore/mscoreview.cpp @@ -62,7 +62,7 @@ Element* MuseScoreView::elementAt(const mu::PointF& p) Page* MuseScoreView::point2page(const mu::PointF& p) { - if (score()->layoutMode() == LayoutMode::LINE) { + if (score()->layoutMode() == mu::engraving::LayoutMode::LINE) { return score()->pages().isEmpty() ? 0 : score()->pages().front(); } foreach (Page* page, score()->pages()) { diff --git a/src/engraving/libmscore/scorefont.cpp b/src/engraving/libmscore/scorefont.cpp index 8f4ad612f8a37..55b653f51c67f 100644 --- a/src/engraving/libmscore/scorefont.cpp +++ b/src/engraving/libmscore/scorefont.cpp @@ -274,7 +274,6 @@ void ScoreFont::load() void ScoreFont::loadGlyphsWithAnchors(const QJsonObject& glyphsWithAnchors) { for (const QString& symName : glyphsWithAnchors.keys()) { - constexpr qreal scale = SPATIUM20; QJsonObject anchors = glyphsWithAnchors.value(symName).toObject(); SymId symId = Sym::nameToSymIdHash.value(symName, SymId::noSym); @@ -284,42 +283,31 @@ void ScoreFont::loadGlyphsWithAnchors(const QJsonObject& glyphsWithAnchors) continue; } - Sym* sym = &m_symbols[int(symId)]; - - for (const QString& anchorKey : anchors.keys()) { - if (anchorKey == "stemDownNW") { - qreal x = anchors.value(anchorKey).toArray().at(0).toDouble(); - qreal y = anchors.value(anchorKey).toArray().at(1).toDouble(); - sym->setSmuflAnchor(SmuflAnchorId::stemDownNW, PointF(x, -y) * 4.0 * DPI_F); - } else if (anchorKey == "stemUpSE") { - qreal x = anchors.value(anchorKey).toArray().at(0).toDouble(); - qreal y = anchors.value(anchorKey).toArray().at(1).toDouble(); - sym->setSmuflAnchor(SmuflAnchorId::stemUpSE, PointF(x, -y) * 4.0 * DPI_F); - } else if (anchorKey == "stemDownSW") { - qreal x = anchors.value(anchorKey).toArray().at(0).toDouble(); - qreal y = anchors.value(anchorKey).toArray().at(1).toDouble(); - sym->setSmuflAnchor(SmuflAnchorId::stemDownSW, PointF(x, -y) * 4.0 * DPI_F); - } else if (anchorKey == "stemUpNW") { - qreal x = anchors.value(anchorKey).toArray().at(0).toDouble(); - qreal y = anchors.value(anchorKey).toArray().at(1).toDouble(); - sym->setSmuflAnchor(SmuflAnchorId::stemUpNW, PointF(x, -y) * 4.0 * DPI_F); - } else if (anchorKey == "cutOutNE") { - qreal x = anchors.value(anchorKey).toArray().at(0).toDouble(); - qreal y = anchors.value(anchorKey).toArray().at(1).toDouble(); - sym->setSmuflAnchor(SmuflAnchorId::cutOutNE, PointF(x, -y) * scale); - } else if (anchorKey == "cutOutNW") { - qreal x = anchors.value(anchorKey).toArray().at(0).toDouble(); - qreal y = anchors.value(anchorKey).toArray().at(1).toDouble(); - sym->setSmuflAnchor(SmuflAnchorId::cutOutNW, PointF(x, -y) * scale); - } else if (anchorKey == "cutOutSE") { - qreal x = anchors.value(anchorKey).toArray().at(0).toDouble(); - qreal y = anchors.value(anchorKey).toArray().at(1).toDouble(); - sym->setSmuflAnchor(SmuflAnchorId::cutOutSE, PointF(x, -y) * scale); - } else if (anchorKey == "cutOutSW") { - qreal x = anchors.value(anchorKey).toArray().at(0).toDouble(); - qreal y = anchors.value(anchorKey).toArray().at(1).toDouble(); - sym->setSmuflAnchor(SmuflAnchorId::cutOutSW, PointF(x, -y) * scale); + Sym& sym = m_symbols[size_t(symId)]; + + static const std::unordered_map smuflAnchorIdNames { + { "stemDownNW", SmuflAnchorId::stemDownNW }, + { "stemUpSE", SmuflAnchorId::stemUpSE }, + { "stemDownSW", SmuflAnchorId::stemDownSW }, + { "stemUpNW", SmuflAnchorId::stemUpNW }, + { "cutOutNE", SmuflAnchorId::cutOutNE }, + { "cutOutNW", SmuflAnchorId::cutOutNW }, + { "cutOutSE", SmuflAnchorId::cutOutSE }, + { "cutOutSW", SmuflAnchorId::cutOutSW } + }; + + for (const QString& anchorId : anchors.keys()) { + auto search = smuflAnchorIdNames.find(anchorId); + if (search == smuflAnchorIdNames.cend()) { + //LOGD() << "Unhandled SMuFL anchorId: " << anchorId; + continue; } + + QJsonArray arr = anchors.value(anchorId).toArray(); + double x = arr.at(0).toDouble(); + double y = arr.at(1).toDouble(); + + sym.setSmuflAnchor(search->second, PointF(x, -y) * SPATIUM20); } } } diff --git a/src/framework/fonts/fonts_Petaluma.qrc b/src/framework/fonts/fonts_Petaluma.qrc index 023dfdbf689b3..14001877ec4da 100644 --- a/src/framework/fonts/fonts_Petaluma.qrc +++ b/src/framework/fonts/fonts_Petaluma.qrc @@ -1,5 +1,6 @@ + ../../../fonts/petaluma/petaluma_metadata.json ../../../fonts/petaluma/Petaluma.otf ../../../fonts/petaluma/PetalumaText.otf ../../../fonts/petaluma/PetalumaScript.otf diff --git a/src/importexport/musicxml/internal/musicxml/importxmlfirstpass.cpp b/src/importexport/musicxml/internal/musicxml/importxmlfirstpass.cpp index 33079005fff45..e489097fc1c75 100644 --- a/src/importexport/musicxml/internal/musicxml/importxmlfirstpass.cpp +++ b/src/importexport/musicxml/internal/musicxml/importxmlfirstpass.cpp @@ -22,6 +22,8 @@ #include "importxmlfirstpass.h" +#include "log.h" + namespace Ms { // TODO: move somewhere else