Font File Format

(The original information can be found on page 1801 of Volume IV of the RISC OS 3.1 PROGRAMMER'S REFERENCE MANUAL)
Fonts are decribed in:

IntMetrics


Size    Description
40      Name of font, padded with Return (&0D) characters
4       16
4       16
1       n=number of defined characters
3       reserved - currently 0
256     character mapping (ie indices into following arrays). For
        example, if the 40th byte in this block is 4, then the fourth
        entry in each of the following arrays refers to that character.
        A zero entry means that character is not defined in this font.
2n      x0     |
2n      y0     |  bounding cox of character (in 1/1000th em)
2n      x1     |  coordinates are relative to the 'origin point'
2n      y1     |
2n      x-offset after printing this character
2n      y-offset after printing this character
The bounding boxes and offsets are given as 16-bit signed numbers, with the low byte first.

x90y45 font files

Each font file starts with a series of 4-word index entries, corresponding to the sizes defined:

Size    Description
1       point size (not multiplied by 16)
1       bits per pixel (4)
1       pixels per inch (x-direction)
1       pixels per inch (y-direction)
4       reserved - currently 0
4       offset of font data in file
4       size of font data
The list is terminated by:
1       0

Font data

Font data is limited to 64K per block. Each block starts word-aligned relative to the start of the file:

Character data


New font file formats

The new font file formats includes definitions for the following types of font files: '9999' = pixel size (ie point size * 16 * dpi / 72) zero-suppressed decimal number.

If the length of an outlines file is less than 256 bytes, then contents are the name of another font whose glyphs are to be used instead (with this fonts metrics).

If the length of a x90y45 file is less than 256 bytes then contents are the name of the f9999x9999 file to use as master bit maps.

File header

The file header is of the following form:

Size    Description
4       "FONT - identification word
1       Bits per pixel:
                 0 = outlines
                 1 = 1 bpp
                 4 = 4 bpp
1       Version number of file format
                 4:no "don't draw skeleton lines unless smaller than this"
                 byte present
                 5:byte at [table+512] = max pixel size for skeleton
                 lines (0 => always do it)
                 6:byte at [chunk+indexsize] = dependency mask (see below)



Instrument data

Instrument names are not recorded; only channel numbers.

Size    Description
1       3 indicates Instrument data follows
This is followed by 8 blocks of 2 bytes each:
1       channel number. Always consecutive 1-8
1       voice number; 0=no voice attached

Volume data


Size    Description
1       4 indicates Volume data follows
1*8     Volume on each channel = 0-7 = ppp-fff. One byte for
        each channel.

Stereo position data


Size    Description
1       5 indicates Stereo data follows
1*8     Stereo position of channel n = 0-7 = Full Left...Full Right.
        One byte for each channel.

Tempo data


Size    Description
1       6 indicates Tempo data follows
1       0-14, which corresponds to one of:
        40, 50, 60, 65, 70, 80, 90, 100, 115, 130, 145, 160, 175, 190, 210
        beats per minute
To convert to values to program into SWI Sound_Tempo, use the formula: Sound_Tempo value = Beats per minute * 128 * 4096/6000

Title string


Size    Description
1       7 indicates Title string follows
n       Null terminated string of n characters total length

Instrument names


Size    Description
1       8 indicates Instrument names follow
 n1..n8 8 null terminated strings for each voice number used in
          ascending order under Instrument data above.

MIDI channels


Size    Description
1       9 indicates MIDI channel numbers follow
1*8     MIDI channel number from 1-16 on this stave for each
        channel. 0 indicates not transmitted over MIDI.

Gates

A Gate is a point in the music where something is interpreted. eg. a note, time-signature, key-signature, bar-line or clef can each occupy a gate. The gate data is one byte for a note or rest; 2 bytes for an attribute (time-signature, key-signature, bar-line or clef).

Note or rest


Bits    Description
0-7     Gate mask, bit n set to 1 note or rest from queue n.

Attribute


Byte    Description
0       0
1       Could be any of the following forms:

Time-signature
    Bit(s) Description 0 1 1-4 Number of beats per bar - 1. In the range 0-15 5-7 Beat type (0 = breve, to 7 = hemidemisemiquaver)
Key-signature
    Bit(s) Description 0-1 01 binary 2 0=#, 1=b 3-5 0 to 7
Clef
    Bit(s) Description 0-2 001 binary 3-4 0 = treble, 1 = alto, 2, = tenor, 3 = bass 5-6 Stave - 1. In the range 0-3
Slur
    Bit(s) Description 0-3 0001 binary 4 1 = on, 0 = off 5 unused 6-7 Stave - 1. In the range 0-3
Octave shift
    Bit(s) Description 0-4 00001 binary 5 0 = up, 1 = down 6-7 Stave - 1. In the range 0-3
Bar
    Bit(s) Description 0-5 000001 binary
Reserved for future expansion
    Bit(s) Description 0-6 0000001 binary

Notes and rests

Notes and rests are each stored in a 2 byte block that has some common elements.

Notes


Bit(s)  Description
0       Stem orientation. 0 for up and 1 for down
1       Set to 1 to join beams (barbs) to next note
2       Set to 1 to tie with next note
3-7     Stave line position 1-31 (16 is the centre line)
8-10    Accidental
        0 = natural
        1 = sharp
        2 = flat
        3 = double-sharp
        4 = double-flat
        5 = natural sharp
        6 = natural flat
        7 = unused
11-12   number of dots, from 0-3
13-15   Type. Breve = 0 to Hemisemidemiquaver = 7

Rests


Bits   Description
 0-10  Unused. Set to 0
11-12  Number of dots, from 0-3
13-15  Type. Breve=0 to Hemisemidemiquaver=7
If a rest coincides with a note, its position is determined by the following note on the same channel.