TransWikia.com

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
     FONT.

     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!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP