FontCollection
Provides a base class for installed and private font collections.
using System.Runtime.CompilerServices;
using Windows.Win32;
using Windows.Win32.Graphics.GdiPlus;
namespace System.Drawing.Text
{
public abstract class FontCollection : IDisposable
{
internal unsafe GpFontCollection* _nativeFontCollection;
[Nullable(1)]
public unsafe FontFamily[] Families {
[NullableContext(1)]
get {
int num = default(int);
PInvoke.GdipGetFontCollectionFamilyCount(_nativeFontCollection, &num).ThrowIfFailed();
if (num == 0)
return Array.Empty<FontFamily>();
GpFontFamily*[] array = new GpFontFamily*[num];
fixed (GpFontFamily** gpfamilies = array) {
PInvoke.GdipGetFontCollectionFamilyList(_nativeFontCollection, num, gpfamilies, &num).ThrowIfFailed();
}
FontFamily[] array2 = new FontFamily[num];
for (int i = 0; i < num; i++) {
GpFontFamily* family = default(GpFontFamily*);
PInvoke.GdipCloneFontFamily(array[i], &family).ThrowIfFailed();
array2[i] = new FontFamily(family);
}
GC.KeepAlive(this);
return array2;
}
}
internal unsafe FontCollection()
{
_nativeFontCollection = null;
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
}
~FontCollection()
{
Dispose(false);
}
}
}