# TypefaceCompat

Artifact: [androidx.core:core](https://developer.android.com/jetpack/androidx/releases/core) [View Source](https://cs.android.com/search?q=file:androidx/core/graphics/TypefaceCompat.java+class:androidx.core.graphics.TypefaceCompat) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

*** ** * ** ***


```
public class TypefaceCompat
```

<br />

*** ** * ** ***

Helper for accessing features in `https://developer.android.com/reference/android/graphics/Typeface.html`.

## Summary

| ### Public methods |
|---|---|
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/graphics/Typeface.html` | `https://developer.android.com/reference/androidx/core/graphics/TypefaceCompat#create(android.content.Context,android.graphics.Typeface,int)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/graphics/Typeface.html family, int style)` Retrieves the best matching typeface given the family, style and context. |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/graphics/Typeface.html` | `https://developer.android.com/reference/androidx/core/graphics/TypefaceCompat#create(android.content.Context,android.graphics.Typeface,int,boolean)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/graphics/Typeface.html family, @https://developer.android.com/reference/androidx/annotation/IntRange(from = 1, to = 1000) int weight, boolean italic )` Creates a typeface object that best matches the specified existing typeface and the specified weight and italic style |

## Public methods

### create

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
public static @NonNull Typeface create(@NonNull Context context, @Nullable Typeface family, int style)
```

Retrieves the best matching typeface given the family, style and context. If null is passed for the family, then the "default" font will be chosen.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context` | The context used to retrieve the font. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/graphics/Typeface.html family` | The font family. May be null. |
| `int style` | The style of the typeface. e.g. NORMAL, BOLD, ITALIC, BOLD_ITALIC |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/graphics/Typeface.html` | The best matching typeface. |

### create

Added in [1.9.0](https://developer.android.com/jetpack/androidx/releases/core#1.9.0)

```
public static @NonNull Typeface create(
    @NonNull Context context,
    @Nullable Typeface family,
    @IntRange(from = 1, to = 1000) int weight,
    boolean italic
)
```

Creates a typeface object that best matches the specified existing typeface and the specified weight and italic style

Below are numerical values and corresponding common weight names.

| Value | Common weight name |
|---|---|
| 100 | Thin |
| 200 | Extra Light |
| 300 | Light |
| 400 | Normal |
| 500 | Medium |
| 600 | Semi Bold |
| 700 | Bold |
| 800 | Extra Bold |
| 900 | Black |

This method is thread safe.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context` | context to use for the creation. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/graphics/Typeface.html family` | An existing `https://developer.android.com/reference/android/graphics/Typeface.html` object. In case of `null`, the default typeface is used instead. |
| `@https://developer.android.com/reference/androidx/annotation/IntRange(from = 1, to = 1000) int weight` | The desired weight to be drawn. |
| `boolean italic` | `true` if italic style is desired to be drawn. Otherwise, `false` |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/graphics/Typeface.html` | A `https://developer.android.com/reference/android/graphics/Typeface.html` object for drawing specified weight and italic style. Never returns `null` |

| See also |
|---|---|
| `https://developer.android.com/reference/android/graphics/Typeface.html#getWeight()` |   |
| `https://developer.android.com/reference/android/graphics/Typeface.html#isItalic()` |   |