@remotion/google-fonts
The @remotion/google-fonts package provides APIs for easily integrating Google Fonts into Remotion.
Installation
- npm
- yarn
- pnpm
bash
bash
bash
Usage
To load a font, import the package @remotion/google-fonts/<FontName> and call loadFont().
Load all font stylestsxloadFont } from '@remotion/google-fonts/TitanOne';const {fontFamily } =loadFont (); // "Titan One"
If you want to import multiple fonts and want to avoid a variable name collision, you can import the fonts using an import * as statement.
Scope loadFont() variabletsxMontserrat from '@remotion/google-fonts/Montserrat';Montserrat .loadFont ();
Call loadFont() to start the loading process. By default, every style, weight and subset is loaded.
You can pass a style (such as normal, italic) to only load that specific style. If you want multiple styles, call loadFont() multiple times.
Load just one styletsxloadFont } from '@remotion/google-fonts/TitanOne';loadFont ('normal');
Use the TypeScript autocomplete to see the available styles. To further narrow down what's being loaded, you can specify weights and subsets. These options are also typesafe.
Load a specific style with limit weights and subsetstsxMontserrat from '@remotion/google-fonts/Montserrat';Montserrat .loadFont ('normal', {weights : ['400', '600', '800'],subsets : ['latin', 'latin-ext'],});
loadFont() returns an object with a fontFamily property. You can use the style attribute to render text in the font you loaded.
Use the fontFamily propertytsxloadFont } from '@remotion/google-fonts/TitanOne';import {AbsoluteFill } from 'remotion';const {fontFamily } =loadFont ();export constGoogleFontsDemoComposition = () => {return (<AbsoluteFill style ={{fontFamily ,}}><div >Hallo Google Fonts</div ></AbsoluteFill >);};
To get information about a font, you can import the getInfo() function:
Get info about the fonttsxgetInfo } from '@remotion/google-fonts/Montserrat';console .log (getInfo ());
Example value of info objectjson
To get a list of all available fonts, you can call getAvailableFonts() imported from @remotion/google-fonts:
tsgetAvailableFonts } from '@remotion/google-fonts';console .log (getAvailableFonts ());
APIs
Troubleshooting
Known issues:
Credits
Implemented by Hidayatullah.
License
MIT