|
@@ -5,30 +5,42 @@ import {VexFlowMeasure} from "./VexFlowMeasure";
|
|
|
import {ITextMeasurer} from "../../Interfaces/ITextMeasurer";
|
|
|
import {PointF2D} from "../../../Common/DataObjects/PointF2D";
|
|
|
import {GraphicalLabel} from "../GraphicalLabel";
|
|
|
-/**
|
|
|
- * Created by Matthias on 22.06.2016.
|
|
|
- */
|
|
|
+import {VexFlowConverter} from "./VexFlowConverter";
|
|
|
+
|
|
|
export class VexFlowMusicSheetDrawer extends MusicSheetDrawer {
|
|
|
private renderer: Vex.Flow.Renderer;
|
|
|
- private ctx: Vex.Flow.CanvasContext;
|
|
|
+ private vfctx: Vex.Flow.CanvasContext;
|
|
|
+ private ctx: CanvasRenderingContext2D;
|
|
|
|
|
|
constructor(canvas: HTMLCanvasElement, textMeasurer: ITextMeasurer, isPreviewImageDrawer: boolean = false) {
|
|
|
super(textMeasurer, isPreviewImageDrawer);
|
|
|
this.renderer = new Vex.Flow.Renderer(canvas, Vex.Flow.Renderer.Backends.CANVAS);
|
|
|
- this.ctx = this.renderer.getContext();
|
|
|
+ this.vfctx = this.renderer.getContext();
|
|
|
+ // The following is a hack to retrieve the actual canvas' drawing context
|
|
|
+ // Not supposed to work forever....
|
|
|
+ this.ctx = (this.vfctx as any).vexFlowCanvasContext;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Zoom the rendering areas
|
|
|
+ * @param k is the zoom factor
|
|
|
+ */
|
|
|
public scale(k: number): void {
|
|
|
- this.ctx.scale(k, k);
|
|
|
+ this.vfctx.scale(k, k);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Resize the rendering areas
|
|
|
+ * @param x
|
|
|
+ * @param y
|
|
|
+ */
|
|
|
public resize(x: number, y: number): void {
|
|
|
this.renderer.resize(x, y);
|
|
|
}
|
|
|
|
|
|
public translate(x: number, y: number): void {
|
|
|
- // FIXME
|
|
|
- //(this.ctx as any).vexFlowCanvasContext.translate(x, y);
|
|
|
+ // Translation seems not supported by VexFlow
|
|
|
+ this.ctx.translate(x, y);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -37,16 +49,15 @@ export class VexFlowMusicSheetDrawer extends MusicSheetDrawer {
|
|
|
* @returns {number} the distance in pixels
|
|
|
*/
|
|
|
public calculatePixelDistance(unitDistance: number): number {
|
|
|
- // ToDo: implement!
|
|
|
return unitDistance * 10.0;
|
|
|
}
|
|
|
|
|
|
protected drawMeasure(measure: VexFlowMeasure): void {
|
|
|
measure.setAbsoluteCoordinates(
|
|
|
- measure.PositionAndShape.AbsolutePosition.x * (measure as VexFlowMeasure).unit,
|
|
|
- measure.PositionAndShape.AbsolutePosition.y * (measure as VexFlowMeasure).unit
|
|
|
+ measure.PositionAndShape.AbsolutePosition.x * 10.0,
|
|
|
+ measure.PositionAndShape.AbsolutePosition.y * 10.0
|
|
|
);
|
|
|
- return measure.draw(this.ctx);
|
|
|
+ return measure.draw(this.vfctx);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -60,10 +71,15 @@ export class VexFlowMusicSheetDrawer extends MusicSheetDrawer {
|
|
|
*/
|
|
|
protected renderLabel(graphicalLabel: GraphicalLabel, layer: number, bitmapWidth: number,
|
|
|
bitmapHeight: number, heightInPixel: number, screenPosition: PointF2D): void {
|
|
|
- // ToDo: implement!
|
|
|
- let ctx: CanvasRenderingContext2D = (this.ctx as any).vexFlowCanvasContext;
|
|
|
- ctx.font = Math.floor(graphicalLabel.Label.fontHeight * 10) + "px 'Times New Roman'";
|
|
|
+ let ctx: CanvasRenderingContext2D = (this.vfctx as any).vexFlowCanvasContext;
|
|
|
+ let old: string = ctx.font;
|
|
|
+ ctx.font = VexFlowConverter.font(
|
|
|
+ graphicalLabel.Label.fontHeight * 10.0,
|
|
|
+ graphicalLabel.Label.fontStyle,
|
|
|
+ graphicalLabel.Label.font
|
|
|
+ );
|
|
|
ctx.fillText(graphicalLabel.Label.text, screenPosition.x, screenPosition.y + heightInPixel);
|
|
|
+ ctx.font = old;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -74,7 +90,10 @@ export class VexFlowMusicSheetDrawer extends MusicSheetDrawer {
|
|
|
* @param styleId the style id
|
|
|
*/
|
|
|
protected renderRectangle(rectangle: RectangleF2D, layer: number, styleId: number): void {
|
|
|
- // ToDo: implement!
|
|
|
+ let old: string|CanvasGradient|CanvasPattern = this.ctx.fillStyle;
|
|
|
+ this.ctx.fillStyle = VexFlowConverter.style(styleId);
|
|
|
+ this.ctx.fillRect(rectangle.x, rectangle.y, rectangle.width, rectangle.height);
|
|
|
+ this.ctx.fillStyle = old;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -83,7 +102,6 @@ export class VexFlowMusicSheetDrawer extends MusicSheetDrawer {
|
|
|
* @returns {PointF2D}
|
|
|
*/
|
|
|
protected applyScreenTransformation(point: PointF2D): PointF2D {
|
|
|
- // ToDo: implement!
|
|
|
return new PointF2D(point.x * 10.0, point.y * 10.0);
|
|
|
}
|
|
|
|
|
@@ -93,7 +111,6 @@ export class VexFlowMusicSheetDrawer extends MusicSheetDrawer {
|
|
|
* @returns {RectangleF2D}
|
|
|
*/
|
|
|
protected applyScreenTransformationForRect(rectangle: RectangleF2D): RectangleF2D {
|
|
|
- // FIXME Check if correct
|
|
|
- return new RectangleF2D(rectangle.x * 10, rectangle.y * 10, rectangle.width * 10, rectangle.height * 10);
|
|
|
+ return new RectangleF2D(rectangle.x * 10.0, rectangle.y * 10.0, rectangle.width * 10.0, rectangle.height * 10.0);
|
|
|
}
|
|
|
}
|