Skip to content

Commit

Permalink
Fix path on Windows and Linux where SMuFL expects system fonts to be
Browse files Browse the repository at this point in the history
  • Loading branch information
Jojo-Schmitz committed Dec 9, 2024
1 parent de7bb02 commit edc70e5
Showing 1 changed file with 32 additions and 9 deletions.
41 changes: 32 additions & 9 deletions libmscore/sym.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6601,15 +6601,20 @@ void Ms::ScoreFont::initScoreFonts()
// Linux: "$XDG_DATA_HOME/SMuFL/Fonts", "$XDG_DATA_DIRS/SMuFL/Fonts"
// as per https://doc.qt.io/qt-5/qstandardpaths.html#standardLocations that is the (start of the) list
// which `GenericDataLocation` gives (without the "/SMuFL/Fonts")
#ifdef Q_OS_WIN
// take only the first two entries of that list on Windows (on Mac it is 2 elements only anyway)
QStringList systemFontsPaths = QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation).mid(0, 2);
#else
QStringList systemFontsPaths = QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation);
// take only the first two entries of that list (on Windows, on Mac it is 2 elements only anyway).
// These standard location roughly match up with what the following returns, but some adjustments are needed.
QStringList standardFontsPaths = QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation).mid(0, 2);
#if defined(Q_OS_WIN)
// On Windows, the second standard location returned by Qt is %ProgramData%, but we want %CommonProgramFiles%
standardFontsPaths[1] = qgetenv("CommonProgramFiles").replace("\\", "/"); // "C:\\Program Files\\Common Files"
#elif defined(Q_OS_LINUX)
// On Unix systems, we want $XDG_DATA_DIRS and $XDG_DATA_HOME
QStringList xdgDataDirs = QString::fromLocal8Bit(qgetenv("XDG_DATA_DIRS")).split(':');
standardFontsPaths = xdgDataDirs << qgetenv("XDG_DATA_HOME");
#endif
for (QString& systemFontsPath : systemFontsPaths) {
systemFontsPath += "/SMuFL/Fonts";
scanUserFonts(systemFontsPath, true);
for (QString& standardFontsPath : standardFontsPaths) {
standardFontsPath += "/SMuFL/Fonts";
scanUserFonts(standardFontsPath, true);
}
}

Expand Down Expand Up @@ -6639,6 +6644,24 @@ void ScoreFont::scanUserFonts(const QString& path, bool system)
}
}

#if 0
QString metadataPath;
QStringList metadataFilenameOptions = {
"/metadata.json",
QString("/%1.json").arg(fontName),
QString("/%1_metadata.json").arg(fontName).toLower().remove(' ')
};
for (const auto& option : metadataFilenameOptions) {
if (QFile::exists(iterator.filePath() + option)) {
metadataPath = iterator.filePath() + option;
break;
}
}
if (metadataPath.isEmpty()) {
qDebug() << "No metadata file found for font" << fontName;
continue;
}
#endif
bool hasMetadataFile = QFileInfo::exists(fontDirPath + (system ? fontName : "metadata") + ".json");

if (hasMetadataFile && !fontFilename.isEmpty()) {
Expand All @@ -6650,7 +6673,7 @@ void ScoreFont::scanUserFonts(const QString& path, bool system)
}


qDebug() << "Found" << userfonts.count() << (system ? "system" : "user") << "score font" << (userfonts.count() > 1? "s" : "") << " in" << path <<".";
qDebug() << "Found" << userfonts.count() << (system ? "system" : "user") << "score" << (userfonts.count() > 1? "fonts" : "font") << "in" << path << ".";

// TODO: Check for fonts that duplicate built-in fonts
if (!system) // reset list when re-reading due to changed Preferences
Expand Down

0 comments on commit edc70e5

Please sign in to comment.