🎥 Make videos programmatically with React
implement fontVariantNumberic variant property to measureText()
Jonny Burgerf56b746af431
diff --git a/packages/docs/docs/layout-utils/measure-text.md b/packages/docs/docs/layout-utils/measure-text.mdindex 06c058a624..105d61908d 100644--- a/packages/docs/docs/layout-utils/measure-text.md+++ b/packages/docs/docs/layout-utils/measure-text.md@@ -44,6 +44,12 @@ _string_Same as CSS style `font-spacing`.+### `fontVariantNumeric`<AvailableFrom v="4.0.57"/>++_string_++Same as CSS style `font-variant-numeric`.+## Return valueAn object with `height` and `width`diff --git a/packages/layout-utils/src/layouts/measure-text.ts b/packages/layout-utils/src/layouts/measure-text.tsindex 341aad7bba..2789c33b8b 100644--- a/packages/layout-utils/src/layouts/measure-text.ts+++ b/packages/layout-utils/src/layouts/measure-text.ts@@ -9,6 +9,7 @@ export type Word = {fontSize: number;fontWeight?: number | string;letterSpacing?: string;+ fontVariantNumeric?: string;};const wordCache = new Map<string, Dimensions>();@@ -19,6 +20,7 @@ export const measureText = ({fontSize,fontWeight,letterSpacing,+ fontVariantNumeric,}: Word): Dimensions => {const key = `${text}-${fontFamily}-${fontWeight}-${fontSize}-${letterSpacing}`;@@ -33,15 +35,20 @@ export const measureText = ({node.style.position = 'absolute';node.style.top = `-10000px`;node.style.whiteSpace = 'pre';+ node.style.fontSize = `${fontSize}px`;+if (fontWeight) {node.style.fontWeight = fontWeight.toString();}- node.style.fontSize = `${fontSize}px`;if (letterSpacing) {node.style.letterSpacing = letterSpacing;}+ if (fontVariantNumeric) {+ node.style.fontVariantNumeric = fontVariantNumeric;+ }+node.innerText = text;document.body.appendChild(node);