Skip to content

Commit

Permalink
render_options protected
Browse files Browse the repository at this point in the history
  • Loading branch information
rvilarl committed Oct 17, 2021
1 parent ca9c6b7 commit 9090878
Show file tree
Hide file tree
Showing 13 changed files with 182 additions and 57 deletions.
14 changes: 13 additions & 1 deletion src/beam.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class Beam extends Element {
return 'Beam';
}

render_options: {
protected render_options: {
flat_beam_offset?: number;
flat_beams: boolean;
secondary_break_ticks?: number;
Expand Down Expand Up @@ -929,4 +929,16 @@ export class Beam extends Element {
this.drawBeamLines(ctx);
this.restoreStyle();
}

/** Set beamWidth render option */
setBeamWidth(beamWidth: number): this {
this.render_options.beam_width = beamWidth;
return this;
}

/** Set partialBeamLength render option */
setPartialBeamLength(partialBeamLength: number): this {
this.render_options.partial_beam_length = partialBeamLength;
return this;
}
}
8 changes: 4 additions & 4 deletions src/gracenotegroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ export class GraceNoteGroup extends Modifier {
if (grace_notes.length > 1) {
const beam = new Beam(grace_notes);

beam.render_options.beam_width = 3;
beam.render_options.partial_beam_length = 4;
beam.setBeamWidth(3);
beam.setPartialBeamLength(4);

this.beams.push(beam);
}
Expand Down Expand Up @@ -181,8 +181,8 @@ export class GraceNoteGroup extends Modifier {
last_indices: [0],
});

this.slur.render_options.cp2 = 12;
this.slur.render_options.y_shift = (is_stavenote ? 7 : 5) + this.render_options.slur_y_shift;
this.slur.setCp2(12);
this.slur.setYShift((is_stavenote ? 7 : 5) + this.render_options.slur_y_shift);
this.slur.setContext(ctx).draw();
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/multimeasurerest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function get_semibreve_rest() {
if (!semibreve_rest) {
const noteHead = new NoteHead({ duration: 'w', note_type: 'r' });
semibreve_rest = {
glyph_font_scale: noteHead.render_options.glyph_font_scale,
glyph_font_scale: noteHead.getGlyphFontScale(),
glyph_code: noteHead.glyph_code,
width: noteHead.getWidth(),
};
Expand Down
25 changes: 24 additions & 1 deletion src/note.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export abstract class Note extends Tickable {
keyProps: KeyProps[];

protected stave?: Stave;
render_options: NoteRenderOptions;
protected render_options: NoteRenderOptions;
protected duration: string;
protected dots: number;
protected leftDisplacedHeadPx: number;
Expand Down Expand Up @@ -636,4 +636,27 @@ export abstract class Note extends Tickable {
getKeyProps(): KeyProps[] {
return this.keyProps;
}

/** Set drawStem render option */
setDrawStem(drawStem: boolean): this {
this.render_options.draw_stem = drawStem;
return this;
}

/** Set drawDots render option */
setDrawDots(drawDots: boolean): this {
this.render_options.draw_dots = drawDots;
return this;
}

/** Set drawStemThroughStaves render option */
setDrawStemThroughStaves(drawStemThroughStaves: boolean): this {
this.render_options.draw_stem_through_stave = drawStemThroughStaves;
return this;
}

/** Get GlyphFontScale render option */
getGlyphFontScale(): number {
return this.render_options.glyph_font_scale;
}
}
56 changes: 55 additions & 1 deletion src/staveline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ export class StaveLine extends Element {
RIGHT: 3,
};

readonly render_options: RenderOptions;
protected render_options: RenderOptions;

protected text: string;
protected font: FontInfo;
Expand Down Expand Up @@ -380,4 +380,58 @@ export class StaveLine extends Element {

return this;
}

/** Set drawEndArrow render option */
setDrawEndArrow(drawEndArrow: boolean): this {
this.render_options.draw_end_arrow = drawEndArrow;
return this;
}

/** Set drawStartArrow render option */
setDrawStartArrow(drawStartArrow: boolean): this {
this.render_options.draw_start_arrow = drawStartArrow;
return this;
}

/** Set arrowheadAngle render option */
setArrowheadAngle(arrowheadAngle: number): this {
this.render_options.arrowhead_angle = arrowheadAngle;
return this;
}

/** Set arrowheadLength render option */
setArrowheadLength(arrowheadLength: number): this {
this.render_options.arrowhead_length = arrowheadLength;
return this;
}

/** Set textJustification render option */
setTextJustification(textJustification: number): this {
this.render_options.text_justification = textJustification;
return this;
}

/** Set textPositionVertical render option */
setTextPositionVertical(textPositionVertical: number): this {
this.render_options.text_position_vertical = textPositionVertical;
return this;
}

/** Set lineWidth render option */
setLineWidth(lineWidth: number): this {
this.render_options.line_width = lineWidth;
return this;
}

/** Set lineDash render option */
setLineDash(lineDash: number[]): this {
this.render_options.line_dash = lineDash;
return this;
}

/** Set color render option */
setColor(color: string): this {
this.render_options.color = color;
return this;
}
}
14 changes: 13 additions & 1 deletion src/stavetie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class StaveTie extends Element {
return 'StaveTie';
}

render_options: {
protected render_options: {
cp2: number;
last_x_shift: number;
tie_spacing: number;
Expand Down Expand Up @@ -218,4 +218,16 @@ export class StaveTie extends Element {
this.renderText(first_x_px, last_x_px);
return true;
}

/** Set cp2 render option */
setCp2(cp2: number): this {
this.render_options.cp2 = cp2;
return this;
}

/** Set yShift render option */
setYShift(yShift: number): this {
this.render_options.y_shift = yShift;
return this;
}
}
26 changes: 25 additions & 1 deletion src/textbracket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class TextBracket extends Element {
return 'TextBracket';
}

render_options: {
protected render_options: {
dashed: boolean;
color: string;
line_width: number;
Expand Down Expand Up @@ -139,6 +139,30 @@ export class TextBracket extends Element {
return this;
}

/** Set lineWidth render option */
setLineWidth(lineWidth: number): this {
this.render_options.line_width = lineWidth;
return this;
}

/** Set showBracket render option */
setShowBracket(showBracket: boolean): this {
this.render_options.show_bracket = showBracket;
return this;
}

/** Set underlineSuperscript render option */
setUnderlineSuperscript(underlineSuperscript: boolean): this {
this.render_options.underline_superscript = underlineSuperscript;
return this;
}

/** Set bracketHeight render option */
setBracketHeight(bracketHeight: number): this {
this.render_options.bracket_height = bracketHeight;
return this;
}

// Set the font for the text
setFont(font: FontInfo): this {
// We use Object.assign to support partial updates to the font object
Expand Down
4 changes: 2 additions & 2 deletions tests/annotation_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,13 +358,13 @@ function tabNotes(options: TestOptions, contextBuilder: ContextBuilder): void {

const notes1 = specs.map((noteSpec) => {
const note = new TabNote(noteSpec);
note.render_options.draw_stem = true;
note.setDrawStem(true);
return note;
});

const notes2 = specs.map((noteSpec) => {
const note = new TabNote(noteSpec);
note.render_options.draw_stem = true;
note.setDrawStem(true);
note.setStemDirection(-1);
return note;
});
Expand Down
4 changes: 2 additions & 2 deletions tests/articulation_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,13 +316,13 @@ function tabNotes(options: TestOptions, contextBuilder: ContextBuilder): void {

const notes1 = specs.map((noteSpec) => {
const tabNote = new TabNote(noteSpec);
tabNote.render_options.draw_stem = true;
tabNote.setDrawStem(true);
return tabNote;
});

const notes2 = specs.map((noteSpec) => {
const tabNote = new TabNote(noteSpec);
tabNote.render_options.draw_stem = true;
tabNote.setDrawStem(true);
tabNote.setStemDirection(-1);
return tabNote;
});
Expand Down
14 changes: 7 additions & 7 deletions tests/beam_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ function tabBeamsUp(options: TestOptions): void {

const notes = specs.map((struct) => {
const tabNote = f.TabNote(struct);
tabNote.render_options.draw_stem = true;
tabNote.setDrawStem(true);
return tabNote;
});

Expand Down Expand Up @@ -556,8 +556,8 @@ function tabBeamsDown(options: TestOptions): void {

const notes = specs.map((struct) => {
const tabNote = f.TabNote(struct);
tabNote.render_options.draw_stem = true;
tabNote.render_options.draw_dots = true;
tabNote.setDrawStem(true);
tabNote.setDrawDots(true);
return tabNote;
});

Expand Down Expand Up @@ -624,8 +624,8 @@ function autoTabBeams(options: TestOptions): void {

const notes = specs.map((struct) => {
const tabNote = f.TabNote(struct);
tabNote.render_options.draw_stem = true;
tabNote.render_options.draw_dots = true;
tabNote.setDrawStem(true);
tabNote.setDrawDots(true);
return tabNote;
});

Expand Down Expand Up @@ -692,8 +692,8 @@ function tabBeamsAutoStem(options: TestOptions): void {

const notes = specs.map((struct) => {
const tabNote = f.TabNote(struct);
tabNote.render_options.draw_stem = true;
tabNote.render_options.draw_dots = true;
tabNote.setDrawStem(true);
tabNote.setDrawDots(true);
return tabNote;
});

Expand Down
52 changes: 26 additions & 26 deletions tests/staveline_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function simple0(options: TestOptions): void {
first_indices: [2, 1, 0],
last_indices: [0, 1, 2],
});
staveLine2.render_options.line_dash = [10, 10];
staveLine2.setLineDash([10, 10]);

f.Formatter().joinVoices([voice]).formatToStave([voice], stave);

Expand Down Expand Up @@ -112,31 +112,31 @@ function simple1(options: TestOptions): void {
options: { text: 'Top' },
});

staveLine0.render_options.draw_end_arrow = true;
staveLine0.render_options.text_justification = 1;
staveLine0.render_options.text_position_vertical = 2;

staveLine1.render_options.draw_end_arrow = true;
staveLine1.render_options.arrowhead_length = 30;
staveLine1.render_options.line_width = 5;
staveLine1.render_options.text_justification = 2;
staveLine1.render_options.text_position_vertical = 2;

staveLine4.render_options.line_width = 2;
staveLine4.render_options.draw_end_arrow = true;
staveLine4.render_options.draw_start_arrow = true;
staveLine4.render_options.arrowhead_angle = 0.5;
staveLine4.render_options.arrowhead_length = 20;
staveLine4.render_options.text_justification = 3;
staveLine4.render_options.text_position_vertical = 2;

staveLine2.render_options.draw_start_arrow = true;
staveLine2.render_options.line_dash = [5, 4];

staveLine3.render_options.draw_end_arrow = true;
staveLine3.render_options.draw_start_arrow = true;
staveLine3.render_options.color = 'red';
staveLine3.render_options.text_position_vertical = 1;
staveLine0.setDrawEndArrow(true);
staveLine0.setTextJustification(1);
staveLine0.setTextPositionVertical(2);

staveLine1.setDrawEndArrow(true);
staveLine1.setArrowheadLength(30);
staveLine1.setLineWidth(5);
staveLine1.setTextJustification(2);
staveLine1.setTextPositionVertical(2);

staveLine4.setLineWidth(2);
staveLine4.setDrawEndArrow(true);
staveLine4.setDrawStartArrow(true);
staveLine4.setArrowheadAngle(0.5);
staveLine4.setArrowheadLength(20);
staveLine4.setTextJustification(3);
staveLine4.setTextPositionVertical(2);

staveLine2.setDrawStartArrow(true);
staveLine2.setLineDash([5, 4]);

staveLine3.setDrawEndArrow(true);
staveLine3.setDrawStartArrow(true);
staveLine3.setColor('red');
staveLine3.setTextPositionVertical(1);

f.Formatter().joinVoices([voice]).formatToStave([voice], stave);

Expand Down
Loading

0 comments on commit 9090878

Please sign in to comment.