Page 1 of 1
Internal Fonts
Posted: Tue Aug 21, 2012 6:52 pm
by CenturyMan1979
Hey All,
Is there a way to internalize fonts in livecode? This was a feature that Adobe Director had and we still would like to use it in livecode if it is possible.
Thanks for any help you can provide on this subject.
Re: Internal Fonts
Posted: Tue Aug 21, 2012 7:32 pm
by shaosean
Unlike Director, you cannot use fonts that have been embedded in your Rev application, but you can fake it..
1. read in the font file and store in a custom property
Code: Select all
put URL "binfile:/path/to/font" into tFont
set the myFont of this stack to tFont
2. when you run your app, save out the font custom property to a temporary file
Code: Select all
put the myFont of this stack into tFont
put tFont into URL ("binfile:/" & specialFolderPath("Temporary") & "/fontName.extension")
3. now load/unload the font(s) as required with
revFontLoad and
revFontUnload
Re: Internal Fonts
Posted: Tue Aug 21, 2012 8:35 pm
by CenturyMan1979
Thanks for the information shaosean. That would of taking me forever to figure out without your help. Love livecode, just wish the documentation was a little better.
Re: Internal Fonts
Posted: Tue Aug 21, 2012 10:27 pm
by shaosean
yeah, the documentation totally needs to be improved, wish they would just switch to using HTML or some other form of text files so we can easily search them.. The online documentation needs to be updated pretty badly as it is a few years out of date

Re: Internal Fonts
Posted: Wed Aug 22, 2012 5:33 pm
by CenturyMan1979
Seem to be having trouble with loading in the binary data and then writing it back out. I have not really worked with the binfile yet so not sure if I am doing something wrong here. My function keeps returning "No font data to save out". I did this check because there was no file being created on my desktop.
Code: Select all
function copyFonts
local tFontFile, tFont
put specialFolderPath("Fonts") & "/helr45w_0.ttf" into tFontFile
if there is a file tFontFile then
put URL("binfile:/" & specialFolderPath("Fonts") & "/helr45w_0.ttf") into tFont
else
return "Font file does not exist"
end if
if tFont is empty then
return "No font data to save out"
else
put tFont into URL ("binfile:/" & specialFolderPath("Desktop") & "/helr45w_0.ttf")
end if
end copyFonts
Re: Internal Fonts
Posted: Wed Aug 22, 2012 9:23 pm
by shaosean
Try removing the slash after "binfile:/" in both places.. The reason for this is there is a slash already from the specialFolder function.. The only other changes I would make is to reuse the "tFontFile" variable and to make it a command instead of a function..
Code: Select all
command copyFonts
local tFontFile, tFont
put specialFolderPath("Fonts") & "/helr45w_0.ttf" into tFontFile
if there is a file tFontFile then
put URL ("binfile:" & tFontFile) into tFont
else
return "Font file does not exist"
end if
if tFont is empty then
return "No font data to save out"
else
put tFont into URL ("binfile:/" & specialFolderPath("Desktop") & "/helr45w_0.ttf")
end if
end copyFonts
Re: Internal Fonts
Posted: Thu Aug 23, 2012 3:30 pm
by CenturyMan1979
shaosean wrote:Try removing the slash after "binfile:/" in both places.. The reason for this is there is a slash already from the specialFolder function..
Taking out the slash fixed it but when I go to the message box and have it output specialFolder("Fonts") there is no slash at the beginning. Instead I get C:/Windows/Fonts . So is the slash not needed because it is an absolute path?
Re: Internal Fonts
Posted: Thu Aug 23, 2012 7:03 pm
by Klaus
CenturyMan1979 wrote:Taking out the slash fixed it...
Sure it does!
The correct syntax is:
url("binfile:" & absolute_or_relative_path)
or
url("file:" & absolute_or_relative_path)
CenturyMan1979 wrote:...but when I go to the message box and have it output specialFolder("Fonts") there is no slash at the beginning.
This is correct, as we just found out.
CenturyMan1979 wrote:Instead I get C:/Windows/Fonts . So is the slash not needed because it is an absolute path?
Bingo (in case you have a harddisk named "C")
A slash isn't even necessary with relative pathnames!
url("file:" & "mytextfile.txt")...
will work as long as "mytextfile.txt" is in the current defaultfolder!
I wonder how you come to think of a slash at the beginning?
This is ONLY neccessary in an internet browser when accessing local files -> file:/...
Re: Internal Fonts
Posted: Thu Aug 23, 2012 9:42 pm
by shaosean
Mac OS X and Linux need the slash at the beginning for absolute paths

Re: Internal Fonts
Posted: Thu Aug 23, 2012 10:06 pm
by mwieder
Sean- specialFolderPath() gives you the complete specification, so a leading slash isn't necessary. Or useful.
Re: Internal Fonts
Posted: Thu Aug 23, 2012 11:10 pm
by Klaus
shaosean wrote:Mac OS X and Linux need the slash at the beginning for absolute paths

Yep. that is true, but we are dealing with plain wrong syntax here
Good:
url("binfile:" & absolute_or_relative_path)
Bad:
url("binfile:/" & absolute_or_relative_path)
Whatever, I think this is just a misunderstanding from your first example:
put URL "binfile:/path/to/font" into tFont
So maybe CenturyMan1979 thought the / would be necessary here!?
OK, all cleared out, move on, nothing to see here
Best
Klaus