next up previous contents index
Next: Underlining, Overlining and Overstriking Up: Using t1lib Previous: Functions for Encoding Handling   Contents   Index


Deleting Data

In frequently appearing cases, it may be wise to return some memory which was explicitly or automatically allocated by the library back to the system.9 For this purpose some functions are available. To understand how size dependent data for a font is organized, see ([*]).

The memory amount required by the size-dependent data of size and font FontID is freed by calling the function

 int T1_DeleteSize( int FontID, float size)

to 0pt \fbox{$\mathcal{F}()\Rightarrow$} The data deleted includes the metric information for 256 characters, some pointers, associated bitmap data (if already existent) as well as the font matrix for that size.

As described in section [*], the data structures containing size-dependent information of a particular font are organized as a linked list. T1_DeleteSize() takes care that a properly linked list is left after deleting the data.

If the combination of size and FontID does not exist, -1 is returned. If the operation was successful, the return value is 0.

For the purpose of removing all size-dependent data for a particular font, there is the function

 int T1_DeleteAllSizes( int FontID)

to 0pt \fbox{$\mathcal{F}()\Rightarrow$} It recursively removes all size-dependent data for the font FontID. This may be appropriate if a user knows some font not to be needed any longer. This function is also to be used, if one intends to reencode a font for which size dependent data has already been generated. In addition, font transformations such as slanting and extending require a font having no size-specific data. T1_DeleteAllSizes() recursively calls T1_DeleteSize() to do its job. It returns the number of sizes removed (including 0 if no sizes were existent) or -1 if an error occurred.

It is also possible to remove the entire data associated with a particular font from memory using

 int T1_DeleteFont( int FontID)

to 0pt \fbox{$\mathcal{F}()\Rightarrow$} T1_DeleteFont() goes one step beyond the above functions and removes all the data associated with the font FontID. This includes: The memory reserved for a font in hierarchy-level 1 is not returned to the system since it is simply one element in the array of structures of type FONTPRIVATE (see [*]). But all entries in this structure are reset to initial values.

Whether it is useful or not, a font that has been removed using T1_DeleteFont() may also be loaded again, explicitly or implicitly.

There is a restriction, which has not yet been mentioned: A font may only be removed if it is a physical font (to be explained later) to which no logical fonts refer or if it is a logical font.10 A reference counter is maintained in each physical font to check for this. If the font to be removed is a logical font, the FONTPRIVATE area is reset and the reference counter of the referenced physical font is decremented. Of course, size dependent data is removed in every case.

T1_DeleteFont() returns 0 if the font has been removed correctly or if the font was not loaded. $n$ ($>0$) is returned if the font was physical and was referenced by $n$ logical fonts. A return value -1 indicates an invalid FontID.

The function

 int T1_FreeGlyph( GLYPH *glyph)

to 0pt \fbox{$\mathcal{F}()\Rightarrow$} returns memory allocated by T1_CopyGlyph() back to the system. This function should not be applied to the pointer to a glyph returned by one of the rastering functions. As said earlier, these functions manage the memory areas by themselves.

Similarly, the function

 int T1_FreeCompCharData( T1_COMP_CHAR_INFO *cci)

to 0pt \fbox{$\mathcal{F}()\Rightarrow$} returns memory associated to the composite caracter data structures, as allocated and returned by T1_GetCompCharData() or T1_GetCompCharDataByIndex() (see Section [*]), to the system. In order to avoid memory leaks, each call of the latter two functions should be followed by a call to this function.

In order to close the library and return all memory to the system,

 int T1_CloseLib( void)

to 0pt \fbox{$\mathcal{F}()\Rightarrow$} should be used. If no problems occur, 0 is returned. The value 1 indicates problems during freeing data. In this case the logfile should be examined. After having freed all data the file search paths, if different from the defaults, are restored. Last, the logfile is closed.


next up previous contents index
Next: Underlining, Overlining and Overstriking Up: Using t1lib Previous: Functions for Encoding Handling   Contents   Index
2004-10-04