The test case image-svg-text-font does not work as expected

Aperta
#8,996 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
48/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
rust
Ambito
backend, testing

Direzione di ricerca

The issue points to tests/suite/visualize/image.typ lines 76–83 and the image-svg-text-font visual test. Start by reading that test and comparing its expected output with the reproduction and font selection results described here. Done means SVG text follows the font set by show image: set text(font: ...), with the visual test updated to capture the corrected behavior.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug

Description

The following test case implies that show image: set text(font: (…, …)) can control the font of <text> in SVG images.

https://github.com/typst/typst/blob/64c5e8c02fe0394d913ead36e42ef8c1334d2107/tests/suite/visualize/image.typ#L76-L83

chinese.svg in the current typst-dev-assets:

<svg xmlns="http://www.w3.org/2000/svg" width="250" height="24" viewBox="0 0 250 22">
  <text x="0" y="10" font-size="10">此文本为中文。</text>
  <text x="0" y="22" font-size="10">The text above is in Chinese.</text>
</svg>

However, if I add Source Han Sans TC VF (default weight: ExtraLight) to typst-dev-assets and rerun cargo testit (without editing any test case), then the Chinese text in the SVG changes from serif to sans-serif, indicating that the show-set rule does not really work:

Image
Links

This test case was added in #2122. It attempted to fix #1154.

Background: #8991, typst/typst-dev-assets#18.

Further investigations

pdffonts shows that the Chinese characters in the reference PDF 10665a9d33a3ea4626a24fb49769456e_image-svg-text-font.pdf indeed use Noto Serif CJK SC.
However, that's because 为 in the text only exists in Noto Serif CJK SC, but not in Noto Serif CJK JP/KR/TC.
If I change it to #show image: set text(font: ("Roboto", "Noto Serif CJK JP")) (SC → JP) and rerun cargo testit, the live output still uses SC, even the hashes remain unchanged.

More tests
#set page(height: auto, width: auto, margin: 2em)
#set text(fallback: false)

#show image: set text(font: ("Libertinus Serif", "Noto Serif CJK SC"))
#image(bytes(
  ```svg
  <svg xmlns="http://www.w3.org/2000/svg" width="80" height="30" viewBox="0 0 80 30">
    <text x="0" y="10" font-size="10">骨返</text>
  </svg>
  ```.text,
))
#pagebreak()

#image(bytes(
  ```svg
  <svg xmlns="http://www.w3.org/2000/svg" width="80" height="30" viewBox="0 0 80 30">
    <text x="0" y="10" font-size="10">此文本为中文。</text>
  </svg>
  ```.text,
))
#pagebreak()

#image(bytes(
  ```svg
  <svg xmlns="http://www.w3.org/2000/svg" width="80" height="30" viewBox="0 0 80 30">
    <text x="0" y="10" font-size="10">骨返为</text>
  </svg>
  ```.text,
))
#pagebreak()

#table(
  columns: 2,
  stroke: none,
  ..for locale in ("JP", "KR", "SC", "TC") {
    (locale, text(font: "Noto Serif CJK " + locale)[骨返;此文本为中文。])
  }
)

Compile the above document with typst compile a.typ --font-path …/dev-assets/files/fonts/ --ignore-system-fonts, and you'll get the following results:

  • 骨返 in page 1 uses Noto Serif CJK JP.
  • 此文本为中文。 in page 2 uses Noto Serif CJK SC.
  • 骨返为 in page 3 uses Noto Serif CJK SC.
  • For reference, page 4 shows the character coverages and glyph variants for Noto Serif CJK fonts.
Image Image
$ pdffonts a.pdf -f 1 -l 1  # -f and -l specify the first and last page to examine
name                                 type              encoding         emb sub uni object ID
------------------------------------ ----------------- ---------------- --- --- --- ---------
NKCZKJ+NotoSerifCJKjp-Regular-Identity-H CID Type 0C       Identity-H       yes yes yes     26  0

$ pdffonts a.pdf -f 2 -l 3
name                                 type              encoding         emb sub uni object ID
------------------------------------ ----------------- ---------------- --- --- --- ---------
VXVQFG+NotoSerifCJKsc-Regular-Identity-H CID Type 0C       Identity-H       yes yes yes     32  0

$ pdffonts a.pdf -f 4 -l 4
name                                 type              encoding         emb sub uni object ID
------------------------------------ ----------------- ---------------- --- --- --- ---------
MEASXG+LibertinusSerif-Regular-Identity-H CID Type 0C       Identity-H       yes yes yes     35  0
NKCZKJ+NotoSerifCJKjp-Regular-Identity-H CID Type 0C       Identity-H       yes yes yes     29  0
XMHHWR+NotoSerifCJKkr-Regular-Identity-H CID Type 0C       Identity-H       yes yes yes     38  0
VXVQFG+NotoSerifCJKsc-Regular-Identity-H CID Type 0C       Identity-H       yes yes yes     32  0
GABABY+NotoSerifCJKtc-Regular-Identity-H CID Type 0C       Identity-H       yes yes yes     41  0
Operating system

Linux, Windows

Typst version
  • I am using the latest version of Typst
Lingua principale
Rust
Stelle
57.2k
Fork
1.8k
Merge medio
1g 17h
PR unite (30g)
22

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di typst/typst

Tutte le issue di typst/typst

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.