summaryrefslogtreecommitdiff
path: root/src/Speedo/out_util.c
blob: a6f02f0a346c88eb5ca2ae3676d4646eca99dceb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
/* $Xorg: out_util.c,v 1.3 2000/08/17 19:46:26 cpqbld Exp $ */

/*

Copyright 1989-1991, Bitstream Inc., Cambridge, MA.
You are hereby granted permission under all Bitstream propriety rights to
use, copy, modify, sublicense, sell, and redistribute the Bitstream Speedo
software and the Bitstream Charter outline font for any purpose and without
restrictions; provided, that this notice is left intact on all copies of such
software or font and that Bitstream's trademark is acknowledged as shown below
on all unmodified copies of such font.

BITSTREAM CHARTER is a registered trademark of Bitstream Inc.


BITSTREAM INC. DISCLAIMS ANY AND ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING
WITHOUT LIMITATION THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE.  BITSTREAM SHALL NOT BE LIABLE FOR ANY DIRECT OR INDIRECT
DAMAGES, INCLUDING BUT NOT LIMITED TO LOST PROFITS, LOST DATA, OR ANY OTHER
INCIDENTAL OR CONSEQUENTIAL DAMAGES, ARISING OUT OF OR IN ANY WAY CONNECTED
WITH THE SPEEDO SOFTWARE OR THE BITSTREAM CHARTER OUTLINE FONT.

*/
/* $XFree86: xc/lib/font/Speedo/out_util.c,v 1.2 1999/02/07 06:18:17 dawes Exp $ */


#define	DEBUG	0

/*************************** O U T _ U T I L . C *****************************
 *                                                                           *
 * This is a utility module share by all bitmap output modules               *
 *                                                                           *
 *****************************************************************************/


#include "spdo_prv.h"               /* General definitions for Speedo   */
/* absolute value function */
#define   ABS(X)     ( (X < 0) ? -X : X)
#if INCL_BLACK || INCL_2D || INCL_SCREEN

FUNCTION  void init_char_out(
GDECL
point_t Psw, point_t Pmin, point_t Pmax)
{
sp_globals.set_width.x = (fix31)Psw.x << sp_globals.poshift;
sp_globals.set_width.y = (fix31)Psw.y << sp_globals.poshift;
set_first_band_out(Pmin, Pmax);
init_intercepts_out();
if (sp_globals.normal)
    {
    sp_globals.bmap_xmin = Pmin.x;
    sp_globals.bmap_xmax = Pmax.x;
    sp_globals.bmap_ymin = Pmin.y;
    sp_globals.bmap_ymax = Pmax.y;
    sp_globals.extents_running = FALSE;
    }
else
    {
    sp_globals.bmap_xmin = 32000;
    sp_globals.bmap_xmax = -32000;
    sp_globals.bmap_ymin = 32000;
    sp_globals.bmap_ymax = -32000;
    sp_globals.extents_running = TRUE;
    }
sp_globals.first_pass = TRUE;
}

FUNCTION void begin_sub_char_out(
GDECL
point_t Psw,
point_t Pmin,
point_t Pmax)
/* Called at the start of each sub-character in a composite character
 */
{
#if DEBUG
printf("BEGIN_SUB_CHAR_out(%3.1f, %3.1f, %3.1f, %3.1f, %3.1f, %3.1f\n", 
                    (real)Psw.x / (real)sp_globals.onepix, (real)Psw.y / (real)sp_globals.onepix,
                    (real)Pmin.x / (real)sp_globals.onepix, (real)Pmin.y / (real)sp_globals.onepix,
                    (real)Pmax.x / (real)sp_globals.onepix, (real)Pmax.y / (real)sp_globals.onepix);
#endif
restart_intercepts_out();
if (!sp_globals.extents_running)
	{
    sp_globals.bmap_xmin = 32000;
    sp_globals.bmap_xmax = -32000;
    sp_globals.bmap_ymin = 32000;
    sp_globals.bmap_ymax = -32000;
    sp_globals.extents_running = TRUE;
	}
}

FUNCTION void curve_out(
GDECL
point_t P1, point_t P2, point_t P3,
fix15 depth)
/* Called for each curve in the transformed character if curves out enabled
 */
{
#if DEBUG
printf("CURVE_OUT(%3.1f, %3.1f, %3.1f, %3.1f, %3.1f, %3.1f)\n", 
    (real)P1.x / (real)sp_globals.onepix, (real)P1.y / (real)sp_globals.onepix,
    (real)P2.x / (real)sp_globals.onepix, (real)P2.y / (real)sp_globals.onepix,
    (real)P3.x / (real)sp_globals.onepix, (real)P3.y / (real)sp_globals.onepix);
#endif
}



