Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1725
Getting embedded fonts to work.
posted

I'm having a problem that may be similar to or related to the post http://news.infragistics.com/forums/p/5509/24602.aspx#24602 "Getting fonts to work".

In my case, I have a font that is embedded resource. What my code does is to load the font data from the resource and then creates an Infragistics.Documents.Graphics.Font as in

Infragistics.Documents.Graphics.Font font = new Infragistics.Documents.Graphics.Font(fontName, 12, fontdata);

This seems to create the font but when I try to use the font in a report and export the pdf file the font is obviously not being used.

I've also tried to create a font loading it into a PrivateFontCollection but that does not seem to work either for some reason. I'm using V8.1.

Is there some trick to fonts that I'm missing?

The code I'm using to create the font looks like the following

System.IntPtr buffer = (System.IntPtr)null;
System.IO.Stream fontStream = TastingMasterFonts.GetFontStream(name);
if (null != fontStream)
{
try
{
buffer = System.Runtime.InteropServices.Marshal.AllocCoTaskMem((int)fontStream.Length);
byte[ fontdata = new byte[fontStream.Length];
fontStream.Read(fontdata, 0, (int)fontStream.Length);
System.Runtime.InteropServices.Marshal.Copy(fontdata, 0, buffer, (int)fontStream.Length);
//* This was an attempt to create and then use the font in a PrivateFontCollection. I get the same result here
if (null == _pf)
_pf = new System.Drawing.Text.PrivateFontCollection();
_pf.AddMemoryFont(buffer, (int)fontStream.Length);
String fontName = name.Replace(".ttf", "").Trim();
Infragistics.Documents.Graphics.Font font = new Infragistics.Documents.Graphics.Font(fontName, 12, fontdata);
//* I tried a font stream and font data, no difference

//fontStream.Seek(0, System.IO.SeekOrigin.Begin);
//Infragistics.Documents.Graphics.Font font = new Infragistics.Documents.Graphics.Font(fontName, 12, fontStream);
_loadedFonts.Add(name.Replace(".ttf", "").Trim(), font);
}
catch (Exception ex)
{
string Error = ex.Message;
LogEventHelper.LogEvent(_log, ex);
}
fina
{
fontStream.Close();
System.Runtime.InteropServices.Marshal.FreeCoTaskMem(buffer);
}

  • 37774
    posted

    The Documents engine will not try to load a font from a collection that it is not aware of.  I think that your approach of passing in a stream is the correct one, but you should also set the font.Preferences.Embed to True.

    -Matt