Skip to content

Commit

Permalink
Merge pull request #120 from DDMAL/rotate-offset
Browse files Browse the repository at this point in the history
Fix staff rotation offset for inserted syllables
  • Loading branch information
yinanazhou authored Dec 21, 2023
2 parents 9970c87 + 5a5cc73 commit ca901b4
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions src/editortoolkit_neume.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -880,40 +880,38 @@ bool EditorToolkitNeume::Insert(std::string elementType, std::string staffId, in
= (int)(m_doc->GetDrawingDoubleUnit(staff->m_drawingStaffSize) / NOTE_HEIGHT_TO_STAFF_SIZE_RATIO);
const int noteWidth
= (int)(m_doc->GetDrawingDoubleUnit(staff->m_drawingStaffSize) / NOTE_WIDTH_TO_STAFF_SIZE_RATIO);
ulx -= noteWidth / 2;

// calculate staff rotation offset
double theta = staff->GetDrawingRotate();
int offsetY = 0;
if (theta) {
double factor = 1.3;
offsetY = (int)((ulx - staff->GetFacsimileInterface()->GetZone()->GetUlx()) * tan(theta * M_PI / 180.0)
/ factor);
}

// Set up facsimile
zone->SetUlx(ulx);
zone->SetUly(uly + offsetY);
zone->SetUly(uly);
zone->SetLrx(ulx + noteWidth);
zone->SetLry(uly + offsetY + noteHeight);
zone->SetLry(uly + noteHeight);

// add syl bounding box if Facs
if (m_doc->GetType() == Facs) {
FacsimileInterface *fi = vrv_cast<FacsimileInterface *>(syl->GetFacsimileInterface());
assert(fi);
sylZone = new Zone();

int draw_h = staff->GetHeight();
int staffUly = staff->GetDrawingY();
int staffLry = staff->GetFacsimileInterface()->GetZone()->GetLry();

// width height and offset can be adjusted
int bboxHeight = 175;
int bboxOffsetX = 50;

// calculate staff rotation offset
double theta = staff->GetDrawingRotate();
int offsetY = 0;
if (theta) {
double factor = 1.3;
offsetY = (int)((ulx - staff->GetFacsimileInterface()->GetZone()->GetUlx()) * tan(theta * M_PI / 180.0)
/ factor);
}

sylZone->SetUlx(ulx);
sylZone->SetUly(staffUly + draw_h + offsetY);
sylZone->SetUly(staffLry + offsetY);
sylZone->SetLrx(ulx + noteWidth + bboxOffsetX);
sylZone->SetLry(staffUly + draw_h + offsetY + bboxHeight);
sylZone->SetLry(staffLry + offsetY + bboxHeight);
surface->AddChild(sylZone);
fi->AttachZone(sylZone);
}
Expand Down

0 comments on commit ca901b4

Please sign in to comment.