From a5eab29662e82458115841b10d1e7c7322644ba7 Mon Sep 17 00:00:00 2001 From: Maharshi Basu <84385565+MashyBasker@users.noreply.github.com> Date: Mon, 4 Mar 2024 00:58:53 +0530 Subject: [PATCH] Implement `all_font_families` for the LinuxTextSystem (#8331) Implemented the function to get all font family names for `LinuxTextSystem` which was previously kept as `unimplemented`. Release Notes: - N/A Change Explanation: - We get the [`&Database`](https://docs.rs/fontdb/0.16.1/fontdb/struct.Database.html) struct from the [`FontSystem`](https://docs.rs/cosmic-text/latest/cosmic_text/struct.FontSystem.html) by using the `.db` method. - From the `Database` struct we get the [`FaceInfo`](https://docs.rs/fontdb/0.16.1/fontdb/struct.FaceInfo.html) which the provides a method to get the family names([`families`](https://docs.rs/fontdb/0.16.1/fontdb/struct.FaceInfo.html#structfield.families)) - The `families` function returns a tuple of Vec. The tuple consists of the `String` containing the name and the [`Language`](https://docs.rs/fontdb/0.16.1/fontdb/enum.Language.html) struct. *It is noted that for the `families` function, the first family is always `English US` unless it is unavailable* Since the empty function provided [here](https://github.com/zed-industries/zed/blob/main/crates/gpui/src/platform/linux/text_system.rs#L75) explicitly declares a `Vec` as the return type so I am prioritizing the `English US` font family unless advised otherwise by the reviewer. --------- Signed-off-by: Maharshi Basu Co-authored-by: Mikayla Maki --- crates/gpui/src/platform/linux/text_system.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/crates/gpui/src/platform/linux/text_system.rs b/crates/gpui/src/platform/linux/text_system.rs index 8fd1be323b03ec776ce072dcc5d52acfb3c84c94..70caa7175b09fd58b5ace93a96f72b66faee8ff3 100644 --- a/crates/gpui/src/platform/linux/text_system.rs +++ b/crates/gpui/src/platform/linux/text_system.rs @@ -9,6 +9,8 @@ use cosmic_text::{ fontdb::Query, Attrs, AttrsList, BufferLine, CacheKey, Family, Font as CosmicTextFont, FontSystem, SwashCache, }; + +use itertools::Itertools; use parking_lot::{RwLock, RwLockUpgradableReadGuard}; use pathfinder_geometry::{ rect::{RectF, RectI}, @@ -71,9 +73,14 @@ impl PlatformTextSystem for LinuxTextSystem { .collect() } - // todo(linux) fn all_font_families(&self) -> Vec { - Vec::new() + self.0 + .read() + .font_system + .db() + .faces() + .filter_map(|face| Some(face.families.get(0)?.0.clone())) + .collect_vec() } fn font_id(&self, font: &Font) -> Result {