Skip to content

Commit

Permalink
Add AndroidSystemFontLister
Browse files Browse the repository at this point in the history
  • Loading branch information
BobLd committed May 8, 2024
1 parent 995f287 commit 5a8e617
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 3 deletions.
52 changes: 52 additions & 0 deletions src/UglyToad.PdfPig.Fonts/SystemFonts/AndroidSystemFontLister.cs
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Collections.Generic;
using System.IO;

internal class LinuxSystemFontLister : ISystemFontLister
internal sealed class LinuxSystemFontLister : ISystemFontLister
{
public IEnumerable<SystemFontRecord> GetAllFonts()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Collections.Generic;
using System.IO;

internal class MacSystemFontLister : ISystemFontLister
internal sealed class MacSystemFontLister : ISystemFontLister
{
public IEnumerable<SystemFontRecord> GetAllFonts()
{
Expand Down
6 changes: 6 additions & 0 deletions src/UglyToad.PdfPig.Fonts/SystemFonts/SystemFontFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ static SystemFontFinder()
{
lister = new LinuxSystemFontLister();
}
#if NET
else if (OperatingSystem.IsAndroid())
{
lister = new AndroidSystemFontLister();
}
#endif
else
{
throw new NotSupportedException($"Unsupported operating system: {RuntimeInformation.OSDescription}.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Collections.Generic;
using System.IO;

internal class WindowsSystemFontLister : ISystemFontLister
internal sealed class WindowsSystemFontLister : ISystemFontLister
{
public IEnumerable<SystemFontRecord> GetAllFonts()
{
Expand Down

0 comments on commit 5a8e617

Please sign in to comment.