Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
# Conflicts:
#	CHANGELOG.md
#	Verovio.podspec
#	bindings/java/pom.xml
#	codemeta.json
  • Loading branch information
lpugin committed Nov 28, 2022
2 parents 1f0a0a9 + 1db2b94 commit 4728805
Show file tree
Hide file tree
Showing 13 changed files with 39 additions and 59 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Changelog

## [unreleased]

## [3.13.0] - 2022-11-23
* Refactoring of the JSON parameters and returned values as dictionaries for the Python binding
* Support for text font fallback when a glyph is missing in the selected font
Expand Down
4 changes: 2 additions & 2 deletions Verovio.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1336,8 +1336,8 @@
2D2A799B1A698137000A441B /* chord.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = chord.h; path = include/vrv/chord.h; sourceTree = "<group>"; };
35FDEBCD24B6DBC100AC1696 /* fing.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = fing.h; path = include/vrv/fing.h; sourceTree = "<group>"; };
35FDEBD024B6DC5B00AC1696 /* fing.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = fing.cpp; path = src/fing.cpp; sourceTree = "<group>"; };
3673E5E428E1DF0C0048BAFA /* graphic.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = graphic.cpp; path = src/graphic.cpp; sourceTree = "<group>"; };
3673E5E528E1DF0C0048BAFA /* graphic.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = graphic.h; path = include/vrv/graphic.h; sourceTree = "<group>"; };
3673E5E428E1DF0C0048BAFA /* graphic.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = graphic.cpp; path = src/graphic.cpp; sourceTree = "<group>"; };
3673E5E528E1DF0C0048BAFA /* graphic.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = graphic.h; path = include/vrv/graphic.h; sourceTree = "<group>"; };
36E0442B2347A9150054F141 /* expansionmap.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = expansionmap.cpp; path = src/expansionmap.cpp; sourceTree = "<group>"; };
36E0442D2347A9290054F141 /* expansionmap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = expansionmap.h; path = include/vrv/expansionmap.h; sourceTree = "<group>"; };
400FEDD1206FA742000D3233 /* gracegrp.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = gracegrp.h; path = include/vrv/gracegrp.h; sourceTree = "<group>"; };
Expand Down
2 changes: 1 addition & 1 deletion bindings/python/.pypi-version
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# dummy file used by setup.py for counting revisions when publishing to test.pypi
# counting can be reset by making a change to this file
3.13.0
3.14.0
12 changes: 12 additions & 0 deletions bindings/python/verovio.i
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,18 @@ def renderToTimemap(toolkit, options = {}):
return json.loads($action(toolkit, json.dumps(options)))
%}

// Toolkit::RenderToTimemapFile
%feature("shadow") vrv::Toolkit::RenderToTimemapFile(const std::string &, const std::string &) %{
def renderToTimemapFile(toolkit, filename, options = {}):
return json.loads($action(toolkit, filename, json.dumps(options)))
%}

// Toolkit::SaveFile
%feature("shadow") vrv::Toolkit::SaveFile(const std::string &, const std::string &) %{
def saveFile(toolkit, filename, options = {}):
return json.loads($action(toolkit, filename, json.dumps(options)))
%}

// Toolkit::Select
%feature("shadow") vrv::Toolkit::Select(const std::string &) %{
def select(toolkit, selection):
Expand Down
1 change: 1 addition & 0 deletions include/vrv/devicecontext.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ class DeviceContext {
*/
///@{
FontInfo *GetFont();
bool HasFont() const { return !m_fontStack.empty(); }
///@}

/**
Expand Down
22 changes: 0 additions & 22 deletions include/vrv/toolkit.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,28 +237,6 @@ class Toolkit {
*/
bool SetOptions(const std::string &jsonOptions);

/**
* Get the value for an option
*
* @remark nojs
*
* @param option The name of the option
* @param defaultValue True to get the default value of the option
* @return The option value as a string
*/
std::string GetOption(const std::string &option, bool defaultValue = false) const;

/**
* Set the value for an option
*
* @remark nojs
*
* @param option The name of the option
* @param value The option value as string
* @return True if the option was successfully set
*/
bool SetOption(const std::string &option, const std::string &value);

