Skip to content

Commit

Permalink
feat(SVG): Add SVG classes for StaveTie, Beam (OSMDPatch)
Browse files Browse the repository at this point in the history
  • Loading branch information
sschmidTU committed Feb 10, 2022
1 parent 21aa916 commit e915eb5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/beam.ts
Original file line number Diff line number Diff line change
Expand Up @@ -879,13 +879,15 @@ export class Beam extends Element {
if (lastBeamX) {
const lastBeamY = this.getSlopeY(lastBeamX, firstStemX, beamY, this.slope);

this.setAttribute('el', ctx.openGroup('beam'));
ctx.beginPath();
ctx.moveTo(startBeamX, startBeamY);
ctx.lineTo(startBeamX, startBeamY + beamThickness);
ctx.lineTo(lastBeamX + 1, lastBeamY + beamThickness);
ctx.lineTo(lastBeamX + 1, lastBeamY);
ctx.closePath();
ctx.fill();
ctx.closeGroup();
} else {
throw new RuntimeError('NoLastBeamX', 'lastBeamX undefined.');
}
Expand Down
8 changes: 8 additions & 0 deletions src/stavetie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,20 @@ export class StaveTie extends Element {
const top_cp_y = (first_y_px + last_y_px) / 2 + cp1 * params.direction;
const bottom_cp_y = (first_y_px + last_y_px) / 2 + cp2 * params.direction;

// id probably unnecessary if we save the group to 'el' via setAttribute
// let id: string = "";
// if (this.notes.first_note) {
// id = this.notes.first_note.getAttribute('id') + '-tie';
// }
// this.setAttribute('el', ctx.openGroup('stavetie', id));
this.setAttribute('el', ctx.openGroup('stavetie'));
ctx.beginPath();
ctx.moveTo(params.first_x_px + first_x_shift, first_y_px);
ctx.quadraticCurveTo(cp_x, top_cp_y, params.last_x_px + last_x_shift, last_y_px);
ctx.quadraticCurveTo(cp_x, bottom_cp_y, params.first_x_px + first_x_shift, first_y_px);
ctx.closePath();
ctx.fill();
ctx.closeGroup();
}
}

Expand Down

0 comments on commit e915eb5

Please sign in to comment.