Plugins can use typefaces available in the Font Picker to get information about specific fonts or to apply them to Text Styles.
To list all available fonts, use the following code.
Unlike the Font Picker, which groups fonts by typeface, getFonts will list individual fonts for each weight and style. You can think these as separate font files.
[
{
family: "Inter",
weight: 900,
style: "normal"
},
{
family: "Noto Sans",
weight: 400,
style: "normal"
},
{
family: "Noto Sans",
weight: 400,
style: "italic"
},
{
family: "Noto Sans",
weight: 500,
style: "normal"
},
]
[
{
family: "Inter",
weight: 900,
style: "normal"
},
{
family: "Noto Sans",
weight: 400,
style: "normal"
},
{
family: "Noto Sans",
weight: 400,
style: "italic"
},
{
family: "Noto Sans",
weight: 500,
style: "normal"
},
]
[
{
family: "Inter",
weight: 900,
style: "normal"
},
{
family: "Noto Sans",
weight: 400,
style: "normal"
},
{
family: "Noto Sans",
weight: 400,
style: "italic"
},
{
family: "Noto Sans",
weight: 500,
style: "normal"
},
]To get a specific font from a family, use getFont and pass in the family name. This is not case sensitive.
By default, this will return a font in the family that has a normal weight and style.
const font = await framer.getFont("Noto Sans")
const font = await framer.getFont("Noto Sans")
const font = await framer.getFont("Noto Sans")You can specify a desired weight or style by passing in optional attributes.
const font = await framer.getFont("Noto Sans", {
weight: 800
})
const font = await framer.getFont("Noto Sans", {
weight: 800,
style: "italic"
})
const font = await framer.getFont("Noto Sans", {
weight: 800
})
const font = await framer.getFont("Noto Sans", {
weight: 800,
style: "italic"
})
const font = await framer.getFont("Noto Sans", {
weight: 800
})
const font = await framer.getFont("Noto Sans", {
weight: 800,
style: "italic"
})Make sure to check that a font exists before using it. If a font does not exist, getFont will return null.
const font = await framer.getFont("General Sans", { weight: 900 })
if (!font) return
const textStyle = await framer.createTextStyle({ font })const font = await framer.getFont("General Sans", { weight: 900 })
if (!font) return
const textStyle = await framer.createTextStyle({ font })const font = await framer.getFont("General Sans", { weight: 900 })
if (!font) return
const textStyle = await framer.createTextStyle({ font })This may happen if the typeface is not available in Framer or if it lacks a certain weight and style combination.
Note: Custom fonts are not available to plugins.