Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/Filee.App/Services/FontSources.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ public static class FontSources
["Cambria"] = "cambria",
["Cambria Math"] = "cambria-math",
["Courier New"] = "courier-new",
["DengXian"] = "dengxian",
["DengXian Light"] = "dengxian",
["等线"] = "dengxian",
["等线 Light"] = "dengxian",
["Tahoma"] = "tahoma",
["Times New Roman"] = "times-new-roman",
};
Expand All @@ -33,7 +37,15 @@ public static class FontSources
"Wingdings", "Wingdings 2", "Wingdings 3", "Webdings", "Symbol", "OpenSymbol",
};

// Office's default font since 2023. Office fetches it from its cloud font service for itself, so other programs don't
// see it until it is installed from this download (Windows and macOS).
private const string AptosDownload = "https://www.microsoft.com/en-us/download/details.aspx?id=106087";

private static bool IsAptos(string family) => family.Equals("Aptos", StringComparison.OrdinalIgnoreCase)
|| family.StartsWith("Aptos ", StringComparison.OrdinalIgnoreCase);

public static Uri? Url(string family) => NoPublicFontPage.Contains(family) ? null
: IsAptos(family) ? new Uri(AptosDownload)
: Microsoft.TryGetValue(family, out var page)
? new Uri("https://learn.microsoft.com/en-us/typography/font-list/" + page)
: OtherOfficial.TryGetValue(family, out var official) ? new Uri(official)
Expand Down
27 changes: 27 additions & 0 deletions tests/Filee.App.Tests/FontSourcesTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Get fonts must lead to the font's own source: Aptos and DengXian aren't on Google Fonts (#1422, #1423).

using Filee.App.Services;

namespace Filee.App.Tests;

public class FontSourcesTests
{
[Theory]
[InlineData("Aptos")]
[InlineData("Aptos Display")]
[InlineData("Aptos Narrow")]
[InlineData("aptos serif")]
public void Aptos_goes_to_microsofts_download(string family) =>
Assert.Equal("https://www.microsoft.com/en-us/download/details.aspx?id=106087", FontSources.Url(family)!.ToString());

[Theory]
[InlineData("DengXian")]
[InlineData("DengXian Light")]
[InlineData("等线")]
public void DengXian_goes_to_its_microsoft_typography_page(string family) =>
Assert.Equal("https://learn.microsoft.com/en-us/typography/font-list/dengxian", FontSources.Url(family)!.ToString());

[Fact]
public void A_family_that_only_starts_with_aptos_letters_is_still_searched() =>
Assert.Equal("https://fonts.google.com/?query=Aptosa", FontSources.Url("Aptosa")!.ToString());
}
Loading