Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions src/engraving/rendering/score/harmonylayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ void HarmonyLayout::renderAction(Harmony* item, Harmony::LayoutData* ldata, cons
{
switch (a->actionType()) {
case RenderAction::RenderActionType::SET:
renderActionSet(item, ldata, std::static_pointer_cast<RenderActionSet>(a), harmonyCtx);
renderActionSet(item, ldata, std::static_pointer_cast<RenderActionSet>(a), harmonyCtx, ctx);
break;
case RenderAction::RenderActionType::MOVE:
renderActionMove(item, std::static_pointer_cast<RenderActionMove>(a), harmonyCtx);
Expand Down Expand Up @@ -781,12 +781,14 @@ void HarmonyLayout::renderActionParen(Harmony* item, const RenderActionParenPtr&
harmonyCtx.renderItemList.push_back(parenItem);
}

void HarmonyLayout::kernCharacters(const Harmony* item, const String& text, HarmonyRenderCtx& harmonyCtx)
void HarmonyLayout::kernCharacters(const Harmony* item, const String& text, HarmonyRenderCtx& harmonyCtx, const LayoutContext& ctx)
{
if (harmonyCtx.renderItemList.empty()) {
return;
}
// Character pair and distance to move the second
// Blank strings will apply the kerning no matter the following character
// TODO - move this information to the XML file
static const std::map<std::pair<String, String>, double> KERNED_CHARACTERS {
{ { u"A", u"\uE870" }, -0.4 }, // dim
{ { u"A", u"\uE871" }, -0.3 }, // half-dim
Expand All @@ -795,9 +797,15 @@ void HarmonyLayout::kernCharacters(const Harmony* item, const String& text, Harm
{ { u"A", u"/" }, 0.1 },

{ { u"A", u"\uE18E" }, -0.15 }, // dim JAZZ
{ { u"A", u"\uE18F" }, -0.15 }, // hal-dim JAZZ
{ { u"A", u"\uE18F" }, -0.15 }, // half-dim JAZZ
{ { u"\uE18A", u"\uE18E" }, -0.15 }, // triangle - dim JAZZ
{ { u"\uE18A", u"\uE18F" }, -0.15 }, // triangle - half-dim JAZZ

{ { u"\u266D", u"" }, -0.15 }, // b JAZZ
{ { u"\u266E", u"" }, -0.15 }, // natural JAZZ
{ { u"\u266F", u"" }, -0.15 }, // # JAZZ
{ { u"\u1D12A", u"" }, -0.15 }, // ## JAZZ
{ { u"\u1D12B", u"" }, -0.15 }, // bb JAZZ
};

HarmonyRenderItem* prevSeg = harmonyCtx.renderItemList.back();
Expand All @@ -808,7 +816,16 @@ void HarmonyLayout::kernCharacters(const Harmony* item, const String& text, Harm

for (auto& kernInfo : KERNED_CHARACTERS) {
const std::pair<String, String> kernPair = kernInfo.first;
if (ts->text().endsWith(kernPair.first) && text.startsWith(kernPair.second)) {
bool endChar = ts->text().endsWith(kernPair.first);
bool startChar = text.startsWith(kernPair.second);
// VERY DIRTY HACK ALERT
// "Match any" should only be applied to the Jazz preset currently.
// Remove the jazz condition when these kern values are moved to the XML files
if (kernPair.second.isEmpty() && ctx.conf().styleV(Sid::chordStyle).value<ChordStylePreset>() != ChordStylePreset::JAZZ) {
continue;
}
bool startMatchAny = kernPair.second.isEmpty();
if ((endChar && startChar) || (endChar && startMatchAny)) {
const FontMetrics fm = FontMetrics(item->font());
const double scale = harmonyCtx.scale * item->mag();
harmonyCtx.pos = harmonyCtx.pos + PointF(kernInfo.second, 0.0) * FontMetrics::capHeight(item->font()) * scale;
Expand All @@ -817,7 +834,8 @@ void HarmonyLayout::kernCharacters(const Harmony* item, const String& text, Harm
}
}

void HarmonyLayout::renderActionSet(Harmony* item, Harmony::LayoutData* ldata, const RenderActionSetPtr& a, HarmonyRenderCtx& harmonyCtx)
void HarmonyLayout::renderActionSet(Harmony* item, Harmony::LayoutData* ldata, const RenderActionSetPtr& a, HarmonyRenderCtx& harmonyCtx,
const LayoutContext& ctx)
{
const ChordList* chordList = item->score()->chordList();
const ChordSymbol cs = chordList->symbol(a->text());
Expand All @@ -829,7 +847,7 @@ void HarmonyLayout::renderActionSet(Harmony* item, Harmony::LayoutData* ldata, c
font.setPointSizeF(font.pointSizeF() * nmag);
}

kernCharacters(item, text, harmonyCtx);
kernCharacters(item, text, harmonyCtx, ctx);

TextSegment* ts = new TextSegment(text, font, harmonyCtx.x(), harmonyCtx.y(), harmonyCtx.hAlign);
harmonyCtx.movex(ts->width());
Expand Down
5 changes: 3 additions & 2 deletions src/engraving/rendering/score/harmonylayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ class HarmonyLayout

static void renderAction(Harmony* item, Harmony::LayoutData* ldata, const RenderActionPtr& a, HarmonyRenderCtx& harmonyCtx,
const LayoutContext& ctx);
static void renderActionSet(Harmony* item, Harmony::LayoutData* ldata, const RenderActionSetPtr& a, HarmonyRenderCtx& harmonyCtx);
static void renderActionSet(Harmony* item, Harmony::LayoutData* ldata, const RenderActionSetPtr& a, HarmonyRenderCtx& harmonyCtx,
const LayoutContext& ctx);
static void renderActionMove(Harmony* item, const RenderActionMovePtr& a, HarmonyRenderCtx& harmonyCtx);
static void renderActionMoveXHeight(Harmony* item, const RenderActionMoveXHeightPtr& a, HarmonyRenderCtx& harmonyCtx);
static void renderActionPush(HarmonyRenderCtx& harmonyCtx);
Expand All @@ -90,6 +91,6 @@ class HarmonyLayout
static void renderActionScale(const RenderActionScalePtr& a, HarmonyRenderCtx& harmonyCtx);
static void renderActionParen(Harmony* item, const RenderActionParenPtr& a, HarmonyRenderCtx& harmonyCtx);

static void kernCharacters(const Harmony* item, const String& text, HarmonyRenderCtx& harmonyCtx);
static void kernCharacters(const Harmony* item, const String& text, HarmonyRenderCtx& harmonyCtx, const LayoutContext& ctx);
};
}
Binary file added vtest/scores/harmony-46.mscz
Binary file not shown.
Loading