Add pancyrillic font
[platform/upstream/kbd.git] / src / psf.h
1 /* psf.h */
2
3 /*
4  * Format of a psf font file:
5  *
6  * 1. The header
7  * 2. The font
8  * 3. Unicode information
9  */
10
11 /*
12  * Format of the Unicode information:
13  *
14  * For each font position <uc>*<seq>*<term>
15  * where <uc> is a 2-byte little endian Unicode value,
16  * <seq> = <ss><uc><uc>*, <ss> = psf1 ? 0xFFFE : 0xFE,
17  * <term> = psf1 ? 0xFFFF : 0xFF.
18  * and * denotes zero or more occurrences of the preceding item.
19  *
20  * Semantics:
21  * The leading <uc>* part gives Unicode symbols that are all
22  * represented by this font position. The following sequences
23  * are sequences of Unicode symbols - probably a symbol
24  * together with combining accents - also represented by
25  * this font position.
26  *
27  * Example:
28  * At the font position for a capital A-ring glyph, we
29  * may have:
30  *      00C5,212B,FFFE,0041,030A,FFFF
31  * Some font positions may be described by sequences only,
32  * namely when there is no precomposed Unicode value for the glyph.
33  */
34
35 #ifndef _PSF_H
36 #define _PSF_H
37
38
39 #define PSF1_MAGIC0     0x36
40 #define PSF1_MAGIC1     0x04
41
42 #define PSF1_MODE512    0x01
43 #define PSF1_MODEHASTAB 0x02
44 #define PSF1_MODEHASSEQ 0x04
45 #define PSF1_MAXMODE    0x05
46
47 #define PSF1_SEPARATOR  0xFFFF
48 #define PSF1_STARTSEQ   0xFFFE
49
50 struct psf1_header {
51         unsigned char magic[2];     /* Magic number */
52         unsigned char mode;         /* PSF font mode */
53         unsigned char charsize;     /* Character size */
54 };
55
56 /*
57  * Format and semantics of psf2 version 0 are as psf (with PSF_MAXMODE == 5).
58  * However, this allows one to specify the length.
59  * It turns out to be very useful to be able to work with fonts
60  * with a few symbols or even only one (like the Euro), and
61  * with very large fonts (like several thousand Unicode symbols
62  * done in the same style).
63  * Following hpa's suggestion, psf2 uses UTF-8 rather than UCS-2,
64  * and has 32-bit magic 0x864ab572.
65  * The integers here are little endian 4-byte integers.
66  */
67
68 #define PSF2_MAGIC0     0x72
69 #define PSF2_MAGIC1     0xb5
70 #define PSF2_MAGIC2     0x4a
71 #define PSF2_MAGIC3     0x86
72
73 struct psf2_header {
74         unsigned char magic[4];
75         unsigned int version;
76         unsigned int headersize;    /* offset of bitmaps in file */
77         unsigned int flags;
78         unsigned int length;        /* number of glyphs */
79         unsigned int charsize;      /* number of bytes for each character */
80         unsigned int height, width; /* max dimensions of glyphs */
81         /* charsize = height * ((width + 7) / 8) */
82 };
83
84 /* bits used in flags */
85 #define PSF2_HAS_UNICODE_TABLE 0x01
86
87 /* max version recognized so far */
88 #define PSF2_MAXVERSION 0
89
90 /* UTF8 separators */
91 #define PSF2_SEPARATOR  0xFF
92 #define PSF2_STARTSEQ   0xFE
93
94
95 #define PSF1_MAGIC_OK(x)        ((x)[0]==PSF1_MAGIC0 && (x)[1]==PSF1_MAGIC1)
96 #define PSF2_MAGIC_OK(x)        ((x)[0]==PSF2_MAGIC0 && (x)[1]==PSF2_MAGIC1 \
97                                 && (x)[2]==PSF2_MAGIC2 && (x)[3]==PSF2_MAGIC3)
98
99
100 #endif  /* _PSF_H */