Add AndroidSystemFontLister

This commit is contained in:
BobLd
2024-05-04 17:13:43 +01:00
parent 995f287e0d
commit 5a8e6179da
5 changed files with 61 additions and 3 deletions

View File

@@ -0,0 +1,52 @@
namespace UglyToad.PdfPig.Fonts.SystemFonts
{
#if NET
using System.Collections.Generic;
using System.IO;
internal sealed class AndroidSystemFontLister : ISystemFontLister
{
public IEnumerable<SystemFontRecord> GetAllFonts()
{
var directories = new List<string>
{
"/system/fonts",
};
foreach (var directory in directories)
{
try
{
if (!Directory.Exists(directory))
{
continue;
}
}
catch
{
continue;
}
string[] files;
try
{
files = Directory.GetFiles(directory, "*.*", SearchOption.AllDirectories);
}
catch
{
continue;
}
foreach (var file in files)
{
if (SystemFontRecord.TryCreate(file, out var record))
{
yield return record;
}
}
}
}
}
#endif
}

View File

@@ -4,7 +4,7 @@
using System.Collections.Generic;
using System.IO;
internal class LinuxSystemFontLister : ISystemFontLister
internal sealed class LinuxSystemFontLister : ISystemFontLister
{
public IEnumerable<SystemFontRecord> GetAllFonts()
{

View File

@@ -4,7 +4,7 @@
using System.Collections.Generic;
using System.IO;
internal class MacSystemFontLister : ISystemFontLister
internal sealed class MacSystemFontLister : ISystemFontLister
{
public IEnumerable<SystemFontRecord> GetAllFonts()
{

View File

@@ -89,6 +89,12 @@ namespace UglyToad.PdfPig.Fonts.SystemFonts
{
lister = new LinuxSystemFontLister();
}
#if NET
else if (OperatingSystem.IsAndroid())
{
lister = new AndroidSystemFontLister();
}
#endif
else
{
throw new NotSupportedException($"Unsupported operating system: {RuntimeInformation.OSDescription}.");

View File

@@ -4,7 +4,7 @@
using System.Collections.Generic;
using System.IO;
internal class WindowsSystemFontLister : ISystemFontLister
internal sealed class WindowsSystemFontLister : ISystemFontLister
{
public IEnumerable<SystemFontRecord> GetAllFonts()
{