diff --git a/druid-shell/Cargo.toml b/druid-shell/Cargo.toml index 29c052c7da..14a89045a1 100755 --- a/druid-shell/Cargo.toml +++ b/druid-shell/Cargo.toml @@ -40,7 +40,7 @@ hdr = ["piet-common/hdr"] [dependencies] # NOTE: When changing the piet or kurbo versions, ensure that # the kurbo version included in piet is compatible with the kurbo version specified here. -piet-common = "=0.4.0" +piet-common = "=0.4.1" kurbo = "0.8.1" tracing = "0.1.22" @@ -99,7 +99,7 @@ version = "0.3.44" features = ["Window", "MouseEvent", "CssStyleDeclaration", "WheelEvent", "KeyEvent", "KeyboardEvent"] [dev-dependencies] -piet-common = { version = "=0.4.0", features = ["png"] } +piet-common = { version = "=0.4.1", features = ["png"] } static_assertions = "1.1.0" test-env-log = { version = "0.2.5", features = ["trace"], default-features = false } tracing-subscriber = "0.2.15" diff --git a/druid-shell/src/platform/windows/application.rs b/druid-shell/src/platform/windows/application.rs index 8bca0e8cbb..4e657714c3 100644 --- a/druid-shell/src/platform/windows/application.rs +++ b/druid-shell/src/platform/windows/application.rs @@ -32,6 +32,8 @@ use winapi::um::winuser::{ IDI_APPLICATION, MSG, PM_NOREMOVE, WM_TIMER, WNDCLASSW, }; +use piet_common::D2DLoadedFonts; + use crate::application::AppHandler; use super::accels; @@ -43,6 +45,7 @@ use super::window::{self, DS_REQUEST_DESTROY}; #[derive(Clone)] pub(crate) struct Application { state: Rc>, + pub(crate) fonts: D2DLoadedFonts, } struct State { @@ -57,7 +60,8 @@ impl Application { quitting: false, windows: HashSet::new(), })); - Ok(Application { state }) + let fonts = D2DLoadedFonts::default(); + Ok(Application { state, fonts }) } /// Initialize the app. At the moment, this is mostly needed for hi-dpi. diff --git a/druid-shell/src/platform/windows/window.rs b/druid-shell/src/platform/windows/window.rs index ca2a470f5a..23ab6f25f2 100644 --- a/druid-shell/src/platform/windows/window.rs +++ b/druid-shell/src/platform/windows/window.rs @@ -167,7 +167,7 @@ enum DeferredOp { #[derive(Clone)] pub struct WindowHandle { - dwrite_factory: DwriteFactory, + text: PietText, state: Weak, } @@ -243,7 +243,7 @@ struct MyWndProc { app: Application, handle: RefCell, d2d_factory: D2DFactory, - dwrite_factory: DwriteFactory, + text: PietText, state: RefCell>, present_strategy: PresentStrategy, } @@ -419,7 +419,7 @@ impl WndState { } // Renders but does not present. - fn render(&mut self, d2d: &D2DFactory, dw: &DwriteFactory, invalid: &Region) { + fn render(&mut self, d2d: &D2DFactory, text: &PietText, invalid: &Region) { let rt = self.render_target.as_mut().unwrap(); rt.begin_draw(); @@ -434,8 +434,8 @@ impl WndState { .unwrap() }); - let text = PietText::new(dw.clone()); - let mut piet_ctx = Piet::new(d2d, text, rt); + //let text = PietText::new(dw.clone()); + let mut piet_ctx = Piet::new(d2d, text.clone(), rt); // Clear the background if transparency DC is found if let Some(dc) = dc_for_transparency { @@ -815,7 +815,7 @@ impl WndProc for MyWndProc { let invalid = self.take_invalid(); if !invalid.rects().is_empty() { s.handler.rebuild_resources(); - s.render(&self.d2d_factory, &self.dwrite_factory, &invalid); + s.render(&self.d2d_factory, &self.text, &invalid); if let Some(ref mut ds) = s.dxgi_state { let mut dirty_rects = util::region_to_rectis(&invalid, self.scale()); let params = DXGI_PRESENT_PARAMETERS { @@ -950,11 +950,7 @@ impl WndProc for MyWndProc { if let Err(e) = s.rebuild_render_target(&self.d2d_factory, scale) { error!("error building render target: {}", e); } - s.render( - &self.d2d_factory, - &self.dwrite_factory, - &size_dp.to_rect().into(), - ); + s.render(&self.d2d_factory, &self.text, &size_dp.to_rect().into()); let present_after = match self.present_strategy { PresentStrategy::Sequential => 1, _ => 0, @@ -1330,12 +1326,13 @@ impl WindowBuilder { unsafe { let class_name = super::util::CLASS_NAME.to_wide(); let dwrite_factory = DwriteFactory::new().unwrap(); - let dw_clone = dwrite_factory.clone(); + let fonts = self.app.fonts.clone(); + let text = PietText::new_with_shared_fonts(dwrite_factory, Some(fonts)); let wndproc = MyWndProc { app: self.app.clone(), handle: Default::default(), d2d_factory: D2DFactory::new().unwrap(), - dwrite_factory: dw_clone, + text: text.clone(), state: RefCell::new(None), present_strategy: self.present_strategy, }; @@ -1382,7 +1379,7 @@ impl WindowBuilder { }; let win = Rc::new(window); let handle = WindowHandle { - dwrite_factory, + text, state: Rc::downgrade(&win), }; @@ -1962,7 +1959,7 @@ impl WindowHandle { } pub fn text(&self) -> PietText { - PietText::new(self.dwrite_factory.clone()) + self.text.clone() } pub fn add_text_field(&self) -> TextFieldToken { @@ -2176,7 +2173,7 @@ impl Default for WindowHandle { fn default() -> Self { WindowHandle { state: Default::default(), - dwrite_factory: DwriteFactory::new().unwrap(), + text: PietText::new_with_shared_fonts(DwriteFactory::new().unwrap(), None), } } } diff --git a/druid/Cargo.toml b/druid/Cargo.toml index 19496ba4c7..fe6425f126 100644 --- a/druid/Cargo.toml +++ b/druid/Cargo.toml @@ -78,7 +78,7 @@ console_error_panic_hook = { version = "0.1.6" } float-cmp = { version = "0.8.0", features = ["std"], default-features = false } # tempfile 3.2.0 broke wasm; I assume it will be yanked (Jan 12, 2021) tempfile = "=3.1.0" -piet-common = { version = "=0.4.0", features = ["png"] } +piet-common = { version = "=0.4.1", features = ["png"] } pulldown-cmark = { version = "0.8", default-features = false } test-env-log = { version = "0.2.5", features = ["trace"], default-features = false }