1/* 2Copyright (c) 1998-2001 by Juliusz Chroboczek 3 4Permission is hereby granted, free of charge, to any person obtaining a copy 5of this software and associated documentation files (the "Software"), to deal 6in the Software without restriction, including without limitation the rights 7to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8copies of the Software, and to permit persons to whom the Software is 9furnished to do so, subject to the following conditions: 10 11The above copyright notice and this permission notice shall be included in 12all copies or substantial portions of the Software. 13 14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20THE SOFTWARE. 21*/ 22 23/* Header for backend-independent encoding code */ 24 25/* An encoding is identified with a name. An encoding contains some 26 global encoding data, such as its size, and a set of mappings. 27 Mappings are identified by their type and two integers, known as 28 pid and eid, the interpretation of which is type dependent. */ 29 30#ifndef _FONTENC_H 31#define _FONTENC_H 32 33/* Encoding types. For future extensions, clients should be prepared 34 to ignore unknown encoding types. */ 35 36/* 0 is treated specially. */ 37 38#define FONT_ENCODING_UNICODE 1 39#define FONT_ENCODING_TRUETYPE 2 40#define FONT_ENCODING_POSTSCRIPT 3 41 42/* This structure represents a mapping, either from numeric codes from 43 numeric codes, or from numeric codes to strings. */ 44 45/* It is expected that only one of `recode' and `name' will actually 46 be present. However, having both fields simplifies the interface 47 somewhat. */ 48 49typedef struct _FontMap { 50 int type; /* the type of the mapping */ 51 int pid, eid; /* the identification of the mapping */ 52 unsigned (*recode) (unsigned, void *); /* mapping function */ 53 char *(*name) (unsigned, void *); /* function returning glyph names */ 54 void *client_data; /* second parameter of the two above */ 55 struct _FontMap *next; /* link to next element in list */ 56 /* The following was added for version 0.3 of the font interface. */ 57 /* It should be kept at the end to preserve binary compatibility. */ 58 struct _FontEnc *encoding; 59} FontMapRec, *FontMapPtr; 60 61/* This is the structure that holds all the info for one encoding. It 62 consists of a charset name, its size, and a linked list of mappings 63 like above. */ 64 65typedef struct _FontEnc { 66 char *name; /* the name of the encoding */ 67 char **aliases; /* its aliases, null terminated */ 68 int size; /* its size, either in bytes or rows */ 69 int row_size; /* the size of a row, or 0 if bytes */ 70 FontMapPtr mappings; /* linked list of mappings */ 71 struct _FontEnc *next; /* link to next element */ 72 /* the following two were added in version 0.2 of the font interface */ 73 /* they should be kept at the end to preserve binary compatibility */ 74 int first; /* first byte or row */ 75 int first_col; /* first column in each row */ 76} FontEncRec, *FontEncPtr; 77 78typedef struct _FontMapReverse { 79 unsigned int (*reverse) (unsigned, void *); 80 void *data; 81} FontMapReverseRec, *FontMapReversePtr; 82 83 84/* Function prototypes */ 85 86/* extract an encoding name from an XLFD name. Returns a pointer to a 87 *static* buffer, or NULL */ 88char *FontEncFromXLFD(const char *, int); 89 90/* find the encoding data for a given encoding name; second parameter 91 is the filename of the font for which the encoding is needed. 92 Returns NULL on failure. */ 93FontEncPtr FontEncFind(const char *, const char *); 94 95/* Find a given mapping for an encoding. This is only a convenience 96 function, as clients are allowed to scavenge the data structures 97 themselves (as the TrueType backend does). */ 98 99FontMapPtr FontMapFind(FontEncPtr, int, int, int); 100 101/* Do both in a single step */ 102FontMapPtr FontEncMapFind(const char *, int, int, int, const char *); 103 104/* Recode a code. Always succeeds. */ 105unsigned FontEncRecode(unsigned, FontMapPtr); 106 107/* Return a name for a code. Returns a string or NULL. */ 108char *FontEncName(unsigned, FontMapPtr); 109 110/* Return a pointer to the name of the system encodings directory. */ 111/* This string is static and should not be modified. */ 112const char *FontEncDirectory(void); 113 114/* Identify an encoding file. If fileName doesn't exist, or is not an 115 encoding file, return NULL, otherwise returns a NULL-terminated 116 array of strings. */ 117char **FontEncIdentify(const char *fileName); 118 119FontMapReversePtr FontMapReverse(FontMapPtr); 120 121void FontMapReverseFree(FontMapReversePtr); 122#endif 123