Skip to content

Commit

Permalink
fix #137101: When changing score font, MuseScore should obey engravin…
Browse files Browse the repository at this point in the history
…g defaults provided by the font metadata
  • Loading branch information
lasconic committed Oct 12, 2016
1 parent 6467261 commit cc0333c
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 42 deletions.
39 changes: 32 additions & 7 deletions fonts/mscore/metadata.json
Expand Up @@ -3,27 +3,52 @@
"fontVersion": 0.1,

"engravingDefaults": {
"tieEndpointThickness": 0.1,
"tieMidpointThickness": 0.22
"arrowShaftThickness": 0.16,
"barlineSeparation": 0.4,
"beamSpacing": 0.25,
"beamThickness": 0.5,
"bracketThickness": 0.45,
"dashedBarlineDashLength": 0.5,
"dashedBarlineGapLength": 0.25,
"dashedBarlineThickness": 0.16,
"hairpinThickness": 0.13,
"legerLineExtension": 0.6,
"legerLineThickness": 0.16,
"lyricLineThickness": 0.1,
"octaveLineThickness": 0.1,
"pedalLineThickness": 0.15,
"repeatBarlineDotSeparation": 0.4,
"repeatEndingLineThickness": 0.1,
"slurEndpointThickness": 0.07,
"slurMidpointThickness": 0.15,
"staffLineThickness": 0.08,
"stemThickness": 0.13,
"subBracketThickness": 0.16,
"textEnclosureThickness": 0.2,
"thickBarlineThickness": 0.5,
"thinBarlineThickness": 0.16,
"tieEndpointThickness": 0.07,
"tieMidpointThickness": 0.15,
"tupletBracketThickness": 0.1
},

"glyphsWithAlternates": {
"6stringTabClef": {
"alternates": [
"alternates": [
{
"codepoint": "U+E1A2",
"codepoint": "U+E1A2",
"name": "6stringTabClefSerif"
}
]
},
"noteheadDoubleWhole": {
"alternates": [
{
"codepoint": "U+E1BA",
"codepoint": "U+E1BA",
"name": "noteheadDoubleWholeAlt"
}
]
}
}
},

"glyphsWithAnchors": {
Expand Down
1 change: 0 additions & 1 deletion libmscore/style.cpp
Expand Up @@ -10,7 +10,6 @@
// the file LICENCE.GPL
//=============================================================================

#include <unordered_map>
#include "mscore.h"
#include "style.h"
#include "xml.h"
Expand Down
38 changes: 37 additions & 1 deletion libmscore/sym.cpp
Expand Up @@ -5896,9 +5896,45 @@ void ScoreFont::load()
}
}
}
oo = metadataJson.value("engravingDefaults").toObject();
static std::list<std::pair<QString, StyleIdx>> engravingDefaultsMapping = {
{ "staffLineThickness", StyleIdx::staffLineWidth },
{ "stemThickness", StyleIdx::stemWidth },
{ "beamThickness", StyleIdx::beamWidth },
{ "beamSpacing", StyleIdx::beamDistance },
{ "legerLineThickness", StyleIdx::ledgerLineWidth },
{ "legerLineExtension", StyleIdx::ledgerLineLength },
{ "slurEndpointThickness", StyleIdx::SlurEndWidth },
{ "slurMidpointThickness", StyleIdx::SlurMidWidth },
{ "thinBarlineThickness", StyleIdx::barWidth },
{ "thinBarlineThickness", StyleIdx::doubleBarWidth },
{ "thickBarlineThickness", StyleIdx::endBarWidth },
{ "dashedBarlineThickness", StyleIdx::barWidth },
{ "barlineSeparation", StyleIdx::doubleBarDistance },
{ "barlineSeparation", StyleIdx::endBarDistance },
{ "repeatBarlineDotSeparation", StyleIdx::repeatBarlineDotSeparation },
{ "bracketThickness", StyleIdx::bracketWidth },
{ "hairpinThickness", StyleIdx::hairpinLineWidth },
{ "octaveLineThickness", StyleIdx::ottavaLineWidth },
{ "pedalLineThickness", StyleIdx::pedalLineWidth },
{ "repeatEndingLineThickness", StyleIdx::voltaLineWidth },
{ "lyricLineThickness", StyleIdx::lyricsLineThickness },
{ "tupletBracketThickness", StyleIdx::tupletBracketWidth }
};
for (auto i : oo.keys()) {
for (auto mapping : engravingDefaultsMapping) {
if (i == mapping.first) {
_engravingDefaults.push_back(std::make_pair(mapping.second, oo.value(i).toDouble()));
break;
}
else if (i == "textEnclosureThickness") {
_textEnclosureThickness = oo.value(i).toDouble();
}
}
}
_engravingDefaults.push_back(std::make_pair(StyleIdx::MusicalTextFont, QString("%1 Text").arg(_family)));

