Skip to content

Commit 75400fa

Browse files
committed
Remove SPATIUM20 variable
This is another variable that has never made any sense to me whatsoever. I can only infer from the way it was used that it was meant to represent the default value of spatium in pixel units. But if that's the case, the way in which it was defined made no sense at all. DPI / 72 used to just be equal to DPI_F, so SPATIUM20 was equal to 5 * DPI_F = 25. To me, the only reason why this seemed to work correctly as the default spatium value is that it just happened to be close to 24.8, which was the actual value. This commit removes SPATIUM20 and replaces it with appropriate calls to the style defaults. In a couple of places (namely StaffType and EngravingFont) the Score and the corresponding Style haven't been created yet, so they need to access the StyleDef class directly. In fact I don't see what StyleDef should make its members private. I think they can be public cause they are const so they can't be changed.
1 parent d206e09 commit 75400fa

File tree

22 files changed

+95
-55
lines changed

22 files changed

+95
-55
lines changed

src/engraving/dom/bend.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ Font Bend::font(double sp) const
9595
f.setUnderline(m_fontStyle & FontStyle::Underline);
9696
f.setStrike(m_fontStyle & FontStyle::Strike);
9797
double m = m_fontSize;
98-
m *= sp / SPATIUM20;
98+
m *= sp / defaultSpatium();
9999

100100
f.setPointSizeF(m);
101101
return f;

src/engraving/dom/engravingitem.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,11 @@ double EngravingItem::spatium() const
264264
return s ? s->spatium(this) : style().spatium();
265265
}
266266

