-
Notifications
You must be signed in to change notification settings - Fork 330
/
Copy pathclass-kirki-fonts.php
244 lines (220 loc) · 6.42 KB
/
class-kirki-fonts.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
<?php
/**
* A simple object containing properties for fonts.
*
* @package Kirki
* @category Core
* @author Aristeides Stathopoulos
* @copyright Copyright (c) 2016, Aristeides Stathopoulos
* @license http://opensource.org/licenses/https://opensource.org/licenses/MIT
* @since 1.0
*/
if ( ! class_exists( 'Kirki_Fonts' ) ) {
/**
* The Kirki_Fonts object.
*/
final class Kirki_Fonts {
/**
* The mode we'll be using to add google fonts.
* This is a todo item, not yet functional.
*
* @static
* @todo
* @access public
* @var string
*/
public static $mode = 'link';
/**
* Holds a single instance of this object.
*
* @static
* @access private
* @var null|object
*/
private static $instance = null;
/**
* An array of our google fonts.
*
* @static
* @access public
* @var null|object
*/
public static $google_fonts = null;
/**
* The class constructor.
*/
private function __construct() {}
/**
* Get the one, true instance of this class.
* Prevents performance issues since this is only loaded once.
*
* @return object Kirki_Fonts
*/
public static function get_instance() {
if ( null === self::$instance ) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Compile font options from different sources.
*
* @return array All available fonts.
*/
public static function get_all_fonts() {
$standard_fonts = self::get_standard_fonts();
$google_fonts = self::get_google_fonts();
return apply_filters( 'kirki/fonts/all', array_merge( $standard_fonts, $google_fonts ) );
}
/**
* Return an array of standard websafe fonts.
*
* @return array Standard websafe fonts.
*/
public static function get_standard_fonts() {
$standard_fonts = array(
'serif' => array(
'label' => 'Serif',
'stack' => 'Georgia,Times,"Times New Roman",serif',
),
'sans-serif' => array(
'label' => 'Sans Serif',
'stack' => 'Helvetica,Arial,sans-serif',
),
'monospace' => array(
'label' => 'Monospace',
'stack' => 'Monaco,"Lucida Sans Typewriter","Lucida Typewriter","Courier New",Courier,monospace',
),
);
return apply_filters( 'kirki/fonts/standard_fonts', $standard_fonts );
}
/**
* Return an array of backup fonts based on the font-category
*
* @return array
*/
public static function get_backup_fonts() {
$backup_fonts = array(
'sans-serif' => 'Helvetica, Arial, sans-serif',
'serif' => 'Georgia, serif',
'display' => '"Comic Sans MS", cursive, sans-serif',
'handwriting' => '"Comic Sans MS", cursive, sans-serif',
'monospace' => '"Lucida Console", Monaco, monospace',
);
return apply_filters( 'kirki/fonts/backup_fonts', $backup_fonts );
}
/**
* Return an array of all available Google Fonts.
*
* @return array All Google Fonts.
*/
public static function get_google_fonts() {
if ( null === self::$google_fonts || empty( self::$google_fonts ) ) {
$fonts = include wp_normalize_path( Kirki::$path . '/core/webfonts.php' );
$google_fonts = array();
if ( is_array( $fonts ) ) {
foreach ( $fonts['items'] as $font ) {
$google_fonts[ $font['family'] ] = array(
'label' => $font['family'],
'variants' => $font['variants'],
'subsets' => $font['subsets'],
'category' => $font['category'],
);
}
}
self::$google_fonts = apply_filters( 'kirki/fonts/google_fonts', $google_fonts );
}
return self::$google_fonts;
}
/**
* Dummy function to avoid issues with backwards-compatibility.
* This is not functional, but it will prevent PHP Fatal errors.
*
* @static
* @access public
*/
public static function get_google_font_uri() {}
/**
* Returns an array of all available subsets.
*
* @static
* @access public
* @return array
*/
public static function get_google_font_subsets() {
return array(
'cyrillic' => 'Cyrillic',
'cyrillic-ext' => 'Cyrillic Extended',
'devanagari' => 'Devanagari',
'greek' => 'Greek',
'greek-ext' => 'Greek Extended',
'khmer' => 'Khmer',
'latin' => 'Latin',
'latin-ext' => 'Latin Extended',
'vietnamese' => 'Vietnamese',
'hebrew' => 'Hebrew',
'arabic' => 'Arabic',
'bengali' => 'Bengali',
'gujarati' => 'Gujarati',
'tamil' => 'Tamil',
'telugu' => 'Telugu',
'thai' => 'Thai',
);
}
/**
* Returns an array of all available variants.
*
* @static
* @access public
* @return array
*/
public static function get_all_variants() {
return apply_filters( 'kirki/l10n', array(
'100light' => esc_attr__( 'Ultra-Light 100', 'kirki' ),
'100italic' => esc_attr__( 'Ultra-Light 100 Italic', 'kirki' ),
'200' => esc_attr__( 'Light 200', 'kirki' ),
'200italic' => esc_attr__( 'Light 200 Italic', 'kirki' ),
'300' => esc_attr__( 'Book 300', 'kirki' ),
'300italic' => esc_attr__( 'Book 300 Italic', 'kirki' ),
'regular' => esc_attr__( 'Normal 400', 'kirki' ),
'italic' => esc_attr__( 'Normal 400 Italic', 'kirki' ),
'500' => esc_attr__( 'Medium 500', 'kirki' ),
'500italic' => esc_attr__( 'Medium 500 Italic', 'kirki' ),
'600bold' => esc_attr__( 'Semi-Bold 600', 'kirki' ),
'600italic' => esc_attr__( 'Semi-Bold 600 Italic', 'kirki' ),
'700' => esc_attr__( 'Bold 700', 'kirki' ),
'700italic' => esc_attr__( 'Bold 700 Italic', 'kirki' ),
'800bold' => esc_attr__( 'Extra-Bold 800', 'kirki' ),
'800italic' => esc_attr__( 'Extra-Bold 800 Italic', 'kirki' ),
'900bold' => esc_attr__( 'Ultra-Bold 900', 'kirki' ),
'900italic' => esc_attr__( 'Ultra-Bold 900 Italic', 'kirki' ),
) );
}
/**
* Determine if a font-name is a valid google font or not.
*
* @static
* @access public
* @param string $fontname The name of the font we want to check.
* @return bool
*/
public static function is_google_font( $fontname ) {
return ( array_key_exists( $fontname, self::$google_fonts ) );
}
/**
* Gets available options for a font.
*
* @static
* @access public
* @return array
*/
public static function get_font_choices() {
$fonts = self::get_all_fonts();
$fonts_array = array();
foreach ( $fonts as $key => $args ) {
$fonts_array[ $key ] = $key;
}
return $fonts_array;
}
}
}