PluginProbe
Gutenberg / 14.7.0
Gutenberg v14.7.0
24.0.0 23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 12.6.0 All 403 releases
gutenberg / lib / block-supports / typography.php

typography.php in Gutenberg 14.7.0, at lib/block-supports/typography.php

557 lines 23.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Typography block support flag.
4 *
5 * @package gutenberg
6 */
7
8 /**
9 * Registers the style and typography block attributes for block types that support it.
10 *
11 * @param WP_Block_Type $block_type Block Type.
12 */
13 function gutenberg_register_typography_support( $block_type ) {
14 if ( ! property_exists( $block_type, 'supports' ) ) {
15 return;
16 }
17
18 $typography_supports = _wp_array_get( $block_type->supports, array( 'typography' ), false );
19 if ( ! $typography_supports ) {
20 return;
21 }
22
23 $has_font_family_support = _wp_array_get( $typography_supports, array( '__experimentalFontFamily' ), false );
24 $has_font_size_support = _wp_array_get( $typography_supports, array( 'fontSize' ), false );
25 $has_font_style_support = _wp_array_get( $typography_supports, array( '__experimentalFontStyle' ), false );
26 $has_font_weight_support = _wp_array_get( $typography_supports, array( '__experimentalFontWeight' ), false );
27 $has_letter_spacing_support = _wp_array_get( $typography_supports, array( '__experimentalLetterSpacing' ), false );
28 $has_line_height_support = _wp_array_get( $typography_supports, array( 'lineHeight' ), false );
29 $has_text_decoration_support = _wp_array_get( $typography_supports, array( '__experimentalTextDecoration' ), false );
30 $has_text_transform_support = _wp_array_get( $typography_supports, array( '__experimentalTextTransform' ), false );
31
32 $has_typography_support = $has_font_family_support
33 || $has_font_size_support
34 || $has_font_style_support
35 || $has_font_weight_support
36 || $has_letter_spacing_support
37 || $has_line_height_support
38 || $has_text_decoration_support
39 || $has_text_transform_support;
40
41 if ( ! $block_type->attributes ) {
42 $block_type->attributes = array();
43 }
44
45 if ( $has_typography_support && ! array_key_exists( 'style', $block_type->attributes ) ) {
46 $block_type->attributes['style'] = array(
47 'type' => 'object',
48 );
49 }
50
51 if ( $has_font_size_support && ! array_key_exists( 'fontSize', $block_type->attributes ) ) {
52 $block_type->attributes['fontSize'] = array(
53 'type' => 'string',
54 );
55 }
56
57 if ( $has_font_family_support && ! array_key_exists( 'fontFamily', $block_type->attributes ) ) {
58 $block_type->attributes['fontFamily'] = array(
59 'type' => 'string',
60 );
61 }
62 }
63
64 /**
65 * Add CSS classes and inline styles for typography features such as font sizes
66 * to the incoming attributes array. This will be applied to the block markup in
67 * the front-end.
68 *
69 * @param WP_Block_Type $block_type Block type.
70 * @param array $block_attributes Block attributes.
71 *
72 * @return array Typography CSS classes and inline styles.
73 */
74 function gutenberg_apply_typography_support( $block_type, $block_attributes ) {
75 if ( ! property_exists( $block_type, 'supports' ) ) {
76 return array();
77 }
78
79 $typography_supports = _wp_array_get( $block_type->supports, array( 'typography' ), false );
80 if ( ! $typography_supports ) {
81 return array();
82 }
83
84 if ( gutenberg_should_skip_block_supports_serialization( $block_type, 'typography' ) ) {
85 return array();
86 }
87
88 $has_font_family_support = _wp_array_get( $typography_supports, array( '__experimentalFontFamily' ), false );
89 $has_font_size_support = _wp_array_get( $typography_supports, array( 'fontSize' ), false );
90 $has_font_style_support = _wp_array_get( $typography_supports, array( '__experimentalFontStyle' ), false );
91 $has_font_weight_support = _wp_array_get( $typography_supports, array( '__experimentalFontWeight' ), false );
92 $has_letter_spacing_support = _wp_array_get( $typography_supports, array( '__experimentalLetterSpacing' ), false );
93 $has_line_height_support = _wp_array_get( $typography_supports, array( 'lineHeight' ), false );
94 $has_text_decoration_support = _wp_array_get( $typography_supports, array( '__experimentalTextDecoration' ), false );
95 $has_text_transform_support = _wp_array_get( $typography_supports, array( '__experimentalTextTransform' ), false );
96
97 // Whether to skip individual block support features.
98 $should_skip_font_size = gutenberg_should_skip_block_supports_serialization( $block_type, 'typography', 'fontSize' );
99 $should_skip_font_family = gutenberg_should_skip_block_supports_serialization( $block_type, 'typography', 'fontFamily' );
100 $should_skip_font_style = gutenberg_should_skip_block_supports_serialization( $block_type, 'typography', 'fontStyle' );
101 $should_skip_font_weight = gutenberg_should_skip_block_supports_serialization( $block_type, 'typography', 'fontWeight' );
102 $should_skip_line_height = gutenberg_should_skip_block_supports_serialization( $block_type, 'typography', 'lineHeight' );
103 $should_skip_text_decoration = gutenberg_should_skip_block_supports_serialization( $block_type, 'typography', 'textDecoration' );
104 $should_skip_text_transform = gutenberg_should_skip_block_supports_serialization( $block_type, 'typography', 'textTransform' );
105 $should_skip_letter_spacing = gutenberg_should_skip_block_supports_serialization( $block_type, 'typography', 'letterSpacing' );
106
107 $typography_block_styles = array();
108 if ( $has_font_size_support && ! $should_skip_font_size ) {
109 $preset_font_size = array_key_exists( 'fontSize', $block_attributes ) ? "var:preset|font-size|{$block_attributes['fontSize']}" : null;
110 $custom_font_size = isset( $block_attributes['style']['typography']['fontSize'] ) ? $block_attributes['style']['typography']['fontSize'] : null;
111 $typography_block_styles['fontSize'] = $preset_font_size ? $preset_font_size : gutenberg_get_typography_font_size_value(
112 array(
113 'size' => $custom_font_size,
114 )
115 );
116 }
117
118 if ( $has_font_family_support && ! $should_skip_font_family ) {
119 $preset_font_family = array_key_exists( 'fontFamily', $block_attributes ) ? "var:preset|font-family|{$block_attributes['fontFamily']}" : null;
120 $custom_font_family = isset( $block_attributes['style']['typography']['fontFamily'] ) ? gutenberg_typography_get_preset_inline_style_value( $block_attributes['style']['typography']['fontFamily'], 'font-family' ) : null;
121 $typography_block_styles['fontFamily'] = $preset_font_family ? $preset_font_family : $custom_font_family;
122 }
123
124 if ( $has_font_style_support && ! $should_skip_font_style && isset( $block_attributes['style']['typography']['fontStyle'] ) ) {
125 $typography_block_styles['fontStyle'] =
126 gutenberg_typography_get_preset_inline_style_value( $block_attributes['style']['typography']['fontStyle'], 'font-style' );
127 }
128
129 if ( $has_font_weight_support && ! $should_skip_font_weight && isset( $block_attributes['style']['typography']['fontWeight'] ) ) {
130 $typography_block_styles['fontWeight'] =
131 gutenberg_typography_get_preset_inline_style_value( $block_attributes['style']['typography']['fontWeight'], 'font-weight' );
132 }
133
134 if ( $has_line_height_support && ! $should_skip_line_height ) {
135 $typography_block_styles['lineHeight'] = _wp_array_get( $block_attributes, array( 'style', 'typography', 'lineHeight' ), null );
136 }
137
138 if ( $has_text_decoration_support && ! $should_skip_text_decoration && isset( $block_attributes['style']['typography']['textDecoration'] ) ) {
139 $typography_block_styles['textDecoration'] =
140 gutenberg_typography_get_preset_inline_style_value( $block_attributes['style']['typography']['textDecoration'], 'text-decoration' );
141 }
142
143 if ( $has_text_transform_support && ! $should_skip_text_transform && isset( $block_attributes['style']['typography']['textTransform'] ) ) {
144 $typography_block_styles['textTransform'] =
145 gutenberg_typography_get_preset_inline_style_value( $block_attributes['style']['typography']['textTransform'], 'text-transform' );
146 }
147
148 if ( $has_letter_spacing_support && ! $should_skip_letter_spacing && isset( $block_attributes['style']['typography']['letterSpacing'] ) ) {
149 $typography_block_styles['letterSpacing'] =
150 gutenberg_typography_get_preset_inline_style_value( $block_attributes['style']['typography']['letterSpacing'], 'letter-spacing' );
151 }
152
153 $attributes = array();
154 $styles = gutenberg_style_engine_get_styles(
155 array( 'typography' => $typography_block_styles ),
156 array( 'convert_vars_to_classnames' => true )
157 );
158
159 if ( ! empty( $styles['classnames'] ) ) {
160 $attributes['class'] = $styles['classnames'];
161 }
162
163 if ( ! empty( $styles['css'] ) ) {
164 $attributes['style'] = $styles['css'];
165 }
166
167 return $attributes;
168 }
169
170 /**
171 * Note: this method is for backwards compatibility.
172 * It mostly replaces `gutenberg_typography_get_css_variable_inline_style()`.
173 *
174 * Generates an inline style value for a typography feature e.g. text decoration,
175 * text transform, and font style.
176 *
177 * @param string $style_value A raw style value for a single typography feature from a block's style attribute.
178 * @param string $css_property Slug for the CSS property the inline style sets.
179 *
180 * @return string? A CSS inline style value.
181 */
182 function gutenberg_typography_get_preset_inline_style_value( $style_value, $css_property ) {
183 // If the style value is not a preset CSS variable go no further.
184 if ( empty( $style_value ) || ! str_contains( $style_value, "var:preset|{$css_property}|" ) ) {
185 return $style_value;
186 }
187
188 // For backwards compatibility.
189 // Presets were removed in https://github.com/WordPress/gutenberg/pull/27555.
190 // We have a preset CSS variable as the style.
191 // Get the style value from the string and return CSS style.
192 $index_to_splice = strrpos( $style_value, '|' ) + 1;
193 $slug = _wp_to_kebab_case( substr( $style_value, $index_to_splice ) );
194
195 // Return the actual CSS inline style value e.g. `var(--wp--preset--text-decoration--underline);`.
196 return sprintf( 'var(--wp--preset--%s--%s);', $css_property, $slug );
197 }
198
199 /**
200 * Deprecated.
201 * This method is no longer used and will have to be deprecated in Core.
202 *
203 * It can be deleted once migrated to the next WordPress version.
204 *
205 * Generates an inline style for a typography feature e.g. text decoration,
206 * text transform, and font style.
207 *
208 * @param array $attributes Block's attributes.
209 * @param string $feature Key for the feature within the typography styles.
210 * @param string $css_property Slug for the CSS property the inline style sets.
211 *
212 * @return string CSS inline style.
213 */
214 function gutenberg_typography_get_css_variable_inline_style( $attributes, $feature, $css_property ) {
215 // Retrieve current attribute value or skip if not found.
216 $style_value = _wp_array_get( $attributes, array( 'style', 'typography', $feature ), false );
217 if ( ! $style_value ) {
218 return;
219 }
220
221 // If we don't have a preset CSS variable, we'll assume it's a regular CSS value.
222 if ( ! str_contains( $style_value, "var:preset|{$css_property}|" ) ) {
223 return sprintf( '%s:%s;', $css_property, $style_value );
224 }
225
226 // We have a preset CSS variable as the style.
227 // Get the style value from the string and return CSS style.
228 $index_to_splice = strrpos( $style_value, '|' ) + 1;
229 $slug = substr( $style_value, $index_to_splice );
230
231 // Return the actual CSS inline style e.g. `text-decoration:var(--wp--preset--text-decoration--underline);`.
232 return sprintf( '%s:var(--wp--preset--%s--%s);', $css_property, $css_property, $slug );
233 }
234
235 /**
236 * Renders typography styles/content to the block wrapper.
237 *
238 * @param string $block_content Rendered block content.
239 * @param array $block Block object.
240 * @return string Filtered block content.
241 */
242 function gutenberg_render_typography_support( $block_content, $block ) {
243 if ( ! isset( $block['attrs']['style']['typography']['fontSize'] ) ) {
244 return $block_content;
245 }
246
247 $custom_font_size = $block['attrs']['style']['typography']['fontSize'];
248 $fluid_font_size = gutenberg_get_typography_font_size_value( array( 'size' => $custom_font_size ) );
249
250 /*
251 * Checks that $fluid_font_size does not match $custom_font_size,
252 * which means it's been mutated by the fluid font size functions.
253 */
254 if ( ! empty( $fluid_font_size ) && $fluid_font_size !== $custom_font_size ) {
255 // Replaces the first instance of `font-size:$custom_font_size` with `font-size:$fluid_font_size`.
256 return preg_replace( '/font-size\s*:\s*' . preg_quote( $custom_font_size, '/' ) . '\s*;?/', 'font-size:' . esc_attr( $fluid_font_size ) . ';', $block_content, 1 );
257 }
258
259 return $block_content;
260
261 }
262
263 /**
264 * Internal method that checks a string for a unit and value and returns an array consisting of `'value'` and `'unit'`, e.g., [ '42', 'rem' ].
265 * A raw font size of `value + unit` is expected. If the value is a number, it will convert to `value + 'px'`.
266 *
267 * @access private
268 *
269 * @param string|int|float $raw_value Raw size value from theme.json.
270 * @param array $options {
271 * Optional. An associative array of options. Default is empty array.
272 *
273 * @type string $coerce_to Coerce the value to rem or px. Default `'rem'`.
274 * @type int $root_size_value Value of root font size for rem|em <-> px conversion. Default `16`.
275 * @type array<string> $acceptable_units An array of font size units. Default `[ 'rem', 'px', 'em' ]`;
276 * }
277 * @return array An array consisting of `'value'` and `'unit'` properties.
278 */
279 function gutenberg_get_typography_value_and_unit( $raw_value, $options = array() ) {
280 if ( ! is_string( $raw_value ) && ! is_int( $raw_value ) && ! is_float( $raw_value ) ) {
281 _doing_it_wrong(
282 __FUNCTION__,
283 __( 'Raw size value must be a string, integer or a float.', 'gutenberg' ),
284 '6.1.0'
285 );
286 return null;
287 }
288
289 // Converts numeric values to pixel values by default.
290 if ( empty( $raw_value ) ) {
291 return null;
292 }
293
294 // Converts numbers to pixel values by default.
295 if ( is_numeric( $raw_value ) ) {
296 $raw_value = $raw_value . 'px';
297 }
298
299 $defaults = array(
300 'coerce_to' => '',
301 'root_size_value' => 16,
302 'acceptable_units' => array( 'rem', 'px', 'em' ),
303 );
304
305 $options = wp_parse_args( $options, $defaults );
306
307 $acceptable_units_group = implode( '|', $options['acceptable_units'] );
308 $pattern = '/^(\d*\.?\d+)(' . $acceptable_units_group . '){1,1}$/';
309
310 preg_match( $pattern, $raw_value, $matches );
311
312 // We need a number value and a px or rem unit.
313 if ( ! isset( $matches[1] ) || ! isset( $matches[2] ) ) {
314 return null;
315 }
316
317 $value = $matches[1];
318 $unit = $matches[2];
319
320 // Default browser font size. Later we could inject some JS to compute this `getComputedStyle( document.querySelector( "html" ) ).fontSize`.
321 if ( 'px' === $options['coerce_to'] && ( 'em' === $unit || 'rem' === $unit ) ) {
322 $value = $value * $options['root_size_value'];
323 $unit = $options['coerce_to'];
324 }
325
326 if ( 'px' === $unit && ( 'em' === $options['coerce_to'] || 'rem' === $options['coerce_to'] ) ) {
327 $value = $value / $options['root_size_value'];
328 $unit = $options['coerce_to'];
329 }
330
331 /*
332 * No calculation is required if swapping between em and rem yet,
333 * since we assume a root size value. Later we might like to differentiate between
334 * :root font size (rem) and parent element font size (em) relativity.
335 */
336 if ( ( 'em' === $options['coerce_to'] || 'rem' === $options['coerce_to'] ) && ( 'em' === $unit || 'rem' === $unit ) ) {
337 $unit = $options['coerce_to'];
338 }
339
340 return array(
341 'value' => round( $value, 3 ),
342 'unit' => $unit,
343 );
344 }
345
346 /**
347 * Internal implementation of clamp() based on available min/max viewport width, and min/max font sizes.
348 *
349 * @access private
350 *
351 * @param array $args {
352 * Optional. An associative array of values to calculate a fluid formula for font size. Default is empty array.
353 *
354 * @type string $maximum_viewport_width Maximum size up to which type will have fluidity.
355 * @type string $minimum_viewport_width Minimum viewport size from which type will have fluidity.
356 * @type string $maximum_font_size Maximum font size for any clamp() calculation.
357 * @type string $minimum_font_size Minimum font size for any clamp() calculation.
358 * @type int $scale_factor A scale factor to determine how fast a font scales within boundaries.
359 * }
360 * @return string|null A font-size value using clamp().
361 */
362 function gutenberg_get_computed_fluid_typography_value( $args = array() ) {
363 $maximum_viewport_width_raw = isset( $args['maximum_viewport_width'] ) ? $args['maximum_viewport_width'] : null;
364 $minimum_viewport_width_raw = isset( $args['minimum_viewport_width'] ) ? $args['minimum_viewport_width'] : null;
365 $maximum_font_size_raw = isset( $args['maximum_font_size'] ) ? $args['maximum_font_size'] : null;
366 $minimum_font_size_raw = isset( $args['minimum_font_size'] ) ? $args['minimum_font_size'] : null;
367 $scale_factor = isset( $args['scale_factor'] ) ? $args['scale_factor'] : null;
368
369 // Normalizes the minimum font size in order to use the value for calculations.
370 $minimum_font_size = gutenberg_get_typography_value_and_unit( $minimum_font_size_raw );
371
372 /*
373 * We get a 'preferred' unit to keep units consistent when calculating,
374 * otherwise the result will not be accurate.
375 */
376 $font_size_unit = isset( $minimum_font_size['unit'] ) ? $minimum_font_size['unit'] : 'rem';
377
378 // Grabs the maximum font size and normalize it in order to use the value for calculations.
379 $maximum_font_size = gutenberg_get_typography_value_and_unit(
380 $maximum_font_size_raw,
381 array(
382 'coerce_to' => $font_size_unit,
383 )
384 );
385
386 // Checks for mandatory min and max sizes, and protects against unsupported units.
387 if ( ! $maximum_font_size || ! $minimum_font_size ) {
388 return null;
389 }
390
391 // Uses rem for accessible fluid target font scaling.
392 $minimum_font_size_rem = gutenberg_get_typography_value_and_unit(
393 $minimum_font_size_raw,
394 array(
395 'coerce_to' => 'rem',
396 )
397 );
398
399 // Viewport widths defined for fluid typography. Normalize units.
400 $maximum_viewport_width = gutenberg_get_typography_value_and_unit(
401 $maximum_viewport_width_raw,
402 array(
403 'coerce_to' => $font_size_unit,
404 )
405 );
406 $minimum_viewport_width = gutenberg_get_typography_value_and_unit(
407 $minimum_viewport_width_raw,
408 array(
409 'coerce_to' => $font_size_unit,
410 )
411 );
412
413 // Build CSS rule.
414 // Borrowed from https://websemantics.uk/tools/responsive-font-calculator/.
415 $view_port_width_offset = round( $minimum_viewport_width['value'] / 100, 3 ) . $font_size_unit;
416 $linear_factor = 100 * ( ( $maximum_font_size['value'] - $minimum_font_size['value'] ) / ( $maximum_viewport_width['value'] - $minimum_viewport_width['value'] ) );
417 $linear_factor_scaled = round( $linear_factor * $scale_factor, 3 );
418 $linear_factor_scaled = empty( $linear_factor_scaled ) ? 1 : $linear_factor_scaled;
419 $fluid_target_font_size = implode( '', $minimum_font_size_rem ) . " + ((1vw - $view_port_width_offset) * $linear_factor_scaled)";
420
421 return "clamp($minimum_font_size_raw, $fluid_target_font_size, $maximum_font_size_raw)";
422 }
423
424 /**
425 * Returns a font-size value based on a given font-size preset.
426 * Takes into account fluid typography parameters and attempts to return a css formula depending on available, valid values.
427 *
428 * @param array $preset {
429 * Required. fontSizes preset value as seen in theme.json.
430 *
431 * @type string $name Name of the font size preset.
432 * @type string $slug Kebab-case unique identifier for the font size preset.
433 * @type string|int|float $size CSS font-size value, including units where applicable.
434 * }
435 * @param bool $should_use_fluid_typography An override to switch fluid typography "on". Can be used for unit testing. Default is `false`.
436 *
437 * @return string|null Font-size value or `null` if a size is not passed in $preset.
438 */
439 function gutenberg_get_typography_font_size_value( $preset, $should_use_fluid_typography = false ) {
440 if ( ! isset( $preset['size'] ) ) {
441 return null;
442 }
443
444 /*
445 * Catches empty values and 0/'0'.
446 * Fluid calculations cannot be performed on 0.
447 */
448 if ( empty( $preset['size'] ) ) {
449 return $preset['size'];
450 }
451
452 // Checks if fluid font sizes are activated.
453 $typography_settings = gutenberg_get_global_settings( array( 'typography' ) );
454 $should_use_fluid_typography = isset( $typography_settings['fluid'] ) && true === $typography_settings['fluid'] ? true : $should_use_fluid_typography;
455
456 if ( ! $should_use_fluid_typography ) {
457 return $preset['size'];
458 }
459
460 // Defaults.
461 $default_maximum_viewport_width = '1600px';
462 $default_minimum_viewport_width = '768px';
463 $default_minimum_font_size_factor = 0.75;
464 $default_scale_factor = 1;
465 $default_minimum_font_size_limit = '14px';
466
467 // Font sizes.
468 $fluid_font_size_settings = isset( $preset['fluid'] ) ? $preset['fluid'] : null;
469
470 // A font size has explicitly bypassed fluid calculations.
471 if ( false === $fluid_font_size_settings ) {
472 return $preset['size'];
473 }
474
475 // Try to grab explicit min and max fluid font sizes.
476 $minimum_font_size_raw = isset( $fluid_font_size_settings['min'] ) ? $fluid_font_size_settings['min'] : null;
477 $maximum_font_size_raw = isset( $fluid_font_size_settings['max'] ) ? $fluid_font_size_settings['max'] : null;
478
479 // Font sizes.
480 $preferred_size = gutenberg_get_typography_value_and_unit( $preset['size'] );
481
482 // Protects against unsupported units.
483 if ( empty( $preferred_size['unit'] ) ) {
484 return $preset['size'];
485 }
486
487 // Parses the minimum font size limit, so we can perform checks using it.
488 $minimum_font_size_limit = gutenberg_get_typography_value_and_unit(
489 $default_minimum_font_size_limit,
490 array(
491 'coerce_to' => $preferred_size['unit'],
492 )
493 );
494
495 // Don't enforce minimum font size if a font size has explicitly set a min and max value.
496 if ( ! empty( $minimum_font_size_limit ) && ( ! $minimum_font_size_raw && ! $maximum_font_size_raw ) ) {
497 /*
498 * If a minimum size was not passed to this function
499 * and the user-defined font size is lower than $minimum_font_size_limit,
500 * do not calculate a fluid value.
501 */
502 if ( $preferred_size['value'] <= $minimum_font_size_limit['value'] ) {
503 return $preset['size'];
504 }
505 }
506
507 // If no fluid max font size is available use the incoming value.
508 if ( ! $maximum_font_size_raw ) {
509 $maximum_font_size_raw = $preferred_size['value'] . $preferred_size['unit'];
510 }
511
512 /*
513 * If no minimumFontSize is provided, create one using
514 * the given font size multiplied by the min font size scale factor.
515 */
516 if ( ! $minimum_font_size_raw ) {
517 $calculated_minimum_font_size = round( $preferred_size['value'] * $default_minimum_font_size_factor, 3 );
518
519 // Only use calculated min font size if it's > $minimum_font_size_limit value.
520 if ( ! empty( $minimum_font_size_limit ) && $calculated_minimum_font_size <= $minimum_font_size_limit['value'] ) {
521 $minimum_font_size_raw = $minimum_font_size_limit['value'] . $minimum_font_size_limit['unit'];
522 } else {
523 $minimum_font_size_raw = $calculated_minimum_font_size . $preferred_size['unit'];
524 }
525 }
526
527 $fluid_font_size_value = gutenberg_get_computed_fluid_typography_value(
528 array(
529 'minimum_viewport_width' => $default_minimum_viewport_width,
530 'maximum_viewport_width' => $default_maximum_viewport_width,
531 'minimum_font_size' => $minimum_font_size_raw,
532 'maximum_font_size' => $maximum_font_size_raw,
533 'scale_factor' => $default_scale_factor,
534 )
535 );
536
537 if ( ! empty( $fluid_font_size_value ) ) {
538 return $fluid_font_size_value;
539 }
540
541 return $preset['size'];
542 }
543
544 // Register the block support.
545 WP_Block_Supports::get_instance()->register(
546 'typography',
547 array(
548 'register_attribute' => 'gutenberg_register_typography_support',
549 'apply' => 'gutenberg_apply_typography_support',
550 )
551 );
552
553 if ( function_exists( 'wp_render_typography_support' ) ) {
554 remove_filter( 'render_block', 'wp_render_typography_support' );
555 }
556 add_filter( 'render_block', 'gutenberg_render_typography_support', 10, 2 );
557