Skip to content

Commit

Permalink
Support the "medium" font weight
Browse files Browse the repository at this point in the history
* lisp/faces.el (set-face-attribute): Mention new font weights in
doc string.
* src/font.c (struct table_entry): Allow more synonyms.
(weight_table): Expand to support separating medium and normal
weights.  Also add heavy/ultra-heavy and some other variants.
(font_parse_fcname): Support more names.

* src/gtkutil.c (xg_weight_to_symbol): Support all the Pango weights.
(xg_style_to_symbol): Make into functions.
(xg_get_font): Adjust.

* src/w32font.c (w32_to_fc_weight): Use symbols.

* src/xfaces.c (syms_of_xfaces): Add the new symbols.
  • Loading branch information
larsmagne committed Oct 21, 2021
1 parent 4e9764e commit 65fd3ca
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 32 deletions.
8 changes: 8 additions & 0 deletions etc/NEWS
Expand Up @@ -53,6 +53,14 @@ time.
Jumping to source from "*Help*" buffer moves the point when the source
buffer is already open. Now, the old point is pushed to mark ring.

** Fonts

---
*** Emacs now supports "medium" fonts.
Emacs previously didn't distinguish between the "regular" weight and
the "medium" weight, but it now also supports the (heavier) "medium"
weight.


* Editing Changes in Emacs 29.1

Expand Down
7 changes: 4 additions & 3 deletions lisp/faces.el
Expand Up @@ -702,9 +702,10 @@ for it to be relative to).
`:weight'
VALUE specifies the weight of the font to use. It must be one of the
symbols `ultra-bold', `extra-bold', `bold', `semi-bold', `normal',
`semi-light', `light', `extra-light', `ultra-light'.
VALUE specifies the weight of the font to use. It must be one of
the symbols `ultra-heavy', `heavy', `ultra-bold', `extra-bold',
`bold', `semi-bold', `medium', `normal', `book', `semi-light',
`light', `extra-light', `ultra-light', or `thin'.
`:slant'
Expand Down
33 changes: 22 additions & 11 deletions src/font.c
Expand Up @@ -57,24 +57,26 @@ struct table_entry
int numeric;
/* The first one is a valid name as a face attribute.
The second one (if any) is a typical name in XLFD field. */
const char *names[5];
const char *names[6];
};

/* Table of weight numeric values and their names. This table must be
sorted by numeric values in ascending order. */
sorted by numeric values in ascending order and the numeric values
must approximately match the weights in the font files. */

static const struct table_entry weight_table[] =
{
{ 0, { "thin" }},
{ 20, { "ultra-light", "ultralight" }},
{ 40, { "extra-light", "extralight" }},
{ 40, { "ultra-light", "ultralight", "extra-light", "extralight" }},
{ 50, { "light" }},
{ 75, { "semi-light", "semilight", "demilight", "book" }},
{ 100, { "normal", "medium", "regular", "unspecified" }},
{ 180, { "semi-bold", "semibold", "demibold", "demi" }},
{ 55, { "semi-light", "semilight", "demilight" }},
{ 80, { "regular", "normal", "unspecified", "book" }},
{ 100, { "medium" }},
{ 180, { "semi-bold", "semibold", "demibold", "demi-bold", "demi" }},
{ 200, { "bold" }},
{ 205, { "extra-bold", "extrabold" }},
{ 210, { "ultra-bold", "ultrabold", "black" }}
{ 205, { "extra-bold", "extrabold", "ultra-bold", "ultrabold" }},
{ 210, { "black", "heavy" }},
{ 250, { "ultra-heavy", "ultraheavy" }}
};

