Using a custom font in an OSX app

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
doobox
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 284
Joined: Tue May 24, 2011 11:47 pm

Using a custom font in an OSX app

Post by doobox » Tue Feb 05, 2013 11:54 pm

Hi there,

I could have sworn i'd done this before and it was just a matter of adding the ttf font file to the copy files, but i could be wrong :-)

Any way, this is what i have done and it does not work on another machine that does not have the font installed already.....

I added my custom font to the copy files.. I had placed it right next to the .livecode file, so the copy files reference just says "myfont.ttf"

In various fields around my app i have via the inspector, in text formatting, selected myfont as the font for the field.

Of course this works on my system as the font is installed, but the font does not show on any other system.


Some misconceptions i had.... I thought Livecode detected the inclusion of the font in the copy files and added the font external, that handled the fonts were i have selected them in certain fields.
Looking at the standalone.. indeed the font external has been included... so what step am i missing here, that is preventing the bundled font from being used in the fields i have marked to use it..?

Kind regards
Gary
Kind Regards
Gary

https://www.doobox.co.uk

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7230
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Using a custom font in an OSX app

Post by jacque » Wed Feb 06, 2013 12:33 am

A script has to load the font. See "revFontLoad" in the dictionary. When you're done, unload it with revFontUnload.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

doobox
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 284
Joined: Tue May 24, 2011 11:47 pm

Re: Using a custom font in an OSX app

Post by doobox » Wed Feb 06, 2013 1:20 am

Thanks jacque, This is not something i ever did so i must have been thinking of ios in the past.

Not quite there though....!
Testing with a couple of temp fields in the app i can see the path to the custom font i have included on the app copy files is correct :

Code: Select all

on preOpenCard
   put tAppPath() & "/rabiohead.ttf" into tPathToCustomFont
   revFontLoad tPathToCustomFont
   put tPathToCustomFont into field "test"
   put the fontNames into field "test2"
   sort field "test2"
end preOpenCard
And when the stack opens i can see that the custom font is loaded in memory in the second temp field showing font names.
But the fonts still don't display correctly in the app, as they do on my build machine where it is already installed on the system..?

Kind regards
Gary
Kind Regards
Gary

https://www.doobox.co.uk

doobox
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 284
Joined: Tue May 24, 2011 11:47 pm

Re: Using a custom font in an OSX app

Post by doobox » Wed Feb 06, 2013 1:33 am

Do i literally have to go through each object like this after loading the font into memory, even though i have selected the font in the objects inspector previously..?

Code: Select all

set the textFont of object to fontName[,language]
Kind Regards
Gary

https://www.doobox.co.uk

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7230
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Using a custom font in an OSX app

Post by jacque » Wed Feb 06, 2013 5:23 am

If all your objects use the same font, it's easier to set the textfont on all of them to empty during development. Then just set the font of the stack and every object will inherit it. If there are only a few exceptions, set those objects to some other font.

If the objects all use different fonts, then I guess you'd have to loop through them. It does seem like you shouldn't have to do any of that though. I haven't ever needed to use a custom font, but I wonder if the engine has decided the font doesn't exist when the stack opens and so it sets all objects to a default. By the time you've loaded in the custom font, the fields have already been reset. Just a guess.

You could try loading the font on startup, before the stack is opened. PreOpenCard is pretty late in the sequence.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

doobox
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 284
Joined: Tue May 24, 2011 11:47 pm

Re: Using a custom font in an OSX app

Post by doobox » Wed Feb 06, 2013 10:00 am

None of this works I am afraid jacque. I found another post on the forum here, that talks about "internal fonts" : http://forums.runrev.com/viewtopic.php? ... ont#p60558
But i am unsure if this applies to all situations.
In it is is stated that a font can't be loaded from an embedded font within the app.
I cant really tell from the wording if, that's exactly what i am trying to do here. I would be surprised if that is the way you add a custom font to an desktop app, it's not documented by Livecode.
Can anyone confirm if that is why i am seeing this fail for me..?
Kind Regards
Gary

https://www.doobox.co.uk

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7230
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Using a custom font in an OSX app

Post by jacque » Wed Feb 06, 2013 8:46 pm

I see. That thread indicates you need to copy the font to the hard drive before loading it. They suggest the temporary folder.

Sorry this is the blind leading the blind. Hopefully someone with experience will get past all the spam and reply.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

doobox
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 284
Joined: Tue May 24, 2011 11:47 pm

Re: Using a custom font in an OSX app

Post by doobox » Wed Feb 06, 2013 8:58 pm

Agreed, it does seem to indicate that a font cant be loaded from a font bundled in the application.
I wonder if this is an operating system constraint, like the fact an app cant save it's self...
It does blow me away though, if it's that convoluted to have a custom font/s in a desktop app.

It would seem simpler to just give the user the font, and install it in there fonts directory from the app.
That said i tried, and that seems to fail also :-)
Kind Regards
Gary

https://www.doobox.co.uk

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

Re: Using a custom font in an OSX app

Post by Klaus » Thu Feb 07, 2013 12:18 pm

Hi Gary,

yes, convoluted or not, you need to save the font file on the users harddisk to be able to activate and use it with Livecode.

The thread here http://forums.runrev.com/viewtopic.php? ... ont#p60558
shows how to do it right.


Best

Klaus

doobox
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 284
Joined: Tue May 24, 2011 11:47 pm

Re: Using a custom font in an OSX app

Post by doobox » Thu Feb 07, 2013 12:53 pm

Thanks for clarifying Klaus :-)
Kind Regards
Gary

https://www.doobox.co.uk

doobox
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 284
Joined: Tue May 24, 2011 11:47 pm

Re: Using a custom font in an OSX app

Post by doobox » Thu Feb 07, 2013 1:01 pm

For my and others benefit and further clarification. Am i correct in these assumptions:

You never actually bundle the font file in the app via copy files.

You could execute this code in the development stage :

Code: Select all

    put URL "binfile:/path/to/font" into tFont
    set the myFont of this stack to tFont
So the font is now permanently stored in the custom property as binary data.

Now running the app in on preOpenStack, save the font to the users disk, so it can be used by your app.
Clicked at last i hope :-)

I was to wrapped up in including the actual font file with the app.
Kind Regards
Gary

https://www.doobox.co.uk

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7230
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Using a custom font in an OSX app

Post by jacque » Thu Feb 07, 2013 9:30 pm

I don't think it matters where or how you store the font file, the important bit is that it needs to be copied out of the bundle and onto the hard drive. Storing it as a file or as a custom property shouldn't make much difference. People do often store binary files as properties so they don't get lost though.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

seaniepie
Posts: 154
Joined: Wed Sep 07, 2011 10:56 am

Re: Using a custom font in an OSX app (Update)

Post by seaniepie » Sat Apr 01, 2017 3:02 am

You can now use

Code: Select all

start using font file (specialfolderpath("resources") & "/YourFont.ttf")
Just wanted to add it to this thread

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”