// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
using System;
namespace SixLabors.Fonts {
///
/// Extension methods for .
///
public static class FontCollectionExtensions
{
///
/// Adds the fonts from the collection to this .
///
/// The font collection.
/// The containing the system fonts.
public static FontCollection AddSystemFonts(this FontCollection collection)
{
// This cast is safe because our underlying SystemFontCollection implements
// both interfaces separately.
foreach (FontMetrics metric in (IReadOnlyFontMetricsCollection)SystemFonts.Collection)
{
((IFontMetricsCollection)collection).AddMetrics(metric);
}
collection.AddSearchDirectories(SystemFonts.Collection.SearchDirectories);
return collection;
}
///
/// Adds the fonts from the collection to this .
///
/// The font collection.
/// The delegate that defines the conditions of to add into the font collection.
/// The containing the system fonts.
public static FontCollection AddSystemFonts(this FontCollection collection, Predicate match)
{
bool isMatch = false;
foreach (FontMetrics metric in (IReadOnlyFontMetricsCollection)SystemFonts.Collection)
{
bool currentMatch = match(metric);
isMatch |= currentMatch;
if (currentMatch)
{
((IFontMetricsCollection)collection).AddMetrics(metric);
}
}
if (isMatch)
{
collection.AddSearchDirectories(SystemFonts.Collection.SearchDirectories);
}
return collection;
}
}
}