1 // Copyright (c) 1999-2012 OPEN CASCADE SAS
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.
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.
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.
19 #include <Xw_Extension.h>
21 /* ifdef then trace on */
23 #define TRACE_GET_TYPE_INDEX
27 XW_STATUS Xw_get_type_index(atypemap,desc,length,index):
29 XW_EXT_TYPEMAP *atypemap Typemap extension structure
30 float desc[] ; Style Descriptor Values
31 int length ; Stle Descriptor length
32 int *index ; Return Type index 0 >= x < MAXTYPE
34 Gets the nearest type index from Style Descriptor values.
36 Returns XW_ERROR if BadType Index or type is not defined
37 Returns XW_SUCCESS if Successful
42 XW_STATUS Xw_get_type_index(void *atypemap,float desc[],int length,int *index)
44 XW_STATUS Xw_get_type_index(atypemap,desc,length,index)
49 #endif /*XW_PROTOTYPE*/
51 XW_EXT_TYPEMAP *ptypemap = (XW_EXT_TYPEMAP*)atypemap ;
52 XW_STATUS status = XW_ERROR ;
56 /*ERROR*Bad EXT_TYPEMAP Address*/
57 Xw_set_error( 51,"Xw_get_type_index",ptypemap ) ;
62 unsigned char *pdesc = (unsigned char*) Xw_malloc(length+1) ;
63 Screen *screen = ScreenOfDisplay(_TDISPLAY,DefaultScreen(_TDISPLAY)) ;
65 for( i=0 ; i<length ; i++ ) {
66 ptype = (int) (0.5 + (desc[i] * (float)WidthOfScreen(screen)/
67 (float)WidthMMOfScreen(screen))) ;
68 pdesc[i] = (unsigned char) (ptype) ? ptype : 1 ;
72 for( i=j=0 ; i<ptypemap->maxtype ; i++ ) {
73 if( ptypemap->types[i] ) {
74 if( !strcmp((char*)pdesc,(char*)ptypemap->types[i]) ) break;
75 } else if( !j ) j = i ;
78 if( i<ptypemap->maxtype ) {
83 status = Xw_def_type (ptypemap,j,length,desc) ;
91 #ifdef TRACE_GET_TYPE_INDEX
92 if( Xw_get_trace() > 1 ) {
93 printf(" %d = Xw_get_type_index(%lx,%f,%d,%d)\n",
94 status,(long ) ptypemap,desc[0],length,*index) ;