2021-05-03 10:35:55 +08:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
|
|
|
|
|
using Markdig.Syntax;
|
2021-05-07 15:36:35 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
2021-05-03 10:35:55 +08:00
|
|
|
|
using osu.Framework.Graphics.Containers.Markdown;
|
2021-05-04 10:34:21 +08:00
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2021-05-03 10:35:55 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Graphics.Containers.Markdown
|
|
|
|
|
{
|
|
|
|
|
public partial class OsuMarkdownHeading : MarkdownHeading
|
|
|
|
|
{
|
2021-05-04 10:34:21 +08:00
|
|
|
|
private readonly int level;
|
|
|
|
|
|
2021-05-03 10:35:55 +08:00
|
|
|
|
public OsuMarkdownHeading(HeadingBlock headingBlock)
|
|
|
|
|
: base(headingBlock)
|
|
|
|
|
{
|
2021-05-04 10:34:21 +08:00
|
|
|
|
level = headingBlock.Level;
|
2021-05-03 10:35:55 +08:00
|
|
|
|
}
|
2021-05-03 10:35:59 +08:00
|
|
|
|
|
2021-05-04 10:34:21 +08:00
|
|
|
|
public override MarkdownTextFlowContainer CreateTextFlow() => new HeadingTextFlowContainer
|
|
|
|
|
{
|
2021-06-22 13:24:51 +08:00
|
|
|
|
FontSize = GetFontSizeByLevel(level),
|
|
|
|
|
FontWeight = GetFontWeightByLevel(level),
|
2021-05-04 10:34:21 +08:00
|
|
|
|
};
|
|
|
|
|
|
2021-05-03 10:35:59 +08:00
|
|
|
|
protected override float GetFontSizeByLevel(int level)
|
|
|
|
|
{
|
2021-05-06 16:00:12 +08:00
|
|
|
|
// Reference for this font size
|
|
|
|
|
// https://github.com/ppy/osu-web/blob/376cac43a051b9c85ce95e2c446099be187b3e45/resources/assets/less/bem/osu-md.less#L9
|
|
|
|
|
// https://github.com/ppy/osu-web/blob/376cac43a051b9c85ce95e2c446099be187b3e45/resources/assets/less/variables.less#L161
|
2021-05-03 10:35:59 +08:00
|
|
|
|
switch (level)
|
|
|
|
|
{
|
|
|
|
|
case 1:
|
2021-06-22 13:24:25 +08:00
|
|
|
|
return 30;
|
2021-05-03 10:35:59 +08:00
|
|
|
|
|
|
|
|
|
case 2:
|
2021-06-22 13:24:25 +08:00
|
|
|
|
return 26;
|
2021-05-03 10:35:59 +08:00
|
|
|
|
|
|
|
|
|
case 3:
|
2021-06-22 13:24:25 +08:00
|
|
|
|
return 20;
|
2021-05-03 10:35:59 +08:00
|
|
|
|
|
|
|
|
|
case 4:
|
2021-06-22 13:24:25 +08:00
|
|
|
|
return 18;
|
2021-05-03 10:35:59 +08:00
|
|
|
|
|
|
|
|
|
case 5:
|
2021-06-22 13:24:25 +08:00
|
|
|
|
return 16;
|
2021-05-03 10:35:59 +08:00
|
|
|
|
|
|
|
|
|
default:
|
2021-06-22 13:24:25 +08:00
|
|
|
|
return 14;
|
2021-05-03 10:35:59 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2021-05-04 10:34:21 +08:00
|
|
|
|
|
|
|
|
|
protected virtual FontWeight GetFontWeightByLevel(int level)
|
|
|
|
|
{
|
|
|
|
|
switch (level)
|
|
|
|
|
{
|
|
|
|
|
case 1:
|
|
|
|
|
case 2:
|
|
|
|
|
return FontWeight.SemiBold;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
return FontWeight.Bold;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private partial class HeadingTextFlowContainer : OsuMarkdownTextFlowContainer
|
|
|
|
|
{
|
2021-06-22 13:24:51 +08:00
|
|
|
|
public float FontSize;
|
|
|
|
|
public FontWeight FontWeight;
|
2021-05-04 10:34:21 +08:00
|
|
|
|
|
2021-06-22 13:24:51 +08:00
|
|
|
|
protected override SpriteText CreateSpriteText()
|
2021-08-03 23:14:44 +08:00
|
|
|
|
=> base.CreateSpriteText().With(t => t.Font = t.Font.With(Typeface.Torus, size: FontSize, weight: FontWeight));
|
2021-05-04 10:34:21 +08:00
|
|
|
|
}
|
2021-05-03 10:35:55 +08:00
|
|
|
|
}
|
|
|
|
|
}
|