How to get ":size" from font-spec

Emacs Asked by Enze Chi on December 11, 2020

How can I get :size from font-spec using Elisp?

One Answer

What about the function font-get? For example:

(font-get (font-spec :size 10) :size) ; => 10

Quoth its docstring:

font-get is a built-in function in `C source code'.

(font-get FONT KEY)

  Probably introduced at or before Emacs version 23.1.

Return the value of FONT's property KEY.
FONT is a font-spec, a font-entity, or a font-object.
KEY is any symbol, but these are reserved for specific meanings:
  :family, :weight, :slant, :width, :foundry, :adstyle, :registry,
  :size, :name, :script, :otf
See the documentation of `font-spec' for their meanings.
In addition, if FONT is a font-entity or a font-object, values of
:script and :otf are different from those of a font-spec as below:

The value of :script may be a list of scripts that are supported by the font.

The value of :otf is a cons (GSUB . GPOS) where GSUB and GPOS are lists
representing the OpenType features supported by the font by this form:
  ((SCRIPT (LANGSYS FEATURE ...) ...) ...)
SCRIPT, LANGSYS, and FEATURE are all symbols representing OpenType
Layout tags.

In addition to the keys listed abobe, the following keys are reserved
for the specific meanings as below:

The value of :combining-capability is non-nil if the font-backend of
FONT supports rendering of combining characters for non-OTF fonts.

Quoth (info "(elisp) Low-Level Font"):

   The following functions can be used to obtain information about a
font.  For these functions, the FONT argument can be a font object, a
font entity, or a font spec.

 -- Function: font-get font property
     This function returns the value of the font property PROPERTY for

     If FONT is a font spec and the font spec does not specify PROPERTY,
     the return value is ‘nil’.  If FONT is a font object or font
     entity, the value for the :SCRIPT property may be a list of scripts
     supported by the font.

Correct answer by Basil on December 11, 2020

Add your own answers!

Related Questions

Force Emacs to start in text mode

1  Asked on November 15, 2021 by ddc


Move point inside of image overlay

2  Asked on November 10, 2021 by cardano


Emacs 26.3: Weird frame title issue with KDE

1  Asked on November 10, 2021 by ed-sabol


How to call `org-sparse-tree` from Lisp?

1  Asked on September 2, 2021 by user2567544


Flycheck – Eslint: ‘config file: missing or incorrect’

1  Asked on September 2, 2021 by ben-krck


Emacs fails to open gnuplot files with extension .gp

1  Asked on September 2, 2021 by paul-c


Automatically activating python virtual environments with pyvenv

1  Asked on September 2, 2021 by jacob-pavlock


Ask a Question

Get help from others!

© 2022 All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP