⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ut1lib.tex

📁 source code: Covert TXT to PDF
💻 TEX
📖 第 1 页 / 共 5 页
字号:
setting metric values to 0. Thus, do not free thereturned glyph pointer since later \verb+T1_SetChar()+ will freememory that is no more allocated and probably used for some other purpose.If you really like to free the memory, set the pointer to \verb+NULL+afterwards. If an error occurs at some point, \verb+T1_SetChar()+ returns aNULL-pointer to the user.Frequently it is advantageous to raster a series ofcharacters at once. This has the advantage that internal accuracy maybe used and the overhead for the user is minimal. For such cases, thefunction \precorr\begin{verbatim} GLYPH *T1_SetString( int FontID, char *string, int len,                       long spaceoff, int modflag,                       float size, T1_TMATRIX *transform)\end{verbatim}\index{\verb+T1_SetString()+}\postcorris provided.It can be considered an extended version of \verb+T1_SetChar()+. Thesame as said above applies to the arguments \verb+FontID+,\verb+size+ and \verb+transform+. But a few additional arguments areneeded here. \verb+string+ is a series of bytes representing the indices into the currentencoding vector. The \verb+len+-parameter is needed because we cannot imply that stringis always an object like a string in C. For example, the ComputerModern Roman fonts contain the uppercase Greek Gamma (\char0) atposition 0 in their internal encoding. In a string to be typeset thevalue 0 is thus a valid value and deserves no specialtreatment. Hence, we cannot not use the C-function \verb+strlen()+ tocompute the length of the string. However, since in most usual encodingsthe special value 0 is not encoded (``\verb+.notdef+''), it makessense to switch between standard situations and non-standard situations:\begin{itemize}\item If \verb+string+ is a string conforming with C-semantics,  \verb+len+ can be set to 0. Then, the length of the string is  internally computed.\item If \verb+string+ contains one or more control characters which make  processing impossible, the \verb+len+-value must be specified  explicitly. \end{itemize}The \verb+spaceoff+ parameter is important for word processingpurposes. The value specified here is interpreted as an offset to thespace width used during rastering. It is interpreted in charspaceunits, i.e., $1/1000$ bp. Every time a space character is requested,this amount of horizontal escapement is added to the naturalspacewidth of the current font. Note that the space character itselfis actually not rastered. All requests to the character with thecharactername ``\verb+space+'' are caught by \tonelib\ and convertedto a simple horizontal escapement. For computation of the resultingspacewidth, the width of the space-character is taken from theAFM data and merged with the specified offset, which may also benegative.\footnote{One consequence of this handling is, that---with a  little tricking---fonts that do not define a space character  themselves may be used for typesetting. This applies to the  dc-fonts, which only define a visible space, but no real space (see  \ref{fonts}).}The \verb+modflag+ argument may be used to specify some option to therastering function. It is generally 0 or an OR'ed combination of the followingnames:\begin{itemize}\item \verb+T1_KERNING+: As the name implies, this argument  determines that pairwise kerning information from the AFM file is to be taken  into account during string rastering. Not specifying \verb+T1_KERNING+   means: ``omit kerning''. It is generally  recommended to use kerning information since this improves the optical  appearance. However, many lower quality fonts do not have kerning  information.  With \tonelib\ V.\ 0.4-beta, kerning information is accessible  much faster than before because it is based on char codes rather than on  characternames.\item \verb+T1_RIGHT_TO_LEFT+: Setting this flag will invert the writing  direction. In {\em Right-To-Left} mode the escapement in writing direction  (left) is inserted before placing the character with the result that the  character laps over to the left side. This principle is kept for all  characters in the string. Note that metrics of fonts that are intended for  {\em Right-To-Left} typesetting have the same meaning as for fonts intended  for standard ({\em Left-To-Right}) typesetting.\item \verb+T1_UNDERLINE+: The string to be rastered is to be underlined  according to the line specifications of the current font. \item \verb+T1_OVERLINE+: The string to be rastered is to be over lined.\item \verb+T1_OVERSTRIKE+: Same here for overstriking. \end{itemize}For a description of underlining and such, see \ref{underlining}. Notice alsothat the \verb+modflag+ argument is a replacement of the \verb+kerning+argument from pre-0.7 versions of \tonelib.Concerning glyph-memory considerations, the same applies as said underthe description of \verb+T1_SetChar()+: Never free a pointer to memorywhich was returned by \verb+T1_SetString()+. Or, alternatively, if freeingthe pointer cannot be avoided set it to NULL after freeing it.\footnote{For  example, {\tt XDestroyImage()} gives the pixel memory for the image  data free although it might not have been allocated by any X11-function.} There are two generic ways how a string-glyph can be produced. The first is totake the paths of all characters needed, concatenate them, insert space andkerning amounts as needed and raster the resulting whole path. This will yieldthe best results since the average position accuracy of the pixels will beoptimal. This applies especially for rotated strings. The drawback is, thatevery character must be rastered every time it is needed. There is no way toaccess the bitmap data of a character inside a rastered string separate fromothers. And the caching of string-glyphs at this programming level doesn'tmake any sense. So this principle takes significantly longer thanconcatenating bitmaps from a cache area. However, it is done when thespecified rotation angle is not equal to $0^\circ$ or when even furthertransformation are to be applied.  This condition should limit the totalnumber of situations when this happens to an amount we can easily bear.If the \verb+transform+-argument is \verb+NULL+ we know transformations orrotation should not be applied and another approach is used. We are then ableto construct the resulting bitmap by adjusting already existent bitmaps intoproper positions.  If a character does not already exist in the cache, it isgenerated just the way \verb+T1_SetChar()+ works. The calculation of thecharacter-bitmap positions in the output bitmap is done withchar space-precision.  Nonetheless, there may be differences in the outputcompared with output of the above method. These are caused by the fact thatrounding to pixel accuracy has already been achieved when generating thecharacter bitmap. Thus, the output of the above principle should always bebetter since the positions of the black pixels are rounded with respect to thewhole string, and not with respect to a single character glyph. On the otherhand, concatenating character glyphs takes significantly less time thanrastering a complete string.  Theoretically, differences of up to two pixelshorizontal shift may appear in the output of the two principles. You cancheck the effect by running the program \verb+xglyph+. Specify a string ofenough length and raster it at angle $0^\circ$. Then specify a very smallangle from 0 different, say, $0.001^\circ$, and raster the string again withthe new setting. You might find that the representation of the string is alittle different now.If two glyphs with arbitrary orientation exist,\precorr\begin{verbatim} GLYPH *T1_ConcatGlyphs( GLYPH *glyph1, GLYPH *glyph2,                         int x_off, int y_off, int modflag)\end{verbatim}\index{\verb+T1_ConcatGlyphs()+}\postcorrcan be used to concatenate them. First the size of the resulting glyph iscomputed and its metric values are filled. Then, the two glyphs are placed attheir appropriate positions in the newly created bitmap. In order to be ableto work, the following conditions must be met:\begin{enumerate}\item Either glyph must be different from \verb+NULL+.\item Both glyphs must have identical \verb+bpp+-values. If antialiased and  non-antialiased glyphs are to be concatenated, have a look at\item There must be enough memory for the new glyph (naturally).\end{enumerate}The quantities \verb+x_off+ and \verb+y_off+ describe the $x$- and$y$-component of an optional offset to be inserted between the twoglyphs. This offset is interpreted as device pixels. The \verb+modflag+argument is used to specify the direction in which the two glyphs are to beconcatenated. That is, only the bit \verb+T1_LEFT_TO_RIGHT+ /\verb+T1_RIGHT_TO_LEFT+ is respected by this function.If problems occur, \verb+NULL+ is returned.It is generally not recommended to produce large glyphs with this functionbecause the char space precision in placing the character bitmaps is lost. Forexample, three times rounding up an advance by 0.3 pixels accumulates to 1pixel position error. A similar effect shows up when two rotated and underlinedglyphs are concatenated with this function. There might be a slight shift in thebaseline at the point where the two glyphs touch.A dilemma occurs, if two antialiased bitmaps have distinct backgroundcolors. Then, it is not clear what the transparent coloris. \verb+T1_ConcatGlyphs()+ always assumes the {\em current} background colorto be transparent.There is one more function that generates pointers to glyphs:\precorr\begin{verbatim} GLYPH *T1_CopyGlyph(GLYPH *glyph)\end{verbatim}\index{\verb+T1_CopyGlyph()+}\postcorrAs mentioned earlier, the user doesn't have the possibility of keepingthe  glyphs longer than to the next call of the respective rastering function. If someone wants to keep a bitmap some time longer,  \verb+T1_CopyGlyph()+ may be usedto copy the glyph to another area which is then completely under user'scontrol. This function simply does the following:\begin{itemize}\item Allocates the memory for the glyph-structure.\item If bitmap data is present, it allocates memory for the bitmap data,  taking the member \verb+bpp+ into account (see \ref{antialiasing}).\item Copies the structure and the bitmap data to the respective locations.\item Initializes the pointer \verb+glyph.bits+.\end{itemize}Return value is the pointer to the allocated glyph-structure. If somethinggoes wrong, NULL is returned to indicate an error. A glyph pointer,returned by a call to this function should be freed by a call to\verb+T1_FreeGlyph()+ (see \ref{deletingdata}).\subsection{Loading Fonts Explicitly}\label{loading}%Usually there is no need for a user to load a font into memory since this isdone automatically as needed by the rastering functions. But there are twosituations where it makes sense to explicitly load a font before generatingany size dependent data:\begin{itemize}\item A font is to be reencoded immediately after loading (see \ref{encoding}).\item A font is to be transformed (see \ref{transformations}).\end{itemize}These operations require a font being loaded but not having any size specificdata. Loading a font explicitly is done by the function\precorr\begin{verbatim} int T1_LoadFont( int FontID)\end{verbatim}\index{\verb+T1_LoadFont()+}\postcorrLoading a font involves several actions:\begin{itemize}\item Locating and loading the Type 1 font file.\item Locating and loading the font metrics data from AFM file.\item Computing and filling the values of the \verb+FONTPRIVATE+ structure as  described in section \ref{internals}.\item Setting up some tables for fast access of metrics information.\end{itemize}\verb+T1_LoadFont()+ returns \verb+0+ if successful or \verb+-1+ if the fontcould not be loaded. A failure may be due to \tonelib\ not having beeninitialized or due to problems with file locations and file parsing. If a fontrefuses to load, the logfile should be examined first. Furthermore, in case ofa failure \verb+T1_errno+ will be set appropriately.\subsection{Functions for Encoding Handling}\label{encoding}%As mentioned earlier, the encoding mechanism used in thePostScript-language allows a font to contain more than 256 differentcharacters, although only 256 are accessible at a given time. Thecharacters which are accessible are given by the elements of thecurrent {\em encoding vector}. In order to maximize flexibility,\tonelib\ allows for changing the current encoding vector. This isalso called ``Reencoding a font''. A new encoding vector is definedand made known to the library by creating an encoding-file and loadingits contents into memory. Before describing the functions needed for this, we shouldbriefly describe the format of an encoding file. An encoding file is an ASCII text file. Noassumptions about filename extensions are made. Here are the rules forscanning the file:\begin{itemize}\item The file contents are completely ignored until a line is encountered  that starts with the string \verb+Encoding=+. This string may optionally be  immediately followed by a string that is assumed to be the identifier of the  {\em encoding scheme} that this file defines. Any further text on this line  is ignored.\item Now, 256 lines have to follow, each line describing one  character's name. The string ranging from the beginning of the line  to the first white space character is assumed to be a character  name. The remainder of the lines is ignored and may (should) be used

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -