home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC Shareware 1999 March
/
PCShareware-3-99.iso
/
IMPLE
/
DJGPP.RAR
/
DJGPP2
/
XLIB-SR0.ZIP
/
SRC
/
XLIBEMU
/
CURSFNT.C
< prev
next >
Wrap
C/C++ Source or Header
|
1994-01-11
|
4KB
|
166 lines
/* $Id: cursfnt.c 1.1 1994/01/12 04:35:08 ulrich Exp $ */
/*
* cursfnt.c
*
* Create an GRX font file for X glyph cursors.
*/
#include <grx.h>
#include <grxfont.h>
#include <grxfile.h>
#include <stdio.h>
#include "cursorfont.h"
#include "cursor.h"
#define INIT_GLYPH(name) \
{ XC_##name, name##_width, name##_height, name##_x_hot, name##_y_hot, name##_bits }, \
{ XC_##name+1, name##_mask_width, name##_mask_height, name##_x_hot, name##_y_hot, name##_mask_bits }
struct cursor_glyph {
int code;
int width;
int height;
int x_hot;
int y_hot;
char *bits;
} glyphs[XC_num_glyphs] = {
INIT_GLYPH(X_cursor),
INIT_GLYPH(arrow),
INIT_GLYPH(based_arrow_down),
INIT_GLYPH(based_arrow_up),
INIT_GLYPH(boat),
INIT_GLYPH(bogosity),
INIT_GLYPH(bottom_left_corner),
INIT_GLYPH(bottom_right_corner),
INIT_GLYPH(bottom_side),
INIT_GLYPH(bottom_tee),
INIT_GLYPH(box_spiral),
INIT_GLYPH(center_ptr),
INIT_GLYPH(circle),
INIT_GLYPH(clock),
INIT_GLYPH(coffee_mug),
INIT_GLYPH(cross),
INIT_GLYPH(cross_reverse),
INIT_GLYPH(crosshair),
INIT_GLYPH(diamond_cross),
INIT_GLYPH(dot),
INIT_GLYPH(dotbox),
INIT_GLYPH(double_arrow),
INIT_GLYPH(draft_large),
INIT_GLYPH(draft_small),
INIT_GLYPH(draped_box),
INIT_GLYPH(exchange),
INIT_GLYPH(fleur),
INIT_GLYPH(gobbler),
INIT_GLYPH(gumby),
INIT_GLYPH(hand1),
INIT_GLYPH(hand2),
INIT_GLYPH(heart),
INIT_GLYPH(icon),
INIT_GLYPH(iron_cross),
INIT_GLYPH(left_ptr),
INIT_GLYPH(left_side),
INIT_GLYPH(left_tee),
INIT_GLYPH(leftbutton),
INIT_GLYPH(ll_angle),
INIT_GLYPH(lr_angle),
INIT_GLYPH(man),
INIT_GLYPH(middlebutton),
INIT_GLYPH(mouse),
INIT_GLYPH(pencil),
INIT_GLYPH(pirate),
INIT_GLYPH(plus),
INIT_GLYPH(question_arrow),
INIT_GLYPH(right_ptr),
INIT_GLYPH(right_side),
INIT_GLYPH(right_tee),
INIT_GLYPH(rightbutton),
INIT_GLYPH(rtl_logo),
INIT_GLYPH(sailboat),
INIT_GLYPH(sb_down_arrow),
INIT_GLYPH(sb_h_double_arrow),
INIT_GLYPH(sb_left_arrow),
INIT_GLYPH(sb_right_arrow),
INIT_GLYPH(sb_up_arrow),
INIT_GLYPH(sb_v_double_arrow),
INIT_GLYPH(shuttle),
INIT_GLYPH(sizing),
INIT_GLYPH(spider),
INIT_GLYPH(spraycan),
INIT_GLYPH(star),
INIT_GLYPH(target),
INIT_GLYPH(tcross),
INIT_GLYPH(top_left_arrow),
INIT_GLYPH(top_left_corner),
INIT_GLYPH(top_right_corner),
INIT_GLYPH(top_side),
INIT_GLYPH(top_tee),
INIT_GLYPH(trek),
INIT_GLYPH(ul_angle),
INIT_GLYPH(umbrella),
INIT_GLYPH(ur_angle),
INIT_GLYPH(watch),
INIT_GLYPH(xterm)
};
int
getbit (char *bits, int width, int x, int y)
{
int offs = (width+7) / 8;
return (bits[y * offs + (x / 8)] & (1 << (x % 8))) ? 1 : 0;
}
void
putbit (char *bits, int width, int x, int y)
{
int offs = (width+7) / 8;
bits[y * offs + (x / 8)] |= (0x80 >> (x % 8));
}
main()
{
int i, x, y;
FntFileHdr fhdr;
char *bitmap;
struct cursor_glyph *gp;
FILE *outfile;
fhdr.magic = FONT_MAGIC;
fhdr.bitmapsize = XC_num_glyphs * 32 * (32 / 8);
fhdr.h.fnt_isfixed = 1;
fhdr.h.fnt_width = 32;
fhdr.h.fnt_height = 32;
fhdr.h.fnt_minchar = XC_X_cursor;
fhdr.h.fnt_maxchar = XC_num_glyphs - 1;
fhdr.h.fnt_internal = 0;
fhdr.h.fnt_baseline = 16;
fhdr.h.fnt_undwidth = 16;
strcpy (fhdr.h.fnt_name, "cursor");
strcpy (fhdr.h.fnt_family, "X_misc");
bitmap = (char *) calloc (1, fhdr.bitmapsize);
for (i = 0; i < XC_num_glyphs; i++) {
gp = &glyphs[i];
for (y = 0; y < gp->height; y++) {
for (x = 0; x < gp->width; x++) {
if (getbit (gp->bits, gp->width, x, y)) {
putbit (bitmap + i * (32 * (32 / 8)), 32, 16 + (x - gp->x_hot), 16 + (y - gp->y_hot));
}
}
}
}
outfile = fopen ("cursor.fnt", "wb");
if (! outfile) {
fprintf (stderr, "cannot open \"cursor.fnt\" for writing\n");
exit (1);
}
fwrite (&fhdr, sizeof(fhdr), 1, outfile);
fwrite (bitmap, fhdr.bitmapsize, 1, outfile);
fclose (outfile);
exit (0);
}