]> git.sesse.net Git - rdpsrv/blob - Xserver/lib/font/Speedo/iface.c
Import X server from vnc-3.3.7.
[rdpsrv] / Xserver / lib / font / Speedo / iface.c
1 /* $XConsortium: iface.c,v 1.3 94/04/17 20:17:44 rws Exp $ */
2
3 /*
4
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.
12
13 BITSTREAM CHARTER is a registered trademark of Bitstream Inc.
14
15
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.
22
23 */
24
25 /***************************** I F A C E . C *********************************
26  *                                                                           *
27  * This module provides a layer to make Speedo function calls to and         *
28  * from it compatible with Fontware 2.X function calls.                      *
29  *                                                                           *
30  ****************************************************************************/
31
32 #include "speedo.h"               /* General definitions for Speedo */
33 #include <math.h>
34
35 #define   DEBUG      0
36
37 #if DEBUG
38 #include <stdio.h>
39 #define SHOW(X) printf("X = %d\n", X)
40 #else
41 #define SHOW(X)
42 #endif
43
44 #define  PI     3.1415926536       /* pi */
45 #define  PTPERINCH   72.2892       /* nbr points per inch, exactly! */
46
47 #define  BIT8           0x0100
48 #define  BIT9           0x0200
49 #define  BIT10          0x0400
50 #define  BIT11          0x0800
51 #define  BIT12          0x1000
52 #define  BIT13          0x2000
53 #define  BIT14          0x4000
54 #define  BIT15          0x8000
55
56 #define   READ      0
57
58 typedef   short     bool16;
59 typedef   int       bool;
60
61 typedef
62 struct
63     {
64     bool16  left;
65     bool16  right;
66     bool16  top;
67     bool16  bottom;
68     }   lrtb;
69
70
71 typedef
72 struct
73     {
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      */
91
92 /***** GLOBAL VARIABLES *****/
93
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        */
98        
99 /***** EXTERNAL VARIABLES *****/
100
101 /***** EXTERNAL FUNCTIONS *****/
102 void    _open_bitmap();
103 void    _close_bitmap();
104 void    _set_bitmap_bits();
105 void    _open_outline();
106 void    _open_outline();
107 void    _start_new_char();
108 void    _start_curve();
109 void    _line_to();
110 void    _close_curve();
111 void    _close_outline();
112
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;
119
120 /***** STATIC FUNCTIONS *****/
121 static fix31 make_mult();
122
123 \f
124 FUNCTION fw_reset()
125 {
126 sp_reset();
127 }
128 \f
129 FUNCTION fw_set_specs(pspecs)
130 comp_char_desc  *pspecs;  /* Pointer to scan conversion parameters structure */
131
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
152  */
153
154 {
155 fix15   irot;
156 fix15   iobl;
157 fix15   x_trans_type;
158 fix15   y_trans_type;
159 fix31   xx_mult;
160 fix31   xy_mult;
161 fix31   yx_mult;
162 fix31   yy_mult;
163 real    sinrot, cosrot, tanobl;
164 real    x_distortion;
165 real    pixperem_h;
166 real    pixperem_v;
167 real    point_size_x;
168 real    point_size_y;
169 real    res_hor;
170 real    res_ver;
171 fix15   mode;
172
173 specsarg.pfont = pspecs->pfont;
174
175 irot = floor(pspecs->rot_angle + 0.5);
176 iobl = floor(pspecs->obl_angle + 0.5);
177 if (iobl > 85)
178     iobl = 85;
179 if (iobl < -85)
180     iobl = -85;
181 if ((irot % 90) == 0)
182     {
183     x_trans_type = y_trans_type = irot / 90 & 0x0003;
184     if (iobl != 0)
185         {
186         if (x_trans_type & 0x01)
187             y_trans_type = 4;
188         else
189             x_trans_type = 4;
190         }
191     }
192 else if (((irot + iobl) % 90) == 0)
193     {
194     x_trans_type = y_trans_type = (irot + iobl) / 90 & 0x0003;
195     if (iobl != 0)
196         {
197         if (x_trans_type & 0x01)
198             x_trans_type = 4;
199         else
200             y_trans_type = 4;
201         }
202     }
203 else
204     {
205     x_trans_type = y_trans_type = 4;
206     }
207
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;
212
213 switch (x_trans_type)
214     {
215 case 0: 
216     xx_mult = make_mult(point_size_x, res_hor);
217     xy_mult = 0;
218     break;
219
220 case 1:
221     xx_mult = 0;
222     xy_mult = make_mult(point_size_y, res_hor);
223     break;
224
225 case 2: 
226     xx_mult = -make_mult(point_size_x, res_hor);
227     xy_mult = 0;
228     break;
229
230 case 3:
231     xx_mult = 0;
232     xy_mult = -make_mult(point_size_y, res_hor);
233     break;
234
235 default:
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);
243     break;
244     }
245
246 switch (y_trans_type)
247     {
248 case 0: 
249     yx_mult = 0;
250     yy_mult = make_mult(point_size_y, res_ver);
251     break;
252
253 case 1:
254     yx_mult = -make_mult(point_size_x, res_hor);
255     yy_mult = 0;
256     break;
257
258 case 2: 
259     yx_mult = 0;
260     yy_mult = -make_mult(point_size_y, res_ver);
261     break;
262
263 case 3:
264     yx_mult = make_mult(point_size_x, res_ver);
265     yy_mult = 0;
266     break;
267
268 default:
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);
276     break;
277     }
278
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;
286
287 /* Select processing mode */
288 switch (pspecs->mode)
289     {
290 case 1:
291     if (pspecs->whitewrite)           /* White-write requested? */
292         {
293         mode = 1;
294         }
295     else
296         {
297         mode = 0;
298         }
299     break;
300     
301 case 2:
302     mode = 2;
303     break;
304
305 default:
306     mode = pspecs->mode;
307     break;
308     }
309
310 if (pspecs->bogus_mode)        /* Linear transformation requested? */
311     {
312     mode |= BIT4;              /* Set linear tranformation flag */
313     }
314
315 if (pspecs->import_widths)     /* Imported widths requested? */
316     {
317     mode |= BIT6;              /* Set imported width flag */
318     }
319
320 if (pspecs->clip.left)         /* Clip left requested? */
321     {
322     mode |= BIT8;              /* Set clip left flag */
323     }
324
325 if (pspecs->clip.right)        /* Clip right requested? */
326     {
327     mode |= BIT9;              /* Set clip right flag */
328     }
329
330 if (pspecs->clip.top)          /* Clip top requested? */
331     {
332     mode |= BIT10;             /* Set clip top flag */
333     }
334
335 if (pspecs->clip.bottom)       /* Clip bottom requested? */
336     {
337     mode |= BIT11;             /* Set clip bottom flag */
338     }
339
340 if (pspecs->squeeze.left)      /* Squeeze left requested? */
341     {
342     mode |= BIT12;             /* Set squeeze left flag */
343     }
344
345 if (pspecs->squeeze.right)     /* Squeeze right requested? */
346     {
347     mode |= BIT13;             /* Set squeeze right flag */
348     }
349
350 if (pspecs->squeeze.top)       /* Squeeze top requested? */
351     {
352     mode |= BIT14;             /* Set squeeze top flag */
353     }
354
355 if (pspecs->squeeze.bottom)    /* Squeeze bottom requested? */
356     {
357     mode |= BIT15;             /* Set squeeze bottom flag */
358     }
359
360 specsarg.flags = mode;
361
362 sp_set_specs(&specsarg);
363 }
364 \f
365 FUNCTION static fix31 make_mult(point_size, resolution)
366 real point_size;
367 real resolution;
368 {
369 real ms_factor;
370
371 return (fix31)floor((point_size * resolution * 65536.0) / (real)PTPERINCH + 0.5);
372 }
373 \f
374 FUNCTION bool fw_make_char(char_index)
375 ufix16 char_index;
376 {
377 return sp_make_char(char_index);
378 }
379 \f
380 FUNCTION buff_t *sp_load_char_data(file_offset, no_bytes, cb_offset)
381 fix31    file_offset;
382 fix15    no_bytes;
383 fix15    cb_offset;
384 /* 
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
388  * been loaded.
389  */
390 {
391 #if DEBUG
392 printf("load_char_data(%d, %d, %d)\n", file_offset, no_bytes, char_offset);
393 #endif
394 char_data.org = pfont->org + file_offset;
395 char_data.no_bytes = no_bytes;
396 return &char_data;
397 }
398 \f
399 FUNCTION void sp_report_error(n)
400 fix15 n;        /* Error identification number */
401 /*
402  * Called by Speedo character generator to report an error.
403  */
404 {
405 switch(n)
406     {
407 case 1:
408     printf("Insufficient font data loaded\n");
409     break;
410
411 case 3:
412     printf("Transformation matrix out of range\n");
413     break;
414
415 case 4:
416     printf("Font format error\n");
417     break;
418                  
419 case 5:
420     printf("Requested specs not compatible with output module\n");
421     break;
422
423 case 7:
424     printf("Intelligent transformation requested but not supported\n");
425     break;
426
427 case 8:
428     printf("Unsupported output mode requested\n");
429     break;
430
431 case 9:
432     printf("Extended font loaded but only compact fonts supported\n");
433     break;
434
435 case 10:
436     printf("Font specs not set prior to use of font\n");
437     break;
438
439 case 12:
440     printf("Character data not available()\n");
441     break;
442
443 case 13:
444     printf("Track kerning data not available()\n");
445     break;
446
447 case 14:
448     printf("Pair kerning data not available()\n");
449     break;
450
451 default:
452     printf("report_error(%d)\n", n);
453     break;
454     }
455 }
456 \f
457
458 \f
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 */
466 /* 
467  * Called by Speedo character generator to initialize a buffer prior
468  * to receiving bitmap data.
469  */
470 {
471
472 fix15 xmin,xmax,ymin,ymax;
473
474 #if DEBUG
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);
479 #endif
480
481 xmin = xorg >> 16;
482 ymin = yorg >> 16;
483 xmax = xmin + xsize;
484 ymax = ymin + ysize;
485
486 set_width_x = ((sw_x >> 15) + 1) >> 1;
487 open_bitmap(set_width_x, xmin, xmax, ymin, ymax);
488 }
489 \f
490 FUNCTION void sp_set_bitmap_bits(y, x1, x2)
491 fix15 y, x1, x2;
492 /* 
493  * Called by Speedo character generator to write one row of pixels 
494  * into the generated bitmap character.                               
495  */
496 {
497 #if DEBUG
498 printf("set_bitmap_bits(%d, %d, %d)\n", y, x1, x2);
499 #endif
500
501 set_bitmap_bits(y, x1, x2);
502 }
503 \f
504 FUNCTION void sp_close_bitmap()
505 /* 
506  * Called by Speedo character generator to indicate all bitmap data
507  * has been generated.
508  */
509 {
510 #if DEBUG
511 printf("close_bitmap()\n");
512 #endif
513
514 close_bitmap();
515 }
516 \f
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 */
524 /*
525  * Called by Speedo character generator to initialize prior to
526  * outputting scaled outline data.
527  */
528 {
529 #if DEBUG
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);
533 #endif
534
535 set_width_x = ((sw_x >> 15) + 1) >> 1;
536 open_outline(set_width_x);
537 }
538 \f
539 FUNCTION void sp_start_new_char()
540 /*
541  * Called by Speedo character generator to initialize prior to
542  * outputting scaled outline data for a sub-character in a compound
543  * character.
544  */
545 {
546 #if DEBUG
547 printf("start_new_char()\n");
548 #endif
549
550 start_new_char();
551 }
552 \f
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) */
557 /*
558  * Called by Speedo character generator at the start of each contour
559  * in the outline data of the character.
560  */
561 {
562 real realx, realy;
563
564 realx = (real)x / 65536.0;
565 realy = (real)y / 65536.0;
566
567 #if DEBUG
568 printf("start_curve(%3.1f, %3.1f, %s)\n", 
569     realx, realy, 
570     outside? "outside": "inside");
571 #endif
572
573 start_curve(realx, realy, outside);
574 }
575 \f
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 */
583 /*
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.
587  */
588 {
589 #if DEBUG
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);
594 #endif
595 }
596 \f
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 */
600 /*
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.
605  */
606 {
607 real realx, realy;
608
609 realx = (real)x / 65536.0;
610 realy = (real)y / 65536.0;
611
612 #if DEBUG
613 printf("line_to(%3.1f, %3.1f)\n", 
614     realx, realy); 
615 #endif            
616
617 line_to(realx, realy);
618 }
619 \f
620 FUNCTION void sp_close_contour()
621 /*
622  * Called by Speedo character generator at the end of each contour
623  * in the outline data of the character.
624  */
625 {
626 #if DEBUG
627 printf("close_curve()\n");
628 #endif
629
630 close_curve();
631 }
632 \f
633 FUNCTION void sp_close_outline()
634 /*
635  * Called by Speedo character generator at the end of output of the
636  * scaled outline of the character.
637  */
638 {
639 #if DEBUG
640 printf("close_outline()\n");
641 #endif
642
643 close_outline(set_width_x);
644 }
645