#ifndef lint static char SccsId[] = "%W% %G%"; #endif /* Module: text.c (Text Image) * Subroutine: btn_MakeTextImage() returns: void * Copyright: 1989 Smithsonian Astrophysical Observatory * You may do anything you like with this file except remove * this copyright. The Smithsonian Astrophysical Observatory * makes no representations about the suitability of this * software for any purpose. It is provided "as is" without * express or implied warranty. * Modified: {0} Michael VanHilst initial version 24 March 1990 * {n} -- -- */ #include #include #include "btnchars.h" btn_InitTool () { /* do nothing (dummy for compatability) */ } /* * Subroutine: btn_MakeTextImage * Purpose: given a string, return a Z image of the word(s), and some info * Note: unoccupied and unoccupied refers to highlighting when pointer * is on the button, or somewhere else */ char *btn_MakeTextImage ( title, width, height, breaklist, breakcnt, sign, in ) char *title; /* i: the label string */ int *width, *height; /* o: width and height of image */ int *breaklist; /* o: array of x offsets of right char edges */ int *breakcnt; /* o: number of chars */ int sign; /* i: sign is code for rotation */ int in; /* i: flag for occupied or unoccupied font */ { struct bitfont *textfont; char *image; char *btn_RotateImage(), *btn_Alloc(); static int btn_ListTextBreaks(); static void btn_MakeZImage(); /* set font for occupation state */ if( in ) textfont = intext; else textfont = outtext; /* set list of lengths to breaks between letters */ *breakcnt = btn_ListTextBreaks(title, textfont, breaklist); /* determine size of full text label */ *width = breaklist[*breakcnt - 1]; *height = textfont->height; image = btn_Alloc(*width * *height, 1, "text image"); /* create the label image (use Z image, it's easier to rotate) */ btn_MakeZImage(title, *breakcnt, textfont, breaklist, *width, *height, image); /* rotate if desired */ if( sign != 0 ) image = btn_RotateImage(image, *width, *height, sign); return( image ); } /* * Subroutine: btn_ListTextBreaks * Purpose: create list of x offsets of breaks between letter in label */ static int btn_ListTextBreaks ( title, textfont, breaklist ) char *title; struct bitfont *textfont; int *breaklist; { unsigned char *alpha; int len, cnt, i; cnt = strlen(title); alpha = (unsigned char *)title; len = 0; for( i=0; ibits; if( height == alpha->height ) { image += x; ycnt = height; } else { if( height > alpha->height ) { ycnt = alpha->height; /* character is taller than the image */ form += (height - ycnt) * alpha->byte_width; } else { /* character is shorter than image */ ycnt = height; image += ((alpha->height - height) * width) + x; } } for( y=0; ybyte_width; byte++ ) { for( bit=0; bit<8; bit++ ) { mask = 1 << bit; if( *form & mask ) *image_char = 1; ++image_char; } ++form; } image += width; } }