🎥 Make videos programmatically with React
@remotion/google-fonts: resolve CJK subsets to chunks; FontInfo.subsets required
Jonny Burger2ee803beb0f5
diff --git a/packages/example/src/GoogleFontsCjk/GoogleFontsCjk.tsx b/packages/example/src/GoogleFontsCjk/GoogleFontsCjk.tsxnew file mode 100644index 0000000000..cdbd5ac898--- /dev/null+++ b/packages/example/src/GoogleFontsCjk/GoogleFontsCjk.tsx@@ -0,0 +1,38 @@+import {loadFont} from '@remotion/google-fonts/NotoSansSC';+import React from 'react';+import {AbsoluteFill} from 'remotion';++const {fontFamily} = loadFont('normal', {+ weights: ['400'],+ subsets: ['latin', 'chinese-simplified'],+ ignoreTooManyRequestsWarning: true,+});++/**+ * Regression cover for #7258: named CJK subsets must resolve to numbered Google Fonts chunks.+ * Loads many files on purpose — open only when validating CJK loading.+ */+export const GoogleFontsCjk: React.FC = () => {+ return (+ <AbsoluteFill+ style={{+ justifyContent: 'center',+ alignItems: 'center',+ backgroundColor: '#ffffff',+ }}+ >+ <div+ style={{+ fontFamily,+ fontSize: 80,+ textAlign: 'center',+ lineHeight: 1.35,+ padding: 48,+ color: '#111',+ }}+ >+ ä½ å¥½ · 日本語 · 한글+ </div>+ </AbsoluteFill>+ );+};diff --git a/packages/example/src/Root.tsx b/packages/example/src/Root.tsxindex c8e52bfda8..a7d3b2f204 100644--- a/packages/example/src/Root.tsx+++ b/packages/example/src/Root.tsx@@ -37,6 +37,7 @@ import {FontDemo} from './Fonts';import {Framer} from './Framer';import {FreezeExample} from './Freeze/FreezeExample';import {FreezePortion} from './FreezePortion/FreezePortion';+import {GoogleFontsCjk} from './GoogleFontsCjk/GoogleFontsCjk';import {Green} from './Green';import {HlsDemo} from './Hls/HlsDemo';import {@@ -1215,6 +1216,12 @@ export const Index: React.FC = () => {defaultProps={{flag: false}}/><Still id="font-demo" component={FontDemo} width={1000} height={1000} />+ <Still+ id="google-fonts-cjk"+ component={GoogleFontsCjk}+ width={1920}+ height={1080}+ /><Compositionid="dynamic-duration"component={VideoTesting}diff --git a/packages/google-fonts/src/BigShouldersDisplay.ts b/packages/google-fonts/src/BigShouldersDisplay.tsindex 51dd19fc8c..e08f2b537c 100644--- a/packages/google-fonts/src/BigShouldersDisplay.ts+++ b/packages/google-fonts/src/BigShouldersDisplay.ts@@ -89,6 +89,7 @@ export const getInfo = () => ({},},},+ subsets: ['latin', 'latin-ext', 'vietnamese'],});export const fontFamily = 'Big Shoulders Display' as const;diff --git a/packages/google-fonts/src/BigShouldersInlineDisplay.ts b/packages/google-fonts/src/BigShouldersInlineDisplay.tsindex 16a3bc321f..f8b4bfe12a 100644--- a/packages/google-fonts/src/BigShouldersInlineDisplay.ts+++ b/packages/google-fonts/src/BigShouldersInlineDisplay.ts@@ -89,6 +89,7 @@ export const getInfo = () => ({},},},+ subsets: ['latin', 'latin-ext', 'vietnamese'],});export const fontFamily = 'Big Shoulders Inline Display' as const;diff --git a/packages/google-fonts/src/BigShouldersInlineText.ts b/packages/google-fonts/src/BigShouldersInlineText.tsindex b835e7de7a..7447efa4a2 100644--- a/packages/google-fonts/src/BigShouldersInlineText.ts+++ b/packages/google-fonts/src/BigShouldersInlineText.ts@@ -89,6 +89,7 @@ export const getInfo = () => ({},},},+ subsets: ['latin', 'latin-ext', 'vietnamese'],});export const fontFamily = 'Big Shoulders Inline Text' as const;diff --git a/packages/google-fonts/src/BigShouldersStencilDisplay.ts b/packages/google-fonts/src/BigShouldersStencilDisplay.tsindex c95d3b6eab..dcb082fc2f 100644--- a/packages/google-fonts/src/BigShouldersStencilDisplay.ts+++ b/packages/google-fonts/src/BigShouldersStencilDisplay.ts@@ -89,6 +89,7 @@ export const getInfo = () => ({},},},+ subsets: ['latin', 'latin-ext', 'vietnamese'],});export const fontFamily = 'Big Shoulders Stencil Display' as const;diff --git a/packages/google-fonts/src/BigShouldersStencilText.ts b/packages/google-fonts/src/BigShouldersStencilText.tsindex 32230687c7..445d851e5b 100644--- a/packages/google-fonts/src/BigShouldersStencilText.ts+++ b/packages/google-fonts/src/BigShouldersStencilText.ts@@ -89,6 +89,7 @@ export const getInfo = () => ({},},},+ subsets: ['latin', 'latin-ext', 'vietnamese'],});export const fontFamily = 'Big Shoulders Stencil Text' as const;diff --git a/packages/google-fonts/src/BigShouldersText.ts b/packages/google-fonts/src/BigShouldersText.tsindex d87df3fd92..3a21ec8da3 100644--- a/packages/google-fonts/src/BigShouldersText.ts+++ b/packages/google-fonts/src/BigShouldersText.ts@@ -89,6 +89,7 @@ export const getInfo = () => ({},},},+ subsets: ['latin', 'latin-ext', 'vietnamese'],});export const fontFamily = 'Big Shoulders Text' as const;diff --git a/packages/google-fonts/src/MontserratSubrayada.ts b/packages/google-fonts/src/MontserratSubrayada.tsindex cfc4f25e22..6d0f0690f6 100644--- a/packages/google-fonts/src/MontserratSubrayada.ts+++ b/packages/google-fonts/src/MontserratSubrayada.ts@@ -21,6 +21,7 @@ export const getInfo = () => ({},},},+ subsets: ['latin'],});export const fontFamily = 'Montserrat Subrayada' as const;diff --git a/packages/google-fonts/src/base.ts b/packages/google-fonts/src/base.tsindex c242242e1b..4edc6963fe 100644--- a/packages/google-fonts/src/base.ts+++ b/packages/google-fonts/src/base.ts@@ -11,7 +11,7 @@ export type FontInfo = {url: string;unicodeRanges: Record<string, string>;fonts: Record<string, Record<string, Record<string, string>>>;- subsets?: string[];+ subsets: string[];};interface WithResolvers<T> {@@ -120,7 +120,7 @@ export const loadFonts = (`The font ${meta.fontFamily} does not have a weight ${weight} in style ${style}`,);}- const requestedSubsets =+ const requestedSubsets: string[] =options?.subsets ?? Object.keys(meta.fonts[style][weight]);const availableSubsetKeys = Object.keys(meta.fonts[style][weight]);const subsets = [diff --git a/packages/google-fonts/src/resolve-font-subsets.ts b/packages/google-fonts/src/resolve-font-subsets.tsindex ff6ef29195..dfb62d5e18 100644--- a/packages/google-fonts/src/resolve-font-subsets.ts+++ b/packages/google-fonts/src/resolve-font-subsets.ts@@ -1,35 +1,29 @@-const cjkSubsets = new Set([- 'chinese-hongkong',- 'chinese-simplified',- 'chinese-traditional',- 'japanese',- 'korean',-]);-const isChunkSubset = (subset: string) => /^\[\d+\]$/.test(subset);const compareChunkSubsets = (a: string, b: string) => {return Number(a.slice(1, -1)) - Number(b.slice(1, -1));};+/**+ * Maps a requested subset name to concrete keys in font metadata.+ * When Google Fonts ships a subset only as numbered unicode-range chunks (typical for CJK),+ * declared subset names appear in `meta.subsets` but not under `fonts[style][weight]`.+ * In that case we expand to every `[n]` chunk key present for that weight.+ */export const resolveFontSubsetKeys = ({availableSubsetKeys,metaSubsets,requestedSubset,}: {availableSubsetKeys: string[];- metaSubsets: string[] | undefined;+ metaSubsets: string[];requestedSubset: string;}) => {if (availableSubsetKeys.includes(requestedSubset)) {return [requestedSubset];}- if (!cjkSubsets.has(requestedSubset)) {- return [requestedSubset];- }-- if (!metaSubsets?.includes(requestedSubset)) {+ if (!metaSubsets.includes(requestedSubset)) {return [requestedSubset];}