Skip to content

Commit b09bd4e

Browse files
authored
Fonts: Add Noto Serif SC, KR, and subsetting tool for CJK (#684)
* Fonts: Add Noto Serif CJK, Simplified Chinese version * Add Noto Serif SC font to preloader script * Switch to a filter for font settings * Use the correct region-subsetted font * Fonts: Add Noto Serif KR * Try font subsetting for CJK fonts * Update bin/font-subset-cjk.js
1 parent 06a21af commit b09bd4e

File tree

80 files changed

+3178
-2201
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+3178
-2201
lines changed

bin/font-subset-cjk.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env node
2+
/* eslint-disable no-console */
3+
/**
4+
* Prerequisite:
5+
* 1. `yarn` to make sure you have the current packages.
6+
* Usage:
7+
* 1. Add {"type": "module"} to package.json.
8+
* 2. Add the `.ttf` font to /fonts/.
9+
* 3. Update the fontNames value.
10+
* 4. Run 'yarn font-subset-cjk'.
11+
* 5. Remove {"type": "module"} from package.json or the linter would prompt an error.
12+
*/
13+
import { readFileSync, unlinkSync } from 'node:fs';
14+
import path from 'node:path';
15+
import { fontSplit } from 'cn-font-split';
16+
17+
const fontNames = [ 'NotoSerifJP', 'NotoSerifKR', 'NotoSerifSC' ];
18+
19+
for ( let i = 0; i < fontNames.length; i++ ) {
20+
const fontName = fontNames[ i ];
21+
const fontPath = path.resolve( `./fonts/${ fontName }.ttf` );
22+
const inputBuffer = new Uint8Array( readFileSync( fontPath ).buffer );
23+
const outputDir = `./mu-plugins/global-fonts/NotoSerif/${ fontName }`;
24+
25+
await fontSplit( {
26+
input: inputBuffer,
27+
outDir: outputDir,
28+
// This seems to be a maximum, not average. Subset files won't exceed this size.
29+
chunkSize: 5 * 1024 * 1024, // 5MB
30+
reduceMins: false,
31+
renameOutputFont: `${ fontName }-[index].[ext]`,
32+
testHtml: false,
33+
reporter: false,
34+
css: {
35+
compress: false,
36+
fileName: 'style.css',
37+
},
38+
silent: false,
39+
} );
40+
41+
// Remove unnecessary file.
42+
unlinkSync( `${ outputDir }/index.proto` );
43+
}

fonts/NotoSerifJP.ttf

12.9 MB
Binary file not shown.

fonts/NotoSerifKR.ttf

22.7 MB
Binary file not shown.

fonts/NotoSerifSC.ttf

24 MB
Binary file not shown.

mu-plugins/blocks/global-header-footer/blocks.php

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -359,17 +359,15 @@ function render_global_header( $attributes = array() ) {
359359

360360
// Preload the menu font.
361361
if ( is_callable( 'global_fonts_preload' ) ) {
362-
if ( 'ckb' === get_locale() ) {
363-
global_fonts_preload( 'Noto Kufi', 'arabic' );
364-
} else {
365-
/*
366-
* translators: Font subset for your locale. Can be any of cyrillic,
367-
* cyrillic-ext, greek, greek-ext, vietnamese, latin, latin-ext.
368-
* Do not translate into your own language.
369-
*/
370-
$subsets = _x( 'latin', 'Inter subsets, comma separated', 'wporg' );
371-
global_fonts_preload( 'Inter', $subsets );
372-
}
362+
/*
363+
* translators: Font subset for your locale. Can be any of cyrillic,
364+
* cyrillic-ext, greek, greek-ext, vietnamese, latin, latin-ext.
365+
* Do not translate into your own language. If you don't use Inter
366+
* for body text, you can ignore this.
367+
*/
368+
$subsets = _x( 'latin', 'Inter subsets, comma separated', 'wporg' );
369+
list( $font, $subsets ) = apply_filters( 'wporg_preload_body_font', [ 'Inter', $subsets ] );
370+
global_fonts_preload( $font, $subsets );
373371
}
374372

375373
// The mobile Get WordPress button needs to be in both menus.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)