Skip to content

Commit

Permalink
Fixed SMuFL anchors
Browse files Browse the repository at this point in the history
  • Loading branch information
cbjeukendrup committed Aug 29, 2021
1 parent 56c8b43 commit fe3ec20
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 38 deletions.
2 changes: 1 addition & 1 deletion src/engraving/engravingmodule.h
Expand Up @@ -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;
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/engraving/libmscore/mscoreview.cpp
Expand Up @@ -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()) {
Expand Down
60 changes: 24 additions & 36 deletions src/engraving/libmscore/scorefont.cpp
Expand Up @@ -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);
Expand All @@ -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<QString, SmuflAnchorId> 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);
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/framework/fonts/fonts_Petaluma.qrc
@@ -1,5 +1,6 @@
<RCC>
<qresource prefix="/">
<file alias="fonts/petaluma/metadata.json">../../../fonts/petaluma/petaluma_metadata.json</file>
<file alias="fonts/petaluma/Petaluma.otf">../../../fonts/petaluma/Petaluma.otf</file>
<file alias="fonts/petaluma/PetalumaText.otf">../../../fonts/petaluma/PetalumaText.otf</file>
<file alias="fonts/petaluma/PetalumaScript.otf">../../../fonts/petaluma/PetalumaScript.otf</file>
Expand Down
Expand Up @@ -22,6 +22,8 @@

#include "importxmlfirstpass.h"

#include "log.h"

namespace Ms {
// TODO: move somewhere else

Expand Down

0 comments on commit fe3ec20

Please sign in to comment.