Sunday, December 2, 2007

Impossible is nothing

Lately I have been doing some flash. I made a happy, decently complex, flash app, with a total size of 10KB. Pretty neat so far. Now a tiny new feature which needed to rotate texts was needed. Apparently TextFields wont rotate (and scale) without embedding fonts. Even a single small font would be atleast 80-100KB. Stuck.....

Interestingly flash let's you paint programmatically. Which means whatever you can show on screen can be rendered onto a Bitmap at runtime. This struck a solution..
var text:TextField = new TextField();
text.text = "Hello World";

var bmp:BitmapData = .......
bmp.draw(text);

So now you have the text as image. Next thing we do draw a rectangle and this time filling it using the image.

graphics.beginBitmapfill(bmp);
graphics.drawRect(0, 0, magic_width, magic_height);

Ofcourse nothing stops us from rotating this shape (there is no text now) and hence ending up rotating the text. You still need the magic numbers to get the right dimensions, I did that constructing a boundary around black pixels in the image.

The text though looks a bit shady, but its an OK compromise. Hopefully I will get that right too. Now no more restriction on fonts I can use and the texts shall rotate :).

Well, the point here is that we do work :D, and hence get stuck, pretty often. The thing to remember is "impossible is nothing".

J.

2 comments:

Nikhil Rao said...

good job harsh. what's the flash for? when do you go beta? :)

Harsh Jain said...

far from beta my friend.. these are just for some internal tools.