Autoadjust fontsize to a rectangular boundry


/ Published in: ActionScript
Save to your folder(s)



Copy this code and paste it in your HTML
  1. class nl.mopics.utils.AlignFunc
  2. {
  3.  
  4. public static function autoAdjustFontSize2Rect( txt:String, tff:TextFormat, desiredSize:Number, minimumSize:Number, tf:TextField, rect:Rectangle ):Void
  5. {
  6. tf._x = rect.x;
  7. tf._y = rect.y;
  8. tf._width = rect.width;
  9. tf.multiline = true;
  10. tf.autoSize = true;
  11. tf.text = txt;
  12. tff.size = desiredSize;
  13. for( var s:Number = desiredSize; s>minimumSize; s-- )
  14. {
  15. if( tf._height < rect.height )
  16. {
  17. break;
  18. }
  19. tff.size = s;
  20. tf.setNewTextFormat( tff );
  21. tf.text = txt;
  22. }
  23. }
  24.  
  25. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.