Search code examples
windowsemacsfont-face

emacs set-fontset-font for specific unicode char under windows


I use the following setting to config the font for emacs under windows system

(create-fontset-from-fontset-spec
 "-outline-Cousine-normal-normal-normal-*-*-*-*-*-*-*-fontset-Consolas")
(set-fontset-font "fontset-Consolas" 
                  '(#x6d4b . #x6d4c) 
                  "Microsoft YaHei" nil 'prepend)
(set-face-attribute 'default nil :font "fontset-Consolas")

After emacs start up, I input that char #x6d4b into the emacs buffer, but it turns out to be a square, which means the font setting does not work. I also use describe-char to show detail information, and get the following result:

             position: 2888 of 4342 (66%), column: 13
            character: 测 (displayed as 测) (codepoint 27979, #o66513, #x6d4b)
    preferred charset: unicode-bmp (Unicode Basic Multilingual Plane (U+0000..U+FFFF))
code point in charset: 0x6D4B
               syntax: w    which means: word
             category: .:Base, C:2-byte han, L:Left-to-right (strong), c:Chinese, |:line breakable
          buffer code: #xE6 #xB5 #x8B
            file code: #xE6 #xB5 #x8B (encoded by coding system utf-8-dos)
              display: no font available

We can find that the display property shows it does not have available font for it, but I indeed give that in the font config.

Could you point out where is the problem? I suppose the set-fontset-font should work even under windows system


Solution

  • As long as you just want to set the default font and a different font for two specific characters, the following works for me:

    (set-face-attribute 'default nil :family "Consolas")
    (set-fontset-font "fontset-default" '(#x6d4b . #x6d4c)
                      "Microsoft YaHei" nil 'prepend)
    

    (prepend is unnecessary with Consolas, but may help with your font).