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<String>` as the return type so I am
prioritizing the `English US` font family unless advised otherwise by
the reviewer.

---------

Signed-off-by: Maharshi Basu <basumaharshi10@gmail.com>
Co-authored-by: Mikayla Maki <mikayla@zed.dev>
This commit is contained in:
Maharshi Basu 2024-03-04 00:58:53 +05:30 committed by GitHub
parent 6a6dbe3aa1
commit a5eab29662
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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<String> {
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<FontId> {