]>
git.proxmox.com Git - vncterm.git/blob - genfont.c
3 Copyright (C) 2007 Proxmox Server Solutions GmbH
5 Copyright: vzdump is under GNU GPL, the GNU General Public License.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; version 2 dated June, 1991.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21 Author: Dietmar Maurer <dietmar@proxmox.com>
27 #include <zlib.h> /* read compressed console fonts */
31 /* map unicode to font */
32 static unsigned short vt_fontmap
[65536];
34 /* font glyph storage */
35 static unsigned char *vt_font_data
= NULL
;
36 static int vt_font_size
= 0;
37 static int vt_font_maxsize
= 0;
42 #define PSF_MAGIC1 0x36
43 #define PSF_MAGIC2 0x04
45 #define PSF_MODE256NOSFM 0
46 #define PSF_MODE512NOSFM 1
47 #define PSF_MODE256SFM 2
48 #define PSF_MODE512SFM 3
50 #define PSF_SEPARATOR 0xFFFF
54 unsigned char magic1
, magic2
; /* Magic number */
55 unsigned char mode
; /* PSF font mode */
56 unsigned char charheight
; /* Character size */
59 #define PSF_MAGIC_OK(x) ((x).magic1 == PSF_MAGIC1 && (x).magic2 == PSF_MAGIC2)
60 #define PSF_MODE_VALID(x) ((x) <= PSF_MODE512SFM)
61 #define PSF_MODE_HAS512(x) (((x) == 1) || ((x) == 3))
62 #define PSF_MODE_HASSFM(x) (((x) == 2) || ((x) == 3))
64 typedef unsigned short unicode
;
67 font_add_glyph (const char *data
)
70 if (vt_font_size
>= vt_font_maxsize
) {
71 vt_font_maxsize
+= 256;
72 vt_font_data
= realloc (vt_font_data
, vt_font_maxsize
*16);
75 memcpy (vt_font_data
+ vt_font_size
*16, data
, 16);
79 return vt_font_size
- 1;
83 load_psf_font (const char *filename
, int is_default
)
85 struct psf_header psfhdr
;
87 gzFile f
= gzopen(filename
, "rb");
89 fprintf (stderr
, "unable to read file %s\n", filename
);
94 if (gzread(f
, &psfhdr
, sizeof(struct psf_header
)) != sizeof(struct psf_header
)) {
95 fprintf (stderr
, "unable to read psf font header (%s)\n", filename
);
100 if (!PSF_MAGIC_OK(psfhdr
) || !PSF_MODE_VALID(psfhdr
.mode
) ||
101 !PSF_MODE_HASSFM(psfhdr
.mode
) || (psfhdr
.charheight
!= 16)) {
102 fprintf (stderr
, "no valid 8*16 psf font (%s)\n", filename
);
107 int charcount
= ((PSF_MODE_HAS512(psfhdr
.mode
)) ? 512 : 256);
109 int size
= 16*charcount
;
111 char *chardata
= (char *)malloc (size
);
113 if (size
!= gzread(f
, chardata
, size
)) {
114 fprintf (stderr
, "unable to read font character data (%s)\n", filename
);
122 for (glyph
= 0 ;glyph
< charcount
;glyph
++) {
124 while (gzread (f
, &unichar
, sizeof(unicode
)) == sizeof(unicode
) &&
125 (unichar
!= PSF_SEPARATOR
)) {
126 if (!vt_fontmap
[unichar
]) {
128 fi
= font_add_glyph (chardata
+ glyph
*16);
130 vt_fontmap
[unichar
] = fi
;
134 if (is_default
&& fi
&& glyph
< 256) {
135 vt_fontmap
[0xf000 + glyph
] = fi
;
150 printf ("static int vt_font_size = %d;\n\n", vt_font_size
);
152 printf ("static unsigned char vt_font_data[] = {\n");
153 for (i
= 0; i
< vt_font_size
; i
++) {
154 printf ("\t/* %d 0x%02x */\n", i
, i
);
155 for (j
= 0; j
< 16; j
++) {
156 unsigned char d
= vt_font_data
[i
*16+j
];
157 printf ("\t0x%02X, /* ", d
);
159 for (k
= 128; k
> 0; k
= k
>>1) {
160 printf ("%c", (d
& k
) ? '1': '0');
168 printf ("static unsigned short vt_fontmap[65536] = {\n");
169 for (i
= 0; i
< 0x0ffff; i
++) {
170 printf ("\t/* 0x%04X => */ %d,\n", i
, vt_fontmap
[i
]);
177 main (int argc
, char** argv
)
179 char empty
[] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 };
182 font_add_glyph (empty
);
184 /* font load order is only important if glyphs are redefined */
185 load_psf_font ("/usr/share/consolefonts/default8x16.psf.gz", 1); /* vga default */
186 load_psf_font ("/usr/share/consolefonts/lat1u-16.psf.gz", 0); /* Latin-1 */
187 load_psf_font ("/usr/share/consolefonts/lat2u-16.psf.gz", 0); /* Latin-2 */
188 load_psf_font ("/usr/share/consolefonts/lat4u-16.psf.gz", 0); /* Baltic */
190 load_psf_font ("/usr/share/consolefonts/iso07.f16.psf.gz", 0); /* Greek */
191 load_psf_font ("/usr/share/consolefonts/Goha-16.psf.gz", 0); /* Ethiopic */
193 /* fixme: Arabic, Japanese letters ? */
196 glob("/usr/share/consolefonts/*", GLOB_ERR
, NULL
, &globbuf
);
199 for (i
= 0; i
< globbuf
.gl_pathc
; i
++) {
200 int pc
= vt_font_size
;
201 load_psf_font (globbuf
.gl_pathv
[i
], 0);
202 if (vt_font_size
> pc
) {
203 printf ("TEST: %s %d\n", globbuf
.gl_pathv
[i
], vt_font_size
- pc
);