MMD Technical Study
Nic Mulvaney - Huddersfield University 2004
Building The Application (Part 2)
March 10, 2004 (421 Words)

Today I've been looking at getting the font saved. With the structure I built for the outlines I parse the XML file into an object array. This means that it is easier to access the values I need, for example, instead of accessing a variable like this..

XMLFile.firstChild.firstChild.childNodes[0].firstChild.childNodes[45].attributes['glyph'];
I can use something like this..
letter_Obj.glyph

The problem with this method, is that I have to write a function to parse the object back into an XML file, by wrapping the tags around the values into one long string.

The code I wrote had to take into account some special characters without certain properties. Here is a code snippet.

function obj2XML(){

var XMLStr = '<?xml version="1.0" encoding="ISO-8859-1" ?>\n';
XMLStr += ' <ttFont ttLibVersion="2.0b1">\n';
XMLStr += ' <glyf>\n\n';

for (x=0; x<alphabetCount; x++) { // LOOP THROUGH LETTERS

// ASSIGN ALTERNATE DETAILS TO CERTAIN CHARACTERS
if(alphabet[x].letter=='.null'){
XMLStr += '<TTGlyph name=".null"/><!-- contains no outline data -->\n' ;
}else if(alphabet[x].letter=='nonbreakingspace'){
XMLStr += '<TTGlyph name="nonbreakingspace"/><!-- contains no outline data -->\n';
}else if(alphabet[x].letter=='nonmarkingreturn'){
XMLStr += '<TTGlyph name="nonmarkingreturn"/><!-- contains no outline data -->\n';
}else if(alphabet[x].letter=='space'){
XMLStr += '<TTGlyph name="space"/><!-- contains no outline data -->\n';

// FORMAT A LETTER
}else{
if(alphabet[x].miscData){
XMLStr += alphabet[x].miscData+'\n'
}else{
XMLStr += ' <TTGlyph name="'+alphabet[x].letter+'" xMin="'+alphabet[x].xMin+'" yMin="'+alphabet[x].yMin+'" xMax="'+alphabet[x].xMax+'" yMax="'+alphabet[x].yMax+'">\n';
for (y=0; y<alphabet[x].plot.length; y++) {
XMLStr += ' <contour>\n';
for (z=0; z<alphabet[x].plot[y].length; z++) {
XMLStr += ' <pt x="'+alphabet[x].plot[y][z].x+'" y="'+alphabet[x].plot[y][z].y+'" on="'+alphabet[x].plot[y][z].method+'" />\n';
}
XMLStr += ' </contour>\n';
}

// INCLUDE EMPTY ASSEMBLY TAG AND GLUE TOGETHER
XMLStr += ' <instructions><assembly></assembly></instructions>\n'
XMLStr += ' </TTGlyph>\n';
}
}
}
XMLStr += '\n </glyf>\n';
XMLStr += ' </ttFont>\n';
return XMLStr;
}

This needs some refining, as it is a bit slow (but at the moment I am processing 267 letters when I only need 26 of them), it will be faster when I set up a time based loop to run instead of for loops.

For a while, my code would blow up in TTX, the error messages are not that helpful, but I found out that it requires the tags <instructions> and <assembly> in order to work. I began writing the assembly data back into these tags but soon realised it was the Hinting information (Hinting makes fonts display differently at different sizes on screen, pushing pixels around in a grid) and I will not be needing this information for my generated fonts. It would also be impossible to successfully hint these fonts without a very time-consuming manual procedure. Leaving these tags empty, clears the hinting and successfully passes through TTX.

Next Page... "Flash MX2004" »