EngravingRules.ts 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879
  1. import { PagePlacementEnum } from "./GraphicalMusicPage";
  2. //import {MusicSymbol} from "./MusicSymbol";
  3. import log from "loglevel";
  4. import { TextAlignmentEnum } from "../../Common/Enums/TextAlignment";
  5. import { PlacementEnum } from "../VoiceData/Expressions/AbstractExpression";
  6. import { AutoBeamOptions, AlignRestOption, FillEmptyMeasuresWithWholeRests } from "../../OpenSheetMusicDisplay/OSMDOptions";
  7. import { ColoringModes as ColoringMode } from "./DrawingParameters";
  8. import { Dictionary } from "typescript-collections";
  9. import { FontStyles } from "../../Common/Enums";
  10. import { NoteEnum } from "../../Common/DataObjects/Pitch";
  11. import { ChordSymbolEnum, CustomChord, DegreesInfo } from "../../MusicalScore/VoiceData/ChordSymbolContainer";
  12. import { GraphicalNote } from "./GraphicalNote";
  13. import { Note } from "../VoiceData/Note";
  14. /** Rendering and Engraving options, more fine-grained than [[IOSMDOptions]].
  15. * Not all of these options are meant to be modified by users of the library,
  16. * full support is only given for [[IOSMDOptions]].
  17. * Nevertheless, there are many useful options here,
  18. * like Render* to (not) render certain elements (e.g. osmd.rules.RenderRehearsalMarks = false)
  19. */
  20. export class EngravingRules {
  21. /** A unit of distance. 1.0 is the distance between lines of a stave for OSMD, which is 10 pixels in Vexflow. */
  22. public static unit: number = 1.0;
  23. public SamplingUnit: number;
  24. public StaccatoShorteningFactor: number;
  25. /** Height (size) of the sheet title. */
  26. public SheetTitleHeight: number;
  27. public SheetSubtitleHeight: number;
  28. public SheetMinimumDistanceBetweenTitleAndSubtitle: number;
  29. public SheetComposerHeight: number;
  30. public SheetAuthorHeight: number;
  31. public CompactMode: boolean;
  32. public PagePlacementEnum: PagePlacementEnum;
  33. public PageHeight: number;
  34. public PageTopMargin: number;
  35. public PageTopMarginNarrow: number;
  36. public PageBottomMargin: number;
  37. public PageLeftMargin: number;
  38. public PageRightMargin: number;
  39. public TitleTopDistance: number;
  40. public TitleBottomDistance: number;
  41. public SystemLeftMargin: number;
  42. public SystemRightMargin: number;
  43. public SystemLabelsRightMargin: number;
  44. public SystemComposerDistance: number;
  45. public InstrumentLabelTextHeight: number;
  46. public MinimumDistanceBetweenSystems: number;
  47. public MinSkyBottomDistBetweenSystems: number;
  48. public LastSystemMaxScalingFactor: number;
  49. public StaffDistance: number;
  50. public BetweenStaffDistance: number;
  51. public StaffHeight: number;
  52. public TabStaffInterlineHeight: number;
  53. public BetweenStaffLinesDistance: number;
  54. /** Whether to automatically beam notes that don't already have beams in XML. */
  55. public AutoBeamNotes: boolean;
  56. /** Options for autoBeaming like whether to beam over rests. See AutoBeamOptions interface. */
  57. public AutoBeamOptions: AutoBeamOptions;
  58. public BeamWidth: number;
  59. public BeamSpaceWidth: number;
  60. public BeamForwardLength: number;
  61. public FlatBeams: boolean;
  62. public FlatBeamOffset: number;
  63. public FlatBeamOffsetPerBeam: number;
  64. public ClefLeftMargin: number;
  65. public ClefRightMargin: number;
  66. /** How many unique note positions a percussion score needs to have to not be rendered on one line. */
  67. public PercussionOneLineCutoff: number;
  68. public PercussionForceVoicesOneLineCutoff: number;
  69. public PercussionUseXMLDisplayStep: boolean;
  70. public PercussionXMLDisplayStepNoteValueShift: number;
  71. public PercussionOneLineXMLDisplayStepOctaveOffset: number;
  72. public BetweenKeySymbolsDistance: number;
  73. public KeyRightMargin: number;
  74. public RhythmRightMargin: number;
  75. public ShowRhythmAgainAfterPartEndOrFinalBarline: boolean;
  76. public NewPartAndSystemAfterFinalBarline: boolean;
  77. public InStaffClefScalingFactor: number;
  78. public DistanceBetweenNaturalAndSymbolWhenCancelling: number;
  79. public NoteHelperLinesOffset: number;
  80. public MeasureLeftMargin: number;
  81. public MeasureRightMargin: number;
  82. public DistanceBetweenLastInstructionAndRepetitionBarline: number;
  83. public ArpeggioDistance: number;
  84. public IdealStemLength: number;
  85. public StemNoteHeadBorderYOffset: number;
  86. public StemWidth: number;
  87. public StemMargin: number;
  88. public StemMinLength: number;
  89. public StemMaxLength: number;
  90. public BeamSlopeMaxAngle: number;
  91. public StemMinAllowedDistanceBetweenNoteHeadAndBeamLine: number;
  92. public SetWantedStemDirectionByXml: boolean;
  93. public GraceNoteScalingFactor: number;
  94. public GraceNoteXOffset: number;
  95. public WedgeOpeningLength: number;
  96. public WedgeMeasureEndOpeningLength: number;
  97. public WedgeMeasureBeginOpeningLength: number;
  98. public WedgePlacementAboveY: number;
  99. public WedgePlacementBelowY: number;
  100. public WedgeHorizontalMargin: number;
  101. public WedgeVerticalMargin: number;
  102. public DistanceOffsetBetweenTwoHorizontallyCrossedWedges: number;
  103. public WedgeMinLength: number;
  104. public WedgeEndDistanceBetweenTimestampsFactor: number;
  105. public DistanceBetweenAdjacentDynamics: number;
  106. public TempoChangeMeasureValidity: number;
  107. public TempoContinousFactor: number;
  108. public StaccatoScalingFactor: number;
  109. public BetweenDotsDistance: number;
  110. public OrnamentAccidentalScalingFactor: number;
  111. public ChordSymbolTextHeight: number;
  112. public ChordSymbolTextAlignment: TextAlignmentEnum;
  113. public ChordSymbolRelativeXOffset: number;
  114. public ChordSymbolXSpacing: number;
  115. public ChordOverlapAllowedIntoNextMeasure: number;
  116. public ChordSymbolYOffset: number;
  117. public ChordSymbolYPadding: number;
  118. public ChordSymbolYAlignment: boolean;
  119. public ChordSymbolYAlignmentScope: string;
  120. public ChordSymbolLabelTexts: Dictionary<ChordSymbolEnum, string>;
  121. public CustomChords: CustomChord[];
  122. public RepetitionSymbolsYOffset: number;
  123. public RehearsalMarkXOffset: number;
  124. public RehearsalMarkXOffsetDefault: number;
  125. public RehearsalMarkXOffsetSystemStartMeasure: number;
  126. public RehearsalMarkYOffset: number;
  127. public RehearsalMarkYOffsetDefault: number;
  128. public RehearsalMarkFontSize: number;
  129. public MeasureNumberLabelHeight: number;
  130. public MeasureNumberLabelOffset: number;
  131. public MeasureNumberLabelXOffset: number;
  132. /** Whether tuplets should display ratio (3:2 instead of 3 for triplet). Default false. */
  133. public TupletsRatioed: boolean;
  134. /** Whether all tuplets should be bracketed (e.g. |--5--| instead of 5). Default false.
  135. * If false, only tuplets given as bracketed in XML (bracket="yes") will be bracketed.
  136. * (If not given in XML, bracketing is implementation-dependent according to standard)
  137. */
  138. public TupletsBracketed: boolean;
  139. /** Whether all triplets should be bracketed. Overrides tupletsBracketed for triplets.
  140. * If false, only triplets given as bracketed in XML (bracket="yes") will be bracketed.
  141. * (Bracketing all triplets can be cluttering)
  142. */
  143. public TripletsBracketed: boolean;
  144. public TupletNumberLabelHeight: number;
  145. public TupletNumberYOffset: number;
  146. public LabelMarginBorderFactor: number;
  147. public TupletVerticalLineLength: number;
  148. public TupletNumbersInTabs: boolean;
  149. public RepetitionEndingLabelHeight: number;
  150. public RepetitionEndingLabelXOffset: number;
  151. public RepetitionEndingLabelYOffset: number;
  152. public RepetitionEndingLineYLowerOffset: number;
  153. public RepetitionEndingLineYUpperOffset: number;
  154. public VoltaOffset: number;
  155. /** Default alignment of lyrics.
  156. * Left alignments will extend text to the right of the bounding box,
  157. * which facilitates spacing by extending measure width.
  158. */
  159. public LyricsAlignmentStandard: TextAlignmentEnum;
  160. public LyricsHeight: number;
  161. public LyricsYOffsetToStaffHeight: number;
  162. public VerticalBetweenLyricsDistance: number;
  163. public HorizontalBetweenLyricsDistance: number;
  164. public BetweenSyllableMaximumDistance: number;
  165. public BetweenSyllableMinimumDistance: number;
  166. public LyricOverlapAllowedIntoNextMeasure: number;
  167. public MinimumDistanceBetweenDashes: number;
  168. public MaximumLyricsElongationFactor: number;
  169. public SlurPlacementFromXML: boolean;
  170. public BezierCurveStepSize: number;
  171. public TPower3: number[];
  172. public OneMinusTPower3: number[];
  173. public FactorOne: number[];
  174. public FactorTwo: number[];
  175. public TieGhostObjectWidth: number;
  176. public TieYPositionOffsetFactor: number;
  177. public MinimumNeededXspaceForTieGhostObject: number;
  178. public TieHeightMinimum: number;
  179. public TieHeightMaximum: number;
  180. public TieHeightInterpolationK: number;
  181. public TieHeightInterpolationD: number;
  182. public SlurNoteHeadYOffset: number;
  183. public SlurStemXOffset: number;
  184. public SlurSlopeMaxAngle: number;
  185. public SlurTangentMinAngle: number;
  186. public SlurTangentMaxAngle: number;
  187. public SlurHeightFactor: number;
  188. public SlurHeightFlattenLongSlursFactorByWidth: number;
  189. public SlurHeightFlattenLongSlursFactorByAngle: number;
  190. public SlurHeightFlattenLongSlursCutoffAngle: number;
  191. public SlurHeightFlattenLongSlursCutoffWidth: number;
  192. public SlursStartingAtSameStaffEntryYOffset: number;
  193. public SlurMaximumYControlPointDistance: number;
  194. public InstantaneousTempoTextHeight: number;
  195. public ContinuousDynamicTextHeight: number;
  196. public MoodTextHeight: number;
  197. public UnknownTextHeight: number;
  198. public ContinuousTempoTextHeight: number;
  199. public VexFlowDefaultNotationFontScale: number;
  200. public VexFlowDefaultTabFontScale: number;
  201. public TremoloStrokeScale: number;
  202. public TremoloYSpacingScale: number;
  203. public StaffLineWidth: number;
  204. public StaffLineColor: string;
  205. public LedgerLineWidth: number;
  206. public LedgerLineStrokeStyle: string;
  207. public LedgerLineColorDefault: string;
  208. public WedgeLineWidth: number;
  209. public TupletLineWidth: number;
  210. public LyricUnderscoreLineWidth: number;
  211. public SystemThinLineWidth: number;
  212. public SystemBoldLineWidth: number;
  213. public SystemRepetitionEndingLineWidth: number;
  214. public SystemDotWidth: number;
  215. public MultipleRestMeasureDefaultWidth: number;
  216. public DistanceBetweenVerticalSystemLines: number;
  217. public DistanceBetweenDotAndLine: number;
  218. public RepeatEndStartPadding: number;
  219. public OctaveShiftLineWidth: number;
  220. public OctaveShiftVerticalLineLength: number;
  221. public GraceLineWidth: number;
  222. public MinimumStaffLineDistance: number;
  223. public MinSkyBottomDistBetweenStaves: number;
  224. public MinimumCrossedBeamDifferenceMargin: number;
  225. public VoiceSpacingMultiplierVexflow: number;
  226. public VoiceSpacingAddendVexflow: number;
  227. public PickupMeasureWidthMultiplier: number;
  228. public DisplacedNoteMargin: number;
  229. public MinNoteDistance: number;
  230. public SubMeasureXSpacingThreshold: number;
  231. public MeasureDynamicsMaxScalingFactor: number;
  232. public WholeRestXShiftVexflow: number;
  233. public MetronomeMarksDrawn: boolean;
  234. public MetronomeMarkXShift: number;
  235. public MetronomeMarkYShift: number;
  236. public SoftmaxFactorVexFlow: number;
  237. /** Stagger (x-shift) whole notes that are the same note, but in different voices (show 2 instead of 1). */
  238. public StaggerSameWholeNotes: boolean;
  239. public MaxInstructionsConstValue: number;
  240. public NoteDistances: number[] = [1.0, 1.0, 1.3, 1.6, 2.0, 2.5, 3.0, 4.0];
  241. public NoteDistancesScalingFactors: number[] = [1.0, 2.0, 4.0, 8.0, 16.0, 32.0, 64.0, 128.0];
  242. public DurationDistanceDict: {[_: number]: number } = {};
  243. public DurationScalingDistanceDict: {[_: number]: number } = {};
  244. /** Whether to align rests. 0 = Never, 1 = Always, 2 = Auto.
  245. * Currently not recommended because rests are now positioned to avoid collisions with notes. */
  246. public AlignRests: AlignRestOption; // 0 = false, 1 = true, 2 = auto
  247. public RestCollisionYPadding: number;
  248. public FillEmptyMeasuresWithWholeRest: FillEmptyMeasuresWithWholeRests | number;
  249. public ArpeggiosGoAcrossVoices: boolean;
  250. public RenderArpeggios: boolean;
  251. public RenderSlurs: boolean;
  252. public ColoringMode: ColoringMode;
  253. public ColoringEnabled: boolean;
  254. public ColorStemsLikeNoteheads: boolean;
  255. public ColorFlags: boolean;
  256. public ColorBeams: boolean;
  257. public ColoringSetCurrent: Dictionary<NoteEnum|number, string>;
  258. public DefaultColorNotehead: string;
  259. public DefaultColorRest: string;
  260. public DefaultColorStem: string;
  261. public DefaultColorLabel: string;
  262. public DefaultColorChordSymbol: string;
  263. public DefaultColorTitle: string;
  264. public DefaultColorCursor: string;
  265. public DefaultFontFamily: string;
  266. public DefaultFontStyle: FontStyles;
  267. public DefaultVexFlowNoteFont: string;
  268. public MaxMeasureToDrawIndex: number;
  269. public MinMeasureToDrawIndex: number;
  270. public MaxPageToDrawNumber: number;
  271. public MaxSystemToDrawNumber: number;
  272. /** Whether to render a label for the composer of the piece at the top of the sheet. */
  273. public RenderComposer: boolean;
  274. public RenderTitle: boolean;
  275. public RenderSubtitle: boolean;
  276. public RenderLyricist: boolean;
  277. public RenderPartNames: boolean;
  278. public RenderPartAbbreviations: boolean;
  279. public RenderFingerings: boolean;
  280. public RenderMeasureNumbers: boolean;
  281. public RenderMeasureNumbersOnlyAtSystemStart: boolean;
  282. public UseXMLMeasureNumbers: boolean;
  283. public RenderLyrics: boolean;
  284. public RenderChordSymbols: boolean;
  285. public RenderMultipleRestMeasures: boolean;
  286. public AutoGenerateMutipleRestMeasuresFromRestMeasures: boolean;
  287. public RenderRehearsalMarks: boolean;
  288. public RenderKeySignatures: boolean;
  289. public RenderTimeSignatures: boolean;
  290. public DynamicExpressionMaxDistance: number;
  291. public DynamicExpressionSpacer: number;
  292. public MpatMode: boolean;
  293. public ArticulationPlacementFromXML: boolean;
  294. /** Where to draw fingerings (Above, Below, AboveOrBelow, Left, Right, or Auto).
  295. * Default AboveOrBelow. Auto experimental. */
  296. public FingeringPosition: PlacementEnum;
  297. public FingeringPositionFromXML: boolean;
  298. public FingeringPositionGrace: PlacementEnum;
  299. public FingeringInsideStafflines: boolean;
  300. public FingeringLabelFontHeight: number;
  301. public FingeringOffsetX: number;
  302. public FingeringOffsetY: number;
  303. public FingeringPaddingY: number;
  304. public FingeringTextSize: number;
  305. /** Whether to render string numbers in classical scores, i.e. not the string numbers in tabs, but e.g. for violin. */
  306. public RenderStringNumbersClassical: boolean;
  307. /** This is not for tabs, but for classical scores, especially violin. */
  308. public StringNumberOffsetY: number;
  309. public NewSystemAtXMLNewSystemAttribute: boolean;
  310. public NewPageAtXMLNewPageAttribute: boolean;
  311. public PageFormat: PageFormat;
  312. public PageBackgroundColor: string; // vexflow-color-string (#FFFFFF). Default undefined/transparent.
  313. public PerformanceMode: boolean;
  314. public RenderSingleHorizontalStaffline: boolean;
  315. public RestoreCursorAfterRerender: boolean;
  316. public StretchLastSystemLine: boolean;
  317. public SpacingBetweenTextLines: number;
  318. public NoteToGraphicalNoteMap: Dictionary<number, GraphicalNote>;
  319. // this is basically a WeakMap, except we save the id in the Note instead of using a WeakMap.
  320. public NoteToGraphicalNoteMapObjectCount: number = 0;
  321. public static FixStafflineBoundingBox: boolean; // TODO temporary workaround
  322. // Playback
  323. public PlayAlreadyStartedNotesFromCursorPosition: boolean = false;
  324. /** The interval between current timer position and note timestamp beyond which notes are not played.
  325. * If you experience notes being skipped during playback, try increasing this interval slightly (e.g. 0.02 -> 0.03).
  326. */
  327. public PlaybackSkipNotesSafetyInterval: number = 0.02;
  328. constructor() {
  329. this.loadDefaultValues();
  330. }
  331. public loadDefaultValues(): void {
  332. // global variables
  333. this.SamplingUnit = EngravingRules.unit * 3;
  334. // mpat specific settings
  335. this.MpatMode = true;
  336. // Page Label Variables
  337. this.SheetTitleHeight = 4.0;
  338. this.SheetSubtitleHeight = 2.0;
  339. this.SheetMinimumDistanceBetweenTitleAndSubtitle = 1.0;
  340. this.SheetComposerHeight = 2.0;
  341. this.SheetAuthorHeight = 2.0;
  342. // Staff sizing Variables
  343. this.CompactMode = false;
  344. this.PagePlacementEnum = PagePlacementEnum.Down;
  345. this.PageHeight = 100001.0;
  346. this.PageTopMargin = 5.0;
  347. this.PageTopMarginNarrow = 0.0; // for compact mode
  348. this.PageBottomMargin = 5.0;
  349. this.PageLeftMargin = 5.0;
  350. this.PageRightMargin = 5.0;
  351. this.TitleTopDistance = 5.0;
  352. this.TitleBottomDistance = 1.0;
  353. this.StaffDistance = 7.0;
  354. this.BetweenStaffDistance = 5.0;
  355. this.MinimumStaffLineDistance = 4.0;
  356. this.MinSkyBottomDistBetweenStaves = 1.0; // default. compacttight mode sets it to 1.0 (as well).
  357. // System Sizing and Label Variables
  358. this.StaffHeight = 4.0;
  359. this.TabStaffInterlineHeight = 1.1111;
  360. this.BetweenStaffLinesDistance = EngravingRules.unit;
  361. this.SystemLeftMargin = 0.0;
  362. this.SystemRightMargin = 0.0;
  363. this.SystemLabelsRightMargin = 2.0;
  364. this.SystemComposerDistance = 2.0;
  365. this.InstrumentLabelTextHeight = 2;
  366. this.MinimumDistanceBetweenSystems = 7.0;
  367. this.MinSkyBottomDistBetweenSystems = 5.0;
  368. this.LastSystemMaxScalingFactor = 1.4;
  369. // autoBeam options
  370. this.AutoBeamNotes = false;
  371. this.AutoBeamOptions = {
  372. beam_middle_rests_only: false,
  373. beam_rests: false,
  374. maintain_stem_directions: false
  375. };
  376. // Beam Sizing Variables
  377. this.BeamWidth = EngravingRules.unit / 2.0;
  378. this.BeamSpaceWidth = EngravingRules.unit / 3.0;
  379. this.BeamForwardLength = 1.25 * EngravingRules.unit;
  380. this.FlatBeams = false;
  381. this.FlatBeamOffset = 20;
  382. this.FlatBeamOffsetPerBeam = 10;
  383. // Beam Sizing Variables
  384. this.ClefLeftMargin = 0.5;
  385. this.ClefRightMargin = 0.75;
  386. this.PercussionOneLineCutoff = 3; // percussion parts with <3 unique note positions rendered on one line
  387. this.PercussionForceVoicesOneLineCutoff = 1;
  388. this.PercussionUseXMLDisplayStep = true;
  389. this.PercussionXMLDisplayStepNoteValueShift = 0;
  390. this.PercussionOneLineXMLDisplayStepOctaveOffset = 0;
  391. this.BetweenKeySymbolsDistance = 0.2;
  392. this.KeyRightMargin = 0.75;
  393. this.RhythmRightMargin = 1.25;
  394. this.ShowRhythmAgainAfterPartEndOrFinalBarline = true;
  395. this.NewPartAndSystemAfterFinalBarline = false;
  396. this.InStaffClefScalingFactor = 0.8;
  397. this.DistanceBetweenNaturalAndSymbolWhenCancelling = 0.4;
  398. // Beam Sizing Variables
  399. this.NoteHelperLinesOffset = 0.25;
  400. this.MeasureLeftMargin = 0.7;
  401. this.MeasureRightMargin = 0.0;
  402. this.DistanceBetweenLastInstructionAndRepetitionBarline = 1.0;
  403. this.ArpeggioDistance = 0.6;
  404. // Stems Variables
  405. this.StaccatoShorteningFactor = 2;
  406. this.IdealStemLength = 3.0;
  407. this.StemNoteHeadBorderYOffset = 0.2;
  408. this.StemMargin = 0.2;
  409. this.StemMinLength = 2.5;
  410. this.StemMaxLength = 4.5;
  411. this.BeamSlopeMaxAngle = 10.0;
  412. this.StemMinAllowedDistanceBetweenNoteHeadAndBeamLine = 1.0;
  413. this.SetWantedStemDirectionByXml = true;
  414. // also see stemwidth further below
  415. // GraceNote Variables
  416. this.GraceNoteScalingFactor = 0.6;
  417. this.GraceNoteXOffset = 0.2;
  418. // Wedge Variables
  419. this.WedgeOpeningLength = 1.2;
  420. this.WedgeMeasureEndOpeningLength = 0.75;
  421. this.WedgeMeasureBeginOpeningLength = 0.75;
  422. this.WedgePlacementAboveY = -1.5;
  423. this.WedgePlacementBelowY = 1.5;
  424. this.WedgeHorizontalMargin = 0.6;
  425. this.WedgeVerticalMargin = 0.5;
  426. this.DistanceOffsetBetweenTwoHorizontallyCrossedWedges = 0.3;
  427. this.WedgeMinLength = 2.0;
  428. this.WedgeEndDistanceBetweenTimestampsFactor = 1.75;
  429. this.DistanceBetweenAdjacentDynamics = 0.75;
  430. // Tempo Variables
  431. this.TempoChangeMeasureValidity = 4;
  432. this.TempoContinousFactor = 0.7;
  433. // various
  434. this.StaccatoScalingFactor = 0.8;
  435. this.BetweenDotsDistance = 0.8;
  436. this.OrnamentAccidentalScalingFactor = 0.65;
  437. this.ChordSymbolTextHeight = 2.0;
  438. this.ChordSymbolTextAlignment = TextAlignmentEnum.LeftBottom;
  439. this.ChordSymbolRelativeXOffset = -1.0;
  440. this.ChordSymbolXSpacing = 1.0;
  441. this.ChordOverlapAllowedIntoNextMeasure = 0;
  442. this.ChordSymbolYOffset = 0.1;
  443. this.ChordSymbolYPadding = 0.0;
  444. this.ChordSymbolYAlignment = true;
  445. this.ChordSymbolYAlignmentScope = "staffline"; // "measure" or "staffline"
  446. this.ChordSymbolLabelTexts = new Dictionary<ChordSymbolEnum, string>();
  447. this.resetChordSymbolLabelTexts(this.ChordSymbolLabelTexts);
  448. this.CustomChords = [];
  449. this.resetChordNames();
  450. this.RepetitionSymbolsYOffset = 0;
  451. this.RehearsalMarkXOffsetDefault = 10; // avoid collision with metronome number
  452. this.RehearsalMarkXOffset = 0; // user defined
  453. this.RehearsalMarkXOffsetSystemStartMeasure = -20; // good test: Haydn Concertante
  454. this.RehearsalMarkYOffsetDefault = -15;
  455. this.RehearsalMarkYOffset = 0; // user defined
  456. this.RehearsalMarkFontSize = 10; // vexflow default: 12, too big with chord symbols
  457. // Tuplets, MeasureNumber and TupletNumber Labels
  458. this.MeasureNumberLabelHeight = 1.5 * EngravingRules.unit;
  459. this.MeasureNumberLabelOffset = 2;
  460. this.MeasureNumberLabelXOffset = -0.5;
  461. this.TupletsRatioed = false;
  462. this.TupletsBracketed = false;
  463. this.TripletsBracketed = false; // special setting for triplets, overrides tuplet setting (for triplets only)
  464. this.TupletNumberLabelHeight = 1.5 * EngravingRules.unit;
  465. this.TupletNumberYOffset = 0.5;
  466. this.LabelMarginBorderFactor = 0.1;
  467. this.TupletVerticalLineLength = 0.5;
  468. this.TupletNumbersInTabs = false; // disabled by default, nonstandard in tabs, at least how we show them in non-tabs.
  469. // Slur and Tie variables
  470. this.SlurPlacementFromXML = true;
  471. this.BezierCurveStepSize = 1000;
  472. this.calculateCurveParametersArrays();
  473. this.TieGhostObjectWidth = 0.75;
  474. this.TieYPositionOffsetFactor = 0.3;
  475. this.MinimumNeededXspaceForTieGhostObject = 1.0;
  476. this.TieHeightMinimum = 0.28;
  477. this.TieHeightMaximum = 1.2;
  478. this.TieHeightInterpolationK = 0.0288;
  479. this.TieHeightInterpolationD = 0.136;
  480. this.SlurNoteHeadYOffset = 0.5;
  481. this.SlurStemXOffset = 0.3;
  482. this.SlurSlopeMaxAngle = 15.0;
  483. this.SlurTangentMinAngle = 30.0;
  484. this.SlurTangentMaxAngle = 80.0;
  485. this.SlurHeightFactor = 1; // 1 = 100% (standard height). 2 = 100% flattening of all slurs.
  486. this.SlurHeightFlattenLongSlursFactorByWidth = 0.24; // additional flattening for long slurs the longer they are.
  487. this.SlurHeightFlattenLongSlursFactorByAngle = 0.36; // when one of these factors is high, increasing the other has a very strong effect.
  488. this.SlurHeightFlattenLongSlursCutoffAngle = 47;
  489. this.SlurHeightFlattenLongSlursCutoffWidth = 16; // 15 ~ slur between measure's first notes in 4/4. 14 -> problem with test_slurs_highNotes
  490. this.SlursStartingAtSameStaffEntryYOffset = 0.8;
  491. //Maximum y difference between control points. Forces slurs to have less 'weight' either way in the x direction
  492. this.SlurMaximumYControlPointDistance = undefined;
  493. // Repetitions
  494. this.RepetitionEndingLabelHeight = 2.0;
  495. this.RepetitionEndingLabelXOffset = 0.5;
  496. this.RepetitionEndingLabelYOffset = 0.3;
  497. this.RepetitionEndingLineYLowerOffset = 0.5;
  498. this.RepetitionEndingLineYUpperOffset = 0.3;
  499. this.VoltaOffset = 2.5;
  500. // Lyrics
  501. this.LyricsAlignmentStandard = TextAlignmentEnum.LeftBottom; // CenterBottom and LeftBottom tested, spacing-optimized
  502. this.LyricsHeight = 2.0; // actually size of lyrics
  503. this.LyricsYOffsetToStaffHeight = 0.0; // distance between lyrics and staff. could partly be even lower/dynamic
  504. this.VerticalBetweenLyricsDistance = 0.5;
  505. this.HorizontalBetweenLyricsDistance = 0.2;
  506. this.BetweenSyllableMaximumDistance = 10.0;
  507. this.BetweenSyllableMinimumDistance = 0.5; // + 1.0 for CenterAlignment added in lyrics spacing
  508. this.LyricOverlapAllowedIntoNextMeasure = 3.4; // optimal for dashed last lyric, see Land der Berge
  509. this.MinimumDistanceBetweenDashes = 10;
  510. this.MaximumLyricsElongationFactor = 2.5;
  511. // expressions variables
  512. this.InstantaneousTempoTextHeight = 2.3;
  513. this.ContinuousDynamicTextHeight = 2.3;
  514. this.MoodTextHeight = 2.3;
  515. this.UnknownTextHeight = 2.0;
  516. this.ContinuousTempoTextHeight = 2.3;
  517. this.DynamicExpressionMaxDistance = 2;
  518. this.DynamicExpressionSpacer = 0.5;
  519. // Line Widths
  520. this.VexFlowDefaultNotationFontScale = 39; // scales notes, including rests. default value 39 in Vexflow.
  521. this.VexFlowDefaultTabFontScale = 39;
  522. this.TremoloStrokeScale = 1;
  523. this.TremoloYSpacingScale = 1;
  524. this.StemWidth = 0.15; // originally 0.13. vexflow default 0.15. should probably be adjusted when increasing vexFlowDefaultNotationFontScale,
  525. this.StaffLineWidth = 0.10; // originally 0.12, but this will be pixels in Vexflow (*10).
  526. this.StaffLineColor = undefined; // if undefined, vexflow default (grey). not a width, but affects visual line clarity.
  527. this.LedgerLineWidth = 1; // vexflow units (pixels). if not undefined, the vexflow default will be overwritten
  528. this.LedgerLineStrokeStyle = undefined; // if not undefined, the vexflow default will be overwritten
  529. this.LedgerLineColorDefault = "#000000"; // black, previously grey by default
  530. this.WedgeLineWidth = 0.12;
  531. this.TupletLineWidth = 0.12;
  532. this.LyricUnderscoreLineWidth = 0.12;
  533. this.SystemThinLineWidth = 0.12;
  534. this.SystemBoldLineWidth = EngravingRules.unit / 2.0;
  535. this.SystemRepetitionEndingLineWidth = 0.12;
  536. this.SystemDotWidth = EngravingRules.unit / 2.0;
  537. this.DistanceBetweenVerticalSystemLines = 0.35;
  538. this.DistanceBetweenDotAndLine = 0.7;
  539. this.RepeatEndStartPadding = 2.0; // set to 0.0 to restore old padding/width with :||: measures
  540. this.OctaveShiftLineWidth = 0.12;
  541. this.OctaveShiftVerticalLineLength = EngravingRules.unit;
  542. this.GraceLineWidth = this.StaffLineWidth * this.GraceNoteScalingFactor;
  543. this.MultipleRestMeasureDefaultWidth = 4;
  544. // Line Widths
  545. this.MinimumCrossedBeamDifferenceMargin = 0.0001;
  546. // xSpacing Variables
  547. this.VoiceSpacingMultiplierVexflow = 0.85;
  548. this.VoiceSpacingAddendVexflow = 3.0;
  549. this.PickupMeasureWidthMultiplier = 1.0;
  550. this.DisplacedNoteMargin = 0.1;
  551. this.MinNoteDistance = 2.0;
  552. this.SubMeasureXSpacingThreshold = 35;
  553. this.MeasureDynamicsMaxScalingFactor = 2.5;
  554. this.WholeRestXShiftVexflow = -1.5; // VexFlow draws rest notes too far to the right
  555. this.MetronomeMarksDrawn = true;
  556. this.MetronomeMarkXShift = -6; // our unit, is taken * unitInPixels
  557. this.MetronomeMarkYShift = -0.5;
  558. this.SoftmaxFactorVexFlow = 15; // only applies to Vexflow 3.x. 15 seems like the sweet spot. Vexflow default is 100.
  559. // if too high, score gets too big, especially half notes. with half note quarter quarter, the quarters get squeezed.
  560. // if too low, smaller notes aren't positioned correctly.
  561. this.StaggerSameWholeNotes = true;
  562. // Render options (whether to render specific or invisible elements)
  563. this.AlignRests = AlignRestOption.Never; // 0 = false, 1 = true, 2 = auto
  564. this.RestCollisionYPadding = 0.0; // 1.0 = half distance between staff lines (e.g. E to F). will be rounded to whole numbers.
  565. this.FillEmptyMeasuresWithWholeRest = FillEmptyMeasuresWithWholeRests.No;
  566. this.ArpeggiosGoAcrossVoices = false; // safe option, as otherwise arpeggios will always go across all voices in Vexflow, which is often unwanted
  567. this.RenderArpeggios = true;
  568. this.RenderSlurs = true;
  569. this.ColoringMode = ColoringMode.XML;
  570. this.ColoringEnabled = true;
  571. this.ColorStemsLikeNoteheads = false;
  572. this.ColorBeams = true;
  573. this.ColorFlags = true;
  574. this.DefaultColorNotehead = "#000000"; // black. undefined is only black if a note's color hasn't been changed before.
  575. this.DefaultColorRest = this.DefaultColorNotehead;
  576. this.DefaultColorStem = this.DefaultColorNotehead;
  577. this.DefaultColorLabel = this.DefaultColorNotehead;
  578. this.DefaultColorTitle = this.DefaultColorNotehead;
  579. this.DefaultColorCursor = "#33e02f"; // green
  580. this.DefaultFontFamily = "Times New Roman"; // what OSMD was initially optimized for
  581. this.DefaultFontStyle = FontStyles.Regular;
  582. this.DefaultVexFlowNoteFont = "gonville"; // was the default vexflow font up to vexflow 1.2.93, now it's Bravura, which is more cursive/bold
  583. this.MaxMeasureToDrawIndex = Number.MAX_VALUE;
  584. this.MinMeasureToDrawIndex = 0;
  585. this.MaxSystemToDrawNumber = Number.MAX_VALUE;
  586. this.MaxPageToDrawNumber = Number.MAX_VALUE;
  587. this.RenderComposer = true;
  588. this.RenderTitle = true;
  589. this.RenderSubtitle = true;
  590. this.RenderLyricist = true;
  591. this.RenderPartNames = true;
  592. this.RenderPartAbbreviations = true;
  593. this.RenderFingerings = true;
  594. this.RenderMeasureNumbers = true;
  595. this.RenderMeasureNumbersOnlyAtSystemStart = false;
  596. this.UseXMLMeasureNumbers = true;
  597. this.RenderLyrics = true;
  598. this.RenderChordSymbols = true;
  599. this.RenderMultipleRestMeasures = true;
  600. this.AutoGenerateMutipleRestMeasuresFromRestMeasures = true;
  601. this.RenderRehearsalMarks = true;
  602. this.RenderKeySignatures = true;
  603. this.RenderTimeSignatures = true;
  604. this.ArticulationPlacementFromXML = true;
  605. this.FingeringPosition = PlacementEnum.AboveOrBelow; // AboveOrBelow = correct bounding boxes
  606. this.FingeringPositionFromXML = true;
  607. this.FingeringPositionGrace = PlacementEnum.Left;
  608. this.FingeringInsideStafflines = false;
  609. this.FingeringLabelFontHeight = 1.7;
  610. this.FingeringOffsetX = 0.0;
  611. this.FingeringOffsetY = 0.0;
  612. this.FingeringPaddingY = -0.2;
  613. this.FingeringTextSize = 1.5;
  614. this.RenderStringNumbersClassical = true;
  615. this.StringNumberOffsetY = 0.0;
  616. this.NewSystemAtXMLNewSystemAttribute = false;
  617. this.NewPageAtXMLNewPageAttribute = false;
  618. this.RestoreCursorAfterRerender = true;
  619. this.StretchLastSystemLine = false;
  620. EngravingRules.FixStafflineBoundingBox = false; // TODO temporary workaround
  621. this.PageFormat = PageFormat.UndefinedPageFormat; // default: undefined / 'infinite' height page, using the canvas'/container's width and height
  622. this.PageBackgroundColor = undefined; // default: transparent. half-transparent white: #FFFFFF88"
  623. this.PerformanceMode = false;
  624. this.RenderSingleHorizontalStaffline = false;
  625. this.SpacingBetweenTextLines = 0;
  626. this.NoteToGraphicalNoteMap = new Dictionary<number, GraphicalNote>();
  627. this.NoteToGraphicalNoteMapObjectCount = 0;
  628. // this.populateDictionaries(); // these values aren't used currently
  629. try {
  630. this.MaxInstructionsConstValue = this.ClefLeftMargin + this.ClefRightMargin + this.KeyRightMargin + this.RhythmRightMargin + 11;
  631. //if (FontInfo.Info) {
  632. // this.maxInstructionsConstValue += FontInfo.Info.getBoundingBox(MusicSymbol.G_CLEF).width
  633. // + FontInfo.Info.getBoundingBox(MusicSymbol.FOUR).width
  634. // + 7 * FontInfo.Info.getBoundingBox(MusicSymbol.SHARP).width;
  635. //}
  636. } catch (ex) {
  637. log.info("EngravingRules()", ex);
  638. }
  639. // collect mpat-specific changes at the end
  640. if (this.MpatMode) {
  641. this.NewPartAndSystemAfterFinalBarline = true;
  642. }
  643. }
  644. public addGraphicalNoteToNoteMap(note: Note, graphicalNote: GraphicalNote): void {
  645. note.NoteToGraphicalNoteObjectId = this.NoteToGraphicalNoteMapObjectCount;
  646. this.NoteToGraphicalNoteMap.setValue(note.NoteToGraphicalNoteObjectId, graphicalNote);
  647. this.NoteToGraphicalNoteMapObjectCount++;
  648. }
  649. /** Returns the GraphicalNote corresponding to (its) note. Also used by Cursor.GNotesUnderCursor().
  650. * We don't want to save a GraphicalNote reference in Note, see Note.NoteToGraphicalNoteObjectId.
  651. */
  652. public GNote(note: Note): GraphicalNote {
  653. return GraphicalNote.FromNote(note, this);
  654. }
  655. /** This should be done before a new sheet is loaded, not each re-render (otherwise the map would end empty). */
  656. public clearMusicSheetObjects(): void {
  657. this.NoteToGraphicalNoteMap = new Dictionary<number, GraphicalNote>();
  658. this.NoteToGraphicalNoteMapObjectCount = 0;
  659. }
  660. public setChordSymbolLabelText(key: ChordSymbolEnum, value: string): void {
  661. this.ChordSymbolLabelTexts.setValue(key, value);
  662. }
  663. public resetChordSymbolLabelTexts(chordtexts: Dictionary<ChordSymbolEnum, string>): Dictionary<ChordSymbolEnum, string> {
  664. chordtexts.setValue(ChordSymbolEnum.minor, "m");
  665. chordtexts.setValue(ChordSymbolEnum.augmented, "aug");
  666. chordtexts.setValue(ChordSymbolEnum.diminished, "dim");
  667. chordtexts.setValue(ChordSymbolEnum.dominant, "7");
  668. chordtexts.setValue(ChordSymbolEnum.majorseventh, "maj7");
  669. chordtexts.setValue(ChordSymbolEnum.minorseventh, "m7");
  670. chordtexts.setValue(ChordSymbolEnum.diminishedseventh, "dim7");
  671. chordtexts.setValue(ChordSymbolEnum.augmentedseventh, "aug7");
  672. chordtexts.setValue(ChordSymbolEnum.halfdiminished, "m7b5");
  673. chordtexts.setValue(ChordSymbolEnum.majorminor, "m(maj7)");
  674. chordtexts.setValue(ChordSymbolEnum.majorsixth, "maj6");
  675. chordtexts.setValue(ChordSymbolEnum.minorsixth, "m6");
  676. chordtexts.setValue(ChordSymbolEnum.dominantninth, "9");
  677. chordtexts.setValue(ChordSymbolEnum.majorninth, "maj9");
  678. chordtexts.setValue(ChordSymbolEnum.minorninth, "m9");
  679. chordtexts.setValue(ChordSymbolEnum.dominant11th, "11");
  680. chordtexts.setValue(ChordSymbolEnum.major11th, "maj11");
  681. chordtexts.setValue(ChordSymbolEnum.minor11th, "m11");
  682. chordtexts.setValue(ChordSymbolEnum.dominant13th, "13");
  683. chordtexts.setValue(ChordSymbolEnum.major13th, "maj13");
  684. chordtexts.setValue(ChordSymbolEnum.minor13th, "m13");
  685. chordtexts.setValue(ChordSymbolEnum.suspendedsecond, "sus2");
  686. chordtexts.setValue(ChordSymbolEnum.suspendedfourth, "sus4");
  687. chordtexts.setValue(ChordSymbolEnum.power, "5");
  688. chordtexts.setValue(ChordSymbolEnum.none, "N.C.");
  689. return chordtexts;
  690. }
  691. public addChordName(
  692. altName: string,
  693. chordKindText: string,
  694. adds: string[],
  695. alts: string[],
  696. subs: string[],
  697. ): void {
  698. if (ChordSymbolEnum[chordKindText] !== undefined) {
  699. const degrees: DegreesInfo = {
  700. adds,
  701. alts,
  702. subs,
  703. };
  704. this.CustomChords.push(CustomChord.createCustomChord(altName, ChordSymbolEnum[chordKindText], degrees));
  705. }
  706. }
  707. public renameChord(altName: string, newAltName: string): void {
  708. CustomChord.renameCustomChord(altName, newAltName, this.CustomChords);
  709. }
  710. public resetChordNames(): void {
  711. // addChordName(alternateName, chordKindText, adds, alters, subtracts)
  712. this.addChordName("alt", "major", ["#5", "b9", "#9"], ["b5"], []);
  713. this.addChordName("7alt", "dominant", ["#5", "b9", "#9"], ["b5"], []);
  714. this.addChordName("7sus4", "dominant", ["4"], [], ["3"]);
  715. this.addChordName("7sus4", "suspendedfourth", ["7"], [], []);
  716. this.addChordName("9sus4", "dominantninth", ["4"], [], ["3"]);
  717. this.addChordName("9sus4", "suspendedfourth", ["9"], [], []);
  718. this.addChordName("11sus4", "dominant11th", ["4"], [], ["3"]);
  719. this.addChordName("11sus4", "suspendedfourth", ["11"], [], []);
  720. this.addChordName("13sus4", "dominant13th", ["4"], [], ["3"]);
  721. this.addChordName("13sus4", "suspendedfourth", ["13"], [], []);
  722. this.addChordName("7sus2", "dominant", ["2"], [], ["3"]);
  723. this.addChordName("7sus2", "suspendedsecond", ["7"], [], []);
  724. this.addChordName("m7b5", "minorseventh", [], ["b5"], []);
  725. this.addChordName("9sus2", "dominantninth", ["2"], [], ["3"]);
  726. this.addChordName("9sus2", "suspendedsecond", ["9"], [], []);
  727. this.addChordName("11sus2", "dominant11th", ["2"], [], ["3"]);
  728. this.addChordName("11sus2", "suspendedsecond", ["11"], [], []);
  729. this.addChordName("13sus2", "dominant13th", ["2"], [], ["3"]);
  730. this.addChordName("13sus2", "suspendedsecond", ["13"], [], []);
  731. this.addChordName("m(maj9)", "majorminor", ["9"], [], []);
  732. this.addChordName("m(maj11)", "majorminor", ["11"], [], []);
  733. this.addChordName("m(maj13)", "majorminor", ["13"], [], []);
  734. this.addChordName("69", "majorsixth", ["9"], [], []);
  735. this.addChordName("mi69", "minorsixth", ["9"], [], []);
  736. }
  737. /**
  738. * This method maps NoteDurations to Distances and DistancesScalingFactors.
  739. */
  740. // private populateDictionaries(): void {
  741. // for (let i: number = 0; i < this.NoteDistances.length; i++) {
  742. // switch (i) {
  743. // case 0:
  744. // this.DurationDistanceDict[0.015625] = this.NoteDistances[i];
  745. // this.DurationScalingDistanceDict[0.015625] = this.NoteDistancesScalingFactors[i];
  746. // break;
  747. // case 1:
  748. // this.DurationDistanceDict[0.03125] = this.NoteDistances[i];
  749. // this.DurationScalingDistanceDict[0.03125] = this.NoteDistancesScalingFactors[i];
  750. // break;
  751. // case 2:
  752. // this.DurationDistanceDict[0.0625] = this.NoteDistances[i];
  753. // this.DurationScalingDistanceDict[0.0625] = this.NoteDistancesScalingFactors[i];
  754. // break;
  755. // case 3:
  756. // this.DurationDistanceDict[0.125] = this.NoteDistances[i];
  757. // this.DurationScalingDistanceDict[0.125] = this.NoteDistancesScalingFactors[i];
  758. // break;
  759. // case 4:
  760. // this.DurationDistanceDict[0.25] = this.NoteDistances[i];
  761. // this.DurationScalingDistanceDict[0.25] = this.NoteDistancesScalingFactors[i];
  762. // break;
  763. // case 5:
  764. // this.DurationDistanceDict[0.5] = this.NoteDistances[i];
  765. // this.DurationScalingDistanceDict[0.5] = this.NoteDistancesScalingFactors[i];
  766. // break;
  767. // case 6:
  768. // this.DurationDistanceDict[1.0] = this.NoteDistances[i];
  769. // this.DurationScalingDistanceDict[1.0] = this.NoteDistancesScalingFactors[i];
  770. // break;
  771. // case 7:
  772. // this.DurationDistanceDict[2.0] = this.NoteDistances[i];
  773. // this.DurationScalingDistanceDict[2.0] = this.NoteDistancesScalingFactors[i];
  774. // break;
  775. // default:
  776. // // FIXME
  777. // }
  778. // }
  779. // }
  780. /**
  781. * Calculate Curve-independend factors, to be used later in the Slur- and TieCurvePoints calculation
  782. */
  783. private calculateCurveParametersArrays(): void {
  784. this.TPower3 = new Array(this.BezierCurveStepSize);
  785. this.OneMinusTPower3 = new Array(this.BezierCurveStepSize);
  786. this.FactorOne = new Array(this.BezierCurveStepSize);
  787. this.FactorTwo = new Array(this.BezierCurveStepSize);
  788. for (let i: number = 0; i < this.BezierCurveStepSize; i++) {
  789. const t: number = i / this.BezierCurveStepSize;
  790. this.TPower3[i] = Math.pow(t, 3);
  791. this.OneMinusTPower3[i] = Math.pow((1 - t), 3);
  792. this.FactorOne[i] = 3 * Math.pow((1 - t), 2) * t;
  793. this.FactorTwo[i] = 3 * (1 - t) * Math.pow(t, 2);
  794. }
  795. }
  796. }
  797. // TODO maybe this should be moved to OSMDOptions. Also see OpenSheetMusicDisplay.PageFormatStandards
  798. export class PageFormat {
  799. constructor(width: number, height: number, idString: string = "noIdStringGiven") {
  800. this.width = width;
  801. this.height = height;
  802. this.idString = idString;
  803. }
  804. public width: number;
  805. public height: number;
  806. public idString: string;
  807. public get aspectRatio(): number {
  808. if (!this.IsUndefined) {
  809. return this.width / this.height;
  810. } else {
  811. return 0; // infinite page height
  812. }
  813. }
  814. /** Undefined page format: use default page format. */
  815. public get IsUndefined(): boolean {
  816. return this.width === undefined || this.height === undefined || this.height === 0 || this.width === 0;
  817. }
  818. public static get UndefinedPageFormat(): PageFormat {
  819. return new PageFormat(0, 0);
  820. }
  821. public Equals(otherPageFormat: PageFormat): boolean {
  822. if (!otherPageFormat) {
  823. return false;
  824. }
  825. return otherPageFormat.width === this.width && otherPageFormat.height === this.height;
  826. }
  827. }