Skip to content

Commit

Permalink
Towards Font Overrides (#6018)
Browse files Browse the repository at this point in the history
The font stylesheets we started allowed us to speficy font objects but not
to override them. This supports that in the skin, although it is still very
incomplete.

But to test it, I made modbutton fonts overridable using the new font
syntax which we are working towards, which Closes #5843
  • Loading branch information
baconpaul authored Apr 5, 2022
1 parent 6c2b352 commit 0d34872
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 9 deletions.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ Released under the OFL

Mrs Beasley Regular: https://fontlibrary.org/en/font/mrs-beasley
Released under the OFL

Playfair Display SC from Google Fonts under OFL
22 changes: 13 additions & 9 deletions resources/data/skins/Tutorials/10 Adding Fonts.surge-skin/skin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@
With surge XT, you can include TTF files in your .skin and use them for various controls.
Put them in the skin/fonts directory and theywill be available!
[doc]-->
<surge-skin name="10 Adding Fonts" category="Tutorials" author="Surge Synth Team" authorURL="https://surge-synth-team.org/" version="2">
<globals>
</globals>
<component-classes>
</component-classes>
<controls>
<control ui_identifier="osc.param_1" font_family="UglyTypist" font_size="13"/>
<control ui_identifier="osc.param_2" font_family="Mrs Beasley"/>
</controls>
<surge-skin name="10 Adding Fonts" category="Tutorials" author="Surge Synth Team"
authorURL="https://surge-synth-team.org/" version="2">
<globals>
<!-- There are global elements for fonts. This is still a work in progress as of surge xt 1.1 but we are slowly adding them as
we approach surge 2.0. For now the modbutton font works this way -->
<font id="fonts.widgets.modbutton" family="PlayfairDisplay" size="8"/>
</globals>
<component-classes>
</component-classes>
<controls>
<control ui_identifier="osc.param_1" font_family="UglyTypist" font_size="13"/>
<control ui_identifier="osc.param_2" font_family="Mrs Beasley"/>
</controls>
</surge-skin>
23 changes: 23 additions & 0 deletions src/surge-xt/gui/SkinSupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,21 @@ bool Skin::reloadSkin(std::shared_ptr<SurgeImageStore> bitmapStore)
colors[id] = ColorStore(val, ColorStore::UNRESOLVED_ALIAS);
}
}
if (g.first == "font")
{
auto p = g.second.props;
auto fo = FontOverride();
if (p.find("family") != p.end())
fo.family = p["family"];
if (p.find("size") != p.end())
fo.size = std::atoi(p["size"].c_str());
if (p.find("id") != p.end())
fontOverrides[p["id"]] = fo;
else
{
FIXMEERROR << "Font without ID ignored ";
}
}

if (g.first == "background" && g.second.props.find("image") != g.second.props.end())
{
Expand Down Expand Up @@ -1084,6 +1099,14 @@ juce::Font Skin::getFont(const Surge::Skin::FontDesc &d)
jassert((int)Surge::Skin::FontDesc::italic == juce::Font::FontStyleFlags::italic);
jassert((int)Surge::Skin::FontDesc::bold == juce::Font::FontStyleFlags::bold);

if (fontOverrides.find(d.id) != fontOverrides.end())
{
auto fo = fontOverrides[d.id];
if (typeFaces.find(fo.family) != typeFaces.end())
return juce::Font(typeFaces[fo.family]).withPointHeight(fo.size);
return juce::Font(fo.family, fo.size, juce::Font::FontStyleFlags::plain);
}

if (d.hasParent)
{
return getFont(d.parent);
Expand Down
7 changes: 7 additions & 0 deletions src/surge-xt/gui/SkinSupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,13 @@ class Skin
juce::Font getFont(const Surge::Skin::FontDesc &d);

private:
struct FontOverride
{
std::string family{"Comic Sans"};
int size{9};
};
std::unordered_map<std::string, FontOverride> fontOverrides;

juce::Colour
getColor(const Surge::Skin::Color &id, const juce::Colour &def,
std::unordered_set<std::string> noLoops = std::unordered_set<std::string>()) const
Expand Down

0 comments on commit 0d34872

Please sign in to comment.