Font not loaded when exporting SVG

I succeded in the past to export my font when downloading a chart by cliking on the 3 dots next to the chart. In this exemple, it works very nicly, for PNG or SVG export.

But, for this Chart, I cannot make it work anymore.

The relevant code is:

const fontName = "Cormorant SC";

  GFontToDataURI(
    "https://fonts.googleapis.com/css2?family=Cormorant SC&display=swap"
  )
    .then((cssRules) => {
      let fontRules = cssRules.join("\n");
      d3.select("svg")
        .append("defs")
        .append("style")
        .attr("type", "text/css")
        .text(fontRules);
      console.log("Added Font");
    })
    .catch((reason) => console.log(reason));

  const g = svg.append("g").attr("font-family", "Cormorant SC");

It seems to me that the later notebook should work as well, but it dosen’t.

Thanks for your help !

Solved, the defs were not added because of d3.select was not well define. I changed to

 GFontToDataURI(
    // "https://fonts.googleapis.com/css2?family=Cormorant+SC:wght@700&display=swap"
    "https://fonts.googleapis.com/css2?family=Cormorant SC&display=swap"
  )
    .then((cssRules) => {
      let fontRules = cssRules.join("\n");
      svg
        .append("defs")
        .append("style")
        .attr("type", "text/css")
        .text(fontRules);
      console.log("Added Font");
    })
    .catch((reason) => console.log(reason));

And it works :wink: