/* name: stk_font.cc info: stk font handling objects and routines - implementation author: Dusan Halicky (dvh.tosomja@post.sk) licence: GNU GPL history: 2005-09-27 - start of developement todo: - finish and release this bugs: - */ // system header files #include #include #include #include // local header files #include "stk_constants.h" #include "stk_display.h" #include "stk_functions.h" // this file header #include "stk_font.h" // debugging #ifdef STK_DEBUG #define STK_FONT_DEBUG #endif // implementation XFontStruct *stkfont; int stkfont_cor; // baseline correction void stk_font_init(void) { // initialize standard STK font stkfont = stk_font_load(STK_FONT_DEFAULT); stkfont_cor = 2; #ifdef STK_FONT_DEBUG printf("stk_font: font = 0x%X\n",(int)stkfont); #endif } void stk_font_done(void) { // release variables } void stk_font_clip_rect(XFontStruct *font_struct, char *string, int *w, int *h, bool decode) { // return screen size of string int count=strlen(string); #ifdef STK_FONT_DEBUG printf("stk_font_clip_rect: font_struct=0x%X string='%s' count=%d decode=%d\n", (int)font_struct, string, count, decode); #endif if (string) { char *dc; if (decode) { // decode caption if decode==true dc = stk_decode_caption(string,NULL,NULL); count = strlen(dc); *w = XTextWidth(font_struct,dc,count); *h = font_struct->ascent; } else { // include & in text width *w = XTextWidth(font_struct,string,count); *h = font_struct->ascent; } } else { *w=0; *h=0; } } XFontStruct *stk_font_load(char *name) { // load the font, debug, set some variables XFontStruct *pomf; #ifdef STK_FONT_DEBUG printf("stk_font_load: loading font (display=0x%X) '%s' ..",(int)stkdisplay,name); fflush(stdout); #endif pomf = XLoadQueryFont(stkdisplay,name); if (pomf->fid <= 0) { printf("stk_font: error, cannot load font!\n"); exit(1); } #ifdef STK_FONT_DEBUG else { printf(". done (pomf=0x%X)\n",(int)pomf); } #endif return pomf; /* int dir_ret = 0; int font_asc_ret = 0; int font_des_ret = 0; XCharStruct ch_struct_ret; XFontStruct *pismo_struct = XQueryFont(dpy,pismo); int sirka = XTextExtents(pismo_struct,"Start",5,&dir_ret,&font_asc_ret,&font_des_ret,&ch_struct_ret); printf("XTextExtents: i=%d dir_ret=%d font_asc_ret=%d font_des_ret=%d ch_struct_ret=%d\n",i,dir_ret,font_asc_ret,font_des_ret,ch_struct_ret); */ }