Dr Wimp p11

Using fonts

Dr Wimp makes the using of outline fonts very easy - but it doesn't (quite!) do everything for you.

In principle, the Wimp requires you to treat a font rather like a file. That is to say, you need to 'open' a link to the font definition before you use it, and close the link after you have finished with it. These links are called font 'handles'. (It is as well to recap that a font handle defines both the font and its point size. So, you would need to open two font handles to define the same font in two different sizes - and you would already be familiar with this if you had been using the Dr Wimp facilities.)

However, unlike files, it doesn't have an immediately serious effect if you open a font handle for use but don't close it after you've finished with it. All that happens is that your system continues to carry the opened handles until you switch off - and, of course, this is very convenient if you have several operations using the same font handle.

Dr Wimp handles the majority of the opening and closing automatically. For example, the opening and closing is done for you if you want to display a drawfile containing fonts, or if you wish to plot text using one of the wimp-functions which specifies the font as a string definition plus its size separately.

But if, instead, you want to plot text with one of the wimp-functions which requires you to specify a valid font handle (i.e one which you have chosen to open previously yourself with FNwimp_getfont), then there isn't much that Dr Wimp can do automatically to help you with closing it - because, in this case, it doesn't know if you've finished with that handle or not.

So, the moral is "If you open a font yourself, then close it when you've finished with it".

The best way to manage this is to declare/open all the fonts that you intend to handle in this way at the start of your program (in PROCuser_initialise) and then to close each one again (with PROCwimp_losefont) after the wimp-poll has been exited, before ending.

If you want to follow the action in more detail, open a Task Window and type *FontList at different times before, during, and after your program is run. It is interesting to see what is happening, font-wise.

Font menus

Continuing on the theme of fonts, the only (in my humble opinion!) major facility that Dr Wimp doesn't yet cover is a means of displaying the available font menu via wimp/user-functions.

The good news is that I have cracked this in a development version and it works well, within limits.

The bad news is that, so far, those limits include the restriction that the font list must not be altered during the application run.

I'm pursuing this... and, in the meantime, I would welcome any thoughts you might have on the potential usefulness of this possible future enhancement. Is it something you are desperately waiting for - or are there other things you think are more important?

The redraw process

As you will know, the redraw process is the means by which the Wimp updates a window when it is needed, i.e. on scrolling or when moving resizing a window. The programmer only needs to get involved if the window has some text/graphics drawn directly to it (i.e. text/sprites in icons are handled automatically by the Wimp).

To do its window updating the Wimp makes repeated calls to the application for redrawing - each for different rectangles making up the area to be refreshed/updated.

Dr Wimp hides all the complication from you, but there are still some things you need to watch - and they apply to all Wimp programming, whether or not you are using Dr Wimp.

The basic rule is: don't do anything in the redraw process that isn't directly concerned with the redrawing. For instance, don't seek to change the text in an icon as part of a redraw. Icon handling isn't part of the redraw process and to try to include it within it will cause trouble. Similarly, don't try to change menu characteristics within the redraw process.

These are, perhaps, obvious points but I thought they were worth a reminder.


Source: Archive 13.11
Publication: Archive Magazine
Contributor: Ray Favre