Archive for June, 2008

Font detection with Javascript and Flash

Thursday, June 26th, 2008

I was playing around with jquery and I wanted to see if it was possible to generate a cheat sheet of all the fonts on your system. Its also a good run through of how to load a SWF with a callback.

View a demo (Though, its possible it might not work)

The steps I used to generate this are:

  • Load SWF
  • Javascript calls to Actionscript fonts() method via ExternalInterface
  • Get the list of system fonts in Flash via Font.enumerateFonts(true)
  • Curse Flash for giving you a list of font names, where half of them are garbage.
  • For each font name, in javascript, create a test which adds a DOM element temporarily with a fallback font family set. For example, font-family: 'Apple Garamond Pro', 'Times New Roman';, where Times New Roman is your fallback.
  • Then check the actual width (via offsetWidth). If it does not match the offsetWidth of the fallback font, then we know it rendered ok. (The original idea is from http://www.lalit.org/lab/javascript-css-font-detect)

The only caveat is, if the actual font width and the fallback font width do match, then you would have a false negative. So its not bulletproof.

The actionscript to enumerate the fonts and call back out is pretty simple:

Expose the method in the constructor using ExternalInterface:

FontList.as

I used swfobject to load the SWF. Also be sure to enable allowScriptAccess.

The javascript to test the fonts is at: font-detect.js

You can use it by including:

In the end, I don’t think this is useful in practice, but I thought I would share anyway. Its on github too.

Updated: Now uses call straight to actionscript, doesn’t marshall JSON first so its much faster, and other refactoring.

S3Hub: S3 Client for Mac OS X

Monday, June 16th, 2008

I’ve been looking for an Amazon S3 client for the Mac for awhile, that had a couple key features that seem to be missing from apps like Cyberduck or Transmit. Mostly I wanted a better way to manage permissions and make it easier to share files with my friends, and I needed something to throttle my bandwidth so I can leave beefier transfers running without nuking my Gears of War latency.

S3Hub (left)

You can download it over at: http://s3hub.com

And, also, its an excuse to do some Cocoa again now that Objective-C 2.0 is out. Garbage collection, declarative properties, and fast enumeration help remove a lot of cruft and let you focus more on making things work. Also there are alot of new and really nice API’s in Leopard like NSOperationQueue.

S3Hub (right)

A major feature I don’t have yet is sync’ing (syncing is hard); but I think that should come in the next version hopefully. I have some ideas about generating rss feeds or some way to track new files which I think could be really useful. If you have any ideas or find any bugs, leave a post on the group.

Time ago in words for Cocoa

Monday, June 9th, 2008

I ported the time_ago_in_words helper for to a category (mixin) for NSString. Its nothing profound but I couldn’t find it anywhere.

Update: Moved to github and is part of GHKit. You can find this helper: GHNSString+TimeInterval.m