Skip to content

Commit

Permalink
Merge pull request #1448 from rvilarl/fix/style
Browse files Browse the repository at this point in the history
minor style fixes
  • Loading branch information
rvilarl authored Oct 7, 2022
2 parents f208afa + 0ef282d commit 15a963f
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/barnote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ export class BarNote extends Note {
draw(): void {
const ctx = this.checkContext();
L('Rendering bar line at: ', this.getAbsoluteX());
if (this.style) this.applyStyle(ctx);
this.applyStyle(ctx);
const barline = new Barline(this.type);
barline.setX(this.getAbsoluteX());
barline.draw(this.checkStave());
if (this.style) this.restoreStyle(ctx);
this.restoreStyle(ctx);
this.setRendered();
}
}
2 changes: 1 addition & 1 deletion src/element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export abstract class Element {
* element.drawWithStyle();
* ```
*/
setStyle(style: ElementStyle): this {
setStyle(style: ElementStyle | undefined): this {
this.style = style;
return this;
}
Expand Down
10 changes: 3 additions & 7 deletions src/notehead.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export class NoteHead extends Note {
this.stem_down_x_offset = noteStruct.stem_down_x_offset || 0;
}

this.style = noteStruct.style;
this.setStyle(noteStruct.style);
this.slashed = noteStruct.slashed || false;

this.render_options = {
Expand Down Expand Up @@ -275,9 +275,7 @@ export class NoteHead extends Note {
const stem_direction = this.stem_direction;
const glyph_font_scale = this.render_options.glyph_font_scale;

if (this.style) {
this.applyStyle(ctx);
}
this.applyStyle(ctx);

const categorySuffix = `${this.glyph_code}Stem${stem_direction === Stem.UP ? 'Up' : 'Down'}`;
if (this.noteType === 's') {
Expand All @@ -289,8 +287,6 @@ export class NoteHead extends Note {
});
}

if (this.style) {
this.restoreStyle(ctx);
}
this.restoreStyle(ctx);
}
}
2 changes: 1 addition & 1 deletion src/stave.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ export class Stave extends Element {
fillStyle: this.options.fill_style,
strokeStyle: this.options.fill_style, // yes, this is correct for legacy compatibility
lineWidth: Tables.STAVE_LINE_THICKNESS,
...this.style,
...super.getStyle(),
};
}

Expand Down
7 changes: 2 additions & 5 deletions src/stavenote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,6 @@ export class StaveNote extends StemmableNote {
protected dot_shiftY: number;
protected use_default_head_x: boolean;
protected ledgerLineStyle: ElementStyle;
protected flagStyle?: ElementStyle;
private _noteHeads: NoteHead[];
// Sorted variant of keyProps used internally
private sortedKeyProps: { keyProps: KeyProps; index: number }[] = [];
Expand Down Expand Up @@ -868,10 +867,10 @@ export class StaveNote extends StemmableNote {
}

setFlagStyle(style: ElementStyle): void {
this.flagStyle = style;
this.flag?.setStyle(style);
}
getFlagStyle(): ElementStyle | undefined {
return this.flagStyle;
return this.flag?.getStyle();
}

// Sets the notehead at `index` to the provided coloring `style`.
Expand Down Expand Up @@ -1155,9 +1154,7 @@ export class StaveNote extends StemmableNote {
(this.flag?.getMetrics().y_shift ?? 0) * (1 - this.getStaveNoteScale());

// Draw the Flag
this.applyStyle(ctx, this.getFlagStyle());
this.flag?.render(ctx, flagX, flagY);
this.restoreStyle(ctx, this.getFlagStyle());
}
}

Expand Down

0 comments on commit 15a963f

Please sign in to comment.