Implement `list_family' for the haikufont driver
authorPo Lu <luangruo@yahoo.com>
Wed, 9 Feb 2022 03:53:13 +0000 (03:53 +0000)
committerPo Lu <luangruo@yahoo.com>
Wed, 9 Feb 2022 03:53:13 +0000 (03:53 +0000)
* 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
src/haiku_support.h
src/haikufont.c

index e6d21c28fe585838d46284f0a0dde7f13b48e2e2..b92373b59ebf53ec06381671b07e1a18eec635bb 100644 (file)
@@ -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;
+}
index ea34ccb435c15700add647776bd3c26462fa155f..369a4b6bb45f2891c641b9fd231fb73dbbff6555 100644 (file)
@@ -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);
index 6cc984f31656c2dc4369b42c2a2850051dd1dc04..ebff619287df56a2e7faecb7b3542915b3f7c444 100644 (file)
@@ -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