/* Table of slant numeric values and their names. This table must be
Expand Down Expand Up @@ -1484,11 +1486,20 @@ font_parse_fcname (char *name, ptrdiff_t len, Lisp_Object font)
#define PROP_MATCH(STR) (word_len == strlen (STR) \
&& memcmp (p, STR, strlen (STR)) == 0)

if (PROP_MATCH ("light")
if (PROP_MATCH ("thin")
|| PROP_MATCH ("ultra-light")
|| PROP_MATCH ("light")
|| PROP_MATCH ("semi-light")
|| PROP_MATCH ("book")
|| PROP_MATCH ("medium")
|| PROP_MATCH ("normal")
|| PROP_MATCH ("semibold")
|| PROP_MATCH ("demibold")
|| PROP_MATCH ("bold")
|| PROP_MATCH ("black"))
|| PROP_MATCH ("ultra-bold")
|| PROP_MATCH ("black")
|| PROP_MATCH ("heavy")
|| PROP_MATCH ("ultra-heavy"))
FONT_SET_STYLE (font, FONT_WEIGHT_INDEX, val);
else if (PROP_MATCH ("roman")
|| PROP_MATCH ("italic")
Expand Down
44 changes: 28 additions & 16 deletions src/gtkutil.c
Expand Up @@ -2237,20 +2237,32 @@ xg_get_file_name (struct frame *f,

#ifdef HAVE_GTK3

#define XG_WEIGHT_TO_SYMBOL(w) \
(w <= PANGO_WEIGHT_THIN ? Qextra_light \
: w <= PANGO_WEIGHT_ULTRALIGHT ? Qlight \
: w <= PANGO_WEIGHT_LIGHT ? Qsemi_light \
: w < PANGO_WEIGHT_MEDIUM ? Qnormal \
: w <= PANGO_WEIGHT_SEMIBOLD ? Qsemi_bold \
: w <= PANGO_WEIGHT_BOLD ? Qbold \
: w <= PANGO_WEIGHT_HEAVY ? Qextra_bold \
: Qultra_bold)

#define XG_STYLE_TO_SYMBOL(s) \
(s == PANGO_STYLE_OBLIQUE ? Qoblique \
: s == PANGO_STYLE_ITALIC ? Qitalic \
: Qnormal)
static
Lisp_Object xg_weight_to_symbol (PangoWeight w)
{
return
(w <= PANGO_WEIGHT_THIN ? Qthin /* 100 */
: w <= PANGO_WEIGHT_ULTRALIGHT ? Qultra_light /* 200 */
: w <= PANGO_WEIGHT_LIGHT ? Qlight /* 300 */
: w <= PANGO_WEIGHT_SEMILIGHT ? Qsemi_light /* 350 */
: w <= PANGO_WEIGHT_BOOK ? Qbook /* 380 */
: w <= PANGO_WEIGHT_NORMAL ? Qnormal /* 400 */
: w <= PANGO_WEIGHT_MEDIUM ? Qmedium /* 500 */
: w <= PANGO_WEIGHT_SEMIBOLD ? Qsemi_bold /* 600 */
: w <= PANGO_WEIGHT_BOLD ? Qbold /* 700 */
: w <= PANGO_WEIGHT_ULTRABOLD ? Qultra_bold /* 800 */
: w <= PANGO_WEIGHT_HEAVY ? Qblack /* 900 */
: Qultra_heavy); /* 1000 */
}

static
Lisp_Object xg_style_to_symbol (PangoStyle s)
{
return
(s == PANGO_STYLE_OBLIQUE ? Qoblique
: s == PANGO_STYLE_ITALIC ? Qitalic
: Qnormal);
}

#endif /* HAVE_GTK3 */

Expand Down Expand Up @@ -2341,8 +2353,8 @@ xg_get_font (struct frame *f, const char *default_name)
font = CALLN (Ffont_spec,
QCfamily, build_string (family),
QCsize, make_float (pango_units_to_double (size)),
QCweight, XG_WEIGHT_TO_SYMBOL (weight),
QCslant, XG_STYLE_TO_SYMBOL (style));
QCweight, xg_weight_to_symbol (weight),
QCslant, xg_style_to_symbol (style));

char *font_desc_str = pango_font_description_to_string (desc);
dupstring (&x_last_font_name, font_desc_str);
Expand Down
4 changes: 2 additions & 2 deletions src/w32font.c
Expand Up @@ -2000,11 +2000,11 @@ w32_encode_weight (int n)
static Lisp_Object
w32_to_fc_weight (int n)
{
if (n >= FW_HEAVY) return intern ("black");
if (n >= FW_HEAVY) return Qbold;
if (n >= FW_EXTRABOLD) return Qextra_bold;
if (n >= FW_BOLD) return Qbold;
if (n >= FW_SEMIBOLD) return intern ("demibold");
if (n >= FW_NORMAL) return intern ("medium");
if (n >= FW_NORMAL) return Qmedium;
if (n >= FW_LIGHT) return Qlight;
if (n >= FW_EXTRALIGHT) return Qextra_light;
return intern ("thin");
Expand Down
7 changes: 7 additions & 0 deletions src/xfaces.c
Expand Up @@ -6933,13 +6933,20 @@ syms_of_xfaces (void)
DEFSYM (Qpressed_button, "pressed-button");
DEFSYM (Qflat_button, "flat-button");
DEFSYM (Qnormal, "normal");
DEFSYM (Qthin, "thin");
DEFSYM (Qextra_light, "extra-light");
DEFSYM (Qultra_light, "ultra-light");
DEFSYM (Qlight, "light");
DEFSYM (Qsemi_light, "semi-light");
DEFSYM (Qmedium, "medium");
DEFSYM (Qsemi_bold, "semi-bold");
DEFSYM (Qbook, "book");
DEFSYM (Qbold, "bold");
DEFSYM (Qextra_bold, "extra-bold");
DEFSYM (Qultra_bold, "ultra-bold");
DEFSYM (Qheavy, "heavy");
DEFSYM (Qultra_heavy, "ultra-heavy");
DEFSYM (Qblack, "black");
DEFSYM (Qoblique, "oblique");
DEFSYM (Qitalic, "italic");

Expand Down

0 comments on commit 65fd3ca

Please sign in to comment.