🎥 Make videos programmatically with React
fonts demo
Jonny Burger523672fbb7cf
diff --git a/packages/example/src/Fonts/index.tsx b/packages/example/src/Fonts/index.tsxindex 3fabb26aef..1e7dfbc977 100644--- a/packages/example/src/Fonts/index.tsx+++ b/packages/example/src/Fonts/index.tsx@@ -1,19 +1,11 @@+import {loadFont} from '@remotion/google-fonts/Montserrat';import React from 'react';-import {AbsoluteFill, continueRender, delayRender, staticFile} from 'remotion';+import {AbsoluteFill} from 'remotion';-const waitForFont = delayRender();-const font = new FontFace(- `Bangers`,- `url(${staticFile('bangers.woff2')}) format('woff2')`-);--font- .load()- .then(() => {- document.fonts.add(font);- continueRender(waitForFont);- })- .catch((err) => console.log('Error loading font', err));+loadFont('italic', {+ subsets: ['latin', 'latin-ext', 'vietnamese'],+ weights: ['400'],+});export const FontDemo: React.FC = () => {return (diff --git a/packages/google-fonts/package.json b/packages/google-fonts/package.jsonindex 41ccd403ec..3f46267a39 100644--- a/packages/google-fonts/package.json+++ b/packages/google-fonts/package.json@@ -9,7 +9,7 @@},"license": "SEE LICENSE IN LICENSE.md","dependencies": {- "remotion": "3.2.35"+ "remotion": "3.2.39"},"devDependencies": {"@types/css-font-loading-module": "^0.0.7",diff --git a/packages/google-fonts/src/base.ts b/packages/google-fonts/src/base.tsindex b57aba22c1..7ec59c3f52 100644--- a/packages/google-fonts/src/base.ts+++ b/packages/google-fonts/src/base.ts@@ -1,12 +1,16 @@-import type { } from "css-font-loading-module";-import { continueRender, delayRender } from 'remotion';+import type {} from "css-font-loading-module";+import { continueRender, delayRender } from "remotion";const loadedFonts: { [key: string]: boolean } = {};-export const loadFonts = (meta: any, style: string, options: {- weights: string[],- subsets: string[],-}) => {+export const loadFonts = (+ meta: any,+ style: string,+ options: {+ weights: string[];+ subsets: string[];+ }+) => {for (const weight of options.weights) {for (const subset of options.subsets) {// Get font url from meta@@ -14,7 +18,9 @@ export const loadFonts = (meta: any, style: string, options: {// Check is font available in metaif (!font) {- throw new Error(`weight: ${weight} subset: ${subset} is not available for '${meta.family}'`);+ throw new Error(+ `weight: ${weight} subset: ${subset} is not available for '${meta.family}'`+ );}// Check is font already loaded@@ -26,21 +32,28 @@ export const loadFonts = (meta: any, style: string, options: {// Mark font as loadedloadedFonts[fontKey] = true;- const handle = delayRender(`Fetching ${meta.family} font ${JSON.stringify({- style,- weight,- subset,- })}`)+ const handle = delayRender(+ `Fetching ${meta.family} font ${JSON.stringify({+ style,+ weight,+ subset,+ })}`+ );// Create font-face- const fontFace = new FontFace(meta.family.replace(/^['"]/g, '').replace(/['"]$/g, ''), `url(${font}) format('woff2')`, {- weight: weight,- style: style,- unicodeRange: meta.unicodeRanges[subset],- });+ const fontFace = new FontFace(+ meta.family.replace(/^['"]/g, "").replace(/['"]$/g, ""),+ `url(${font}) format('woff2')`,+ {+ weight: weight,+ style: style,+ unicodeRange: meta.unicodeRanges[subset],+ }+ );// Load font-face- fontFace.load()+ fontFace+ .load().then(() => {document.fonts.add(fontFace);continueRender(handle);@@ -52,4 +65,4 @@ export const loadFonts = (meta: any, style: string, options: {});}}-}\ No newline at end of file+};