solomon@dev8a.mdcbbs.com (09/10/90)
If I allow a user to set an environment variable to specify a font for use by my program, is it possible to figure out whether this font is a two-byte or extended-ascii of simply 7-bit ascii character set? Barry
mouse@LARRY.MCRCIM.MCGILL.EDU (09/12/90)
> If I allow a user to set an environment variable to specify a font > for use by my program, is it possible to figure out whether this font > is a two-byte or extended-ascii of simply 7-bit ascii character set? When you XQueryFont, you get back a pointer to an XFontStruct. Among other things, this structure contains the following members: unsigned min_char_or_byte2;/* first character */ unsigned max_char_or_byte2;/* last character */ unsigned min_byte1; /* first row that exists */ unsigned max_byte1; /* last row that exists */ From the description of XFontStruct: X supports single byte/character, two bytes/character matrix, and 16-bit character text operations. Note that any of these forms can be used with a font, but a single byte/character text request can only specify a single byte (that is, the first row of a 2-byte font). You should view 2-byte fonts as a two-dimensional matrix of defined charac- ters: byte1 specifies the range of defined rows and byte2 defines the range of defined columns of the font. Single byte/character fonts have one row defined, and the byte2 range specified in the structure defines a range of charac- ters. [...] The members of the XFontStruct have the following semantics: [...] o If the min_byte1 and max_byte1 members are both zero, min_char_or_byte2 specifies the linear character index corresponding to the first element of the per_char array, and max_char_or_byte2 specifies the linear char- acter index of the last element. If either min_byte1 or max_byte1 are nonzero, both min_char_or_byte2 and max_char_or_byte2 are less than 256, and the 2-byte character index values correspond- ing to the per_char array element N (counting from 0) are: byte1 = N/D + min_byte1 byte2 = N\D + min_char_or_byte2 where: D = max_char_or_byte2 - min_char_or_byte2 + 1 / = integer division \ = integer modulus Thus, you can figure out what cells in the character array exist easily enough. As for deciding whether it bears any relation to ASCII or not, there is no required thing that has any bearing on this. However, XLFD fonts (ideally, all fonts should be XLFD fonts) have two fields, called CHARSET_REGISTRY and CHARSET_ENCODING, that describe this: 3.1.2.13. CHARSET_REGISTRY : x-registered-name 3.1.2.14. CHARSET_ENCODING : registered-name The character set used to encode the glyphs of the font (and implicitly the font's glyph repertoire), as maintained by the X Consortium character set registry. CHARSET_REGISTRY is an x-registered-name that identifies the registration authority that owns the specified encoding. CHARSET_ENCODING is a registered-name that identifies the coded character set as defined by that registration authority. Although the X protocol does not explicitly have any knowledge about character set encodings, it is expected that server implementers will prefer to embed knowledge of certain proprietary or industry standard charsets into their font library for reasons of performance and convenience. The CHARSET_REGISTRY and CHARSET_ENCODING fields/properties allow an X client font request to specify a specific charset mapping in server environments where multiple charsets are supported. The availability of any particular character set is font and server implementation dependent. der Mouse old: mcgill-vision!mouse new: mouse@larry.mcrcim.mcgill.edu