mirror of
https://github.com/UglyToad/PdfPig.git
synced 2026-03-10 00:23:29 +08:00
Add AndroidSystemFontLister
This commit is contained in:
@@ -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
|
||||
}
|
||||
@@ -4,7 +4,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
internal class LinuxSystemFontLister : ISystemFontLister
|
||||
internal sealed class LinuxSystemFontLister : ISystemFontLister
|
||||
{
|
||||
public IEnumerable<SystemFontRecord> GetAllFonts()
|
||||
{
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
internal class MacSystemFontLister : ISystemFontLister
|
||||
internal sealed class MacSystemFontLister : ISystemFontLister
|
||||
{
|
||||
public IEnumerable<SystemFontRecord> GetAllFonts()
|
||||
{
|
||||
|
||||
@@ -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}.");
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
internal class WindowsSystemFontLister : ISystemFontLister
|
||||
internal sealed class WindowsSystemFontLister : ISystemFontLister
|
||||
{
|
||||
public IEnumerable<SystemFontRecord> GetAllFonts()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user