Printer’s Apprentice Update
April 22nd, 2009 by
Bryan Kinkel
Now that Postscript printing is out of the way, I”m working on performance issues for Printer’s Apprentice.
One bottleneck in the system is reading fonts with the Font Files and Font Groups tabs.
When PA displays a list of fonts, it does not just show the file name and size. It also has to show the proper font name. The font names are stored deep inside the TrueType file structure in a series of tables. So when listing the the fonts in a folder, PA opens each file, reads in the file name and other data, then close the file. If you have hundreds of files in a folder, this can take a few (annoying) moments.
To get around this delay, I’m implementing a very simple font cache mechanism. The cache is an XML file, stored in %appdata%\printer’s apprentice\fontcache.xml, with the following structure.
<?xml version="1.0" standalone="yes"?>
<NewDataSet>
<fontcache>
<path>c:\fonts\ttfonts\a_c\tt0035m_.ttf</path>
<size>47356</size>
<fontfamily>Bodoni Bk BT</fontfamily>
<fullfamilyname>Bodoni Book BT</fullfamilyname>
<format>1</format>
<outline>1</outline>
<bold>0</bold>
<italic>0</italic>
<weight>400</weight>
</fontcache>
</NewDataSet>
I’m still working with the code and .NET calls to see how I can compact the XML. But the basic idea is in place.
When Printer’s Apprentice reads a directory, it first checks the cache for a match on name and file size. If it finds a match, then the font data is right there. Otherwise we need to read the TTF/PFM/OTF data directly. Any new data is saved in the cache as well.
Here are some very preliminary benchmarks for reading in a few folders of TrueType and Postscript fonts. The “initial read” is the first time PA examines a folder of font file. Since it is they are not in the cache, each file is opened up and examined. The “cached read” is the time for subsequent reads of the folder. The files are all found in the cache and don’t need to be opened. The data is right there in the cache.
| Folder contains | Initial Read | Cached Read |
| 145 TrueType fonts | 5 seconds | 2 seconds |
| 125 Type 1 fonts | 10 seconds | 2 seconds |
| 502 TrueType fonts | 10 seconds | 6 seconds |
| 500 Type 1 fonts | 20 seconds | 6 seconds |
This is all still in the early stage of development. I’m still working with the storage format and benchmarking. But the work is moving forward. Stay tuned.
Comments? Questions? helpdesk at lose your mind dot com.
Bryan
Posted in .NET Framework 2.0, Fonts, Printer's Apprentice |
No Comments »