Skip to main content
Participating Frequently
July 5, 2011
Question

Loading custom fonts in iOS at runtime

  • July 5, 2011
  • 8 replies
  • 3305 views

Our application downloads and renders external, custom content which includes custom, proprietary fonts.  For web, desktop, and Android we simply use external SWF files that have the fonts embedded.  It makes technical sense why this method wouldn't work for iOS, but I haven't been able to find any alternatives.  Is this simply not possible?  I hope that's not the case as it would mean our application isn't possible for iOS using the AIR mobile technologies.

Eric

This topic has been closed for replies.

8 replies

Participant
September 20, 2011

Hi,

Do you have the capability of compiling your main swf on-the-fly using a server-side compiler? I ran into a similar problem and the solution I found to replace the lack of capability to load a small swf for each font was to compile the font file into a swc and include it in my Library Path. Of course, we can't load the swc at runtime but if you can compile on-demand it could be a solution.

HTH,

Jean

Participating Frequently
May 23, 2012

Hi Soarbirw,

Any news about this problem? I'm also stucked with this kind of problem, my application works perfectly in Android environment, in iOS non-appstore environment, but for ad-hoc version, the texts disapear, as the fonts are in SWFs...

Any help would be grandly appreciated

Mounir.

SoabirwAuthor
Participating Frequently
May 23, 2012

Mounir,

Yes and no.  We ended up using wumedia's parser and vector packages.  With that we could download the SWF, then parse it to get our glyphs out, then manually place them with VectorText.  It is not a very efficient process and with large quantatites of text it can be a bit slow.  For a full page of text, it will take a few full seconds to render.

Something we will be trying at some point is working directly with TTF instead of having them embedded in SWF.  There are complications with this conversion given our source materials, but I think we should be able to download a TTF and embedd it just fine.

Hope that helps a bit.

Eric

Participating Frequently
July 5, 2011

Hi Eric,

do you mean "shared" runtime fonts? (loaded at runtime) That is not supported on iOS (as sthere is no Flash runtime on iOS). Here is documentation:

http://help.adobe.com/en_US/as3/iphone/WS789ea67d3e73a8b2-5b45bb17124b3295cc8-7ffd.html

(but you could certainly make version of your project that use "embedded" library symbols instead of "runtime shared" - this is how people are doing project versioning for 3rd party software that packages standalone executables where using shared fonts is not supported as well),

thanks,

regards,

Peter

SoabirwAuthor
Participating Frequently
July 5, 2011

Let me go into a bit more detail on this process.  On the server a PDF is uploaded.  We then parse and extract content from the PDF, including fonts for each page.  These fonts are often completely custom and prioprietary to the content owner, as they store symbols for math and other non-standard characters.  When we extract these fonts, we assign the font to a unique identifier, embed it, and compile it into a SWF.  When that content is requested from the client, we have a list of fonts for it.  We download all SWF files that contain that font and then load and register the fonts.  Here is an example of the SWF we are pulling down.  This is the entirety of the compiled SWF being pulled down.

package {

    import flash.display.Sprite;

    import flash.text.Font;

    import flash.system.Security;

    public class F9471cf2d10924f87820ae61a30dd4b8f extends Sprite

    {

          [Embed(source='TempF9471cf2d10924f87820ae61a30dd4b8f.swf',symbol='F9471cf2d10924f87820ae61a30dd4b8f')]

          public static var F9471cf2d10924f87820ae61a30dd4b8f:Class;

          public function F9471cf2d10924f87820ae61a30dd4b8f()

          {

              Security.allowDomain("*");

              Security.allowInsecureDomain("*");

                Font.registerFont(F9471cf2d10924f87820ae61a30dd4b8f);

          }

    }

}

We don't have a collection of these fonts to store an any libraries before hand.  This is all dynamically generated content, so we need to be able to download and register fonts on demand, without any beforehand knowledge of the font.
I'll do some reading on "embedded library symbols".  I'm not exactly sure what that is referring to.  Do you think it would be a possible solution?
Eric

Participating Frequently
July 7, 2011

Hi Eric,

for one reason I think your current solution could not work: it loads on-demand server created Flash movie (.swf) which contains ActionScript - on iOS there is no runtime and loaded content cannot contain ActionScript at all:

http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118a9b90204-7e13.html

(very first paragraph about iOS). This not exclude option of different implementation as I'm not familiar with iOS ADT to such extent to know created content fonts limitations (except of that first documentation link),

regards,

Peter