From 3ea1a6672b1cc8c7ea505585e8687500014e524b Mon Sep 17 00:00:00 2001 From: Po Lu Date: Mon, 2 May 2022 05:48:48 +0000 Subject: Default to currently selected font in Haiku font dialogs * src/haiku_font_support.cc (be_find_font_indices): New function. * src/haiku_support.cc (class EmacsFontSelectionDialog) (UpdateStylesForIndex, EmacsFontSelectionDialog): Allow specifying an initial font family and style. (be_select_font): New parameters `initial_family' and `initial_style'. * src/haiku_support.h: Update prototypes. * src/haikufont.c (haikufont_lisp_to_weight) (haikufont_lisp_to_slant, haikufont_lisp_to_width): Handle `regular'. (haikufont_pattern_from_object): New function. (haikufont_spec_or_entity_to_pattern): Fix coding style. (Fx_select_font): Compute indices based on currently selected font. (syms_of_haikufont): New defsyms. --- src/haiku_font_support.cc | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'src/haiku_font_support.cc') diff --git a/src/haiku_font_support.cc b/src/haiku_font_support.cc index 95a0db8ae68..de55ad2001a 100644 --- a/src/haiku_font_support.cc +++ b/src/haiku_font_support.cc @@ -815,3 +815,38 @@ be_font_style_to_flags (char *style, struct haiku_font_pattern *pattern) font_style_to_flags (style, pattern); } + +int +be_find_font_indices (struct haiku_font_pattern *pattern, + int *family_index, int *style_index) +{ + int32 i, j, n_families, n_styles; + font_family family; + font_style style; + uint32 flags; + + n_families = count_font_families (); + + for (i = 0; i < n_families; ++i) + { + if (get_font_family (i, &family, &flags) == B_OK) + { + n_styles = count_font_styles (family); + + for (j = 0; j < n_styles; ++j) + { + if (get_font_style (family, j, &style, &flags) == B_OK + && font_family_style_matches_p (family, style, + flags, pattern)) + { + *family_index = i; + *style_index = j; + + return 0; + } + } + } + } + + return 1; +} -- cgit v1.2.3