Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
Locked
0

embedding fonts in AIR 2.7 for iOS

Guest
Aug 12, 2011 Aug 12, 2011

Hi,

this may have been ask several times, but what is the exact / best way to use custom fonts in an iOS app?

It seems, that by using a lot of textfields, the app is not running smooth anymore.

Is there some magic way that will restore performance? And still be able to use custom fonts?

kind regards!

TOPICS
Development
1.5K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Participant , Aug 12, 2011 Aug 12, 2011

The 'magic trick' would be to create bitmaps of the textfields and add these to the display list rather than the textfields.

//container is a sprite that has a textfield added to it.

var bmp:BitmapData = new BitmapData(container.width, container.height);

bmp.draw(container);

var snapshot:Bitmap = new Bitmap(bmp);

snapshot.smoothing = true;

snapshot.cacheAsBitmap = true;

addChild(snapshot);

Hope that helps.

Translate
Participant ,
Aug 12, 2011 Aug 12, 2011

The 'magic trick' would be to create bitmaps of the textfields and add these to the display list rather than the textfields.

//container is a sprite that has a textfield added to it.

var bmp:BitmapData = new BitmapData(container.width, container.height);

bmp.draw(container);

var snapshot:Bitmap = new Bitmap(bmp);

snapshot.smoothing = true;

snapshot.cacheAsBitmap = true;

addChild(snapshot);

Hope that helps.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 07, 2011 Sep 07, 2011

Hi! Just realized that I didn't mark your answer, but that was indeed working! Kinda weard still, I thought using bitmap drawing would be much slower then just using "simple" ready made text field. Anyways...Thnx for the tip!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Sep 16, 2011 Sep 16, 2011
LATEST

Very true...  rendering TFs to bitmaps is faster than rendering TFs directly, even with cacheAsBitmap enabled on the text fields. 

However, cacheAsBitmap helps prevent memory overruns in some cases, as there are hooks in Flash to garbage collect cached bitmaps early, when they are no longer needed (I believe: even setting visible to false on a TF with CAB will cause the bitmap to be garbage collected -- someone might correct me on that).

This more "active" garbage collection can make the difference sometimes, in GPU mode especially, if you are scolling lots of text fields.  In one of my apps, scrolling many bitmaps (rendered TFs) would eventually cause a crash (memory overrun), while scrolling the TFs with CAB enabled was fine.  I also had code to set visible to false on objects whose bounds were no longer within the visible stage area.

Note:  in the code above, unless "snapshot" or a container thereof is scaled, there is no need to use cacheAsBitmap on a Bitmap (you'd be using twice as much memory for nothing).

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines