(******************************************************************************) (* *) (* The global constants and variables defined in this module are optional: *) (* if you don't want to access their features, you needn't import them into *) (* your program. The variables in the parameter lists of the procedures are *) (* the only variables you are required to supply. *) (* When describing the order in which certain routines are called, I have *) (* adopted the curly-bracket notation of EBNF: routines in curly brackets {} *) (* may be called an arbitrary number of times (0 to n). A, {B}, {C, {D}} thus *) (* implies that A is called once, followed by an arbitrary number of calls to *) (* to B, followed by an arbitrary number of calls to C. Each of the calls to *) (* C may be followed by an arbitrary number of calls to D. Likewise, {{C},{D}}*) (* implies an arbitrary number of calls to C and D in any order. *) (* *) (******************************************************************************) (* *) (* Version 1.00a.002 (Beta) : March 2, 1988 *) (* *) (* These procedures were originally written under version 1.20 of the TDI *) (* Modula-2 compiler. I have rewritten this module to operate under the v2.00 *) (* compiler. However, should you find any problem or inconsistency with the *) (* functionality of this code, please contact me at the following address: *) (* *) (* Jerry Mack *) (* 23 Prospect Hill Ave. *) (* Waltham, MA 02154 *) (* *) (* Check the module MenuUtils for TDI's (considerably less powerful) ver- *) (* sions of my Menu and IntuitionText procedures. The modules GadgetUtils and *) (* EasyGadgets should also be of great help. *) (* *) (******************************************************************************) (* *) (* The source code to FontTools is in the public domain. You may do with *) (* it as you please. *) (* *) (******************************************************************************) DEFINITION MODULE FontTools; FROM DiskFontLibrary IMPORT AvailFontsHeaderPtr; FROM Libraries IMPORT LibraryPtr; FROM Text IMPORT TextFontPtr; TYPE FontListNodePtr = POINTER TO FontListNodeType; FontListNodeType = RECORD node : TextFontPtr; next : FontListNodePtr; END; (* FontListNodeType *) VAR UserDiskFontBase : LibraryPtr; (* entry point into DiskFont library *) FontBuffer : AvailFontsHeaderPtr; (* description of available fonts *) FontList : FontListNodePtr; (* list of pointers to opened fonts *) PROCEDURE GetAndSortAllFonts () : BOOLEAN; PROCEDURE ReturnFontResourcesToSystem; PROCEDURE OpenAllFonts () : CARDINAL; PROCEDURE CloseAllFonts; (* GetAndSortAllFonts fills FontBuffer with an array of AvailFonts struc- *) (* tures, each of which contains a TextAttr structure and a flag informing *) (* whether the font resides in memory or on disk. The array contains data *) (* for the system fonts and all fonts in the FONTS: directory. The array is *) (* sorted by name and also by point-size. Thus, the fonts on the left would *) (* be returned in the order shown on the right: *) (* *) (* 9 point diamond.font 9 point diamond.font *) (* 12 point ruby.font 9 point garnet.font *) (* 8 point topaz.font 16 point garnet.font *) (* 9 point topaz.font 12 point ruby.font *) (* 19 point sapphire.font 19 point sapphire.font *) (* 11 point topaz.font 8 point topaz.font *) (* 9 point garnet.font 9 point topaz.font *) (* 16 point garnet.font 11 point topaz.font *) (* *) (* ReturnFontResourcesToSystem should be called when you are finished with *) (* the FontBuffer. Also, you must call ReturnFontResourcesToSystem prior to *) (* calling GetAndSortAllFonts again. However, unless you reassign the FONTS:*) (* directory, there is little need to call GetAndSortAllFonts more than *) (* once. ReturnFontResourcesToSystem closes the DiskFont library which Get- *) (* AndSortAllFonts opened (and which you may access via UserDiskFontBase), *) (* and DEALLOCATES the memory used by FontBuffer. *) (* OpenAllFonts opens all of the fonts in the FONTS: directory, making them *) (* immediately available for use in your program. OpenAllFonts first calls *) (* GetAndSortAllFonts to obtain a list of the fonts available. It then opens*) (* each font (in the order listed in FontBuffer) and adds a pointer to the *) (* corresponding font-definition structure to the global variable FontList. *) (* In the process of opening it, the font is added to the system font-list, *) (* where it remains until it is closed and removed by each of the processes *) (* which opened it. OpenAllFonts returns the number of fonts it opened. *) (* CloseAllFonts closes all of the fonts listed in FontList and relinquishes*) (* all memory used by the FontList. Furthermore, it also removes each font *) (* from the system font-list, unless another task is using the font. Lastly,*) (* CloseAllFonts calls ReturnFontResourcesToSystem to relinquish the memory *) (* used by FontBuffer and everything else described above. *) (* The order in which these procedures are invoked is as follows: *) (* *) (* { {GetAndSortAllFonts, ReturnFontResourcesToSystem}, *) (* *) (* {OpenAllFonts, CloseAllFonts } } *) END FontTools.