Rodney Pillay's Blog

Just another WordPress.com site

FontSwf Utility in FLEX SDK 4

with 3 comments

I came across fontswf.bat while going through the flex bin directly and realized that this will be a very useful tool especially to those that use embedded fonts.

fontswf.bat is just a wrapper for flex-fontkit.jar which exists inside the Flex SDK 4 lib folder, and being a windows user, I appreciate the batch file 🙂

Usage
The usage is fairly simple and running fontswf.bat without any parameters will display a list of options, but let me try and expand on it and give a working example.

Options

-a, -alias [name] – set the font alias (defaults to font family)
The alias is the name that you will reference the font by inside your AS3 application.

-b, -bold – treat the font as bold
If you use this option and the font supports bold, you will be able to use the font as regular and bold.

-i, -italic – treat the font as italic
If you use this option and the font supports italic, you will be able to the font as regular and bold.
If you choose both -i and -b, and the font supports both options then you will be able to use the font as regular, bold, italic, regular-italic and bold-italic.

-o, -output (file path) – specify the SWF output file path

-u, -unicode-range (range) – set a unicode character range (default is ‘*’ which includes all characters)
If you want to embed all glyphs, don’t use -u, the utility will automatically embed everything.

-3 – generate DefineFont3 SWF tag
If you are using the original Flash TextField then you have to use DefineFont3

-4 – generate DefineFont4 SWF tag (default)
If you are using Vellum components then you have to use DefineFont4 (Gumbo components use Vellum)

Check out this article for a deeper look at DefineFont3 and DefineFont4

Example
Assuming that I am using the original TextField, I have a directory myfonts on my c drive and I want to embed the Comic Sans MS font.

Create myComicFont.swf
Copy the target font from your windows fonts folder into your myfonts directory.

C:\flex_sdk_4\bin>fontswf -3 -a myComic -o c:\myfonts\myComicFont.swf C:\myfonts\Comic.ttf

you will now notice a myComicFont.swf created inside your myfonts directory.

Now, you can either embed the font swf or load it at runtime

Sample AS3 code embedding and using the font swf

package
{
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.text.Font;
    import flash.text.TextField;
    import flash.text.TextFieldAutoSize;
    import flash.text.TextFormat;

    public class Main extends Sprite
    {

      public function Main():void
      {
        if (stage) init();
        else addEventListener(Event.ADDED_TO_STAGE, init);
      }

      [Embed(source="C:\\myfonts\\myComicFont.swf",      symbol="myComic")]
      private var _fontClass:Class;

      private var _alias:String = "myComic";

      private function init(e:Event = null):void
      {
        removeEventListener(Event.ADDED_TO_STAGE, init);

        Font.registerFont(_fontClass);

        var tf:TextField = new TextField();
        tf.defaultTextFormat = new TextFormat(_alias);
        tf.embedFonts = true;
        tf.autoSize = TextFieldAutoSize.LEFT
        tf.text = "The quick brown fox jumps over the lazy dog. 1234567890";

        addChild(tf);
      }
    }
}
Advertisements

Written by rodneypillay

May 18, 2010 at 11:14 AM

Toast : To Ruth First

Born to Jewish immigrants that founded the South African Communist Party, she grew up in a household full of intense political debate between people of all races and classes.

She attended the University of Witwatersrand, majoring in social studies. At the time the university allowed a small group of black students, and her fellow students included Nelson Mandela, Joe Slovo, JN Singh and Ismail Meer.

As a journalist she concentrated her efforts to the woman’s anti-pass campaign and the slum conditions of most townships. She also supported the mineworkers strike in 1946 and the Indian passive resistance campaign.

In 1953 she helped found the Congress of Democrats, the white wing of the Congress Alliance and became the editor of “Fighting Talk”, a journal supporting the alliance. She was on the drafting committee of the freedom charter but her banning order prevented her from attending.

In 1963 during the Rivonia trial, although she was not an accused, she was put into solitary confinement for 90 days, during which she attempted suicide.

When she was released she went into exile and campaigned from Britain. In 1977 she was given the post of professor and research director at Eduardo Mondlane University in Maputo, It is here that she was assassinated by the South African Police… they used a letter bomb.

I have been asked many times… “Who is she and why has the M4 been renamed”

She was a freedom fighter, who died for her beliefs and never got to see her good friend Nelson Mandela be inaugurated on this day(10th May) in 1994

She was a liberator of women

And a leader of Men

Please stand as we raise a glass

To Ruth First

Written by rodneypillay

May 11, 2010 at 7:13 AM

