Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add OpenSans font manifest #43

Merged
merged 3 commits into from
Jul 5, 2024

Conversation

Youssef1313
Copy link
Member

GitHub Issue (If applicable): #

PR Type

What kind of change does this PR introduce?

What is the current behavior?

What is the new behavior?

PR Checklist

Please check if your PR fulfills the following requirements:

  • Tested code with current supported SDKs
  • Docs have been added/updated which fit documentation template. (for bug fixes / features)
  • Unit Tests and/or UI Tests for the changes have been added (for bug fixes / features) (if applicable)
  • Wasm UI Tests are not showing unexpected any differences. Validate PR Screenshots Compare Test Run results.
  • Contains NO breaking changes
  • Updated the Release Notes
  • Associated with an issue (GitHub or internal)

Other information

Code used to generate manifest:

using System.Text.Json;
using System.Text.Json.Serialization;

var options = new JsonSerializerOptions()
{
    AllowTrailingCommas = true,
    PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower,
    ReadCommentHandling = JsonCommentHandling.Skip,
    Converters =
    {
        new JsonStringEnumConverter(),
    },
};

var directory = "C:\\Users\\PC\\Desktop\\uno.fonts\\nuget\\OpenSans\\Uno.Fonts.OpenSans\\Fonts\\";

var list = new List<FontInfo>();

foreach (var stretch in Enum.GetValues<FontStretch>())
{
    foreach (ushort weight in (ReadOnlySpan<ushort>)[300, 400, 500, 600, 700, 800])
    {
        foreach (var style in (ReadOnlySpan<FontStyle>)[FontStyle.Normal, FontStyle.Italic])
        {
            var name = "OpenSans";
            if (stretch != FontStretch.Normal)
            {
                name += "_" + stretch.ToString();
            }

            if (weight != 400 || style != FontStyle.Normal)
            {
                name += "-";
                if (weight != 400)
                {
                    name += WeightToName(weight);
                }

                if (style != FontStyle.Normal)
                {
                    name += style.ToString();
                }
            }
            else
            {
                name += "-Regular";
            }

            name += ".ttf";

            if (File.Exists(directory + name))
            {
                list.Add(new FontInfo
                {
                    FontWeight = weight,
                    FontStyle = style,
                    FontStretch = stretch,
                    FamilyName = "ms-appx:///Uno.Fonts.OpenSans/Fonts/" + name,
                });
            }
        }
    }
}

var manifest = new FontManifest
{
    Fonts = list.ToArray(),
};

var json = JsonSerializer.Serialize<FontManifest>(manifest, options);

Console.WriteLine(json);

string WeightToName(ushort weight)
{
    return weight switch
    {
        300 => "Light",
        500 => "Medium",
        600 => "SemiBold",
        700 => "Bold",
        800 => "ExtraBold",
        _ => throw new Exception()
    };
}

internal sealed class FontManifest
{
    public FontInfo[] Fonts { get; set; }
}

internal sealed class FontInfo
{
    public FontStyle FontStyle { get; set; }
    public ushort FontWeight { get; set; }
    public FontStretch FontStretch { get; set; }
    public string FamilyName { get; set; }
}

public enum FontStyle
{
    Normal,
    Oblique,
    Italic,
}
public enum FontStretch
{
    Undefined = 0,
    UltraCondensed = 1,
    ExtraCondensed = 2,
    Condensed = 3,
    SemiCondensed = 4,
    Normal = 5,
    SemiExpanded = 6,
    Expanded = 7,
    ExtraExpanded = 8,
    UltraExpanded = 9,
}

Internal Issue (If applicable):

@Youssef1313 Youssef1313 force-pushed the dev/youssef/opensans branch from de46283 to 512b1a8 Compare June 21, 2024 03:40
@Youssef1313 Youssef1313 marked this pull request as ready for review July 5, 2024 03:37
@MartinZikmund
Copy link
Member

@agneszitte When you are on-line, please merge this one 🙏

@agneszitte agneszitte merged commit 4fe3729 into unoplatform:main Jul 5, 2024
7 checks passed
@Youssef1313 Youssef1313 deleted the dev/youssef/opensans branch July 5, 2024 13:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants