Embeded Fonts

  • Thread starter Thread starter Jon Finch
  • Start date Start date
J

Jon Finch

Appologies if this has been covered before, I did do a search but cannot
find any relevant info.

I am looking to embed a font inside vb.net. I have embedded the font okay
but all the examples I have to read a font back from the assembly use c#
unsafe blocks and other c# functionality which is not supported by vb (or at
least I can't get them to work)

Has anybody got any examples regarding reading embeded fonts back into vb
from the assembly? Any help or pointers in the right direction would be very
much appreciated..

All the best,

Jon

p.s.
Just installing the font into the windows font directory is sadly not an
option as we do not have a license for the font to be distributed only to be
used at runtime.
 
Hello,

Jon Finch said:
Appologies if this has been covered before, I did do a search
but cannot find any relevant info.

I am looking to embed a font inside vb.net. I have embedded
the font okay but all the examples I have to read a font
back from the assembly use c# unsafe blocks and other
c# functionality which is not supported by vb (or at least I
can't get them to work)

This will AFAIK require some pinvoke stuff. Do you have links pointing to
C# samples? Maybe somebody here wants to translate the code to VB.NET.
 
Hi, could you point us to the C# code, perhaps we can translate it for you.

--
HTH,
-- Tom Spink, Über Geek

Please respond to the newsgroup,
so all can benefit

"Chaos, Panic, Disorder, my work here is done"


: Appologies if this has been covered before, I did do a search but cannot
: find any relevant info.
:
: I am looking to embed a font inside vb.net. I have embedded the font okay
: but all the examples I have to read a font back from the assembly use c#
: unsafe blocks and other c# functionality which is not supported by vb (or
at
: least I can't get them to work)
:
: Has anybody got any examples regarding reading embeded fonts back into vb
: from the assembly? Any help or pointers in the right direction would be
very
: much appreciated..
:
: All the best,
:
: Jon
:
: p.s.
: Just installing the font into the windows font directory is sadly not an
: option as we do not have a license for the font to be distributed only to
be
: used at runtime.
:
:
:
:
:
:
 
Sorry I didn't post the code samples b4 but I deleted them from my file
(teach me not to comment them out so I had to route them out again)

He's one I found from a newsgroup
---
Stream fontStream =
this.GetType().Assembly.GetManifestResourceStream("embedfont.Alphd___.ttf");
byte[] fontdata = new byte[fontStream.Length];
fontStream.Read(fontdata,0,(int)fontStream.Length);
fontStream.Close();
unsafe
{
fixed(byte * pFontData = fontdata)
{
pfc.AddMemoryFont((System.IntPtr)pFontData,fontdata.Length);
}
}
---

The problems I had with this are the unsafe block and the fixed(byte *
pFontData = fontdata) lines.

I also found this code example from another site
---
PrivateFontCollections fonts = new PrivateFontCollection();
Assembly asm this.getType().Assembly;

Stream stm = asm.GetManifestResourceStream("Application.font.ttf");
byte[] buffer = new byte[stm.length]
stm.Read(buffer, 0, (int)stm.length)
IntPtr pi = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(byte)) *
buffer.length);
Marshal.Copy(buffer, 0, pi, buffer.Length);
fonts.AddmemoryFont(pi, buffer.Length);
Marshal.FreeHGlobal(pi);
---

The problem I had with converting this section of code was
(Marshal.SizeOf(typeof(byte)) * buffer.length) I am assuming this does the
same as the fixed(byte * pFontData = fontdata) that I was having problems
with in the other example. Any ideas of the vb.net equivilant?

I should have really built the whole project in c# as I'm a Java coder and
it's not a million miles away but since I had experience in VB6 I thought it
might be quicker to do it in vb.net ;)

Thanks for any help,

Jon
 
Back
Top