summaryrefslogtreecommitdiff
path: root/xts5/src/lib/checkfont.c
blob: f2c54985fd78213bf5d481a8ad2462d136b7f433 (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
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
/*
Copyright (c) 2005 X.Org Foundation L.L.C.

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
AUTHORS OR COPYRIGHT HOLDERS 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.
*/
/*
*
* Copyright Applied Testing and Technology Inc. 1995
* All rights reserved
*
* Project: VSW5
*
* File:	xts5/src/lib/checkfont.c
*
* Description:
*	Font support routines
*
* Modifications:
* $Log: checkfont.c,v $
* Revision 1.2  2005-11-03 08:42:01  jmichael
* clean up all vsw5 paths to use xts5 instead.
*
* Revision 1.1.1.2  2005/04/15 14:05:09  anderson
* Reimport of the base with the legal name in the copyright fixed.
*
* Revision 8.0  1998/12/23 23:24:27  mar
* Branch point for Release 5.0.2
*
* Revision 7.0  1998/10/30 22:42:38  mar
* Branch point for Release 5.0.2b1
*
* Revision 6.0  1998/03/02 05:16:52  tbr
* Branch point for Release 5.0.1
*
* Revision 5.0  1998/01/26 03:13:25  tbr
* Branch point for Release 5.0.1b1
*
* Revision 4.2  1998/01/12 22:59:58  andy
* Corrected checking for ANSI mode
*
* Revision 4.1  1996/01/25 01:57:14  andy
* Portability improvements from DEPLOY tools
*
* Revision 4.0  1995/12/15  08:41:56  tbr
* Branch point for Release 5.0.0
*
* Revision 3.1  1995/12/15  00:39:04  andy
* Prepare for GA Release
*
*/

/*
Portions of this software are based on Xlib and X Protocol Test Suite.
We have used this material under the terms of its copyright, which grants
free use, subject to the conditions below.  Note however that those
portions of this software that are based on the original Test Suite have
been significantly revised and that all such revisions are copyright (c)
1995 Applied Testing and Technology, Inc.  Insomuch as the proprietary
revisions cannot be separated from the freely copyable material, the net
result is that use of this software is governed by the ApTest copyright.

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.
*/


#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include	"stdlib.h"
#include	"stdio.h"
#include	"xtest.h"
#include	"X11/Xlib.h"
#include	"X11/Xutil.h"
#include	"X11/Xatom.h"
#include	"tet_api.h"
#include	"xtestlib.h"
#include	"pixval.h"

extern	Display *Dsp;

extern	XFontStruct	xtfont0, xtfont1, xtfont2, xtfont3, xtfont4;
extern	XFontStruct xtfont5, xtfont6;
extern	char	*xtfont0cpright;
extern	char	*xtfont1cpright;
extern	char	*xtfont2cpright;
extern	char	*xtfont3cpright;
extern	char	*xtfont4cpright;
extern	char	*xtfont5cpright;
extern	char	*xtfont6cpright;

struct	fontinfo fontinfo[] = {
	{"xtfont0", &xtfont0, &xtfont0cpright},
	{"xtfont1", &xtfont1, &xtfont1cpright},
	{"xtfont2", &xtfont2, &xtfont2cpright},
	{"xtfont3", &xtfont3, &xtfont3cpright},
	{"xtfont4", &xtfont4, &xtfont4cpright},
	{"xtfont5", &xtfont5, &xtfont5cpright},
	{"xtfont6", &xtfont6, &xtfont6cpright},
};
int 	nfontinfo = NELEM(fontinfo);

#ifdef __STDC__
static int checkprops(XFontStruct *fsp, XFontStruct *good, char *str);
static XCharStruct *getmetric(XFontStruct *fsp, unsigned int c);
static check1prop(XFontStruct *fsp, XFontProp *fp, char *str);
#else
static int checkprops();
static XCharStruct *getmetric();
static check1prop();
#endif

/*
 * Check a XCharStruct item.  FAIL is issued on error, PASS is not.
 * Used by checkfsp().
 * Returns True if checking is OK.
 */
static int
checkcharstruct(csp, good, name)
XCharStruct	*csp;
XCharStruct	*good;
char	*name;
{
int 	pass = 0, fail = 0;

	if (csp->lbearing != good->lbearing) {
		report("%s, lbearing was %d, expecting %d",
			name, csp->lbearing, good->lbearing);
		FAIL;
	} else
		pass++;

	if (csp->rbearing != good->rbearing) {
		report("%s, rbearing was %d, expecting %d",
			name, csp->rbearing, good->rbearing);
		FAIL;
	} else
		pass++;

	if (csp->width != good->width) {
		report("%s, width was %d, expecting %d",
			name, csp->width, good->width);
		FAIL;
	} else
		pass++;

	if (csp->ascent != good->ascent) {
		report("%s, ascent was %d, expecting %d",
			name, csp->ascent, good->ascent);
		FAIL;
	} else
		pass++;

	if (csp->descent != good->descent) {
		report("%s, descent was %d, expecting %d",
			name, csp->descent, good->descent);
		FAIL;
	} else
		pass++;

	if (fail == 0 && pass == 5)
		return(True);
	else {
		if (fail == 0)
			report("Path check error in checkcharstruct");
		return(False);
	}
}


/*
 * Check a XFontStruct against a known good one.  The font property
 * checking is based on a knowledge of the properties defined in the xtest
 * fonts.
 */
int
checkfsp(fsp, good, str)
XFontStruct	*fsp;
XFontStruct	*good; /* Known good XFontStruct */
char	*str;	/* Known good copyright string */
{
int 	i;
int 	nchars;
int 	metrics_correct;
int 	pass = 0, fail = 0;
	
	if (fsp == NULL) {
		report("returned XFontStruct pointer was NULL");
		FAIL;
		return(False);
	}

	/*
	 * No clear definition of what this hint is
	 */
	if (fsp->direction != FontLeftToRight && fsp->direction != FontRightToLeft){
		report("direction was %d, expecting %d", fsp->direction, good->direction);
		FAIL;
	} else
		pass++;

	if (fsp->min_char_or_byte2 != good->min_char_or_byte2) {
		report("min_char_or_byte2 was %d, expecting %d", fsp->min_char_or_byte2, good->min_char_or_byte2);
		FAIL;
	} else
		pass++;

	if (fsp->max_char_or_byte2 != good->max_char_or_byte2) {
		report("max_char_or_byte2 was %d, expecting %d", fsp->max_char_or_byte2,
			good->max_char_or_byte2);
		FAIL;
	} else
		pass++;

	if (fsp->min_byte1 != good->min_byte1) {
		report("min_byte1 was %d, expecting %d", fsp->min_byte1,
			good->min_byte1);
		FAIL;
	} else
		pass++;

	if (fsp->max_byte1 != good->max_byte1) {
		report("max_byte1 was %d, expecting %d", fsp->max_byte1,
			good->max_byte1);
		FAIL;
	} else
		pass++;

	if (fsp->all_chars_exist != good->all_chars_exist) {
		report("all_chars_exist was %d, expecting %d", fsp->all_chars_exist,
			good->all_chars_exist);
		FAIL;
	} else
		pass++;

	if (fsp->default_char != good->default_char) {
		report("default_char was %d, expecting %d", fsp->default_char,
			good->default_char);
		FAIL;
	} else
		pass++;

	/*
	 * There may be extra properties added by the font compiler, so
	 * we can only check that there are at least enough properties.
	 */
	if (fsp->n_properties < good->n_properties) {
		report("n_properties was %d, expecting a number greater than %d",
			fsp->n_properties, good->n_properties);
		FAIL;
	} else
		pass++;

	if (fsp->ascent != good->ascent) {
		report("ascent was %d, expecting %d", fsp->ascent, good->ascent);
		FAIL;
	} else
		pass++;

	if (fsp->descent != good->descent) {
		report("descent was %d, expecting %d", fsp->descent, good->descent);
		FAIL;
	} else
		pass++;

	/*
	 * Check that the per_char pointer is NULL or not as appropriate.
	 */
	if (good->per_char == NULL) {
		if (fsp->per_char == NULL)
			pass++;
		else {
			report("The per_char member of XFontStruct was not NULL");
			FAIL;
		}
	} else {
		if (fsp->per_char == NULL) {
			report("The per_char member of XFontStruct was NULL");
			FAIL;
		} else {
			pass++;
		}
	}

	if (checkcharstruct(&fsp->min_bounds, &good->min_bounds, "min_bounds"))
		pass++;
	else {
		report("min_bound check failed");
		FAIL;
	}
	if (checkcharstruct(&fsp->max_bounds, &good->max_bounds, "max_bounds"))
		pass++;
	else {
		report("max_bounds check failed");
		FAIL;
	}


	if (fsp->per_char != NULL && good->per_char != NULL) {
	int 	giveup;

#define percharsize(FSP) ( (FSP->max_char_or_byte2 - FSP->min_char_or_byte2 + 1) * (FSP->max_byte1 - FSP->min_byte1 + 1))

		nchars = percharsize(good);
		/*
		 * Make sure that we don't run off the end of the array, if
		 * the min and max chars are wrong then will probably fail,
		 * but try anyway.
		 */
		if (nchars > percharsize(fsp))
			nchars = percharsize(fsp);

		/*
		 * If the max and min bytes are wrong then there is not much
		 * chance that the per_char metrics will tally, so if there
		 * have been previous errors then abandon checking per_char
		 * after a few errors.
		 */
		giveup = 9999;
		if (fail)
			giveup = 3;

		metrics_correct = 0;

		for (i = 0; i < nchars; i++) {
		char	mess[32];

			sprintf(mess, "char %d", i);

			if (checkcharstruct(&fsp->per_char[i], &good->per_char[i], mess))
				metrics_correct++;
			else if (--giveup == 0) {
				report("Abandoning checks to other characters");
				break;
			}
		}

		if (metrics_correct == nchars)
			pass++;
		else {
			if (giveup == 0) {
				report("Metrics bad, %d correct seen before abandoning checks",
					metrics_correct);
			} else {
				report("Metrics for %d out of %d chars incorrect",
					nchars-metrics_correct, nchars);
			}
			FAIL;
		}
	} else {
		/* Nothing to check */
		pass++;
	}

	if (checkprops(fsp, good, str))
		pass++;
	else {
		report("Property checking failed");
		FAIL;
	}

	if (fail == 0 && pass == 15) {
		return(True);
	} else {
		if (fail == 0)
			report("Path check error in checkfsp");
		return(False);
	}
}

/*
 * Check each of the properties that we have chosen to test.  There may be
 * other properties defined in the returned XFontStruct which are ignored.
 */
static int
checkprops(fsp, good, str)
XFontStruct	*fsp;
XFontStruct	*good;
char	*str;
{
XFontProp	*fp;
int 	pass = 0, fail = 0;

	for (fp = good->properties;
		  fp < &good->properties[good->n_properties];
		  fp++) {
		if (check1prop(fsp, fp, str))
			pass++;
		else
			fail++;
	}
	if (fail == 0 && pass == good->n_properties)
		return(True);
	else
		return(False);
}

/*
 * Check a single property
 */
static
check1prop(fsp, fp, str)
XFontStruct	*fsp;
XFontProp	*fp;
char	*str;
{
XFontProp	*testp;
char	*teststr;
int 	found;
int 	pass = 0, fail = 0;

	found = 0;
	for (testp = fsp->properties; testp < &fsp->properties[fsp->n_properties];
			testp++){
		
		if (testp->name == fp->name) {
			found = 1;

			if (fp->name == XA_COPYRIGHT) {

				/*
				 * This is a string value, so have to get the atom value.
				 * Have to disable default error processing because the
				 * atom may not exist.
				 */
				XSetErrorHandler(error_status);
				reseterr();
				teststr = XGetAtomName(Dsp, testp->card32);
				XSetErrorHandler(unexp_err);

				switch (geterr()) {
				case Success:
					break;
				case BadAtom:
					report("XA_COPYRIGHT atom value was not a valid atom");
					FAIL;
					break;
				default:
					delete("Unexpected error on XGetAtomName");
					return(False);
				}

				if (str && strcmp(teststr, str) != 0) {
					report("XA_COPYRIGHT string..");
					report(" was '%s'", teststr);
					report(" expecting '%s'", str);
					FAIL;
				}
				else
					pass++;
			} else {
				if (testp->card32 != fp->card32) {
					report("Value of %s was %d, expecting %d",
						atomname(fp->name), testp->card32, fp->card32);
					FAIL;
				}
				else
					pass++;
			}
		}
	}
	if (!found) {
		report("Font property %s not found", atomname(fp->name));
		FAIL;
	}
	else
		pass++;
	if (fail == 0 && pass == 2)
		return(True);
	else
		return(False);
}


#define	min(a, b) ((a)<(b)? (a): (b))
#define	max(a, b) ((a)>(b)? (a): (b))

/*
 * Direct calculation of extents.
 */
void
txtextents(fsp, str, n, dir, ascent, descent, overall)
XFontStruct	*fsp;
unsigned char	*str;
int 	n;
int 	*dir;	/*NOTUSED*/
int 	*ascent;
int 	*descent;
XCharStruct	*overall;
{
int 	i;
unsigned int 	c;
XCharStruct	*cm;
extern XCharStruct	*getmetric();
short 	width;
short 	rbearing = 0;
short 	lbearing = 0;
short  	oascent = 0;
short  	odescent = 0;
int 	firstchar = 1;

	*ascent = fsp->ascent;
	*descent = fsp->descent;

	/*
	 * If there are no per_char metrics then use max_bounds
	 * of the font width.
	 */
	if (fsp->per_char == NULL) {
		rbearing = max(fsp->max_bounds.rbearing, (n-1)*fsp->max_bounds.width + fsp->max_bounds.rbearing);
		lbearing = min(fsp->max_bounds.lbearing, (n-1)*fsp->max_bounds.width + fsp->max_bounds.lbearing);
		oascent = fsp->max_bounds.ascent;
		odescent = fsp->max_bounds.descent;
		width = n*fsp->max_bounds.width;
	}

	width = 0;
	for (i = 0; i < n; i++) {
		c = str[i];

		cm = getmetric(fsp, c);
		if (cm == NULL)
			cm = getmetric(fsp, fsp->default_char);

		if (cm == NULL)
			continue;

		if (firstchar) {
			firstchar = 0;
			rbearing = cm->rbearing;
			lbearing = cm->lbearing;
			oascent = cm->ascent;
			odescent = cm->descent;
			width = cm->width;
		} else {
			rbearing = max(width+cm->rbearing, rbearing);
			lbearing = min(width+cm->lbearing, lbearing);
			oascent = max(oascent, cm->ascent);
			odescent = max(odescent, cm->descent);
			width += cm->width;
		}
	}
	overall->rbearing = rbearing;
	overall->lbearing = lbearing;
	overall->width = width;
	overall->ascent = oascent;
	overall->descent = odescent;
}

/*
 * Direct calculation of extents with 16bit strings.
 */
void
txtextents16(fsp, str, n, dir, ascent, descent, overall)
XFontStruct	*fsp;
XChar2b	*str;
int 	n;
int 	*dir;
int 	*ascent;
int 	*descent;
XCharStruct	*overall;
{
int 	i;
unsigned int 	c;
XCharStruct	*cm;
extern XCharStruct	*getmetric();
short	width;
short	rbearing = 0;
short	lbearing = 0;
short	oascent = 0;
short	odescent = 0;
int 	firstchar = 1;

	*ascent = fsp->ascent;
	*descent = fsp->descent;

	/*
	 * If there are no per_char metrics then use max_bounds
	 * of the font width.
	 */
	if (fsp->per_char == NULL) {
		rbearing = max(fsp->max_bounds.rbearing, (n-1)*fsp->max_bounds.width + fsp->max_bounds.rbearing);
		lbearing = min(fsp->max_bounds.lbearing, (n-1)*fsp->max_bounds.width + fsp->max_bounds.lbearing);
		oascent = fsp->max_bounds.ascent;
		odescent = fsp->max_bounds.descent;
		width = n*fsp->max_bounds.width;
	}

	width = 0;
	for (i = 0; i < n; i++) {
		c = str[i].byte1;
		c <<= 8;
		c += str[i].byte2;

		cm = getmetric(fsp, c);
		if (cm == NULL)
			cm = getmetric(fsp, fsp->default_char);

		if (cm == NULL)
			continue;

		if (firstchar) {
			firstchar = 0;
			rbearing = cm->rbearing;
			lbearing = cm->lbearing;
			oascent = cm->ascent;
			odescent = cm->descent;
			width = cm->width;
		} else {
			rbearing = max(width+cm->rbearing, rbearing);
			lbearing = min(width+cm->lbearing, lbearing);
			oascent = max(oascent, cm->ascent);
			odescent = max(odescent, cm->descent);
			width += cm->width;
		}
	}
	overall->rbearing = rbearing;
	overall->lbearing = lbearing;
	overall->width = width;
	overall->ascent = oascent;
	overall->descent = odescent;
}

/*
 * Direct calculation of width.
 */
int
txtwidth(fsp, str, n)
XFontStruct	*fsp;
unsigned char	*str;
int 	n;
{
XCharStruct	cm;
int 	dum;

	txtextents(fsp, str, n, &dum, &dum, &dum, &cm);
	return(cm.width);
}

/*
 * Direct calculation of width for 16 bit strings.
 */
int
txtwidth16(fsp, str, n)
XFontStruct	*fsp;
XChar2b	*str;
int 	n;
{
XCharStruct	cm;
int 	dum;

	txtextents16(fsp, str, n, &dum, &dum, &dum, &cm);
	return(cm.width);
}

/*
 * Get a metric.  Note that the spec states that a character is non-existant
 * when all metrics are zero.  Xlib only checks width, lbearing and rbearing.
 * All metrics zero is used here.
 */
static XCharStruct *
getmetric(fsp, c)
XFontStruct	*fsp;
unsigned int 	c;
{
XCharStruct	*cm;
int 	byte1;
int 	byte2;

	byte1 = (c>>8)&0xff;
	byte2 = c&0xff;

	/*
	 * Out of range character.
	 */
	if (byte1 < fsp->min_byte1 || byte1 > fsp->max_byte1)
		return((XCharStruct *)0);
	if (byte2 < fsp->min_char_or_byte2 || byte2 > fsp->max_char_or_byte2)
		return((XCharStruct *)0);

	c = (byte1-fsp->min_byte1)*(fsp->max_char_or_byte2 - fsp->min_char_or_byte2+1)
		+ byte2 - fsp->min_char_or_byte2;
	cm = &fsp->per_char[c];
	/*
	 * Check for non-existant character.
	 */
	if (cm->lbearing == 0 && cm->rbearing == 0 &&
			cm->ascent == 0 && cm->descent == 0 &&
			cm->width == 0) {
		return((XCharStruct*)0);
	}
	return(cm);
}