From 8acf80bfad4d49ad3a20644c7599e4c83ff1eece Mon Sep 17 00:00:00 2001 From: Benjamin Klum Date: Wed, 14 Feb 2024 16:43:48 +0100 Subject: [PATCH] SWELL: Fix CreateFontIndirect on Windows --- main/low/src/swell_impl.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/main/low/src/swell_impl.rs b/main/low/src/swell_impl.rs index ddad8287..a7d4c221 100644 --- a/main/low/src/swell_impl.rs +++ b/main/low/src/swell_impl.rs @@ -6,7 +6,6 @@ #![allow(non_snake_case)] #![allow(unused_variables)] -use std::ptr::null; use crate::{ bindings::root, register_plugin_destroy_hook, PluginContext, Swell, SwellFunctionPointers, }; @@ -348,8 +347,8 @@ impl Swell { if font.is_null() { return std::ptr::null_mut(); } - let font = *font; - let mut wide_font = winapi::um::wingdi::LOGFONTW{ + let font = &*font; + let mut wide_font = winapi::um::wingdi::LOGFONTW { lfHeight: font.lfHeight, lfWidth: font.lfWidth, lfEscapement: font.lfEscapement, @@ -365,10 +364,10 @@ impl Swell { lfPitchAndFamily: font.lfPitchAndFamily as _, lfFaceName: [0; 32], }; - - winapi::um::wingdi::CreateFontIndirectW( - &mut wide_font as *mut _ - ) as _ + for (i, ch) in font.lfFaceName.iter().take(15).enumerate() { + (*ch as u8 as char).encode_utf16(&mut wide_font.lfFaceName[i * 2..]); + } + winapi::um::wingdi::CreateFontIndirectW(&mut wide_font as *mut _) as _ } /// # Safety