Forum How do I...?

Finding fonts used in SVG on Linux

arjana
Hello,

We are planning to use Prince in scenarios when we cannot control user input, and we've been testing various fonts related cases. We found a case which we do not know how to make work:

If there is an svg referenced within an html, and let's say Chinese fonts are used within, but the font-family is specified as Arial, the output pdf works differently depending on the system:

- on Windows, no problems, additional fonts are used in pdf and embedded into the pdf,
- on Linux (RedHat 9 specifically), nothing seems to work unless the font-family within the svg is changed to a font-family that includes those Chinese symbols. There are various fonts that support Chinese symbols installed on the system, and we tried specifying them as a font-family for the whole document. Texts outside the svg diagram are converted with correct fonts but they do not affect the svg fonts.

Is there a way to make search for fonts work within svg if their font-family is incorrect on Linux? What is different about the font selection on Windows that it works correctly even though Arial is used within the svg?

It may not be an issue for some other users but our users convert htmls with svg diagrams that have this Arial font specified as default so it is a very real scenario.

I'm attaching a sample input, and output on Linux and Windows. During conversion on Linux, the following is logged:

prince -v chinese.html -o chinese.pdf
prince: loading document: /opt/Prince/lib/prince/license/license.dat
prince: Loading document...
prince: loading HTML5 input: chinese.html
prince: loading document: chinese.html
prince: Applying style sheets...
prince: Preparing document...
prince: loading image: chinese.svg
prince: loading document: chinese.svg
prince: loading document: /opt/Prince/lib/prince/dtd/svg10/svg10.dtd
prince: Applying style sheets...
prince: loading document: chinese.svg
prince: loading document: chinese.svg
prince: loading document: /opt/Prince/lib/prince/dtd/svg10/svg10.dtd
prince: Applying style sheets...
prince: loading font: /usr/share/fonts/msttcore/arialbd.ttf
prince: used font: Arial, Bold
prince: loading font: /usr/share/fonts/msttcore/arial.ttf
prince: used font: Arial, Regular
prince: loading font: /usr/share/fonts/msttcore/timesbd.ttf
prince: warning: no font for CJK character U+641C, fallback to U+2BD1 ⯑
prince: loading font: /opt/Prince/lib/prince/style/../fonts/prince-fallback.ttf
prince: used font: PrinceFallback, Regular
prince: warning: no font for CJK character U+5C0B, fallback to U+2BD1 ⯑
prince: warning: no font for CJK character U+8A02, fallback to U+2BD1 ⯑
prince: warning: no font for CJK character U+55AE, fallback to U+2BD1 ⯑
prince: warning: no font for CJK character U+5EFA, fallback to U+2BD1 ⯑
prince: warning: no font for CJK character U+7ACB, fallback to U+2BD1 ⯑
prince: warning: no font for CJK character U+4EBA, fallback to U+2BD1 ⯑
prince: Converting document...
prince: loading font: /usr/share/fonts/google-noto-cjk/NotoSansCJK-Regular.ttc
prince: used font: Noto Sans CJK SC, Regular
prince: Finished: success


Arjana
  1. chinese.html0.5 kB
    input html
  2. chinese.svg13.2 kB
    input svg
  3. chinese.windows.pdf45.1 kB
    Output from Windows
  4. chinese_linux.pdf34.8 kB
    Output from Linux

Edited by arjana

mikeday
This will require adding a reference to Noto Sans CJK SC to fonts.css in the Prince installation so that it can be used for the default serif font family, something like this:
@font-face {
    font-family: serif; /* Chinese, simplified */
    src: prince-lookup("AR PL UMing CN"), prince-lookup("AR PL SungtiL GB"), prince-lookup("Noto Sans CJK SC")
}
mikeday
We have added the Noto CJK fonts to the default font families in the latest build so it should work properly out of the box now.