Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Font Face: avoid using non required property as index and use right property to render font face #54610

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ private static function parse_settings( array $settings ) {
foreach ( $settings['typography']['fontFamilies'] as $font_families ) {
foreach ( $font_families as $definition ) {

// Skip if font-family "name" is not defined.
if ( empty( $definition['name'] ) ) {
// Skip if font-family "slug" is not defined.
if ( empty( $definition['slug'] ) ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it should use slug. Instead I think it should use fontFamily. Why? slug is not the proper name of the Font Family, but rather is the lowercase and hyphen version of the name. Currently Font Face uses this font-family name in the CSS.

I have PR coming shortly to show it in action.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR #54615 uses the fontFamily setting as the fallback to get the name.

continue;
}

Expand All @@ -66,14 +66,14 @@ private static function parse_settings( array $settings ) {
continue;
}

$font_family = $definition['name'];
$font_family = $definition['slug'];

// Prepare the fonts array structure for this font-family.
if ( ! array_key_exists( $font_family, $fonts ) ) {
$fonts[ $font_family ] = array();
}

$fonts[ $font_family ] = static::convert_font_face_properties( $definition['fontFace'], $font_family );
$fonts[ $font_family ] = static::convert_font_face_properties( $definition['fontFace'] );
}
}

Expand All @@ -85,16 +85,15 @@ private static function parse_settings( array $settings ) {
*
* @since 6.4.0
*
* @param array $font_face_definition The font-face definitions to convert.
* @param string $font_family_property The value to store in the font-face font-family property.
* @param array $font_face_definition The font-face definitions to convert.
* @return array Converted font-face properties.
*/
private static function convert_font_face_properties( array $font_face_definition, $font_family_property ) {
private static function convert_font_face_properties( array $font_face_definition ) {
$converted_font_faces = array();

foreach ( $font_face_definition as $font_face ) {
// Add the font-family property to the font-face.
$font_face['font-family'] = $font_family_property;
$font_face['font-family'] = $font_face['fontFamily'];

// Converts the "file:./" src placeholder into a theme font file URI.
if ( ! empty( $font_face['src'] ) ) {
Expand Down
Loading