// create missing composed glyphs

struct Composed {
SymId id;
std::vector<SymId> rids;
Expand Down
5 changes: 5 additions & 0 deletions libmscore/sym.h
Expand Up @@ -24,6 +24,7 @@ class QPainter;
namespace Ms {

class TextStyle;
enum class StyleIdx;

//---------------------------------------------------------
// SymId
Expand Down Expand Up @@ -2772,6 +2773,8 @@ class ScoreFont {
QString _filename;
QByteArray fontImage;
QCache<GlyphKey, GlyphPixmap>* cache { 0 };
std::list<std::pair<StyleIdx, QVariant>> _engravingDefaults;
double _textEnclosureThickness = 0;
mutable QFont* font { 0 };

static QVector<ScoreFont> _scoreFonts;
Expand All @@ -2791,6 +2794,8 @@ class ScoreFont {

const QString& name() const { return _name; }
const QString& family() const { return _family; }
std::list<std::pair<StyleIdx, QVariant>> engravingDefaults() { return _engravingDefaults; }
double textEnclosureThickness() { return _textEnclosureThickness; }

QString fontPath() const { return _fontPath; }

Expand Down
19 changes: 19 additions & 0 deletions mscore/editstyle.cpp
Expand Up @@ -724,6 +724,7 @@ void EditStyle::setValues()
}
++idx;
}
musicalTextFont->blockSignals(true);
musicalTextFont->clear();
// CAUTION: the second element, the itemdata, is a font family name!
// It's also stored in score file as the musicalTextFont
Expand All @@ -734,6 +735,7 @@ void EditStyle::setValues()
QString tfont(lstyle.value(StyleIdx::MusicalTextFont).toString());
idx = musicalTextFont->findData(tfont);
musicalTextFont->setCurrentIndex(idx);
musicalTextFont->blockSignals(false);

toggleHeaderOddEven(lstyle.value(StyleIdx::headerOddEven).toBool());

Expand Down Expand Up @@ -912,8 +914,25 @@ void EditStyle::valueChanged(int i)
{
StyleIdx idx = (StyleIdx)i;
QVariant val = getValue(idx);
bool setValue = false;
if (idx == StyleIdx::MusicalSymbolFont && optimizeStyleCheckbox->isChecked()) {
ScoreFont* scoreFont = ScoreFont::fontFactory(val.toString());
if (scoreFont) {
for (auto i : scoreFont->engravingDefaults()) {
cs->undo(new ChangeStyleVal(cs, i.first, i.second));
}
if (scoreFont->textEnclosureThickness()) {
TextStyle ts = cs->textStyle(TextStyleType::REHEARSAL_MARK);
ts.setFrameWidth(Spatium(scoreFont->textEnclosureThickness()));
cs->undo(new ChangeTextStyle(cs, ts));
}
}
setValue = true;
}
cs->undo(new ChangeStyleVal(cs, idx, val));
cs->update();
if (setValue)
setValues();

const StyleWidget& sw = styleWidget(idx);
if (sw.reset)
Expand Down
80 changes: 47 additions & 33 deletions mscore/editstyle.ui
Expand Up @@ -152,6 +152,39 @@
<layout class="QVBoxLayout" name="verticalLayout_6">
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="2">
<widget class="QCheckBox" name="optimizeStyleCheckbox">
<property name="toolTip">
<string>MuseScore will change style to suit the font better</string>
</property>
<property name="text">
<string> use style default settings for the font</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_63">
<property name="text">
<string>Musical symbols font:</string>
</property>
<property name="buddy">
<cstring>musicalSymbolFont</cstring>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Musical text font:</string>
</property>
<property name="buddy">
<cstring>musicalTextFont</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="musicalSymbolFont">
<property name="sizePolicy">
Expand All @@ -177,39 +210,6 @@
</item>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_63">
<property name="text">
<string>Musical symbols font:</string>
</property>
<property name="buddy">
<cstring>musicalSymbolFont</cstring>
</property>
</widget>
</item>
<item row="0" column="2">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Musical text font:</string>
</property>
<property name="buddy">
<cstring>musicalTextFont</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="musicalTextFont">
<item>
Expand All @@ -234,6 +234,19 @@
</item>
</widget>
</item>
<item row="0" column="3">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
Expand Down Expand Up @@ -7730,6 +7743,7 @@
<tabstops>
<tabstop>pageList</tabstop>
<tabstop>musicalSymbolFont</tabstop>
<tabstop>optimizeStyleCheckbox</tabstop>
<tabstop>musicalTextFont</tabstop>
<tabstop>concertPitch</tabstop>
<tabstop>multiMeasureRests</tabstop>
Expand Down

0 comments on commit cc0333c

Please sign in to comment.