Text Layout Framework memory leak

Shortly before I flew to Abu Dhabi for Cityscape, I found a memory leak in the AIR application I’d been developing for the past few months. As with most memory leaks it only became apparent after several hours of usage, and given the application had to run at least 10 hours a day, was a serious problem.

Thankfully, Flex Builder has a profiler tool built-in, and leaving my application running for hours in the profiler revealed the rapid accumulation of instances of a mystery class TextAccImpl, which it’s package structure revealed was part of the new Text Layout Framework.

This was more problematic than you may imagine, as not only is the TLF still in beta, but was an integral part of my application as it gave us the ability to switch seamlessly between English and Arabic.

After spending time tweaking my code to check if I was using the API incorrectly, it became apparent it was a bug in TLF itself. Googling didn’t find anything, so I resorted to the official TLF blog, where I noticed a post announcing they were releasing weekly builds to their Adobe Labs download page.

As I was compiling against the version of TLF that came with the Flex 4 MAX Preview, I decided to upgrade by adding the latest weekly build (411 at that time) as an external library to my project. After making the necessary changes to my code to reflect the API changes they’d made, I left my application running in the profiler overnight and to my relief the bug had been fixed.

If anyone is experiencing dramatic degradation of performance over time after adding the TLF to your application, I’d recommend you upgrade to the latest weekly build.

This was posted 2 years ago. It has 0 notes.

Embedded fonts and the Text Layout Framework

Adobe’s Text Layout Framework, in combination with the new text engine in Flash Player 10, is finally giving Flash developers the kind of typographic control we’ve needed for years. Feature highlights include bi—directional and vertical text, support for over 30 writing systems, flowing text across multiple columns and vastly improved character formatting including kerning, ligatures and typographic case. While a few tutorials on it have been appearing in the last few days, notably Using the Text Layout Framework in Flex 3.2 and AIR 1.5, there’s still a lack of information on how to use embedded fonts which as we all know is necessary if you want to use non-standard fonts or tween the alpha property of your text.

Flex 4 SDK / Flash Professional CS4

From the Text Layout Framework release notes;
DefineFont4 is a new embedded font format used by the new text engine in Flash Player 10 providing improved typography, international support and reduced font size. The new text engine does not support any of the previous SWF embedded formats such as DefineFont3 generated by Flash CS3 Professional or Flex 3. You will have to use Flash CS4 Professional or Flex Gumbo to embed fonts using the DefineFont4 format.
This means that to use embedded fonts with the TLF, you have to use either the Flex 4 (“Gumbo”) SDK, which is currently still in Beta, or Flash Professional CS4.

Moving to Flex 4 SDK

If you’re currently using the Flex 3 SDK and want to move to Flex 4, there’s a handy tutorial on the Flex Examples blog, Using the beta Gumbo in Flex Builder 3. A word of warning is that several of the nightly builds and the latest stable build refuse to run on OS X. I wasn’t alone with this problem, both Richard Leggett and Aral Balkan have been bitten too as you’ll see in the comments on Richard’s blog post, Upgrading Flex 3/AIR Projects to Gumbo/Flex 4. For the time being, I’m using the Adobe MAX preview (build 4.0.0.4021) version.

Embedding fonts

Here’s an example of how to embed a font in AS3, the important new part to notice is the cff="true", which is a reference to the Compact Font Format required by the new text engine.
package com.cameronyule.fonts
{
	import flash.text.Font;

	public class AFont extends Font 
	{
		[Embed(source="/path/to/fonts/AFont.ttf", fontFamily="AFont", cff="true")]
		private var _a_font:String;

		public static const NAME:String = "AFont";

		public function AFont() 
		{
			super();
			_a_font;
		}
	}
}

Using your embedded fonts

There are two main ways to use the Text Layout Framework, TextFlows and TextLines. TextFlows are better for larger blocks of text while TextLines are good for single lines of text. The most important part is actually the character formatting, so while this example uses TextLines you’ll be able to easily transfer it to TextFlows as well.
private function createTextLine(someText:String):void
{	
	var bounds:Rectangle = new Rectangle(10, 10, this.width, this.height);

	var paragraphFormat:ParagraphFormat = new ParagraphFormat();
	paragraphFormat.direction = Direction.LTR;

	var characterFormat:CharacterFormat = new CharacterFormat();
	characterFormat.fontSize = 18;
	characterFormat.fontFamily = AFont.NAME;
	characterFormat.fontLookup = flash.text.engine.FontLookup.EMBEDDED_CFF;
	characterFormat.renderingMode = flash.text.engine.RenderingMode.CFF;

	TextLineFactory.createTextLinesFromString(addTextLineToContainer, someText, bounds, characterFormat, paragraphFormat);
}

