Skip to content

Commit

Permalink
fix(BoundingBox): Fix PageTopMargin also partly added to a bottom mar…
Browse files Browse the repository at this point in the history
…gin / container size in certain cases (opensheetmusicdisplay#1245)
  • Loading branch information
sschmidTU committed Sep 30, 2022
1 parent 6e90aa2 commit fa5fa7c
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/MusicalScore/Graphical/MusicSheetCalculator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2120,7 +2120,7 @@ export abstract class MusicSheetCalculator {
firstSystemAbsoluteTopMargin = firstMusicSystem.PositionAndShape.RelativePosition.y + firstMusicSystem.PositionAndShape.BorderTop;
}
//const firstStaffLine: StaffLine = this.graphicalMusicSheet.MusicPages[0].MusicSystems[0].StaffLines[0];
if (this.graphicalMusicSheet.Title) {
if (this.graphicalMusicSheet.Title && this.rules.RenderTitle) {
const title: GraphicalLabel = this.graphicalMusicSheet.Title;
title.PositionAndShape.Parent = page.PositionAndShape;
//title.PositionAndShape.Parent = firstStaffLine.PositionAndShape;
Expand All @@ -2131,7 +2131,7 @@ export abstract class MusicSheetCalculator {
title.PositionAndShape.RelativePosition = relative;
page.Labels.push(title);
}
if (this.graphicalMusicSheet.Subtitle) {
if (this.graphicalMusicSheet.Subtitle && this.rules.RenderTitle && this.rules.RenderSubtitle) {
const subtitle: GraphicalLabel = this.graphicalMusicSheet.Subtitle;
//subtitle.PositionAndShape.Parent = firstStaffLine.PositionAndShape;
subtitle.PositionAndShape.Parent = page.PositionAndShape;
Expand All @@ -2148,7 +2148,7 @@ export abstract class MusicSheetCalculator {
// we don't need a skybottomcalculator currently, labels are put above system skyline anyways.
const composer: GraphicalLabel = this.graphicalMusicSheet.Composer;
let composerRelativeY: number;
if (composer) {
if (composer && this.rules.RenderComposer) {
composer.PositionAndShape.Parent = page.PositionAndShape; // if using pageWidth. (which can currently be too wide) TODO fix pageWidth (#578)
//composer.PositionAndShape.Parent = topStaffline.PositionAndShape; // if using firstStaffLine...width.
// y-collision problems, harder to y-align with lyrics
Expand Down Expand Up @@ -2190,7 +2190,7 @@ export abstract class MusicSheetCalculator {
page.Labels.push(composer);
}
const lyricist: GraphicalLabel = this.graphicalMusicSheet.Lyricist;
if (lyricist) {
if (lyricist && this.rules.RenderLyricist) {
lyricist.PositionAndShape.Parent = page.PositionAndShape;
lyricist.setLabelPositionAndShapeBorders();
const relative: PointF2D = new PointF2D();
Expand Down
5 changes: 5 additions & 0 deletions src/MusicalScore/Graphical/MusicSheetDrawer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,11 @@ export abstract class MusicSheetDrawer {
} else if (type === "VexFlowContinuousDynamicExpression") {
typeMatch = startBox.DataObject instanceof VexFlowContinuousDynamicExpression;
}
// else if (type === "MusicSystem") {
// typeMatch = startBox.DataObject instanceof MusicSystem;
// } else if (type === "GraphicalMusicPage") {
// typeMatch = startBox.DataObject instanceof GraphicalMusicPage;
// }
}
if (typeMatch || dataObjectString === type) {
this.drawBoundingBox(startBox, undefined, true, dataObjectString, layer);
Expand Down
8 changes: 7 additions & 1 deletion src/OpenSheetMusicDisplay/OpenSheetMusicDisplay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,11 +310,17 @@ export class OpenSheetMusicDisplay {
} else {
height = page.PositionAndShape.Size.height;
height += this.rules.PageBottomMargin;
height += this.rules.CompactMode ? this.rules.PageTopMarginNarrow : this.rules.PageTopMargin;
if (backend.getOSMDBackendType() === BackendType.Canvas) {
height += 0.1; // Canvas bug: cuts off bottom pixel with PageBottomMargin = 0. Doesn't happen with SVG.
// we could only add 0.1 if PageBottomMargin === 0, but that would mean a margin of 0.1 has no effect compared to 0.
}
//height += this.rules.CompactMode ? this.rules.PageTopMarginNarrow : this.rules.PageTopMargin;
// adding the PageTopMargin with a composer label leads to the margin also added to the bottom of the page
height += page.PositionAndShape.BorderTop;
// try to respect elements like composer cut off: this gets messy.
// if (page.PositionAndShape.BorderTop < 0 && this.rules.PageTopMargin === 0) {
// height += page.PositionAndShape.BorderTop + this.rules.PageTopMargin;
// }
if (this.rules.RenderTitle) {
height += this.rules.TitleTopDistance;
}
Expand Down
5 changes: 5 additions & 0 deletions test/Util/generateImages_browserless.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,8 @@ async function generateSampleImage (sampleFilename, directory, osmdInstance, osm
const defaultOrCompactTightMode = sampleFilename.startsWith("OSMD_Function_Test_Container_height") ? "compacttight" : "default";
const isTestFlatBeams = sampleFilename.startsWith("test_drum_tuplet_beams");
const isTestEndClefStaffEntryBboxes = sampleFilename.startsWith("test_end_measure_clefs_staffentry_bbox");
const isTestPageBottomMargin0 = sampleFilename.includes("PageBottomMargin0");
osmdInstance.EngravingRules.loadDefaultValues();
if (isTestEndClefStaffEntryBboxes) {
drawBoundingBoxString = "VexFlowStaffEntry";
} else {
Expand Down Expand Up @@ -353,6 +355,9 @@ async function generateSampleImage (sampleFilename, directory, osmdInstance, osm
} else {
osmdInstance.EngravingRules.FlatBeams = false;
}
if (isTestPageBottomMargin0) {
osmdInstance.EngravingRules.PageBottomMargin = 0;
}
}

try {
Expand Down
106 changes: 106 additions & 0 deletions test/data/test_PageBottomMargin0.musicxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE score-partwise PUBLIC "-//Recordare//DTD MusicXML 3.1 Partwise//EN" "http://www.musicxml.org/dtds/partwise.dtd">
<score-partwise version="3.1">
<work>
<work-title>test_PageBottomMargin0</work-title>
</work>
<identification>
<creator type="composer">Composer</creator>
<encoding>
<software>MuseScore 3.6.2</software>
<encoding-date>2022-09-30</encoding-date>
<supports element="accidental" type="yes"/>
<supports element="beam" type="yes"/>
<supports element="print" attribute="new-page" type="yes" value="yes"/>
<supports element="print" attribute="new-system" type="yes" value="yes"/>
<supports element="stem" type="yes"/>
</encoding>
</identification>
<defaults>
<scaling>
<millimeters>6.99911</millimeters>
<tenths>40</tenths>
</scaling>
<page-layout>
<page-height>1596.77</page-height>
<page-width>1233.87</page-width>
<page-margins type="even">
<left-margin>85.7252</left-margin>
<right-margin>85.7252</right-margin>
<top-margin>85.7252</top-margin>
<bottom-margin>85.7252</bottom-margin>
</page-margins>
<page-margins type="odd">
<left-margin>85.7252</left-margin>
<right-margin>85.7252</right-margin>
<top-margin>85.7252</top-margin>
<bottom-margin>85.7252</bottom-margin>
</page-margins>
</page-layout>
<word-font font-family="Edwin" font-size="10"/>
<lyric-font font-family="Edwin" font-size="10"/>
</defaults>
<credit page="1">
<credit-type>title</credit-type>
<credit-words default-x="616.935" default-y="1511.05" justify="center" valign="top" font-size="22">Title</credit-words>
</credit>
<credit page="1">
<credit-type>composer</credit-type>
<credit-words default-x="1148.15" default-y="1411.05" justify="right" valign="bottom">Composer</credit-words>
</credit>
<part-list>
<score-part id="P1">
<part-name>Piano</part-name>
<part-abbreviation>Pno.</part-abbreviation>
<score-instrument id="P1-I1">
<instrument-name>Piano</instrument-name>
</score-instrument>
<midi-device id="P1-I1" port="1"></midi-device>
<midi-instrument id="P1-I1">
<midi-channel>1</midi-channel>
<midi-program>1</midi-program>
<volume>78.7402</volume>
<pan>0</pan>
</midi-instrument>
</score-part>
</part-list>
<part id="P1">
<measure number="1" width="313.47">
<print>
<system-layout>
<system-margins>
<left-margin>50.00</left-margin>
<right-margin>665.23</right-margin>
</system-margins>
<top-system-distance>170.00</top-system-distance>
</system-layout>
</print>
<attributes>
<divisions>1</divisions>
<key>
<fifths>0</fifths>
</key>
<time>
<beats>4</beats>
<beat-type>4</beat-type>
</time>
<clef>
<sign>G</sign>
<line>2</line>
</clef>
</attributes>
<note default-x="84.22" default-y="-80.00">
<pitch>
<step>D</step>
<octave>3</octave>
</pitch>
<duration>4</duration>
<voice>1</voice>
<type>whole</type>
</note>
<barline location="right">
<bar-style>light-heavy</bar-style>
</barline>
</measure>
</part>
</score-partwise>

0 comments on commit fa5fa7c

Please sign in to comment.