267+
double EngravingItem::defaultSpatium() const
268+
{
269+
return style().defaultSpatium();
270+
}
271+
267272
bool EngravingItem::isInteractionAvailable() const
268273
{
269274
if (!getProperty(Pid::VISIBLE).toBool() && (score()->printing() || !score()->isShowInvisible())) {
@@ -293,7 +298,7 @@ PlacementV EngravingItem::placement() const
293298

294299
double EngravingItem::magS() const
295300
{
296-
return mag() * (style().spatium() / SPATIUM20);
301+
return mag() * (style().spatium() / defaultSpatium());
297302
}
298303

299304
//---------------------------------------------------------

src/engraving/dom/engravingitem.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ class EngravingItem : public EngravingObject
189189
virtual bool isEngravingItem() const override { return true; }
190190

191191
double spatium() const;
192+
double defaultSpatium() const;
192193

193194
inline void setFlag(ElementFlag f, bool v)
194195
{

src/engraving/dom/indicatoricon.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Font IndicatorIcon::font() const
3737
{
3838
Font font(configuration()->iconsFontFamily(), Font::Type::Icon);
3939
static constexpr double STANDARD_POINT_SIZE = 12.0;
40-
const double scaling = spatium() / SPATIUM20;
40+
const double scaling = spatium() / defaultSpatium();
4141
font.setPointSizeF(STANDARD_POINT_SIZE * scaling);
4242
return font;
4343
}

src/engraving/dom/layoutbreak.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ Font LayoutBreak::font() const
260260
{
261261
Font font(configuration()->iconsFontFamily(), Font::Type::Icon);
262262
static constexpr double STANDARD_POINT_SIZE = 12.0;
263-
double scaling = spatium() / SPATIUM20;
263+
double scaling = spatium() / defaultSpatium();
264264
font.setPointSizeF(STANDARD_POINT_SIZE * scaling);
265265
return font;
266266
}

src/engraving/dom/mscore.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ static constexpr double INCH = 25.4; // millimitres per inch
6868
static constexpr double PPI = 72.0; // typographical points per inch
6969

7070
static constexpr double DPI = 1200;
71-
static constexpr double SPATIUM20 = 5.0 * (DPI / 72.0);
7271
static constexpr double DPMM = DPI / INCH;
7372

7473
// NOTE: the SMuFL default is actually 20pt. We use 10 for historical reasons

src/engraving/dom/score.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,7 +1382,7 @@ void Score::spatiumChanged(double oldValue, double newValue)
13821382
for (Staff* staff : m_staves) {
13831383
staff->spatiumChanged(oldValue, newValue);
13841384
}
1385-
m_layoutOptions.noteHeadWidth = m_engravingFont->width(SymId::noteheadBlack, newValue / SPATIUM20);
1385+
m_layoutOptions.noteHeadWidth = m_engravingFont->width(SymId::noteheadBlack, newValue / style().defaultSpatium());
13861386
createPaddingTable();
13871387
}
13881388

@@ -5997,7 +5997,7 @@ void Score::doLayoutRange(const Fraction& st, const Fraction& et)
59975997
}
59985998

59995999
m_engravingFont = engravingFonts()->fontByName(style().value(Sid::musicalSymbolFont).value<String>().toStdString());
6000-
m_layoutOptions.noteHeadWidth = m_engravingFont->width(SymId::noteheadBlack, style().spatium() / SPATIUM20);
6000+
m_layoutOptions.noteHeadWidth = m_engravingFont->width(SymId::noteheadBlack, style().spatium() / style().defaultSpatium());
60016001

60026002
if (this->cmdState().layoutFlags & LayoutFlag::REBUILD_MIDI_MAPPING) {
60036003
if (this->isMaster()) {

src/engraving/dom/stafftype.cpp

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ void StaffType::setDurationMetrics()
441441
RectF bb(fm.tightBoundingRect(txt));
442442
// raise symbols by a default margin and, if marks are above lines, by half the line distance
443443
// (converted from spatium units to raster units)
444-
m_durationGridYOffset = (TAB_DEFAULT_DUR_YOFFS - (m_onLines ? 0.0 : lineDistance().val() * 0.5)) * SPATIUM20;
444+
m_durationGridYOffset = (TAB_DEFAULT_DUR_YOFFS - (m_onLines ? 0.0 : lineDistance().val() * 0.5)) * defaultSpatium();
445445
// this is the bottomest point of any duration sign
446446
m_durationYOffset = m_durationGridYOffset;
447447
// move symbols so that the lowest margin 'sits' on the base line:
@@ -480,12 +480,12 @@ void StaffType::setFretMetrics()
480480

481481
// Calculate position for dead fret marks - these must be centred separately based on their glyph
482482
RectF deadBb = fm.tightBoundingRect(m_fretFontInfo.xChar);
483-
double lineThickness = style().styleS(Sid::staffLineWidth).val() * SPATIUM20 * 0.5;
483+
double lineThickness = style().styleS(Sid::staffLineWidth).val() * defaultSpatium() * 0.5;
484484
m_deadFretYOffset = -deadBb.y() / 2.0 + lineThickness;
485485

486486
// if on string, we are done; if between strings, raise by half line distance
487487
if (!m_onLines) {
488-
double lineAdj = lineDistance().val() * SPATIUM20 * 0.5;
488+
double lineAdj = lineDistance().val() * defaultSpatium() * 0.5;
489489
m_fretYOffset -= lineAdj;
490490
m_deadFretYOffset -= lineAdj;
491491
}
@@ -522,6 +522,11 @@ void StaffType::setDurationFontName(const String& name)
522522
// durationBoxH / durationBoxY
523523
//---------------------------------------------------------
524524

525+
double StaffType::defaultSpatium() const
526+
{
527+
return StyleDef::styleValues[static_cast<size_t>(Sid::spatium)].defaultValue().toDouble();
528+
}
529+
525530
double StaffType::durationBoxH() const
526531
{
527532
if (!m_genDurations && !m_stemless) {
@@ -535,7 +540,37 @@ double StaffType::durationBoxY() const
535540
if (!m_genDurations && !m_stemless) {
536541
return 0.0;
537542
}
538-
return m_durationBoxY + m_durationFontUserY * SPATIUM20;
543+
return m_durationBoxY + m_durationFontUserY * defaultSpatium();
544+
}
545+
546+
double StaffType::durationFontYOffset() const
547+
{
548+
return m_durationYOffset + m_durationFontUserY * defaultSpatium();
549+
}
550+
551+
double StaffType::fretBoxY() const
552+
{
553+
return m_fretBoxY + m_fretFontUserY * defaultSpatium();
554+
}
555+
556+
double StaffType::deadFretBoxY() const
557+
{
558+
return m_deadFretBoxY + m_fretFontUserY * defaultSpatium();
559+
}
560+
561+
double StaffType::fretMaskH() const
562+
{
563+
return m_lineDistance.val() * defaultSpatium();
564+
}
565+
566+
double StaffType::fretMaskY() const
567+
{
568+
return (m_onLines ? -0.5 : -1.0) * m_lineDistance.val() * defaultSpatium();
569+
}
570+
571+
double StaffType::fretFontYOffset() const
572+
{
573+
return m_fretYOffset + m_fretFontUserY * defaultSpatium();
539574
}
540575

541576
//---------------------------------------------------------
@@ -669,7 +704,7 @@ void StaffType::drawInputStringMarks(Painter* p, int string, const Color& select
669704
static constexpr double LEDGER_LINE_LEFTX = 0.25; // in % of cursor rectangle width
670705
static constexpr double LEDGER_LINE_RIGHTX = 0.75; // in % of cursor rectangle width
671706

672-
double spatium = SPATIUM20;
707+
double spatium = defaultSpatium();
673708
double lineDist = m_lineDistance.val() * spatium;
674709
bool hasFret = false;
675710
String text = tabBassStringPrefix(string, &hasFret);

src/engraving/dom/stafftype.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -258,22 +258,22 @@ class StaffType
258258
const String& durationFontName() const { return m_durationFonts[m_durationFontIdx].displayName; }
259259
double durationFontSize() const { return m_durationFontSize; }
260260
double durationFontUserY() const { return m_durationFontUserY; }
261-
double durationFontYOffset() const { return m_durationYOffset + m_durationFontUserY * SPATIUM20; }
261+
double durationFontYOffset() const;
262262
double durationGridYOffset() const { return m_durationGridYOffset; }
263263
double fretBoxH() const { return m_fretBoxH; }
264264
double deadFretBoxH() const { return m_deadFretBoxH; }
265-
double fretBoxY() const { return m_fretBoxY + m_fretFontUserY * SPATIUM20; }
266-
double deadFretBoxY() const { return m_deadFretBoxY + m_fretFontUserY * SPATIUM20; }
265+
double fretBoxY() const;
266+
double deadFretBoxY() const;
267267

268268
// 2 methods to return the size of a box masking lines under a fret mark
269-
double fretMaskH() const { return m_lineDistance.val() * SPATIUM20; }
270-
double fretMaskY() const { return (m_onLines ? -0.5 : -1.0) * m_lineDistance.val() * SPATIUM20; }
269+
double fretMaskH() const;
270+
double fretMaskY() const;
271271

272272
const muse::draw::Font& fretFont() const { return m_fretFont; }
273273
const String fretFontName() const { return m_fretFontInfo.displayName; }
274274
double fretFontSize() const { return m_fretFontSize; }
275275
double fretFontUserY() const { return m_fretFontUserY; }
276-
double fretFontYOffset() const { return m_fretYOffset + m_fretFontUserY * SPATIUM20; }
276+
double fretFontYOffset() const;
277277
bool genDurations() const { return m_genDurations; }
278278
bool linesThrough() const { return m_linesThrough; }
279279
TablatureMinimStyle minimStyle() const { return m_minimStyle; }
@@ -336,6 +336,7 @@ class StaffType
336336

337337
Score* m_score = nullptr;
338338

339+
double defaultSpatium() const;
339340
void setDurationMetrics();
340341
void setFretMetrics();
341342

src/engraving/dom/textbase.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -898,9 +898,9 @@ Font TextFragment::font(const TextBase* t) const
898898
double spatiumScaling = 0.0;
899899

900900
if (t->isInstrumentName()) {
901-
spatiumScaling = toInstrumentName(t)->largestStaffSpatium() / SPATIUM20;
901+
spatiumScaling = toInstrumentName(t)->largestStaffSpatium() / t->defaultSpatium();
902902
} else {
903-
spatiumScaling = t->spatium() / SPATIUM20;
903+
spatiumScaling = t->spatium() / t->defaultSpatium();
904904
}
905905

906906
if (t->sizeIsSpatiumDependent()) {
@@ -2757,7 +2757,7 @@ Font TextBase::font() const
27572757
{
27582758
double m = size();
27592759
if (sizeIsSpatiumDependent()) {
2760-
m *= spatium() / SPATIUM20;
2760+
m *= spatium() / defaultSpatium();
27612761
}
27622762
Font f(family(), Font::Type::Unknown);
27632763
f.setPointSizeF(m);

0 commit comments

Comments
 (0)