private function addTextLineToContainer(textLine:flash.text.engine.TextLine):void
{
	this.addChild(textLine);
}
And there you have it, embedded fonts using the new Text Layout Framework.

This was posted 2 years ago. It has 0 notes.

Myrin (Jar City)

ingvar

I watched the Icelandic film Mýrin tonight and it was superb.

Based on a novel by Arnaldur Indriðason, it follows the policeman Erlendur as he and his colleagues try and solve the seemingly motiveless murder of a man in his home. As with all good examples of the genre, the plot evolves throughout the film and involves opening old wounds in closed cases and a recurring connection to an inherited genetic disease.

Despite his appearance - he’s rarely without a cardigan - Erlendur can be tough when needed, as seen in his confrontations with the violent skinhead Elliði and later when some enforcers for a local drug dealer try to break into his home.

With a drug-addicted, pregnant, daughter and no social life, it’d be easy to assume the brooding atmosphere was present throughout the entire film, but there’s a few rare moments of black humour, particularly in the back and forth dialogue with his partner Sigurður.

The cinematography and music are breathtaking, making the vast Icelandic landscapes simultaneously beautiful and bleak while only intensifying the sense of foreboding and helplessness.

Here’s hoping we get to see more of Erlendur and his cardigans soon.

This was posted 3 years ago. It has 1 note.

The importance of to-do lists

I’ve accomplished more in the past two days than I have the last few weeks combined. Thanks to using up my holiday allowance before the year end, I found myself with two spare days and managed to clear a backlog of miscellaneous stuff that’s needed doing for ages.

You see, I’ve had a re-introduction to the awesome power of the To-do List.

Using nothing more than a tiny Muji notepad, pen and a little forward planning I wrote a list of the things I wanted to get done each day. The motivational power of having a plan (Heath Ledger’s Joker would love that) is incredible, with the feeling of accomplishment as you cross things out encouraging you to do more.

Amusingly, the use of to-do lists is one of the core concepts in David Allen’s Getting Things Done, which has sat unread on my desk for at least a year… a victim of my time management on things I decide are non-essential.

Thanks to the success I’ve had with the simple paper and pen lists, I’m going to apply the same approach at work. I’ll follow up in the comments and let you know how it goes - fingers crossed!

This was posted 3 years ago. It has 1 note.

Archiving large files across multiple DVDs

I was backing up our SVN repositories to DVD a while ago and wrote an entry on our wiki detailing how I’d done it. Thinking this is the kind of thing people will have to do at some point I thought it could be useful to share. The method I’ve used is to create a single tar file of everything you’re looking to backup and then split that file into chunks which fit onto a single DVD.

Install GNU Core Utilities

Before we start, you’re going to need gsplit installed. This comes as part of the GNU Core Utilities package, so you can either download it from there or use your favourite package management software. You can either build from source,
wget http://ftp.gnu.org/gnu/coreutils/coreutils-6.9.tar.gz
tar xzvf coreutils-6.9.tar.gz
cd coreutils-6.9
./configure
make && make install
Or use a package management tool like MacPorts.
sudo port install coreutils

Split your content into chunks

Put all the files you want to backup into one folder, create the tar achive and then split that into chunks.
mkdir archive
# … add some content to the archive/ folder …
cd archive
tar -cvf archive.tar *
gsplit -b4500m archive.tar
After you’ve burned each generated file to a DVD, delete both those and the source archive.tar file as they’ll be using quite a lot of space on your drive.

Restoring

Should the worst happen and you need to get your content back, copy all the files from across your DVDs to a folder on your machine and run the following.
cat x* > archive.tar
tar -xvf archive.tar

This was posted 3 years ago. It has 0 notes.

Taking regular breaks

I’ve always been on the lookout for a small application to remind me to take regular breaks from my computer, as it’s easy to get totally involved in what you’re doing and lose track of time.

The few I’ve found in the past have always had their problems, from terrible interfaces to being overly intrusive - think alarm calls and locking the computer. Thankfully I’ve found the perfect app for the task - AntiRSI.

As well as reminding you to take breaks, it’s small, unobtrusive and highly configurable. As an added bonus it even takes idle time into account so if you’ve told it you want to take 5 minute breaks each hour and leave the machine idle, the counter for your next break will adjust appropriately, clever!

This was posted 3 years ago. It has 0 notes.

Ladytron — Shepherds Bush Empire

I’ve seen Ladytron once before, about four or five years ago at the GUU and it was one of my most disappointing gigs. Terrible performance, restless crowd and a fire alarm going off midway through their set that dumped us all outside in the rain.

The reason I’ve given them another chance was that after years of promise they’ve finally delivered an album that proved they were capable of more than just the occasional decent song. The album, Velocifero, may not be perfect but it’s one of the best from what’s been a disappointing year for music.

