[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 65fd3ca: Support the "medium" font weight
From: |
Lars Ingebrigtsen |
Subject: |
master 65fd3ca: Support the "medium" font weight |
Date: |
Wed, 20 Oct 2021 22:30:13 -0400 (EDT) |
branch: master
commit 65fd3ca84f75aee0dfebb87fa793dae57c1caf35
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>
Support the "medium" font weight
* 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.
---
etc/NEWS | 8 ++++++++
lisp/faces.el | 7 ++++---
src/font.c | 33 ++++++++++++++++++++++-----------
src/gtkutil.c | 44 ++++++++++++++++++++++++++++----------------
src/w32font.c | 4 ++--
src/xfaces.c | 7 +++++++
6 files changed, 71 insertions(+), 32 deletions(-)
diff --git a/etc/NEWS b/etc/NEWS
index f9fe72e..c1b8adc 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -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
diff --git a/lisp/faces.el b/lisp/faces.el
index 47f7f3f..58c5714 100644
--- a/lisp/faces.el
+++ b/lisp/faces.el
@@ -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'
diff --git a/src/font.c b/src/font.c
index 6cd4a6b..5e761ab 100644
--- a/src/font.c
+++ b/src/font.c
@@ -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
@@ -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")
diff --git a/src/gtkutil.c b/src/gtkutil.c
index e87845c..9a2850d 100644
--- a/src/gtkutil.c
+++ b/src/gtkutil.c
@@ -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 */
@@ -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);
diff --git a/src/w32font.c b/src/w32font.c
index 6b9ab04..885daf9 100644
--- a/src/w32font.c
+++ b/src/w32font.c
@@ -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");
diff --git a/src/xfaces.c b/src/xfaces.c
index 5e63e87..22f3722 100644
--- a/src/xfaces.c
+++ b/src/xfaces.c
@@ -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");
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- master 65fd3ca: Support the "medium" font weight,
Lars Ingebrigtsen <=