The implementation of anti-alias fonts on the Archimedes was an innovatory step. This method of providing high quality text is normally associated with powerful graphics engines, and in particular with broadcast quality titling systems such as that used in the legendary Quantel Paintbox. But the native speed of the ARM processor makes this feasible on the Arc.
The distinguishing feature of these fonts is that special algorithms are used which attempt to reduce the ragged edges caused by the finite size of each pixel. This is achieved by inserting pixels at the boundaries of each character in colours intermediate between the foreground and background colours, thus blurring otherwise jagged edges.
The software support for the Arc's anti-alias fonts is good. The Arthur 1.2 Welcome disc contained two font styles (Corpus and Trinity), and the new RISC OS Applications disc 1 contains three (Corpus, Trinity and Porterhouse). Additionally, the Programmer's Reference Manual documents a considerable number of SWIs dedicated to font use.
In RISC User Volume 1 Issue 3 we took an introductory look at the use of anti-alias fonts on the Arc, concentrating on their use in the 16 colour modes. In the present article the investigation is extended into the 256 colour modes. In doing so we can dispel a major restriction claimed to hold for these modes. In the Programmer's Reference Manual it specifically states that anti-alias fonts are ORed onto the screen, with the result that you must generally use a background colour of 0 (thus restricting you to a black background in the 256 colour modes, where the palette is not easily redefined). Fortunately this is not the case, and any background colour may be used.
One of the chief advantages of using the 256 colour modes for anti-alias fonts is that text may be written in many different colours, and against many different backgrounds all on the same screen. In the 16 colour modes there is a serious colour limitation. To generate decent looking text you need to set aside at least 4 (and preferably 8) colours for the anti-aliasing palette for each text colour, and the font manager redefines them to the physical colours required for painting the text.
In the 256 colour modes, the palette is not redefined, instead the Font Manager attempts to allocate an appropriate set of pre-defined colours for the job; though how well it achieves this in practice depends on the colours chosen by the user. Because the palette is not redefined, all 256 colours remain at the user's disposal, and it is therefore possible to construct screens containing, for example, full colour digitised images together with anti-aliased text in a wide variety of colours.
Without further ado we will get down to the practicalities of anti-aliased text in mode 15. The accompanying program demonstrates the major calls used for the 256 colour modes, and parcels them up, as far as possible, into a number of customisable procedures and functions.
To begin with, type in the program and save it to disc. Before running it you will need to configure some font space (30 or 40K will be more than adequate). Either use:
*Config.Font.10 then Ctrl-Break
or use the RISC OS Task Manager. Next, install on your current disc the following directory sequence:
$.FONTS.TRINITY.MEDIUM
Into the directory MEDIUM, copy the two files:
IntMetrics
and x90y45
from the Arthur 1.2 Welcome disc directory:
FONTS.TRINITY.MEDIUM
or from the RISC OS Applications disc 1:
!FONTS.TRINITY.MEDIUM
Now you can run the program! You should see a dark blue background with anti-alias text in white. Then a line of text in yellow bordered with red should appear and drift down the screen leaving a "trail". The first time around the program will take several seconds to run, but when repeated it will execute in just less than a second, displaying each line of text in around 0.05 seconds. The excellent timing on subsequent displays is a result of the font caching process which takes place in the area of RAM set aside for the purpose, above. To check the cache, use:
*FontList
The additional command *FontCat will list the names of fonts stored on your current disc.
The main program loop is simple. Fonts are initialised, colours are initialised, text is written, and the fonts put on hold (by PROCtidy). The font initialising procedure PROCinitfont has two functions. Firstly it establishes the so-called font prefix. This is just the directory path to where the fonts are stored (in this case: $.FONTS). It then sets up two font sizes in Trinity medium, and assigns so-called font handles for each (these are held in font1 and font2). The first has a point size of 30 (line 540), and the second of 30 horizontally by 35 vertically (line 560), though these may be altered as required.
The colours used for the fonts are set up in PROCinitcols. This uses the block of data at line 390. The first item (currently set to 2) tells the procedure how many anti-alias palettes are to be set up. It then reads in the foreground and background colour and tint for each. The first palette uses colour 63 tint 192 (white) and background 32 tint 0 (mirroring the background colour set up in line 90), while the second uses a yellow foreground and a red background, causing the red bordering effect on the second set of text.
The procedure PROCinitcols may be expanded to set up as many as 16 colour palettes. Each is subsequently referred to by a number n, where n=1 refers to the first defined palette, and so on. As you may have noticed, PROCinitcols calls FNconvert. The purpose of this is to convert the user-supplied values of GCOL and TINT for foreground and background into the special form required by SYS "Font_SetPalette".
The text is actually written using PROCwrite. This takes five parameters: the font number (this is the handle returned when the font was initialised - font1 or font2 in this case), the palette number as defined above, the X and Y co-ordinates of the start of the text (in graphics units), and finally the text string itself. As you can see, this procedure makes three SYS calls: "Font_SetFont to establish the required font as the current font, "Font_SetFontColours" to establish a particular palette, and "Font_Paint" to paint the current font on the screen using the currently selected font palette.
Note by the way, that the Programmer's Reference Manual misses a vital "s" from the end of the name of the SYS call "Font_SetFontColours", and that the fourth parameter (=14) in both this call and "Font_SetPalette" is confusingly referred to as a "foreground offset". It is in fact the number of anti-alias levels to be set between foreground and background. In 256 colour modes, this would normally be set to 14, indicating that the font manager should attempt to set up a 16 level palette - though depending on the foreground and background colours specified, it will not always fully achieve this goal.
10 REM >FontDemo
20 REM Program Anti-Alias Fonts
30 REM Version A 0.3
40 REM Author Lee Calcraft
50 REM RISC User June 1989
60 REM Program Subject to Copyright
70 :
80 MODE15
90 GCOL 32+128:CLG:REM Blue Bcgnd
100 PROCinitfonts
110 PROCinitcols
120 REM Title text
130 PROCwrite(font1,1,200,800,"**ANTI-ALIASED TEXT**")
140 REM Drift effect
150 FOR Z=700 TO 500 STEP -12
160 PROCwrite(font2,2,200,Z,"ACORN'S TRINITY FONT")
170 NEXT
180 PROCtidy
190 END
200 :---------------------------------
210 DEFPROCwrite(font,col,X,Y,text$)
220 SYS "Font_SetFont",font
230 SYS "Font_SetFontColours",,,col,14
240 SYS "Font_Paint",,text$,20,X,Y
250 ENDPROC
260 :---------------------------------
270 DEFPROCinitcols
280 READ totpal
290 FOR n=1 TO totpal
300 READ gcol,tint
310 fgnd%=FNconvert(gcol,tint)
320 READ gcol,tint
330 bgnd%=FNconvert(gcol,tint)
340 REM Anti-alias palette (index 1)
350 SYS"Font_SetPalette",,,n,14,bgnd%,fgnd%
360 NEXT
370 ENDPROC
380 :---------------------------------
390 REM data: no of sets then
400 REM fgnd gcol,tint, bgnd gcol,tint
410 DATA 2
420 DATA 63, 192, 32, 0
430 DATA 15, 192, 2, 0
440 :---------------------------------
450 DEFFNconvert(gcol,tint)
460 tint=tint>>>6
470 red=((gcol AND 3)<<2)+tint
480 green=(gcol AND 12)+tint
490 blue=((gcol AND 48)>>>2)+tint
500 =(red<<12)+(green<<20)+(blue<<28)
510 :---------------------------------
520 DEFPROCinitfonts
530 *SET Font$Prefix $.FONTS
540 xpoint=30:ypoint=30
550 SYS "Font_FindFont",,"Trinity.Medium",xpoint*16,ypoint*16 TO font1
560 xpoint=30:ypoint=35
570 SYS "Font_FindFont",,"Trinity.Medium",xpoint*16,ypoint*16 TO font2
580 ENDPROC
590 :---------------------------------
600 DEFPROCtidy
610 SYS "Font_LoseFont",font1
620 SYS "Font_LoseFont",font2
630 ENDPROC
640 :---------------------------------