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
32// todo!(linux): Double check this
33unsafe impl Send for LinuxTextSystemState {}
34unsafe impl Sync for LinuxTextSystemState {}
35
36impl LinuxTextSystem {
37 pub(crate) fn new() -> Self {
38 Self(RwLock::new(LinuxTextSystemState {
39 memory_source: MemSource::empty(),
40 system_source: SystemSource::new(),
41 fonts: Vec::new(),
42 font_selections: HashMap::default(),
43 font_ids_by_postscript_name: HashMap::default(),
44 font_ids_by_family_name: HashMap::default(),
45 postscript_names_by_font_id: HashMap::default(),
46 }))
47 }
48}
49
50impl Default for LinuxTextSystem {
51 fn default() -> Self {
52 Self::new()
53 }
54}
55
56#[allow(unused)]
57impl PlatformTextSystem for LinuxTextSystem {
58 // todo!(linux)
59 fn add_fonts(&self, fonts: Vec<Cow<'static, [u8]>>) -> Result<()> {
60 Ok(())
61 }
62
63 // todo!(linux)
64 fn all_font_names(&self) -> Vec<String> {
65 Vec::new()
66 }
67
68 // todo!(linux)
69 fn all_font_families(&self) -> Vec<String> {
70 Vec::new()
71 }
72
73 // todo!(linux)
74 fn font_id(&self, descriptor: &Font) -> Result<FontId> {
75 Ok(FontId(0))
76 }
77
78 // todo!(linux)
79 fn font_metrics(&self, font_id: FontId) -> FontMetrics {
80 unimplemented!()
81 }
82
83 // todo!(linux)
84 fn typographic_bounds(&self, font_id: FontId, glyph_id: GlyphId) -> Result<Bounds<f32>> {
85 unimplemented!()
86 }
87
88 // todo!(linux)
89 fn advance(&self, font_id: FontId, glyph_id: GlyphId) -> Result<Size<f32>> {
90 unimplemented!()
91 }
92
93 // todo!(linux)
94 fn glyph_for_char(&self, font_id: FontId, ch: char) -> Option<GlyphId> {
95 None
96 }
97
98 // todo!(linux)
99 fn glyph_raster_bounds(&self, params: &RenderGlyphParams) -> Result<Bounds<DevicePixels>> {
100 unimplemented!()
101 }
102
103 // todo!(linux)
104 fn rasterize_glyph(
105 &self,
106 params: &RenderGlyphParams,
107 raster_bounds: Bounds<DevicePixels>,
108 ) -> Result<(Size<DevicePixels>, Vec<u8>)> {
109 unimplemented!()
110 }
111
112 // todo!(linux)
113 fn layout_line(&self, text: &str, font_size: Pixels, runs: &[FontRun]) -> LineLayout {
114 LineLayout::default() //TODO
115 }
116
117 // todo!(linux)
118 fn wrap_line(
119 &self,
120 text: &str,
121 font_id: FontId,
122 font_size: Pixels,
123 width: Pixels,
124 ) -> Vec<usize> {
125 unimplemented!()
126 }
127}