VexFlowBackend.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 abstract getContext(): Vex.Flow.RenderContext;
  24. // public abstract setWidth(width: number): void;
  25. // public abstract setHeight(height: number): void;
  26. public abstract scale(k: number): void;
  27. public resize(x: number, y: number): void {
  28. this.renderer.resize(x, y);
  29. }
  30. public abstract clear(): void;
  31. public abstract translate(x: number, y: number): void;
  32. public abstract renderText(fontHeight: number, fontStyle: FontStyles, font: Fonts, text: string,
  33. heightInPixel: number, screenPosition: PointF2D, color?: string): void;
  34. /**
  35. * Renders a rectangle with the given style to the screen.
  36. * It is given in screen coordinates.
  37. * @param rectangle the rect in screen coordinates
  38. * @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.
  39. * @param styleId the style id
  40. * @param alpha alpha value between 0 and 1
  41. */
  42. public abstract renderRectangle(rectangle: RectangleF2D, styleId: number, alpha: number): void;
  43. public abstract renderLine(start: PointF2D, stop: PointF2D, color: string, lineWidth: number): void;
  44. public abstract renderCurve(points: PointF2D[]): void;
  45. public abstract getBackendType(): number;
  46. protected renderer: Vex.Flow.Renderer;
  47. protected inner: HTMLElement;
  48. protected canvas: HTMLElement;
  49. }