📄 ut1lib.tex
字号:
for comments, thereby describing the current character code.\item All further lines of text are ignored.\end{itemize}As well known from PostScript, non-existent characters have to benamed \verb+.notdef+.Here's an example of such an encoding file:\begin{verbatim}Sample encoding file for t1lib!The first two lines are considered to be comments!Encoding=ISOLatin1Encoding .notdef /* '000 000 "00 */ .notdef /* '001 001 "01 */ .notdef /* '002 002 "02 */ . . . . . .greater /* '076 062 "3E */question /* '077 063 "3F */at /* '100 064 "40 */A /* '101 065 "41 */B /* '102 066 "42 */ . . . . . .yacute /* '375 253 "FD */thorn /* '376 254 "FE */ydieresis /* '377 255 "FF */ \end{verbatim}Since V.~1.2, \tonelib\ is also able to load encoding files in the format usedby \verb+dvips+. This makes a large set of existing encoding files availableto the user. When parsing \verb+dvips+ encoding files, \tonelib\ requiresPostScript syntax. This means white space may be interspersed freely andline comments are defined by the character \%. The mark-characters, \verb+[+and\verb+]+, are considered as special tokens and need not be preceded orfollowed by white space. Similarly, the literal escape character \verb+/+delimits a preceding token without interspersed white space. When parsing\verb+dvips+ encoding files, \tonelib\ tolerates less than 256 character namedefinitions. If characters are missing, they are substituted by \verb+.notdef+until the counter reaches $256$. Aside from comments, no PostScript tokens areallowed after the encoding definition in a \verb+dvips+ encoding file iscomplete.With the defining terms above, it turns out that a file which has successfullybeen scanned as a \verb+dvips+ encoding file, cannot specify a valid \tonelib\encoding after the PostScript encoding definition is complete (because novalid character name can start with \% and because at least a line such as\verb+Encoding=+, would have to follow the PostScript encoding). Hence thefile format are mutually exclusive and it is possible to read both formatusing one function. In a first pass \tonelib\ tries to read the file as a\verb+dvips+ encoding file, and if that fails, it assumes to have a \tonelib\encoding file. Once such an encoding file of either type has been created, it can be loadedinto memory. This is done with the function\precorr\begin{verbatim} char **T1_LoadEncoding( char *filename)\end{verbatim}\index{\verb+T1_LoadEncoding()+}\postcorrThe function will use the search path definitions read fromthe configuration file during initialization (see\ref{runtimesetup}, \verb+ENCODING=+). If noerrors occur, an array of pointers to strings is created andinitialized. The start address of this pointer array is returned as adouble pointer to a char. This pointer is intendedto be used to reencode a font via \verb+T1_ReencodeFont()+. If the encodingdata structure could not be created, \verb+NULL+ is returned to indicate theerror. The memory allocated by \verb+T1_LoadEncoding()+ is organized in twocontinuous blocks. One block is the pointer array of size 257\footnote{This number results from 256 charactername pointers plus one pointer to the encoding scheme identifier.} and theother block contains the character name strings plus the encoding schemespecification, separated byASCII-zeros. This memory can be returned to the system using the function \precorr\begin{verbatim} int T1_DeleteEncoding( char **Encoding)\end{verbatim}\index{\verb+T1_DeleteEncoding()+}\postcorr\tonelib\ does not check whether a valid pointer value was passed. So becareful to pass the correct pointer. An error in this function should almostalways be followed by a segmentation violation.A newly loaded encoding is applied to an existent font bycalling \precorr\begin{verbatim} int T1_ReencodeFont( int FontID, char **Encoding)\end{verbatim}\index{\verb+T1_ReencodeFont()+}\postcorr\verb+FontID+ must be a valid font identification and\verb+Encoding+ a pointer returned from asuccessful call to \verb+T1_LoadEncoding()+. There are two requirementsin order to reencode a font:\begin{enumerate}\item The font must already have been loaded into memory. \item No size-dependent data exists for this font. If it does, it must be removed explicitly prior to calling \verb+T1_ReencodeFont()+. \end{enumerate}It follows that there are two ways to reencode a font. The first isto load a font explicitly and reencode it before any size dependentdata is created. The second is to use an automatically loaded fontand delete all of its size dependent data before reencoding it.The user may also specify the special pointer NULL as the\verb+Encoding+-argument. This would reencode the font to its internalencoding vector.In case of success, the function returns 0, otherwise -1 is returned.Reencoding a font takes a considerable amount of time since the mapping tableshave to be reorganized. In situations where it is \`a priori foreseeable that thefont will be reencoded using some standard encoding vector, it makes sense toassign that particular encoding vector as the default encoding vector,thereby overwriting the internal encoding vector of each font at load timebefore the mapping tables are setup. Setting the default encoding can beachieved using \precorr\begin{verbatim} int T1_SetDefaultEncoding( char **Encoding)\end{verbatim}\index{\verb+T1_SetDefaultEncoding()+}\postcorrHere \verb+Encoding+ encoding is assumed to be a valid \tonelib\ encodingvector, e.g., created by a call to \verb+T1_LoadEncoding+.\verb+T1_SetDefaultEncoding()+ has to be called after initialization. Itreturns \verb+0+ if this condition is fulfilled and \verb+-1+otherwise. In the latter case \verb+T1_errno+ is set appropriately. Notice that the internal encoding of the font is still accessible byreencoding the font using \verb+NULL+ as encoding specification (see above). Note further that the default encoding vector is only applied to those fontthat have \verb+StandardEncoding+ as internal encoding. This is to preventfonts like ZapfDingbats, Symbol or Sonata\footnote{A musical notation font.}from being reencoded automatically at load time because this would besurely inappropriate for such fonts.It is also possible to query the encoding scheme that the font associated with\verb+FontID+ uses. This is achieved with the function\precorr\begin{verbatim} char *T1_GetEncodingScheme( int FontID)\end{verbatim}\index{\verb+T1_GetEncodingScheme()+}\postcorrThe return value is a pointer to a string which describes the encoding schemein question. The are 3 possible cases:\begin{itemize}\item The font uses Adobe StandardEncoding, which is internally known by the rasterizer. Then, \verb+StandardEncoding+ is returned.\item The font defines its own encoding by \hbox{\verb+dup+ $n$ {\em LiteralName} \verb+put+} statements. In this case no particular name is associated with the encoding scheme and \verb+FontSpecific+ is returned.\item The encoding is externally loaded by \verb+T1_LoadEncoding()+. Then the encoding scheme entry of this file is returned. If this (optional) entry is not specified in the file, \verb+Unspecified+ is returned.\end{itemize}Notice that the name of the encoding scheme is also accessible as\verb+Encoding[256]+ where \verb+Encoding+ is the pointer returned by asuccessful call to \verb+T1_LoadEncoding()+.\subsection{Deleting Data}\label{deletingdata}%In frequently appearing cases, it may be wise to return some memorywhich was explicitly or automatically allocated by the library back to thesystem.\footnote{This is especially true, since there is presently no caching algorithm which automatically takes care of this.} Forthis purpose some functions are available. To understand how size dependentdata for a font is organized, see (\ref{internals}).The memory amount required by the size-dependent data of \verb+size+and font \verb+FontID+ is freed by calling the function \precorr\begin{verbatim} int T1_DeleteSize( int FontID, float size)\end{verbatim}\index{\verb+T1_DeleteSize()+}\postcorrThe data deleted includes the metricinformation for 256 characters, some pointers, associated bitmap data (ifalready existent) as well as the font matrix for that size.As described in section \ref{internals}, the data structures containingsize-dependent information of a particular font are organized as alinked list. \verb+T1_DeleteSize()+ takes care that a properly linkedlist is left after deleting the data.If the combination of \verb+size+ and \verb+FontID+ does not exist, -1is returned. If the operation was successful, the return value is 0.For the purpose of removing all size-dependent data for a particularfont, there is the function\precorr\begin{verbatim} int T1_DeleteAllSizes( int FontID)\end{verbatim}\index{\verb+T1_DeleteAllSizes()+}\postcorrIt recursively removes all size-dependent data for the font\verb+FontID+. This may be appropriate if a user knows some font notto be needed any longer. This function is also to be used, if one intends toreencode a font for which size dependent data has already been generated. In addition, font transformationssuch as {\em slanting} and {\em extending} require a font having no size-specific data. \verb+T1_DeleteAllSizes()+ recursively calls \verb+T1_DeleteSize()+ todo its job.It returns the number of sizes removed (including 0 if no sizes wereexistent) or -1 if an error occurred.It is also possible to remove the entire data associated with aparticular font from memory using\precorr\begin{verbatim} int T1_DeleteFont( int FontID)\end{verbatim}\index{\verb+T1_DeleteFont()+}\postcorr\verb+T1_DeleteFont()+ goes one step beyond the above functions andremoves all the data associated with the font \verb+FontID+. Thisincludes:\begin{itemize}\item All size dependent data.\item All data from the Type 1 font program, held in memory.\item All AFM data kept in memory. \end{itemize}The memory reserved for a font in hierarchy-level 1 is not returned tothe system since it is simply one element in the array of structures oftype \verb+FONTPRIVATE+ (see \ref{internals}). But all entries in thisstructure are reset to initial values.Whether it is useful or not, a font that has been removed using\verb+T1_DeleteFont()+ may also be loaded again, explicitly orimplicitly.There is a restriction, which has not yet been mentioned: A font may only beremoved if it is a physical font (to be explained later) to which no logicalfonts refer or if it is a logical font.\footnote{See \ref{logicalfonts} for explanation of logical fonts.} A reference counter is maintained in eachphysical font to check for this. If the font to be removed is a logical font,the \verb+FONTPRIVATE+ area is reset and the reference counter of thereferenced physical font is decremented. Of course, size dependent data isremoved in every case.\verb+T1_DeleteFont()+ returns 0 if the font has been removed correctly or ifthe font was not loaded. $n$ ($>0$) is returned ifthe font was physical and was referenced by $n$ logical fonts. Areturn value -1 indicates an invalid \verb+FontID+.The function \precorr\begin{verbatim} int T1_FreeG
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -