Skip to content

Commit

Permalink
Activate the fonts coming from the backend and not the data from the …
Browse files Browse the repository at this point in the history
…frontend (#60093)

* Activate the fonts coming from the backend and not the data from the frontend

* add comment

-----

Co-authored-by: matiasbenedetto <mmaattiiaass@git.wordpress.org>
Co-authored-by: mikachan <mikachan@git.wordpress.org>
Co-authored-by: getdave <get_dave@git.wordpress.org>
Co-authored-by: mcsf <mcsf@git.wordpress.org>
Co-authored-by: carolinan <poena@git.wordpress.org>
Co-authored-by: huzaifaalmesbah <huzaifaalmesbah@git.wordpress.org>
Co-authored-by: srueegger <kim88@git.wordpress.org>
Co-authored-by: annezazu <annezazu@git.wordpress.org>
  • Loading branch information
9 people committed Mar 27, 2024
1 parent a5ab3c5 commit d2191d4
Showing 1 changed file with 23 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -281,11 +281,13 @@ function FontLibraryProvider( { children } ) {
sucessfullyInstalledFontFaces?.length > 0 ||
alreadyInstalledFontFaces?.length > 0
) {
fontFamilyToInstall.fontFace = [
// Use font data from REST API not from client to ensure
// correct font information is used.
installedFontFamily.fontFace = [
...sucessfullyInstalledFontFaces,
...alreadyInstalledFontFaces,
];
fontFamiliesToActivate.push( fontFamilyToInstall );

fontFamiliesToActivate.push( installedFontFamily );
}

// If it's a system font but was installed successfully, activate it.
Expand Down Expand Up @@ -402,14 +404,29 @@ function FontLibraryProvider( { children } ) {
};

const activateCustomFontFamilies = ( fontsToAdd ) => {
// Merge the existing custom fonts with the new fonts.
// Removes the id from the families and faces to avoid saving that to global styles post content.
const fontsToActivate = fontsToAdd.map(
( { id: _familyDbId, fontFace, ...font } ) => ( {
...font,
...( fontFace && fontFace.length > 0
? {
fontFace: fontFace.map(
( { id: _faceDbId, ...face } ) => face
),
}
: {} ),
} )
);

// Activate the fonts by set the new custom fonts array.
setFontFamilies( {
...fontFamilies,
custom: mergeFontFamilies( fontFamilies?.custom, fontsToAdd ),
// Merge the existing custom fonts with the new fonts.
custom: mergeFontFamilies( fontFamilies?.custom, fontsToActivate ),
} );

// Add custom fonts to the browser.
fontsToAdd.forEach( ( font ) => {
fontsToActivate.forEach( ( font ) => {
if ( font.fontFace ) {
font.fontFace.forEach( ( face ) => {
// Load font faces just in the iframe because they already are in the document.
Expand Down

0 comments on commit d2191d4

Please sign in to comment.