Let’s sum up the many faces of sharedfonts with swfmill.
Sharing one font per swf:
<movie width="1" height="1" framerate="12">
<frame>
<library>
<font import="src/ttf/georgia.ttf"/>
</library>
<import url="http://www.deja-vue.net/test/shared/swf/fonts/Georgia Gras.swf"></import>
</frame>
</movie>
CommandLine :
swfmill simple "src/georgia.xml" "deploy/Georgia Gras.swf"
if we do so, we access the font by its default name:
fmt.font = "Georgia";
Because we didn’t give the font any name in particular in the configuration file, the embedded font is identified by its Digital Signature.
In case we want to specify a name:
<movie width="1" height="1" framerate="12">
<frame>
<library>
<font name="dragon" import="src/ttf/Lisas Dragons.ttf" glyphs="My little dragon"/>
</library>
<import url="http://www.deja-vue.net/shared/swf/font/lisasDragons.swf"></import>
</frame>
</movie>
We then refer the font as follow:
There are advantages to specify a custom name.
- to import various styles in one go:
<movie width="1" height="1" framerate="12">
<frame>
<library>
<font name="Charter" import="src/ct.ttf"/>
<font name="Charter" import="src/ct__Italic.ttf"/>
<font name="Charter" import="src/ct__Bold.ttf"/>
<font name="Charter" import="src/ct__BoldItalic.ttf"/>
</library>
<import url="http://www.deja-vue.net/test/charters.swf"></import>
</frame>
</movie>
We have then free hand to use the style we want:
fmt.font = "Charter";
// Italic
fmt.italic = true;
// Italic and Bold
fmt.italic = true;
fmt.bold = true;
- It's very handy if we deal with differents weights by classifying them semantically:
<frame>
<library>
<font name="Charter Regular" import="src/charterRegular.ttf"/>
<font name="Charter Medium" import="src/charterMed.ttf"/>
<font name="Charter Extended" import="src/charterExtended.ttf"/>
</library>
<import url="http://www.deja-vue.net/test/charters.swf"></import>
</frame>
</movie>
Finally it's up to you to decide how to handle the build:
Personally, I use a batch process, like so:
swfmill simple "src/dejavue/cactus.xml" "build/dejavue/cactus.swf"
swfmill simple "src/dejavue/benegraphic.xml" "build/dejavue/Benegraphic.swf"
swfmill simple "src/dejavue/The Dark Crystal.xml" "build/dejavue/The Dark Crystal.swf"
swfmill simple "src/dejavue/Lisas Dragons.xml" "build/dejavue/gs.swf"
swfmill simple "src/dejavue/KingArthurSpecial.xml" "build/dejavue/King Arthur Special.swf"
Okay, that's all folks!
You will learn more from the source files where you'll find:
- the TTF/ XML assets' directory structure inside sharedfontBuilder;) folder.
- the source .as files (Application and TextFormatCellRenderer classes).
--------------------------------------------------------------------------------
A few words about the application example
- Datagrid instantiation and cellRenderer linkage were all done in Fla. ActionScript was injected later with MTASC.
- I used Pixlib's XMLToObject and Libstack/GraphicLib to handle the fonts loading process (I LOVE Pixlib, everybody should know from now ^^).
Enjoy!
This is really cool, if I understand it correctly... The fonts are being loaded individually... Are they available for use anywhere in the datagrid, or just in individual cells? Can you do multiple fonts in the same TextField, as with htmlText?
Hi Tom,
Yes, in this case the fonts are loaded individually.
Once the Flash Player references them in the library they are globally available (You can use them anywhere).
I guess it depends on how you implement CellRenderers on each columns.
If I remember well, last time I checked I still wasn't possible. You can only use one embedded font per Textfield.
I'm not very familiar with swfmill. It looks really cool, but I haven't had time to dig into it yet. Is it possible to get the same results with the Flash IDE, or does swfmill work around some limitations?
Swfmill is very easy to use. Plus, with the source files I provided you have the necessary bits of code to start very quickly.
If however you absolutely want to do it using the IDE, you can check the following article: Zárate - Shared Fonts Today. But IMHO its much more complicated that way.
Swfmill would definitely streamline the process. Thanks!
By the way, in my testing I have found that you can in fact use multiple fonts in the same textfield using the shared fonts technique you describe. However, rather than using a TextFormat object to format the TextField, you set TextField.html to true, and set the htmlText like this:
TextField.htmlText = 'Foo Bar';
Incidentally, I never was able to get the Zarate method to work for me.
The listbox "up" and "down" buttons are upside down!
I love this technique but can't get it to work with Flash 8.
The fonts show up but the text is completely misaligned - moves up by about 20 pixels or so. When I add 'version="8"' to the XML, no text shows up at all.
Any suggestions?
cheers - Nils.
I've tried with another TTF now and the font is aligned correctly.
Adding 'version="8"' still results in no fonts being displayed anymore though.
Anybody else had these problems or resolved them?
- Nils.