Skip to content

Commit

Permalink
[engraving] restructured engraving fonts
Browse files Browse the repository at this point in the history
  • Loading branch information
igorkorsukov committed Jul 26, 2022
1 parent 9cc3854 commit 9bcd966
Show file tree
Hide file tree
Showing 59 changed files with 568 additions and 480 deletions.
7 changes: 6 additions & 1 deletion sandbox/engraving/fontproviderstub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
using namespace mu;
using namespace mu::draw;

int FontProviderStub::addApplicationFont(const QString&, const QString&)
int FontProviderStub::addSymbolFont(const QString&, const io::path_t &)
{
return -1;
}

int FontProviderStub::addTextFont(const io::path_t& path)
{
return -1;
}
Expand Down
3 changes: 2 additions & 1 deletion sandbox/engraving/fontproviderstub.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ class FontProviderStub : public IFontProvider
{
public:

int addApplicationFont(const QString& family, const QString& path) override;
int addSymbolFont(const QString& family, const io::path_t& path) override;
int addTextFont(const io::path_t& path) override;
void insertSubstitution(const QString& familyName, const QString& substituteName) override;

qreal lineSpacing(const Font& f) const override;
Expand Down
6 changes: 6 additions & 0 deletions src/engraving/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ set(MODULE_SRC
${CMAKE_CURRENT_LIST_DIR}/infrastructure/debugpaint.h
${CMAKE_CURRENT_LIST_DIR}/infrastructure/paintdebugger.cpp
${CMAKE_CURRENT_LIST_DIR}/infrastructure/paintdebugger.h
${CMAKE_CURRENT_LIST_DIR}/infrastructure/symbolfonts.cpp
${CMAKE_CURRENT_LIST_DIR}/infrastructure/symbolfonts.h
${CMAKE_CURRENT_LIST_DIR}/infrastructure/symbolfont.cpp
${CMAKE_CURRENT_LIST_DIR}/infrastructure/symbolfont.h
${CMAKE_CURRENT_LIST_DIR}/infrastructure/smufl.cpp
${CMAKE_CURRENT_LIST_DIR}/infrastructure/smufl.h

${LIBMSCORE_SRC}

Expand Down
94 changes: 82 additions & 12 deletions src/engraving/engravingmodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
#include "modularity/ioc.h"
#include "global/allocator.h"

#include "draw/ifontprovider.h"
#include "infrastructure/smufl.h"
#include "infrastructure/symbolfonts.h"

#ifndef ENGRAVING_NO_INTERNAL
#include "internal/engravingconfiguration.h"
#endif
Expand All @@ -36,12 +40,14 @@

#include "engraving/libmscore/mscore.h"
#include "engraving/libmscore/masterscore.h"
#include "engraving/libmscore/scorefont.h"

#include "compat/scoreaccess.h"

#include "log.h"

using namespace mu::engraving;
using namespace mu::modularity;
using namespace mu::draw;

#ifndef ENGRAVING_NO_INTERNAL
static std::shared_ptr<EngravingConfiguration> s_configuration = std::make_shared<EngravingConfiguration>();
Expand Down Expand Up @@ -82,6 +88,67 @@ void EngravingModule::registerUiTypes()

void EngravingModule::onInit(const framework::IApplication::RunMode&)
{
// Init fonts
{
// Symbols
Smufl::init();

SymbolFonts::addFont(u"Leland", u"Leland", ":/fonts/leland/Leland.otf");
SymbolFonts::addFont(u"Bravura", u"Bravura", ":/fonts/bravura/Bravura.otf");
SymbolFonts::addFont(u"Emmentaler", u"MScore", ":/fonts/mscore/mscore.ttf");
SymbolFonts::addFont(u"Gonville", u"Gootville", ":/fonts/gootville/Gootville.otf");
SymbolFonts::addFont(u"MuseJazz", u"MuseJazz", ":/fonts/musejazz/MuseJazz.otf");
SymbolFonts::addFont(u"Petaluma", u"Petaluma", ":/fonts/petaluma/Petaluma.otf");
SymbolFonts::addFont(u"Finale Maestro", u"Finale Maestro", ":/fonts/finalemaestro/FinaleMaestro.otf");
SymbolFonts::addFont(u"Finale Broadway", u"Finale Broadway", ":/fonts/finalebroadway/FinaleBroadway.otf");

SymbolFonts::setFallbackFont(u"Bravura");

// Text
const std::vector<io::path_t> textFonts = {
":/fonts/musejazz/MuseJazzText.otf",
":/fonts/campania/Campania.otf",
":/fonts/edwin/Edwin-Roman.otf",
":/fonts/edwin/Edwin-Bold.otf",
":/fonts/edwin/Edwin-Italic.otf",
":/fonts/edwin/Edwin-BdIta.otf",
":/fonts/FreeSans.ttf",
":/fonts/FreeSerif.ttf",
":/fonts/FreeSerifBold.ttf",
":/fonts/FreeSerifItalic.ttf",
":/fonts/FreeSerifBoldItalic.ttf",
":/fonts/mscoreTab.ttf",
":/fonts/mscore-BC.ttf",
":/fonts/leland/LelandText.otf",
":/fonts/leland/Leland.otf",
":/fonts/bravura/BravuraText.otf",
":/fonts/gootville/GootvilleText.otf",
":/fonts/mscore/MScoreText.ttf",
":/fonts/petaluma/PetalumaText.otf",
":/fonts/petaluma/PetalumaScript.otf",
":/fonts/finalemaestro/FinaleMaestroText.otf",
":/fonts/finalebroadway/FinaleBroadwayText.otf",
};

std::shared_ptr<IFontProvider> fontProvider = ioc()->resolve<IFontProvider>("fonts");
for (const io::path_t& font : textFonts) {
int loadStatusCode = fontProvider->addTextFont(font);
if (loadStatusCode == -1) {
LOGE() << "Fatal error: cannot load internal font " << font;
}
}

fontProvider->insertSubstitution(u"Leland Text", u"Bravura Text");
fontProvider->insertSubstitution(u"Bravura Text", u"Leland Text");
fontProvider->insertSubstitution(u"MScore Text", u"Leland Text");
fontProvider->insertSubstitution(u"Gootville Text", u"Leland Text");
fontProvider->insertSubstitution(u"MuseJazz Text", u"Leland Text");
fontProvider->insertSubstitution(u"Petaluma Text", u"MuseJazz Text");
fontProvider->insertSubstitution(u"Finale Maestro Text", u"Leland Text");
fontProvider->insertSubstitution(u"Finale Broadway Text", u"MuseJazz Text");
fontProvider->insertSubstitution(u"ScoreFont", u"Leland Text");// alias for current Musical Text Font
}

#ifndef ENGRAVING_NO_INTERNAL
s_configuration->init();

Expand All @@ -95,24 +162,27 @@ void EngravingModule::onInit(const framework::IApplication::RunMode&)
MScore::setNudgeStep10(1.0); // Ctrl + cursor key (default 1.0)
MScore::setNudgeStep50(0.01); // Alt + cursor key (default 0.01)

// Palette
{
#ifndef ENGRAVING_NO_ACCESSIBILITY
AccessibleItem::enabled = false;
AccessibleItem::enabled = false;
#endif
gpaletteScore = compat::ScoreAccess::createMasterScore();
gpaletteScore = compat::ScoreAccess::createMasterScore();
#ifndef ENGRAVING_NO_ACCESSIBILITY
AccessibleItem::enabled = true;
AccessibleItem::enabled = true;
#endif

if (EngravingObject::elementsProvider()) {
EngravingObject::elementsProvider()->unreg(gpaletteScore);
}
if (EngravingObject::elementsProvider()) {
EngravingObject::elementsProvider()->unreg(gpaletteScore);
}

gpaletteScore->setStyle(DefaultStyle::baseStyle());
gpaletteScore->setStyle(DefaultStyle::baseStyle());

gpaletteScore->style().set(Sid::MusicalTextFont, String(u"Leland Text"));
ScoreFont* scoreFont = ScoreFont::fontByName(u"Leland");
gpaletteScore->setScoreFont(scoreFont);
gpaletteScore->setNoteHeadWidth(scoreFont->width(SymId::noteheadBlack, gpaletteScore->spatium()) / SPATIUM20);
gpaletteScore->style().set(Sid::MusicalTextFont, String(u"Leland Text"));
SymbolFont* scoreFont = SymbolFonts::fontByName(u"Leland");
gpaletteScore->setSymbolFont(scoreFont);
gpaletteScore->setNoteHeadWidth(scoreFont->width(SymId::noteheadBlack, gpaletteScore->spatium()) / SPATIUM20);
}

//! NOTE And some initialization in the `Notation::init()`
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,98 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "smuflranges.h"
#include "smufl.h"

#include "io/file.h"
#include "serialization/json.h"

#include "types/symnames.h"

#include "libmscore/mscore.h"

#include "log.h"

using namespace mu;
using namespace mu::io;
using namespace mu::engraving;

std::array<Smufl::Code, size_t(SymId::lastSym) + 1> Smufl::s_symIdCodes { { } };

const Smufl::Code Smufl::code(SymId id)
{
return s_symIdCodes.at(static_cast<size_t>(id));
}

char32_t Smufl::smuflCode(SymId id)
{
return s_symIdCodes.at(static_cast<size_t>(id)).smuflCode;
}

bool Smufl::init()
{
bool ok = initGlyphNamesJson();

return ok;
}

bool Smufl::initGlyphNamesJson()
{
File file(":fonts/smufl/glyphnames.json");
if (!file.open(IODevice::ReadOnly)) {
LOGE() << "could not open glyph names JSON file.";
return false;
}

std::string error;
JsonObject glyphNamesJson = JsonDocument::fromJson(file.readAll(), &error).rootObject();
file.close();

if (!error.empty()) {
LOGE() << "JSON parse error in glyph names file: " << error;
return false;
}

IF_ASSERT_FAILED(!glyphNamesJson.empty()) {
LOGE() << "Could not read glyph names JSON";
return false;
}

for (size_t i = 0; i < s_symIdCodes.size(); ++i) {
SymId sym = static_cast<SymId>(i);
if (sym == SymId::noSym || sym == SymId::lastSym) {
continue;
}

std::string name(SymNames::nameForSymId(sym).ascii());
JsonObject symObj = glyphNamesJson.value(name).toObject();
if (!symObj.isValid()) {
continue;
}

bool ok;
uint code = symObj.value("codepoint").toString().mid(2).toUInt(&ok, 16);
if (ok) {
s_symIdCodes[i].smuflCode = code;
} else if (MScore::debugMode) {
LOGD() << "could not read codepoint for glyph " << name;
}

uint alernativeCode = symObj.value("alternateCodepoint").toString().mid(2).toUInt(&ok, 16);
if (ok) {
s_symIdCodes[i].musicSymBlockCode = alernativeCode;
} else if (MScore::debugMode) {
LOGD() << "could not read alternate codepoint for glyph " << name;
}
}
return true;
}

//---------------------------------------------------------
// smuflRanges
// read smufl ranges.json file
//---------------------------------------------------------

const std::map<String, StringList>& mu::smuflRanges()
const std::map<String, StringList>& Smufl::smuflRanges()
{
static std::map<String, StringList> ranges;
StringList allSymbols;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,41 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef SMUFLRANGES_H
#define SMUFLRANGES_H
#ifndef MU_ENGRAVING_SMUFL_H
#define MU_ENGRAVING_SMUFL_H

#include <array>
#include <map>

#include "types/string.h"
#include "types/symid.h"

namespace mu::engraving {
class Smufl
{
public:

static bool init();

struct Code {
char32_t smuflCode = 0;
char32_t musicSymBlockCode = 0;

bool isValid() const { return smuflCode != 0 || musicSymBlockCode != 0; }
};

static const Code code(SymId id);
static char32_t smuflCode(SymId id);

static const std::map<String, StringList>& smuflRanges();
static constexpr const char* SMUFL_ALL_SYMBOLS = "All symbols";

private:

static bool initGlyphNamesJson();

//! NOTE temporary place for this method
namespace mu {
const std::map<String, StringList>& smuflRanges();
constexpr const char* SMUFL_ALL_SYMBOLS = "All symbols";
static std::array<Code, size_t(SymId::lastSym) + 1> s_symIdCodes;
};
}

#endif // SMUFLRANGES_H
#endif // MU_ENGRAVING_SMUFL_H
Loading

0 comments on commit 9bcd966

Please sign in to comment.