www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Resource availability: fonts

reply Tyro[a.c.edwards] <nospam home.com> writes:
One cannot necessarily rely on particular font being available on a system, and
for security reasons asminsistrators restrict instalation of fonts (among other
things) onto systems in a network. I would like to know if it is possible to
embed a font into my code so that I know that it will always be there, or can I
provide it with the exe but not have to rely on it being "installed" (i.e. use
it from the same folder in which the exe resides)? 

Thanks,
Andrew
May 05 2009
next sibling parent reply Daniel Keep <daniel.keep.lists gmail.com> writes:
Tyro[a.c.edwards] wrote:
 One cannot necessarily rely on particular font being available on a system,
and for security reasons asminsistrators restrict instalation of fonts (among
other things) onto systems in a network. I would like to know if it is possible
to embed a font into my code so that I know that it will always be there, or
can I provide it with the exe but not have to rely on it being "installed"
(i.e. use it from the same folder in which the exe resides)? 
 
 Thanks,
 Andrew
That depends. What are you using the font for? If you're using a library that requires a family name, then probably not. If you're using a library that can accept a file name, then probably yes. Remember that the system doesn't care if you append crap to the end of an executable. One trick you can use is to just append whatever files you want to the end of the executable, and then have a little 1K block at the end that tells you where the files are and how big they are; you can then extract the files at run time and delete them when you terminate. -- Daniel
May 05 2009
parent reply "Tyro[a.c.edwards]" <nospam home.com> writes:
On 5/6/2009 12:30 PM, Daniel Keep wrote:
 Tyro[a.c.edwards] wrote:
 One cannot necessarily rely on particular font being available on a system,
and for security reasons asminsistrators restrict instalation of fonts (among
other things) onto systems in a network. I would like to know if it is possible
to embed a font into my code so that I know that it will always be there, or
can I provide it with the exe but not have to rely on it being "installed"
(i.e. use it from the same folder in which the exe resides)?

 Thanks,
 Andrew
That depends. What are you using the font for? If you're using a library that requires a family name, then probably not. If you're using a library that can accept a file name, then probably yes.
I'm using DFL which uses family names (eg. "Times New Roman").
 Remember that the system doesn't care if you append crap to the end of
 an executable.  One trick you can use is to just append whatever files
 you want to the end of the executable, and then have a little 1K block
 at the end that tells you where the files are and how big they are; you
 can then extract the files at run time and delete them when you terminate.
When I do this, how do I ensure that the program is able to locate the font after extraction without "installing" it?
    -- Daniel
May 06 2009
parent reply John C <johnch_atms hotmail.com> writes:
Tyro[a.c.edwards] Wrote:

 When I do this, how do I ensure that the program is able to locate the 
 font after extraction without "installing" it?
 
I think AddFontResource from the SDK will do that. http://msdn.microsoft.com/en-us/library/dd183326(VS.85).aspx
May 06 2009
parent "Tyro[a.c.edwards]" <nospam home.com> writes:
On 5/6/2009 9:50 PM, John C wrote:
 Tyro[a.c.edwards] Wrote:

 When I do this, how do I ensure that the program is able to locate the
 font after extraction without "installing" it?
I think AddFontResource from the SDK will do that. http://msdn.microsoft.com/en-us/library/dd183326(VS.85).aspx
That was it... Aswesome! Thank you all very much for your assistance.
May 06 2009
prev sibling parent reply grauzone <none example.net> writes:
Use
ubyte[] fontbytes = cast(ubyte[])import("yourfont.ttf");
May 05 2009
next sibling parent reply "Lars T. Kyllingstad" <public kyllingen.NOSPAMnet> writes:
grauzone wrote:
 Use
 ubyte[] fontbytes = cast(ubyte[])import("yourfont.ttf");
That is so cool. I've seen the import() expression mentioned here on the NG before. It returns a string containing the imported source file, right? Is it mentioned anywhere in the docs? I can't seem to find it. -Lars
May 05 2009
parent reply grauzone <none example.net> writes:
http://digitalmars.com/d/1.0/expression.html#ImportExpression

It returns a char[], which is a misdesign, because the loaded file can 
be binary data as well. I think.
May 06 2009
parent Rainer Deyke <rainerd eldwood.com> writes:
grauzone wrote:
 http://digitalmars.com/d/1.0/expression.html#ImportExpression
 
 It returns a char[], which is a misdesign, because the loaded file can
 be binary data as well. I think.
The file could also contain non-utf8 text, which should also not be stored in a char[]. char[] is for utf-8 only. -- Rainer Deyke - rainerd eldwood.com
May 06 2009
prev sibling parent "Tyro[a.c.edwards]" <nospam home.com> writes:
On 5/6/2009 1:39 PM, grauzone wrote:
 Use
 ubyte[] fontbytes = cast(ubyte[])import("yourfont.ttf");
This will take care of making sure the font is available. How do you instruct the library (DFL in this case) that this variable contains the font or that after you write it back to the hard drive to refer to the file? A font that is not installed, but instead, simply residing in a folder of your choosing?
May 06 2009