FUNCTION void end_contour_out()
GDECL
/* Called after the last vector in each contour
 */
{
#if DEBUG
printf("END_CONTOUR_OUT()\n");
#endif
}


FUNCTION void end_sub_char_out()
GDECL
/* Called after the last contour in each sub-character in a compound character
 */
{
#if DEBUG
printf("END_SUB_CHAR_OUT()\n");
#endif
}


FUNCTION void init_intercepts_out()
GDECL
/*  Called to initialize intercept storage data structure
 */

{
fix15 i;
fix15 no_lists;

#if DEBUG
printf("    Init intercepts (Y band from %d to %d)\n", sp_globals.y_band.band_min, sp_globals.y_band.band_max);
if (sp_globals.x_scan_active)
    printf("                    (X band from %d to %d)\n", sp_globals.x_band.band_min, sp_globals.x_band.band_max);
#endif 

sp_globals.intercept_oflo = FALSE;

sp_globals.no_y_lists = sp_globals.y_band.band_max - sp_globals.y_band.band_min + 1;
#if INCL_2D
if (sp_globals.output_mode == MODE_2D)
	{
	sp_globals.no_x_lists = sp_globals.x_scan_active ? 
		sp_globals.x_band.band_max - sp_globals.x_band.band_min + 1 : 0;
	no_lists = sp_globals.no_y_lists + sp_globals.no_x_lists;
	} 
else
#endif
	no_lists = sp_globals.no_y_lists;

#if INCL_2D
sp_globals.y_band.band_floor = 0;
sp_globals.y_band.band_ceiling = sp_globals.no_y_lists;
#endif
                                        
if (no_lists >= MAX_INTERCEPTS)  /* Not enough room for list table? */
    {
    no_lists = sp_globals.no_y_lists = MAX_INTERCEPTS;
    sp_globals.intercept_oflo = TRUE;
	sp_globals.y_band.band_min = sp_globals.y_band.band_max - sp_globals.no_y_lists + 1;
#if INCL_2D
    sp_globals.y_band.band_array_offset = sp_globals.y_band.band_min;
    sp_globals.y_band.band_ceiling = sp_globals.no_y_lists;
    sp_globals.no_x_lists = 0;
    sp_globals.x_scan_active = FALSE;
#endif
    }

for (i = 0; i < no_lists; i++)   /* For each active value... */
    {
#if INCL_SCREEN
	if (sp_globals.output_mode == MODE_SCREEN)
		sp_intercepts.inttype[i]=0;
#endif
    sp_intercepts.cdr[i] = 0;                    /* Mark each intercept list empty */
    }

sp_globals.first_offset = sp_globals.next_offset = no_lists;

#if INCL_2D
sp_globals.y_band.band_array_offset = sp_globals.y_band.band_min;
sp_globals.x_band.band_array_offset = sp_globals.x_band.band_min - sp_globals.no_y_lists;
sp_globals.x_band.band_floor = sp_globals.no_y_lists;
sp_globals.x_band.band_ceiling = no_lists;
#endif
#if INCL_SCREEN
sp_intercepts.inttype[sp_globals.no_y_lists-1] = END_INT;
#endif

}


FUNCTION void restart_intercepts_out()
GDECL

/*  Called by sp_make_char when a new sub character is started
 *  Freezes current sorted lists
 */

{

#if DEBUG
printf("    Restart intercepts:\n");
#endif
sp_globals.first_offset = sp_globals.next_offset;
}



