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;
14 bool doShift (uint ch
) {
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;
32 while (wdt
>= 0 && !hasPixelAtX(ch
, wdt
)) --wdt
;
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
45 //writeln(ch, " : ", wdt);
46 fo
.writeNum
!ubyte(cast(ubyte)wdt
);
47 fo
.rawWriteExact(vlFont6
[ch
*8..ch
*8+8]);
52 auto fo
= VFile("zxpfontkoi.fnt", "w");
53 foreach (immutable ch
; 0..256) processChar(fo
, ch
);