emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master ea60b54: Allow font names that end in "-NN", where


From: Eli Zaretskii
Subject: [Emacs-diffs] master ea60b54: Allow font names that end in "-NN", where NN is a number
Date: Mon, 29 Jun 2015 16:11:18 +0000

branch: master
commit ea60b543f6829061b751a0a1c60309bcfe2ff7a7
Author: Eli Zaretskii <address@hidden>
Commit: Eli Zaretskii <address@hidden>

    Allow font names that end in "-NN", where NN is a number
    
    * src/font.c (font_load_for_lface): If the font-spec didn't match
    any available fonts, try again without interpreting trailing "-NN"
    as the font size.  For the description of the original problem, see
    http://lists.gnu.org/archive/html/help-emacs-windows/2015-06/msg00001.html
---
 src/font.c |   32 ++++++++++++++++++++++++++++++++
 1 files changed, 32 insertions(+), 0 deletions(-)

diff --git a/src/font.c b/src/font.c
index 564c53a..575975c 100644
--- a/src/font.c
+++ b/src/font.c
@@ -3337,6 +3337,38 @@ font_load_for_lface (struct frame *f, Lisp_Object 
*attrs, Lisp_Object spec)
       /* No font is listed for SPEC, but each font-backend may have
         different criteria about "font matching".  So, try it.  */
       entity = font_matching_entity (f, attrs, spec);
+      /* Perhaps the user asked for a font "Foobar-123", and we
+        interpreted "-123" as the size, whereas it really is part of
+        the name.  So we reset the size to nil and the family name to
+        the entire "Foobar-123" thing, and try again with that.  */
+      if (NILP (entity))
+       {
+         name = Ffont_get (spec, QCuser_spec);
+         if (STRINGP (name))
+           {
+             char *p = SDATA (name), *q = strrchr (p, '-');
+
+             if (q != NULL && c_isdigit (q[1]))
+               {
+                 char *tail;
+                 double font_size = strtod (q + 1, &tail);
+
+                 if (font_size > 0 && tail != q + 1)
+                   {
+                     Lisp_Object lsize = Ffont_get (spec, QCsize);
+
+                     if ((FLOATP (lsize) && XFLOAT_DATA (lsize) == font_size)
+                         || (INTEGERP (lsize) && XINT (lsize) == font_size))
+                       {
+                         ASET (spec, FONT_FAMILY_INDEX,
+                               font_intern_prop (p, tail - p, 1));
+                         ASET (spec, FONT_SIZE_INDEX, Qnil);
+                         entity = font_matching_entity (f, attrs, spec);
+                       }
+                   }
+               }
+           }
+       }
       if (NILP (entity))
        return Qnil;
     }



reply via email to

[Prev in Thread] Current Thread [Next in Thread]