1use crate::{
2 Bounds, DevicePixels, Font, FontId, FontMetrics, FontRun, GlyphId, LineLayout, Pixels,
3 PlatformTextSystem, RenderGlyphParams, SharedString, Size,
4};
5use anyhow::Result;
6use collections::HashMap;
7use font_kit::{
8 font::Font as FontKitFont,
9 handle::Handle,
10 hinting::HintingOptions,
11 metrics::Metrics,
12 properties::{Style as FontkitStyle, Weight as FontkitWeight},
13 source::SystemSource,
14 sources::mem::MemSource,
15};
16use parking_lot::RwLock;
17use smallvec::SmallVec;
18use std::{borrow::Cow};
19
20pub(crate) struct LinuxTextSystem(RwLock<LinuxTextSystemState>);
21
22struct LinuxTextSystemState {
23 memory_source: MemSource,
24 system_source: SystemSource,
25 fonts: Vec<FontKitFont>,
26 font_selections: HashMap<Font, FontId>,
27 font_ids_by_postscript_name: HashMap<String, FontId>,
28 font_ids_by_family_name: HashMap<SharedString, SmallVec<[FontId; 4]>>,
29 postscript_names_by_font_id: HashMap<FontId, String>,
30}
31
32unsafe impl Send for LinuxTextSystemState {}
33unsafe impl Sync for LinuxTextSystemState {}
34
35impl LinuxTextSystem {
36 pub(crate) fn new() -> Self {
37 Self(RwLock::new(LinuxTextSystemState {
38 memory_source: MemSource::empty(),
39 system_source: SystemSource::new(),
40 fonts: Vec::new(),
41 font_selections: HashMap::default(),
42 font_ids_by_postscript_name: HashMap::default(),
43 font_ids_by_family_name: HashMap::default(),
44 postscript_names_by_font_id: HashMap::default(),
45 }))
46 }
47}
48
49impl Default for LinuxTextSystem {
50 fn default() -> Self {
51 Self::new()
52 }
53}
54
55#[allow(unused)]
56impl PlatformTextSystem for LinuxTextSystem {
57 fn add_fonts(&self, fonts: Vec<Cow<'static, [u8]>>) -> Result<()> {
58 Ok(()) //TODO
59 }
60 fn all_font_names(&self) -> Vec<String> {
61 Vec::new()
62 }
63 fn all_font_families(&self) -> Vec<String> {
64 Vec::new()
65 }
66 fn font_id(&self, descriptor: &Font) -> Result<FontId> {
67 Ok(FontId(0)) //TODO
68 }
69 fn font_metrics(&self, font_id: FontId) -> FontMetrics {
70 unimplemented!()
71 }
72 fn typographic_bounds(&self, font_id: FontId, glyph_id: GlyphId) -> Result<Bounds<f32>> {
73 unimplemented!()
74 }
75 fn advance(&self, font_id: FontId, glyph_id: GlyphId) -> Result<Size<f32>> {
76 unimplemented!()
77 }
78 fn glyph_for_char(&self, font_id: FontId, ch: char) -> Option<GlyphId> {
79 unimplemented!()
80 }
81 fn glyph_raster_bounds(&self, params: &RenderGlyphParams) -> Result<Bounds<DevicePixels>> {
82 unimplemented!()
83 }
84 fn rasterize_glyph(
85 &self,
86 params: &RenderGlyphParams,
87 raster_bounds: Bounds<DevicePixels>,
88 ) -> Result<(Size<DevicePixels>, Vec<u8>)> {
89 unimplemented!()
90 }
91 fn layout_line(&self, text: &str, font_size: Pixels, runs: &[FontRun]) -> LineLayout {
92 LineLayout::default() //TODO
93 }
94 fn wrap_line(
95 &self,
96 text: &str,
97 font_id: FontId,
98 font_size: Pixels,
99 width: Pixels,
100 ) -> Vec<usize> {
101 unimplemented!()
102 }
103}