Stylesheets: Take advantage of Font stacking (#5111)

Depends on https://github.com/space-wizards/RobustToolbox/pull/2182
 - Adds Noto Sans Symbols and its sequel, Noto Sans Symbols 2: Revenge
   of the Unicode.
 - Uses a stack of Noto Sans, Symbols, and Symbols 2 in all places where
   Noto Sans/Noto Sans Display are used.

If you _really_ wanted to, you could use this to add Noto Emoji too.

In considering this, please remember that not everything that _can_ be
done, _should_ be done.
This commit is contained in:
E F R
2021-11-04 03:32:03 +00:00
committed by GitHub
parent 6739bbc85b
commit 1b5b32c8a6
7 changed files with 92 additions and 17 deletions

View File

@@ -27,5 +27,23 @@ namespace Content.Client.Resources
{ {
return cache.GetFont(new ResourcePath(path), size); return cache.GetFont(new ResourcePath(path), size);
} }
public static Font GetFont(this IResourceCache cache, ResourcePath[] path, int size)
{
var fs = new Font[path.Length];
for (var i = 0; i < path.Length; i++)
fs[i] = new VectorFont(cache.GetResource<FontResource>(path[i]), size);
return new StackedFont(fs);
}
public static Font GetFont(this IResourceCache cache, string[] path, int size)
{
var rp = new ResourcePath[path.Length];
for (var i = 0; i < path.Length; i++)
rp[i] = new ResourcePath(path[i]);
return cache.GetFont(rp, size);
}
} }
} }

View File