Posted in Toast Masters, Toasts

Speech : An Apple A Day Takes Your Choice Away

The ideal tyranny is that which is ignorantly self-administered by its victims. The most perfect slaves are, therefore, those which blissfully and unawaredly enslave themselves. (Dresden James)

Good evening to the Chairman and fellow toastmasters.

On January 9th 2007, Steve Jobs, the CEO of Apple announced that the Iphone was coming. In the beginning of June of the same year he announced that 3rd parties would be able to write web 2.0 applications for the device. By the end of the month, Iphones went on sale but only through an AT&T contract or by using your credit card, you where being locked down and tracked from the start. Today, with over 200 000 applications in the Apple App Store, it may seem as though your choices, for what you can install on the device which you paid over R6000 for, is limitless, but in fact its limited to what Apple thinks you want.

There are tons of applications that get reject by Apple, and there are multiple reasons which they give, applications are too similar to current ones in the store, applications do not adhere to any number of moral standards or they just don’t think that the application is what their store needs. As of a few weeks ago there were a few more clauses added to the Apple legislation otherwise known as their SDK license agreement but let me first tell you why Apple’s application rejection is a slap in the face for developers and Apple device users.

Firstly, and it’s a kicker, developers actually pay Apple to develop for their devices. It’s a $99 a year fee and I am one of the suckers, without the SDK license fee, you will not be able to get your application into the Apple Store so developers are forced to adhere. So here I am paying Apple, I write an application which lets say take about 2 months to develop, and then it gets rejected. That can’t be right! I don’t even have the opportunity to make the application freely available in the market. So the developer has no choice but to walk away and continue trying until Apple approves.

Secondly there’s the consumer, why is Apple rejecting applications before the consumer see’s it. Surely it’s up to the consumer to decide what they want and don’t want. Apple does not work that way, they know what’s right for you, you are just a dumb device user, a drone that see’s what they want you to see and do what they want you to do.

Let’s look at an extreme case of an application rejection, a porn application. Apple has declared that it is the moral police of the internet and it will not allow any pornographic material on its devices, but why is Apple taking this stance, does it not think that people may want to view porn on their devices or are they protecting people who are unaware that something like pornography exists. So some of you out there might be agreeing with Apple’s decision not to put porn in Store, you might have kids or you might have bought your grandmother a device. But what if Apple came out and told you that porn will be available in the Store and there will be a parental guidance system and that you will be able to tailor your profile to what you can view and download and they also have a mechanism in which you can download a porn application and password protect it. Would you now be more open to porn being available, but Apple is not giving you that choice, Apple is telling you not only that they know what you want but that they don’t believe that you can make parental or any other moral decisions

As mentioned earlier, Apple amended their license agreement a few weeks ago and there has been a huge outcry from the development community. The reason for the change is because of Innovation on the part of Adobe, Unity3d, Appcelerator and Mono Touch. What these guys are doing is enable developers who do not code in Objective C, which is what the Apple SDK caters for, to code in their native language, ActionScript, C# and Javascript. The language of choice is then compiled to the Apple format for its devices. Now you would think that Apple would be chuffed, more developers equals more applications equals more royalties, but no, the amended license agreement, which you have to sign to get the updated sdk, declares that applications which are originally coded in anything other than C, C++ or Objective C will be rejected. When I first read the amendment, I tweeted “Is Apple a Software development bigot”, they have now taken away the choice of the developer coding in his/her first language whatever that may be. In their amendment, they have segregated those that they believe are worthy and not worthy by language. Apple are portraying themselves as a fascist company led by someone who thinks that he is a technology messiah.

They have also maimed innovation, they have in essence decided that the universal translator is not needed, can u imagine how long a Star Trek movie would be if everything a Klingon said was translated by the linguistics expert. Star Trek officers have a device that when switched on can translate any alien language to English and English to any alien language, it’s much more efficient than you learning all the alien languages or using a manual translator, and this is what the Adobe and others are trying to do, give developers a universal translator.

I’d like to conclude by saying that you have the right to choose, and you will make bad decisions but those where your bad decisions. The one thing we don’t want is the internet to be policed by autocratic companies like Apple and yes, some of my words could be used in some anti-racism speech but if Apple services become mainstream then expect your freedom of roaming the internet to be gone and with that your freedom of choice. Remember that your technology choice’s today determines the direction of innovation, if we choose products sold by a dictator wannabe, then we will only evolve as fast as the dictator wants us to.

(take a bow)

Written by rodneypillay

May 11, 2010 at 7:09 AM