Change info.txt logic to font.json

This commit is contained in:
Tetrakern 2024-02-07 12:28:49 +01:00
parent 2336d35573
commit 9c293e98a3
6 changed files with 48 additions and 48 deletions

1
fonts/lato/font.css Normal file
View File

@ -0,0 +1 @@
/* stub */

1
fonts/open-sans/font.css Normal file
View File

@ -0,0 +1 @@
/* stub */

24
fonts/open-sans/font.json Normal file
View File

@ -0,0 +1,24 @@
{
"skip": true,
"version": "40",
"key": "open-sans",
"name": "Open Sans",
"family": "'Open Sans'",
"type": "sans-serif",
"styles": ["normal", "italic"],
"weights": [300, 325, 400, 500, 600, 700],
"charsets": ["cyrillic", "cyrillic-ext", "greek", "greek-ext", "hebrew", "latin", "latin-ext", "vietnamese"],
"formats": ["woff2"],
"about": "Open Sans is a humanist sans serif typeface designed by Steve Matteson, Type Director of Ascender Corp. This version contains the complete 897 character set, which includes the standard ISO Latin 1, Latin CE, Greek and Cyrillic character sets. Open Sans was designed with an upright stress, open forms and a neutral, yet friendly appearance. It was optimized for print, web, and mobile interfaces, and has excellent legibility characteristics in its letterforms.",
"note": "Custom version with 325 font weight. Not used by default.",
"sources": {
"googleFonts": {
"name": "Google Fonts",
"url": "https://fonts.google.com/specimen/Open+Sans"
},
"googleWebfontsHelper": {
"name": "Google Webfonts Helper",
"url": "https://gwfh.mranftl.com/fonts/open-sans?subsets=cyrillic,cyrillic-ext,greek,greek-ext,hebrew,latin,latin-ext,vietnamese"
}
}
}

View File

@ -1,12 +0,0 @@
Skip: true
Name: Open Sans
Family: 'Open Sans'
Type: sans-serif
Styles: normal, italic
Weights: 300, 325, 400, 500, 600, 700
Charsets: cyrillic, cyrillic-ext, greek, greek-ext, hebrew, latin, latin-ext, vietnamese
Formats: woff2
Version: 40
About: Open Sans is a humanist sans serif typeface designed by Steve Matteson, Type Director of Ascender Corp. This version contains the complete 897 character set, which includes the standard ISO Latin 1, Latin CE, Greek and Cyrillic character sets. Open Sans was designed with an upright stress, open forms and a neutral, yet friendly appearance. It was optimized for print, web, and mobile interfaces, and has excellent legibility characteristics in its letterforms.
Note: Custom version with 325 font weight.
Sources: Google Fonts|https://fonts.google.com/specimen/Open+Sans ||| Google Webfonts Helper|https://gwfh.mranftl.com/fonts/open-sans?subsets=cyrillic,cyrillic-ext,greek,greek-ext,hebrew,latin,latin-ext,vietnamese

View File

@ -2747,20 +2747,19 @@ function fictioneer_get_font_data() {
}
$full_path = "{$font_dir}/{$path}";
$info_file = "$full_path/info.txt";
$json_file = "$full_path/font.json";
$css_file = "$full_path/font.css";
if ( is_dir( $full_path ) && file_exists( $info_file ) && file_exists( $css_file ) ) {
if ( is_dir( $full_path ) && file_exists( $json_file ) && file_exists( $css_file ) ) {
$folder = basename( $path );
$info = array( 'css_path' => "/fonts/{$folder}/font.css", 'css_file' => $css_file );
$lines = file( $info_file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES );
$data = @json_decode( file_get_contents( $json_file ), true );
foreach ( $lines as $line ) {
list( $key, $value ) = explode( ':', $line, 2 );
$info[ trim( strtolower( $key ) ) ] = trim( $value );
if ( $data && json_last_error() === JSON_ERROR_NONE ) {
$data['css_path'] = "/fonts/{$folder}/font.css";
$data['css_file'] = $css_file;
$fonts[ $data['key'] ] = $data;
}
$fonts[ $folder ] = $info;
}
}
}

