Skip to content

Commit

Permalink
Font library: load font assets on editor canvas
Browse files Browse the repository at this point in the history
This change adds loaded font faces to the editor canvas iframe so that they can be used immediately after uploading them.

Re: #51764
  • Loading branch information
Vicente Canales committed Sep 10, 2023
1 parent e0f3f70 commit 533fd47
Showing 1 changed file with 5 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,18 @@ function LocalFonts() {
};

const addFontFaceToBrowser = async ( fontFaceData ) => {
const editorCanvas = document.querySelector(
'iframe[name="editor-canvas"]'
);
const iframeDocument = editorCanvas.contentDocument;
const data = await fontFaceData.file.arrayBuffer();
const newFont = new window.FontFace( fontFaceData.fontFamily, data, {
style: fontFaceData.fontStyle,
weight: fontFaceData.fontWeight,
} );
const loadedFace = await newFont.load();
document.fonts.add( loadedFace );
iframeDocument.fonts.add( loadedFace );
};

/**
Expand Down

0 comments on commit 533fd47

Please sign in to comment.