LCOV - code coverage report
Current view: top level - src/engraving/editing - autospatium.cpp Coverage Total Hit
Test: filtered_coverage.info Lines: 0.0 % 18 0
Test Date: 2026-11-05 04:07:02

            Line data    Source code
       1              : /*
       2              :  * SPDX-License-Identifier: GPL-3.0-only
       3              :  * MuseScore-Studio-CLA-applies
       4              :  *
       5              :  * MuseScore Studio
       6              :  * Music Composition & Notation
       7              :  *
       8              :  * Copyright (C) 2026 MuseScore Limited
       9              :  *
      10              :  * This program is free software: you can redistribute it and/or modify
      11              :  * it under the terms of the GNU General Public License version 3 as
      12              :  * published by the Free Software Foundation.
      13              :  *
      14              :  * This program is distributed in the hope that it will be useful,
      15              :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      16              :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
      17              :  * GNU General Public License for more details.
      18              :  *
      19              :  * You should have received a copy of the GNU General Public License
      20              :  * along with this program. If not, see <https://www.gnu.org/licenses/>.
      21              :  */
      22              : 
      23              : #include "autospatium.h"
      24              : 
      25              : #include "../dom/measurebase.h"
      26              : #include "../dom/score.h"
      27              : 
      28              : using namespace mu::engraving;
      29              : 
      30              : //--------------------------------------------------------
      31              : // update()
      32              : // Reduces the spatium size as necessary to accommodate all
      33              : // staves in the page. Caution: the spatium is expressed in
      34              : // DPI, page dimensions in inches, staff sizes in mm.
      35              : //--------------------------------------------------------
      36            0 : void AutoSpatium::update(Score* score)
      37              : {
      38              :     static constexpr double breathingSpace = 2.5; // allow breathing space between staves
      39              :     static constexpr double minStaffHeight = 2.0; // never make staff smaller than 2.0 mm
      40              :     static constexpr double maxStaffHeight = 7.0; // never make staff bigger than 7.0 mm (default value)
      41              : 
      42            0 :     const MStyle& style = score->style();
      43            0 :     double availableHeight = (style.styleD(Sid::pageHeight)
      44            0 :                               - style.styleD(Sid::pageOddTopMargin)
      45            0 :                               - style.styleD(Sid::pageOddBottomMargin)) * DPI; // convert from inches to DPI
      46            0 :     double titleHeight = (!score->measures()->empty() && score->measures()->first()->isVBox()) ? score->measures()->first()->height() : 0.0;
      47            0 :     availableHeight -= titleHeight;
      48            0 :     double totalNeededSpaces = 4 * score->nstaves() * breathingSpace;
      49            0 :     double targetSpatium = availableHeight / totalNeededSpaces;
      50              : 
      51            0 :     double resultingStaffHeight = 4 * targetSpatium / DPI * INCH; // conversion from DPI to mm
      52            0 :     resultingStaffHeight = round(resultingStaffHeight * 10) / 10; // round to nearest 0.1 mm
      53            0 :     if (resultingStaffHeight > maxStaffHeight) {
      54            0 :         return;
      55              :     }
      56            0 :     if (resultingStaffHeight < minStaffHeight) {
      57            0 :         resultingStaffHeight = minStaffHeight;
      58              :     }
      59              : 
      60            0 :     targetSpatium = (resultingStaffHeight / 4) * DPI / INCH;
      61              : 
      62            0 :     score->style().setSpatium(targetSpatium);
      63            0 :     score->updatePaddingTables();
      64              : }
        

Generated by: LCOV version 2.0-1