GoogleFont.Provider

class GoogleFont.Provider


Attributes used to create a FontRequest for a GoogleFont based Font.

See also
FontRequest

Summary

Public constructors

Provider(
    providerAuthority: String,
    providerPackage: String,
    certificates: @ArrayRes Int
)

Describe a downloadable fonts provider using a resource array for certificates.

Provider(
    providerAuthority: String,
    providerPackage: String,
    certificates: List<List<ByteArray>>
)

Describe a downloadable fonts provider using a list of certificates.

Provider(
    providerAuthority: String,
    providerPackage: String,
    certificates: @ArrayRes Int,
    systemCertificates: @ArrayRes Int
)

Describe a downloadable fonts provider using resource arrays for certificates and system certificates.

Public functions

open operator Boolean
equals(other: Any?)
open Int

Extension functions

Boolean

Check if the downloadable fonts provider is available on device.

Public constructors

Provider

Added in 1.2.0
Provider(
    providerAuthority: String,
    providerPackage: String,
    certificates: @ArrayRes Int
)

Describe a downloadable fonts provider using a resource array for certificates.

The font provider is matched by providerAuthority and packageName, then the resulting provider has it's certificates validated against certificates.

If the certificates check success, the provider is used for downloadable fonts.

If the certificates check fails, the provider will not be used and any downloadable fonts requests configured with it will fail.

Parameters
providerAuthority: String

The authority of the Font Provider to be used for the request.

providerPackage: String

The package for the Font Provider to be used for the request. This is used to verify the identity of the provider.

certificates: @ArrayRes Int

A resource array with the list of sets of hashes for the certificates the provider should be signed with. This is used to verify the identity of the provider. Each set in the list represents one collection of signature hashes. Refer to your font provider's documentation for these values.

Provider

Provider(
    providerAuthority: String,
    providerPackage: String,
    certificates: List<List<ByteArray>>
)

Describe a downloadable fonts provider using a list of certificates.

The font provider is matched by providerAuthority and packageName, then the resulting provider has it's certificates validated against certificates.

If the certificates check success, the provider is used for downloadable fonts.

If the certificates check fails, the provider will not be used and any downloadable fonts requests configured with it will fail.

Parameters
providerAuthority: String

The authority of the Font Provider to be used for the request.

providerPackage: String

The package for the Font Provider to be used for the request. This is used to verify the identity of the provider.

certificates: List<List<ByteArray>>

The list of sets of hashes for the certificates the provider should be signed with. This is used to verify the identity of the provider. Each set in the list represents one collection of signature hashes. Refer to your font provider's documentation for these values.

Provider

Provider(
    providerAuthority: String,
    providerPackage: String,
    certificates: @ArrayRes Int,
    systemCertificates: @ArrayRes Int
)

Describe a downloadable fonts provider using resource arrays for certificates and system certificates.

The font provider is matched by providerAuthority and providerPackage, then the resulting provider has its certificates validated against certificates first, or against systemCertificates if the provider is installed on the system image (ApplicationInfo.FLAG_SYSTEM or ApplicationInfo.FLAG_UPDATED_SYSTEM_APP).

If the certificates check succeeds, the provider is used for downloadable fonts. If the certificates check fails, the provider will not be used and any downloadable fonts requests configured with it will fail.

At least one of certificates or systemCertificates must be a non-zero resource ID (pass 0 for certificates to only trust system providers matching systemCertificates, or pass 0 for systemCertificates to only trust certificates).

import androidx.compose.material3.Text
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.text.font.FontVariation
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.googlefonts.Font
import androidx.compose.ui.text.googlefonts.GoogleFont
import androidx.compose.ui.text.googlefonts.R

val fontProvider =
    GoogleFont.Provider(
        providerAuthority = "com.google.android.gms.fonts",
        providerPackage = "com.google.android.gms",
        certificates = R.array.com_google_android_gms_fonts_certs_prod,
        systemCertificates = R.array.com_google_android_gms_fonts_certs_dev,
    )

val fontFamily =
    FontFamily(
        Font(
            googleFont = GoogleFont("Google Sans Flex"),
            fontProvider = fontProvider,
            weight = FontWeight.W600,
            variationSettings = FontVariation.Settings(FontWeight.W600, FontStyle.Normal),
        )
    )

Text("Hello World", style = TextStyle(fontFamily = fontFamily))
Parameters
providerAuthority: String

The authority of the Font Provider to be used for the request.

providerPackage: String

The package for the Font Provider to be used for the request. This is used to verify the identity of the provider.

certificates: @ArrayRes Int

A resource array with the list of sets of hashes for the certificates the provider should be signed with. This is used to verify the identity of the provider, and each set in the list represents one collection of signature hashes. Refer to your font provider's documentation for these values. Matching certificates are trusted regardless of whether the provider is installed as a system application. Pass 0 to only trust system providers matching systemCertificates.

systemCertificates: @ArrayRes Int

A resource array with the list of sets of hashes for the certificates the provider should be signed with when installed as a system application (ApplicationInfo.FLAG_SYSTEM or ApplicationInfo.FLAG_UPDATED_SYSTEM_APP). Each set in the list represents one collection of signature hashes. Pass 0 if no system-only certificates are needed.

Throws
IllegalArgumentException

if both certificates and systemCertificates are 0.

Public functions

equals

open operator fun equals(other: Any?): Boolean

hashCode

open fun hashCode(): Int

Extension functions

GoogleFont.Provider.isAvailableOnDevice

@WorkerThread
fun GoogleFont.Provider.isAvailableOnDevice(context: Context): Boolean

Check if the downloadable fonts provider is available on device.

This is not necessary for normal usage, but may be useful in debugging downloadable fonts behavior.

Parameters
context: Context

for looking up font provider in

Returns
Boolean

true if the provider is usable for downloadable fonts, false if it's not found

Throws
IllegalStateException

if the provider is on device, but certificates don't match (note that systemCertificates only match when the provider is installed as a system application)