CatsSolutions
asked on
WPF FontFamily from memory
HI,
I am creating a program that downloads a required font through a web service as a byte[] and I would like to assign the font on a label control.
I know I could save the font as a file and get a new FontFamily from a URI but I'd rather not have temporary files.
I have seen that in System.Drawing you could use a PrivateFontCollection from memory but I'm not sure if its possible use that in a WPF label.
Any help?
I am creating a program that downloads a required font through a web service as a byte[] and I would like to assign the font on a label control.
I know I could save the font as a file and get a new FontFamily from a URI but I'd rather not have temporary files.
I have seen that in System.Drawing you could use a PrivateFontCollection from memory but I'm not sure if its possible use that in a WPF label.
Any help?
ASKER
Hi sognot,
Thank you for the reply but the code does not seem to work. A label has a fontfamily, not a font.
Where does AddFontMemResourceEx come from?
Label does not have a property for UseCompatibleTextRendering
Thank you for the reply but the code does not seem to work. A label has a fontfamily, not a font.
Where does AddFontMemResourceEx come from?
Label does not have a property for UseCompatibleTextRendering
sorry now I tested code, wpf does not allow PrivateFontCollection as in standard forms.
The only and simplest way is to put the font inside the site that host web service then you can call :
label1.FontFamily = new FontFamily( new Uri("http://myserver/Fonts/#My Custom Font", UriKind.Absolute), "My Custom Font");
So service can expose the fonts not as byte but as url of the disponible font to use.
The only and simplest way is to put the font inside the site that host web service then you can call :
label1.FontFamily = new FontFamily( new Uri("http://myserver/Fonts/#My Custom Font", UriKind.Absolute), "My Custom Font");
So service can expose the fonts not as byte but as url of the disponible font to use.
ASKER
Unfortunately that's something I can't do so I think I'll have to settle for creating temporary files and deleting them when done.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
suppose that fontData is Byte[]
and fondatalenght its lenght
Open in new window
this code comes from a project of mine, I've done some modification on the fly, so some debugging is necessary