emacs-diffs
[Top][All Lists]
Advanced

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

master f96eee4e06: Implement `list_family' for the haikufont driver


From: Po Lu
Subject: master f96eee4e06: Implement `list_family' for the haikufont driver
Date: Tue, 8 Feb 2022 22:54:19 -0500 (EST)

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

    Implement `list_family' for the haikufont driver
    
    * src/haiku_font_support.cc (be_list_font_families): New
    function.
    * src/haiku_support.h: Update prototypes.
    * src/haikufont.c (haikufont_list_family): New function.
    (haikufont_driver): Add `haikufont_list_family'.
---
 src/haiku_font_support.cc | 24 ++++++++++++++++++++++++
 src/haiku_support.h       |  3 +++
 src/haikufont.c           | 33 ++++++++++++++++++++++++++++++++-
 3 files changed, 59 insertions(+), 1 deletion(-)

diff --git a/src/haiku_font_support.cc b/src/haiku_font_support.cc
index e6d21c28fe..b92373b59e 100644
--- a/src/haiku_font_support.cc
+++ b/src/haiku_font_support.cc
@@ -615,3 +615,27 @@ BFont_string_width (void *font, const char *utf8)
 {
   return ((BFont *) font)->StringWidth (utf8);
 }
+
+haiku_font_family_or_style *
+be_list_font_families (size_t *length)
+{
+  int32 families = count_font_families ();
+  haiku_font_family_or_style *array;
+  int32 idx;
+  uint32 flags;
+
+  array = (haiku_font_family_or_style *) malloc (sizeof *array * families);
+
+  if (!array)
+    return NULL;
+
+  for (idx = 0; idx < families; ++idx)
+    {
+      if (get_font_family (idx, &array[idx], &flags) != B_OK)
+       array[idx][0] = '\0';
+    }
+
+  *length = families;
+
+  return array;
+}
diff --git a/src/haiku_support.h b/src/haiku_support.h
index ea34ccb435..369a4b6bb4 100644
--- a/src/haiku_support.h
+++ b/src/haiku_support.h
@@ -883,6 +883,9 @@ extern "C"
   extern void
   EmacsWindow_signal_menu_update_complete (void *window);
 
+  extern haiku_font_family_or_style *
+  be_list_font_families (size_t *length);
+
 #ifdef __cplusplus
   extern void *
   find_appropriate_view_for_draw (void *vw);
diff --git a/src/haikufont.c b/src/haikufont.c
index 6cc984f316..ebff619287 100644
--- a/src/haikufont.c
+++ b/src/haikufont.c
@@ -29,6 +29,7 @@ along with GNU Emacs.  If not, see 
<https://www.gnu.org/licenses/>.  */
 #include "fontset.h"
 #include "haikuterm.h"
 #include "character.h"
+#include "coding.h"
 #include "font.h"
 #include "termchar.h"
 #include "pdumper.h"
@@ -1023,6 +1024,35 @@ haikufont_draw (struct glyph_string *s, int from, int to,
   return 1;
 }
 
+static Lisp_Object
+haikufont_list_family (struct frame *f)
+{
+  Lisp_Object list = Qnil;
+  size_t length;
+  ptrdiff_t idx;
+  haiku_font_family_or_style *styles;
+
+  block_input ();
+  styles = be_list_font_families (&length);
+  unblock_input ();
+
+  if (!styles)
+    return list;
+
+  block_input ();
+  for (idx = 0; idx < length; ++idx)
+    {
+      if (styles[idx][0])
+       list = Fcons (build_string_from_utf8 ((char *) &styles[idx]),
+                     list);
+    }
+
+  free (styles);
+  unblock_input ();
+
+  return list;
+}
+
 struct font_driver const haikufont_driver =
   {
     .type = LISPSYM_INITIALLY (Qhaiku),
@@ -1036,7 +1066,8 @@ struct font_driver const haikufont_driver =
     .prepare_face = haikufont_prepare_face,
     .encode_char = haikufont_encode_char,
     .text_extents = haikufont_text_extents,
-    .shape = haikufont_shape
+    .shape = haikufont_shape,
+    .list_family = haikufont_list_family
   };
 
 void



reply via email to

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