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 >
C/C++ Source or Header  |  1994-01-11  |  4KB  |  166 lines

  1. /* $Id: cursfnt.c 1.1 1994/01/12 04:35:08 ulrich Exp $ */
  2. /*
  3.  * cursfnt.c
  4.  *
  5.  * Create an GRX font file for X glyph cursors.
  6.  */
  7.  
  8. #include <grx.h>
  9. #include <grxfont.h>
  10. #include <grxfile.h>
  11. #include <stdio.h>
  12.  
  13. #include "cursorfont.h"
  14. #include "cursor.h"
  15.  
  16. #define INIT_GLYPH(name) \
  17. { XC_##name, name##_width, name##_height, name##_x_hot, name##_y_hot, name##_bits }, \
  18. { XC_##name+1, name##_mask_width, name##_mask_height, name##_x_hot, name##_y_hot, name##_mask_bits }
  19.  
  20. struct cursor_glyph {
  21.   int code;
  22.   int width;
  23.   int height;
  24.   int x_hot;
  25.   int y_hot;
  26.   char *bits;
  27. } glyphs[XC_num_glyphs] = {
  28.   INIT_GLYPH(X_cursor),
  29.   INIT_GLYPH(arrow),
  30.   INIT_GLYPH(based_arrow_down),
  31.   INIT_GLYPH(based_arrow_up),
  32.   INIT_GLYPH(boat),
  33.   INIT_GLYPH(bogosity),
  34.   INIT_GLYPH(bottom_left_corner),
  35.   INIT_GLYPH(bottom_right_corner),
  36.   INIT_GLYPH(bottom_side),
  37.   INIT_GLYPH(bottom_tee),
  38.   INIT_GLYPH(box_spiral),
  39.   INIT_GLYPH(center_ptr),
  40.   INIT_GLYPH(circle),
  41.   INIT_GLYPH(clock),
  42.   INIT_GLYPH(coffee_mug),
  43.   INIT_GLYPH(cross),
  44.   INIT_GLYPH(cross_reverse),
  45.   INIT_GLYPH(crosshair),
  46.   INIT_GLYPH(diamond_cross),
  47.   INIT_GLYPH(dot),
  48.   INIT_GLYPH(dotbox),
  49.   INIT_GLYPH(double_arrow),
  50.   INIT_GLYPH(draft_large),
  51.   INIT_GLYPH(draft_small),
  52.   INIT_GLYPH(draped_box),
  53.   INIT_GLYPH(exchange),
  54.   INIT_GLYPH(fleur),
  55.   INIT_GLYPH(gobbler),
  56.   INIT_GLYPH(gumby),
  57.   INIT_GLYPH(hand1),
  58.   INIT_GLYPH(hand2),
  59.   INIT_GLYPH(heart),
  60.   INIT_GLYPH(icon),
  61.   INIT_GLYPH(iron_cross),
  62.   INIT_GLYPH(left_ptr),
  63.   INIT_GLYPH(left_side),
  64.   INIT_GLYPH(left_tee),
  65.   INIT_GLYPH(leftbutton),
  66.   INIT_GLYPH(ll_angle),
  67.   INIT_GLYPH(lr_angle),
  68.   INIT_GLYPH(man),
  69.   INIT_GLYPH(middlebutton),
  70.   INIT_GLYPH(mouse),
  71.   INIT_GLYPH(pencil),
  72.   INIT_GLYPH(pirate),
  73.   INIT_GLYPH(plus),
  74.   INIT_GLYPH(question_arrow),
  75.   INIT_GLYPH(right_ptr),
  76.   INIT_GLYPH(right_side),
  77.   INIT_GLYPH(right_tee),
  78.   INIT_GLYPH(rightbutton),
  79.   INIT_GLYPH(rtl_logo),
  80.   INIT_GLYPH(sailboat),
  81.   INIT_GLYPH(sb_down_arrow),
  82.   INIT_GLYPH(sb_h_double_arrow),
  83.   INIT_GLYPH(sb_left_arrow),
  84.   INIT_GLYPH(sb_right_arrow),
  85.   INIT_GLYPH(sb_up_arrow),
  86.   INIT_GLYPH(sb_v_double_arrow),
  87.   INIT_GLYPH(shuttle),
  88.   INIT_GLYPH(sizing),
  89.   INIT_GLYPH(spider),
  90.   INIT_GLYPH(spraycan),
  91.   INIT_GLYPH(star),
  92.   INIT_GLYPH(target),
  93.   INIT_GLYPH(tcross),
  94.   INIT_GLYPH(top_left_arrow),
  95.   INIT_GLYPH(top_left_corner),
  96.   INIT_GLYPH(top_right_corner),
  97.   INIT_GLYPH(top_side),
  98.   INIT_GLYPH(top_tee),
  99.   INIT_GLYPH(trek),
  100.   INIT_GLYPH(ul_angle),
  101.   INIT_GLYPH(umbrella),
  102.   INIT_GLYPH(ur_angle),
  103.   INIT_GLYPH(watch),
  104.   INIT_GLYPH(xterm)
  105.   };
  106.  
  107. int
  108. getbit (char *bits, int width, int x, int y)
  109. {
  110.   int offs = (width+7) / 8;
  111.  
  112.   return (bits[y * offs + (x / 8)] & (1 << (x % 8))) ? 1 : 0;
  113. }
  114.  
  115. void
  116. putbit (char *bits, int width, int x, int y)
  117. {
  118.   int offs = (width+7) / 8;
  119.  
  120.   bits[y * offs + (x / 8)] |= (0x80 >> (x % 8));
  121. }
  122.  
  123.  
  124. main()
  125. {
  126.   int i, x, y;
  127.   FntFileHdr fhdr;
  128.   char *bitmap;
  129.   struct cursor_glyph *gp;
  130.   FILE *outfile;
  131.  
  132.   fhdr.magic = FONT_MAGIC;
  133.   fhdr.bitmapsize = XC_num_glyphs * 32 * (32 / 8);
  134.   fhdr.h.fnt_isfixed = 1;
  135.   fhdr.h.fnt_width = 32;
  136.   fhdr.h.fnt_height = 32;
  137.   fhdr.h.fnt_minchar = XC_X_cursor;
  138.   fhdr.h.fnt_maxchar = XC_num_glyphs - 1;
  139.   fhdr.h.fnt_internal = 0;
  140.   fhdr.h.fnt_baseline = 16;
  141.   fhdr.h.fnt_undwidth = 16;
  142.   strcpy (fhdr.h.fnt_name, "cursor");
  143.   strcpy (fhdr.h.fnt_family, "X_misc");
  144.  
  145.   bitmap = (char *) calloc (1, fhdr.bitmapsize);
  146.   for (i = 0; i < XC_num_glyphs; i++) {
  147.     gp = &glyphs[i];
  148.     for (y = 0; y < gp->height; y++) {
  149.       for (x = 0; x < gp->width; x++) {
  150.     if (getbit (gp->bits, gp->width, x, y)) {
  151.       putbit (bitmap + i * (32 * (32 / 8)), 32, 16 + (x - gp->x_hot), 16 + (y - gp->y_hot));
  152.     }
  153.       }
  154.     }
  155.   }
  156.   outfile = fopen ("cursor.fnt", "wb");
  157.   if (! outfile) {
  158.     fprintf (stderr, "cannot open \"cursor.fnt\" for writing\n");
  159.     exit (1);
  160.   }
  161.   fwrite (&fhdr, sizeof(fhdr), 1, outfile);
  162.   fwrite (bitmap, fhdr.bitmapsize, 1, outfile);
  163.   fclose (outfile);
  164.   exit (0);
  165. }
  166.