Implement font loader for .NET assemblies

This commit is contained in:
Yoshi Askharoun
2025-08-04 00:05:36 -05:00
parent 49e08bd707
commit a2b3addfc1
2 changed files with 19 additions and 3 deletions
+16 -3
View File
@@ -217,14 +217,27 @@ namespace Microsoft.Iris.Markup.UIX
if (string.IsNullOrEmpty(resourceName))
ErrorManager.ReportError("Script runtime failure: Invalid 'null' value for '{0}'", "resourceName");
// Check if DLL is a .NET assembly
bool error;
// UIXRender doesn't know how to load resources from .NET assemblies, so we'll
// call the relevant GDI API manually for CLR DLLs.
var assemblyName = System.IO.Path.GetFileNameWithoutExtension(moduleName);
if (ClrDllResources.Instance.TryGetResource($"{assemblyName}!{resourceName}", $"clr-res://{assemblyName}", true, out var resource))
{
return null;
resource.Acquire();
uint cFonts = 0;
var hFont = Win32Api.AddFontMemResourceEx(resource.Buffer, resource.Length, System.IntPtr.Zero, ref cFonts);
error = hFont == System.IntPtr.Zero;
}
else
{
error = !NativeApi.SpLoadFontResource(moduleName, resourceName);
}
if (!NativeApi.SpLoadFontResource(moduleName, resourceName))
if (error)
ErrorManager.ReportError("Font Resource {1} not found in module {0}", moduleName, resourceName);
return null;
+3
View File
@@ -289,6 +289,9 @@ namespace Microsoft.Iris.OS
[DllImport("user32.dll")]
public static extern bool GetProcessDefaultLayout(out int pdwDefaultLayout);
[DllImport("gdi32.dll")]
public static extern IntPtr AddFontMemResourceEx(IntPtr pbFont, uint cbFont, IntPtr pdv, [In] ref uint pcFonts);
[Serializable]
public struct HANDLE
{