@@ -35,9 +35,24 @@ public static function renderCustomUserStyle(array $config): string
3535
3636 $ fontCss = '' ;
3737
38+ $ loadedFontUrls = [];
39+
40+ $ appendFontFace = static function (string $ family , string $ path ) use (&$ fontCss , &$ loadedFontUrls ): string {
41+ $ url = PathUtility::getPublicPath ($ path );
42+
43+ // Avoid emitting duplicate @font-face rules when the same font file is used in multiple slots.
44+ if (!isset ($ loadedFontUrls [$ url ])) {
45+ $ loadedFontUrls [$ url ] = $ family ;
46+ $ fontCss .= "@font-face {font-family:' {$ family }';src:url(' {$ url }') format('truetype');font-display:swap;} \n" ;
47+ }
48+
49+ return $ loadedFontUrls [$ url ];
50+ };
51+
3852 // Default font
3953 if (!empty ($ config ['fonts ' ]['default ' ])) {
40- $ fontCss .= "@font-face {font-family:'DefaultFont';src:url(' " . PathUtility::getPublicPath ($ config ['fonts ' ]['default ' ]) . "') format('truetype');font-display:swap;} \n" ;
54+ $ fontFamily = $ appendFontFace ('DefaultFont ' , $ config ['fonts ' ]['default ' ]);
55+ $ properties ['--font-family-default ' ] = $ fontFamily ;
4156 }
4257 if (!empty ($ config ['fonts ' ]['default_color ' ])) {
4358 $ properties ['--font-color ' ] = $ config ['fonts ' ]['default_color ' ];
@@ -47,51 +62,53 @@ public static function renderCustomUserStyle(array $config): string
4762
4863 // Start screen font
4964 if (!empty ($ config ['fonts ' ]['start_screen_title ' ])) {
50- $ fontCss .= "@font-face {font-family:'StartScreenFont';src:url(' " . PathUtility::getPublicPath ($ config ['fonts ' ]['start_screen_title ' ]) . "') format('truetype');font-display:swap;} \n" ;
65+ $ fontFamily = $ appendFontFace ('StartScreenFont ' , $ config ['fonts ' ]['start_screen_title ' ]);
66+ $ properties ['--font-family-start-text ' ] = $ fontFamily ;
5167 }
5268 $ properties ['--start-text-color ' ] = $ config ['fonts ' ]['start_screen_title_color ' ] ?? '__UNSET__ ' ;
5369 $ properties ['--start-text-weight ' ] = !empty ($ config ['fonts ' ]['start_screen_title_bold ' ]) ? '700 ' : '400 ' ;
5470 $ properties ['--start-text-style ' ] = !empty ($ config ['fonts ' ]['start_screen_title_italic ' ]) ? 'italic ' : 'normal ' ;
5571
5672 // Event font
5773 if (!empty ($ config ['fonts ' ]['event_text ' ])) {
58- $ fontCss .= "@font-face {font-family:'EventFont';src:url(' " . PathUtility::getPublicPath ($ config ['fonts ' ]['event_text ' ]) . "') format('truetype');font-display:swap;} \n" ;
74+ $ fontFamily = $ appendFontFace ('EventFont ' , $ config ['fonts ' ]['event_text ' ]);
75+ $ properties ['--font-family-event-text ' ] = $ fontFamily ;
5976 }
6077 $ properties ['--event-text-color ' ] = $ config ['fonts ' ]['event_text_color ' ] ?? '__UNSET__ ' ;
6178 $ properties ['--event-text-weight ' ] = !empty ($ config ['fonts ' ]['event_text_bold ' ]) ? '700 ' : '400 ' ;
6279 $ properties ['--event-text-style ' ] = !empty ($ config ['fonts ' ]['event_text_italic ' ]) ? 'italic ' : 'normal ' ;
6380
6481 // Gallery title font
6582 if (!empty ($ config ['fonts ' ]['gallery_title ' ])) {
66- $ fontCss .= "@font-face {font-family:'GalleryFont';src:url(' " . PathUtility::getPublicPath ($ config ['fonts ' ]['gallery_title ' ]) . "') format('truetype');font-display:swap;} \n" ;
83+ $ fontFamily = $ appendFontFace ('GalleryFont ' , $ config ['fonts ' ]['gallery_title ' ]);
84+ $ properties ['--font-family-gallery-title ' ] = $ fontFamily ;
6785 }
6886 $ properties ['--gallery-title-color ' ] = $ config ['fonts ' ]['gallery_title_color ' ] ?? '__UNSET__ ' ;
6987 $ properties ['--gallery-title-weight ' ] = !empty ($ config ['fonts ' ]['gallery_title_bold ' ]) ? '700 ' : '400 ' ;
7088 $ properties ['--gallery-title-style ' ] = !empty ($ config ['fonts ' ]['gallery_title_italic ' ]) ? 'italic ' : 'normal ' ;
7189
7290 // Screensaver font
7391 if (!empty ($ config ['fonts ' ]['screensaver_text ' ])) {
74- $ fontCss .= "@font-face {font-family:'ScreensaverFont';src:url(' " . PathUtility::getPublicPath ($ config ['fonts ' ]['screensaver_text ' ]) . "') format('truetype');font-display:swap;} \n" ;
75- } elseif (!empty ($ config ['screensaver ' ]['text_font ' ])) {
76- // fallback to legacy location
77- $ fontCss .= "@font-face {font-family:'ScreensaverFont';src:url(' " . PathUtility::getPublicPath ($ config ['screensaver ' ]['text_font ' ]) . "') format('truetype');font-display:swap;} \n" ;
92+ $ fontFamily = $ appendFontFace ('ScreensaverFont ' , $ config ['fonts ' ]['screensaver_text ' ]);
93+ $ properties ['--font-family-screensaver-text ' ] = $ fontFamily ;
7894 }
79- $ properties ['--screensaver-text-color ' ] = $ config ['fonts ' ]['screensaver_text_color ' ]
80- ?? ($ config ['screensaver ' ]['text_color ' ] ?? '#ffffff ' );
95+ $ properties ['--screensaver-text-color ' ] = $ config ['fonts ' ]['screensaver_text_color ' ] ?? '__UNSET__ ' ;
8196 $ properties ['--screensaver-text-weight ' ] = !empty ($ config ['fonts ' ]['screensaver_text_bold ' ]) ? '700 ' : '400 ' ;
8297 $ properties ['--screensaver-text-style ' ] = !empty ($ config ['fonts ' ]['screensaver_text_italic ' ]) ? 'italic ' : 'normal ' ;
8398
8499 // Font variables (button)
85100 if (!empty ($ config ['fonts ' ]['button_font ' ])) {
86- $ fontCss .= "@font-face {font-family:'ButtonFont';src:url(' " . PathUtility::getPublicPath ($ config ['fonts ' ]['button_font ' ]) . "') format('truetype');font-display:swap;} \n" ;
101+ $ fontFamily = $ appendFontFace ('ButtonFont ' , $ config ['fonts ' ]['button_font ' ]);
102+ $ properties ['--font-family-button ' ] = $ fontFamily ;
87103 }
88104 $ properties ['--button-font-color ' ] = $ config ['fonts ' ]['button_font_color ' ] ?? '__UNSET__ ' ;
89105 $ properties ['--button-font-weight ' ] = !empty ($ config ['fonts ' ]['button_font_bold ' ]) ? '700 ' : '400 ' ;
90106 $ properties ['--button-font-style ' ] = !empty ($ config ['fonts ' ]['button_font_italic ' ]) ? 'italic ' : 'normal ' ;
91107
92108 // Font variables (buzzer message)
93109 if (!empty ($ config ['fonts ' ]['button_buzzer_message_font ' ])) {
94- $ fontCss .= "@font-face {font-family:'BuzzerMessageFont';src:url(' " . PathUtility::getPublicPath ($ config ['fonts ' ]['button_buzzer_message_font ' ]) . "') format('truetype');font-display:swap;} \n" ;
110+ $ fontFamily = $ appendFontFace ('BuzzerMessageFont ' , $ config ['fonts ' ]['button_buzzer_message_font ' ]);
111+ $ properties ['--font-family-button_buzzer_message ' ] = $ fontFamily ;
95112 }
96113 $ properties ['--buzzer-message-font-color ' ] = $ config ['fonts ' ]['button_buzzer_message_font_color ' ] ?? '__UNSET__ ' ;
97114 $ properties ['--buzzer-message-font-weight ' ] = !empty ($ config ['fonts ' ]['button_buzzer_message_font_bold ' ]) ? '700 ' : '400 ' ;
0 commit comments