1 /* $XConsortium: iface.c,v 1.3 94/04/17 20:17:44 rws Exp $ */
5 Copyright 1989-1991, Bitstream Inc., Cambridge, MA.
6 You are hereby granted permission under all Bitstream propriety rights to
7 use, copy, modify, sublicense, sell, and redistribute the Bitstream Speedo
8 software and the Bitstream Charter outline font for any purpose and without
9 restrictions; provided, that this notice is left intact on all copies of such
10 software or font and that Bitstream's trademark is acknowledged as shown below
11 on all unmodified copies of such font.
13 BITSTREAM CHARTER is a registered trademark of Bitstream Inc.
16 BITSTREAM INC. DISCLAIMS ANY AND ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING
17 WITHOUT LIMITATION THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
18 PARTICULAR PURPOSE. BITSTREAM SHALL NOT BE LIABLE FOR ANY DIRECT OR INDIRECT
19 DAMAGES, INCLUDING BUT NOT LIMITED TO LOST PROFITS, LOST DATA, OR ANY OTHER
20 INCIDENTAL OR CONSEQUENTIAL DAMAGES, ARISING OUT OF OR IN ANY WAY CONNECTED
21 WITH THE SPEEDO SOFTWARE OR THE BITSTREAM CHARTER OUTLINE FONT.
25 /***************************** I F A C E . C *********************************
27 * This module provides a layer to make Speedo function calls to and *
28 * from it compatible with Fontware 2.X function calls. *
30 ****************************************************************************/
32 #include "speedo.h" /* General definitions for Speedo */
39 #define SHOW(X) printf("X = %d\n", X)
44 #define PI 3.1415926536 /* pi */
45 #define PTPERINCH 72.2892 /* nbr points per inch, exactly! */
74 buff_t *pfont; /* Pointer to font data */
75 ufix16 mode; /* what mode is the font generator in */
76 real point_size_x; /* Point size in X dimension */
77 real point_size_y; /* Point size in Y dimension */
78 real res_hor; /* Horizontal resolution of output device */
79 real res_ver; /* Vertical resolution of output device */
80 real rot_angle; /* Rotation angle in degrees (clockwise) */
81 real obl_angle; /* Obliquing angle in degrees (clockwise) */
82 bool16 whitewrite; /* if T, generate bitmaps for whitewriters */
83 fix15 thresh; /* Scan conversion threshold *
84 * Thickens characters on each edge by *
85 * <thresh> sub-pixels */
86 bool16 import_widths; /* Use imported width table */
87 lrtb clip; /* Clip to standard character cell */
88 lrtb squeeze; /* Squeeze to standard character cell */
89 bool16 bogus_mode; /* if T, ignore plaid data */
90 } comp_char_desc; /* character attributes for scan conv */
92 /***** GLOBAL VARIABLES *****/
94 /***** GLOBAL FUNCTIONS *****/
95 fw_reset(); /* Fontware 2.X reset call */
96 fw_set_specs(); /* Fontware 2.X set specs call */
97 bool fw_make_char(); /* Fontware 2.X make character call */
99 /***** EXTERNAL VARIABLES *****/
101 /***** EXTERNAL FUNCTIONS *****/
103 void _close_bitmap();
104 void _set_bitmap_bits();
105 void _open_outline();
106 void _open_outline();
107 void _start_new_char();
111 void _close_outline();
113 /***** STATIC VARIABLES *****/
114 static specs_t *pspecs;
115 static buff_t *pfont;
116 static buff_t char_data;
117 static fix15 set_width_x;
118 static specs_t specsarg;
120 /***** STATIC FUNCTIONS *****/
121 static fix31 make_mult();
129 FUNCTION fw_set_specs(pspecs)
130 comp_char_desc *pspecs; /* Pointer to scan conversion parameters structure */
132 /* Fontware 2.X character generator call to set font specifications
133 * compc -- pointer to structure containing scan conversion parameters.
134 * ->compf -- compressed font data structure
135 * ->point_size_x -- x pointsize
136 * ->point_size_y -- y pointsize
137 * ->res_hor -- horizontal pixels per inch
138 * ->res_ver -- vertical pixels per inch
139 * ->rot_angle -- rotation angle in degrees (clockwise)
140 * ->obl_angle -- obliquing angle in degrees (clockwise)
141 * ->whitewrite -- if true, generate bitmaps for whitewriters
142 * ->thresh -- scan-conversion threshold
143 * ->import_widths -- if true, use external width table
144 * ->clip.left -- clips min x at left of emsquare
145 * ->clip.right -- clips max x at right of emsquare
146 * ->clip.bottom -- clips min x at bottom of emsquare
147 * ->clip.top -- clips max x at top of emsquare
148 * ->squeeze.left -- squeezes min x at left of emsquare
149 * ->squeeze.right, .top, .bottom &c
150 * ->sw_fixed -- if TRUE, match pixel widths to scaled outline widths
151 * ->bogus_mode -- ignore plaid data if TRUE
163 real sinrot, cosrot, tanobl;
173 specsarg.pfont = pspecs->pfont;
175 irot = floor(pspecs->rot_angle + 0.5);
176 iobl = floor(pspecs->obl_angle + 0.5);
181 if ((irot % 90) == 0)
183 x_trans_type = y_trans_type = irot / 90 & 0x0003;
186 if (x_trans_type & 0x01)
192 else if (((irot + iobl) % 90) == 0)
194 x_trans_type = y_trans_type = (irot + iobl) / 90 & 0x0003;
197 if (x_trans_type & 0x01)
205 x_trans_type = y_trans_type = 4;
208 point_size_x = pspecs->point_size_x;
209 point_size_y = pspecs->point_size_y;
210 res_hor = pspecs->res_hor;
211 res_ver = pspecs->res_ver;
213 switch (x_trans_type)
216 xx_mult = make_mult(point_size_x, res_hor);
222 xy_mult = make_mult(point_size_y, res_hor);
226 xx_mult = -make_mult(point_size_x, res_hor);
232 xy_mult = -make_mult(point_size_y, res_hor);
236 sinrot = sin((real)irot * PI / 180.);
237 cosrot = cos((real)irot * PI / 180.);
238 tanobl = tan((real)iobl * PI / 180.);
239 x_distortion = point_size_x / point_size_y;
240 pixperem_h = point_size_y * res_hor / (real)PTPERINCH; /* this is NOT a bug */
241 xx_mult = floor(cosrot * x_distortion * pixperem_h * 65536.0 + 0.5);
242 xy_mult = floor((sinrot + cosrot * tanobl) * pixperem_h * 65536.0 + 0.5);
246 switch (y_trans_type)
250 yy_mult = make_mult(point_size_y, res_ver);
254 yx_mult = -make_mult(point_size_x, res_hor);
260 yy_mult = -make_mult(point_size_y, res_ver);
264 yx_mult = make_mult(point_size_x, res_ver);
269 sinrot = sin((real)irot * PI / 180.);
270 cosrot = cos((real)irot * PI / 180.);
271 tanobl = tan((real)iobl * PI / 180.);
272 x_distortion = point_size_x / point_size_y;
273 pixperem_v = point_size_y * res_ver / (real)PTPERINCH;
274 yx_mult = floor(-sinrot * x_distortion * pixperem_v * 65536.0 + 0.5);
275 yy_mult = floor((cosrot - sinrot * tanobl) * pixperem_v * 65536.0 + 0.5);
279 specsarg.xxmult = xx_mult;
280 specsarg.xymult = xy_mult;
281 specsarg.xoffset = 0;
282 specsarg.yxmult = yx_mult;
283 specsarg.yymult = yy_mult;
284 specsarg.yoffset = 0;
285 specsarg.out_info = 0;
287 /* Select processing mode */
288 switch (pspecs->mode)
291 if (pspecs->whitewrite) /* White-write requested? */
310 if (pspecs->bogus_mode) /* Linear transformation requested? */
312 mode |= BIT4; /* Set linear tranformation flag */
315 if (pspecs->import_widths) /* Imported widths requested? */
317 mode |= BIT6; /* Set imported width flag */
320 if (pspecs->clip.left) /* Clip left requested? */
322 mode |= BIT8; /* Set clip left flag */
325 if (pspecs->clip.right) /* Clip right requested? */
327 mode |= BIT9; /* Set clip right flag */
330 if (pspecs->clip.top) /* Clip top requested? */
332 mode |= BIT10; /* Set clip top flag */
335 if (pspecs->clip.bottom) /* Clip bottom requested? */
337 mode |= BIT11; /* Set clip bottom flag */
340 if (pspecs->squeeze.left) /* Squeeze left requested? */
342 mode |= BIT12; /* Set squeeze left flag */
345 if (pspecs->squeeze.right) /* Squeeze right requested? */
347 mode |= BIT13; /* Set squeeze right flag */
350 if (pspecs->squeeze.top) /* Squeeze top requested? */
352 mode |= BIT14; /* Set squeeze top flag */
355 if (pspecs->squeeze.bottom) /* Squeeze bottom requested? */
357 mode |= BIT15; /* Set squeeze bottom flag */
360 specsarg.flags = mode;
362 sp_set_specs(&specsarg);
365 FUNCTION static fix31 make_mult(point_size, resolution)
371 return (fix31)floor((point_size * resolution * 65536.0) / (real)PTPERINCH + 0.5);
374 FUNCTION bool fw_make_char(char_index)
377 return sp_make_char(char_index);
380 FUNCTION buff_t *sp_load_char_data(file_offset, no_bytes, cb_offset)
385 * Called by Speedo character generator to request that character
386 * data be loaded from the font file.
387 * This is a dummy function that assumes that the entire font has
392 printf("load_char_data(%d, %d, %d)\n", file_offset, no_bytes, char_offset);
394 char_data.org = pfont->org + file_offset;
395 char_data.no_bytes = no_bytes;
399 FUNCTION void sp_report_error(n)
400 fix15 n; /* Error identification number */
402 * Called by Speedo character generator to report an error.
408 printf("Insufficient font data loaded\n");
412 printf("Transformation matrix out of range\n");
416 printf("Font format error\n");
420 printf("Requested specs not compatible with output module\n");
424 printf("Intelligent transformation requested but not supported\n");
428 printf("Unsupported output mode requested\n");
432 printf("Extended font loaded but only compact fonts supported\n");
436 printf("Font specs not set prior to use of font\n");
440 printf("Character data not available()\n");
444 printf("Track kerning data not available()\n");
448 printf("Pair kerning data not available()\n");
452 printf("report_error(%d)\n", n);
459 FUNCTION void sp_open_bitmap(sw_x, sw_y, xorg, yorg, xsize, ysize)
460 fix31 sw_x; /* X component of escapement vector */
461 fix31 sw_y; /* Y component of escapement vector */
462 fix31 xorg; /* X origin */
463 fix31 yorg; /* Y origin */
464 fix15 xsize; /* width of bitmap */
465 fix15 ysize; /* height of bitmap */
467 * Called by Speedo character generator to initialize a buffer prior
468 * to receiving bitmap data.
472 fix15 xmin,xmax,ymin,ymax;
475 printf("sp_open_bitmap:\n");
476 printf(" X component of set width vector = %3.1f\n", (real)sw_x / 65536.0);
477 printf(" Y component of set width vector = %3.1f\n", (real)sw_y / 65536.0);
478 printf(" Bounding box is (%d, %d, %d, %d)\n", xmin, ymin, xmax, ymax);
486 set_width_x = ((sw_x >> 15) + 1) >> 1;
487 open_bitmap(set_width_x, xmin, xmax, ymin, ymax);
490 FUNCTION void sp_set_bitmap_bits(y, x1, x2)
493 * Called by Speedo character generator to write one row of pixels
494 * into the generated bitmap character.
498 printf("set_bitmap_bits(%d, %d, %d)\n", y, x1, x2);
501 set_bitmap_bits(y, x1, x2);
504 FUNCTION void sp_close_bitmap()
506 * Called by Speedo character generator to indicate all bitmap data
507 * has been generated.
511 printf("close_bitmap()\n");
517 FUNCTION void sp_open_outline(sw_x, sw_y, xmin, xmax, ymin, ymax)
518 fix31 sw_x; /* X component of escapement vector */
519 fix31 sw_y; /* Y component of escapement vector */
520 fix31 xmin; /* Minimum X value in outline */
521 fix31 xmax; /* Maximum X value in outline */
522 fix31 ymin; /* Minimum Y value in outline */
523 fix31 ymax; /* Maximum Y value in outline */
525 * Called by Speedo character generator to initialize prior to
526 * outputting scaled outline data.
530 printf("open_outline(%3.1f, %3.1f, %3.1f, %3.1f, %3.1f, %3.1f)\n",
531 (real)sw_x / 65536.0, (real)sw_y / 65536.0,
532 (real)xmin / 65536.0, (real)xmax / 65536.0, (real)ymin / 65536.0, (real)ymax / 65536.0);
535 set_width_x = ((sw_x >> 15) + 1) >> 1;
536 open_outline(set_width_x);
539 FUNCTION void sp_start_new_char()
541 * Called by Speedo character generator to initialize prior to
542 * outputting scaled outline data for a sub-character in a compound
547 printf("start_new_char()\n");
553 FUNCTION void sp_start_contour(x, y, outside)
554 fix31 x; /* X coordinate of start point in 1/65536 pixels */
555 fix31 y; /* Y coordinate of start point in 1/65536 pixels */
556 boolean outside; /* TRUE if curve encloses ink (Counter-clockwise) */
558 * Called by Speedo character generator at the start of each contour
559 * in the outline data of the character.
564 realx = (real)x / 65536.0;
565 realy = (real)y / 65536.0;
568 printf("start_curve(%3.1f, %3.1f, %s)\n",
570 outside? "outside": "inside");
573 start_curve(realx, realy, outside);
576 FUNCTION void sp_curve_to(x1, y1, x2, y2, x3, y3)
577 fix31 x1; /* X coordinate of first control point in 1/65536 pixels */
578 fix31 y1; /* Y coordinate of first control point in 1/65536 pixels */
579 fix31 x2; /* X coordinate of second control point in 1/65536 pixels */
580 fix31 y2; /* Y coordinate of second control point in 1/65536 pixels */
581 fix31 x3; /* X coordinate of curve end point in 1/65536 pixels */
582 fix31 y3; /* Y coordinate of curve end point in 1/65536 pixels */
584 * Called by Speedo character generator once for each curve in the
585 * scaled outline data of the character. This function is only called if curve
586 * output is enabled in the set_specs() call.
590 printf("curve_to(%3.1f, %3.1f, %3.1f, %3.1f, %3.1f, %3.1f)\n",
591 (real)x1 / 65536.0, (real)y1 / 65536.0,
592 (real)x2 / 65536.0, (real)y2 / 65536.0,
593 (real)x3 / 65536.0, (real)y3 / 65536.0);
597 FUNCTION void sp_line_to(x, y)
598 fix31 x; /* X coordinate of vector end point in 1/65536 pixels */
599 fix31 y; /* Y coordinate of vector end point in 1/65536 pixels */
601 * Called by Speedo character generator onece for each vector in the
602 * scaled outline data for the character. This include curve data that has
603 * been sub-divided into vectors if curve output has not been enabled
604 * in the set_specs() call.
609 realx = (real)x / 65536.0;
610 realy = (real)y / 65536.0;
613 printf("line_to(%3.1f, %3.1f)\n",
617 line_to(realx, realy);
620 FUNCTION void sp_close_contour()
622 * Called by Speedo character generator at the end of each contour
623 * in the outline data of the character.
627 printf("close_curve()\n");
633 FUNCTION void sp_close_outline()
635 * Called by Speedo character generator at the end of output of the
636 * scaled outline of the character.
640 printf("close_outline()\n");
643 close_outline(set_width_x);