VexFlowBackend.ts 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import * as Vex from "vexflow";
  2. import {FontStyles} from "../../../Common/Enums/FontStyles";
  3. import {Fonts} from "../../../Common/Enums/Fonts";
  4. import {RectangleF2D} from "../../../Common/DataObjects/RectangleF2D";
  5. import {PointF2D} from "../../../Common/DataObjects/PointF2D";
  6. export class VexFlowBackends {
  7. public static CANVAS: 0;
  8. public static RAPHAEL: 1;
  9. public static SVG: 2;
  10. public static VML: 3;
  11. }
  12. export abstract class VexFlowBackend {
  13. public abstract initialize(container: HTMLElement): void;
  14. public getInnerElement(): HTMLElement {
  15. return this.inner;
  16. }
  17. public getCanvas(): HTMLElement {
  18. return this.canvas;
  19. }
  20. public getRenderer(): Vex.Flow.Renderer {
  21. return this.renderer;
  22. }
  23. public removeFromContainer(container: HTMLElement): void {
  24. container.removeChild(this.canvas);
  25. }
  26. public abstract getContext(): Vex.IRenderContext;
  27. // public abstract setWidth(width: number): void;
  28. // public abstract setHeight(height: number): void;
  29. public abstract scale(k: number): void;
  30. public resize(x: number, y: number): void {
  31. this.renderer.resize(x, y);
  32. }
  33. public abstract clear(): void;
  34. public abstract translate(x: number, y: number): void;
  35. public abstract renderText(fontHeight: number, fontStyle: FontStyles, font: Fonts, text: string,
  36. heightInPixel: number, screenPosition: PointF2D, color?: string): void;
  37. /**
  38. * Renders a rectangle with the given style to the screen.
  39. * It is given in screen coordinates.
  40. * @param rectangle the rect in screen coordinates
  41. * @param layer is the current rendering layer. There are many layers on top of each other to which can be rendered. Not needed for now.
  42. * @param styleId the style id
  43. * @param alpha alpha value between 0 and 1
  44. */
  45. public abstract renderRectangle(rectangle: RectangleF2D, styleId: number, alpha: number): void;
  46. public abstract renderLine(start: PointF2D, stop: PointF2D, color: string, lineWidth: number): void;
  47. public abstract renderCurve(points: PointF2D[]): void;
  48. public abstract getBackendType(): number;
  49. protected renderer: Vex.Flow.Renderer;
  50. protected inner: HTMLElement;
  51. protected canvas: HTMLElement;
  52. }