b311480e |
1 | // Copyright (c) 1999-2012 OPEN CASCADE SAS |
2 | // |
3 | // The content of this file is subject to the Open CASCADE Technology Public |
4 | // License Version 6.5 (the "License"). You may not use the content of this file |
5 | // except in compliance with the License. Please obtain a copy of the License |
6 | // at http://www.opencascade.org and read it completely before using this file. |
7 | // |
8 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its |
9 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. |
10 | // |
11 | // The Original Code and all software distributed under the License is |
12 | // distributed on an "AS IS" basis, without warranty of any kind, and the |
13 | // Initial Developer hereby disclaims all such warranties, including without |
14 | // limitation, any warranties of merchantability, fitness for a particular |
15 | // purpose or non-infringement. Please see the License for the specific terms |
16 | // and conditions governing the rights and limitations under the License. |
17 | |
7fd59977 |
18 | |
19 | #include <Xw_Extension.h> |
20 | |
b311480e |
21 | /* ifdef then trace on */ |
7fd59977 |
22 | #ifdef TRACE |
23 | #define TRACE_GET_FONT_INDEX |
24 | #endif |
25 | |
26 | /* |
27 | STATUS Xw_get_font_index(afontmap,size,fontname,index): |
28 | |
29 | XW_EXT_FONTMAP *afontmap Fontmap extension structure |
30 | float size ; Font size in MM |
31 | char *fontname ; Font descriptor ended with '\0' |
32 | int *index ; Return Font index 0 >= x < MAXFONT |
33 | |
34 | Gets the nearest font index from Font Descriptor. |
35 | |
36 | Returns ERROR if BadFont Index or font is not defined |
37 | Returns SUCCESS if Successful |
38 | |
39 | */ |
40 | |
41 | #ifdef XW_PROTOTYPE |
42 | XW_STATUS Xw_get_font_index(void* afontmap,float size,char* fontname,int* index) |
43 | #else |
44 | XW_STATUS Xw_get_font_index(afontmap,size,fontname,index) |
45 | void *afontmap ; |
46 | float size ; |
47 | char *fontname ; |
48 | int *index ; |
49 | #endif /*XW_PROTOTYPE*/ |
50 | { |
51 | XW_EXT_FONTMAP *pfontmap = (XW_EXT_FONTMAP*)afontmap ; |
52 | XW_STATUS status = XW_ERROR ; |
53 | int i,j ; |
54 | |
55 | if( !pfontmap ) { |
56 | /*ERROR*Bad EXT_FONTMAP Address*/ |
57 | Xw_set_error( 44,"Xw_get_font_index",pfontmap ) ; |
58 | return( XW_ERROR ) ; |
59 | } |
60 | |
61 | if( fontname && strlen(fontname) ) { |
62 | |
63 | for( i=j=0 ; i<pfontmap->maxfont ; i++ ) { |
64 | if( pfontmap->gnames[i] ) { |
65 | if( !strcmp(fontname,pfontmap->gnames[i]) ) { |
66 | if( fabs(size-pfontmap->gsizes[i]) < 0.1 ) break; |
67 | } |
68 | } else if( !j ) j = i ; |
69 | } |
70 | |
71 | if( i<pfontmap->maxfont ) { |
72 | *index = i ; |
73 | status = XW_SUCCESS ; |
74 | } else { |
75 | *index = j ; |
76 | status = Xw_def_font (pfontmap,j,size,fontname) ; |
77 | } |
78 | } else { |
79 | *index = 0 ; |
80 | status = XW_SUCCESS ; |
81 | } |
82 | |
83 | #ifdef TRACE_GET_FONT_INDEX |
84 | if( Xw_get_trace() > 1 ) { |
85 | printf(" %d = Xw_get_font_index(%lx,%f,'%s',%d)\n", |
86 | status,(long ) pfontmap,size,fontname,*index) ; |
87 | } |
88 | #endif |
89 | |
90 | return( status ) ; |
91 | } |