mirror of
https://github.com/zed-industries/zed.git
synced 2024-11-07 20:39:04 +03:00
windows: Introduce Direct Write
(#10119)
This PR brings `Direct Write` to Zed. Now, Zed first trys to query dwrite interface, if not supported, which means runing on Windows below win10 1703), will choose `cosmic` as a fallback text system. This direct write text system supports: - Full font features support - Emoji support - Default system fonts as fallback ### Font features https://github.com/zed-industries/zed/assets/14981363/198eff88-47df-4bc8-a257-e3acf81fd61d ### Emoji ![Screenshot 2024-04-03 211354](https://github.com/zed-industries/zed/assets/14981363/a5bc5845-42e8-4af1-af7e-abba598c1e72) **Note: input emoji through IME or IMM not working yet, copy paste emoji works fine (will be fixed by #10125 )** ### Font fallback I use `Zed mono` which dose not support chinese chars to test font fallback https://github.com/zed-industries/zed/assets/14981363/c97d0847-0ac5-47e6-aa00-f3ce6d1e50a5 Release Notes: - N/A
This commit is contained in:
parent
1127b1a0de
commit
11a3d2b04b
10
Cargo.toml
10
Cargo.toml
@ -260,7 +260,9 @@ futures-batch = "0.6.1"
|
||||
futures-lite = "1.13"
|
||||
git2 = { version = "0.18", default-features = false }
|
||||
globset = "0.4"
|
||||
heed = { git = "https://github.com/meilisearch/heed", rev = "036ac23f73a021894974b9adc815bc95b3e0482a", features = ["read-txn-no-tls"] }
|
||||
heed = { git = "https://github.com/meilisearch/heed", rev = "036ac23f73a021894974b9adc815bc95b3e0482a", features = [
|
||||
"read-txn-no-tls",
|
||||
] }
|
||||
hex = "0.4.3"
|
||||
ignore = "0.4.22"
|
||||
indoc = "1"
|
||||
@ -365,10 +367,16 @@ sys-locale = "0.3.1"
|
||||
version = "0.53.0"
|
||||
features = [
|
||||
"implement",
|
||||
"Foundation_Numerics",
|
||||
"Wdk_System_SystemServices",
|
||||
"Win32_Globalization",
|
||||
"Win32_Graphics_Direct2D",
|
||||
"Win32_Graphics_Direct2D_Common",
|
||||
"Win32_Graphics_DirectWrite",
|
||||
"Win32_Graphics_Dxgi_Common",
|
||||
"Win32_Graphics_Gdi",
|
||||
"Win32_Graphics_Imaging",
|
||||
"Win32_Graphics_Imaging_D2D",
|
||||
"Win32_Media",
|
||||
"Win32_Security",
|
||||
"Win32_Security_Credentials",
|
||||
|
@ -125,8 +125,11 @@ impl Platform for TestPlatform {
|
||||
#[cfg(target_os = "macos")]
|
||||
return Arc::new(crate::platform::mac::MacTextSystem::new());
|
||||
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
#[cfg(target_os = "linux")]
|
||||
return Arc::new(crate::platform::cosmic_text::CosmicTextSystem::new());
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
return Arc::new(crate::platform::windows::DirectWriteTextSystem::new().unwrap());
|
||||
}
|
||||
|
||||
fn run(&self, _on_finish_launching: Box<dyn FnOnce()>) {
|
||||
|
@ -1,9 +1,11 @@
|
||||
mod direct_write;
|
||||
mod dispatcher;
|
||||
mod display;
|
||||
mod platform;
|
||||
mod util;
|
||||
mod window;
|
||||
|
||||
pub(crate) use direct_write::*;
|
||||
pub(crate) use dispatcher::*;
|
||||
pub(crate) use display::*;
|
||||
pub(crate) use platform::*;
|
||||
|
1277
crates/gpui/src/platform/windows/direct_write.rs
Normal file
1277
crates/gpui/src/platform/windows/direct_write.rs
Normal file
File diff suppressed because it is too large
Load Diff
@ -57,7 +57,7 @@ pub(crate) struct WindowsPlatformInner {
|
||||
background_executor: BackgroundExecutor,
|
||||
pub(crate) foreground_executor: ForegroundExecutor,
|
||||
main_receiver: flume::Receiver<Runnable>,
|
||||
text_system: Arc<CosmicTextSystem>,
|
||||
text_system: Arc<dyn PlatformTextSystem>,
|
||||
callbacks: Mutex<Callbacks>,
|
||||
pub raw_window_handles: RwLock<SmallVec<[HWND; 4]>>,
|
||||
pub(crate) dispatch_event: OwnedHandle,
|
||||
@ -155,7 +155,13 @@ impl WindowsPlatform {
|
||||
let dispatcher = Arc::new(WindowsDispatcher::new(main_sender, dispatch_event.to_raw()));
|
||||
let background_executor = BackgroundExecutor::new(dispatcher.clone());
|
||||
let foreground_executor = ForegroundExecutor::new(dispatcher);
|
||||
let text_system = Arc::new(CosmicTextSystem::new());
|
||||
let text_system = if let Some(direct_write) = DirectWriteTextSystem::new().log_err() {
|
||||
log::info!("Using direct write text system.");
|
||||
Arc::new(direct_write) as Arc<dyn PlatformTextSystem>
|
||||
} else {
|
||||
log::info!("Using cosmic text system.");
|
||||
Arc::new(CosmicTextSystem::new()) as Arc<dyn PlatformTextSystem>
|
||||
};
|
||||
let callbacks = Mutex::new(Callbacks::default());
|
||||
let raw_window_handles = RwLock::new(SmallVec::new());
|
||||
let settings = RefCell::new(WindowsPlatformSystemSettings::new());
|
||||
|
@ -26,6 +26,29 @@ macro_rules! create_definitions {
|
||||
}
|
||||
}
|
||||
)*
|
||||
|
||||
/// Get the tag name list of the font OpenType features
|
||||
/// only enabled or disabled features are returned
|
||||
#[cfg(target_os = "windows")]
|
||||
pub fn tag_value_list(&self) -> Vec<(String, bool)> {
|
||||
let mut result = Vec::new();
|
||||
$(
|
||||
{
|
||||
let value = if (self.enabled & (1 << $idx)) != 0 {
|
||||
Some(true)
|
||||
} else if (self.disabled & (1 << $idx)) != 0 {
|
||||
Some(false)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
if let Some(enable) = value {
|
||||
let tag_name = stringify!($name).to_owned();
|
||||
result.push((tag_name, enable));
|
||||
}
|
||||
}
|
||||
)*
|
||||
result
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for FontFeatures {
|
||||
@ -94,10 +117,12 @@ macro_rules! create_definitions {
|
||||
let mut map = serializer.serialize_map(None)?;
|
||||
|
||||
$(
|
||||
{
|
||||
let feature = stringify!($name);
|
||||
if let Some(value) = self.$name() {
|
||||
map.serialize_entry(feature, &value)?;
|
||||
}
|
||||
}
|
||||
)*
|
||||
|
||||
map.end()
|
||||
@ -161,5 +186,5 @@ create_definitions!(
|
||||
(swsh, 30),
|
||||
(titl, 31),
|
||||
(tnum, 32),
|
||||
(zero, 33)
|
||||
(zero, 33),
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user