Skip to content

Commit

Permalink
Merge pull request #960 from rvilarl/migration/timesignote
Browse files Browse the repository at this point in the history
Migration/timesignote
  • Loading branch information
0xfe authored May 9, 2021
2 parents 6dd7dd9 + 9fe0bf2 commit 8362d35
Show file tree
Hide file tree
Showing 5 changed files with 243 additions and 206 deletions.
14 changes: 7 additions & 7 deletions src/glyph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,14 @@ export class Glyph extends Element {
bbox: BoundingBox = new BoundingBox(0, 0, 0, 0);
code: string;
metrics?: GlyphMetrics;
topGlyphs?: Glyph[];
botGlyphs?: Glyph[];
topGlyphs: Glyph[] = [];
botGlyphs: Glyph[] = [];

protected options: GlyphOptions;
protected originShift: { x: number; y: number };
protected x_shift: number;
protected y_shift: number;
protected scale: number = 1;
scale: number = 1;
protected point: number;
protected stave?: Stave;

Expand Down Expand Up @@ -371,10 +371,10 @@ export class Glyph extends Element {
x_max: this.metrics.x_max * this.scale * this.metrics.scale,
width: this.bbox.getW(),
height: this.bbox.getH(),
scale: 1,
x_shift: 0,
y_shift: 0,
outline: [],
scale: this.scale * this.metrics.scale,
x_shift: this.metrics.x_shift,
y_shift: this.metrics.y_shift,
outline: this.metrics.outline,
};
}

Expand Down
85 changes: 85 additions & 0 deletions src/timesigglyph.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import { Glyph, GlyphMetrics } from './glyph';
import { TimeSignature } from './timesignature';

export class TimeSignatureGlyph extends Glyph {
timeSignature: TimeSignature;
topStartX: number;
botStartX: number;
width: number;
xMin: number;

constructor(
timeSignature: TimeSignature,
topDigits: string[],
botDigits: string[],
code: string,
point: number,
options?: { category: string }
) {
super(code, point, options);
this.timeSignature = timeSignature;
this.topGlyphs = [];
this.botGlyphs = [];

let topWidth = 0;
for (let i = 0; i < topDigits.length; ++i) {
const num = topDigits[i];
const topGlyph = new Glyph('timeSig' + num, this.timeSignature.point!);

this.topGlyphs.push(topGlyph);
topWidth += topGlyph.getMetrics().width!;
}

let botWidth = 0;
for (let i = 0; i < botDigits.length; ++i) {
const num = botDigits[i];
const botGlyph = new Glyph('timeSig' + num, this.timeSignature.point!);

this.botGlyphs.push(botGlyph);
botWidth += botGlyph.getMetrics().width!;
}

this.width = Math.max(topWidth, botWidth);
this.xMin = this.getMetrics().x_min;
this.topStartX = (this.width - topWidth) / 2.0;
this.botStartX = (this.width - botWidth) / 2.0;
this.reset();
}

getMetrics(): GlyphMetrics {
return {
x_min: this.xMin,
x_max: this.xMin + this.width,
width: this.width,
} as GlyphMetrics;
}

renderToStave(x: number): void {
let start_x = x + this.topStartX;
for (let i = 0; i < this.topGlyphs.length; ++i) {
const glyph = this.topGlyphs[i];
Glyph.renderOutline(
this.checkContext(),
glyph.getMetrics().outline,
this.scale,
start_x + this.x_shift,
this.stave!.getYForLine(this.timeSignature.topLine!)
);
start_x += glyph.getMetrics().width!;
}

start_x = x + this.botStartX;
for (let i = 0; i < this.botGlyphs.length; ++i) {
const glyph = this.botGlyphs[i];
this.timeSignature.placeGlyphOnLine(glyph, this.stave!, 0);
Glyph.renderOutline(
this.checkContext(),
glyph.getMetrics().outline,
this.scale,
start_x + glyph.getMetrics().x_shift,
this.stave!.getYForLine(this.timeSignature.bottomLine!)
);
start_x += glyph.getMetrics().width!;
}
}
}
186 changes: 0 additions & 186 deletions src/timesignature.js

This file was deleted.

Loading

0 comments on commit 8362d35

Please sign in to comment.