Skip to content

Setting fonts repeatedly with different covers is not effective #6566

@YDX-2147483647

Description

@YDX-2147483647

Description

In the following example, the font Libertinus Serif support all characters in the text 123.
If I set text.font to ((name: font, covers: regex("1")), font), then the second item in the list (font) is not effective, leading to 1⬜⬜ rather than 123.

#let font = "Libertinus Serif"

#text(font: font)[123]

#text(font: (
  (name: font, covers: regex("1")),
  font,
))[123]
Image
Full code
#set page(height: auto, width: auto, margin: 1em)

#set text(fallback: false)

#let font = "Libertinus Serif"

#text(font: font)[123]

#text(font: (
  (name: font, covers: regex("1")),
  font,
))[123]

Is this behaviour expected?

Use case

The above is a minimal but meaningless example, and here's a real example.

I am using Twitter Color Emoji font, but the official version didn't update after Unicode 14. Therefore, I use Noto Color Emoji as a fallback.

However, I want to use both 🔗 link (Unicode 6.0) and ⛓‍💥 broken chain (⛓+zwj+💥, Unicode 15.1). These two emojis are used in pairs, but only the former is included in Twemoji. As a result, I want both of them fallback to Noto Color Emoji.

To sum up,

  1. For 🔗 and ⛓‍💥, use Noto Color Emoji.
  2. For other emojis, use Twitter Color Emoji if possible.
  3. For other emojis, use Noto Color Emoji.

That is,

#set text(font: (
  (name: "Noto Color Emoji", covers: regex("[🔗⛓‍💥]")),
  "Twitter Color Emoji",
  "Noto Color Emoji",
))
Image
Full code
#set page(height: auto, width: auto, margin: 1em)

#import emoji: chain, fingerprint, key
#let broken-chain = emoji.chains + sym.zwj + emoji.explosion

// https://github.com/googlefonts/noto-emoji/blob/b3e3051a088047d19fd4d49b1c3ac42fb8c3aaf8/fonts/NotoColorEmoji.ttf
// Note that this version is newer than that in typst.app.
#let font-n = "Noto Color Emoji"
// TwitterColorEmoji-SVGinOT.ttf in https://github.com/13rac1/twemoji-color-font/releases/download/v14.0.2/TwitterColorEmoji-SVGinOT-14.0.2.zip
#let font-t = "Twitter Color Emoji"

#set text(font: ("Libertinus Serif", font-n), fallback: false)
#table(
  stroke: none,
  align: start + horizon,
  columns: 3,
  table.hline(),
  table.header()[*Font*][*Current*][*Explanation*],
  table.hline(stroke: 0.5pt),

  font-n, text(font: font-n)[#chain#broken-chain#fingerprint#key], [✅✅✅✅],
  font-t, text(font: font-t)[#chain#broken-chain#fingerprint#key], [✅💔❌✅],

  [Noto (#chain#broken-chain), Twitter, Noto],
  text(font: (
    (name: font-n, covers: regex("[" + chain + broken-chain + "]")),
    font-t,
    font-n,
  ))[#chain#broken-chain#fingerprint#key],
  [✅✅⬜✅],

  [Expected of the above],
  text(font: (font-t, font-n), {
    text(font: font-n)[#chain#broken-chain]
    [#fingerprint#key]
  }),
  [✅✅✅✅],

  table.hline(),
)

#set text(0.7em)

- ✅ = OK
- 💔 = This is a zwj-joined emoji, but splitted
- ❌ = Missing / fallback
- ⬜ = Tofu

(Yes, there are many workarounds for this specific demand: #let broken-chain = text(font: …, …), show "⛓‍💥": …, etc.)

A related post

What is the designed behaviour of font covers in math equations? - Questions - Typst Forum

Reproduction URL

No response

Operating system

Windows

Typst version

  • I am using the latest version of Typst

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtextRelated to the text category, which is all about text handling, shaping, etc.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions