The truly free, open-source, local-first, cross-platform CapCut replacement. Scriptable through a JSON-RPC API & MCP.
Rust ffmpegfree-video-editormodel-context-protocolnon-linear-editoroffline-firstopen-source-video-editorself-hostedvideo-editingvideo-editing-automationvideo-editing-softwarevideo-editing-toolsvideo-editorvoice-cloningyoutube-automationyoutube-shorts
fix(windows): the window's text is drawn with ClearType when the desk has it on
Jareerbdcaedff5bcf
diff --git a/src/patches/README.md b/src/patches/README.mdindex a370868d..9722722b 100644--- a/src/patches/README.md+++ b/src/patches/README.md@@ -7,9 +7,25 @@ the change, and read it again.## i-slint-renderer-skia 1.18.1-`itemrenderer.rs`, `draw_glyph_run`: glyphs are positioned on whole-pixels when the window's scale factor is under 1.5. Slint always asks-Skia for subpixel positioning, which on a 1x Windows screen lands stems-between pixels and the text reads blurred (jub0t/concat#278). On a-high-density screen the subpixel positions stay, where they are worth-their spacing. Nothing else differs from the published crate.+Text on a 1x Windows screen read soft and grey (jub0t/concat#278). Three+changes, all marked `Concat:` in the source:++- `itemrenderer.rs`, `draw_glyph_run`: glyphs are positioned on whole+ pixels when the window's scale factor is under 1.5. Slint always asks+ Skia for subpixel positioning, which on a 1x screen lands stems between+ pixels and the text reads blurred. On a high-density screen the subpixel+ positions stay, where they are worth their spacing. The edging is LCD+ where the canvas's top layer names a subpixel order and greyscale+ everywhere else. Not LCD everywhere: on a surface with no order Skia+ derives greyscale from LCD rendering, which on macOS turns on CoreText's+ font smoothing and draws text heavier.+- `wgpu_30_surface/dx12.rs`, `system_text_props`, and its caller+ `make_swapchain_surface`: the Windows window's surface carries the+ desk's ClearType settings (on or off, RGB or BGR), so its text is drawn+ with ClearType as the system's own is. A texture rendered to stays+ greyscale.+- `itemrenderer.rs`, `create_layer_target`: a layer's surface is created with+ default props, so text in a transparent, cached layer is greyscale+ rather than inheriting the window's subpixel order.++Nothing else differs from the published crate.diff --git a/src/patches/i-slint-renderer-skia/itemrenderer.rs b/src/patches/i-slint-renderer-skia/itemrenderer.rsindex 9b6a398c..544bfe15 100644--- a/src/patches/i-slint-renderer-skia/itemrenderer.rs+++ b/src/patches/i-slint-renderer-skia/itemrenderer.rs@@ -996,7 +996,10 @@ impl<'a> LayerRenderer<'a> for SkiaItemRenderer<'a> {skia_safe::ColorType::RGBA8888,skia_safe::AlphaType::Premul,);- self.canvas.new_surface(&image_info, None)+ // Concat: a layer starts transparent and is composited later, so its+ // text is greyscale; with no props it would inherit the window's+ // subpixel order and fringe where the layer is drawn.+ self.canvas.new_surface(&image_info, Some(&skia_safe::SurfaceProps::default()))}fn render_into_layer(@@ -1106,9 +1109,21 @@ impl GlyphRenderer for SkiaItemRenderer<'_> {// smear is a fraction of a hairline and the spacing is worth more.// Hinting is left to Skia's default, which snaps stems on its own// once positions are whole.+ //+ // LCD coverage where what is drawn into names a subpixel order - the+ // Windows window with ClearType on (wgpu_30_surface/dx12.rs), outside+ // any translucent layer - and greyscale everywhere else. Asked for+ // only there: on a surface with no order Skia makes greyscale out of+ // LCD rendering, which on macOS turns on CoreText's font smoothing+ // and draws every word heavier than it does today.let dense = self.scale_factor.get() >= 1.5;font.set_subpixel(dense);- font.set_edging(skia_safe::font::Edging::AntiAlias);+ let lcd = self.canvas.top_props().pixel_geometry() != skia_safe::PixelGeometry::Unknown;+ font.set_edging(if lcd {+ skia_safe::font::Edging::SubpixelAntiAlias+ } else {+ skia_safe::font::Edging::AntiAlias+ });let (glyph_ids, glyph_positions): (Vec<_>, Vec<_>) = glyphs_it.into_iter()diff --git a/src/patches/i-slint-renderer-skia/wgpu_30_surface.rs b/src/patches/i-slint-renderer-skia/wgpu_30_surface.rsindex 07ad5521..c1b571f6 100644--- a/src/patches/i-slint-renderer-skia/wgpu_30_surface.rs+++ b/src/patches/i-slint-renderer-skia/wgpu_30_surface.rs@@ -609,7 +609,7 @@ impl Backend {#[cfg(target_vendor = "apple")]Self::Metal => unsafe { metal::make_metal_surface(gr_context, texture) },#[cfg(target_family = "windows")]- Self::Dx12 => unsafe { dx12::make_dx12_surface(gr_context, texture) },+ Self::Dx12 => unsafe { dx12::make_dx12_surface(gr_context, texture, None) },#[cfg(skia_wgpu_vulkan)]Self::Vulkan { .. } => unsafe {vulkan::make_vulkan_surface(@@ -635,8 +635,13 @@ impl Backend {match self {#[cfg(target_vendor = "apple")]Self::Metal => unsafe { metal::make_metal_surface(gr_context, texture) },+ // Concat: the window, and only the window, takes the desk's+ // ClearType settings; a texture rendered to may be composited+ // anywhere, where LCD coverage would fringe.#[cfg(target_family = "windows")]- Self::Dx12 => unsafe { dx12::make_dx12_surface(gr_context, texture) },+ Self::Dx12 => unsafe {+ dx12::make_dx12_surface(gr_context, texture, dx12::system_text_props().as_ref())+ },#[cfg(skia_wgpu_vulkan)]Self::Vulkan { .. } => unsafe {vulkan::make_vulkan_surface(diff --git a/src/patches/i-slint-renderer-skia/wgpu_30_surface/dx12.rs b/src/patches/i-slint-renderer-skia/wgpu_30_surface/dx12.rsindex c1bcc561..d9f21964 100644--- a/src/patches/i-slint-renderer-skia/wgpu_30_surface/dx12.rs+++ b/src/patches/i-slint-renderer-skia/wgpu_30_surface/dx12.rs@@ -19,6 +19,7 @@ unsafe fn wrap_dx12_texture(dxgi_format: windows::Win32::Graphics::Dxgi::Common::DXGI_FORMAT,color_type: skia_safe::ColorType,color_space: skia_safe::ColorSpace,+ surface_props: Option<&skia_safe::SurfaceProps>,) -> Option<skia_safe::Surface> {let texture_info = skia_safe::gpu::d3d::TextureResourceInfo {resource,@@ -38,16 +39,64 @@ unsafe fn wrap_dx12_texture(skia_safe::gpu::SurfaceOrigin::TopLeft,color_type,color_space,- None,+ surface_props,)}+// Concat: the window's text is drawn with ClearType, as every other program+// on a Windows desk is, when the desk has it on (jub0t/concat#278). Greyscale+// coverage on a 1x screen reads soft and grey beside the system's own text;+// LCD coverage triples the horizontal resolution a stem is drawn at.+//+// The settings are the ones the Control Panel's "Adjust ClearType text"+// writes, read per frame so turning ClearType off takes effect at once.+// SystemParametersInfoW is declared here rather than through the `windows`+// crate so the copy's dependency features stay as published.+#[link(name = "user32")]+unsafe extern "system" {+ fn SystemParametersInfoW(+ action: u32,+ param: u32,+ pv_param: *mut core::ffi::c_void,+ win_ini: u32,+ ) -> i32;+}++/// The surface properties for the window's swapchain: the subpixel order of+/// the screen when ClearType is on, so Skia draws LCD text, and `None`, its+/// greyscale default, when font smoothing is off or not ClearType.+pub fn system_text_props() -> Option<skia_safe::SurfaceProps> {+ const SPI_GETFONTSMOOTHING: u32 = 0x004A;+ const SPI_GETFONTSMOOTHINGTYPE: u32 = 0x200A;+ const SPI_GETFONTSMOOTHINGORIENTATION: u32 = 0x2012;+ const FE_FONTSMOOTHINGCLEARTYPE: u32 = 0x0002;+ const FE_FONTSMOOTHINGORIENTATIONBGR: u32 = 0x0000;++ let get = |action: u32| -> Option<u32> {+ let mut value: u32 = 0;+ // SAFETY: each of these actions writes one UINT (or BOOL) to pv_param.+ let ok = unsafe { SystemParametersInfoW(action, 0, (&raw mut value).cast(), 0) };+ (ok != 0).then_some(value)+ };++ let smoothing = get(SPI_GETFONTSMOOTHING)? != 0;+ if !smoothing || get(SPI_GETFONTSMOOTHINGTYPE)? != FE_FONTSMOOTHINGCLEARTYPE {+ return None;+ }+ let geometry = match get(SPI_GETFONTSMOOTHINGORIENTATION) {+ Some(FE_FONTSMOOTHINGORIENTATIONBGR) => skia_safe::PixelGeometry::BGRH,+ _ => skia_safe::PixelGeometry::RGBH,+ };+ Some(skia_safe::SurfaceProps::new(Default::default(), geometry))+}+/// # Safety/// The caller must ensure `texture` was created by a DX12-backed wgpu device and remains/// valid for the lifetime of the returned `skia_safe::Surface`.pub unsafe fn make_dx12_surface(gr_context: &mut skia_safe::gpu::DirectContext,texture: &wgpu::Texture,+ surface_props: Option<&skia_safe::SurfaceProps>,) -> Option<skia_safe::Surface> {// SAFETY: texture is borrowed for the duration of this call; the D3D12 resource is// ref-counted (COM) and cloned into Skia's internal BackendRenderTarget via wrap_dx12_texture.@@ -77,6 +126,7 @@ pub unsafe fn make_dx12_surface(dxgi_format,color_type,super::attachment_color_space(texture),+ surface_props,)}}