13da084b3Smrg/*
23da084b3SmrgCopyright (c) 1998-2001 by Juliusz Chroboczek
33da084b3Smrg
43da084b3SmrgPermission is hereby granted, free of charge, to any person obtaining a copy
53da084b3Smrgof this software and associated documentation files (the "Software"), to deal
63da084b3Smrgin the Software without restriction, including without limitation the rights
73da084b3Smrgto use, copy, modify, merge, publish, distribute, sublicense, and/or sell
83da084b3Smrgcopies of the Software, and to permit persons to whom the Software is
93da084b3Smrgfurnished to do so, subject to the following conditions:
103da084b3Smrg
113da084b3SmrgThe above copyright notice and this permission notice shall be included in
123da084b3Smrgall copies or substantial portions of the Software.
133da084b3Smrg
143da084b3SmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
153da084b3SmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
163da084b3SmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
173da084b3SmrgAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
183da084b3SmrgLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
193da084b3SmrgOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
203da084b3SmrgTHE SOFTWARE.
213da084b3Smrg*/
223da084b3Smrg
233da084b3Smrg/* Header for backend-independent encoding code */
243da084b3Smrg
253da084b3Smrg/* An encoding is identified with a name.  An encoding contains some
263da084b3Smrg   global encoding data, such as its size, and a set of mappings.
273da084b3Smrg   Mappings are identified by their type and two integers, known as
283da084b3Smrg   pid and eid, the interpretation of which is type dependent. */
293da084b3Smrg
303da084b3Smrg#ifndef _FONTENC_H
313da084b3Smrg#define _FONTENC_H
323da084b3Smrg
333da084b3Smrg/* Encoding types.  For future extensions, clients should be prepared
343da084b3Smrg   to ignore unknown encoding types. */
353da084b3Smrg
363da084b3Smrg/* 0 is treated specially. */
373da084b3Smrg
383da084b3Smrg#define FONT_ENCODING_UNICODE 1
393da084b3Smrg#define FONT_ENCODING_TRUETYPE 2
403da084b3Smrg#define FONT_ENCODING_POSTSCRIPT 3
413da084b3Smrg
423da084b3Smrg/* This structure represents a mapping, either from numeric codes from
433da084b3Smrg   numeric codes, or from numeric codes to strings. */
443da084b3Smrg
453da084b3Smrg/* It is expected that only one of `recode' and `name' will actually
463da084b3Smrg   be present.  However, having both fields simplifies the interface
473da084b3Smrg   somewhat. */
483da084b3Smrg
493da084b3Smrgtypedef struct _FontMap {
503da084b3Smrg    int type;                   /* the type of the mapping */
513da084b3Smrg    int pid, eid;               /* the identification of the mapping */
52e1c0d025Smrg    unsigned (*recode) (unsigned, void *);      /* mapping function */
53e1c0d025Smrg    char *(*name) (unsigned, void *);   /* function returning glyph names */
543da084b3Smrg    void *client_data;          /* second parameter of the two above */
553da084b3Smrg    struct _FontMap *next;      /* link to next element in list */
563da084b3Smrg    /* The following was added for version 0.3 of the font interface. */
573da084b3Smrg    /* It should be kept at the end to preserve binary compatibility. */
583da084b3Smrg    struct _FontEnc *encoding;
593da084b3Smrg} FontMapRec, *FontMapPtr;
603da084b3Smrg
613da084b3Smrg/* This is the structure that holds all the info for one encoding.  It
623da084b3Smrg   consists of a charset name, its size, and a linked list of mappings
633da084b3Smrg   like above. */
643da084b3Smrg
653da084b3Smrgtypedef struct _FontEnc {
663da084b3Smrg    char *name;                 /* the name of the encoding */
673da084b3Smrg    char **aliases;             /* its aliases, null terminated */
683da084b3Smrg    int size;                   /* its size, either in bytes or rows */
693da084b3Smrg    int row_size;               /* the size of a row, or 0 if bytes */
703da084b3Smrg    FontMapPtr mappings;        /* linked list of mappings */
713da084b3Smrg    struct _FontEnc *next;      /* link to next element */
723da084b3Smrg    /* the following two were added in version 0.2 of the font interface */
733da084b3Smrg    /* they should be kept at the end to preserve binary compatibility */
743da084b3Smrg    int first;                  /* first byte or row */
753da084b3Smrg    int first_col;              /* first column in each row */
763da084b3Smrg} FontEncRec, *FontEncPtr;
773da084b3Smrg
783da084b3Smrgtypedef struct _FontMapReverse {
79e1c0d025Smrg    unsigned int (*reverse) (unsigned, void *);
80e1c0d025Smrg    void *data;
813da084b3Smrg} FontMapReverseRec, *FontMapReversePtr;
823da084b3Smrg
833da084b3Smrg
843da084b3Smrg/* Function prototypes */
853da084b3Smrg
863da084b3Smrg/* extract an encoding name from an XLFD name.  Returns a pointer to a
873da084b3Smrg   *static* buffer, or NULL */
88e1c0d025Smrgchar *FontEncFromXLFD(const char *, int);
893da084b3Smrg
903da084b3Smrg/* find the encoding data for a given encoding name; second parameter
913da084b3Smrg   is the filename of the font for which the encoding is needed.
923da084b3Smrg   Returns NULL on failure. */
93e1c0d025SmrgFontEncPtr FontEncFind(const char *, const char *);
943da084b3Smrg
953da084b3Smrg/* Find a given mapping for an encoding.  This is only a convenience
963da084b3Smrg   function, as clients are allowed to scavenge the data structures
973da084b3Smrg   themselves (as the TrueType backend does). */
983da084b3Smrg
993da084b3SmrgFontMapPtr FontMapFind(FontEncPtr, int, int, int);
1003da084b3Smrg
1013da084b3Smrg/* Do both in a single step */
1023da084b3SmrgFontMapPtr FontEncMapFind(const char *, int, int, int, const char *);
1033da084b3Smrg
1043da084b3Smrg/* Recode a code.  Always succeeds. */
1053da084b3Smrgunsigned FontEncRecode(unsigned, FontMapPtr);
1063da084b3Smrg
1073da084b3Smrg/* Return a name for a code.  Returns a string or NULL. */
1083da084b3Smrgchar *FontEncName(unsigned, FontMapPtr);
1093da084b3Smrg
1103da084b3Smrg/* Return a pointer to the name of the system encodings directory. */
1113da084b3Smrg/* This string is static and should not be modified. */
11252fd71cdSmrgconst char *FontEncDirectory(void);
1133da084b3Smrg
1143da084b3Smrg/* Identify an encoding file.  If fileName doesn't exist, or is not an
1153da084b3Smrg   encoding file, return NULL, otherwise returns a NULL-terminated
1163da084b3Smrg   array of strings. */
1173da084b3Smrgchar **FontEncIdentify(const char *fileName);
1183da084b3Smrg
1193da084b3SmrgFontMapReversePtr FontMapReverse(FontMapPtr);
1203da084b3Smrg
1213da084b3Smrgvoid FontMapReverseFree(FontMapReversePtr);
1223da084b3Smrg#endif
123