Skip to content

Commit

Permalink
Change --ligatureStraight to ligatureOblique with auto, `straig…
Browse files Browse the repository at this point in the history
…ht` and `curved`
  • Loading branch information
lpugin committed Feb 23, 2025
1 parent 0375777 commit ee1cfff
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 88 deletions.
5 changes: 4 additions & 1 deletion include/vrv/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ enum option_FOOTER { FOOTER_none = 0, FOOTER_auto, FOOTER_encoded, FOOTER_always

enum option_HEADER { HEADER_none = 0, HEADER_auto, HEADER_encoded };

enum option_LIGATURE_OBL { LIGATURE_OBL_auto = 0, LIGATURE_OBL_straight, LIGATURE_OBL_curved };

enum option_MULTIRESTSTYLE {
MULTIRESTSTYLE_auto = 0,
MULTIRESTSTYLE_default,
Expand Down Expand Up @@ -148,6 +150,7 @@ class Option {
static const std::map<int, std::string> s_fontFallback;
static const std::map<int, std::string> s_footer;
static const std::map<int, std::string> s_header;
static const std::map<int, std::string> s_ligatureOblique;
static const std::map<int, std::string> s_multiRestStyle;
static const std::map<int, std::string> s_pedalStyle;
static const std::map<int, std::string> s_systemDivider;
Expand Down Expand Up @@ -845,7 +848,7 @@ class Options {

OptionIntMap m_durationEquivalence;
OptionBool m_ligatureAsBracket;
OptionBool m_ligatureStraight;
OptionIntMap m_ligatureOblique;
OptionBool m_mensuralScoreUp;
OptionBool m_mensuralResponsiveView;
OptionBool m_mensuralToCmn;
Expand Down
2 changes: 1 addition & 1 deletion include/vrv/view.h
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ class View {
void CalcBrevisPoints(
Note *note, Staff *staff, Point *topLeft, Point *bottomRight, int sides[4], int shape, bool isMensuralBlack);
void CalcObliquePoints(Note *note1, Note *note2, Staff *staff, Point points[4], int sides[4], int shape,
bool isMensuralBlack, bool firstHalf);
bool isMensuralBlack, bool firstHalf, bool straight);

/**
* Internal methods for drawing a BeamSegment
Expand Down
9 changes: 6 additions & 3 deletions src/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ const std::map<int, std::string> Option::s_footer
const std::map<int, std::string> Option::s_header
= { { HEADER_none, "none" }, { HEADER_auto, "auto" }, { HEADER_encoded, "encoded" } };

const std::map<int, std::string> Option::s_ligatureOblique
= { { LIGATURE_OBL_auto, "auto" }, { LIGATURE_OBL_straight, "straight" }, { LIGATURE_OBL_curved, "curved" } };

const std::map<int, std::string> Option::s_multiRestStyle = { { MULTIRESTSTYLE_auto, "auto" },
{ MULTIRESTSTYLE_default, "default" }, { MULTIRESTSTYLE_block, "block" }, { MULTIRESTSTYLE_symbols, "symbols" } };

Expand Down Expand Up @@ -1832,9 +1835,9 @@ Options::Options()
m_ligatureAsBracket.Init(false);
this->Register(&m_ligatureAsBracket, "ligatureAsBracket", &m_mensural);

m_ligatureStraight.SetInfo("Ligature straight", "Render oblique ligatures as straight polygons");
m_ligatureStraight.Init(false);
this->Register(&m_ligatureStraight, "ligatureStraight", &m_mensural);
m_ligatureOblique.SetInfo("Ligature oblique", "Ligature oblique shape");
m_ligatureOblique.Init(LIGATURE_OBL_auto, &Option::s_ligatureOblique);
this->Register(&m_ligatureOblique, "ligatureOblique", &m_mensural);

m_mensuralResponsiveView.SetInfo(
"Mensural reduced view", "Convert mensural content to a more responsive view reduced to the seleceted markup");
Expand Down
98 changes: 15 additions & 83 deletions src/view_mensural.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,12 +350,17 @@ void View::DrawLigatureNote(DeviceContext *dc, LayerElement *element, Layer *lay
bool oblique = ((shape & LIGATURE_OBLIQUE) || (prevShape & LIGATURE_OBLIQUE));
bool obliqueEnd = (prevShape & LIGATURE_OBLIQUE);
bool stackedEnd = (shape & LIGATURE_STACKED);
bool straight = m_doc->GetOptions()->m_ligatureStraight.GetValue();

int stemWidth = m_doc->GetDrawingStemWidth(staff->m_drawingStaffSize);
int strokeWidth = 2.8 * stemWidth;
/** end code duplicated */

bool straight = true;
switch (m_doc->GetOptions()->m_ligatureOblique.GetValue()) {
case LIGATURE_OBL_auto: straight = !isMensuralBlack; break;
case LIGATURE_OBL_straight: straight = true; break;
case LIGATURE_OBL_curved: straight = false; break;
}

Point points[4];
Point *topLeft = &points[0];
Point *bottomLeft = &points[1];
Expand All @@ -373,11 +378,11 @@ void View::DrawLigatureNote(DeviceContext *dc, LayerElement *element, Layer *lay
// First half of the oblique - checking the nextNote is there just in case, but is should
if ((shape & LIGATURE_OBLIQUE) && nextNote) {
// return;
CalcObliquePoints(note, nextNote, staff, points, sides, shape, isMensuralBlack, true);
CalcObliquePoints(note, nextNote, staff, points, sides, shape, isMensuralBlack, true, straight);
}
// Second half of the oblique - checking the prevNote is there just in case, but is should
else if ((prevShape & LIGATURE_OBLIQUE) && prevNote) {
CalcObliquePoints(prevNote, note, staff, points, sides, prevShape, isMensuralBlack, false);
CalcObliquePoints(prevNote, note, staff, points, sides, prevShape, isMensuralBlack, false, straight);
}
else {
assert(false);
Expand All @@ -386,7 +391,7 @@ void View::DrawLigatureNote(DeviceContext *dc, LayerElement *element, Layer *lay

// Oblique polygons
if (straight) {
if (fillNotehead) {
if (!fillNotehead) {
this->DrawObliquePolygon(dc, topLeft->x, topLeft->y, topRight->x, topRight->y, -strokeWidth);
this->DrawObliquePolygon(dc, bottomLeft->x, bottomLeft->y, bottomRight->x, bottomRight->y, strokeWidth);
}
Expand Down Expand Up @@ -646,7 +651,7 @@ void View::CalcBrevisPoints(
}

void View::CalcObliquePoints(Note *note1, Note *note2, Staff *staff, Point points[4], int sides[4], int shape,
bool isMensuralBlack, bool firstHalf)
bool isMensuralBlack, bool firstHalf, bool straight)
{
assert(note1);
assert(note2);
Expand All @@ -655,7 +660,8 @@ void View::CalcObliquePoints(Note *note1, Note *note2, Staff *staff, Point point
const int stemWidth = m_doc->GetDrawingStemWidth(staff->m_drawingStaffSize);
const int noteDiff = note1->PitchDifferenceTo(note2);

const int yAdjust = noteDiff * stemWidth / 10;
// Adjustment for end points according to the note diff
const int yAdjust = noteDiff * stemWidth / 5;

Point *topLeft = &points[0];
Point *bottomLeft = &points[1];
Expand Down Expand Up @@ -686,10 +692,10 @@ void View::CalcObliquePoints(Note *note1, Note *note2, Staff *staff, Point point
slope = (double)(bottomRight->y - bottomLeft->y) / (double)(bottomRight->x - bottomLeft->x);

int length = (bottomRight->x - bottomLeft->x) / 2;
slope *= 0.85;
if (!straight) slope *= 0.85;

if (firstHalf) {
// make sure there are some pixels of overlap
// make sure there is one pixel of overlap
length += 1;
bottomRight->x = bottomLeft->x + length;
topRight->x = bottomRight->x;
Expand All @@ -710,80 +716,6 @@ void View::CalcObliquePoints(Note *note1, Note *note2, Staff *staff, Point point
}
}

/*
void View::CalcObliquePoints(Note *note1, Note *note2, Staff *staff, Point points[4], int sides[4], int shape,
bool isMensuralBlack, bool firstHalf)
{
assert(note1);
assert(note2);
assert(staff);
const int stemWidth = m_doc->GetDrawingStemWidth(staff->m_drawingStaffSize);
Point *topLeft = &points[0];
Point *bottomLeft = &points[1];
Point *topRight = &points[2];
Point *bottomRight = &points[3];
int sides1[4];
CalcBrevisPoints(note1, staff, topLeft, bottomLeft, sides1, shape, isMensuralBlack);
// Correct the x of bottomLeft
bottomLeft->x = topLeft->x;
// Copy the left sides
sides[0] = sides1[0];
sides[1] = sides1[1];
int sides2[4];
// add OBLIQUE shape to make sure sides are shortened in mensural black
CalcBrevisPoints(note2, staff, topRight, bottomRight, sides2, LIGATURE_OBLIQUE, isMensuralBlack);
// Correct the x of topRight;
topRight->x = bottomRight->x;
// Copy the right sides
sides[2] = sides2[2];
sides[3] = sides2[3];
// With oblique it is best visually to move them up / down - more with (white) ligatures with serif
double adjustmentFactor = (isMensuralBlack) ? 2.5 : 1.8;
double slope = 0.0;
slope *= 1.6;
if (bottomRight->x != bottomLeft->x)
slope = (double)(bottomRight->y - bottomLeft->y) / (double)(bottomRight->x - bottomLeft->x);
int adjustment = (int)(slope * stemWidth) * adjustmentFactor;
topLeft->y -= adjustment;
// bottomLeft->y -= adjustment;
if (firstHalf) {
topRight->y -= adjustment;
// bottomRight->y += adjustment;
}
else {
// topRight->y += adjustment;
// bottomRight->y -= adjustment;
}
slope = 0.0;
// recalculate slope after adjustment
if (bottomRight->x != bottomLeft->x)
slope = (double)(bottomRight->y - bottomLeft->y) / (double)(bottomRight->x - bottomLeft->x);
int length = (bottomRight->x - bottomLeft->x) / 2;
slope *= 1.6;
if (firstHalf) {
// make sure there are some pixels of overlap
// length += 10;
bottomRight->x = bottomLeft->x + length;
topRight->x = bottomRight->x;
bottomRight->y = bottomLeft->y + (int)(length * slope);
topRight->y = topLeft->y + (int)(length * slope);
}
else {
bottomLeft->x = bottomLeft->x + length;
topLeft->x = bottomLeft->x;
bottomLeft->y = bottomLeft->y + (int)(length * slope);
topLeft->y = topLeft->y + (int)(length * slope);
}
}
*/

data_STEMDIRECTION View::GetMensuralStemDir(Layer *layer, Note *note, int verticalCenter)
{
// constants
Expand Down

0 comments on commit ee1cfff

Please sign in to comment.