33
44pub use parley;
55
6+ use std:: boxed:: Box ;
67use std:: cell:: RefCell ;
78
89use crate :: {
@@ -15,15 +16,25 @@ use i_slint_common::sharedfontique;
1516
1617pub const DEFAULT_FONT_SIZE : LogicalLength = LogicalLength :: new ( 12. ) ;
1718
18- fn font_context ( ) -> parley:: FontContext {
19- parley:: FontContext {
20- collection : sharedfontique:: COLLECTION . inner . clone ( ) ,
21- source_cache : sharedfontique:: COLLECTION . source_cache . clone ( ) ,
19+ struct Contexts {
20+ layout : parley:: LayoutContext < Brush > ,
21+ font : parley:: FontContext ,
22+ }
23+
24+ impl Default for Contexts {
25+ fn default ( ) -> Self {
26+ Self {
27+ font : parley:: FontContext {
28+ collection : sharedfontique:: COLLECTION . inner . clone ( ) ,
29+ source_cache : sharedfontique:: COLLECTION . source_cache . clone ( ) ,
30+ } ,
31+ layout : Default :: default ( ) ,
32+ }
2233 }
2334}
2435
2536std:: thread_local! {
26- static LAYOUT_CONTEXT : RefCell <parley :: LayoutContext < Brush >> = Default :: default ( ) ;
37+ static CONTEXTS : RefCell <Box < Contexts >> = Default :: default ( ) ;
2738}
2839
2940#[ derive( Debug , Default , PartialEq , Clone , Copy ) ]
@@ -65,10 +76,9 @@ pub fn layout(text: &str, scale_factor: ScaleFactor, options: LayoutOptions) ->
6576 . and_then ( |font_request| font_request. pixel_size )
6677 . unwrap_or ( DEFAULT_FONT_SIZE ) ;
6778
68- let mut layout = LAYOUT_CONTEXT . with_borrow_mut ( move |layout_context| {
69- let mut font_context = font_context ( ) ;
79+ let mut layout = CONTEXTS . with_borrow_mut ( move |contexts| {
7080 let mut builder =
71- layout_context . ranged_builder ( & mut font_context , text, scale_factor. get ( ) , true ) ;
81+ contexts . layout . ranged_builder ( & mut contexts . font , text, scale_factor. get ( ) , true ) ;
7282 if let Some ( ref font_request) = options. font_request {
7383 if let Some ( family) = & font_request. family {
7484 builder. push_default ( parley:: StyleProperty :: FontStack (
0 commit comments