HighTechTalks DotNet Forums  

AddMemoryFont

Dotnet Framework (Drawing) microsoft.public.dotnet.framework.drawing


Discuss AddMemoryFont in the Dotnet Framework (Drawing) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
James
 
Posts: n/a

Default AddMemoryFont - 05-10-2007 , 05:39 AM






Hi

I am having some trouble with the AddMemoryFont method. I am trying to
embed an OpenType font but it keeps giving me the following:

System.InvalidOperationException: Error loading font --->
System.IO.FileNotFoundException: File not found.
at System.Drawing.Text.PrivateFontCollection.AddMemor yFont(IntPtr
memory, Int32 length)

My code looks like this:

// buffer
byte[] fontData = new byte[fontStream.Length];

// read
fontStream.Read(fontData, 0, (int)fontStream.Length);

IntPtr data = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(byte)) *
fontData.Length);

// copy to unsafe memory block
Marshal.Copy(fontData, 0, data, fontData.Length);

// add to font collection
_pfc.AddMemoryFont(data, fontData.Length);

Int32 pcFonts = 1;

AddFontMemResourceEx(data, fontData.Length, 0, pcFonts);

// clean up
fontStream.Close();
Marshal.FreeHGlobal(data);


It works when I use a TrueType font but is there anyway to get an
OpenType font to store in memory. If not, is there a good way to
convert my .otf to .ttf.

Thanks

James


Reply With Quote
  #2  
Old   
James
 
Posts: n/a

Default Re: AddMemoryFont - 05-10-2007 , 05:40 AM






Also, I forgot to mention I have to use .net 1.1


Reply With Quote
  #3  
Old   
Bob Powell [MVP]
 
Posts: n/a

Default Re: AddMemoryFont - 05-14-2007 , 02:05 AM



See my article in Windows Forms Tips and Tricks about embedding a font.

--
--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.


"James" <jamesnaylor85 (AT) googlemail (DOT) com> wrote

Quote:
Also, I forgot to mention I have to use .net 1.1



Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.