Added in [API level 35](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

# FontScaleConverter

*** ** * ** ***


`
public


interface
FontScaleConverter
`


`


`

|---|
| android.content.res.FontScaleConverter |

<br />

*** ** * ** ***

A converter for non-linear font scaling. Converts font sizes given in "sp" dimensions to a
"dp" dimension according to a non-linear curve.

This is meant to improve readability at larger font scales: larger fonts will scale up more
slowly than smaller fonts, so we don't get ridiculously huge fonts that don't fit on the screen.

The thinking here is that large fonts are already big enough to read, but we still want to
scale them slightly to preserve the visual hierarchy when compared to smaller fonts.

## Summary

| ### Public methods ||
|---|---|
| ` abstract float` | ` https://developer.android.com/reference/android/content/res/FontScaleConverter#convertDpToSp(float)(float dp) ` Converts a dimension in "dp" back to "sp". |
| ` abstract float` | ` https://developer.android.com/reference/android/content/res/FontScaleConverter#convertSpToDp(float)(float sp) ` Converts a dimension in "sp" to "dp". |
| ` static https://developer.android.com/reference/android/content/res/FontScaleConverter` | ` https://developer.android.com/reference/android/content/res/FontScaleConverter#forScale(float)(float fontScale) ` Finds a matching FontScaleConverter for the given fontScale factor. |
| ` static boolean` | ` https://developer.android.com/reference/android/content/res/FontScaleConverter#isNonLinearFontScalingActive(float)(float fontScale) ` Returns true if non-linear font scaling curves would be in effect for the given scale, false if the scaling would follow a linear curve or for no scaling. |

## Public methods

### convertDpToSp

Added in [API level 35](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public abstract float convertDpToSp (float dp)
```

Converts a dimension in "dp" back to "sp".

<br />

| Parameters ||
|---|---|
| `dp` | `float` <br /> |

| Returns ||
|---|---|
| `float` | <br /> |

### convertSpToDp

Added in [API level 35](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public abstract float convertSpToDp (float sp)
```

Converts a dimension in "sp" to "dp".

<br />

| Parameters ||
|---|---|
| `sp` | `float` <br /> |

| Returns ||
|---|---|
| `float` | <br /> |

### forScale

Added in [API level 35](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static FontScaleConverter forScale (float fontScale)
```

Finds a matching FontScaleConverter for the given fontScale factor.

Generally you shouldn't need this; you can use `https://developer.android.com/reference/android/util/TypedValue#applyDimension(int,%20float,%20android.util.DisplayMetrics)`
directly and it will do the scaling conversion for you. Dimens and resources loaded from XML
will also be automatically converted. But for UI frameworks or other situations where you
need to do the conversion without an Android Context, you can use this method.


This method is safe to call from any thread.

<br />

| Parameters ||
|---|---|
| `fontScale` | `float`: the scale factor, usually from `https://developer.android.com/reference/android/content/res/Configuration#fontScale`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/content/res/FontScaleConverter` | a converter for the given scale, or null if non-linear scaling should not be used. <br /> |

### isNonLinearFontScalingActive

Added in [API level 35](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static boolean isNonLinearFontScalingActive (float fontScale)
```

Returns true if non-linear font scaling curves would be in effect for the given scale, false
if the scaling would follow a linear curve or for no scaling.

Example usage: `isNonLinearFontScalingActive(getResources().getConfiguration().fontScale)`


This method is safe to call from any thread.

<br />

| Parameters ||
|---|---|
| `fontScale` | `float` <br /> |

| Returns ||
|---|---|
| `boolean` | <br /> |