/*
    ####             #    #     # #
    #   #            #    #       #          The FreeWare C library for 
    #   #  ##   ###  #  # #     # ###             RISC OS machines
    #   # #  # #     # #  #     # #  #   ___________________________________
    #   # ####  ###  ##   #     # #  #                                      
    #   # #        # # #  #     # #  #    Please refer to the accompanying
    ####   ### ####  #  # ##### # ###    documentation for conditions of use
    ________________________________________________________________________

    File:    Template.UseOutFont.c
    Author:  Copyright  1993 Jason Williams
    Version: 1.01 (14 Nov 1995)
    Purpose: Support for use of outline fonts in templates
    History: 1.00 (29 Jun 1993)
             1.01 (14 Nov 1995) JS Made font-handling SDLS compatible.
*/


#include "TempDefs.h"

#include "Desk.Font.h"
#include "Desk.JumpRaw.h"


Desk_SDLS_PtrFn(
	static,
	void,
	Desk_Template_ExitHandler(void)
	)
/*static void Desk_Template_ExitHandler(void)*/
/*  Called on exit to clean up the fonts we're using */
/* cc warns about extern ... not declared in header in SDLS compiles	*/
{
  if ((int) Desk_template_fontarray > 0)
    Desk_Font_LoseAllFonts(Desk_template_fontarray);
} 


extern void Desk_Template_UseOutlineFonts(void)
/*  Allocates store for the font usage array - must be called before calls
 *  to Desk_Template_LoadFile or your outline fonts won't be used.
 *  Note that if it fails, it does so quietly - your windows will come up
 *  without outline fonts.
 */
{
  if ((int) Desk_template_fontarray > 0) return;

  Desk_JumpAuto_TryCatch(
  	Desk_template_fontarray = Desk_DeskMem_Malloc(sizeof(Desk_font_array));
  	,
  	Desk_template_fontarray = (Desk_font_array *) -1;     /* Failed! Ensure we are safe*/
  	return;
  	)
  {
    int i;

    for (i = 0; i < 256; i++)                   /* Initialise counts to zero */
      Desk_template_fontarray->fonts[i] = 0;

    atexit(Desk_SDLS_dllEntry( Desk_Template_ExitHandler));               /* Set up exit handler       */
  }
}
