Subject: Re: bug#66941: 29.1; Emacs on Windows can't display CJK characters correctly in svg images

From: Alan Third <[email-masked]>
Date: Sun, 5 Nov 2023 23:27:23 +0000

On Sun, Nov 05, 2023 at 08:54:27AM +0200, Eli Zaretskii wrote:
> > Cc: [email-masked]
> > Date: Sun, 05 Nov 2023 08:47:08 +0200
> > From: Eli Zaretskii <[email-masked]>
> > 
> > > (progn
> > >   (require 'svg)
> > >   (switch-to-buffer "*svg-test*")
> > >   (let ((svg-image (svg-create 200 200))
> > > 	(inhibit-read-only t))
> > >     (erase-buffer)
> > >     (svg-text svg-image "我喜欢自由软件" :y 100 :x 50)
> > >     (svg-print svg-image)
> > >     (image-mode)))
> > 
> > I cannot get Emacs on Windows to display _any_ non-ASCII text with the
> > above recipe, not even if I use Latin-1 characters or characters from
> > the current system codepage.  Emacs encodes non-ASCII characters as
> > &#nnnn numbers (you can see that if you type "C-c C-c" in the
> > *svg-test* buffer), which is probably correct, but the SVG image is
> > not displayed for some reason.
> > 
> > Alan, any ideas or suggestions?
> 
> Could be a problem with the font used by librsvg to show text?  Maybe
> the font doesn't have any non-ASCII characters.

This seems plausible. It should be possible to check by over-riding
the CSS with a font you know should work:

(progn
  (require 'svg)
  (switch-to-buffer "*svg-test*")
  (let ((svg-image (svg-create 200 200))
        (inhibit-read-only t))
    (erase-buffer)
    (svg-text svg-image "我喜欢自由软件" :y 100 :x 50)
    (insert-image (svg-image svg-image :css "svg{font-family:\"Noto Sans Mono CJK HK\";}"))))

Choose a font you know can show the text you're testing. I've a vague
memory that the Noto CJK fonts behave slightly oddly on Windows, so
maybe something else is a better choice.

I think setting the :css attribute to an empty string should reset
librsvg so it will use its default font settings and that would let
us see if it works right without our customisation.

-- 
Alan Third