> Ideas.NewFontMgr


Font files
----------

        IntMetrics              metrics information
        x90y45                  old-style font file (for compatibility)
        f9999x9999              new-style font file (1 or 4-bpp)
        Outlines                outline font master
        Alias                   name of a font to use instead

Note that the '9999' in the above list denotes the pixel size of the font,
derived as follows:

        pixel size = (point size * 16) * 72 / dots per inch

The font manager looks for files in the following order:

        f9999x9999              use the bitmaps directly
        Outlines                create a master font to hold the outlines
        x90y45                  scale the bitmaps to the correct size
        Alias                   use another font's pixel definitions

The f9999x9999 file may be defined in 1 or 4-bpp - so if there is a 1-bpp
file for a font at a particular size, it will always be used regardless of
whether more than one shade is required.  Most of the time this will not
matter, since the printer output device is likely to have a different
resolution from the screen.


Font cache
----------

font handle => font name
               size, resolution, old size, magnification
               master font handle
               file offsets
               full filename - different for metrics and pixels files.
               metrics block
               pixels blocks

The master font handle is zero if the font is derived directly from the disc.
There are two types of master fonts:

        bitmap fonts, whose children are marked with a '*'
        outline fonts, which have a size of 0 and cannot be used directly

Children of bitmap fonts are scaled from bitmaps themselves, so they do not
necessarily reflect the 'best' state of the font, and for that reason they
are marked with a '*' so that further requests for fonts will not match them.

On the other hand, fonts are assigned to outline fonts if it is found that
the best available font definition is an outline file.  If the outlines are
used, another font is found that contains the outlines, and this is used as
the master font.  In this way many fonts can share the same outline data in
the cache, thus saving memory and reducing the number of disc accesses.

Master fonts are 'used' by each of their children, so the font header cannot
be deleted until all the children have been 'lost'.

If a master font turns out to contain precisely that information required by
the child (ie. if it is a bitmap font with the same size), then the chunk is
not copied, but is used directly (ie. the pixelsptr is pointed at the
relevant chunk).  This allows for the provision of a different set of metrics
with a given font, by having the child with a new set of metrics share the
pixels information in the master font.  To do this the name of the master
font is put in a file called 'alias' in the child's directory, to be picked
up at Font_FindFont time (filetype = font file, contents = font name followed
by <cr>).  Note that the directory can still contain other files  (eg. 1-bpp
fonts at certain sizes).

Each font has only one set of metrics and pixels information.  There are 8
pixel chunks, corresponding to 32 characters each.  If the font file is
'sorted', then the characters will appear in frequency order.

Note that there is never any ambiguity about the sorted bit, since a given
font is always derived from the same source file:

        outline fonts inherit the sorted flag from their parent
          - they may be cached as 4- or 1-bpp, but always from the same master
        disc-based fonts have either a 4- or 1-bpp master (not both)


; -----------------
; Font header block
; -----------------
                ^       0
std_size        #       4
std_age         #       4
std_end         #       0               ; end of cache entry header

hdr_usage       #       4               ; font usage count

hdr_metricshandle  #    1               ; metrics
hdr_pixelshandle   #    1               ; type depends on font header type
                   #    2               ; word-align

; this part is loaded from the metrics file

hdr_name        #       40
hdr_nameend     #       0
hdr_xsize       #       4               ; x-size of font (1/16ths point)
hdr_ysize       #       4               ; y-size of font
hdr_nchars      #       1               ; number of defined characters
hdr_masterfont  #       1               ; 0 unless scaled from cache

hdr_shiftdown   #       1               ; no of bits to shift designsize down
hdr_pixflags    #       1               ; bit set => chunk is 1-bpp

hdr_xscale      #       4               ; = psiz * xres * xscaling * 16
hdr_yscale      #       4               ; = psiz * yres * yscaling * 16
hdr_xmag        #       4
hdr_ymag        #       4

; this part is loaded from the old-style 4-bpp file

hdr_xfactor     #       4               ; old font size
hdr_yfactor     #       4               ; remember for recacheing
hdr_xres        #       4
hdr_yres        #       4
hdr_boxx0       #       1
hdr_boxy0       #       1
hdr_boxx1       #       1
hdr_boxy1       #       1

                ASSERT  (hdr_boxy1-hdr_xfactor)=(fpix_boxy1-fpix_xscale)

; offsets to information within files

hdr_MetOffset   #       4               ; from fmet_chmap onwards
hdr_MetSize     #       4
hdr_PixOffset   #       4               ; from fpix_index onwards
hdr_PixSize     #       4

hdr_leafname    #       12              ; 3 words, not terminated if 12 chars
hdr_flags       #       2               ; 4 bpp / outlines / none
                                        ; sorted / not sorted
hdr_size        #       2               ; design size
hdr_PixOffsets  #       4*9             ; offsets to chunks in file

; list of pointers to sub-blocks in cache

hdr_MetricsPtr  #       4               ; 1 set for all characters
hdr_Charlist    #       4
hdr_PathName    #       4               ; block containing (expanded) pathname
hdr_PixelsPtrs  #       4*8             ; 8 sets of 32 characters each
nhdr_ptrs       *       (@-hdr_MetricsPtr)/4

hdr_end         #       0

; -------------
; Metrics block
; -------------
                ^       std_end
met_chmap       #       256             ; mapping from 0-255 to 0-(n-1)c
met_data        #       0


; -----------------
; Pixel chunk block
; -----------------
                ^       std_end
pix_index       #       4*32            ; 32-word index (rel. to index start)
pix_data        #       0

                ^       0
chr_boxx0       #       1
chr_boxy0       #       1
chr_boxx1       #       1
chr_boxy1       #       1
chr_data        #       0

; --------------
; PathName block
; --------------
                ^       std_end
pth_leafptr     #       1               ; offset to leafname (word-aligned)
pth_name        #       0               ; may be left-padded with spaces
                                        ; name ends in ". (12 chars) ",0


