private static void EnumFonts(IDWriteFontCollection coll) { var count = coll.GetFontFamilyCount(); var locale = System.Globalization.CultureInfo.CurrentCulture.Name; for (var i = 0U; i < count; i++) { try { using var pFontFam = ComReleaserFactory.Create(coll.GetFontFamily(i)); using var pFamNames = ComReleaserFactory.Create(pFontFam.Item.GetFamilyNames()); pFamNames.Item.FindLocaleName(locale, out var index, out var exists); if (!exists) { index = 0; } var len = pFamNames.Item.GetStringLength(index) + 1; var str = new StringBuilder((int)len); pFamNames.Item.GetString(index, str, len); TestContext.WriteLine(str); } catch (Exception ex) { TestContext.WriteLine("ERROR: " + ex.Message); } } }
public static IReadOnlyList <IDWriteFontFamily> GetFamilies(this IDWriteFontCollection collection) { if (collection == null) { throw new ArgumentNullException(nameof(collection)); } var list = new List <IDWriteFontFamily>((int)collection.GetFontFamilyCount()); for (var i = 0; i < list.Capacity; i++) { collection.GetFontFamily((uint)i, out var family).ThrowOnError(); list.Add(family); } return(list); }