@@ -44,6 +44,40 @@ export const FONT_FAMILY_FALLBACKS = Object.freeze({
4444 */
4545export const DEFAULT_GENERIC_FALLBACK = 'sans-serif' ;
4646
47+ /**
48+ * Known serif-like font families used as a heuristic when OOXML `w:family`
49+ * is unavailable. This keeps fallbacks closer to Word metrics for fonts like Cambria.
50+ */
51+ const SERIF_LIKE_FONTS = new Set ( [
52+ 'cambria' ,
53+ 'cambria math' ,
54+ 'times' ,
55+ 'times new roman' ,
56+ 'georgia' ,
57+ 'garamond' ,
58+ 'palatino' ,
59+ 'palatino linotype' ,
60+ 'book antiqua' ,
61+ 'baskerville' ,
62+ 'cochin' ,
63+ 'hoefler text' ,
64+ 'minion pro' ,
65+ 'didot' ,
66+ 'bodoni mt' ,
67+ 'constantia' ,
68+ ] ) ;
69+
70+ const normalizeFontNameForLookup = ( fontName ) => {
71+ if ( ! fontName || typeof fontName !== 'string' ) return '' ;
72+ return fontName
73+ . trim ( )
74+ . replace ( / ^ [ " ' ] | [ " ' ] $ / g, '' )
75+ . toLowerCase ( ) ;
76+ } ;
77+
78+ const inferGenericFallbackFromFontName = ( fontName ) =>
79+ SERIF_LIKE_FONTS . has ( normalizeFontNameForLookup ( fontName ) ) ? 'serif' : DEFAULT_GENERIC_FALLBACK ;
80+
4781/**
4882 * Normalizes a comma-separated font-family string into an array of trimmed, non-empty parts.
4983 *
@@ -189,7 +223,7 @@ export function mapWordFamilyFallback(wordFamily) {
189223 * @example
190224 * // Basic usage with default fallback
191225 * toCssFontFamily('Arial'); // "Arial, sans-serif"
192- * toCssFontFamily('Times New Roman'); // "Times New Roman, sans- serif"
226+ * toCssFontFamily('Times New Roman'); // "Times New Roman, serif"
193227 *
194228 * @example
195229 * // Custom explicit fallback
@@ -244,7 +278,9 @@ export function toCssFontFamily(fontName, options = {}) {
244278
245279 const { fallback, wordFamily } = options ;
246280 const fallbackValue =
247- fallback ?? ( wordFamily ? mapWordFamilyFallback ( wordFamily ) : undefined ) ?? DEFAULT_GENERIC_FALLBACK ;
281+ fallback ??
282+ ( wordFamily ? mapWordFamilyFallback ( wordFamily ) : undefined ) ??
283+ inferGenericFallbackFromFontName ( trimmed ) ;
248284
249285 const fallbackParts = normalizeParts ( fallbackValue ) ;
250286 if ( fallbackParts . length === 0 ) {
0 commit comments