Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 09-06-2006, 03:55 PM   #1
ven
Registered User
 
Join Date: Mar 2006
Posts: 41
Default Projects fonts in AS 3.0

Earlier in my projects, I have used the Flash IDE and the options "Anti-alias for readability" and "Bitmap text (no anti-alias)". This have worked excellent in Flash 8.

Now in AS 3.0 I want to replicate these features with a codeapproach, which havent been an easy task sofar, and there is not much information on the web about this. At the same time the examples in the Flex 2 documentation full of errors. (i.e. the one at TextRender)

My apologies if this thread is similar to the one i posted some days ago, but this is so much more in depth (and maybe despreate ), and i couldnt edit the title in it, so i requested a delete on it.


Here is some approaches that i have tested, and only gotten sofar with:

1: Embedding TTF fontfiles into the main swf
2: Embedding Flash 8 SWFfile with fonts into the main swf
3: Sharing fonts from Flash 9 Beta IDE
4: Used CSMSettings on the fonts ive been able to get into advanced antialiasing


What do i want to achieve?

- Crisp nonantialised fonts (but can be embeded as outlined fonts like bitmap text.
- Advanced antialiased fonts
- Formatable (bold, italic, the usual htmlformatting)
- Can be masked
- Fonts included in swf, to ensure the correct font is viewing



What is the problems? Well there are several, but the biggest issues afaik:

- I cant seem to use fontFamily with embedded fonts, so they wont get formatted with i.e. htmlText <b> <i> etc.

- I have this theory that i can replicate "Bitmap text" with the manipulation of CSMSettings. However, allthough ive been able to apply CSMSettings, i seems to ignore the values i set in insideCutoff and outsideCutoff. It always looks the same.

I have uploaded a rar-file with the files ive experimented with.



Here is code used, if anyone should want to just browse it quickly:
PHP Code:
package {
    
    
/* Members */
    
import flash.display.*;
    
import flash.text.*;
    
    
/* Movie settings */
    
[SWF(width="800"height="600"frameRate="50"backgroundColor="#FFFFFF")]
    
    
/* Class */
    
public class BitmapAlias extends Sprite {
        
        
/* Embed TTF-fonts*/
        
[Embed(source="verdana.ttf"fontName="_verdana_regular"fontFamily="_verdana")]
        public var 
verdanaClass:Class;
        [
Embed(source="verdanab.ttf"fontName="_verdana_bold"fontFamily="_verdana")]
        public var 
verdanaBoldClass:Class;
        [
Embed(source="verdanai.ttf"fontName="_verdana_italic"fontFamily="_verdana")]
        public var 
verdanaItalic:Class;
        [
Embed(source="verdanaz.ttf"fontName="_verdana_bold_italic"fontFamily="_verdana")]
        public var 
verdanaBoldItalicClass:Class;
        
        
        
/* Embed a font for CSMSetting manipulation */
        
[Embed(source="verdana.ttf"fontName="_verdana_CSM"fontFamily="_verdana_fam_CSM")]
        private var 
verdanaCSMClass:Class;
        
        
        
/* Embed fonts through Flash 8 as shown on:
        http://livedocs.macromedia.com/flex/2/docs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00000795.html */
        
[Embed(source="_verdana.swf"fontName="Verdana")]
        public var 
verdanaFromSWF:Class;
        
            
        
/* Properties */
        
private var fontFamily:String "_verdana";
        private var 
fontName:String "_verdana_regular";
        private var 
myFormat:TextFormat;
        private var 
myTextfield:TextField;
        private var 
i:int;

        
        
/* Constructor */
        
public function BitmapAlias() {
            
i++;
            
            
            
            
/***\
            * Using fonts from TTFfile:
            \***/
            
            
var toggleTTFFont:String fontName;
            
//toggleTTFFont:String = fontFamily;
            
            
            /* No anti-alias, no outline */
            
var deviceTitle:TextField createTitleField("From TTF: Device (no embed):");
            var 
deviceField:TextField createTextField(toggleTTFFont);
            
i++;
            
            
/* Plain anti-alias */
            
var embedTitle:TextField createTitleField("From TTF: Embed:");
            var 
embedField:TextField createTextField(toggleTTFFont);
            
embedField.embedFonts true;
            
embedField.antiAliasType =  AntiAliasType.NORMAL;
            
i++;
            
            
/* Anti-alias advanced */
            
var embedAdvancedTitle:TextField createTitleField("From TTF: Embed Advanced:");
            var 
embedAdvancedField:TextField createTextField(toggleTTFFont);
            
embedAdvancedField.embedFonts true;
            
embedAdvancedField.antiAliasType =  AntiAliasType.ADVANCED;
            
i++;
            
            
/* Anti-alias with CSMSettings applied */
            
var embedCSMTitle:TextField createTitleField("From TTF: Manipulated by CSMSettings:");
            var 
embedCSMField:TextField createTextField("_verdana_CSM");
            
embedCSMField.embedFonts true;
            
embedCSMField.antiAliasType =  AntiAliasType.ADVANCED;
            var 
antiAliasEntry:CSMSettings = new CSMSettings(123, -1);
            var 
verdanaTable:Array = new Array(antiAliasEntry);
            
TextRenderer.setAdvancedAntiAliasingTable("_verdana_CSM"FontStyle.REGULARTextColorType.DARK_COLORverdanaTable);
            
i++;
            
            
            
            
/***\
            * Using fonts from SWFfile:
            \***/
            
            
i++;
            var 
toggleSWFFont:String "Verdana";
            
            
            
            
/* Plain */
            
var deviceSwfTitle:TextField createTitleField("From SWF: Device: (This will use the systemfont *if* its installed, else nothing)");
            var 
deviceSwfField:TextField createTextField(toggleSWFFont);
            
i++;
            
            
/* Embed normal */
            
var embedSwfTitle:TextField createTitleField("From SWF: Embed");
            var 
embedSwfField:TextField createTextField(toggleSWFFont);
            
embedSwfField.embedFonts true;
            
embedSwfField.antiAliasType =  AntiAliasType.NORMAL;
            
i++;
            
            
/* Embed advanced */
            
var embedAdvancedSwfTitle:TextField createTitleField("From SWF: Embed advanced");
            var 
embedAdvancedSwfField:TextField createTextField(toggleSWFFont);
            
embedAdvancedSwfField.embedFonts true;
            
embedAdvancedSwfField.antiAliasType =  AntiAliasType.ADVANCED;
            
            
            
/* Toggle CSM settings for Verdana anti-aliased text. It results in another
            type of result then CSMSettings for the TTF-font */
            
            //var antiAliasEntrySWF:CSMSettings = new CSMSettings(50, 10, -10);
            //var verdanaTableSWF:Array = new Array(antiAliasEntrySWF);
            //TextRenderer.setAdvancedAntiAliasingTable("Verdana", FontStyle.REGULAR, TextColorType.DARK_COLOR, verdanaTableSWF);
            
            
i++;
            
            
        }
        
        
/* Methods */
        
public function createTextField(fnt:String):TextField {
            var 
field:TextField = new TextField();
            
field.defaultTextFormat getTextFormat(fnt);
            
field.border true;
            
field.i*20i++;
            
field.30;
            
field.width 300;
            
field.height 20;
            
field.htmlText "Lorem <b>ipsum</b> dolor <i>sit</i> amet";
            
addChild(field);
            return 
field;
        }
        public function 
createTitleField(ttl:String):TextField {
            var 
field:TextField = new TextField();
            
field.i*20i++;
            
field.30;
            
field.width 500;
            
field.height 20;
            
field.text ttl;
            
addChild(field);
            return 
field;
        }
        public function 
getTextFormat(fnt:String):TextFormat {
            var 
format:TextFormat = new TextFormat();
            
//format.bold = true;
            
format.font fnt;
            
format.size 12;
            return 
format;
        }
    }


Here is the result swf


Is what im trying to do impossible? Ive been working two weeks with this now, searching everywhere on the web and im running out of ideas on how to try new things and wich searchterms to use...
ven is offline   Reply With Quote
Old 09-07-2006, 02:20 AM   #2
blockage
Senior Member
 
blockage's Avatar
 
Join Date: Jan 2005
Posts: 476
Default

Not sure this quite what you wanted but it might give you another angle. I've managed to get bitmap fonts into my Flex 2 projects by embedding textFields (with fonts set to bitmap) into a Flash 9a swf and then loading it at run time (with a Loader). To get at each textField with AS I also have to declare them in the loaded swf's document class and recast the loader.content object to the same class; or cheat and use bracket access.
blockage is offline   Reply With Quote
Old 09-07-2006, 12:19 PM   #3
ven
Registered User
 
Join Date: Mar 2006
Posts: 41
Default

Fresh angels are always good

Your method works excellent, except that i need to duplicate the TextField that is loaded (or duplicate the imported TextField-instance settings somehow to the textfields created).

PHP Code:
private function onMovieComplete(event:Event):void {
    var 
myLoadedMovie:MovieClip movieLoader.content as MovieClip;
    
myLoadedMovie.mask setTextMask();
    
addChild(myLoadedMovie);
    
myLoadedMovie.myTextField.htmlText "<b>Hello</b> <i>World</i>";

The example above returns either bitmap text or advanced anti-aliased fonts (depending on the formatting i set in the source swf) as "Hello World". I can mask it, format it and addChild the textfield where i want etc.
ven is offline   Reply With Quote
Old 09-07-2006, 01:19 PM   #4
Tink
Addict
 
Tink's Avatar
 
Join Date: Nov 2001
Location: London
Posts: 2,128
Default

http://livedocs.macromedia.com/flex/...=00000796.html might be useful
Tink is offline   Reply With Quote
Old 09-07-2006, 01:43 PM   #5
blockage
Senior Member
 
blockage's Avatar
 
Join Date: Jan 2005
Posts: 476
Default

I think the core of Ven's problem is, you can't get at all text rendering options using actionscript or mxml. There's no code option for embedding fonts as bitmap text for example. Also, in the test that I ran - when I tried to follow the livedocs example, but set the text rendering to "bitmap" in the flashtype.swf's textFields, embedding the swf fails.
blockage is offline   Reply With Quote
Old 09-07-2006, 01:51 PM   #6
blockage
Senior Member
 
blockage's Avatar
 
Join Date: Jan 2005
Posts: 476
Default

To get around the duplication - one option might be to use a single loaded textfield which you use as an off screen buffer and then gerenerate bitmapdata (textsnapshot?) to display the actually text? The text wouldn't be selectable but would be really fast for animation...
blockage is offline   Reply With Quote
Old 09-07-2006, 03:04 PM   #7
ven
Registered User
 
Join Date: Mar 2006
Posts: 41
Default

I have managed to get duplication of textfield working now with help of senoculars examples at kirupas.

duplicateDisplayObject


much much love to everyone <3

ill make an example tomorrow
ven is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
TextArea, CSS, Embedding Fonts high1memo Components 30 03-31-2010 12:08 PM
CSS and embedded fonts montey ActionScript 2.0 10 12-24-2004 09:07 AM
Fonts Help!!! lilp ActionScript 1.0 (and below) 3 12-06-2004 09:48 PM
Can fonts be populated in a combox box from the server ?? khushru20 ActionScript 2.0 0 07-31-2004 04:32 AM
Fonts and Mac OS X? :confused: mcdanyel General Chat 7 10-05-2002 05:40 AM


All times are GMT. The time now is 09:15 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.