New Feature In Printer’s Apprentice 8

October 26th, 2006 by Bryan Kinkel

This is something I’m very pleased about. Displaying fonts in a listbox is a very popular request. This lets the user quickly compare fonts side by side. Microsoft Word has done it for years in the toolbar. Start up Word and click the Fonts listbox in the toolbar to see what I’m talking about.

This functionality was something I never could perfect using Visual Basic 6.0. And I tried. Controls that draw their own content are called owner draw controls. Drawing custom content in VB6 listboxes involved all sorts of Win32 API calls and introduced a tremendous amount of complexity and overhead into the code.

However, the .NET Framework 2.0 makes owner draw controls a snap.

This screenshot from Printer’s Apprentice 8 shows the new Compare Fonts tab. Select a font from the list on the left and it will appear in the Compare Fonts tab.

In this example, I’ve selected nine fonts to compare. Two of them are Adobe Type 1 fonts.

Using the controls at the bottom, I can change the sample text and the point size. The point size control has a series of fixed sizes to select from.

As it turns out, executing code cannot change the height of a listbox item without doing a total refresh of the control contents. This means the items have to be cleared and reloaded into the listbox.* I used a dropdown listbox instead of a slider control to reduce the amount of code executed when the point size is changed.

The new Compare Fonts tab also works with uninstalled fonts. In this screenshot I have several fonts from my c:\dev\fonts folder selected.

Drawing the listbox with uninstalled fonts is more complex than drawing with regular installed fonts. When a font is drawn for the first time, I call a Win32 API function -

AddFontResourceEx(fontfile.ttf, FR_PRIVATE, IntPtr.Zero)

This installs the font for use with the GDI drawing functions. The font installation is tagged FR_PRIVATE so it is only available for the Printer’s A Apprentice process and not other running applications. When the drawing is complete, the font is uninstalled. It works quite well.

So what is next for this feature? Couple things… The main thing is performance testing. My rough code needs to be refined for speed and error handling. And I need to throw my stacks of TrueType and Type 1 CDs at the routines for testing. We can’t have one bad font bring down the entire application. Some of those 500 TrueType Fonts for $10 CDs have lots of bum fonts.

Then note the not-so-fancy text box and Go button in the upper left hand corner of the screenshot. I need to replace these controls with a true Explorer tree that lists all the drives and folders on your system.

And finally, I’m not sure of the tab title. Compare Fonts. Is this the best wording for this tab? If you have comments or ideas, let me know. — Bryan

* I think this is a limitation at the Win32 API level. But I may be wrong.

Posted in Printer's Apprentice | 1 Comment »