Add font value quote wrapper utility

This commit is contained in:
Tetrakern 2024-02-07 22:14:08 +01:00
parent 84d70f8541
commit 0b6c8ee464
7 changed files with 31 additions and 8 deletions

View File

@ -4,7 +4,7 @@
"version": "16",
"key": "cormorant-garamond",
"name": "Cormorant Garamond",
"family": "'Cormorant Garamond'",
"family": "Cormorant Garamond",
"alt": "Garamond",
"type": "serif",
"styles": ["normal", "italic"],

View File

@ -4,7 +4,7 @@
"version": "19",
"key": "crimson-text",
"name": "Crimson Text",
"family": "'Crimson Text'",
"family": "Crimson Text",
"type": "serif",
"styles": ["normal", "italic"],
"weights": [400, 600, 700],

View File

@ -4,7 +4,7 @@
"version": "",
"key": "helvetica-neue",
"name": "Helvetica Neue",
"family": "'Helvetica Neue'",
"family": "Helvetica Neue",
"alt": "Helvetica, Arial",
"type": "sans-serif",
"styles": ["normal", "italic"],

View File

@ -4,7 +4,7 @@
"version": "40",
"key": "open-sans",
"name": "Open Sans",
"family": "'Open Sans'",
"family": "Open Sans",
"type": "sans-serif",
"styles": ["normal", "italic"],
"weights": [300, 325, 400, 500, 600, 700],

View File

@ -4,7 +4,7 @@
"version": "23",
"key": "roboto-mono",
"name": "Roboto Mono",
"family": "'Roboto Mono'",
"family": "Roboto Mono",
"type": "monospace",
"styles": ["normal", "italic"],
"weights": [300, 400, 500, 600, 700],

View File

@ -4,7 +4,7 @@
"version": "13",
"key": "roboto-serif",
"name": "Roboto Serif",
"family": "'Roboto Serif'",
"family": "Roboto Serif",
"type": "serif",
"styles": ["normal", "italic"],
"weights": [300, 400, 500, 600, 700],

View File

@ -1977,7 +1977,7 @@ if ( ! function_exists( 'fictioneer_get_fonts' ) ) {
// Setup
$custom_fonts = get_option( 'fictioneer_chapter_fonts' );
$fonts = array(
array( 'css' => "'" . FICTIONEER_PRIMARY_FONT_CSS . "'", 'name' => FICTIONEER_PRIMARY_FONT_NAME ),
array( 'css' => fictioneer_font_family_value( FICTIONEER_PRIMARY_FONT_CSS ), 'name' => FICTIONEER_PRIMARY_FONT_NAME ),
array( 'css' => '', 'name' => _x( 'System Font', 'Font name.', 'fictioneer' ) )
);
@ -1997,6 +1997,29 @@ if ( ! function_exists( 'fictioneer_get_fonts' ) ) {
}
}
// =============================================================================
// WRAP MULTI-WORD FONTS INTO QUOTES
// =============================================================================
/**
* Returns font family value with quotes if required
*
* @since 5.10.0
*
* @param string $font_value The font family value.
* @param string $quote Optional. The wrapping character. Default '"'.
*
* @return string Ready to use font family value.
*/
function fictioneer_font_family_value( $font_value, $quote = '"' ) {
if ( preg_match( '/\s/', $font_value ) ) {
return $quote . $font_value . $quote;
} else {
return $font_value;
}
}
// =============================================================================
// GET FONT COLORS
// =============================================================================
@ -2792,7 +2815,7 @@ function fictioneer_build_bundled_fonts() {
foreach ( $fonts as $font ) {
if ( $font['chapter'] ?? 0 ) {
$font_stack[ $font['key'] ] = array(
'css' => $font['family'] ?? '',
'css' => fictioneer_font_family_value( $font['family'] ?? '' ),
'name' => $font['name'] ?? '',
'alt' => $font['alt'] ?? ''
);