summaryrefslogtreecommitdiff
path: root/xc/test/xsuite/xtest/tset/CH06/crtglyphcr/crtglyphcr.m
blob: 3631f12caa5961dc37664a9430595aafa9904049 (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
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
/*
 
Copyright (c) 1990, 1991  X Consortium

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Except as contained in this notice, the name of the X Consortium shall not be
used in advertising or otherwise to promote the sale, use or other dealings
in this Software without prior written authorization from the X Consortium.

 *
 * Copyright 1990, 1991 by UniSoft Group Limited.
 * 
 * Permission to use, copy, modify, distribute, and sell this software and
 * its documentation for any purpose is hereby granted without fee,
 * provided that the above copyright notice appear in all copies and that
 * both that copyright notice and this permission notice appear in
 * supporting documentation, and that the name of UniSoft not be
 * used in advertising or publicity pertaining to distribution of the
 * software without specific, written prior permission.  UniSoft
 * makes no representations about the suitability of this software for any
 * purpose.  It is provided "as is" without express or implied warranty.
 *
 * $XConsortium: crtglyphcr.m,v 1.16 94/04/17 21:04:32 rws Exp $
 */
>>TITLE XCreateGlyphCursor CH06
Cursor
XCreateGlyphCursor (display, source_font, mask_font, source_char, mask_char, foreground_color, background_color)
Display *display = Dsp;
Font source_font;
Font mask_font;
unsigned int source_char;
unsigned int mask_char;
XColor *foreground_color = mkcolor(1);
XColor *background_color = mkcolor(0);
>>SET startup fontstartup
>>SET cleanup fontcleanup
>>EXTERN
static char xtfont0[] = "xtfont0";	/* known font, used for source font */
static unsigned int good_char0 = 1;	/* known defined glyph in xtfont0 */
static unsigned int goodblank_char0 = 1;/* blank defined glyph in xtfont0  */
static unsigned int bad_char0 = 0;	/* undefined glyph xtfont0 */
static unsigned int bounding0 = 4;	/* diff. bounding box than good_char0 */

static char xtfont1[] = "xtfont1";	/* font sometimes used for mask font */
static unsigned int good_char1 = 1;	/* known defined glyph in xtfont1 */

static char xtfont6[] = "xtfont6";	/* known 2-byte matrix font */
static unsigned int good_char6 = 504;	/* known defined glyph in xtfont6 */

/*
 * mkcolor() -	return a pointer to a color structure.
 *		flag indicates whether or not color is foreground
 */
static XColor *
mkcolor(flag)
{
	static	XColor	fore;
	static	XColor	back;
	static	int	first = 1;

	if (first)
	{
		first = 0;

		fore.pixel = BlackPixel(display, DefaultScreen(display));
		XQueryColor(display, DefaultColormap(display, DefaultScreen(display)), &fore);
		back.pixel = WhitePixel(display, DefaultScreen(display));
		XQueryColor(display, DefaultColormap(display, DefaultScreen(display)), &back);
	}
	return(flag ? &fore : &back);
}
>>ASSERTION Good B 1
A call to xname creates a
.S Cursor
with colours defined by
.A foreground_color
and
.A background_color
and returns its ID.
>>STRATEGY
Load xtfont0 using XLoadFont.
Call XCreateGlyphCursor with foreground colour W_FG and
background colour W_BG.
Verify that XCreateGlyphCursor returns non-zero.
>>CODE
Cursor qstat;

/* Load xtfont0 using XLoadFont. */
	source_font = XLoadFont(display, xtfont0);
	mask_font = source_font;
	source_char = good_char0;
	mask_char = good_char0;

/* Call XCreateGlyphCursor with foreground colour W_FG and */
/* background colour W_BG. */
	qstat = XCALL;

/* Verify that XCreateGlyphCursor returns non-zero. */
	if (qstat == (Cursor) 0) {
		report("Returned wrong value %ld", (long) qstat);
		FAIL;
	} else
		CHECK;

	CHECKUNTESTED(1);
>>ASSERTION Good B 1
The
.A source_char
specifies the glyph in the
.A source_font
from which the source bitmap is obtained.
>>STRATEGY
Load xtfont0 using XLoadFont.
Call XCreateGlyphCursor with source_char set to
a known defined glyph in font xtfont0.
Verify that XCreateGlyphCursor returns non-zero.
>>#
>># This code is identical to the code for the previous assertion...pc
>>#
>>CODE
Cursor qstat;

/* Load xtfont0 using XLoadFont. */
	source_font = XLoadFont(display, xtfont0);
	mask_font = source_font;
	source_char = good_char0;
	mask_char = good_char0;

/* Call XCreateGlyphCursor with source_char set to */
/* a known defined glyph in font xtfont0. */
	qstat = XCALL;

/* Verify that XCreateGlyphCursor returns non-zero. */
	if (qstat == (Cursor) 0) {
		report("Returned wrong value %ld", (long) qstat);
		FAIL;
	} else
		CHECK;

	CHECKUNTESTED(1);
>>ASSERTION Good B 1
The
.A mask_char
specifies the glyph in the
.A mask_font
from which the mask bitmap is obtained.
>>STRATEGY
Load xtfont0 using XLoadFont.
Load xtfont1 using XLoadFont.
Call XCreateGlyphCursor with mask_char set to
a known defined glyph in font xtfont1.
Verify that XCreateGlyphCursor returns non-zero.
>>CODE
Cursor qstat;

/* Load xtfont0 using XLoadFont. */
	source_font = XLoadFont(display, xtfont0);
/* Load xtfont1 using XLoadFont. */
	mask_font = XLoadFont(display, xtfont1);

	source_char = good_char0;
	mask_char = good_char1;

/* Call XCreateGlyphCursor with mask_char set to */
/* a known defined glyph in font xtfont1. */
	qstat = XCALL;

/* Verify that XCreateGlyphCursor returns non-zero. */
	if (qstat == (Cursor) 0) {
		report("Returned wrong value %ld", (long) qstat);
		FAIL;
	} else
		CHECK;

	CHECKUNTESTED(1);
>>ASSERTION Good B 1
When
.A mask_char
is zero, then all pixels of the source are displayed.
>>STRATEGY
Load xtfont0 using XLoadFont.
Load xtfont1 using XLoadFont.
Call XCreateGlyphCursor with mask_char set to zero.
Verify that XCreateGlyphCursor returns non-zero.
>>CODE
Cursor qstat;

/* Load xtfont0 using XLoadFont. */
	source_font = XLoadFont(display, xtfont0);
/* Load xtfont1 using XLoadFont. */
	mask_font = XLoadFont(display, xtfont1);

	source_char = good_char0;
	mask_char = 0;

/* Call XCreateGlyphCursor with mask_char set to zero. */
	qstat = XCALL;

/* Verify that XCreateGlyphCursor returns non-zero. */
	if (qstat == (Cursor) 0) {
		report("Returned wrong value %ld", (long) qstat);
		FAIL;
	} else
		CHECK;

	CHECKUNTESTED(1);
>>ASSERTION Good B 1
When
.A mask_char
and
.A mask_font
are non-zero and a given bit in the mask bitmap is 1, then
the corresponding pixel of the source is displayed.
>>STRATEGY
Load xtfont0 using XLoadFont.
Load xtfont1 using XLoadFont.
Call XCreateGlyphCursor with mask_font set to non-zero and
mask_char corresponding to a glyph in mask_font which
has at least one bit set to non-zero.
Verify that XCreateGlyphCursor returns non-zero.
>>#
>># This code is identical to the code in an assertion which,
>># at one time, was located two assertions previous.
>>#
>>CODE
Cursor qstat;

/* Load xtfont0 using XLoadFont. */
	source_font = XLoadFont(display, xtfont0);
/* Load xtfont1 using XLoadFont. */
	mask_font = XLoadFont(display, xtfont1);

	source_char = good_char0;
	mask_char = good_char1;

/* Call XCreateGlyphCursor with mask_font set to non-zero and */
/* mask_char corresponding to a glyph in mask_font which */
/* has at least one bit set to non-zero. */
	qstat = XCALL;

/* Verify that XCreateGlyphCursor returns non-zero. */
	if (qstat == (Cursor) 0) {
		report("Returned wrong value %ld", (long) qstat);
		FAIL;
	} else
		CHECK;

	CHECKUNTESTED(1);
>>ASSERTION Good B 1
When
.A mask_char
and
.A mask_font
are non-zero and a given bit in the mask bitmap is 0, then
the corresponding pixel of the source is not displayed.
>>STRATEGY
Load xtfont0 using XLoadFont.
Load xtfont1 using XLoadFont.
Call XCreateGlyphCursor with mask_font set to non-zero and
mask_char corresponding to a glyph in mask_font which
has at least one bit set to zero.
Verify that XCreateGlyphCursor returns non-zero.
>>#
>># This code is identical to that for the previous assertion.
>>#
>>CODE
Cursor qstat;

/* Load xtfont0 using XLoadFont. */
	source_font = XLoadFont(display, xtfont0);
/* Load xtfont1 using XLoadFont. */
	mask_font = XLoadFont(display, xtfont1);

	source_char = good_char0;
	mask_char = good_char1;

/* Call XCreateGlyphCursor with mask_font set to non-zero and */
/* mask_char corresponding to a glyph in mask_font which */
/* has at least one bit set to zero. */
	qstat = XCALL;

/* Verify that XCreateGlyphCursor returns non-zero. */
	if (qstat == (Cursor) 0) {
		report("Returned wrong value %ld", (long) qstat);
		FAIL;
	} else
		CHECK;

	CHECKUNTESTED(1);
>>ASSERTION Good B 1
When a bit in the source bitmap is 1, then
.A foreground_color
is used.
>>STRATEGY
Load xtfont0 using XLoadFont.
Load xtfont1 using XLoadFont.
Call XCreateGlyphCursor with glyph with at least
one bit in the source bitmap set to 1.
Verify that XCreateGlyphCursor returns non-zero.
>>#
>># This code is identical to that for the previous assertion.
>>#
>>CODE
Cursor qstat;

/* Load xtfont0 using XLoadFont. */
	source_font = XLoadFont(display, xtfont0);
/* Load xtfont1 using XLoadFont. */
	mask_font = XLoadFont(display, xtfont1);

	source_char = good_char0;
	mask_char = good_char1;

/* Call XCreateGlyphCursor with glyph with at least */
/* one bit in the source bitmap set to 1. */
	qstat = XCALL;

/* Verify that XCreateGlyphCursor returns non-zero. */
	if (qstat == (Cursor) 0) {
		report("Returned wrong value %ld", (long) qstat);
		FAIL;
	} else
		CHECK;

	CHECKUNTESTED(1);
>>ASSERTION Good B 1
When a bit in the source bitmap is 0, then
.A background_color
is used.
>>STRATEGY
Load xtfont0 using XLoadFont.
Load xtfont1 using XLoadFont.
Call XCreateGlyphCursor with source char corresponding to glyph which
has at least one bit set to zero.
Verify that XCreateGlyphCursor returns non-zero.
>>CODE
Cursor qstat;

/* Load xtfont0 using XLoadFont. */
	source_font = XLoadFont(display, xtfont0);
/* Load xtfont1 using XLoadFont. */
	mask_font = XLoadFont(display, xtfont1);

	source_char = goodblank_char0;
	mask_char = good_char1;

/* Call XCreateGlyphCursor with source char corresponding to glyph which */
/* has at least one bit set to zero. */
	qstat = XCALL;

/* Verify that XCreateGlyphCursor returns non-zero. */
	if (qstat == (Cursor) 0) {
		report("Returned wrong value %ld", (long) qstat);
		FAIL;
	} else
		CHECK;

	CHECKUNTESTED(1);
>>ASSERTION Good B 1
When
.A mask_char
is non-zero, then its glyph
.M origin
is positioned coincidently with
that of
.A source_char .
>>STRATEGY
Load xtfont0 using XLoadFont.
Load xtfont1 using XLoadFont.
Call XCreateGlyphCursor with non-zero mask_char.
Verify that XCreateGlyphCursor returns non-zero.
>>#
>># This code is identical to that for the previous assertion.
>>#
>>CODE
Cursor qstat;

/* Load xtfont0 using XLoadFont. */
	source_font = XLoadFont(display, xtfont0);
/* Load xtfont1 using XLoadFont. */
	mask_font = XLoadFont(display, xtfont1);

	source_char = goodblank_char0;
	mask_char = good_char1;

/* Call XCreateGlyphCursor with non-zero mask_char. */
	qstat = XCALL;

/* Verify that XCreateGlyphCursor returns non-zero. */
	if (qstat == (Cursor) 0) {
		report("Returned wrong value %ld", (long) qstat);
		FAIL;
	} else
		CHECK;

	CHECKUNTESTED(1);
>>ASSERTION Good B 1
The
.M origin
of the
.A source_char
defines the hotspot.
>>#
>># Don't think we need to repeat yet another test for this case...pc
>>#
>>ASSERTION Good B 1
The
.A source_char
and
.A mask_char
need not have the same bounding box metrics.
>>STRATEGY
Load xtfont0 using XLoadFont.
Call XCreateGlyphCursor with source_char and mask_char
with different bounding boxes.
Verify that XCreateGlyphCursor returns non-zero.
>>CODE
Cursor qstat;

/* Load xtfont0 using XLoadFont. */
	source_font = XLoadFont(display, xtfont0);
	mask_font = source_font;
	source_char = good_char0;
	mask_char = bounding0;
/* Call XCreateGlyphCursor with source_char and mask_char */
/* with different bounding boxes. */

	qstat = XCALL;

/* Verify that XCreateGlyphCursor returns non-zero. */
	if (qstat == (Cursor) 0) {
		report("Returned wrong value %ld", (long) qstat);
		FAIL;
	} else
		CHECK;

	CHECKUNTESTED(1);
>>ASSERTION Good B 1
When a cursor is created by a call to xname,
and the
.A source_font
or
.A mask_font
argument is freed be a subsequent call to
.F XFreeFont ,
then the cursor is unaffected.
>>STRATEGY
Load xtfont0 using XLoadQueryFont.
Verify that XLoadQueryFont returns non-zero.
Load xtfont1 using XLoadQueryFont.
Verify that XLoadQueryFont returns non-zero.
Call XCreateGlyphCursor with foreground colour W_FG and background colour W_BG.
Verify that XCreateGlyphCursor returns non-zero.
Call XFreeFont for xtfont0.
Call XFreeFont for xtfont1.
>>CODE
Cursor qstat;
XFontStruct *font_struct0;
XFontStruct *font_struct1;

/* Load xtfont0 using XLoadQueryFont. */
	font_struct0 = XLoadQueryFont(display, xtfont0);
/* Verify that XLoadQueryFont returns non-zero. */
	if (font_struct0 == (XFontStruct *) 0) {
		delete("Could not load and query font \"%s\".", xtfont0);
		return;
	}
	else
		CHECK;
/* Load xtfont1 using XLoadQueryFont. */
	font_struct1 = XLoadQueryFont(display, xtfont1);
/* Verify that XLoadQueryFont returns non-zero. */
	if (font_struct1 == (XFontStruct *) 0) {
		delete("Could not load and query font \"%s\".", xtfont1);
		return;
	}
	else
		CHECK;
	source_font = font_struct0->fid;
	mask_font = font_struct1->fid;
	source_char = good_char0;
	mask_char = good_char1;
/* Call XCreateGlyphCursor with foreground colour W_FG and background colour W_BG. */

	qstat = XCALL;

/* Verify that XCreateGlyphCursor returns non-zero. */
	if (qstat == (Cursor) 0) {
		report("Returned wrong value %ld", (long) qstat);
		FAIL;
	} else
		CHECK;

/* Call XFreeFont for xtfont0. */
	XFreeFont(display, font_struct0);
/* Call XFreeFont for xtfont1. */
	XFreeFont(display, font_struct1);

	CHECKUNTESTED(3);
>>ASSERTION Good B 1
For 2-byte matrix fonts,
the 16-bit value should be formed with the byte1 member
in the most significant byte and the byte2 member in the
least significant byte.
>>STRATEGY
Load 2-byte matrix font xtfont6 using XLoadFont.
Call XCreateGlyphCursor with foreground colour W_FG and
background colour W_BG.
Verify that XCreateGlyphCursor returns non-zero.
>>CODE
Cursor qstat;

/* Load 2-byte matrix font xtfont6 using XLoadFont. */
	source_font = XLoadFont(display, xtfont6);
	mask_font = source_font;
	source_char = good_char6;
	mask_char = good_char6;
/* Call XCreateGlyphCursor with foreground colour W_FG and */
/* background colour W_BG. */

	qstat = XCALL;

/* Verify that XCreateGlyphCursor returns non-zero. */
	if (qstat == (Cursor) 0) {
		report("Returned wrong value %ld", (long) qstat);
		FAIL;
	} else
		CHECK;

	CHECKUNTESTED(1);
>>ASSERTION Bad B 1
.ER BadAlloc
>>ASSERTION Bad A
When the
.A source_char 
argument is not
a defined glyph in
.A source_font ,
then a
.S BadValue
error occurs.
>>STRATEGY
Load xtfont0 using XLoadFont.
Call XCreateGlyphCursor with a source_char which is
an undefined glyph in source_font.
Verify that a BadValue error occurs.
>>CODE BadValue
Cursor qstat;

/* Load xtfont0 using XLoadFont. */
	source_font = XLoadFont(display, xtfont0);
	mask_font = source_font;
	source_char = bad_char0;
	mask_char = good_char0;

/* Call XCreateGlyphCursor with a source_char which is */
/* an undefined glyph in source_font. */
	XCALL;

/* Verify that a BadValue error occurs. */
	if (geterr() == BadValue)
		PASS;
	else
		FAIL;
>>ASSERTION Bad A
When
.A mask_font
is non-zero and
.A mask_char
is non-zero and not a defined glyph in
.A mask_font ,
then a
.S BadValue
error occurs.
>>STRATEGY
Load xtfont0 using XLoadFont.
Call XCreateGlyphCursor with a mask_char which is
an undefined glyph in mask_font.
Verify that a BadValue error occurs.
>>CODE BadValue
Cursor qstat;

/* Load xtfont0 using XLoadFont. */
	source_font = XLoadFont(display, xtfont0);
	mask_font = source_font;
	source_char = good_char0;
	mask_char = bad_char0;

/* Call XCreateGlyphCursor with a mask_char which is */
/* an undefined glyph in mask_font. */
	XCALL;

/* Verify that a BadValue error occurs. */
	if (geterr() == BadValue)
		PASS;
	else
		FAIL;
>>ASSERTION Bad A
.ER BadFont bad-font
>>#HISTORY peterc Completed Updated as per RTCB#3