1 /* $XConsortium: sptobdf.c,v 1.5 94/04/17 20:17:51 dpw Exp $ */
3 * Copyright 1990, 1991 Network Computing Devices;
4 * Portions Copyright 1987 by Digital Equipment Corporation
6 * Permission to use, copy, modify, distribute, and sell this software and its
7 * documentation for any purpose is hereby granted without fee, provided that
8 * the above copyright notice appear in all copies and that both that
9 * copyright notice and this permission notice appear in supporting
10 * documentation, and that the names of Network Computing Devices and
11 * Digital not be used in advertising or publicity pertaining to
12 * distribution of the software without specific, written prior permission.
13 * Network Computing Devices and Digital make no representations about the
14 * suitability of this software for any purpose. It is provided "as is"
15 * without express or implied warranty.
17 * NETWORK COMPUTING DEVICES AND DIGITAL DISCLAIM ALL WARRANTIES WITH
18 * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
19 * AND FITNESS, IN NO EVENT SHALL NETWORK COMPUTING DEVICES OR DIGITAL BE
20 * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
21 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
22 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
23 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
30 Copyright (c) 1987, 1994 X Consortium
32 Permission is hereby granted, free of charge, to any person obtaining
33 a copy of this software and associated documentation files (the
34 "Software"), to deal in the Software without restriction, including
35 without limitation the rights to use, copy, modify, merge, publish,
36 distribute, sublicense, and/or sell copies of the Software, and to
37 permit persons to whom the Software is furnished to do so, subject to
38 the following conditions:
40 The above copyright notice and this permission notice shall be included
41 in all copies or substantial portions of the Software.
43 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
44 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
45 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
46 IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
47 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
48 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
49 OTHER DEALINGS IN THE SOFTWARE.
51 Except as contained in this notice, the name of the X Consortium shall
52 not be used in advertising or otherwise to promote the sale, use or
53 other dealings in this Software without prior written authorization
54 from the X Consortium.
59 * Speedo outline to BFD format converter
77 static char line_of_bits[MAX_BITS + 1];
80 static ufix16 char_index,
83 static buff_t char_data;
84 static ufix8 *f_buffer,
86 static ufix16 mincharsize;
88 static fix15 bit_width,
102 }; /* Font decryption key */
105 static char *progname;
106 static char *fontname = NULL;
107 static char *fontfile = NULL;
109 static int point_size = 120;
110 static int x_res = 72;
111 static int y_res = 72;
112 static int quality = 0;
113 static int iso_encoding = 1;
115 static int num_props = 7;
116 static int stretch = 120;
118 static specs_t specs;
120 static void dump_header();
125 fprintf(stderr, "Usage: %s [-xres x resolution] [-yres y resolution]\n\t[-ptsize pointsize] [-fn fontname] [-q quality (0-1)] fontfile\n", progname);
126 fprintf(stderr, "Where:\n");
127 fprintf(stderr, "-xres specifies the X resolution (72)\n");
128 fprintf(stderr, "-yres specifies the Y resolution (72)\n");
129 fprintf(stderr, "-pts specifies the pointsize in decipoints (120)\n");
130 fprintf(stderr, "-fn specifies the font name (full Bitstream name)\n");
131 fprintf(stderr, "-q specifies the font quality [0-1] (0)\n");
132 fprintf(stderr, "\n");
143 tmp = (tmp << 8) + *ptr;
154 tmp = (tmp << 8) + *ptr++;
155 tmp = (tmp << 8) + *ptr++;
156 tmp = (tmp << 8) + *ptr;
167 for (i = 1; i < ac; i++) {
168 if (!strncmp(av[i], "-xr", 3)) {
170 x_res = atoi(av[++i]);
173 } else if (!strncmp(av[i], "-yr", 3)) {
175 y_res = atoi(av[++i]);
178 } else if (!strncmp(av[i], "-pt", 3)) {
180 point_size = atoi(av[++i]);
183 } else if (!strncmp(av[i], "-fn", 3)) {
188 } else if (!strncmp(av[i], "-q", 2)) {
190 quality = atoi(av[++i]);
193 } else if (!strncmp(av[i], "-st", 3)) {
195 stretch = atoi(av[++i]);
198 } else if (!strncmp(av[i], "-noni", 5)) {
200 } else if (*av[i] == '-') {
218 int first_char_index,
222 process_args(argc, argv);
223 fp = fopen(fontfile, "r");
225 fprintf(stderr, "No such font file, \"%s\"\n", fontfile);
228 if (fread(tmp, sizeof(ufix8), 16, fp) != 16) {
229 fprintf(stderr, "error reading \"%s\"\n", fontfile);
232 minbufsize = (ufix32) read_4b(tmp + FH_FBFSZ);
233 f_buffer = (ufix8 *) malloc(minbufsize);
235 fprintf(stderr, "can't get %x bytes of memory\n", minbufsize);
238 fseek(fp, (ufix32) 0, 0);
240 if (fread(f_buffer, sizeof(ufix8), (ufix16) minbufsize, fp) != minbufsize) {
241 fprintf(stderr, "error reading file \"%s\"\n", fontfile);
244 mincharsize = read_2b(f_buffer + FH_CBFSZ);
246 c_buffer = (ufix8 *) malloc(mincharsize);
248 fprintf(stderr, "can't get %x bytes for char buffer\n", mincharsize);
255 font.no_bytes = minbufsize;
257 if ((cust_no = sp_get_cust_no(font)) != CUS0) {
258 fprintf(stderr, "Non-standard encryption for \"%s\"\n", fontfile);
263 first_char_index = read_2b(f_buffer + FH_FCHRF);
264 num_chars = read_2b(f_buffer + FH_NCHRL);
267 /* Note that point size is in decipoints */
269 /* XXX beware of overflow */
270 specs.xxmult = point_size * x_res / 720 * (1 << 16);
271 specs.xymult = 0L << 16;
272 specs.xoffset = 0L << 16;
273 specs.yxmult = 0L << 16;
274 specs.yymult = point_size * y_res / 720 * (1 << 16);
275 specs.yoffset = 0L << 16;
281 specs.flags = MODE_SCREEN;
284 specs.flags = MODE_2D;
287 fprintf(stderr, "bogus quality value %d\n", quality);
290 specs.out_info = NULL;
293 fontname = (char *) (f_buffer + FH_FNTNM);
296 num_chars = num_iso_chars;
297 dump_header(num_chars);
299 if (!sp_set_specs(&specs)) {
300 fprintf(stderr, "can't set specs\n");
303 for (i = 0; i < num_iso_chars * 2; i += 2) {
304 char_index = iso_map[i + 1];
305 char_id = iso_map[i];
306 if (!sp_make_char(char_index)) {
307 fprintf(stderr, "can't make char %x\n", char_index);
311 for (i = 0; i < num_chars; i++) {
312 char_index = i + first_char_index;
313 char_id = sp_get_char_id(char_index);
315 if (!sp_make_char(char_index)) {
316 fprintf(stderr, "can't make char %x\n", char_index);
330 dump_header(num_chars)
341 xmin = read_2b(f_buffer + FH_FXMIN);
342 ymin = read_2b(f_buffer + FH_FYMIN);
343 xmax = read_2b(f_buffer + FH_FXMAX);
344 ymax = read_2b(f_buffer + FH_FYMAX);
345 pixel_size = point_size * x_res / 720;
347 printf("STARTFONT 2.1\n");
349 printf("COMMENT Generated from Bitstream Speedo outlines via sptobdf\n");
351 printf("FONT %s\n", fontname);
352 printf("SIZE %d %d %d\n", pixel_size, x_res, y_res);
353 printf("FONTBOUNDINGBOX %d %d %d %d\n", xmin, ymin, xmax, ymax);
354 printf("STARTPROPERTIES %d\n", num_props);
356 printf("RESOLUTION_X %d\n", x_res);
357 printf("RESOLUTION_Y %d\n", y_res);
358 printf("POINT_SIZE %d\n", point_size);
359 printf("PIXEL_SIZE %d\n", pixel_size);
360 printf("COPYRIGHT \"%s\"\n", f_buffer + FH_CPYRT);
362 /* do some stretching here so that its isn't too tight */
363 pixel_size = pixel_size * stretch / 100;
364 ascent = pixel_size * 764 / 1000; /* 764 == EM_TOP */
365 descent = pixel_size - ascent;
366 printf("FONT_ASCENT %d\n", ascent);
367 printf("FONT_DESCENT %d\n", descent);
369 printf("ENDPROPERTIES\n");
370 printf("CHARS %d\n", num_chars);
374 sp_load_char_data(file_offset, num, cb_offset)
379 if (fseek(fp, (long) file_offset, (int) 0)) {
380 fprintf(stderr, "can't seek to char\n");
384 if ((num + cb_offset) > mincharsize) {
385 fprintf(stderr, "char buf overflow\n");
389 if (fread((c_buffer + cb_offset), sizeof(ufix8), num, fp) != num) {
390 fprintf(stderr, "can't get char data\n");
393 char_data.org = (ufix8 *) c_buffer + cb_offset;
394 char_data.no_bytes = num;
400 * Called by Speedo character generator to report an error.
402 * Since character data not available is one of those errors
403 * that happens many times, don't report it to user
411 fprintf(stderr, "Insufficient font data loaded\n");
414 fprintf(stderr, "Transformation matrix out of range\n");
417 fprintf(stderr, "Font format error\n");
420 fprintf(stderr, "Requested specs not compatible with output module\n");
423 fprintf(stderr, "Intelligent transformation requested but not supported\n");
426 fprintf(stderr, "Unsupported output mode requested\n");
429 fprintf(stderr, "Extended font loaded but only compact fonts supported\n");
432 fprintf(stderr, "Font specs not set prior to use of font\n");
437 fprintf(stderr, "Track kerning data not available()\n");
440 fprintf(stderr, "Pair kerning data not available()\n");
443 fprintf(stderr, "report_error(%d)\n", n);
449 sp_open_bitmap(x_set_width, y_set_width, xorg, yorg, xsize, ysize)
467 off_horz = (fix15) ((xorg + 32768L) >> 16);
468 off_vert = (fix15) ((yorg + 32768L) >> 16);
470 if (bit_width > MAX_BITS) {
473 fprintf(stderr, "char wider than max bits -- truncated\n");
476 bit_width = MAX_BITS;
478 width = sp_get_char_width(char_index);
479 pix_width = width * (specs.xxmult / 65536L) +
480 ((ufix32) width * ((ufix32) specs.xxmult & 0xffff)) / 65536L;
483 width = (pix_width * 7200L) / (point_size * y_res);
485 (void) sp_get_char_bbox(char_index, &bb);
492 if ((bb.xmax - bb.xmin) != bit_width)
493 fprintf(stderr, "bbox & width mismatch 0x%x (%d) (%d vs %d)\n",
494 char_index, char_id, (bb.xmax - bb.xmin), bit_width);
495 if ((bb.ymax - bb.ymin) != bit_height)
496 fprintf(stderr, "bbox & height mismatch 0x%x (%d) (%d vs %d)\n",
497 char_index, char_id, (bb.ymax - bb.ymin), bit_height);
498 if (bb.xmin != off_horz)
499 fprintf(stderr, "x min mismatch 0x%x (%d) (%d vs %d)\n",
500 char_index, char_id, bb.xmin, off_horz);
501 if (bb.ymin != off_vert)
502 fprintf(stderr, "y min mismatch 0x%x (%d) (%d vs %d)\n",
503 char_index, char_id, bb.ymin, off_vert);
507 bit_width = bb.xmax - bb.xmin;
508 bit_height = bb.ymax - bb.ymin;
513 /* XXX kludge to handle space */
514 if (bb.xmin == 0 && bb.ymin == 0 && bb.xmax == 0 && bb.ymax == 0 &&
519 printf("STARTCHAR %d\n", char_id);
520 printf("ENCODING %d\n", char_id);
521 printf("SWIDTH %d 0\n", width);
522 printf("DWIDTH %d 0\n", pix_width);
523 printf("BBX %d %d %d %d\n", bit_width, bit_height, off_horz, off_vert);
526 for (i = 0; i < bit_width; i++) {
527 line_of_bits[i] = '.';
529 line_of_bits[bit_width] = '\0';
541 for (bit = 0; bit < bit_width; bit++) {
542 if (line[bit] == 'X')
543 byte |= (1 << (7 - (bit & 7)));
544 if ((bit & 7) == 7) {
545 printf("%02X", byte);
550 printf("%02X", byte);
556 static int trunc = 0;
561 sp_set_bitmap_bits(y, xbit1, xbit2)
568 if (xbit1 > MAX_BITS) {
571 fprintf(stderr, "run wider than max bits -- truncated\n");
576 if (xbit2 > MAX_BITS) {
579 fprintf(stderr, "run wider than max bits -- truncated\n");
585 dump_line(line_of_bits);
586 for (i = 0; i < bit_width; i++) {
587 line_of_bits[i] = '.';
594 if (y >= bit_height) {
598 "y value is larger than height 0x%x (%d) -- truncated\n",
599 char_index, char_id);
605 #endif /* BBOX_CLIP */
607 for (i = xbit1; i < xbit2; i++) {
608 line_of_bits[i] = 'X';
620 dump_line(line_of_bits);
625 while (last_y < bit_height) {
628 fprintf(stderr, "padding out height for 0x%x (%d)\n",
629 char_index, char_id);
632 for (i = 0; i < bit_width; i++) {
633 line_of_bits[i] = '.';
635 dump_line(line_of_bits);
640 dump_line(line_of_bits);