Global Font Declaration

Hi there,
I’m running into issues trying to allocate an ofTrueTypeFont, I have a font loading ok in my ofApp, but i can’t seem to load the font in another class of mine, I keep on getting EXC_BAD_ACCESS errors but no “failed to load font” errors.

Is there a way to declare and use a font in all classes without having to redeclare it in all of my classes

Thanks,
Miles

I’m having similar issues Miles.
Did you ever find a solution to this?

it would help to see a simple example of a program that causes errors.

when I need to share a font among classes I use pointers – I load the font in the ofApp level but I pass a pointer to that to my classes.

if it’s helpful, there’s this addon which makes sharing fonts among classes easier:

Thanks Zach.
This addOn looks very helpful and i’ll try to get it integrated into my app.

The reason I’m starting to look into simplifying how fonts are used across my app (it’s a bit big so hard to share here), is that my real issue is actually how to get fonts to get loaded properly when I put my app on a different computer. I’m finding that some computers work and some don’t. I’ve tried providing different paths to the ‘load’ method but its inconsistent across different machines that are running the same operating system (os x 10.12).

Specifically, i’m putting my .ttf file in the ‘data’ folder; and i’m trying to load the font like this:

ofTrueTypeFont thisFont;
thisFont.load("Arial.ttf',12);

The data folder of my app has Arial.ttf in it; not in a subdirectory, but right in the data folder.

This works on my computer, but when i put it on a different laptop, no fonts render.

I’ve tried debug and release builds; i have also confirmed that the Arial.ttf font IS in Resources/data within the application package.

I’m having the same issue with @braitsch 's ofxDatGUI as well; i’ve posted that issue here.

one thing to pay attention to is on 10.12 there’s a weird security setting which runs apps from a temporary read only directory if it’s coming from an unsigned zip – which means app can’t find the data folder. This has made my life really hard this year with freelancing / clients when I send them apps to try.

Here’s an email I wrote to a client, explaining it:

if you are on sierra, there’s a weird security thing that will mean this app will be run from a weird location which means it can’t load the fonts that are next to it. sierra has some weird security settings that runs apps that are not signed in randomized locations so it can’t find the data folder. (the fancy term for this is app translocation — http://lapcatsoftware.com/articles/app-translocation.html) it’s kind of annoying and I’ve had issues sharing apps with people recently.

to override this, you simply need to move the app (the sharpApp file) around before you run it which makes it run ok. you can simply move the “sharpApp” file to the desktop and back to the folder it was in (next to the data folder) and it should run fine when you launch it again.

an alternative is to launch the app from the command line (terminal) if you cd to the directory that the app is in and type:

./APPNAME.app/Contents/MacOS/APPNAME

replace APPNAME with your app’s name…

I think one solution is make a signed dmg instead of a zip.

ps: this is why the project generator on 10.12 requires you to point it to the OF folder. It doesn’t know where it is since it’s run from a temporary location. We (cc @arturo @theo) might want to look at distributing OF in a signed dmg instead of zip for a better fix…

i think it’s the application itself that would need to be signed not OF itself so i don’t think there’s much we can do on our side except for providing instructions on how to sign apps. also probably moving the assets into the generated dmg and using ofToDataPath to set the assets path to that folder might make things better?

I haven’t tested but from what I’ve read the app translocation has to do with the archive format (signed disk img vs zip) then the app being signed – AFAIK unsigned apps you need to approve via security settings but it doesn’t trigger app translocation…

I think we might want to look at how hard it is to sign dmgs vs using zips for OSX downloads. I am going to investigate this a bit because it trips up many of my interactions with clients when I send them apps now.

yeah that’s what i meant with signed app, signed dmg vs zip, i dont’t think that doing so for OF itself will make any difference and the problem comes when people create an application and distribute it as a zip

but also i believe if you put the data inside the dmg the translocation will happen for the whole dmg so it might work better than having an external data folder

ah but I am talking specifically about the project generator and how on 10.12 we need to ask people to find the root of OF. using a signed dmg will help with this, afaik…

…and for people who use OF maybe some tips in the OSX readme like how to use hdiutil to make a dmg and codesign to sign it… (I didn’t figure out all these steps yet but it seems like those are the command line tools to explore)

Ah, i thought you meant packaging OF itself as a dmg. Didn’t @danoli3 fixed something like this with https://github.com/openframeworks/openFrameworks/issues/4825

sorry I meant if we package OF as a DMG then we can potentially avoid this work around which can be a little confusing for beginners: