0022627: Change OCCT memory management defaults
[occt.git] / src / Xw / Xw_get_font_index.cxx
CommitLineData
7fd59977 1
2#include <Xw_Extension.h>
3
4 /* ifdef then trace on */
5#ifdef TRACE
6#define TRACE_GET_FONT_INDEX
7#endif
8
9/*
10 STATUS Xw_get_font_index(afontmap,size,fontname,index):
11
12 XW_EXT_FONTMAP *afontmap Fontmap extension structure
13 float size ; Font size in MM
14 char *fontname ; Font descriptor ended with '\0'
15 int *index ; Return Font index 0 >= x < MAXFONT
16
17 Gets the nearest font index from Font Descriptor.
18
19 Returns ERROR if BadFont Index or font is not defined
20 Returns SUCCESS if Successful
21
22*/
23
24#ifdef XW_PROTOTYPE
25XW_STATUS Xw_get_font_index(void* afontmap,float size,char* fontname,int* index)
26#else
27XW_STATUS Xw_get_font_index(afontmap,size,fontname,index)
28void *afontmap ;
29float size ;
30char *fontname ;
31int *index ;
32#endif /*XW_PROTOTYPE*/
33{
34XW_EXT_FONTMAP *pfontmap = (XW_EXT_FONTMAP*)afontmap ;
35XW_STATUS status = XW_ERROR ;
36int i,j ;
37
38 if( !pfontmap ) {
39 /*ERROR*Bad EXT_FONTMAP Address*/
40 Xw_set_error( 44,"Xw_get_font_index",pfontmap ) ;
41 return( XW_ERROR ) ;
42 }
43
44 if( fontname && strlen(fontname) ) {
45
46 for( i=j=0 ; i<pfontmap->maxfont ; i++ ) {
47 if( pfontmap->gnames[i] ) {
48 if( !strcmp(fontname,pfontmap->gnames[i]) ) {
49 if( fabs(size-pfontmap->gsizes[i]) < 0.1 ) break;
50 }
51 } else if( !j ) j = i ;
52 }
53
54 if( i<pfontmap->maxfont ) {
55 *index = i ;
56 status = XW_SUCCESS ;
57 } else {
58 *index = j ;
59 status = Xw_def_font (pfontmap,j,size,fontname) ;
60 }
61 } else {
62 *index = 0 ;
63 status = XW_SUCCESS ;
64 }
65
66#ifdef TRACE_GET_FONT_INDEX
67if( Xw_get_trace() > 1 ) {
68 printf(" %d = Xw_get_font_index(%lx,%f,'%s',%d)\n",
69 status,(long ) pfontmap,size,fontname,*index) ;
70}
71#endif
72
73 return( status ) ;
74}