{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}

FontFamilyResolverKt

public final class FontFamilyResolverKt


Summary

Public methods

static final @NonNull FontFamily.Resolver

Create a new fontFamilyResolver for use outside of composition context

static final @NonNull FontFamily.Resolver
createFontFamilyResolver(
    @NonNull Context context,
    @NonNull CoroutineContext coroutineContext
)

Create a new fontFamilyResolver for use outside of composition context with a coroutine context.

static final @NonNull State<@NonNull Typeface>
resolveAsTypeface(
    @NonNull FontFamily.Resolver receiver,
    FontFamily fontFamily,
    @NonNull FontWeight fontWeight,
    @NonNull FontStyle fontStyle,
    @NonNull FontSynthesis fontSynthesis
)

Resolve a font to an Android Typeface

Public methods

createFontFamilyResolver

public static final @NonNull FontFamily.Resolver createFontFamilyResolver(@NonNull Context context)

Create a new fontFamilyResolver for use outside of composition context

Example usages:

Usages inside of Composition should use LocalFontFamilyResolver.current

All instances of FontFamily.Resolver created by createFontFamilyResolver share the same typeface caches.

createFontFamilyResolver

public static final @NonNull FontFamily.Resolver createFontFamilyResolver(
    @NonNull Context context,
    @NonNull CoroutineContext coroutineContext
)

Create a new fontFamilyResolver for use outside of composition context with a coroutine context.

Example usages:

Usages inside of Composition should use LocalFontFamilyResolver.current

Any kotlinx.coroutines.CoroutineExceptionHandler provided will be called with exceptions related to fallback font loading. These exceptions are not fatal, and indicate that font fallback continued to the next font load.

If no kotlinx.coroutines.CoroutineExceptionHandler is provided, a default implementation will be added that ignores all exceptions.

All instances of FontFamily.Resolver created by createFontFamilyResolver share the same typeface caches.

Parameters
@NonNull Context context

Android context for resolving fonts

@NonNull CoroutineContext coroutineContext

context to launch async requests in during resolution.

resolveAsTypeface

public static final @NonNull State<@NonNull TypefaceresolveAsTypeface(
    @NonNull FontFamily.Resolver receiver,
    FontFamily fontFamily,
    @NonNull FontWeight fontWeight,
    @NonNull FontStyle fontStyle,
    @NonNull FontSynthesis fontSynthesis
)

Resolve a font to an Android Typeface

On Android, font resolution always produces an android.graphics.Typeface.

This convenience method converts State to State to avoid casting the result.

Parameters
FontFamily fontFamily

fontFamily to resolve from

@NonNull FontWeight fontWeight

font weight to resolve in fontFamily, will use closest match if not exact

@NonNull FontStyle fontStyle

italic or upright text, to resolve in fontFamily

@NonNull FontSynthesis fontSynthesis

allow font synthesis if fontFamily or fontStyle don't have an exact match. This will allow "fake bold" (drawing with too wide a brush) and "fake italic" (drawing then skewing) to be applied when no exact match is present for the weight and style.