backend/net: try to prevent hangup on conntection/read failure
[chiroptera.git] / databin / zfntx_koi.d
blob7f421d181cec22f948ae2bab31ac80d45d13e74c
1 import iv.vfs.io;
3 //font6x8
4 mixin(import("koifont.d"));
7 bool hasPixelAtX (uint ch, int x) {
8 if (x < 0 || x > 7) return false;
9 immutable ubyte mask = 0x80>>x;
10 foreach (immutable ubyte b; vlFont6[ch*8..ch*8+8]) if (b&mask) return true;
11 return false;
14 bool doShift (uint ch) {
15 return
16 (ch >= 32 && ch <= 127) ||
17 (ch >= 143 && ch <= 144) ||
18 (ch >= 166 && ch <= 167) ||
19 (ch >= 192 && ch <= 255);
23 // hi nibble: lshift; lo nibble: width
24 void processChar (VFile fo, uint ch) {
25 if (doShift(ch) && !(ch >= '0' && ch <= '9')) {
26 foreach (immutable _; 0..8) {
27 if (hasPixelAtX(ch, 0)) break;
28 foreach (ref ubyte b; vlFont6[ch*8..ch*8+8]) b <<= 1;
31 int wdt = 7;
32 while (wdt >= 0 && !hasPixelAtX(ch, wdt)) --wdt;
33 ++wdt;
34 switch (ch) {
35 case 0: wdt = 8; break; // 8px space
36 case 32: wdt = 4; break; // 4px space
37 case 17: .. case 27: wdt = 8; break; // single frames
38 case 48: .. case 57: wdt = 5; break; // digits are monospaced
39 case 128: .. case 142: wdt = 8; break; // filled frames
40 case 145: .. case 151: wdt = 8; break; // filled frames
41 case 155: .. case 159: wdt = 8; break; // filled frames
42 //case 195: case 196: --wdt; break; // lowercase ce, lowercase de
43 default:
45 //writeln(ch, " : ", wdt);
46 fo.writeNum!ubyte(cast(ubyte)wdt);
47 fo.rawWriteExact(vlFont6[ch*8..ch*8+8]);
51 void main () {
52 auto fo = VFile("zxpfontkoi.fnt", "w");
53 foreach (immutable ch; 0..256) processChar(fo, ch);