0

I'm trying to set default face to use PingFang Mono SC font. But I notice that faces that don't use this font become italic unexpectedly. As one can see below the font-lock-comment-face is italic, but it is not set to be (it's only set to use SF Pro family).

The only weird part I notice is that the "oblique" word in describe-char on the PingFang Mono SC font (see the 3rd image below), as one can see the font do have a regular variant. I don't understand what's happening here and how it affects other faces that don't use this font (notice that "italic" is found in the describe-char buffer of SF Pro font in the 1st image).

As you can see the test config below, I do not set any italic related things.

I've tested it in an emacs -q session.

I don't has this issue with other mono fonts for default face.

How can I set default face to use PingFang Mono SC font but without this unexpected italic issue?

Call describe-char on T of the word this

(Notice the "italic" word in the second window, I didn't set it.)

enter image description here

(The font-lock-comment-face is not set to be italic.)

enter image description here

(Notice the "oblique" word in the second window, I don't know why it is.)

enter image description here

(The information of PingFang Mono SC font.)

enter image description here

(The information of SF Pro font.)

enter image description here

(As for comparison, the issue does not happen when using other mono fonts for default face. As one can see in this case, the default face is set to DM Mono, but font-lock-comment-face is normal. Also notice the "normal-normal-normal" part for SF Pro. Everything is just fine.)

Minimal test config:

;; This buffer is for text that is not saved, and for Lisp evaluation.
;; To create a file, visit it with C-x C-f and enter text in its buffer.

(when (display-graphic-p)
  (set-face-attribute 'default nil :font "PingFang Mono SC")
  (custom-set-faces '(font-lock-comment-face ((t (:family "SF Pro"))))))
  • The PingFang Mono SC font is downloaded from here.
  • The SF Pro font comes with system.
  • OS: macOS 12.5 (21G72)
  • Emacs: GNU Emacs 28.1 (build 1, x86_64-apple-darwin21.5.0, Carbon Version 165 AppKit 2113.5) of 2022-07-04
8
  • There is a lot of information in your post, but I am unsure of what your question is. Could you please clarify your question? Are you asking "Why does switching to this font cause others to default to italics and how do I prevent this behaviour?" or "How do I ensure that faces with this font that are set to italics are displayed in italics within Emacs?" or "Where can I find out how Emacs utilizes fonts for faces?" Also, your bounty is for a canonical answer. Could you clarify what you are looking for in the answer?
    – Malle Yeno
    Aug 10, 2022 at 15:50
  • @MalleYeno Hi, when I set PingFang Mono SC font for the default face, other faces like font-lock-comment-face that are set to use other fonts become italic unexpectedly. I'm not sure how can this happens (Notice that I didn't set any italic related things for default and font-lock-comment-face). I want a way to figure out what's happening and fix this issue. And I don't have this issue with other fonts so I post the link where I got this font. Aug 11, 2022 at 1:09
  • @MalleYeno I also updated the question, I hope the issue is clearer... Aug 11, 2022 at 1:37
  • Can you explain how did you get this Emacs version? the word "Carbon" stands for "Carbon(API)" display engine, deprecated since 2009. Actually in use is the Cocoa(API), shown as "NS appkit" in emacs-version string.
    – Ian
    Aug 11, 2022 at 11:44
  • @lan I installed it by brew install --with-dbus --with-rsvg --with-natural-title-bar --with-mac-metal --with-glib --with-imagemagick. Aug 12, 2022 at 1:19

3 Answers 3

0
+200

Try this

(create-fontset-from-fontset-spec
 (font-xlfd-name (font-spec :registry "fontset-mine" :family "SF Pro"
                :weight 'regular :slant 'normal :width 'normal)))

(set-face-attribute 'font-lock-comment-face nil :font "fontset-mine")


On Debian, I see regular in xfld-name. But looking at your screenshots I see normal. So try tweaking the :weight to either regular or normal to match the the xfld-name that gives you the desired face properties.

Docstring for font-spec says a value of regular, normal and book for weight is equivalent, but the xfld string generated depends on the value passed to :weight property

*** Welcome to IELM ***  Type (describe-mode) or press C-h m for help.
ELISP> (create-fontset-from-fontset-spec
    (font-xlfd-name 
     (font-spec  
      :registry "fontset-mine" 
      :family "SF Pro"
      :weight 'regular 
      :slant 'normal
      :width 'normal)))
"-*-sf pro-regular-normal-normal-*-*-*-*-*-*-*-fontset-mine"
ELISP> (create-fontset-from-fontset-spec
    (font-xlfd-name 
     (font-spec  
      :registry "fontset-mine" 
      :family "SF Pro"
      :weight 'normal
      :slant 'normal
      :width 'normal)))
"-*-sf pro-normal-normal-normal-*-*-*-*-*-*-*-fontset-mine"
ELISP> 

It is possible that the name of the weight portion--regular or normal--matters and makes a difference. So, specify them explicitly instead of using wildcards.


I have used SF Pro in my examples, you could try the same diagnostics on Ping Fang Mono font files. Note that I am trying with Debian, so you may have to make some adjustments to the strings based on what the Mac side (or Windows) reports.

8
  • This answer works for the original issue. But when I try to use fontset-mine in buffer-face-set, I can not change the height of the font, e.g. (buffer-face-set :family "fontset-mine" :height 150). Aug 15, 2022 at 3:16
  • Have you tried 1.50 instead of 150. Do you want both the comment and regular text to be of different heights, or you want the whole buffer to be scaled to 1.50 .... I can scale just the comment face with (set-face-attribute 'font-lock-comment-face nil :font "fontset-mine" :height 1.50). Ensure that scaling works with regular config, before moving on to buffer-face-mode.
    – user31220
    Aug 15, 2022 at 3:27
  • buffer-face-set basically does (face-remap-add-relative 'default buffer-face-mode-face). It overlays the the default font with buffer-face-mode-face. How have you configured the bufffer-face-mode-face? In your case, the default and font-lock-comment-face uses different font-family. So, you may have to experiment with face-remap-add-relative on both the default and font-lock-comment-face, I guess ...
    – user31220
    Aug 15, 2022 at 3:36
  • (buffer-face-set :height 1.50) works for me.
    – user31220
    Aug 15, 2022 at 3:39
  • Sorry and I'm trying to clarify the problem. Let's call fontset-mine as a fixed version of SF Pro...Due to the original issue exists, I need this fixed version for some faces like font-lock-comment-facein my prog-mode buffers. But I also use a variable font (originally SF Pro) in org-mode with a larger font size. With this fixed fontset-mine, I can not tweak its size. (buffer-face-set :family "fontset-mine" :height 1.50) does not work for me (The font size becomes large, but it does not recognize the font correctly. It uses Helvetica instead as a fallback option). Aug 15, 2022 at 3:58
0

The suggested answer is here https://emacs.stackexchange.com/a/73065/31220 or here https://emacs.stackexchange.com/a/73067/31220.

This is some supplementary information for the above answer. This is the infomration I obtained for SF Pro fonts. I have done a similar exercise for Coelacanth font. See all my comments under Font problem: Coelacanth Italics

This is not an answer, but a comment ...

Hopefully it will give you leads

Try to identify the font file that provides non-zero slant attribute

$ echo "|%{fullname}| %{file} | %{foundry} | %{family}| %{slant}|\n"; fc-list -f "|%{fullname} |%{file} | %{foundry} | %{family}| %{slant}|\n" | grep 'SF Pro' 
| %{fullname}                      | %{file}                             | %{foundry} | %{family}      | %{slant} | \n |
| SF Pro Text Regular              | SF-Pro-Text-Regular.otf             | APPL       | SF Pro Text    |        0 |    |
| SF Pro Italic                    | SF-Pro-Italic.ttf                   | APPL       | SF Pro         |      100 |    |
| SF Pro Text Light Italic         | SF-Pro-Text-LightItalic.otf         | APPL       | SF Pro Text    |      100 |    |
| SF Pro Display Black Italic      | SF-Pro-Display-BlackItalic.otf      | APPL       | SF Pro Display |      100 |    |
| SF Pro Rounded Semibold          | SF-Pro-Rounded-Semibold.otf         | APPL       | SF Pro Rounded |        0 |    |
| SF Pro Text Heavy                | SF-Pro-Text-Heavy.otf               | APPL       | SF Pro Text    |        0 |    |
| SF Pro                           | SF-Pro.ttf                          | APPL       | SF Pro         |        0 |    |
| SF Pro                           | SF-Pro.ttf                          | APPL       | SF Pro         |        0 |    |
| SF Pro Display Regular Italic    | SF-Pro-Display-RegularItalic.otf    | APPL       | SF Pro Display |      100 |    |
| SF Pro Italic                    | SF-Pro-Italic.ttf                   | APPL       | SF Pro         |      100 |    |
| SF Pro Text Light                | SF-Pro-Text-Light.otf               | APPL       | SF Pro Text    |        0 |    |
| SF Pro Display Light Italic      | SF-Pro-Display-LightItalic.otf      | APPL       | SF Pro Display |      100 |    |
| SF Pro Rounded Heavy             | SF-Pro-Rounded-Heavy.otf            | APPL       | SF Pro Rounded |        0 |    |
| SF Pro Display Medium            | SF-Pro-Display-Medium.otf           | APPL       | SF Pro Display |        0 |    |
| SF Pro Display Heavy             | SF-Pro-Display-Heavy.otf            | APPL       | SF Pro Display |        0 |    |
| SF Pro Text Semibold Italic      | SF-Pro-Text-SemiboldItalic.otf      | APPL       | SF Pro Text    |      100 |    |
| SF Pro Rounded Light             | SF-Pro-Rounded-Light.otf            | APPL       | SF Pro Rounded |        0 |    |
| SF Pro Rounded Thin              | SF-Pro-Rounded-Thin.otf             | APPL       | SF Pro Rounded |        0 |    |
| SF Pro Display Semibold          | SF-Pro-Display-Semibold.otf         | APPL       | SF Pro Display |        0 |    |
| SF Pro Display Light             | SF-Pro-Display-Light.otf            | APPL       | SF Pro Display |        0 |    |
| SF Pro Display Thin              | SF-Pro-Display-Thin.otf             | APPL       | SF Pro Display |        0 |    |
| SF Pro Display Regular           | SF-Pro-Display-Regular.otf          | APPL       | SF Pro Display |        0 |    |
| SF Pro Italic                    | SF-Pro-Italic.ttf                   | APPL       | SF Pro         |      100 |    |
| SF Pro Text Thin Italic          | SF-Pro-Text-ThinItalic.otf          | APPL       | SF Pro Text    |      100 |    |
| SF Pro                           | SF-Pro.ttf                          | APPL       | SF Pro         |        0 |    |
| SF Pro                           | SF-Pro.ttf                          | APPL       | SF Pro         |        0 |    |
| SF Pro Text Bold                 | SF-Pro-Text-Bold.otf                | APPL       | SF Pro Text    |        0 |    |
| SF Pro Italic                    | SF-Pro-Italic.ttf                   | APPL       | SF Pro         |      100 |    |
| SF Pro                           | SF-Pro.ttf                          | APPL       | SF Pro         |        0 |    |
| SF Pro Text Regular Italic       | SF-Pro-Text-RegularItalic.otf       | APPL       | SF Pro Text    |      100 |    |
| SF Pro                           | SF-Pro.ttf                          | APPL       | SF Pro         |        0 |    |
| SF Pro Italic                    | SF-Pro-Italic.ttf                   | APPL       | SF Pro         |      100 |    |
| SF Pro Text Medium Italic        | SF-Pro-Text-MediumItalic.otf        | APPL       | SF Pro Text    |      100 |    |
| SF Pro                           | SF-Pro.ttf                          | APPL       | SF Pro         |        0 |    |
| SF Pro                           | SF-Pro.ttf                          | APPL       | SF Pro         |        0 |    |
| SF Pro Rounded Bold              | SF-Pro-Rounded-Bold.otf             | APPL       | SF Pro Rounded |        0 |    |
| SF Pro Display Thin Italic       | SF-Pro-Display-ThinItalic.otf       | APPL       | SF Pro Display |      100 |    |
| SF Pro Text Black                | SF-Pro-Text-Black.otf               | APPL       | SF Pro Text    |        0 |    |
| SF Pro Display Black             | SF-Pro-Display-Black.otf            | APPL       | SF Pro Display |        0 |    |
| SF Pro Rounded Black             | SF-Pro-Rounded-Black.otf            | APPL       | SF Pro Rounded |        0 |    |
| SF Pro Italic                    | SF-Pro-Italic.ttf                   | APPL       | SF Pro         |      100 |    |
| SF Pro Display Semibold Italic   | SF-Pro-Display-SemiboldItalic.otf   | APPL       | SF Pro Display |      100 |    |
| SF Pro                           | SF-Pro.ttf                          | APPL       | SF Pro         |        0 |    |
| SF Pro                           | SF-Pro.ttf                          | APPL       | SF Pro         |        0 |    |
| SF Pro Italic                    | SF-Pro-Italic.ttf                   | APPL       | SF Pro         |      100 |    |
| SF Pro Rounded Medium            | SF-Pro-Rounded-Medium.otf           | APPL       | SF Pro Rounded |        0 |    |
| SF Pro Italic                    | SF-Pro-Italic.ttf                   | APPL       | SF Pro         |      100 |    |
| SF Pro Rounded Regular           | SF-Pro-Rounded-Regular.otf          | APPL       | SF Pro Rounded |        0 |    |
| SF Pro Display Heavy Italic      | SF-Pro-Display-HeavyItalic.otf      | APPL       | SF Pro Display |      100 |    |
| SF Pro Display Ultralight        | SF-Pro-Display-Ultralight.otf       | APPL       | SF Pro Display |        0 |    |
| SF Pro Text Thin                 | SF-Pro-Text-Thin.otf                | APPL       | SF Pro Text    |        0 |    |
| SF Pro Rounded Ultralight        | SF-Pro-Rounded-Ultralight.otf       | APPL       | SF Pro Rounded |        0 |    |
| SF Pro Text Ultralight Italic    | SF-Pro-Text-UltralightItalic.otf    | APPL       | SF Pro Text    |      100 |    |
| SF Pro Display Ultralight Italic | SF-Pro-Display-UltralightItalic.otf | APPL       | SF Pro Display |      100 |    |
| SF Pro Text Semibold             | SF-Pro-Text-Semibold.otf            | APPL       | SF Pro Text    |        0 |    |
| SF Pro Italic                    | SF-Pro-Italic.ttf                   | APPL       | SF Pro         |      100 |    |
| SF Pro Text Heavy Italic         | SF-Pro-Text-HeavyItalic.otf         | APPL       | SF Pro Text    |      100 |    |
| SF Pro Italic                    | SF-Pro-Italic.ttf                   | APPL       | SF Pro         |      100 |    |
| SF Pro Display Medium Italic     | SF-Pro-Display-MediumItalic.otf     | APPL       | SF Pro Display |      100 |    |
| SF Pro Text Bold Italic          | SF-Pro-Text-BoldItalic.otf          | APPL       | SF Pro Text    |      100 |    |
| SF Pro Display Bold Italic       | SF-Pro-Display-BoldItalic.otf       | APPL       | SF Pro Display |      100 |    |
| SF Pro Text Ultralight           | SF-Pro-Text-Ultralight.otf          | APPL       | SF Pro Text    |        0 |    |
| SF Pro Text Black Italic         | SF-Pro-Text-BlackItalic.otf         | APPL       | SF Pro Text    |      100 |    |
| SF Pro Text Medium               | SF-Pro-Text-Medium.otf              | APPL       | SF Pro Text    |        0 |    |
| SF Pro Display Bold              | SF-Pro-Display-Bold.otf             | APPL       | SF Pro Display |        0 |    |


How to quickly identify the string for use with create-fontset-from-fontset-spec

(require 'dash)
(->> (font-family-list)
     (--filter (string-match-p "SF Pro" it)) ; change the family name, if requried
     -uniq
     (--map
      (cons it
        (if nil       ; flip this to t, for simpler result
        (x-family-fonts it)
          (->> (list-fonts (font-spec :family it))
           (--map (list it :name (or (font-get it :name)
                         (mouse-generate-font-name-for-menu it))
                :xlfd-name (font-xlfd-name it))))))))

(("SF Pro"
  (#<font-entity ftcrhb APPL SF\ Pro nil iso10646-1 medium italic normal 0 nil nil 0
         ((:font-entity "~/.local/share/fonts/SF-Pro-Italic.ttf" . 327680))
         > :name "medium italic" :xlfd-name "-APPL-SF Pro-medium-italic-normal-*-*-*-*-*-*-0-iso10646-1")
  (#<font-entity ftcrhb APPL SF\ Pro nil iso10646-1 regular italic normal 0 nil nil 0
         ((:font-entity "~/.local/share/fonts/SF-Pro-Italic.ttf" . 0))
         > :name "regular italic" :xlfd-name "-APPL-SF Pro-regular-italic-normal-*-*-*-*-*-*-0-iso10646-1")
  (#<font-entity ftcrhb APPL SF\ Pro nil iso10646-1 thin normal normal 0 nil nil 0
         ((:font-entity "~/.local/share/fonts/SF-Pro.ttf" . 65536))
         > :name "thin" :xlfd-name "-APPL-SF Pro-thin-normal-normal-*-*-*-*-*-*-0-iso10646-1")
  (#<font-entity ftcrhb APPL SF\ Pro nil iso10646-1 black normal normal 0 nil nil 0
         ((:font-entity "~/.local/share/fonts/SF-Pro.ttf" . 524288))
         > :name "black" :xlfd-name "-APPL-SF Pro-black-normal-normal-*-*-*-*-*-*-0-iso10646-1")
  (#<font-entity ftcrhb APPL SF\ Pro nil iso10646-1 semi-bold normal normal 0 nil nil 0
         ((:font-entity "~/.local/share/fonts/SF-Pro.ttf" . 393216))
         > :name "semi-bold" :xlfd-name "-APPL-SF Pro-semibold-normal-normal-*-*-*-*-*-*-0-iso10646-1")
  (#<font-entity ftcrhb APPL SF\ Pro nil iso10646-1 regular normal normal 0 nil nil 0
         ((:font-entity "~/.local/share/fonts/SF-Pro.ttf" . 0))
         > :name "regular" :xlfd-name "-APPL-SF Pro-regular-normal-normal-*-*-*-*-*-*-0-iso10646-1")
  (#<font-entity ftcrhb APPL SF\ Pro nil iso10646-1 thin normal normal 0 nil nil 0
         ((:font-entity "~/.local/share/fonts/SF-Pro.ttf" . 131072))
         > :name "thin" :xlfd-name "-APPL-SF Pro-thin-normal-normal-*-*-*-*-*-*-0-iso10646-1")
  (#<font-entity ftcrhb APPL SF\ Pro nil iso10646-1 light italic normal 0 nil nil 0
         ((:font-entity "~/.local/share/fonts/SF-Pro-Italic.ttf" . 196608))
         > :name "light italic" :xlfd-name "-APPL-SF Pro-light-italic-normal-*-*-*-*-*-*-0-iso10646-1")
  (#<font-entity ftcrhb APPL SF\ Pro nil iso10646-1 black normal normal 0 nil nil 0
         ((:font-entity "~/.local/share/fonts/SF-Pro.ttf" . 589824))
         > :name "black" :xlfd-name "-APPL-SF Pro-black-normal-normal-*-*-*-*-*-*-0-iso10646-1")
  (#<font-entity ftcrhb APPL SF\ Pro nil iso10646-1 semi-bold italic normal 0 nil nil 0
         ((:font-entity "~/.local/share/fonts/SF-Pro-Italic.ttf" . 393216))
         > :name "semi-bold italic" :xlfd-name "-APPL-SF Pro-semibold-italic-normal-*-*-*-*-*-*-0-iso10646-1")
  (#<font-entity ftcrhb APPL SF\ Pro nil iso10646-1 bold normal normal 0 nil nil 0
         ((:font-entity "~/.local/share/fonts/SF-Pro.ttf" . 458752))
         > :name "bold" :xlfd-name "-APPL-SF Pro-bold-normal-normal-*-*-*-*-*-*-0-iso10646-1")
  (#<font-entity ftcrhb APPL SF\ Pro nil iso10646-1 medium normal normal 0 nil nil 0
         ((:font-entity "~/.local/share/fonts/SF-Pro.ttf" . 327680))
         > :name "medium" :xlfd-name "-APPL-SF Pro-medium-normal-normal-*-*-*-*-*-*-0-iso10646-1")
  (#<font-entity ftcrhb APPL SF\ Pro nil iso10646-1 black italic normal 0 nil nil 0
         ((:font-entity "~/.local/share/fonts/SF-Pro-Italic.ttf" . 524288))
         > :name "black italic" :xlfd-name "-APPL-SF Pro-black-italic-normal-*-*-*-*-*-*-0-iso10646-1")
  (#<font-entity ftcrhb APPL SF\ Pro nil iso10646-1 black italic normal 0 nil nil 0
         ((:font-entity "~/.local/share/fonts/SF-Pro-Italic.ttf" . 589824))
         > :name "black italic" :xlfd-name "-APPL-SF Pro-black-italic-normal-*-*-*-*-*-*-0-iso10646-1")
  (#<font-entity ftcrhb APPL SF\ Pro nil iso10646-1 bold italic normal 0 nil nil 0
         ((:font-entity "~/.local/share/fonts/SF-Pro-Italic.ttf" . 458752))
         > :name "bold italic" :xlfd-name "-APPL-SF Pro-bold-italic-normal-*-*-*-*-*-*-0-iso10646-1")
  (#<font-entity ftcrhb APPL SF\ Pro nil iso10646-1 light normal normal 0 nil nil 0
         ((:font-entity "~/.local/share/fonts/SF-Pro.ttf" . 196608))
         > :name "light" :xlfd-name "-APPL-SF Pro-light-normal-normal-*-*-*-*-*-*-0-iso10646-1")
  (#<font-entity ftcrhb APPL SF\ Pro nil iso10646-1 thin italic normal 0 nil nil 0
         ((:font-entity "~/.local/share/fonts/SF-Pro-Italic.ttf" . 131072))
         > :name "thin italic" :xlfd-name "-APPL-SF Pro-thin-italic-normal-*-*-*-*-*-*-0-iso10646-1")
  (#<font-entity ftcrhb APPL SF\ Pro nil iso10646-1 thin italic normal 0 nil nil 0
         ((:font-entity "~/.local/share/fonts/SF-Pro-Italic.ttf" . 65536))
         > :name "thin italic" :xlfd-name "-APPL-SF Pro-thin-italic-normal-*-*-*-*-*-*-0-iso10646-1"))
 ("SF Pro Rounded"
  (#<font-entity ftcrhb APPL SF\ Pro\ Rounded nil iso10646-1 semi-bold normal normal 0 nil nil 0
         ((:font-entity "~/.local/share/fonts/SF-Pro-Rounded-Semibold.otf" . 0))
         > :name "semi-bold" :xlfd-name "-APPL-SF Pro Rounded-semibold-normal-normal-*-*-*-*-*-*-0-iso10646-1")
  (#<font-entity ftcrhb APPL SF\ Pro\ Rounded nil iso10646-1 regular normal normal 0 nil nil 0
         ((:font-entity "~/.local/share/fonts/SF-Pro-Rounded-Regular.otf" . 0))
         > :name "regular" :xlfd-name "-APPL-SF Pro Rounded-regular-normal-normal-*-*-*-*-*-*-0-iso10646-1")
  (#<font-entity ftcrhb APPL SF\ Pro\ Rounded nil iso10646-1 black normal normal 0 nil nil 0
         ((:font-entity "~/.local/share/fonts/SF-Pro-Rounded-Black.otf" . 0))
         > :name "black" :xlfd-name "-APPL-SF Pro Rounded-black-normal-normal-*-*-*-*-*-*-0-iso10646-1")
  (#<font-entity ftcrhb APPL SF\ Pro\ Rounded nil iso10646-1 semi-bold normal normal 0 nil nil 0
         ((:font-entity "~/.local/share/fonts/SF-Pro-Rounded-Bold.otf" . 0))
         > :name "semi-bold" :xlfd-name "-APPL-SF Pro Rounded-semibold-normal-normal-*-*-*-*-*-*-0-iso10646-1")
  (#<font-entity ftcrhb APPL SF\ Pro\ Rounded nil iso10646-1 extra-bold normal normal 0 nil nil 0
         ((:font-entity "~/.local/share/fonts/SF-Pro-Rounded-Heavy.otf" . 0))
         > :name "extra-bold" :xlfd-name "-APPL-SF Pro Rounded-extrabold-normal-normal-*-*-*-*-*-*-0-iso10646-1")
  (#<font-entity ftcrhb APPL SF\ Pro\ Rounded nil iso10646-1 light normal normal 0 nil nil 0
         ((:font-entity "~/.local/share/fonts/SF-Pro-Rounded-Light.otf" . 0))
         > :name "light" :xlfd-name "-APPL-SF Pro Rounded-light-normal-normal-*-*-*-*-*-*-0-iso10646-1")
  (#<font-entity ftcrhb APPL SF\ Pro\ Rounded nil iso10646-1 medium normal normal 0 nil nil 0
         ((:font-entity "~/.local/share/fonts/SF-Pro-Rounded-Medium.otf" . 0))
         > :name "medium" :xlfd-name "-APPL-SF Pro Rounded-medium-normal-normal-*-*-*-*-*-*-0-iso10646-1")
  (#<font-entity ftcrhb APPL SF\ Pro\ Rounded nil iso10646-1 thin normal normal 0 nil nil 0
         ((:font-entity "~/.local/share/fonts/SF-Pro-Rounded-Ultralight.otf" . 0))
         > :name "thin" :xlfd-name "-APPL-SF Pro Rounded-thin-normal-normal-*-*-*-*-*-*-0-iso10646-1")
  (#<font-entity ftcrhb APPL SF\ Pro\ Rounded nil iso10646-1 ultra-light normal normal 0 nil nil 0
         ((:font-entity "~/.local/share/fonts/SF-Pro-Rounded-Thin.otf" . 0))
         > :name "ultra-light" :xlfd-name "-APPL-SF Pro Rounded-ultralight-normal-normal-*-*-*-*-*-*-0-iso10646-1"))
 ("SF Pro Display"
  (#<font-entity ftcrhb APPL SF\ Pro\ Display nil iso10646-1 ultra-light italic normal 0 nil nil 0
         ((:font-entity "~/.local/share/fonts/SF-Pro-Display-ThinItalic.otf" . 0))
         > :name "ultra-light italic" :xlfd-name "-APPL-SF Pro Display-ultralight-italic-normal-*-*-*-*-*-*-0-iso10646-1")
  (#<font-entity ftcrhb APPL SF\ Pro\ Display nil iso10646-1 thin normal normal 0 nil nil 0
         ((:font-entity "~/.local/share/fonts/SF-Pro-Display-Ultralight.otf" . 0))
         > :name "thin" :xlfd-name "-APPL-SF Pro Display-thin-normal-normal-*-*-*-*-*-*-0-iso10646-1")
  (#<font-entity ftcrhb APPL SF\ Pro\ Display nil iso10646-1 light italic normal 0 nil nil 0
         ((:font-entity "~/.local/share/fonts/SF-Pro-Display-LightItalic.otf" . 0))
         > :name "light italic" :xlfd-name "-APPL-SF Pro Display-light-italic-normal-*-*-*-*-*-*-0-iso10646-1")
  (#<font-entity ftcrhb APPL SF\ Pro\ Display nil iso10646-1 regular italic normal 0 nil nil 0
         ((:font-entity "~/.local/share/fonts/SF-Pro-Display-RegularItalic.otf" . 0))
         > :name "regular italic" :xlfd-name "-APPL-SF Pro Display-regular-italic-normal-*-*-*-*-*-*-0-iso10646-1")
  (#<font-entity ftcrhb APPL SF\ Pro\ Display nil iso10646-1 extra-bold italic normal 0 nil nil 0
         ((:font-entity "~/.local/share/fonts/SF-Pro-Display-HeavyItalic.otf" . 0))
         > :name "extra-bold italic" :xlfd-name "-APPL-SF Pro Display-extrabold-italic-normal-*-*-*-*-*-*-0-iso10646-1")
  (#<font-entity ftcrhb APPL SF\ Pro\ Display nil iso10646-1 semi-bold italic normal 0 nil nil 0
         ((:font-entity "~/.local/share/fonts/SF-Pro-Display-BoldItalic.otf" . 0))
         > :name "semi-bold italic" :xlfd-name "-APPL-SF Pro Display-semibold-italic-normal-*-*-*-*-*-*-0-iso10646-1")
  (#<font-entity ftcrhb APPL SF\ Pro\ Display nil iso10646-1 black normal normal 0 nil nil 0
         ((:font-entity "~/.local/share/fonts/SF-Pro-Display-Black.otf" . 0))
         > :name "black" :xlfd-name "-APPL-SF Pro Display-black-normal-normal-*-*-*-*-*-*-0-iso10646-1")
  (#<font-entity ftcrhb APPL SF\ Pro\ Display nil iso10646-1 semi-bold normal normal 0 nil nil 0
         ((:font-entity "~/.local/share/fonts/SF-Pro-Display-Semibold.otf" . 0))
         > :name "semi-bold" :xlfd-name "-APPL-SF Pro Display-semibold-normal-normal-*-*-*-*-*-*-0-iso10646-1")
  (#<font-entity ftcrhb APPL SF\ Pro\ Display nil iso10646-1 medium normal normal 0 nil nil 0
         ((:font-entity "~/.local/share/fonts/SF-Pro-Display-Medium.otf" . 0))
         > :name "medium" :xlfd-name "-APPL-SF Pro Display-medium-normal-normal-*-*-*-*-*-*-0-iso10646-1")
  (#<font-entity ftcrhb APPL SF\ Pro\ Display nil iso10646-1 medium italic normal 0 nil nil 0
         ((:font-entity "~/.local/share/fonts/SF-Pro-Display-MediumItalic.otf" . 0))
         > :name "medium italic" :xlfd-name "-APPL-SF Pro Display-medium-italic-normal-*-*-*-*-*-*-0-iso10646-1")
  (#<font-entity ftcrhb APPL SF\ Pro\ Display nil iso10646-1 regular normal normal 0 nil nil 0
         ((:font-entity "~/.local/share/fonts/SF-Pro-Display-Regular.otf" . 0))
         > :name "regular" :xlfd-name "-APPL-SF Pro Display-regular-normal-normal-*-*-*-*-*-*-0-iso10646-1")
  (#<font-entity ftcrhb APPL SF\ Pro\ Display nil iso10646-1 semi-bold normal normal 0 nil nil 0
         ((:font-entity "~/.local/share/fonts/SF-Pro-Display-Bold.otf" . 0))
         > :name "semi-bold" :xlfd-name "-APPL-SF Pro Display-semibold-normal-normal-*-*-*-*-*-*-0-iso10646-1")
  (#<font-entity ftcrhb APPL SF\ Pro\ Display nil iso10646-1 extra-bold normal normal 0 nil nil 0
         ((:font-entity "~/.local/share/fonts/SF-Pro-Display-Heavy.otf" . 0))
         > :name "extra-bold" :xlfd-name "-APPL-SF Pro Display-extrabold-normal-normal-*-*-*-*-*-*-0-iso10646-1")
  (#<font-entity ftcrhb APPL SF\ Pro\ Display nil iso10646-1 light normal normal 0 nil nil 0
         ((:font-entity "~/.local/share/fonts/SF-Pro-Display-Light.otf" . 0))
         > :name "light" :xlfd-name "-APPL-SF Pro Display-light-normal-normal-*-*-*-*-*-*-0-iso10646-1")
  (#<font-entity ftcrhb APPL SF\ Pro\ Display nil iso10646-1 semi-bold italic normal 0 nil nil 0
         ((:font-entity "~/.local/share/fonts/SF-Pro-Display-SemiboldItalic.otf" . 0))
         > :name "semi-bold italic" :xlfd-name "-APPL-SF Pro Display-semibold-italic-normal-*-*-*-*-*-*-0-iso10646-1")
  (#<font-entity ftcrhb APPL SF\ Pro\ Display nil iso10646-1 thin italic normal 0 nil nil 0
         ((:font-entity "~/.local/share/fonts/SF-Pro-Display-UltralightItalic.otf" . 0))
         > :name "thin italic" :xlfd-name "-APPL-SF Pro Display-thin-italic-normal-*-*-*-*-*-*-0-iso10646-1")
  (#<font-entity ftcrhb APPL SF\ Pro\ Display nil iso10646-1 black italic normal 0 nil nil 0
         ((:font-entity "~/.local/share/fonts/SF-Pro-Display-BlackItalic.otf" . 0))
         > :name "black italic" :xlfd-name "-APPL-SF Pro Display-black-italic-normal-*-*-*-*-*-*-0-iso10646-1")
  (#<font-entity ftcrhb APPL SF\ Pro\ Display nil iso10646-1 ultra-light normal normal 0 nil nil 0
         ((:font-entity "~/.local/share/fonts/SF-Pro-Display-Thin.otf" . 0))
         > :name "ultra-light" :xlfd-name "-APPL-SF Pro Display-ultralight-normal-normal-*-*-*-*-*-*-0-iso10646-1"))
 ("SF Pro Text"
  (#<font-entity ftcrhb APPL SF\ Pro\ Text nil iso10646-1 black italic normal 0 nil nil 0
         ((:font-entity "~/.local/share/fonts/SF-Pro-Text-BlackItalic.otf" . 0))
         > :name "black italic" :xlfd-name "-APPL-SF Pro Text-black-italic-normal-*-*-*-*-*-*-0-iso10646-1")
  (#<font-entity ftcrhb APPL SF\ Pro\ Text nil iso10646-1 extra-bold italic normal 0 nil nil 0
         ((:font-entity "~/.local/share/fonts/SF-Pro-Text-HeavyItalic.otf" . 0))
         > :name "extra-bold italic" :xlfd-name "-APPL-SF Pro Text-extrabold-italic-normal-*-*-*-*-*-*-0-iso10646-1")
  (#<font-entity ftcrhb APPL SF\ Pro\ Text nil iso10646-1 thin italic normal 0 nil nil 0
         ((:font-entity "~/.local/share/fonts/SF-Pro-Text-UltralightItalic.otf" . 0))
         > :name "thin italic" :xlfd-name "-APPL-SF Pro Text-thin-italic-normal-*-*-*-*-*-*-0-iso10646-1")
  (#<font-entity ftcrhb APPL SF\ Pro\ Text nil iso10646-1 semi-bold italic normal 0 nil nil 0
         ((:font-entity "~/.local/share/fonts/SF-Pro-Text-SemiboldItalic.otf" . 0))
         > :name "semi-bold italic" :xlfd-name "-APPL-SF Pro Text-semibold-italic-normal-*-*-*-*-*-*-0-iso10646-1")
  (#<font-entity ftcrhb APPL SF\ Pro\ Text nil iso10646-1 regular italic normal 0 nil nil 0
         ((:font-entity "~/.local/share/fonts/SF-Pro-Text-RegularItalic.otf" . 0))
         > :name "regular italic" :xlfd-name "-APPL-SF Pro Text-regular-italic-normal-*-*-*-*-*-*-0-iso10646-1")
  (#<font-entity ftcrhb APPL SF\ Pro\ Text nil iso10646-1 thin normal normal 0 nil nil 0
         ((:font-entity "~/.local/share/fonts/SF-Pro-Text-Ultralight.otf" . 0))
         > :name "thin" :xlfd-name "-APPL-SF Pro Text-thin-normal-normal-*-*-*-*-*-*-0-iso10646-1")
  (#<font-entity ftcrhb APPL SF\ Pro\ Text nil iso10646-1 medium italic normal 0 nil nil 0
         ((:font-entity "~/.local/share/fonts/SF-Pro-Text-MediumItalic.otf" . 0))
         > :name "medium italic" :xlfd-name "-APPL-SF Pro Text-medium-italic-normal-*-*-*-*-*-*-0-iso10646-1")
  (#<font-entity ftcrhb APPL SF\ Pro\ Text nil iso10646-1 medium normal normal 0 nil nil 0
         ((:font-entity "~/.local/share/fonts/SF-Pro-Text-Medium.otf" . 0))
         > :name "medium" :xlfd-name "-APPL-SF Pro Text-medium-normal-normal-*-*-*-*-*-*-0-iso10646-1")
  (#<font-entity ftcrhb APPL SF\ Pro\ Text nil iso10646-1 semi-bold italic normal 0 nil nil 0
         ((:font-entity "~/.local/share/fonts/SF-Pro-Text-BoldItalic.otf" . 0))
         > :name "semi-bold italic" :xlfd-name "-APPL-SF Pro Text-semibold-italic-normal-*-*-*-*-*-*-0-iso10646-1")
  (#<font-entity ftcrhb APPL SF\ Pro\ Text nil iso10646-1 semi-bold normal normal 0 nil nil 0
         ((:font-entity "~/.local/share/fonts/SF-Pro-Text-Bold.otf" . 0))
         > :name "semi-bold" :xlfd-name "-APPL-SF Pro Text-semibold-normal-normal-*-*-*-*-*-*-0-iso10646-1")
  (#<font-entity ftcrhb APPL SF\ Pro\ Text nil iso10646-1 black normal normal 0 nil nil 0
         ((:font-entity "~/.local/share/fonts/SF-Pro-Text-Black.otf" . 0))
         > :name "black" :xlfd-name "-APPL-SF Pro Text-black-normal-normal-*-*-*-*-*-*-0-iso10646-1")
  (#<font-entity ftcrhb APPL SF\ Pro\ Text nil iso10646-1 regular normal normal 0 nil nil 0
         ((:font-entity "~/.local/share/fonts/SF-Pro-Text-Regular.otf" . 0))
         > :name "regular" :xlfd-name "-APPL-SF Pro Text-regular-normal-normal-*-*-*-*-*-*-0-iso10646-1")
  (#<font-entity ftcrhb APPL SF\ Pro\ Text nil iso10646-1 ultra-light normal normal 0 nil nil 0
         ((:font-entity "~/.local/share/fonts/SF-Pro-Text-Thin.otf" . 0))
         > :name "ultra-light" :xlfd-name "-APPL-SF Pro Text-ultralight-normal-normal-*-*-*-*-*-*-0-iso10646-1")
  (#<font-entity ftcrhb APPL SF\ Pro\ Text nil iso10646-1 light italic normal 0 nil nil 0
         ((:font-entity "~/.local/share/fonts/SF-Pro-Text-LightItalic.otf" . 0))
         > :name "light italic" :xlfd-name "-APPL-SF Pro Text-light-italic-normal-*-*-*-*-*-*-0-iso10646-1")
  (#<font-entity ftcrhb APPL SF\ Pro\ Text nil iso10646-1 light normal normal 0 nil nil 0
         ((:font-entity "~/.local/share/fonts/SF-Pro-Text-Light.otf" . 0))
         > :name "light" :xlfd-name "-APPL-SF Pro Text-light-normal-normal-*-*-*-*-*-*-0-iso10646-1")
  (#<font-entity ftcrhb APPL SF\ Pro\ Text nil iso10646-1 extra-bold normal normal 0 nil nil 0
         ((:font-entity "~/.local/share/fonts/SF-Pro-Text-Heavy.otf" . 0))
         > :name "extra-bold" :xlfd-name "-APPL-SF Pro Text-extrabold-normal-normal-*-*-*-*-*-*-0-iso10646-1")
  (#<font-entity ftcrhb APPL SF\ Pro\ Text nil iso10646-1 semi-bold normal normal 0 nil nil 0
         ((:font-entity "~/.local/share/fonts/SF-Pro-Text-Semibold.otf" . 0))
         > :name "semi-bold" :xlfd-name "-APPL-SF Pro Text-semibold-normal-normal-*-*-*-*-*-*-0-iso10646-1")
  (#<font-entity ftcrhb APPL SF\ Pro\ Text nil iso10646-1 ultra-light italic normal 0 nil nil 0
         ((:font-entity "~/.local/share/fonts/SF-Pro-Text-ThinItalic.otf" . 0))
         > :name "ultra-light italic" :xlfd-name "-APPL-SF Pro Text-ultralight-italic-normal-*-*-*-*-*-*-0-iso10646-1")))
2
  • Thanks for digging into this! A quick try of this answer seems to work! Although I don't fully understand what causes the issue now. I originally think that there maybe something wrong with the PingFang Mono SC font (as the issue also exists when it's paired with other variable fonts) and the :font part somehow misread its properties as defaults and other faces inherits that (the doc says :font sets lots of things). I try to use :family instead that that's not working. Aug 15, 2022 at 2:16
  • Can you also give me a tl;dr version of how this issue happens :)? I also need some time to read and fully understand your posts. Aug 15, 2022 at 2:18
0

FWIW, I see no issues with Debian/Linux.


Try identifying the xfld-name that does NOT have italic in description. (In your question you have already identified a fontspec that is "normal" or "regular" as opposed to "italic" or "oblique". If not use the following elisp code to identify the xfld strings

(require 'dash)
(->> (font-family-list)
     (--filter (string-match-p "SF Pro" it)) ; change the family name, if requried
     -uniq
     (--map
      (cons it
        (if nil       ; flip this to t, for simpler result
        (x-family-fonts it)
          (->> (list-fonts (font-spec :family it))
               (--map (font-xlfd-name it) ))))))

(("SF Pro"
  "-APPL-SF Pro-thin-normal-normal-*-*-*-*-*-*-0-iso10646-1"
  "-APPL-SF Pro-black-normal-normal-*-*-*-*-*-*-0-iso10646-1"
  "-APPL-SF Pro-semibold-normal-normal-*-*-*-*-*-*-0-iso10646-1"
  "-APPL-SF Pro-regular-normal-normal-*-*-*-*-*-*-0-iso10646-1"
  "-APPL-SF Pro-thin-normal-normal-*-*-*-*-*-*-0-iso10646-1"
  "-APPL-SF Pro-black-normal-normal-*-*-*-*-*-*-0-iso10646-1"
  "-APPL-SF Pro-bold-normal-normal-*-*-*-*-*-*-0-iso10646-1"
  "-APPL-SF Pro-medium-normal-normal-*-*-*-*-*-*-0-iso10646-1"
  "-APPL-SF Pro-light-normal-normal-*-*-*-*-*-*-0-iso10646-1"
  )
 ("SF Pro Rounded"
  "-APPL-SF Pro Rounded-semibold-normal-normal-*-*-*-*-*-*-0-iso10646-1"
  "-APPL-SF Pro Rounded-regular-normal-normal-*-*-*-*-*-*-0-iso10646-1"
  "-APPL-SF Pro Rounded-black-normal-normal-*-*-*-*-*-*-0-iso10646-1"
  "-APPL-SF Pro Rounded-semibold-normal-normal-*-*-*-*-*-*-0-iso10646-1"
  "-APPL-SF Pro Rounded-extrabold-normal-normal-*-*-*-*-*-*-0-iso10646-1"
  "-APPL-SF Pro Rounded-light-normal-normal-*-*-*-*-*-*-0-iso10646-1"
  "-APPL-SF Pro Rounded-medium-normal-normal-*-*-*-*-*-*-0-iso10646-1"
  "-APPL-SF Pro Rounded-thin-normal-normal-*-*-*-*-*-*-0-iso10646-1"
  "-APPL-SF Pro Rounded-ultralight-normal-normal-*-*-*-*-*-*-0-iso10646-1"
  )
 ("SF Pro Display"
  "-APPL-SF Pro Display-thin-normal-normal-*-*-*-*-*-*-0-iso10646-1"
  "-APPL-SF Pro Display-black-normal-normal-*-*-*-*-*-*-0-iso10646-1"
  "-APPL-SF Pro Display-semibold-normal-normal-*-*-*-*-*-*-0-iso10646-1"
  "-APPL-SF Pro Display-medium-normal-normal-*-*-*-*-*-*-0-iso10646-1"
  "-APPL-SF Pro Display-regular-normal-normal-*-*-*-*-*-*-0-iso10646-1"
  "-APPL-SF Pro Display-semibold-normal-normal-*-*-*-*-*-*-0-iso10646-1"
  "-APPL-SF Pro Display-extrabold-normal-normal-*-*-*-*-*-*-0-iso10646-1"
  "-APPL-SF Pro Display-light-normal-normal-*-*-*-*-*-*-0-iso10646-1"
  "-APPL-SF Pro Display-ultralight-normal-normal-*-*-*-*-*-*-0-iso10646-1"
  )
 ("SF Pro Text"
  "-APPL-SF Pro Text-thin-normal-normal-*-*-*-*-*-*-0-iso10646-1"
  "-APPL-SF Pro Text-medium-normal-normal-*-*-*-*-*-*-0-iso10646-1"
  "-APPL-SF Pro Text-semibold-normal-normal-*-*-*-*-*-*-0-iso10646-1"
  "-APPL-SF Pro Text-black-normal-normal-*-*-*-*-*-*-0-iso10646-1"
  "-APPL-SF Pro Text-regular-normal-normal-*-*-*-*-*-*-0-iso10646-1"
  "-APPL-SF Pro Text-ultralight-normal-normal-*-*-*-*-*-*-0-iso10646-1"
  "-APPL-SF Pro Text-light-normal-normal-*-*-*-*-*-*-0-iso10646-1"
  "-APPL-SF Pro Text-extrabold-normal-normal-*-*-*-*-*-*-0-iso10646-1"
  "-APPL-SF Pro Text-semibold-normal-normal-*-*-*-*-*-*-0-iso10646-1"
  ))

In the above list, replace the iso10646-1 part with fontset-xxx; it doesn't matter what xxx happens to be. (See https://emacs.stackexchange.com/a/73067/31220 if you want to do away with manually editing out the iso10646-1 part, and replacing it with a fontset name)

Then explicity set the :font property of font-lock-comment-face, as below

;; fontset-1 uses regular

(create-fontset-from-fontset-spec
 "-APPL-SF Pro-regular-normal-normal-*-*-*-*-*-*-0-fontset-1")

(set-face-attribute 'font-lock-comment-face nil :font "fontset-1")

;; fontset-2 uses italic

(create-fontset-from-fontset-spec
 "-APPL-SF Pro-medium-italic-normal-*-*-*-*-*-*-0-fontset-2")

(set-face-attribute 'font-lock-comment-face nil :font "fontset-2")

;; fontset-3 uses bold
(create-fontset-from-fontset-spec
 "-APPL-SF Pro-bold-normal-normal-*-*-*-*-*-*-0-fontset-3")

(set-face-attribute 'font-lock-comment-face nil :font "fontset-3")


5
  • When I try the code snippet for PingFang Mono SC, I get (("PingFang Mono SC" "-*-PingFang Mono SC-normal-oblique-normal-*-*-*-*-*-m-0-iso10646-1" "-*-PingFang Mono SC-bold-oblique-normal-*-*-*-*-*-m-0-iso10646-1")). There no normal-normal-normal for it. Maybe there's some issue of this font? Aug 15, 2022 at 2:48
  • This is what I get (("PingFang Mono SC" "-APPL-PingFang Mono SC-bold-normal-normal-*-*-*-*-*-*-0-iso10646-1" "-APPL-PingFang Mono SC-regular-normal-normal-*-*-*-*-*-*-0-iso10646-1")). Which OS are you in? I downloaded the MacOS versions of the fonts, only yesterday. Have you looked at the output from fc-list? As noted in emacs.stackexchange.com/a/72415/31220, the Coelocanth font was using italic style, but the font file wasn't declaring the slant property. Use fontforge on PingFang font file to see if something is amiss ...
    – user31220
    Aug 15, 2022 at 3:10
  • | %{fullname} | %{file} | %{foundry} | %{family} | %{slant} | \n | |--------------------------+-------------------------------------------------+------------+------------------+----------+----| | PingFang Mono SC Bold | ~/.local/share/fonts/PingFangMonoSC-Bold.ttf | APPL | PingFang Mono SC | 0 | | | PingFang Mono SC Regular | ~/.local/share/fonts/PingFangMonoSC-Regular.ttf | APPL | PingFang Mono SC | 0 | | The foundry in my case is APPL. I suspect you have downloaded the windows version
    – user31220
    Aug 15, 2022 at 3:15
  • I'm using macOS 12.5. The OS itself does not ship with the mono version of PingFang. So I got the font from the link in the original post. I don't seem to find other available places for the font. Where did you get the font? The fc-list result is |%{fullname}| %{file} | %{foundry} | %{family}| %{slant}|\n |PingFang Mono SC Regular |/Users/User/Library/Fonts/PingFangMonoSC-Regular.ttf | APPL | PingFang Mono SC| 0| |PingFang Mono SC Bold |/Users/User/Library/Fonts/PingFangMonoSC-Bold.ttf | APPL | PingFang Mono SC| 0|. Aug 15, 2022 at 3:20
  • The Slant is 0 in your output. I downloaded it from the link. May be they revised the font files since you downloaded. If I were you, I wouldn't worry about the font file, as long as I get what I want.
    – user31220
    Aug 15, 2022 at 3:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.