@@ -41,8 +41,26 @@ namespace Content.Client.Stylesheets
protected StyleBase(IResourceCache resCache) protected StyleBase(IResourceCache resCache)
{ {
var notoSans12 = resCache.GetFont("/Fonts/NotoSans/NotoSans-Regular.ttf", 12); var notoSans12 = resCache.GetFont
var notoSans12Italic = resCache.GetFont("/Fonts/NotoSans/NotoSans-Italic.ttf", 12); (
new []
{
"/Fonts/NotoSans/NotoSans-Regular.ttf",
"/Fonts/NotoSans/NotoSansSymbols-Regular.ttf",
"/Fonts/NotoSans/NotoSansSymbols2-Regular.ttf"
},
12
);
var notoSans12Italic = resCache.GetFont
(
new []
{
"/Fonts/NotoSans/NotoSans-Italic.ttf",
"/Fonts/NotoSans/NotoSansSymbols-Regular.ttf",
"/Fonts/NotoSans/NotoSansSymbols2-Regular.ttf"
},
12
);
var textureCloseButton = resCache.GetTexture("/Textures/Interface/Nano/cross.svg.png"); var textureCloseButton = resCache.GetTexture("/Textures/Interface/Nano/cross.svg.png");
// Button styles. // Button styles.

View File

@@ -18,6 +18,27 @@ using static Robust.Client.UserInterface.StylesheetHelpers;
namespace Content.Client.Stylesheets namespace Content.Client.Stylesheets
{ {
public static class ResCacheExtension
{
public static Font notoStack(this IResourceCache resCache, string variation = "Regular", int size = 10, bool display = false)
{
var ds = display ? "Display" : "";
var sv = variation.StartsWith("Bold") ? "Bold" : "Regular";
return resCache.GetFont
(
// Ew, but ok
new []
{
$"/Fonts/NotoSans{ds}/NotoSans{ds}-{variation}.ttf",
$"/Fonts/NotoSans/NotoSansSymbols-{sv}.ttf",
"/Fonts/NotoSans/NotoSansSymbols2-Regular.ttf"
},
size
);
}
}
public sealed class StyleNano : StyleBase public sealed class StyleNano : StyleBase
{ {
public const string StyleClassBorderedWindowPanel = "BorderedWindowPanel"; public const string StyleClassBorderedWindowPanel = "BorderedWindowPanel";
@@ -88,19 +109,19 @@ namespace Content.Client.Stylesheets
public StyleNano(IResourceCache resCache) : base(resCache) public StyleNano(IResourceCache resCache) : base(resCache)
{ {
var notoSans10 = resCache.GetFont("/Fonts/NotoSans/NotoSans-Regular.ttf", 10); var notoSans10 = resCache.notoStack(size: 10);
var notoSansItalic10 = resCache.GetFont("/Fonts/NotoSans/NotoSans-Italic.ttf", 10); var notoSansItalic10 = resCache.notoStack(variation: "Italic", size: 10);
var notoSans12 = resCache.GetFont("/Fonts/NotoSans/NotoSans-Regular.ttf", 12); var notoSans12 = resCache.notoStack(size: 12);
var notoSansItalic12 = resCache.GetFont("/Fonts/NotoSans/NotoSans-Italic.ttf", 12); var notoSansItalic12 = resCache.notoStack(variation: "Italic", size: 12);
var notoSansBold12 = resCache.GetFont("/Fonts/NotoSans/NotoSans-Bold.ttf", 12); var notoSansBold12 = resCache.notoStack(variation: "Bold", size: 12);
var notoSansBoldItalic12 = resCache.GetFont("/Fonts/NotoSans/NotoSans-BoldItalic.ttf", 12); var notoSansBoldItalic12 = resCache.notoStack(variation: "BoldItalic", size: 12);
var notoSansDisplayBold14 = resCache.GetFont("/Fonts/NotoSansDisplay/NotoSansDisplay-Bold.ttf", 14); var notoSansDisplayBold14 = resCache.notoStack(variation: "Bold", display: true, size: 14);
var notoSansDisplayBold16 = resCache.GetFont("/Fonts/NotoSansDisplay/NotoSansDisplay-Bold.ttf", 16); var notoSansDisplayBold16 = resCache.notoStack(variation: "Bold", display: true, size: 16);
var notoSans15 = resCache.GetFont("/Fonts/NotoSans/NotoSans-Regular.ttf", 15); var notoSans15 = resCache.notoStack(variation: "Regular", size: 15);
var notoSans16 = resCache.GetFont("/Fonts/NotoSans/NotoSans-Regular.ttf", 16); var notoSans16 = resCache.notoStack(variation: "Regular", size: 16);
var notoSansBold16 = resCache.GetFont("/Fonts/NotoSans/NotoSans-Bold.ttf", 16); var notoSansBold16 = resCache.notoStack(variation: "Bold", size: 16);
var notoSansBold18 = resCache.GetFont("/Fonts/NotoSans/NotoSans-Bold.ttf", 18); var notoSansBold18 = resCache.notoStack(variation: "Bold", size: 18);
var notoSansBold20 = resCache.GetFont("/Fonts/NotoSans/NotoSans-Bold.ttf", 20); var notoSansBold20 = resCache.notoStack(variation: "Bold", size: 20);
var windowHeaderTex = resCache.GetTexture("/Textures/Interface/Nano/window_header.png"); var windowHeaderTex = resCache.GetTexture("/Textures/Interface/Nano/window_header.png");
var windowHeader = new StyleBoxTexture var windowHeader = new StyleBoxTexture
{ {

View File

@@ -27,8 +27,26 @@ namespace Content.Client.Stylesheets
public StyleSpace(IResourceCache resCache) : base(resCache) public StyleSpace(IResourceCache resCache) : base(resCache)
{ {
var notoSans10 = resCache.GetFont("/Fonts/NotoSans/NotoSans-Regular.ttf", 10); var notoSans10 = resCache.GetFont
var notoSansBold16 = resCache.GetFont("/Fonts/NotoSans/NotoSans-Bold.ttf", 16); (
new []
{
"/Fonts/NotoSans/NotoSans-Regular.ttf",
"/Fonts/NotoSans/NotoSansSymbols-Regular.ttf",
"/Fonts/NotoSans/NotoSansSymbols2-Regular.ttf"
},
10
);
var notoSansBold16 = resCache.GetFont
(
new []
{
"/Fonts/NotoSans/NotoSans-Bold.ttf",
"/Fonts/NotoSans/NotoSansSymbols-Regular.ttf",
"/Fonts/NotoSans/NotoSansSymbols2-Regular.ttf"
},
16
);
var progressBarBackground = new StyleBoxFlat var progressBarBackground = new StyleBoxFlat
{ {

Binary file not shown.

Binary file not shown.

Binary file not shown.