简体   繁体   中英

VB.Net embedded font not working in windows XP

I want a specific font to display on certain buttons in an application so have chosen to include it in the project as a resource.

I then .addMemoryFont to a new PrivateFontCollection by the way of the Marshal namespace and then set the font to my new font family.

This works on Windows Vista, Windows7 and Windows 8 (preview) but will not work on windows XP which my app has to support.

There is no error on XP .. the font just doesn't display.

I have also tried embedding the font as a file and loading it through a stream object - Assembly.GetExecutingAssembly().GetManifestResourceStream(resource)

This again works on everything but XP, any thoughts? Thanks

Here's the function that I load the resource with: For this testing I have added AVP.TTF (widely available, non commercial) as a resource called AVP.

I use button.Font = LoadFontResource(9.75, FontStyle.Regular) in the client.

Public Function LoadFontResource(ByVal Size As Single, ByVal style As FontStyle) As Font
    _fontsResource = New PrivateFontCollection
    Dim fontMemPointer As IntPtr = Marshal.AllocCoTaskMem(My.Resources.AVP.Length)
    Marshal.Copy(My.Resources.AVP, 0, fontMemPointer, My.Resources.AVP.Length)
    _fontsResource.AddMemoryFont(fontMemPointer, My.Resources.AVP.Length)
    Marshal.FreeCoTaskMem(fontMemPointer)
    Return New Font(_fontsResource.Families(0), Size, style)
End Function

Writing the embedded font to a temporary file and then using .AddFontFile leads to a more stable performance in XP. Thanks Hans for pointing me down the old GDI+ route.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM