GraphicalLyricEntry.ts 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import {LyricsEntry} from "../VoiceData/Lyrics/LyricsEntry";
  2. import {GraphicalLyricWord} from "./GraphicalLyricWord";
  3. import {GraphicalLabel} from "./GraphicalLabel";
  4. import {GraphicalStaffEntry} from "./GraphicalStaffEntry";
  5. import {Label} from "../Label";
  6. import {PointF2D} from "../../Common/DataObjects/PointF2D";
  7. import { EngravingRules } from "./EngravingRules";
  8. import { TextAlignmentEnum } from "../../Common/Enums/TextAlignment";
  9. /**
  10. * The graphical counterpart of a [[LyricsEntry]]
  11. */
  12. export class GraphicalLyricEntry {
  13. private lyricsEntry: LyricsEntry;
  14. private graphicalLyricWord: GraphicalLyricWord;
  15. private graphicalLabel: GraphicalLabel;
  16. private graphicalStaffEntry: GraphicalStaffEntry;
  17. constructor(lyricsEntry: LyricsEntry, graphicalStaffEntry: GraphicalStaffEntry, lyricsHeight: number, staffHeight: number) {
  18. this.lyricsEntry = lyricsEntry;
  19. this.graphicalStaffEntry = graphicalStaffEntry;
  20. const lyricsTextAlignment: TextAlignmentEnum = EngravingRules.Rules.LyricsAlignmentStandard;
  21. // for small notes with long text, use center alignment
  22. // TODO use this, fix center+left alignment combination spacing
  23. if (lyricsEntry.Text.length >= 4
  24. && lyricsEntry.Parent.Notes[0].Length.Denominator > 4
  25. && lyricsTextAlignment === TextAlignmentEnum.LeftBottom) {
  26. // lyricsTextAlignment = TextAlignmentAndPlacement.CenterBottom;
  27. }
  28. this.graphicalLabel = new GraphicalLabel(
  29. new Label(lyricsEntry.Text),
  30. lyricsHeight,
  31. lyricsTextAlignment,
  32. graphicalStaffEntry.PositionAndShape
  33. );
  34. this.graphicalLabel.PositionAndShape.RelativePosition = new PointF2D(0, staffHeight);
  35. if (lyricsTextAlignment === TextAlignmentEnum.LeftBottom) {
  36. this.graphicalLabel.PositionAndShape.RelativePosition.x -= 1; // make lyrics optically left-aligned
  37. }
  38. }
  39. public get LyricsEntry(): LyricsEntry {
  40. return this.lyricsEntry;
  41. }
  42. public get ParentLyricWord(): GraphicalLyricWord {
  43. return this.graphicalLyricWord;
  44. }
  45. public set ParentLyricWord(value: GraphicalLyricWord) {
  46. this.graphicalLyricWord = value;
  47. }
  48. public get GraphicalLabel(): GraphicalLabel {
  49. return this.graphicalLabel;
  50. }
  51. public set GraphicalLabel(value: GraphicalLabel) {
  52. this.graphicalLabel = value;
  53. }
  54. public get StaffEntryParent(): GraphicalStaffEntry {
  55. return this.graphicalStaffEntry;
  56. }
  57. public set StaffEntryParent(value: GraphicalStaffEntry) {
  58. this.graphicalStaffEntry = value;
  59. }
  60. }