import { ITextMeasurer } from "../../Interfaces/ITextMeasurer" ; import { Fonts } from "../../../Common/Enums/Fonts" ; import { FontStyles } from "../../../Common/Enums/FontStyles" ; import { VexFlowConverter } from "./VexFlowConverter" ; import { EngravingRules } from "../EngravingRules" ; /**
 * Created by Matthias on 21.06.2016.
 */ export class VexFlowTextMeasurer implements ITextMeasurer { constructor ( rules ) { const canvas = document . createElement ( "canvas" ) ; this . context = canvas . getContext ( "2d" ) ; this . rules = rules ; } private context : CanvasRenderingContext2D ; public fontSize : number = 20 ; public fontSizeStandard : number = this . fontSize ; private rules : EngravingRules ; param text param font param style returns { number } public computeTextWidthToHeightRatio ( text , font , style , fontFamily = undefined , fontSize = this . fontSize ) { this . context . font = VexFlowConverter . font ( fontSize , style , font , this . rules , fontFamily ) ; return this . context . measureText ( text ) . width / fontSize ; } public setFontSize ( fontSize = this . fontSizeStandard ) { this . fontSize = fontSize ; return fontSize ; } }