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", "version": "16",
"key": "cormorant-garamond", "key": "cormorant-garamond",
"name": "Cormorant Garamond", "name": "Cormorant Garamond",
"family": "'Cormorant Garamond'", "family": "Cormorant Garamond",
"alt": "Garamond", "alt": "Garamond",
"type": "serif", "type": "serif",
"styles": ["normal", "italic"], "styles": ["normal", "italic"],

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1977,7 +1977,7 @@ if ( ! function_exists( 'fictioneer_get_fonts' ) ) {
// Setup // Setup
$custom_fonts = get_option( 'fictioneer_chapter_fonts' ); $custom_fonts = get_option( 'fictioneer_chapter_fonts' );
$fonts = array( $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' ) ) 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 // GET FONT COLORS
// ============================================================================= // =============================================================================
@ -2792,7 +2815,7 @@ function fictioneer_build_bundled_fonts() {
foreach ( $fonts as $font ) { foreach ( $fonts as $font ) {
if ( $font['chapter'] ?? 0 ) { if ( $font['chapter'] ?? 0 ) {
$font_stack[ $font['key'] ] = array( $font_stack[ $font['key'] ] = array(
'css' => $font['family'] ?? '', 'css' => fictioneer_font_family_value( $font['family'] ?? '' ),
'name' => $font['name'] ?? '', 'name' => $font['name'] ?? '',
'alt' => $font['alt'] ?? '' 'alt' => $font['alt'] ?? ''
); );