|
|
1.1 ! root 1: .NH ! 2: Fonts and Information about Fonts ! 3: .XS ! 4: Fonts and Information about Fonts ! 5: .XE ! 6: .PP ! 7: .IN "Font Loading" ! 8: WARNING: This section WILL change in major ways soon, ! 9: to provide a more sophisticated view of fonts, ! 10: and lift limitations in the current font format. ! 11: Please plan accordingly. ! 12: .PP ! 13: The X server loads fonts whenever a program requests a new font. ! 14: Fonts are unloaded when the last program using the font exits or ! 15: closes it. ! 16: There is never more than one copy of a font stored in the server at ! 17: one time. ! 18: .PP ! 19: There are several levels one can deal with fonts. ! 20: .IN "XOpenFont" ! 21: .IN "XCloseFont" ! 22: You can use the general font routines \fIXOpenFont\fP and \fIXCloseFont\fP, ! 23: or only get the information you want explicitly. ! 24: .IN "FontInfo" ! 25: .FD ! 26: .IN "Definitions" "XOpenFont" ! 27: .IN "XOpenFont" ! 28: FontInfo *XOpenFont(name) ! 29: char *name; ! 30: .FN ! 31: .IN "XGetFont" ! 32: .IN "XQueryFont" ! 33: .IN "XFontWidths" ! 34: This function does a \fIXGetFont\fP, ! 35: \fIXQueryFont\fP and \fIXFontWidths\fP in one operation, ! 36: creating an instance of the font structure. ! 37: It allocates the memory to store the font information in. ! 38: It returns NULL if it could not succeed. ! 39: .FD ! 40: .IN "Definitions" "XCloseFont" ! 41: .IN "XCloseFont" ! 42: XCloseFont(info) ! 43: FontInfo *info; ! 44: .FN ! 45: This function closes off any use of a font, and deallocates the storage ! 46: associated with the \fIFontInfo\fP structure. ! 47: .IN "XOpenFont" ! 48: WARNING: it is a gross error to close a font not opened with \fIXOpenFont\fP, ! 49: since you may corrupt the memory pool. ! 50: .FD ! 51: .IN "Definitions" "XGetFont" ! 52: .IN "XGetFont" ! 53: Font XGetFont (name) ! 54: char *name; /* null-terminated string */ ! 55: .FN ! 56: \fIXGetFont\fP loads a font of the specified \fIname\fP. ! 57: A font id is returned, or 0 if it could not succeed. ! 58: .IN "XFreeFont" ! 59: The client should call \fIXFreeFont\fP when it is no longer needed. ! 60: .FD ! 61: .IN "Definitions" "XQueryFont" ! 62: .IN "XQueryFont" ! 63: Status XQueryFont (font, info) ! 64: Font font; ! 65: FontInfo *info; /* RETURN */ ! 66: .FN ! 67: \fIXQueryFont\fP gets various facts about a font. It fills in the ! 68: client-passed \fIFontInfo\fP, which is defined as follows: ! 69: .sp ! 70: .DS ! 71: .TA .5i 2.5i ! 72: .ta .5i 2.5i ! 73: typedef struct _FontInfo { ! 74: Font id; /* font id for this font */ ! 75: short height; /* constant for all characters in font */ ! 76: short width; /* "average" width of characters in font */ ! 77: short baseline; /* baseline of characters */ ! 78: short fixedwidth; /* 0 or 1 */ ! 79: unsigned char firstchar, lastchar; /* first & last characters in font */ ! 80: short *widths; /* pointer to font width array */ ! 81: } FontInfo; ! 82: .DE ! 83: .IN "Data Structures" "FontInfo" ! 84: .IN "FontInfo" ! 85: The \fIbaseline\fP specifies where in pixels from the bottom of the font the ! 86: characters without descenders begin. ! 87: .PP ! 88: A font is fixed width if all characters in the range of legal characters ! 89: are the same width. ! 90: .PP ! 91: It does NOT get the width array, but the space is in the ! 92: data structure for a pointer to the array. ! 93: .FD ! 94: .IN "Definitions" "XFreeFont" ! 95: .IN "XFreeFont" ! 96: XFreeFont (font) ! 97: Font font; ! 98: .FN ! 99: \fIXFreeFont\fP tells the server that this font is no longer needed. ! 100: The font may be unloaded on the server if this is the last ! 101: reference to the font. ! 102: In any case, the ! 103: font should never again be referenced. ! 104: .FD ! 105: .IN "Definitions" "XCharWidths" ! 106: .IN "XCharWidths" ! 107: Status XCharWidths (chars, len, font, widths) ! 108: char *chars; /* NOT necessarily null-terminated */ ! 109: int len; /* number of characters */ ! 110: Font font; ! 111: short *widths; /* RETURN widths [0..len-1] */ ! 112: .FN ! 113: \fIXCharWidths\fP determines the width, in the specified font, of each ! 114: character in a string. ! 115: For each element of the character array, the width of ! 116: that character is stored in the corresponding element of the \fIwidths\fP ! 117: array (i.e. widths[i] is set to the width of the character chars[i].) ! 118: .FD ! 119: .IN "Definitions" "XFontWidths" ! 120: .IN "XFontWidths" ! 121: short *XFontWidths (font) ! 122: Font font; ! 123: .FN ! 124: \fIXFontWidths\fP allocates and returns a pointer to an array containing the ! 125: width of every character defined in the font. ! 126: It is only possible to get the widths of a variable width font. ! 127: If \fIXFontWidths\fP returns NULL, an error has occurred and no ! 128: array is allocated. ! 129: The client must free this array when he no longer ! 130: needs it. ! 131: .PP ! 132: .IN "XFontWidths" ! 133: .IN "XQueryFont" ! 134: \fIXFontWidths\fP should be used in conjunction with \fIXQueryFont\fP, ! 135: which returns ! 136: (among other data) the font's \fIfirstchar\fP and \fIlastchar\fP. ! 137: The length of the array ! 138: .IN "XFontWidths" ! 139: returned by \fIXFontWidths\fP will always be equal to (lastchar-firstchar+1). ! 140: In the array, widths[i] will be set to the width of character (firstchar+i). ! 141: .FD ! 142: .IN "XQueryWidth" ! 143: .IN "Definitions" "XQueryFont" ! 144: int XQueryWidth(str, font) ! 145: char *str; /* null-terminated string */ ! 146: Font font; ! 147: .FN ! 148: \fIXQueryWidth\fP returns the width in pixels of a null-terminated string in ! 149: the specified font. ! 150: It queries the server for the width computation. ! 151: .FD ! 152: .IN "XQueryWidth" ! 153: .IN "Definitions" "XQueryFont" ! 154: int XStringWidth(string, info, charpad, spacepad) ! 155: char *str; ! 156: FontInfo *info; ! 157: int charpad, spacepad; ! 158: .FN ! 159: This function computes the width of the string given a complete ! 160: .IN "FontInfo" ! 161: \fIFontInfo\fP structure. ! 162: \fICharpad\fP and \fIspacepad\fP are added to the width on each ! 163: character and space defined in the string. ! 164: It does not reference the window system server, as the information is ! 165: all available locally in this case.
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.