Support was from the fantastic shoegaze/pop band Asobi Seksu, whose album Citrus I’ve been enjoying for what seems like forever. Thanks to the London trains running behind we only caught their closing song, but it made a big impression with loads of chaotic noise. It gave some extra life and kick to music that can occasionally sound lightweight and I’ll definitely be going to see a full gig by them when I get the chance.

Ladytron came on about half an hour later and things didn’t start well with the vocals being so low in the mix that they were - unintentionally - unintelligble. This carried on for the first three or four songs until someone finally realised and brought the drums down to a reasonable level. Unfortunately it was too little too late and from where I was standing the band had already lost the crowd.

That’s not to say there weren’t any highlights, but they were few and far between. Old favourite Seventeen was good and a few of the newer songs towards the end of their set were also decent, but it wasn’t enough to salvage what on reflection was a pretty awful gig.

This was posted 3 years ago. It has 0 notes.

Configuring MySQL to use UTF-8

A project I’m working on at the moment is going to have multiple language options available, not all of which use the same alphabet (e.g. Russian and Chinese). To lessen the pain commonly associated with internationalisation on the web, it’s beneficial to use the UTF-8 character set. This short summary from the Unicode Consortium may help explain better;

Unicode provides a unique number for every character, no matter what the platform, no matter what the program, no matter what the language. … Unicode enables a single software product or a single website to be targeted across multiple platforms, languages and countries without re-engineering. It allows data to be transported through many different systems without corruption.
Thankfully MySQL has supported Unicode for quite some time now, even if it’s not configured to use it by default. First, let’s check what our settings are at the moment;
mysql> SHOW VARIABLES LIKE 'collation%';
+----------------------+-------------------+
| Variable_name        | Value             |
+----------------------+-------------------+
| collation_connection | latin1_swedish_ci |
| collation_database   | latin1_swedish_ci |
| collation_server     | latin1_swedish_ci |
+----------------------+-------------------+
3 rows in set (0.01 sec)
mysql> SHOW VARIABLES LIKE 'character_set%';
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | latin1                     | 
| character_set_connection | latin1                     | 
| character_set_database   | latin1                     | 
| character_set_filesystem | binary                     | 
| character_set_results    | latin1                     | 
| character_set_server     | latin1                     | 
| character_set_system     | utf8                       | 
| character_sets_dir       | /usr/share/mysql/charsets/ | 
+--------------------------+----------------------------+
8 rows in set (0.00 sec)
That’s to be expected, but it’s not really what we wanted. Find your MySQL configuration file (on most Linux/BSD systems it’s /etc/my.cnf) and make sure it’s got the following statements under the relevant headers.
[mysqld]
default-character-set=utf8
default-collation=utf8_general_ci
character-set-server=utf8
collation-server=utf8_general_ci
init-connect='SET NAMES utf8'

[client]
default-character-set=utf8
Restart MySQL and make sure it’s working;
service mysql restart
mysql> SHOW VARIABLES LIKE 'collation%';
+----------------------+-----------------+
| Variable_name        | Value           |
+----------------------+-----------------+
| collation_connection | utf8_general_ci | 
| collation_database   | utf8_general_ci | 
| collation_server     | utf8_general_ci | 
+----------------------+-----------------+
3 rows in set (0.00 sec)
mysql> SHOW VARIABLES LIKE 'character_set%';
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       | 
| character_set_connection | utf8                       | 
| character_set_database   | utf8                       | 
| character_set_filesystem | binary                     | 
| character_set_results    | utf8                       | 
| character_set_server     | utf8                       | 
| character_set_system     | utf8                       | 
| character_sets_dir       | /usr/share/mysql/charsets/ | 
+--------------------------+----------------------------+
8 rows in set (0.00 sec)
Update; Mo pointed out that it’s worth demonstrating setting the charset and collation when creating tables too (good point!).
CREATE TABLE `content` (
  `id` int(11) NOT NULL auto_increment,
  `language` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  `title` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL default '',
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_general_ci;

This was posted 3 years ago. It has 0 notes.

Testing is overrated

But the truth is, no single technique is effective at detecting all defects. We need manual testing, peer reviews, usability testing and developer testing (and that’s just the start) if we want to produce high-quality software.
Ignoring the (playfully) sensational headline, this is an insightful quote from a good article on not overstating the importance of automated testing at the expense of other QA techniques. Informal design and code reviews is something I’d love to introduce at work, as I firmly believe they’d not only increase the quality of the end product but also our skills as individual programmers. Testing is overrated at Rails Spikes.

This was posted 3 years ago. It has 0 notes.

My Bloody Valentine

Went to see My Bloody Valentine at the Barrowlands with Sarah and my ears are still recovering. The following video is from a section of the gig that came in the middle of their last song, and is called ‘the holocaust’.    

This was posted 3 years ago. It has 0 notes.