2 * Copyright 2008 Department of Mathematical Sciences, New Mexico State University
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * DEPARTMENT OF MATHEMATICAL SCIENCES OR NEW MEXICO STATE UNIVERSITY BE
18 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
19 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 /**************************************************************************
32 * PSF1 Macros and values.
34 **************************************************************************/
37 * Macros that specify the indexes of the mode and height fields of the header
38 * info passed to the PSF1 loader.
40 #define _BDF_PSF1MODE 2
41 #define _BDF_PSF1HEIGHT 3
44 * Flags which can appear in the third byte of the header (PSF1 mode). HAS512
45 * means the font contains up to 512 glyphs. Otherwise the font has 256
46 * glyphs. HASTAB and HASSEQ indicate the glyphs are followed by a Unicode
49 * The HASTAB and HASSEQ flags appear to be essentially equivalent.
51 #define _BDF_PSF1_HAS512 0x01
52 #define _BDF_PSF1_HASTAB 0x02
53 #define _BDF_PSF1_HASSEQ 0x04
55 /**************************************************************************
59 **************************************************************************/
61 #define _BDF_PSF2_HASTAB 0x01
64 * Little endian versions of the PSF magic numbers.
66 unsigned char _bdf_psf1magic[] = {0x36, 0x04};
67 unsigned char _bdf_psf2magic[] = {0x72, 0xb5, 0x4a, 0x86};
70 * The special header for PSF fonts that specify a list of partial
73 char _bdf_psfcombined[] = {'#', ' ', 'c', 'o'};
76 * The PSF2 internal header.
80 unsigned int headersize;
88 /**************************************************************************
92 **************************************************************************/
94 #define _swap_endian(n) ((n) >> 16) | (((n) & 0xffff) << 16)
97 _bdf_psf_load_map(FILE *in, bdf_font_t *font, int psf2, int *res)
99 int i, more, c0, c1, cnt;
101 unsigned char buf[4];
106 while ((c0 = getc(in)) >= 0) {
108 * If we are still reading bytes after the end of the glyphs,
109 * the table is too int.
111 if (gp == font->glyphs + font->glyphs_used)
112 return BDF_PSF_LONG_TABLE;
117 if ((c1 = getc(in)) < 0)
118 return BDF_PSF_SHORT_TABLE;
119 if (bdf_little_endian())
120 code = (c1 << 8) | (c0 & 0xff);
122 code = (c0 << 8) | (c1 & 0xff);
127 if (code != 0xffff) {
129 buf[cnt++] = code & 0xff;
130 else if (code < 0x800) {
131 buf[cnt++] = 0xc0 | (code >> 6);
132 buf[cnt++] = 0x80 | (code & 0x3f);
133 } else if (code < 0x10000) {
134 buf[cnt++] = 0xe0 | (code >> 12);
135 buf[cnt++] = 0x80 | ((code >> 6) & 0x3f);
136 buf[cnt++] = 0x80 | (code & 0x3f);
137 } else if (code < 0x200000) {
138 buf[cnt++] = 0xf0 | (code >> 18);
139 buf[cnt++] = 0x80 | ((code >> 12) & 0x3f);
140 buf[cnt++] = 0x80 | ((code >> 6) & 0x3f);
141 buf[cnt++] = 0x80 | (code & 0x3f);
142 } else if (code < 0x4000000) {
143 buf[cnt++] = 0xf8 | (code >> 24);
144 buf[cnt++] = 0x80 | ((code >> 18) & 0x3f);
145 buf[cnt++] = 0x80 | ((code >> 12) & 0x3f);
146 buf[cnt++] = 0x80 | ((code >> 6) & 0x3f);
147 buf[cnt++] = 0x80 | (code & 0x3f);
148 } else if (code < 0x7fffffff) {
149 buf[cnt++] = 0xfc | (code >> 30);
150 buf[cnt++] = 0x80 | ((code >> 24) & 0x3f);
151 buf[cnt++] = 0x80 | ((code >> 18) & 0x3f);
152 buf[cnt++] = 0x80 | ((code >> 12) & 0x3f);
153 buf[cnt++] = 0x80 | ((code >> 6) & 0x3f);
154 buf[cnt++] = 0x80 | (code & 0x3f);
160 if (c0 < 0xfd && (c0 & 0x80) != 0) {
162 * Only look for more if the byte is not 0xfe or 0xff,
166 if ((c0 & 0xe0) == 0xc0)
168 else if ((c0 & 0xf0) == 0xe0)
170 else if ((c0 & 0xf0) == 0xf0)
173 for (i = 0; i < more; i++) {
174 if ((c0 = getc(in)) < 0)
175 return BDF_PSF_SHORT_TABLE;
177 return BDF_PSF_CORRUPT_UTF8;
182 if (buf[0] != 0xff) {
183 if (gp->unicode.map_used + cnt > gp->unicode.map_size) {
184 more = ((cnt >> 2) + ((cnt & 3) ? 1 : 0)) << 2;
185 if (gp->unicode.map_size == 0)
186 gp->unicode.map = (unsigned char *)
187 malloc(sizeof(unsigned char) * more);
189 gp->unicode.map = (unsigned char *)
190 realloc((char *) gp->unicode.map,
191 sizeof(unsigned char) *
192 (gp->unicode.map_size + more));
193 gp->unicode.map_size += more;
195 (void) memcpy((char *) (gp->unicode.map + gp->unicode.map_used),
196 (char *) buf, sizeof(unsigned char) * cnt);
197 gp->unicode.map_used += cnt;
206 _bdf_psf_dump_map(FILE *out, bdf_font_t *font, bdf_glyphlist_t *glyphs)
209 unsigned int i, nglyphs, n;
211 unsigned char *map, *map_end;
214 nglyphs = (glyphs->glyphs_used > 512) ? 512 : glyphs->glyphs_used;
215 for (i = 0, gp = glyphs->glyphs; i < nglyphs; i++, gp++) {
218 fprintf(out, "0x%03x", i);
220 fprintf(out, "0x%02x", i);
222 map = gp->unicode.map;
223 map_end = map + gp->unicode.map_used;
226 while (map < map_end) {
236 * Convert from UTF-8 to UTF-32.
238 if ((*map & 0x80) == 0)
240 * One byte character.
242 code = (unsigned short) *map;
243 else if (*map < 0xe0) {
245 * Two byte character.
247 if (map + 2 >= map_end)
248 return BDF_PSF_CORRUPT_UTF8;
249 code = ((*map & 0x1f) << 6) | (*(map + 1) & 0x3f);
251 } else if (*map < 0xf0) {
253 * Three byte character.
255 if (map + 3 >= map_end)
256 return BDF_PSF_CORRUPT_UTF8;
257 code = ((*map & 0x0f) << 12) |
258 ((*(map + 1) & 0x3f) << 6) | (*(map + 2) & 0x3f);
260 } else if (*map < 0xf8) {
262 * Four byte character.
264 if (map + 4 >= map_end)
265 return BDF_PSF_CORRUPT_UTF8;
266 code = ((*map & 0x07) << 18) |
267 ((*(map + 1) & 0x3f) << 12) |
268 ((*(map + 2) & 0x3f) << 6) | (*(map + 3) & 0x3f);
270 } else if (*map < 0xfc) {
272 * Five byte character.
274 if (map + 5 >= map_end)
275 return BDF_PSF_CORRUPT_UTF8;
276 code = ((*map & 0x03) << 24) |
277 ((*(map + 1) & 0x3f) << 18) |
278 ((*(map + 2) & 0x3f) << 12) |
279 ((*(map + 3) & 0x3f) << 6) |
282 } else if (*map < 0xfe) {
284 * Six byte character.
286 if (map + 6 >= map_end)
287 return BDF_PSF_CORRUPT_UTF8;
288 code = ((*map & 0x01) << 30) |
289 ((*(map + 1) & 0x3f) << 24) |
290 ((*(map + 2) & 0x3f) << 18) |
291 ((*(map + 3) & 0x3f) << 12) |
292 ((*(map + 4) & 0x3f) << 6) |
297 * Print the code(s). If we are printing the first one,
298 * then print a tab, otherwise we are printing separating
301 if (map == gp->unicode.map)
304 putc(((seq == 1) ? ',' : ' '), out);
306 fprintf(out, "U+%04X", code);
308 fprintf(out, "U+%06X", code);
314 * Print the line separator.
319 * Free the current glyph storage.
324 free((char *) gp->bitmap);
325 if (gp->unicode.map_size > 0)
326 free((char *) gp->unicode.map);
330 * Free the storage for the glyph list.
332 if (glyphs->glyphs_size > 0)
333 free((char *) glyphs->glyphs);
338 /**************************************************************************
342 **************************************************************************/
345 * Return an array of strings with the Unicode encodings already formatted for
349 _bdf_psf_unpack_mapping(bdf_psf_unimap_t *unimap, int *num_seq)
353 unsigned char *mp, *ep;
361 if (unimap == 0 || unimap->map_used == 0)
365 * This routine will calculate the amount of storage is needed to be
366 * allocated as one big block so an array of strings can be returned.
367 * That way it can be deallocated as a single item by the caller.
372 * Count the total number of characters and sequences at the same time.
375 ep = mp + unimap->map_used;
406 * The block of storage will need this many bytes for pointers to the
409 sum = sizeof(unsigned char *) * ns;
412 * Each character uses up to 8 bytes in U+XXXXXX form and each is followed
413 * by either space or a null, so each is basically nine bytes including
418 list = (char **) malloc(sum);
419 lp = (char *) (list + ns);
422 * Now generate the codes one at a time.
432 * The last thing added was a sequence, so move up to the
445 * Convert from UTF-8 to UTF-32.
449 * One byte character.
451 code = (unsigned short) *mp;
452 else if (*mp < 0xe0) {
454 * Two byte character.
456 code = ((*mp & 0x1f) << 6) | (*(mp + 1) & 0x3f);
458 } else if (*mp < 0xf0) {
460 * Three byte character.
462 code = ((*mp & 0x0f) << 12) |
463 ((*(mp + 1) & 0x3f) << 6) | (*(mp + 2) & 0x3f);
465 } else if (*mp < 0xf8) {
467 * Four byte character.
469 code = ((*mp & 0x07) << 18) |
470 ((*(mp + 1) & 0x3f) << 12) |
471 ((*(mp + 2) & 0x3f) << 6) | (*(mp + 3) & 0x3f);
473 } else if (*mp < 0xfc) {
475 * Five byte character.
477 code = ((*mp & 0x03) << 24) |
478 ((*(mp + 1) & 0x3f) << 18) |
479 ((*(mp + 2) & 0x3f) << 12) |
480 ((*(mp + 3) & 0x3f) << 6) |
483 } else if (*mp < 0xfe) {
485 * Six byte character.
487 code = ((*mp & 0x01) << 30) |
488 ((*(mp + 1) & 0x3f) << 24) |
489 ((*(mp + 2) & 0x3f) << 18) |
490 ((*(mp + 3) & 0x3f) << 12) |
491 ((*(mp + 4) & 0x3f) << 6) |
503 sprintf(lp, "U+%04X", code);
505 sprintf(lp, "U+%06X", code);
517 * Routine used to insure the list of mappings is in ascending order
518 * by length of string.
521 cmplen(const void *a, const void *b)
524 char *as = *((char **)a);
525 char *bs = *((char **)b);
527 n = strlen(as) - strlen(bs);
528 return (n) ? n : strcmp(as, bs);
532 * Taking a list of strings, generate a packed UTF-8 representation to
533 * be stored back into a Unicode map.
536 _bdf_psf_pack_mapping(char **list, int len, int encoding,
537 bdf_psf_unimap_t *map)
539 int i, j, ncodes, bytes = 3;
541 unsigned int codes[128];
543 if (list == 0 || len == 0 || map == 0)
549 * First thing that needs to be done is to make sure the list is sorted by
550 * length so the single character mappings come first.
552 qsort((char *) list, len, sizeof(char *), cmplen);
554 for (i = 0; i < len; i++) {
559 * Skip anything that isn't expected.
561 while (*lp && *lp != 'U' && *lp != 'u' && *lp != '0')
565 codes[ncodes] = _bdf_atoul(lp, &elp, 16);
568 * Determine how many UTF-8 bytes the current code will
571 if (codes[ncodes] < 0x80)
573 else if (codes[ncodes] < 0x800)
575 else if (codes[ncodes] < 0x10000)
577 else if (codes[ncodes] < 0x200000)
579 else if (codes[ncodes] < 0x4000000)
581 else if (codes[ncodes] < 0x7fffffff)
587 * Make sure there is enough room in the map for this number of bytes.
588 * The number includes the encoding and the 0xff at the end on the
591 if (map->map_used + bytes > map->map_size) {
592 if (map->map_size == 0)
593 map->map = (unsigned char *)
594 malloc(sizeof(unsigned char *) * 128);
596 map->map = (unsigned char *)
597 realloc((char *) map->map,
598 sizeof(unsigned char) * (map->map_size + 128));
599 map->map_size += 128;
604 * Have to increment the number of bytes by 1 to include the
605 * PSF2 sequence marker.
607 map->map[map->map_used++] = 0xfe;
610 * Go through the codes and convert to UTF-8.
612 for (j = 0; j < ncodes; j++) {
614 map->map[map->map_used++] = (codes[j] & 0x7f);
615 else if (codes[j] < 0x800) {
616 map->map[map->map_used++] = 0xc0 | ((codes[j] >> 6) & 0xff);
617 map->map[map->map_used++] = 0x80 | (codes[j] & 0x3f);
618 } else if (codes[j] < 0x10000) {
619 map->map[map->map_used++] = 0xe0 | ((codes[j] >> 12) & 0xff);
620 map->map[map->map_used++] = 0x80 | ((codes[j] >> 6) & 0x3f);
621 map->map[map->map_used++] = 0x80 | (codes[j] & 0x3f);
622 } else if (codes[j] < 0x200000) {
623 map->map[map->map_used++] = 0xf0 | ((codes[j] >> 18) & 0xff);
624 map->map[map->map_used++] = 0x80 | ((codes[j] >> 12) & 0x3f);
625 map->map[map->map_used++] = 0x80 | ((codes[j] >> 6) & 0x3f);
626 map->map[map->map_used++] = 0x80 | (codes[j] & 0x3f);
627 } else if (codes[j] < 0x4000000) {
628 map->map[map->map_used++] = 0xf8 | ((codes[j] >> 24) & 0xff);
629 map->map[map->map_used++] = 0x80 | ((codes[j] >> 18) & 0xff);
630 map->map[map->map_used++] = 0x80 | ((codes[j] >> 12) & 0x3f);
631 map->map[map->map_used++] = 0x80 | ((codes[j] >> 6) & 0x3f);
632 map->map[map->map_used++] = 0x80 | (codes[j] & 0x3f);
633 } else if (codes[j] < 0x7fffffff) {
634 map->map[map->map_used++] = 0xfc | ((codes[j] >> 30) & 0xff);
635 map->map[map->map_used++] = 0x80 | ((codes[j] >> 24) & 0xff);
636 map->map[map->map_used++] = 0x80 | ((codes[j] >> 18) & 0xff);
637 map->map[map->map_used++] = 0x80 | ((codes[j] >> 12) & 0x3f);
638 map->map[map->map_used++] = 0x80 | ((codes[j] >> 6) & 0x3f);
639 map->map[map->map_used++] = 0x80 | (codes[j] & 0x3f);
649 bdf_load_psf(FILE *in, unsigned char *magic, bdf_options_t *opts,
650 bdf_callback_t callback, void *data, int *awidth)
653 unsigned short dwidth, swidth;
657 bdf_callback_struct_t cb;
661 * Check options for loading the Unicode table or not.
664 if (*magic == 0x36) {
670 hdr.height = hdr.bpc = (int) magic[_BDF_PSF1HEIGHT];
671 hdr.length = (magic[_BDF_PSF1MODE] & _BDF_PSF1_HAS512) ? 512 : 256;
672 hdr.flags = (magic[_BDF_PSF1MODE] & _BDF_PSF1_HASTAB) ?
673 _BDF_PSF2_HASTAB : 0;
678 fread((char *) &hdr, sizeof(_bdf_psfhdr_t), 1, in);
679 if (!bdf_little_endian()) {
681 * Need to convert all the integers to big endian.
683 hdr.version = _swap_endian(hdr.version);
684 hdr.headersize = _swap_endian(hdr.headersize);
685 hdr.flags = _swap_endian(hdr.flags);
686 hdr.length = _swap_endian(hdr.length);
687 hdr.bpc = _swap_endian(hdr.bpc);
688 hdr.height = _swap_endian(hdr.height);
689 hdr.width = _swap_endian(hdr.width);
694 * The point size of the font will be the height, the resolution will
695 * default to 72dpi, and the spacing will default to character cell.
697 fp = bdf_new_font(0, (int) hdr.height, 72, 72, BDF_CHARCELL, 1);
700 * Force the bits per pixel to be 1.
705 * Set the font width and average width.
707 *awidth = fp->bbx.width = hdr.width;
710 * Set the rest of the font bounding box parameters.
712 fp->font_ascent = fp->bbx.ascent;
713 fp->font_descent = fp->bbx.descent;
717 * MAY NOT BE NEEDED ANY MORE.
721 * Adjust the ascent and descent by hand for point sizes other than 16.
723 if (hdr.height != 16) {
730 * Default the font ascent and descent to that of the bounding box.
732 fp->font_ascent = fp->bbx.ascent;
733 fp->font_descent = fp->bbx.descent;
736 * Allocate the expected number of glyphs.
738 fp->glyphs_size = hdr.length;
739 fp->glyphs = (bdf_glyph_t *) malloc(sizeof(bdf_glyph_t) * fp->glyphs_size);
740 (void) memset((char *) fp->glyphs, 0,
741 sizeof(bdf_glyph_t) * fp->glyphs_size);
744 * Determine the default scalable and device width for each character.
746 dwidth = fp->bbx.width;
747 swidth = (unsigned short)
748 (((double) dwidth) * 72000.0) /
749 ((double) fp->point_size * fp->resolution_x);
752 * Set up to call the callback.
755 cb.reason = BDF_LOAD_START;
757 cb.total = fp->glyphs_size;
758 (*callback)(&cb, data);
762 * Now load the glyphs, assigning a default encoding.
764 for (i = 0, gp = fp->glyphs; i < fp->glyphs_size; i++, gp++) {
768 (void) memcpy((char *) &gp->bbx, (char *) &fp->bbx, sizeof(bdf_bbx_t));
771 gp->bitmap = (unsigned char *) malloc(hdr.bpc);
772 fread((char *) gp->bitmap, hdr.bpc, 1, in);
776 * Call the callback if indicated.
779 cb.reason = BDF_LOADING;
780 cb.total = fp->glyphs_size;
781 cb.current = fp->glyphs_used;
782 (*callback)(&cb, data);
787 * Now load the Unicode mapping table if it exists.
789 if (hdr.flags & _BDF_PSF2_HASTAB) {
791 switch (_bdf_psf_load_map(in, fp, (*magic == 0x72), &enc)) {
792 case BDF_PSF_SHORT_TABLE:
793 sprintf(msgbuf, "PSF Unicode table too short at 0x%04X (%d).",
794 (unsigned short) (enc & 0xffff), enc);
796 case BDF_PSF_LONG_TABLE:
797 strcpy(msgbuf, "PSF Unicode table too int.");
799 case BDF_PSF_CORRUPT_UTF8:
800 sprintf(msgbuf, "PSF UTF-8 sequence corrupt at 0x%04X (%d).",
801 (unsigned short) (enc & 0xffff), enc);
803 case BDF_PSF_BUFFER_OVRFL:
804 sprintf(msgbuf, "PSF mapping buffer overflow at 0x%04X (%d).",
805 (unsigned short) (enc & 0xffff), enc);
809 _bdf_add_acmsg(fp, msgbuf, strlen(msgbuf));
812 sprintf(msgbuf, "Font converted from PSF%c to BDF.",
813 (*magic == 0x36) ? '1' : '2');
814 _bdf_add_comment(fp, msgbuf, 32);
815 _bdf_add_acmsg(fp, msgbuf, 32);
821 * Exports all PSF fonts in PSF2 format for now. start and end are
822 * supplied when a partial font needs to be created.
825 bdf_export_psf(FILE *out, bdf_font_t *font, bdf_options_t *opts, int start,
828 unsigned int i, nglyphs, flags;
832 bdf_glyphlist_t glyphs;
835 if (font->glyphs_used == 0)
836 return BDF_EMPTY_FONT;
839 * This routine only exports from CHARCELL and MONOWIDTH fonts, padding
840 * the glyphs as it writes.
842 if (font->spacing == BDF_PROPORTIONAL)
843 return BDF_EMPTY_FONT;
846 return BDF_BAD_RANGE;
849 * Make a copy of the glyphs so we can get the smallest bounding box for
850 * the glyphs being exported. This also does a bit of range checking.
852 (void) memset((char *) &glyphs, 0, sizeof(bdf_glyphlist_t));
853 bdf_copy_glyphs(font, start, end, &glyphs, 0);
856 * At this point, if only the Unicode table is desired, then
857 * call the routine that prints the plain text version.
859 if ((opts->psf_flags == BDF_PSF_UNIMAP))
860 return _bdf_psf_dump_map(out, font, &glyphs);
863 * Set up the temporary font so glyph padding will happen like it is
866 tmpfont.bpp = glyphs.bpp;
867 (void) memcpy((char *) &tmpfont.bbx, (char *) &glyphs.bbx,
871 * Create the header. The extra 4 on the header size account
872 * for the magic number.
874 * Number of glyphs and flags have to be calculated properly before writing
875 * so it isn't necessary to go back and rewrite the header after the font
876 * has been written. That causes havoc when writing to stdout.
878 hdr.version = hdr.flags = 0;
879 hdr.headersize = sizeof(_bdf_psfhdr_t) + 4;
880 hdr.length = (glyphs.glyphs_used > 512) ? 512 : glyphs.glyphs_used;
881 hdr.width = glyphs.bbx.width;
882 hdr.height = glyphs.bbx.height;
883 hdr.bpc = hdr.height * ((hdr.width + 7) >> 3);
886 * Determine if the font will have a Unicode mapping table.
888 for (i = 0; i < hdr.length; i++) {
889 if (glyphs.glyphs[i].unicode.map_used > 0) {
890 hdr.flags |= _BDF_PSF2_HASTAB;
896 * Save these values so it doesn't get whacked in an endian conversion.
898 nglyphs = hdr.length;
902 * Set up a structure for padding glyphs to cell boundaries.
904 cell.bytes = hdr.bpc;
905 cell.bitmap = (unsigned char *) malloc(cell.bytes);
906 (void) memcpy((char *) &cell.bbx, (char *) &glyphs.bbx, sizeof(bdf_bbx_t));
908 if (!bdf_little_endian()) {
910 * Swap the integers into little endian order before writing.
912 hdr.version = _swap_endian(hdr.version);
913 hdr.headersize = _swap_endian(hdr.headersize);
914 hdr.flags = _swap_endian(hdr.flags);
915 hdr.length = _swap_endian(hdr.length);
916 hdr.bpc = _swap_endian(hdr.bpc);
917 hdr.height = _swap_endian(hdr.height);
918 hdr.width = _swap_endian(hdr.width);
924 fwrite((char *) _bdf_psf2magic, sizeof(unsigned char), 4, out);
925 fwrite((char *) &hdr, sizeof(_bdf_psfhdr_t), 1, out);
928 * Generate the glyphs, padding them out to the dimensions of the
931 for (i = 0, gp = glyphs.glyphs; i < nglyphs; i++, gp++) {
933 * We only need to do cropping on CHARCELL glyphs because MONOWIDTH
934 * glyphs are already cropped to their minimum dimensions.
936 if (font->spacing == BDF_CHARCELL)
937 _bdf_crop_glyph(&tmpfont, gp);
938 _bdf_pad_cell(&tmpfont, gp, &cell);
939 fwrite((char *) cell.bitmap, sizeof(unsigned char), cell.bytes, out);
943 * Now generate the Unicode table if called for.
945 if ((opts->psf_flags & BDF_PSF_UNIMAP) && (flags & _BDF_PSF2_HASTAB)) {
946 for (gp = glyphs.glyphs, i = 0; i < nglyphs; i++, gp++) {
947 if (gp->unicode.map_used > 0)
948 fwrite((char *) gp->unicode.map, sizeof(unsigned char),
949 gp->unicode.map_used, out);
955 * Finally, dispose of the glyph copies.
957 for (i = 0, gp = glyphs.glyphs; i < glyphs.glyphs_used; i++, gp++) {
961 free((char *) gp->bitmap);
962 if (gp->unicode.map_size > 0)
963 free((char *) gp->unicode.map);
965 if (glyphs.glyphs_size > 0)
966 free((char *) glyphs.glyphs);