@@ -17,7 +17,7 @@ use cosmic_text::{Attrs, Buffer, Metrics, Shaping, Wrap};
17
17
18
18
use crate :: {
19
19
error:: TextError , ComputedTextBlock , Font , FontAtlasSets , FontSmoothing , Justify , LineBreak ,
20
- PositionedGlyph , TextBounds , TextEntity , TextFont , TextLayout ,
20
+ PositionedGlyph , TextBounds , TextEntity , TextFont , TextLayout , TextPlugin ,
21
21
} ;
22
22
23
23
/// A wrapper resource around a [`cosmic_text::FontSystem`]
@@ -30,20 +30,39 @@ pub struct CosmicFontSystem(pub cosmic_text::FontSystem);
30
30
31
31
impl Default for CosmicFontSystem {
32
32
fn default ( ) -> Self {
33
- Self :: new ( true )
33
+ Self :: new_with_settings ( & TextPlugin :: default ( ) )
34
34
}
35
35
}
36
36
37
37
impl CosmicFontSystem {
38
38
/// Creates a new, wrapped [`cosmic_text::FontSystem`].
39
39
///
40
- /// The option to load system fonts is typically provided via [`TextPlugin`](super::TextPlugin) .
41
- pub fn new ( load_system_fonts : bool ) -> Self {
40
+ /// The option to load system fonts is typically provided via the values in [`TextPlugin`].
41
+ pub fn new_with_settings ( plugin_settings : & TextPlugin ) -> Self {
42
42
let locale = sys_locale:: get_locale ( ) . unwrap_or_else ( || String :: from ( "en-US" ) ) ;
43
43
let mut db = cosmic_text:: fontdb:: Database :: new ( ) ;
44
- if load_system_fonts {
44
+ if plugin_settings . load_system_fonts {
45
45
db. load_system_fonts ( ) ;
46
46
}
47
+ if let Some ( family_serif) = & plugin_settings. family_serif {
48
+ db. set_serif_family ( family_serif. to_string ( ) ) ;
49
+ }
50
+
51
+ if let Some ( family_sans_serif) = & plugin_settings. family_sans_serif {
52
+ db. set_serif_family ( family_sans_serif. to_string ( ) ) ;
53
+ }
54
+
55
+ if let Some ( family_cursive) = & plugin_settings. family_cursive {
56
+ db. set_serif_family ( family_cursive. to_string ( ) ) ;
57
+ }
58
+
59
+ if let Some ( family_fantasy) = & plugin_settings. family_fantasy {
60
+ db. set_serif_family ( family_fantasy. to_string ( ) ) ;
61
+ }
62
+
63
+ if let Some ( family_monospace) = & plugin_settings. family_monospace {
64
+ db. set_serif_family ( family_monospace. to_string ( ) ) ;
65
+ }
47
66
48
67
Self ( cosmic_text:: FontSystem :: new_with_locale_and_db ( locale, db) )
49
68
}
0 commit comments