Mac Format

HOW TO | merge and export the font

-

1 Font name

Select the ‘Generate’ button and click the Code button to open it in the Code Editor window. Just as in the previous button’s script, we start by declaring the global variables outside of the mouseUp handler, so they’re available for the handlers in this script as well: global gFontData, gUUID1, gUUID2, gTheFile . The rest of this work will go inside the mouseUp handler.

The path to the font file we opened is still stored in the gTheFile variable. Let’s extract the file name from the whole path. First tell LiveCode what the ‘itemDelimi­ter’ is so it can tell each folder apart. As in web URLs, it’s the / character, so set the itemDelimi­ter to "/" does the trick. The next line is put the last item of gTheFile into fontName – what you get is just the file name.

2 Merge data

The XML template you downloaded has placeholde­rs in the right places where different bits of data need to be stored. Rather than trying to track down each placeholde­r and replace it one by one, LiveCode’s ‘merge’ function can do the whole thing in one step. The text that’s being ‘merged’ is evaluated, and anything wrapped in double square brackets is replaced with what it refers to in LiveCode, no matter how big or small that might be. For example, ‘[[gUUID1]]’ will be replaced with whatever that named variable happens to contain, and ‘[[field 1]]’ will be replaced with what’s in field number 1 (which is the first field you made, or the bottommost field if you’ve been shuffling things forward and back).

We don’t want to change the template field itself or it’d be no use the next time we want to convert something, so first we need to put field ‘template’ into a variable and use that. Because we don’t need to preserve this data beyond this script’s operation, we don’t need to set it up as a global variable. In fact, if we simply ‘get’ the field rather than putting the field into something, it’ll be stored in that automatic ‘it’ variable: get field "template" .

With the template data in the ‘it’ variable, the next line is simple: put merge(it) into theData places the merged data into a regular temporary variable made on the fly for this purpose. It will be remembered for the duration of this mouseUp script handler, but because it’s an ordinary temporary variable, it is forgotten at the end. That’s fine, because we’ll have written it into a new file on disk by then.

3 Save the font

The ‘ask file’ command opens a file dialog for naming and saving a file – or rather, it allows you to choose where something’s to be saved and what it should be called; the actual saving of data to the file is handled separately. Adding ask file "Save this" with fontName & ". mobileconf­ig" will put what’s in the ‘fontName’ variable there followed by the ‘.mobileconf­ig’ filename suffix, which is necessary for the file to work when opened on an iOS device. Click OK and the full path to the location and file name are stored in ‘it’. Let’s check this was done, then create a file, write ‘theData’ to it, and close it again: if it is empty then exit mouseUp open file it write theData to file it close file it

4 Run the app

When you’ve finished adding the code (and clicked Apply in the Code window) you can try it out on a font. Switch to the Run tool in the Tools palette, type a one-word name in the first field and your full name in the second, then click Choose. Find and select a TrueType or OpenType font (you could download some from google.com/fonts), then click Generate and choose where to save the file. If you get a script error, check your code for errors. Otherwise you’re ready to email the new .mobileconf­ig document to your iPad (or upload it) and open it on the device. You should be taken to the Settings app and asked to authorise installing the font. After this, it’s available to use in apps such as Pages and Keynote. If you want to see examples of readyto-use converted fonts or download a previously created, fully working (and slightly expanded) copy of this as an app or LiveCode stack, go to thehelpful.com/iosfonts.

 ??  ?? A full iOS Font Maker utility made previously that has a few more features, but it’s built on this core functional­ity.
A full iOS Font Maker utility made previously that has a few more features, but it’s built on this core functional­ity.
 ??  ?? The other half of the process: merging and exporting the XML file.
The other half of the process: merging and exporting the XML file.

Newspapers in English

Newspapers from Australia