thx / resvg-js

A high-performance SVG renderer and toolkit, powered by Rust based resvg and napi-rs.
https://resvg-js.vercel.app/
Mozilla Public License 2.0
1.58k stars 59 forks source link

Does wasm support multiple font families? #342

Open AndrewAskins opened 5 months ago

AndrewAskins commented 5 months ago

I am trying to load multiple font families, and specific a different sans serif and monospace font. But my image is only using the first font loaded. It looks from resvg-js/wasm/index.d.ts like it should but that's not the behavior I'm seeing.

` const inter400 = await fetch('https://cdn.jsdelivr.net/fontsource/fonts/inter@latest/latin-400-normal.woff2') if (!inter400.ok) return const bufferInter400 = new Uint8Array(await inter400.arrayBuffer())

  const inter700 = await fetch('https://cdn.jsdelivr.net/fontsource/fonts/inter@latest/latin-700-normal.woff2')
  if (!inter700.ok) return
  const bufferInter700 = new Uint8Array(await inter700.arrayBuffer())

  const lora400 = await fetch('https://cdn.jsdelivr.net/fontsource/fonts/lora@latest/latin-400-normal.woff2')
  if (!lora400.ok) return
  const bufferLora400 = new Uint8Array(await lora400.arrayBuffer())

  const lora700 = await fetch('https://cdn.jsdelivr.net/fontsource/fonts/lora@latest/latin-700-normal.woff2')
  if (!lora700.ok) return
  const bufferLora700 = new Uint8Array(await lora700.arrayBuffer())

  const ibmPlexMono400 = await fetch('https://cdn.jsdelivr.net/fontsource/fonts/ibm-plex-mono@latest/latin-400-normal.woff2')
  if (!ibmPlexMono400.ok) return
  const bufferIbmPlexMono400 = new Uint8Array(await ibmPlexMono400.arrayBuffer())

  const ibmPlexMono700 = await fetch('https://cdn.jsdelivr.net/fontsource/fonts/ibm-plex-mono@latest/latin-700-normal.woff2')
  if (!ibmPlexMono700.ok) return
  const bufferIbmPlexMono700 = new Uint8Array(await ibmPlexMono700.arrayBuffer())

  const opts = {
    dpi: 96,
    shapeRendering: 1,
    textRendering: 2,
    imageRendering: 0,
    font: {
      fontBuffers: [bufferInter400, bufferInter700, bufferLora400, bufferLora700, bufferIbmPlexMono400, bufferIbmPlexMono700], // New in 2.5.0, loading custom fonts
      monospaceFamily: 'IBM Plex Mono',
      sansSerifFamily: 'Inter',
      serifFamily: 'Lora',
      loadSystemFonts: false,
    },
  }`