From f96eee4e06001cbeb1f6b0caa0b138015858ce33 Mon Sep 17 00:00:00 2001 From: Po Lu Date: Wed, 9 Feb 2022 03:53:13 +0000 Subject: [PATCH] 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 e6d21c28fe5..b92373b59eb 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 ea34ccb435c..369a4b6bb45 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 6cc984f3165..ebff619287d 100644 --- a/src/haikufont.c +++ b/src/haikufont.c @@ -29,6 +29,7 @@ along with GNU Emacs. If not, see . */ #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 -- 2.39.5