emacs-diffs
[Top][All Lists]
Advanced

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

master 9596e68383: Improve Haiku font size fallback


From: Po Lu
Subject: master 9596e68383: Improve Haiku font size fallback
Date: Sun, 1 Jan 2023 06:03:38 -0500 (EST)

branch: master
commit 9596e683834a36060497903b47b870b338d88095
Author: Po Lu <luangruo@yahoo.com>
Commit: Po Lu <luangruo@yahoo.com>

    Improve Haiku font size fallback
    
    * src/haikufont.c (haikufont_open): If pixel_size is zero, don't
    use a font parameter that doesn't exist.
---
 src/haikufont.c | 25 +++++++++++++++++--------
 1 file changed, 17 insertions(+), 8 deletions(-)

diff --git a/src/haikufont.c b/src/haikufont.c
index 4599ca40c4..a025dec58b 100644
--- a/src/haikufont.c
+++ b/src/haikufont.c
@@ -754,7 +754,7 @@ haikufont_encode_char (struct font *font, int c)
 }
 
 static Lisp_Object
-haikufont_open (struct frame *f, Lisp_Object font_entity, int x)
+haikufont_open (struct frame *f, Lisp_Object font_entity, int pixel_size)
 {
   struct haikufont_info *font_info;
   struct haiku_font_pattern ptn;
@@ -765,11 +765,19 @@ haikufont_open (struct frame *f, Lisp_Object font_entity, 
int x)
   int avg_width, height, space_width, ascent;
   int descent, underline_pos, underline_thickness;
 
-  if (x <= 0)
+  if (XFIXNUM (AREF (font_entity, FONT_SIZE_INDEX)) != 0)
+    pixel_size = XFIXNUM (AREF (font_entity, FONT_SIZE_INDEX));
+  else if (pixel_size == 0)
     {
-      /* Get pixel size from frame instead.  */
-      tem = get_frame_param (f, Qfontsize);
-      x = NILP (tem) ? 0 : XFIXNAT (tem);
+      /* Try to resolve a suitable size for the font, if the font size
+        has not already been specified.  First, if FRAME_FONT is set,
+        use its size.  Otherwise, use 12, which is the default on
+        Haiku.  */
+
+      if (FRAME_FONT (f))
+       pixel_size = FRAME_FONT (f)->pixel_size;
+      else
+       pixel_size = 12;
     }
 
   extra = AREF (font_entity, FONT_EXTRA_INDEX);
@@ -788,7 +796,8 @@ haikufont_open (struct frame *f, Lisp_Object font_entity, 
int x)
     {
       block_input ();
       be_font = be_open_font_at_index (XFIXNUM (XCAR (indices)),
-                                      XFIXNUM (XCDR (indices)), x);
+                                      XFIXNUM (XCDR (indices)),
+                                      pixel_size);
       unblock_input ();
 
       if (!be_font)
@@ -799,7 +808,7 @@ haikufont_open (struct frame *f, Lisp_Object font_entity, 
int x)
       block_input ();
       haikufont_spec_or_entity_to_pattern (font_entity, 1, &ptn);
 
-      if (BFont_open_pattern (&ptn, &be_font, x))
+      if (BFont_open_pattern (&ptn, &be_font, pixel_size))
        {
          haikufont_done_with_query_pattern (&ptn);
          unblock_input ();
@@ -813,7 +822,7 @@ haikufont_open (struct frame *f, Lisp_Object font_entity, 
int x)
   block_input ();
 
   font_object = font_make_object (VECSIZE (struct haikufont_info),
-                                 font_entity, x);
+                                 font_entity, pixel_size);
 
   ASET (font_object, FONT_TYPE_INDEX, Qhaiku);
   font_info = (struct haikufont_info *) XFONT_OBJECT (font_object);



reply via email to

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