View File

@ -37,34 +37,19 @@ $fonts = fictioneer_get_font_data();
<?php foreach ( $fonts as $key => $font ) : ?>
<?php
$fallback = _x( 'n/a', 'Settings font card.', 'fictioneer' );
$name = $font['name'] ?? $key;
$family = $font['family'] ?? _x( 'n/a', 'Settings font card.', 'fictioneer' );
$family = $font['family'] ?? $fallback;
$type = $font['type'] ?? '';
$skip = $font['skip'] ?? false;
$version = $font['version'] ?? '';
$charsets = $font['charsets'] ?? _x( 'n/a', 'Settings font card.', 'fictioneer' );
$formats = $font['formats'] ?? _x( 'n/a', 'Settings font card.', 'fictioneer' );
$charsets = $font['charsets'] ?? [ $fallback ];
$formats = $font['formats'] ?? [ $fallback ];
$about = $font['about'] ?? _x( 'No description provided', 'Settings font card.', 'fictioneer' );
$weights = $font['weights'] ?? _x( 'n/a', 'Settings font card.', 'fictioneer' );
$styles = $font['styles'] ?? _x( 'n/a', 'Settings font card.', 'fictioneer' );
$sources = empty( $font['sources'] ?? '' ) ? '' : explode( '|||', $font['sources'] );
$links = [];
$weights = $font['weights'] ?? [ $fallback ];
$styles = $font['styles'] ?? [ $fallback ];
$sources = $font['sources'] ?? [];
$note = $font['note'] ?? '';
if ( ! empty( $sources ) ) {
$links = array_map(
function( $source ) {
$parts = explode( '|', $source );
if ( count( $parts ) < 2 ) {
$parts = [ _x( 'Link', 'Settings font card.', 'fictioneer' ), $parts[0] ];
}
return sprintf( '<a href="%s" target="_blank">%s</a>', trim( $parts[1] ), trim( $parts[0] ) );
},
$sources
);
}
?>
<div class="fictioneer-card">
@ -91,7 +76,9 @@ $fonts = fictioneer_get_font_data();
'fictioneer'
);
echo implode( ', ', $links );
foreach ( $sources as $source ) {
printf( '<a href="%s" target="_blank">%s</a>', $source['url'], $source['name'] );
}
}
?></div>
@ -107,21 +94,21 @@ $fonts = fictioneer_get_font_data();
<div class="fictioneer-card__box-title"><?php
_ex( 'Weights', 'Settings font card.', 'fictioneer' );
?></div>
<div class="fictioneer-card__box-content"><?php echo $weights; ?></div>
<div class="fictioneer-card__box-content"><?php echo implode( ', ', $weights ); ?></div>
</div>
<div class="fictioneer-card__box">
<div class="fictioneer-card__box-title"><?php
_ex( 'Styles', 'Settings font card.', 'fictioneer' );
?></div>
<div class="fictioneer-card__box-content"><?php echo $styles; ?></div>
<div class="fictioneer-card__box-content"><?php echo implode( ', ', $styles ); ?></div>
</div>
<div class="fictioneer-card__box">
<div class="fictioneer-card__box-title"><?php
_ex( 'Formats', 'Settings font card.', 'fictioneer' );
?></div>
<div class="fictioneer-card__box-content"><?php echo $formats; ?></div>
<div class="fictioneer-card__box-content"><?php echo implode( ', ', $formats ); ?></div>
</div>
<div class="fictioneer-card__box">
@ -141,7 +128,7 @@ $fonts = fictioneer_get_font_data();
<div class="fictioneer-card__box-title"><?php
_ex( 'Charsets', 'Settings font card.', 'fictioneer' );
?></div>
<div class="fictioneer-card__box-content"><?php echo $charsets; ?></div>
<div class="fictioneer-card__box-content"><?php echo implode( ', ', $charsets ); ?></div>
</div>
</div>