Internal Fonts

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
CenturyMan1979
Posts: 86
Joined: Tue May 15, 2012 5:56 pm
Location: Minneapolis, MN

Internal Fonts

Post by CenturyMan1979 » Tue Aug 21, 2012 6:52 pm

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.

shaosean
Posts: 906
Joined: Thu Nov 04, 2010 7:53 am

Re: Internal Fonts

Post by shaosean » Tue Aug 21, 2012 7:32 pm

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

CenturyMan1979
Posts: 86
Joined: Tue May 15, 2012 5:56 pm
Location: Minneapolis, MN

Re: Internal Fonts

Post by CenturyMan1979 » Tue Aug 21, 2012 8:35 pm

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.

shaosean
Posts: 906
Joined: Thu Nov 04, 2010 7:53 am

Re: Internal Fonts

Post by shaosean » Tue Aug 21, 2012 10:27 pm

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 :(

CenturyMan1979
Posts: 86
Joined: Tue May 15, 2012 5:56 pm
Location: Minneapolis, MN

Re: Internal Fonts

Post by CenturyMan1979 » Wed Aug 22, 2012 5:33 pm

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

shaosean
Posts: 906
Joined: Thu Nov 04, 2010 7:53 am

Re: Internal Fonts

Post by shaosean » Wed Aug 22, 2012 9:23 pm

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

CenturyMan1979
Posts: 86
Joined: Tue May 15, 2012 5:56 pm
Location: Minneapolis, MN

Re: Internal Fonts

Post by CenturyMan1979 » Thu Aug 23, 2012 3:30 pm

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?

Klaus
Posts: 13834
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Internal Fonts

Post by Klaus » Thu Aug 23, 2012 7:03 pm

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") :D
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:/...

shaosean
Posts: 906
Joined: Thu Nov 04, 2010 7:53 am

Re: Internal Fonts

Post by shaosean » Thu Aug 23, 2012 9:42 pm

Mac OS X and Linux need the slash at the beginning for absolute paths ;-)

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: Internal Fonts

Post by mwieder » Thu Aug 23, 2012 10:06 pm

Sean- specialFolderPath() gives you the complete specification, so a leading slash isn't necessary. Or useful.

Klaus
Posts: 13834
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Internal Fonts

Post by Klaus » Thu Aug 23, 2012 11:10 pm

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 8)

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 :D


Best

Klaus

Post Reply

Return to “Talking LiveCode”