Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Formatting
  • Loading branch information
ramonjd committed Sep 9, 2022
commit 5f0d72642e34cc31fb6e7d0d73a0c3645b57b3e4
12 changes: 6 additions & 6 deletions src/wp-includes/block-supports/typography.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,7 @@ function wp_get_computed_fluid_typography_value( $args = array() ) {
// Grab the minimum font size and normalize it in order to use the value for calculations.
$minimum_font_size = wp_get_typography_value_and_unit( $minimum_font_size_raw );

// We get a 'preferred' unit to keep units consistent when calculating,
// otherwise the result will not be accurate.
// We get a 'preferred' unit to keep units consistent when calculating, otherwise the result will not be accurate.
$font_size_unit = isset( $minimum_font_size['unit'] ) ? $minimum_font_size['unit'] : 'rem';

// Grab the maximum font size and normalize it in order to use the value for calculations.
Expand Down Expand Up @@ -321,9 +320,10 @@ function wp_get_computed_fluid_typography_value( $args = array() ) {
'coerce_to' => $font_size_unit,
)
);

// Build CSS rule.
// Borrowed from https://websemantics.uk/tools/responsive-font-calculator/.
/*
* Build CSS rule.
* Borrowed from https://websemantics.uk/tools/responsive-font-calculator/.
*/
$view_port_width_offset = round( $minimum_viewport_width['value'] / 100, 3 ) . $font_size_unit;
$linear_factor = 100 * ( ( $maximum_font_size['value'] - $minimum_font_size['value'] ) / ( $maximum_viewport_width['value'] - $minimum_viewport_width['value'] ) );
$linear_factor = round( $linear_factor, 3 ) * $scale_factor;
Expand All @@ -350,7 +350,7 @@ function wp_get_computed_fluid_typography_value( $args = array() ) {
* @return string Font-size value.
*/
function wp_get_typography_font_size_value( $preset, $should_use_fluid_typography = false ) {
// Check if fluid font sizes are activated.
// Checks if fluid font sizes are activated.
$typography_settings = wp_get_global_settings( array( 'typography' ) );
$should_use_fluid_typography = isset( $typography_settings['fluid'] ) && true === $typography_settings['fluid'] ? true : $should_use_fluid_typography;

Expand Down
16 changes: 12 additions & 4 deletions tests/phpunit/tests/block-supports/typography.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ function set_up() {
$this->test_block_name = null;
}

/**
* Unregisters block type after each test.
*/
function tear_down() {
unregister_block_type( $this->test_block_name );
$this->test_block_name = null;
Expand All @@ -23,6 +26,7 @@ function tear_down() {
* Tests whether slugs with numbers are kebab cased.
*
* @ticket 54337
*
* @covers ::wp_apply_typography_support
*/
function test_should_kebab_case_font_size_slug_with_numbers() {
Expand Down Expand Up @@ -58,6 +62,7 @@ function test_should_kebab_case_font_size_slug_with_numbers() {
* Tests legacy inline styles for font family.
*
* @ticket 54337
*
* @covers ::wp_apply_typography_support
*/
function test_should_generate_font_family_with_legacy_inline_styles_using_a_value() {
Expand Down Expand Up @@ -92,6 +97,7 @@ function test_should_generate_font_family_with_legacy_inline_styles_using_a_valu
* Tests skipping serialization.
*
* @ticket 55505
*
* @covers ::wp_apply_typography_support
*/
function test_should_skip_serialization_for_typography_block_supports() {
Expand Down Expand Up @@ -139,6 +145,7 @@ function test_should_skip_serialization_for_typography_block_supports() {
* Tests skipping serialization of individual block supports properties.
*
* @ticket 55505
*
* @covers ::wp_apply_typography_support
*/
function test_should_skip_serialization_for_letter_spacing_block_supports() {
Expand Down Expand Up @@ -176,6 +183,7 @@ function test_should_skip_serialization_for_letter_spacing_block_supports() {
* Tests legacy css var inline styles for font family.
*
* @ticket 54337
*
* @covers ::wp_apply_typography_support
*/
function test_should_generate_css_var_for_font_family_with_legacy_inline_styles() {
Expand Down Expand Up @@ -210,6 +218,7 @@ function test_should_generate_css_var_for_font_family_with_legacy_inline_styles(
* Tests that a classname is generated for font family.
*
* @ticket 54337
*
* @covers ::wp_apply_typography_support
*/
function test_should_generate_classname_for_font_family() {
Expand Down Expand Up @@ -244,21 +253,20 @@ function test_should_generate_classname_for_font_family() {
* Tests generating font size values, including fluid formulae, from fontSizes preset.
*
* @ticket 56467
*
* @covers ::wp_get_typography_font_size_value
* @covers ::wp_get_typography_value_and_unit
* @covers ::wp_get_computed_fluid_typography_value
*
* @dataProvider data_generate_font_size_preset_fixtures
*
* @param array $font_size_preset {
* @param array $font_size_preset {
* Required. fontSizes preset value as seen in theme.json.
*
* @type string $name Name of the font size preset.
* @type string $slug Kebab-case unique identifier for the font size preset.
* @type string $size CSS font-size value, including units where applicable.
* }
* @param bool $should_use_fluid_typography An override to switch fluid typography "on". Can be used for unit testing.
* @param string $expected_output Expected output of gutenberg_get_typography_font_size_value().
* @param string $expected_output Expected output of gutenberg_get_typography_font_size_value().
*/
function test_wp_get_typography_font_size_value( $font_size_preset, $should_use_fluid_typography, $expected_output ) {
$actual = wp_get_typography_font_size_value( $font_size_preset, $should_use_fluid_typography );
Expand Down