-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathpcf.txt
212 lines (186 loc) · 6.82 KB
/
pcf.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
// -*- c++ -*-
// PCF File Format from libXfont-1.4.5
// include/X11/fonts/pcf.h
// src/bitmap/pcfread.c
// src/bitmap/pcfwrite.c
// miscellaneous definition ///////////////////////////////////////////////////
/* Type names are formatted as 'TypeSize_Endian'.
* name Type Size(bits) Endian
* --------------- --------------- --------------- -------
* char8 char 8 none
* bool8 bool 8 none
* int32_little int 32 big
* type32_little type32 32 big
* format32_little format32 32 big
* etc.
* In the *SECTION*, the endianess is determined by the format.byte
*/
#define PCF_FILE_VERSION (('p'<<24)|('c'<<16)|('f'<<8)|1)
enum type32 {
PCF_PROPERTIES = (1 << 0),
PCF_ACCELERATORS = (1 << 1),
PCF_METRICS = (1 << 2),
PCF_BITMAPS = (1 << 3),
PCF_INK_METRICS = (1 << 4),
PCF_BDF_ENCODINGS = (1 << 5),
PCF_SWIDTHS = (1 << 6),
PCF_GLYPH_NAMES = (1 << 7),
PCF_BDF_ACCELERATORS = (1 << 8),
};
struct format32 {
uint32 format:24; // format << 8
uint32 dummy:2; // = 0 padding << 6
uint32 scan:2; // bitmap scan unit is (1 << scan) bytes << 4
uint32 bit:1; // 0:LSBbit first, 1:MSBit first << 3
uint32 byte:1; // 0:LSByte first, 1:MSByte first << 2
uint32 glyph:2; // glyph pad is (1 << glyph) bytes << 0
};
// format32.format is one of the followings
#define PCF_DEFAULT_FORMAT 0
#define PCF_INKBOUNDS 2
#define PCF_ACCEL_W_INKBOUNDS 1
#define PCF_COMPRESSED_METRICS 1
typedef struct _PCFTable
{
type32_little type; // type of this section
format32_little format; // format of this section
int32_little size; // size of this section
int32_little offset; // offset of this section from the begining of the file
} PCFTableRec;
struct metric_t
{
int16 leftSideBearing;
int16 rightSideBearing;
int16 characterWidth;
int16 ascent;
int16 descent;
uint16 attributes;
};
struct compressedMetric_t
{
uint8 leftSideBearing; // - 0x80 == metric_t.leftSideBearing
uint8 rightSideBearing; // - 0x80 == metric_t.rightSideBearing
uint8 characterWidth; // - 0x80 == metric_t.characterWidth
uint8 ascent; // - 0x80 == metric_t.ascent
uint8 descent; // - 0x80 == metric_t.descent
};
#define GLYPHPADOPTIONS 4 // 1, 2, 4, or 8
#define MAKE_CHARCODE(row,col) (row * 256 + col)
// begining of the PCF file ///////////////////////////////////////////////////
// table of contents
uint32_little version = PCF_FILE_VERSION;
int32_little nTables; // 1 <= nTables <= 134217727
// note: 134217727 == INT32_MAX / sizeof(PCFTableRec) == 0x7fffffff / 16
PCFTableRec tables[nTables];
/*** SECTION ***/
// properties section (tables[i].type = PCF_PROPERTIES)
format32_little format; // format.id = PCF_DEFAULT_FORMAT
int32 nProps; // 1 <= nProps <= 268435455
// note: 268435455 == INT32_MAX / sizeof(FontPropRec) == 0x7fffffff / 8
struct property_t {
int32 name; // offset from &string[0] (0 <= name)
bool8 isStringProp; // is this property is string ? (0 or 1)
int32 value; // offset from &string[0] if isStringProp is 1
} props[nProps];
byte8 dummy[3 - ((sizeof(props) + 3) % 4)]; // padding
int32 stringSize; // 0 <= stringSize
char8 string[stringSize]; // pointed by property_t::{name,value}
/*** SECTION ***/
// old accelerators section (tables[i].type = PCF_ACCELERATORS)
/* if PCF_BDF_ACCELERATORS section exists, this section is omitted. */
format32_little format; // format.id = PCF_DEFAULT_FORMAT
// // or PCF_ACCEL_W_INKBOUNDS
bool8 noOverlap;
bool8 constantMetrics;
bool8 terminalFont;
bool8 constantWidth;
bool8 inkInside;
bool8 inkMetrics;
bool8 drawDirection;
bool8 dummy; // padding
int32 fontAscent;
int32 fontDescent;
int32 maxOverlap;
metric_t minBounds;
metric_t maxBounds;
#if format.id == PCF_ACCEL_W_INKBOUNDS
metric_t ink_minBounds;
metric_t ink_maxBounds;
#endif
/*** SECTION ***/
// metrics section (tables[i].type = PCF_METRICS)
format32_little format; // format.id = PCF_DEFAULT_FORMAT
// // or PCF_COMPRESSEDMETRICS
#if format.id == PCF_DEFAULT_FORMAT
int32 nMetrics; // 0 <= nMetrics <= 134217727
// note: 134217727 == INT32_MAX / sizeof(CharInfoRec) == 0x7fffffff / 16
metric_t metrics[nMetrics];
#else
uint16 nMetrics; // 0 <= nMetrics <= 65535
compressedMetric_t cmetrics[nMetrics];
#end
/*** SECTION ***/
// bitmaps section (tables[i].type = PCF_BITMAPS)
format32_little format; // format.id = PCF_DEFAULT_FORMAT
int32 nBitmaps; // == nMetrics
uint32 bitmapOffsets[nBitmaps];
uint32 bitmapSizes[GLYPHPADOPTIONS];
byte8 bitmaps[bitmapSizes[format.glyph]];
/* if (format.bit != THIS_MACHINE.bit)
* BitOrderInvert(bitmaps, bitmapSizes[format.glyph]);
* if ((format.bit == format.byte) !=
* (THIS_MACHINE.bit == THIS_MACHINE.byte)) {
* switch (1 << (THIS_MACHINE.bit == THIS_MACHINE.byte ?
* format.scan : THIS_MACHINE.scan)) {
* case 1: break;
* case 2: TwoByteSwap(bitmaps, sizeof(bitmaps)); break;
* case 4: FourByteSwap(bitmaps, sizeof(bitmaps)); break;
* }
* } */
/* each line of the bitmaps is aligned by 1<<format.glyph bytes. */
/*** SECTION ***/
// ink metrics secion (tables[i].type = PCF_INK_METRICS)
/* this section may be omitted */
/* same as PCF_METRICS */
/*** SECTION ***/
// encodings section (tables[i].type = PCF_BDF_ENCODINGS)
format32_little format; // format.id = PCF_DEFAULT_FORMAT
uint16 firstCol;
uint16 lastCol;
uint16 firstRow;
uint16 lastRow;
uint16 defaultCh; // default char or NO_SUCH_CHAR (= -1)
uint16 encodingOffset[(lastCol-firstCol+1)*(lastRow-firstRow+1)];
/* |0 firstCol lastCol 255
* row\column |v v v v
* -----------+---------------------
* 0->|
* firstRow->|A B C D E F G H
* |I J K L M N O P
* |Q R S T U V W X
* lastRow->|Y Z a b c d e f
* 255->|
*
* The charcode MAKE_CHARCODE(firstCol, firstRow)'s metrics is metrics[B].
* And, encodingOffset={ B,C,D,E,F,G, J,K,L,M,N,O, R,S,T,U,V,W, Z,a,b,c,d,e, };
* If Z == 0xffff, then the charcode MAKE_CHARCODE(firstCol, lastRow) does not
* exist. */
/*** SECTION ***/
// swidths section (tables[i].type = PCF_SWIDTHS)
/* this section may be omitted */
format32_little format; // format.id = PCF_DEFAULT_FORMAT
int32 nSwidths; // == nMetrics
int32 swidths[nSwidths];
/*** SECTION ***/
// glyph names section (tables[i].type = PCF_GLYPH_NAMES)
/* this section may be omitted */
format32_little format; // format.id = PCF_DEFAULT_FORMAT
int32 nGlyphNames; // == nMetrics
int32 glyphNameOffsets[nGlyphNames]; // offset from &glyph_names[0]
int32 glyphNamesSize;
char8 glyphNames[glyphNamesSize]; // pointed by glyphNameOffsets[]
/*** SECTION ***/
// BDF style accelerators section (tables[i].type = PCF_BDF_ACCELERATORS)
/* if PCF_ACCELERATORS section exists, this section is omitted. */
/* same as PCF_ACCELERATORS */
// end of the PCF file ////////////////////////////////////////////////////////