Skip to content

Commit

Permalink
Adjust font loading from the command line
Browse files Browse the repository at this point in the history
  • Loading branch information
lpugin committed Feb 7, 2024
1 parent bf078a8 commit 78046a7
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
1 change: 1 addition & 0 deletions src/filereader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ bool ZipFileReader::Load(const std::string &filename)
#else
std::ifstream fin(filename.c_str(), std::ios::in | std::ios::binary);
if (!fin.is_open()) {
LogError("File archive '%s' could not be open.", filename.c_str());
return false;
}

Expand Down
6 changes: 4 additions & 2 deletions src/resources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,10 @@ bool Resources::AddCustom(const std::vector<std::string> &extraFonts)
// options supplied fonts
for (const std::string &fontFile : extraFonts) {
ZipFileReader zipFile;
zipFile.Load(fontFile);
std::string fontName = GetCustomFontname("", zipFile);
if (!zipFile.Load(fontFile)) {
continue;
}
std::string fontName = GetCustomFontname(fontFile, zipFile);
if (fontName.empty() || IsFontLoaded(fontName)) {
continue;
}
Expand Down
15 changes: 10 additions & 5 deletions src/toolkit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,18 @@ bool Toolkit::SetResourcePath(const std::string &path)
Resources &resources = m_doc.GetResourcesForModification();
resources.SetPath(path);
bool success = resources.InitFonts();
success = success && resources.SetFallback(m_options->m_fontFallback.GetStrValue());
if (m_options->m_fontLoadAll.GetValue()) {
success = success && resources.LoadAll();
}
if (!m_options->m_fontAddCustom.GetValue().empty()) {
if (m_options->m_fontAddCustom.IsSet()) {
success = success && resources.AddCustom(m_options->m_fontAddCustom.GetValue());
}
if (m_options->m_font.IsSet()) {
success = success && this->SetFont(m_options->m_font.GetValue());
}
if (m_options->m_fontFallback.IsSet()) {
success = success && resources.SetFallback(m_options->m_fontFallback.GetStrValue());
}
if (m_options->m_fontLoadAll.IsSet()) {
success = success && resources.LoadAll();
}
return success;
}

Expand Down
6 changes: 0 additions & 6 deletions tools/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,12 +293,6 @@ int main(int argc, char **argv)
exit(1);
}

// Load a specified font
if (!toolkit.SetOptions(vrv::StringFormat("{\"font\": \"%s\" }", options->m_font.GetValue().c_str()))) {
std::cerr << "Font '" << options->m_font.GetValue() << "' could not be loaded." << std::endl;
exit(1);
}

const std::vector<std::string> outformats = { "mei", "mei-basic", "mei-pb", "mei-facs", "svg", "midi", "timemap",
"expansionmap", "humdrum", "hum", "pae" };
if (std::find(outformats.begin(), outformats.end(), outformat) == outformats.end()) {
Expand Down

0 comments on commit 78046a7

Please sign in to comment.