/**
* Reset all options to default values
*/
Expand Down
2 changes: 1 addition & 1 deletion include/vrv/vrvdef.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace vrv {
//----------------------------------------------------------------------------

#define VERSION_MAJOR 3
#define VERSION_MINOR 13
#define VERSION_MINOR 14
#define VERSION_REVISION 0
// Adds "-dev" in the version number - should be set to false for releases
#define VERSION_DEV false
Expand Down
2 changes: 1 addition & 1 deletion src/devicecontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ void DeviceContext::SetFont(FontInfo *font)

FontInfo *DeviceContext::GetFont()
{
assert(m_fontStack.top());
assert(!m_fontStack.empty());
return m_fontStack.top();
}

Expand Down
25 changes: 0 additions & 25 deletions src/toolkit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1109,31 +1109,6 @@ bool Toolkit::SetOptions(const std::string &jsonOptions)
return true;
}

std::string Toolkit::GetOption(const std::string &option, bool defaultValue) const
{
if (m_options->GetItems()->count(option) == 0) {
LogError("Unsupported option '%s'", option.c_str());
return "[unspecified]";
}
Option *opt = m_options->GetItems()->at(option);
assert(opt);
return (defaultValue) ? opt->GetDefaultStrValue() : opt->GetStrValue();
}

bool Toolkit::SetOption(const std::string &option, const std::string &value)
{
if (m_options->GetItems()->count(option) == 0) {
LogError("Unsupported option '%s'", option.c_str());
return false;
}
Option *opt = m_options->GetItems()->at(option);
assert(opt);
const bool result = opt->SetValue(value);
// If the option is 'font' we need to reset the font resource explicitly
if (result && option == "font") this->SetFont(m_options->m_font.GetValue());
return result;
}

