summaryrefslogtreecommitdiff
path: root/src/Xw/Xw_get_text_size.cxx
blob: 52dc62ad16554af74e0f086c7dc1efed230bab54 (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
#define GG002	/*GG_020197
		Renvoyer la hauteur du texte et non de la font
*/

#include <Xw_Extension.h>

	/* ifdef then trace on */
#ifdef TRACE
#define TRACE_GET_TEXT_SIZE
#endif

/*
   XW_STATUS Xw_get_text_size (awindow,index,string,width,height,xoffset,yoffset):
   XW_EXT_WINDOW *awindow
   int index			Font Index
   char *string			String to evaluate 
   float *width,*height		Returned String size in DWU
   float *xoffset,*yoffset	Returned text offsets from the text boundary box.

	Evaluate String size depending of the specified font Index. 

	Returns XW_ERROR if Font Index is NOT defined
	Returns XW_SUCCESS if successfull     

*/

#ifdef XW_PROTOTYPE
XW_STATUS Xw_get_text_size (void *awindow,int index,char *string,float *width,float *height,float *xoffset,float *yoffset)
#else
XW_STATUS Xw_get_text_size (awindow,index,string,width,height,xoffset,yoffset)
void *awindow;
int index ;
char *string ;
float *width,*height,*xoffset,*yoffset ;
#endif /*XW_PROTOTYPE*/
{
  XW_EXT_WINDOW *pwindow = (XW_EXT_WINDOW*)awindow;

	*width = *height = *xoffset = *yoffset = 0.;

        if( !Xw_isdefine_window(pwindow) ) {
            /*ERROR*Bad EXT_WINDOW Address*/
            Xw_set_error(24,"Xw_get_text_size",pwindow) ;
            return (XW_ERROR) ;
        }

        if( !Xw_isdefine_font(_FONTMAP,index) ) {
            /*ERROR*Bad Font Index*/
            Xw_set_error(7,"Xw_get_text_size",&index) ;
            return (XW_ERROR) ;
        }

#ifdef GG002
	{
	int dir,fascent,fdescent;
 	XCharStruct overall;
        XTextExtents(_FONTMAP->fonts[index],string,strlen(string),
				&dir,&fascent,&fdescent,&overall);
	*width = UVALUE(overall.width);
	*height = UVALUE(overall.ascent + overall.descent);
	*xoffset = UVALUE(overall.lbearing);
	*yoffset = UVALUE(overall.descent);
	}
#else		/* Renvoyer la hauteur du texte et non de la font */
	*width = UVALUE(XTextWidth(_FONTMAP->fonts[index],
						string,strlen(string))) ;

	*height = UVALUE((_FONTMAP->fonts[index])->ascent +
	  		  	(_FONTMAP->fonts[index])->descent) ;
	*xoffset = 0.;
	*yoffset = UVALUE((_FONTMAP->fonts[index])->descent) ;
#endif


#ifdef  TRACE_GET_TEXT_SIZE
if( Xw_get_trace() > 1 ) {
    printf (" Xw_get_text_size(%lx,'%s',%f,%f,%f,%f\n",
			(long ) awindow,string,*width,*height,*xoffset,*yoffset) ;
}
#endif

	return (XW_SUCCESS);
}