FUNCTION void set_first_band_out(
GDECL
point_t Pmin,
point_t Pmax)
{

sp_globals.ymin = Pmin.y;
sp_globals.ymax = Pmax.y;

sp_globals.ymin = (sp_globals.ymin - sp_globals.onepix + 1) >> sp_globals.pixshift;
sp_globals.ymax = (sp_globals.ymax + sp_globals.onepix - 1) >> sp_globals.pixshift;

#if INCL_CLIPPING
    switch(sp_globals.tcb0.xtype)
       {
       case 1: /* 180 degree rotation */
	    if (sp_globals.specs.flags & CLIP_TOP)
               {
               sp_globals.clip_ymin = (fix31)((fix31)EM_TOP * sp_globals.tcb0.yppo + ((1<<sp_globals.multshift)/2));
               sp_globals.clip_ymin = sp_globals.clip_ymin >> sp_globals.multshift;
	       sp_globals.clip_ymin = -1* sp_globals.clip_ymin;
	       if (sp_globals.ymin < sp_globals.clip_ymin)
		    sp_globals.ymin = sp_globals.clip_ymin;
	       }
            if (sp_globals.specs.flags & CLIP_BOTTOM)
	       {
               sp_globals.clip_ymax = (fix31)((fix31)(-1 * EM_BOT) * sp_globals.tcb0.yppo + ((1<<sp_globals.multshift)/2));
               sp_globals.clip_ymax = sp_globals.clip_ymax >> sp_globals.multshift;
	       if (sp_globals.ymax > sp_globals.clip_ymax)
		    sp_globals.ymax = sp_globals.clip_ymax;
               }
               break;
       case 2: /* 90 degree rotation */
            sp_globals.clip_ymax = 0;
            if ((sp_globals.specs.flags & CLIP_TOP) &&
                (sp_globals.ymax > sp_globals.clip_ymax))
                 sp_globals.ymax = sp_globals.clip_ymax;
            sp_globals.clip_ymin = ((sp_globals.set_width.y+32768L) >> 16);
            if ((sp_globals.specs.flags & CLIP_BOTTOM) &&
                (sp_globals.ymin < sp_globals.clip_ymin))
                 sp_globals.ymin = sp_globals.clip_ymin;
            break;
       case 3: /* 270 degree rotation */
               sp_globals.clip_ymax = ((sp_globals.set_width.y+32768L) >> 16);
               if ((sp_globals.specs.flags & CLIP_TOP) &&
                   (sp_globals.ymax > sp_globals.clip_ymax))
                    sp_globals.ymax = sp_globals.clip_ymax;
               sp_globals.clip_ymin = 0;
               if ((sp_globals.specs.flags & CLIP_BOTTOM) &&
                   (sp_globals.ymin < sp_globals.clip_ymin))
                    sp_globals.ymin = sp_globals.clip_ymin;
               break;
       default: /* this is for zero degree rotation and arbitrary rotation */
	    if (sp_globals.specs.flags & CLIP_TOP)
               {
	       sp_globals.clip_ymax = (fix31)((fix31)EM_TOP * sp_globals.tcb0.yppo +  ((1<<sp_globals.multshift)/2));
               sp_globals.clip_ymax = sp_globals.clip_ymax >> sp_globals.multshift;
	       if (sp_globals.ymax > sp_globals.clip_ymax)
		    sp_globals.ymax = sp_globals.clip_ymax;
	       }
            if (sp_globals.specs.flags & CLIP_BOTTOM)
	       {
	       sp_globals.clip_ymin = (fix31)((fix31)(-1 * EM_BOT) * sp_globals.tcb0.yppo +  ((1<<sp_globals.multshift)/2));
               sp_globals.clip_ymin = sp_globals.clip_ymin >> sp_globals.multshift;
	       sp_globals.clip_ymin = - sp_globals.clip_ymin;
	       if (sp_globals.ymin < sp_globals.clip_ymin)
		    sp_globals.ymin = sp_globals.clip_ymin;
               }
               break;
       }
#endif
sp_globals.y_band.band_min = sp_globals.ymin;
sp_globals.y_band.band_max = sp_globals.ymax - 1; 

sp_globals.xmin = (Pmin.x + sp_globals.pixrnd) >> sp_globals.pixshift;
sp_globals.xmax = (Pmax.x + sp_globals.pixrnd) >> sp_globals.pixshift;


#if INCL_2D
sp_globals.x_band.band_min = sp_globals.xmin - 1; /* subtract one pixel of "safety margin" */
sp_globals.x_band.band_max = sp_globals.xmax /* - 1 + 1 */; /* Add one pixel of "safety margin" */
#endif
}




                                  


FUNCTION void reduce_band_size_out()
GDECL
{
sp_globals.y_band.band_min = sp_globals.y_band.band_max - ((sp_globals.y_band.band_max - sp_globals.y_band.band_min) >> 1);
#if INCL_2D
sp_globals.y_band.band_array_offset = sp_globals.y_band.band_min;
#endif
}


FUNCTION boolean next_band_out()
GDECL
{
fix15  tmpfix15;

if (sp_globals.y_band.band_min <= sp_globals.ymin)
    return FALSE;
tmpfix15 = sp_globals.y_band.band_max - sp_globals.y_band.band_min;
sp_globals.y_band.band_max = sp_globals.y_band.band_min - 1;
sp_globals.y_band.band_min = sp_globals.y_band.band_max - tmpfix15;
if (sp_globals.y_band.band_min < sp_globals.ymin)
    sp_globals.y_band.band_min = sp_globals.ymin;
#if INCL_2D
sp_globals.y_band.band_array_offset = sp_globals.y_band.band_min;
#endif
return TRUE;
}
#endif