void Toolkit::ResetOptions()
{
std::for_each(m_options->GetItems()->begin(), m_options->GetItems()->end(),
Expand Down
4 changes: 3 additions & 1 deletion src/view_element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1657,7 +1657,7 @@ void View::DrawSyl(DeviceContext *dc, LayerElement *element, Layer *layer, Staff
params.m_width = syl->GetDrawingWidth();
params.m_height = syl->GetDrawingHeight();
}
assert(dc->GetFont());
assert(dc->HasFont());
params.m_pointSize = dc->GetFont()->GetPointSize();

dc->StartText(ToDeviceContextX(params.m_x), ToDeviceContextY(params.m_y));
Expand All @@ -1673,6 +1673,7 @@ void View::DrawSyl(DeviceContext *dc, LayerElement *element, Layer *layer, Staff
}
else {
FontInfo vrvTxt;
assert(dc->HasFont());
vrvTxt.SetPointSize(dc->GetFont()->GetPointSize() * m_doc->GetMusicToLyricFontSizeRatio());
vrvTxt.SetFaceName(m_doc->GetOptions()->m_font.GetValue());
std::u32string str;
Expand Down Expand Up @@ -1879,6 +1880,7 @@ int View::DrawMeterSigFigures(DeviceContext *dc, int x, int y, MeterSig *meterSi
int yDen = y - m_doc->GetDrawingDoubleUnit(glyphSize);
// In case when one of the handwritten fonts is used, we need to make sure that meterSig is displayed properly
// for it, based on the height of corresponding glyphs
assert(dc->HasFont());
FontInfo *fontInfo = dc->GetFont();
std::vector<std::string> handwrittenFonts = m_doc->GetOptions()->m_handwrittenFont.GetValue();
if (const auto it = std::find(handwrittenFonts.begin(), handwrittenFonts.end(), fontInfo->GetFaceName());
Expand Down
18 changes: 14 additions & 4 deletions src/view_text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void View::DrawTextString(DeviceContext *dc, const std::u32string &str, TextDraw
void View::DrawDirString(DeviceContext *dc, const std::u32string &str, TextDrawingParams &params)
{
assert(dc);
assert(dc->GetFont());
assert(dc->HasFont());

std::u32string convertedStr = str;
// If the current font is a music font, we want to convert Music Unicode glyph to SMuFL
Expand All @@ -85,6 +85,7 @@ void View::DrawDirString(DeviceContext *dc, const std::u32string &str, TextDrawi
void View::DrawDynamString(DeviceContext *dc, const std::u32string &str, TextDrawingParams &params, Rend *rend)
{
assert(dc);
assert(dc->HasFont());

const bool singleGlyphs = m_doc->GetOptions()->m_dynamSingleGlyphs.GetValue();

Expand Down Expand Up @@ -147,6 +148,7 @@ void View::DrawDynamString(DeviceContext *dc, const std::u32string &str, TextDra
void View::DrawHarmString(DeviceContext *dc, const std::u32string &str, TextDrawingParams &params)
{
assert(dc);
assert(dc->HasFont());

int toDcX = ToDeviceContextX(params.m_x);
int toDcY = ToDeviceContextY(params.m_y);
Expand Down Expand Up @@ -256,6 +258,7 @@ void View::DrawLyricString(
DeviceContext *dc, const std::u32string &str, int staffSize, std::optional<TextDrawingParams> params)
{
assert(dc);
assert(dc->HasFont());

bool wroteText = false;
std::u32string syl = U"";
Expand Down Expand Up @@ -307,6 +310,7 @@ void View::DrawLyricString(
void View::DrawLb(DeviceContext *dc, Lb *lb, TextDrawingParams &params)
{
assert(dc);
assert(dc->HasFont());
assert(lb);

dc->StartTextGraphic(lb, "", lb->GetID());
Expand Down Expand Up @@ -395,7 +399,7 @@ void View::DrawRend(DeviceContext *dc, Rend *rend, TextDrawingParams &params)
if (rend->HasFontfam() && rend->GetFontfam() == "smufl") {
// Because we do not have the string at this stage we rely only on the selected font
// This means fallback will not work for missing glyphs within <rend>
rendFont.SetSmuflWithFallback(SMUFL_FONT_SELECTED);
rendFont.SetSmuflWithFallback(false);
rendFont.SetFaceName(m_doc->GetOptions()->m_font.GetValue());
int pointSize = (rendFont.GetPointSize() != 0) ? rendFont.GetPointSize() : params.m_pointSize;
rendFont.SetPointSize(pointSize * m_doc->GetMusicToLyricFontSizeRatio());
Expand All @@ -414,7 +418,6 @@ void View::DrawRend(DeviceContext *dc, Rend *rend, TextDrawingParams &params)

int yShift = 0;
if ((rend->GetRend() == TEXTRENDITION_sup) || (rend->GetRend() == TEXTRENDITION_sub)) {
assert(dc->GetFont());
int MHeight = m_doc->GetTextGlyphHeight('M', dc->GetFont(), false);
if (rend->GetRend() == TEXTRENDITION_sup) {
yShift += m_doc->GetTextGlyphHeight('o', dc->GetFont(), false);
Expand Down Expand Up @@ -450,14 +453,21 @@ void View::DrawRend(DeviceContext *dc, Rend *rend, TextDrawingParams &params)
params.m_enclose = rend->GetRend();
}

if (customFont) dc->ResetFont();
if (customFont) {
dc->ResetFont();
// Reset the point size not to have it cummulated
assert(dc->HasFont());
params.m_pointSize = dc->GetFont()->GetPointSize();
// Possilbe corner case: maybe we also need to reset text enclosure here?
}

dc->EndTextGraphic(rend, this);
}

void View::DrawText(DeviceContext *dc, Text *text, TextDrawingParams &params)
{
assert(dc);
assert(dc->HasFont());
assert(text);

const Resources *resources = dc->GetResources();
Expand Down
2 changes: 1 addition & 1 deletion src/vrv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ void LogInfo(const char *fmt, ...)
std::string s;
va_list args;
va_start(args, fmt);
s = "[Message] " + StringFormatVariable(fmt, args) + "\n";
s = "[Info] " + StringFormatVariable(fmt, args) + "\n";
LogString(s, LOG_INFO);
va_end(args);
}
Expand Down
2 changes: 1 addition & 1 deletion tools/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ int main(int argc, char **argv)
}

// Load a specified font
if (!toolkit.SetOption("font", options->m_font.GetValue())) {
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);
}
Expand Down

0 comments on commit 4728805

Please sign in to comment.