- Timestamp:
- 10/19/2022 12:28:02 PM (3 years ago)
- Location:
- branches/6.1
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
src/wp-includes/block-supports/typography.php (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/6.1
-
branches/6.1/src/wp-includes/block-supports/typography.php
r54497 r54647 120 120 ? $block_attributes['style']['typography']['fontSize'] 121 121 : null; 122 $typography_block_styles['fontSize'] = $preset_font_size ? $preset_font_size : wp_get_typography_font_size_value(123 array(124 'size' => $custom_font_size,125 )126 );122 $typography_block_styles['fontSize'] = $preset_font_size ? $preset_font_size : wp_get_typography_font_size_value( 123 array( 124 'size' => $custom_font_size, 125 ) 126 ); 127 127 } 128 128 … … 349 349 } 350 350 351 /* 352 * No calculation is required if swapping between em and rem yet, 353 * since we assume a root size value. Later we might like to differentiate between 354 * :root font size (rem) and parent element font size (em) relativity. 355 */ 356 if ( ( 'em' === $options['coerce_to'] || 'rem' === $options['coerce_to'] ) && ( 'em' === $unit || 'rem' === $unit ) ) { 357 $unit = $options['coerce_to']; 358 } 359 351 360 return array( 352 'value' => $value,361 'value' => round( $value, 3 ), 353 362 'unit' => $unit, 354 363 ); … … 381 390 $scale_factor = isset( $args['scale_factor'] ) ? $args['scale_factor'] : null; 382 391 383 // Grab the minimum font size and normalize itin order to use the value for calculations.392 // Normalizes the minimum font size in order to use the value for calculations. 384 393 $minimum_font_size = wp_get_typography_value_and_unit( $minimum_font_size_raw ); 385 394 386 // We get a 'preferred' unit to keep units consistent when calculating, otherwise the result will not be accurate. 395 /* 396 * We get a 'preferred' unit to keep units consistent when calculating, 397 * otherwise the result will not be accurate. 398 */ 387 399 $font_size_unit = isset( $minimum_font_size['unit'] ) ? $minimum_font_size['unit'] : 'rem'; 388 400 389 // Grab the maximum font size and normalize itin order to use the value for calculations.401 // Normalizes the maximum font size in order to use the value for calculations. 390 402 $maximum_font_size = wp_get_typography_value_and_unit( 391 403 $maximum_font_size_raw, … … 395 407 ); 396 408 397 // Protectagainst unsupported units.409 // Checks for mandatory min and max sizes, and protects against unsupported units. 398 410 if ( ! $maximum_font_size || ! $minimum_font_size ) { 399 411 return null; 400 412 } 401 413 402 // Use rem for accessible fluid target font scaling.414 // Uses rem for accessible fluid target font scaling. 403 415 $minimum_font_size_rem = wp_get_typography_value_and_unit( 404 416 $minimum_font_size_raw, … … 428 440 $view_port_width_offset = round( $minimum_viewport_width['value'] / 100, 3 ) . $font_size_unit; 429 441 $linear_factor = 100 * ( ( $maximum_font_size['value'] - $minimum_font_size['value'] ) / ( $maximum_viewport_width['value'] - $minimum_viewport_width['value'] ) ); 430 $linear_factor = round( $linear_factor, 3 ) * $scale_factor; 431 $fluid_target_font_size = implode( '', $minimum_font_size_rem ) . " + ((1vw - $view_port_width_offset) * $linear_factor)"; 442 $linear_factor_scaled = round( $linear_factor * $scale_factor, 3 ); 443 $linear_factor_scaled = empty( $linear_factor_scaled ) ? 1 : $linear_factor_scaled; 444 $fluid_target_font_size = implode( '', $minimum_font_size_rem ) . " + ((1vw - $view_port_width_offset) * $linear_factor_scaled)"; 432 445 433 446 return "clamp($minimum_font_size_raw, $fluid_target_font_size, $maximum_font_size_raw)"; … … 479 492 $default_maximum_font_size_factor = 1.5; 480 493 $default_scale_factor = 1; 494 $default_minimum_font_size_limit = '14px'; 481 495 482 496 // Font sizes. … … 500 514 } 501 515 502 // If no fluid min or max font sizes are available, create some using min/max font size factors. 516 // If no fluid max font size is available, create one using max font size factor. 517 if ( ! $maximum_font_size_raw ) { 518 $maximum_font_size_raw = round( $preferred_size['value'] * $default_maximum_font_size_factor, 3 ) . $preferred_size['unit']; 519 } 520 521 // If no fluid min font size is available, create one using min font size factor. 503 522 if ( ! $minimum_font_size_raw ) { 504 $minimum_font_size_raw = ( $preferred_size['value'] * $default_minimum_font_size_factor ) . $preferred_size['unit']; 505 } 506 507 if ( ! $maximum_font_size_raw ) { 508 $maximum_font_size_raw = ( $preferred_size['value'] * $default_maximum_font_size_factor ) . $preferred_size['unit']; 523 $minimum_font_size_raw = round( $preferred_size['value'] * $default_minimum_font_size_factor, 3 ) . $preferred_size['unit']; 524 } 525 526 // Normalizes the minimum font size limit according to the incoming unit, so we can perform checks using it. 527 $minimum_font_size_limit = wp_get_typography_value_and_unit( 528 $default_minimum_font_size_limit, 529 array( 530 'coerce_to' => $preferred_size['unit'], 531 ) 532 ); 533 534 if ( ! empty( $minimum_font_size_limit ) ) { 535 /* 536 * If a minimum size was not passed to this function 537 * and the user-defined font size is lower than $minimum_font_size_limit, 538 * then use the user-defined font size as the minimum font-size. 539 */ 540 if ( ! isset( $fluid_font_size_settings['min'] ) && $preferred_size['value'] < $minimum_font_size_limit['value'] ) { 541 $minimum_font_size_raw = implode( '', $preferred_size ); 542 } else { 543 $minimum_font_size_parsed = wp_get_typography_value_and_unit( 544 $minimum_font_size_raw, 545 array( 546 'coerce_to' => $preferred_size['unit'], 547 ) 548 ); 549 550 /* 551 * If the passed or calculated minimum font size is lower than $minimum_font_size_limit 552 * use $minimum_font_size_limit instead. 553 */ 554 if ( ! empty( $minimum_font_size_parsed ) && $minimum_font_size_parsed['value'] < $minimum_font_size_limit['value'] ) { 555 $minimum_font_size_raw = implode( '', $minimum_font_size_limit ); 556 } 557 } 509 558 } 510 559
Note: See TracChangeset
for help on using the changeset viewer.