home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / x / volume21 / xfig / patch02n / xfig.09
Encoding:
Text File  |  1993-10-21  |  27.8 KB  |  1,001 lines

  1.   /********************* EXPORTS *******************/
  2.   
  3.   int        put_msg();
  4. ***************
  5. *** 73,88 ****
  6.   
  7.   setup_msg()
  8.   {
  9. !     Dimension ht;
  10.   
  11. !     /* set the height of the message panel to the height of the file name panel */
  12.       XtUnmanageChild(msg_panel);
  13. !     FirstArg(XtNheight, &ht);
  14.       GetValues(name_panel);
  15. !     FirstArg(XtNheight, ht);
  16.       SetValues(msg_panel);
  17.       /* set the MSGFORM_HT variable so the mouse panel can be resized to fit */
  18. !     MSGFORM_HT = ht;
  19.       XtManageChild(msg_panel);
  20.       if (msg_win == 0)
  21.       msg_win = XtWindow(msg_panel);
  22. --- 77,97 ----
  23.   
  24.   setup_msg()
  25.   {
  26. !     Dimension htm,htf;
  27.   
  28. !     /* set the height of the message panel and filename panel to the 
  29. !        greater of the two heights */
  30.       XtUnmanageChild(msg_panel);
  31. !     FirstArg(XtNheight, &htm);
  32.       GetValues(name_panel);
  33. !     FirstArg(XtNheight, &htf);
  34. !     GetValues(msg_panel);
  35. !     htf = max2(htf,htm);
  36. !     FirstArg(XtNheight, htf);
  37.       SetValues(msg_panel);
  38. +     SetValues(name_panel);
  39.       /* set the MSGFORM_HT variable so the mouse panel can be resized to fit */
  40. !     MSGFORM_HT = htf;
  41.       XtManageChild(msg_panel);
  42.       if (msg_win == 0)
  43.       msg_win = XtWindow(msg_panel);
  44. ***************
  45. *** 95,100 ****
  46. --- 104,110 ----
  47.    * space, by getting the width of the command panel and subtract the new 
  48.    * width of the name_panel to get the new width of the message panel
  49.    */
  50.   update_cur_filename(newname)
  51.       char    *newname;
  52.   {
  53. ***************
  54. *** 112,120 ****
  55. --- 122,135 ----
  56.       FirstArg(XtNwidth, &namwid);
  57.       GetValues(name_panel);
  58.       MSGPANEL_WD = MSGFORM_WD-namwid;
  59. +     if (MSGPANEL_WD <= 0)
  60. +         MSGPANEL_WD = 100;
  61.       /* resize the message panel to fit with the new width of the name panel */
  62.       FirstArg(XtNwidth, MSGPANEL_WD);
  63.       SetValues(msg_panel);
  64. +     /* keep the height the same */
  65. +     FirstArg(XtNheight, MSGFORM_HT);
  66. +     SetValues(name_panel);
  67.       XtManageChild(msg_panel);
  68.       XtManageChild(name_panel);
  69.   
  70. ***************
  71. *** 122,127 ****
  72. --- 137,144 ----
  73.       FirstArg(XtNwidth, MSGFORM_WD);
  74.       SetValues(msg_form);
  75.       XtManageChild(msg_form);
  76. +     /* put the filename being edited in the icon */
  77. +     XSetIconName(tool_d, XtWindow(tool), basename(cur_filename));
  78.   }
  79.   
  80.   /* VARARGS1 */
  81. diff -rc xfig.2.1.7a/w_print.c xfig.2.1.8/w_print.c
  82. *** xfig.2.1.7a/w_print.c    Tue Mar 23 10:21:42 1993
  83. --- xfig.2.1.8/w_print.c    Tue Aug 31 14:20:47 1993
  84. ***************
  85. *** 96,103 ****
  86.          var and put it into the widget */
  87.       if (emptyname(printer_val)) {
  88.           printer_val=getenv("PRINTER");
  89. !         FirstArg(XtNstring, printer_val);
  90. !         SetValues(printer_text);
  91.       }
  92.       FirstArg(XtNstring, ¶m_val);
  93.       GetValues(param_text);
  94. --- 96,107 ----
  95.          var and put it into the widget */
  96.       if (emptyname(printer_val)) {
  97.           printer_val=getenv("PRINTER");
  98. !         if (printer_val == NULL) {
  99. !             printer_val = "";
  100. !         } else {
  101. !             FirstArg(XtNstring, printer_val);
  102. !             SetValues(printer_text);
  103. !         }
  104.       }
  105.       FirstArg(XtNstring, ¶m_val);
  106.       GetValues(param_text);
  107. ***************
  108. *** 122,128 ****
  109.       char       *pr_params;
  110.   {
  111.       if (emptyname(printer)) {    /* send to default printer */
  112. ! #if defined(SYSV) || defined(SVR4)
  113.       sprintf(cmd, "lp %s -oPS %s", 
  114.           pr_params,
  115.           shell_protect_string(file));
  116. --- 126,132 ----
  117.       char       *pr_params;
  118.   {
  119.       if (emptyname(printer)) {    /* send to default printer */
  120. ! #if (defined(SYSV) || defined(SVR4)) && !defined(BSDLPR)
  121.       sprintf(cmd, "lp %s -oPS %s", 
  122.           pr_params,
  123.           shell_protect_string(file));
  124. ***************
  125. *** 135,141 ****
  126.       put_msg("Printing figure on default printer in %s mode ...     ",
  127.           print_landscape ? "LANDSCAPE" : "PORTRAIT");
  128.       } else {
  129. ! #if defined(SYSV) || defined(SVR4)
  130.       sprintf(cmd, "lp %s, -d%s -oPS %s",
  131.           pr_params,
  132.           printer, 
  133. --- 139,145 ----
  134.       put_msg("Printing figure on default printer in %s mode ...     ",
  135.           print_landscape ? "LANDSCAPE" : "PORTRAIT");
  136.       } else {
  137. ! #if (defined(SYSV) || defined(SVR4)) && !defined(BSDLPR)
  138.       sprintf(cmd, "lp %s, -d%s -oPS %s",
  139.           pr_params,
  140.           printer, 
  141. ***************
  142. *** 160,166 ****
  143.   do_print_batch(w)
  144.       Widget        w;
  145.   {
  146. -     DeclareArgs(1);
  147.       float        mag;
  148.       FILE       *infp,*outfp;
  149.       char        tmp_exp_file[32];
  150. --- 164,169 ----
  151. ***************
  152. *** 215,222 ****
  153.   do_clear_batch(w)
  154.       Widget        w;
  155.   {
  156. -     DeclareArgs(1);
  157. -   
  158.       unlink(batch_file);
  159.       batch_exists = False;
  160.       num_batch_figures = 0;
  161. --- 218,223 ----
  162. ***************
  163. *** 228,234 ****
  164.   
  165.   update_batch_count()
  166.   {
  167. !     String        num[4];
  168.       DeclareArgs(1);
  169.   
  170.       sprintf(num,"%3d",num_batch_figures);
  171. --- 229,235 ----
  172.   
  173.   update_batch_count()
  174.   {
  175. !     char        num[4];
  176.       DeclareArgs(1);
  177.   
  178.       sprintf(num,"%3d",num_batch_figures);
  179. ***************
  180. *** 272,280 ****
  181.   popup_print_panel(w)
  182.       Widget        w;
  183.   {
  184. -     Widget        image;
  185. -     Pixmap        p;
  186. -     DeclareArgs(10);
  187.       extern        Atom wm_delete_window;
  188.   
  189.       set_temp_cursor(wait_cursor);
  190. --- 273,278 ----
  191. ***************
  192. *** 294,299 ****
  193. --- 292,298 ----
  194.       Widget        image;
  195.       Pixmap        p;
  196.       DeclareArgs(10);
  197. +     unsigned long fg, bg;
  198.   
  199.       print_w = w;
  200.       XtTranslateCoords(w, (Position) 0, (Position) 0, &xposn, &yposn);
  201. ***************
  202. *** 311,323 ****
  203.       print_panel = XtCreateManagedWidget("print_panel", formWidgetClass,
  204.                           print_popup, NULL, ZERO);
  205.   
  206. -     p = XCreateBitmapFromData(tool_d, XtWindow(canvas_sw),
  207. -               (char *) printer_ic.data, printer_ic.width, printer_ic.height);
  208.       FirstArg(XtNlabel, "   ");
  209.       NextArg(XtNwidth, printer_ic.width);
  210.       NextArg(XtNheight, printer_ic.height);
  211. -     NextArg(XtNbitmap, p);
  212.       NextArg(XtNborderWidth, 0);
  213.       NextArg(XtNinternalWidth, 0);
  214.       NextArg(XtNinternalHeight, 0);
  215. --- 310,318 ----
  216. ***************
  217. *** 325,330 ****
  218. --- 320,333 ----
  219.       NextArg(XtNresizable, False);
  220.       image = XtCreateManagedWidget("printer_image", labelWidgetClass,
  221.                         print_panel, Args, ArgCount);
  222. +     FirstArg(XtNforeground, &fg);
  223. +     NextArg(XtNbackground, &bg);
  224. +     GetValues(image);
  225. +     p = XCreatePixmapFromBitmapData(tool_d, XtWindow(canvas_sw),
  226. +               (char *) printer_ic.data, printer_ic.width, printer_ic.height,
  227. +               fg, bg, DefaultDepthOfScreen(tool_s));
  228. +     FirstArg(XtNbitmap, p);
  229. +     SetValues(image);
  230.   
  231.       FirstArg(XtNlabel, "  Magnification%:");
  232.       NextArg(XtNfromVert, image);
  233. diff -rc xfig.2.1.7a/w_rottext.c xfig.2.1.8/w_rottext.c
  234. *** xfig.2.1.7a/w_rottext.c    Wed Feb 10 10:25:21 1993
  235. --- xfig.2.1.8/w_rottext.c    Mon Sep 13 14:25:40 1993
  236. ***************
  237. *** 1,56 ****
  238. ! /*
  239. !  * FIG : Facility for Interactive Generation of figures
  240. !  * Copyright (c) 1992 by Alan Richardson
  241.    *
  242. !  * "Permission to use, copy, modify, distribute, and sell this software and its
  243. !  * documentation for any purpose is hereby granted without fee, provided that
  244. !  * the above copyright notice appear in all copies and that both the copyright
  245. !  * notice and this permission notice appear in supporting documentation. 
  246. !  * No representations are made about the suitability of this software for 
  247. !  * any purpose.  It is provided "as is" without express or implied warranty."
  248.    */
  249.   
  250.   #include "fig.h"
  251.   #include "w_rottext.h"
  252.   
  253.   /* ---------------------------------------------------------------------- */
  254.   
  255. - #define XROTMAX(a, b) ((a)>(b)?(a):(b))
  256.   
  257.   /* ---------------------------------------------------------------------- */
  258.   
  259. - char            *my_strdup();
  260. - char            *my_strtok();
  261. - XRotFontStruct         *XRotLoadFont();
  262. - void              XRotUnloadFont();
  263. - int               XRotTextWidth();
  264. - int               XRotTextHeight();
  265. - void             XRotDrawString();
  266. - void               XRotDrawImageString();
  267. - void                     XRotPaintString();
  268. - void               XRotDrawAlignedString();
  269. - void                     XRotDrawAlignedImageString();
  270. - void                     XRotPaintAlignedString();
  271.   
  272.   /* ---------------------------------------------------------------------- */
  273. -   
  274. - /* *** Routine to mimic `strdup()' (some machines don't have it) *** */
  275.   
  276. - char *my_strdup(str)
  277. -  char *str;
  278. - {
  279. -  char *s;
  280.   
  281. !  if(str==NULL) return (char *)NULL;
  282.   
  283. !  s=(char *)malloc((unsigned)(strlen(str)+1));
  284. !  if(!s)
  285. !   { fprintf(stderr, "Error: my_strdup(): Couldn't do malloc\n");
  286. !     exit(1); }
  287.   
  288. !  strcpy(s, str);
  289.   
  290. !  return s;
  291.   }
  292.   
  293.   
  294. --- 1,162 ----
  295. ! /* ********************************************************************** */
  296. ! /* xvertext 5.0, Copyright (c) 1993 Alan Richardson (mppa3@uk.ac.sussex.syma)
  297.    *
  298. !  * Permission to use, copy, modify, and distribute this software and its
  299. !  * documentation for any purpose and without fee is hereby granted, provided
  300. !  * that the above copyright notice appear in all copies and that both the
  301. !  * copyright notice and this permission notice appear in supporting
  302. !  * documentation.  All work developed as a consequence of the use of
  303. !  * this program should duly acknowledge such use. No representations are
  304. !  * made about the suitability of this software for any purpose.  It is
  305. !  * provided "as is" without express or implied warranty.
  306.    */
  307.   
  308. + /* ********************************************************************** */
  309. + /* BETTER: xvertext now does rotation at any angle!!
  310. +  *
  311. +  * BEWARE: function arguments have CHANGED since version 2.0!!
  312. +  */
  313. + /* ********************************************************************** */
  314.   #include "fig.h"
  315. + #include "resources.h"
  316. + #include <X11/Xatom.h>
  317.   #include "w_rottext.h"
  318.   
  319.   /* ---------------------------------------------------------------------- */
  320.   
  321.   
  322. + /* Make sure cache size is set */
  323. + #ifndef CACHE_SIZE_LIMIT
  324. + #define CACHE_SIZE_LIMIT 0
  325. + #endif /*CACHE_SIZE_LIMIT */
  326. +     
  327. + /* Cache by FID if can't find name because OpenWindows screws up */
  328. + #define CACHE_FID
  329. + /* Make sure a cache method is specified */
  330. + #ifndef CACHE_XIMAGES
  331. + #ifndef CACHE_BITMAPS
  332. + #define CACHE_BITMAPS
  333. + #endif /*CACHE_BITMAPS*/
  334. + #endif /*CACHE_XIMAGES*/
  335.   /* ---------------------------------------------------------------------- */
  336.   
  337.   
  338. + /* Debugging macros */
  339. + #define DEBUG_PRINT1(a) if (appres.DEBUG) printf (a)
  340. + #define DEBUG_PRINT2(a, b) if (appres.DEBUG) printf (a, b)
  341. + #define DEBUG_PRINT3(a, b, c) if (appres.DEBUG) printf (a, b, c)
  342. + #define DEBUG_PRINT4(a, b, c, d) if (appres.DEBUG) printf (a, b, c, d)
  343. + #define DEBUG_PRINT5(a, b, c, d, e) if (appres.DEBUG) printf (a, b, c, d, e)
  344.   /* ---------------------------------------------------------------------- */
  345.   
  346.   
  347. ! /* A structure holding everything needed for a rotated string */
  348.   
  349. ! typedef struct rotated_text_item_template {
  350. !     Pixmap bitmap;
  351. !     XImage *ximage;
  352. !     
  353. !     char *text;
  354. !     char *font_name;
  355. !     Font fid;
  356. !     float angle;
  357. !     int align;
  358. !     float magnify;
  359. !     
  360. !     int cols_in;
  361. !     int rows_in;
  362. !     int cols_out;
  363. !     int rows_out;
  364. !     
  365. !     int nl;
  366. !     int max_width;
  367. !     float *corners_x;
  368. !     float *corners_y;
  369. !     
  370. !     long int size;
  371. !     int cached;
  372.   
  373. !     struct rotated_text_item_template *next;
  374. ! } RotatedTextItem;
  375.   
  376. ! RotatedTextItem *first_text_item=NULL;
  377. ! /* ---------------------------------------------------------------------- */
  378. ! /* A structure holding current magnification and bounding box padding */
  379. ! static struct style_template {
  380. !     float magnify;
  381. !     int bbx_pad;
  382. ! } style={
  383. !     1.,
  384. !     0
  385. !     };
  386. ! /* ---------------------------------------------------------------------- */
  387. ! static char            *my_strdup();
  388. ! static char            *my_strtok();
  389. ! float                   XRotVersion();
  390. ! void                    XRotSetMagnification();
  391. ! void                    XRotSetBoundingBoxPad();
  392. ! int                     XRotDrawString();
  393. ! int                     XRotDrawImageString();
  394. ! int                     XRotDrawAlignedString();
  395. ! int                     XRotDrawAlignedImageString();
  396. ! XPoint                 *XRotTextExtents();
  397. ! static XImage          *MakeXImage();
  398. ! static int              XRotPaintAlignedString();
  399. ! static int              XRotDrawHorizontalString();
  400. ! static RotatedTextItem *XRotRetrieveFromCache();
  401. ! static RotatedTextItem *XRotCreateTextItem();
  402. ! static void             XRotAddToLinkedList();
  403. ! static void             XRotFreeTextItem();
  404. ! static XImage          *XRotMagnifyImage();
  405. ! /* ---------------------------------------------------------------------- */
  406. ! /**************************************************************************/
  407. ! /* Routine to mimic `strdup()' (some machines don't have it)              */
  408. ! /**************************************************************************/
  409. ! static char *my_strdup(str)
  410. !     char *str;
  411. ! {
  412. !     char *s;
  413. !     
  414. !     if(str==NULL)
  415. !     return NULL;
  416. !     
  417. !     s=(char *)malloc((unsigned)(strlen(str)+1));
  418. !     if(s!=NULL) 
  419. !     strcpy(s, str);
  420. !     
  421. !     return s;
  422.   }
  423.   
  424.   
  425. ***************
  426. *** 57,331 ****
  427.   /* ---------------------------------------------------------------------- */
  428.   
  429.   
  430. ! /* *** Routine to replace `strtok' : this one returns a zero
  431. !        length string if it encounters two consecutive delimiters *** */
  432.   
  433. ! char *my_strtok(str1, str2)
  434. !  char *str1, *str2;
  435.   {
  436. !  char *ret;
  437. !  int i, j, stop;
  438. !  static int start, len;
  439. !  static char *stext;
  440.   
  441. -  if(str2==NULL)
  442. -   { fprintf(stderr, "Error: my_strtok(): null delimiter string\n");
  443. -     exit(1);
  444. -   }
  445.   
  446. !  /* initialise if str1 not NULL ... */
  447. !  if(str1!=NULL)
  448. !   { start=0;
  449. !     stext=str1;
  450. !     len=strlen(str1);
  451. !   }
  452.   
  453. -  /* run out of tokens ? ... */
  454. -  if(start>=len) return (char *)NULL;
  455.   
  456. !  /* loop through characters ... */
  457. !  for(i=start; i<len; i++)
  458. !  {
  459. !   /* loop through delimiters ... */
  460. !   stop=0;
  461. !   for(j=0; j<strlen(str2); j++) if(stext[i]==str2[j]) stop=1;
  462.   
  463. !   if(stop) break;
  464. !  }
  465.   
  466. -  stext[i]='\0';
  467.   
  468. !  ret=stext+start;
  469.   
  470. -  start=i+1;
  471.   
  472. !  return ret;
  473.   }
  474.   
  475.   
  476.   /* ---------------------------------------------------------------------- */
  477. -   
  478.   
  479. ! /* *** Load the rotated version of a given font *** */
  480. !  
  481. ! XRotFontStruct *XRotLoadFont(dpy, fontname, angle)
  482. !  Display *dpy;
  483. !  char *fontname;
  484. !  float angle;
  485.   {
  486. !  char         val;
  487. !  XImage        *I1, *I2;
  488. !  Pixmap         canvas;
  489. !  Window         root;
  490. !  int         screen;
  491. !  GC         font_gc;
  492. !  char         text[3];
  493. !  XFontStruct    *fontstruct;
  494. !  XRotFontStruct    *rotfont;
  495. !  int         ichar, i, j, index, boxlen, dir;
  496. !  int         vert_w, vert_h, vert_len, bit_w, bit_h, bit_len;
  497. !  int         min_char, max_char;
  498. !  unsigned char    *vertdata, *bitdata;
  499. !  int         ascent, descent, lbearing, rbearing;
  500. !  int         on=1, off=0;
  501.   
  502. -  dir=(int)(angle/90.0+0.01);
  503. -  if (dir > 3)
  504. -     dir -= 4;
  505.   
  506. !  /* useful macros ... */
  507. !  screen=DefaultScreen(dpy);
  508. !  root=DefaultRootWindow(dpy);
  509.   
  510. -  /* load the font ... */
  511. -  fontstruct=XLoadQueryFont(dpy, fontname);
  512. -  if(!fontstruct) { 
  513. -     fprintf(stderr,
  514. -             "Error: XRotLoadFont(): XServer couldn't load the font `%s'\n",
  515. -             fontname);
  516. -     exit(1); 
  517. -  }
  518. -  
  519. -  /* boxlen is the square size that would enclose the largest character */
  520. -  boxlen = max2(fontstruct->max_bounds.rbearing - fontstruct->max_bounds.lbearing, 
  521. -           fontstruct->max_bounds.ascent + fontstruct->max_bounds.descent);
  522. -  boxlen *= 2;
  523.   
  524. !  /* create the depth 1 canvas bitmap ... */
  525. !  canvas=XCreatePixmap(dpy, root, boxlen, boxlen, 1);
  526. !  
  527. !  /* create a GC ... */
  528. !  font_gc=XCreateGC(dpy, canvas, NULL, 0);
  529. !  XSetBackground(dpy, font_gc, off);
  530.   
  531. !  XSetFont(dpy, font_gc, fontstruct->fid);
  532.   
  533. -  /* allocate space for rotated font ... */
  534. -  rotfont=(XRotFontStruct *)malloc((unsigned)sizeof(XRotFontStruct));
  535. -  if(!rotfont) { 
  536. -     fprintf(stderr,"Error: XRotLoadFont(): Couldn't do malloc\n");
  537. -     exit(1); 
  538. -  }
  539. -    
  540. -  /* determine which characters are defined in font ... */
  541. -  min_char=fontstruct->min_char_or_byte2; 
  542. -  max_char=fontstruct->max_char_or_byte2;
  543. -  
  544. -  /* we only want printing characters ... */
  545. -  if(min_char<32)  min_char=32;
  546. -  if(max_char>126) max_char=126;
  547. -      
  548. -  /* some overall font data ... */
  549. -  rotfont->name=my_strdup(fontname);
  550. -  rotfont->dir=dir;
  551. -  rotfont->min_char=min_char;
  552. -  rotfont->max_char=max_char;
  553. -  rotfont->max_ascent=fontstruct->max_bounds.ascent;
  554. -  rotfont->max_descent=fontstruct->max_bounds.descent;   
  555. -  rotfont->height=rotfont->max_ascent+rotfont->max_descent;
  556. -  rotfont->width=fontstruct->max_bounds.width;
  557.   
  558. !  /* remember xfontstruct for `normal' text ... */
  559. !  if(dir==0) 
  560. !     rotfont->xfontstruct=fontstruct;
  561.   
  562. -  /* loop through each character ... */
  563. -  for(ichar=min_char; ichar<=max_char; ichar++) {
  564.   
  565. !      index=ichar-fontstruct->min_char_or_byte2;
  566. !      /* per char dimensions ... */
  567. !      ascent=  rotfont->per_char[ichar-32].ascent=
  568. !                       fontstruct->per_char[index].ascent;
  569. !      descent= rotfont->per_char[ichar-32].descent=
  570. !                       fontstruct->per_char[index].descent;
  571. !      lbearing=rotfont->per_char[ichar-32].lbearing=
  572. !                       fontstruct->per_char[index].lbearing;
  573. !      rbearing=rotfont->per_char[ichar-32].rbearing=
  574. !                       fontstruct->per_char[index].rbearing;
  575. !               rotfont->per_char[ichar-32].width=
  576. !                       fontstruct->per_char[index].width;
  577.   
  578. !      /* no need for the following with normal text */
  579. !      if (dir == 0)
  580. !     continue;
  581.   
  582. -      /* some space chars have zero body, but a bitmap can't have ... */
  583. -      if(!ascent && !descent)   
  584. -             ascent=  rotfont->per_char[ichar-32].ascent=  1;
  585. -      if(!lbearing && !rbearing) 
  586. -             rbearing=rotfont->per_char[ichar-32].rbearing=1;
  587.   
  588. !      /* glyph width and height when vertical ... */
  589. !      vert_w=rbearing-lbearing;
  590. !      vert_h=ascent+descent;
  591.   
  592. -      /* width in bytes ... */
  593. -      vert_len=(vert_w-1)/8+1;   
  594. -  
  595. -      XSetForeground(dpy, font_gc, off);
  596. -      XFillRectangle(dpy, canvas, font_gc, 0, 0, boxlen, boxlen);
  597.   
  598. !      /* draw the character centre top right on canvas ... */
  599. !      sprintf(text, "%c", ichar);
  600. !      XSetForeground(dpy, font_gc, on);
  601. !      XDrawImageString(dpy, canvas, font_gc, boxlen/2-lbearing,
  602. !                       boxlen/2-descent, text, 1);
  603.   
  604. !      /* reserve memory for first XImage ... */
  605. !      vertdata=(unsigned char *) malloc((unsigned)(vert_len*vert_h));
  606. !      if(!vertdata) { 
  607. !     fprintf(stderr,"Error: XRotLoadFont(): Couldn't do malloc\n");
  608. !         exit(1); 
  609. !       }
  610. !   
  611. !      /* create the XImage ... */
  612. !      I1=XCreateImage(dpy, DefaultVisual(dpy, screen), 1, XYBitmap,
  613. !                      0, (char *) vertdata, vert_w, vert_h, 8, 0);
  614.   
  615. -      if(!I1) { 
  616. -     fprintf(stderr,"Error: XRotLoadFont(): Couldn't create XImage\n");
  617. -         exit(1); 
  618. -      }
  619. -   
  620. -      I1->byte_order=I1->bitmap_bit_order=MSBFirst;
  621.   
  622. !      /* extract character from canvas ... */
  623. !      XGetSubImage(dpy, canvas, boxlen/2, boxlen/2-vert_h,
  624. !                   vert_w, vert_h, 1, XYPixmap, I1, 0, 0);
  625. !      I1->format=XYBitmap; 
  626. !  
  627. !      /* width, height of rotated character ... */
  628. !      if(dir==2) { 
  629. !     bit_w=vert_w; bit_h=vert_h; 
  630. !      } else { 
  631. !     bit_w=vert_h; bit_h=vert_w; 
  632. !      }
  633.   
  634. -      /* width in bytes ... */
  635. -      bit_len=(bit_w-1)/8+1;
  636. -    
  637. -      rotfont->per_char[ichar-32].glyph.bit_w=bit_w;
  638. -      rotfont->per_char[ichar-32].glyph.bit_h=bit_h;
  639.   
  640. !      /* reserve memory for the rotated image ... */
  641. !      bitdata=(unsigned char *)calloc((unsigned)(bit_h*bit_len), 1);
  642. !      if(!bitdata) { 
  643. !     fprintf(stderr,"Error: XRotLoadFont(): Couldn't do calloc\n");
  644. !         exit(1); 
  645. !      }
  646.   
  647. !      /* create the image ... */
  648. !      I2=XCreateImage(dpy, DefaultVisual(dpy, screen), 1, XYBitmap, 0,
  649. !                      (char *) bitdata, bit_w, bit_h, 8, 0); 
  650. !  
  651. !      if(!I2) { 
  652. !     fprintf(stderr,"Error: XRotLoadFont(): Couldn't create XImage\n");
  653. !         exit(1);
  654. !      }
  655.   
  656. -      I2->byte_order=I2->bitmap_bit_order=MSBFirst;
  657.   
  658. !      /* map vertical data to rotated character ... */
  659. !      for(j=0; j<bit_h; j++) {
  660. !       for(i=0; i<bit_w; i++) {
  661. !        /* map bits ... */
  662. !        if(dir==1)
  663. !          val=vertdata[i*vert_len + (vert_w-j-1)/8] & (128>>((vert_w-j-1)%8));
  664. !    
  665. !        else if(dir==2)
  666. !          val=vertdata[(vert_h-j-1)*vert_len + (vert_w-i-1)/8] &
  667. !                                                        (128>>((vert_w-i-1)%8));
  668. !        else 
  669. !          val=vertdata[(vert_h-i-1)*vert_len + j/8] & (128>>(j%8));
  670. !         
  671. !        if(val) bitdata[j*bit_len + i/8] = 
  672. !                    bitdata[j*bit_len + i/8]|(128>>(i%8));
  673. !       }
  674. !      }
  675. !    
  676. !      /* create this character's bitmap ... */
  677. !      rotfont->per_char[ichar-32].glyph.bm=
  678. !        XCreatePixmap(dpy, root, bit_w, bit_h, 1);
  679. !      
  680. !      /* put the image into the bitmap ... */
  681. !      XPutImage(dpy, rotfont->per_char[ichar-32].glyph.bm, 
  682. !                font_gc, I2, 0, 0, 0, 0, bit_w, bit_h);
  683. !   
  684. !      /* free the image and data ... */
  685. !      XDestroyImage(I1);
  686. !      XDestroyImage(I2);
  687. !      free((char *)bitdata);
  688. !      free((char *)vertdata);
  689. !  }
  690.   
  691. -  if (dir != 0)
  692. -     XFreeFont(dpy, fontstruct);
  693.   
  694. !  /* free pixmap and GC ... */
  695. !  XFreePixmap(dpy, canvas);
  696. !  XFreeGC(dpy, font_gc);
  697.   
  698. !  return rotfont;
  699.   }
  700.   
  701.   
  702. --- 163,382 ----
  703.   /* ---------------------------------------------------------------------- */
  704.   
  705.   
  706. ! /**************************************************************************/
  707. ! /* Routine to replace `strtok' : this one returns a zero length string if */
  708. ! /* it encounters two consecutive delimiters                               */
  709. ! /**************************************************************************/
  710.   
  711. ! static char *my_strtok(str1, str2)
  712. !     char *str1, *str2;
  713.   {
  714. !     char *ret;
  715. !     int i, j, stop;
  716. !     static int start, len;
  717. !     static char *stext;
  718. !     
  719. !     if(str2==NULL)
  720. !     return NULL;
  721. !     
  722. !     /* initialise if str1 not NULL */
  723. !     if(str1!=NULL) {
  724. !     start=0;
  725. !     stext=str1;
  726. !     len=strlen(str1);
  727. !     }
  728. !     
  729. !     /* run out of tokens ? */
  730. !     if(start>=len)
  731. !     return NULL;
  732. !     
  733. !     /* loop through characters */
  734. !     for(i=start; i<len; i++) {
  735. !     /* loop through delimiters */
  736. !     stop=0;
  737. !     for(j=0; j<strlen(str2); j++)
  738. !         if(stext[i]==str2[j])
  739. !         stop=1;
  740. !     
  741. !     if(stop)
  742. !         break;
  743. !     }
  744. !     
  745. !     stext[i]='\0';
  746. !     
  747. !     ret=stext+start;
  748. !     
  749. !     start=i+1;
  750. !     
  751. !     return ret;
  752. ! }
  753.   
  754.   
  755. ! /* ---------------------------------------------------------------------- */
  756.   
  757.   
  758. ! /**************************************************************************/
  759. ! /* Return version/copyright information                                   */
  760. ! /**************************************************************************/
  761.   
  762. ! float XRotVersion(str, n)
  763. !     char *str;
  764. !     int n;
  765. ! {
  766. !     if(str!=NULL)
  767. !     strncpy(str, XV_COPYRIGHT, n);
  768. !     return XV_VERSION;
  769. ! }
  770.   
  771.   
  772. ! /* ---------------------------------------------------------------------- */
  773.   
  774.   
  775. ! /**************************************************************************/
  776. ! /* Set the font magnification factor for all subsequent operations        */
  777. ! /**************************************************************************/
  778. ! void XRotSetMagnification(m)
  779. !     float m;
  780. ! {
  781. !     if(m>0.)
  782. !     style.magnify=m;
  783.   }
  784.   
  785.   
  786.   /* ---------------------------------------------------------------------- */
  787.   
  788. ! /**************************************************************************/
  789. ! /* Set the padding used when calculating bounding boxes                   */
  790. ! /**************************************************************************/
  791. ! void XRotSetBoundingBoxPad(p)
  792. !     int p;
  793.   {
  794. !     if(p>=0)
  795. !     style.bbx_pad=p;
  796. ! }
  797.   
  798.   
  799. ! /* ---------------------------------------------------------------------- */
  800.   
  801.   
  802. ! /**************************************************************************/
  803. ! /*  Create an XImage structure and allocate memory for it                 */
  804. ! /**************************************************************************/
  805.   
  806. ! static XImage *MakeXImage(dpy, w, h)
  807. !     Display *dpy;
  808. !     int w, h;
  809. ! {
  810. !     XImage *I;
  811. !     char *data;
  812. !     
  813. !     /* reserve memory for image */
  814. !     data=(char *)calloc((unsigned)(((w-1)/8+1)*h), 1);
  815. !     if(data==NULL)
  816. !     return NULL;
  817. !     
  818. !     /* create the XImage */
  819. !     I=XCreateImage(dpy, DefaultVisual(dpy, DefaultScreen(dpy)), 1, XYBitmap,
  820. !                    0, data, w, h, 8, 0);
  821. !     if(I==NULL)
  822. !     return NULL;
  823. !     
  824. !     I->byte_order=I->bitmap_bit_order=MSBFirst;
  825. !     return I;
  826. ! }
  827.   
  828.   
  829. ! /* ---------------------------------------------------------------------- */
  830.   
  831.   
  832. ! /**************************************************************************/
  833. ! /*  A front end to XRotPaintAlignedString:                                */
  834. ! /*      -no alignment, no background                                      */
  835. ! /**************************************************************************/
  836.   
  837. ! int XRotDrawString(dpy, font, angle, drawable, gc, x, y, str)
  838. !     Display *dpy;
  839. !     XFontStruct *font;
  840. !     float angle;
  841. !     Drawable drawable;
  842. !     GC gc;
  843. !     int x, y;
  844. !     char *str;
  845. ! {
  846. !     return (XRotPaintAlignedString(dpy, font, angle, drawable, gc,
  847. !                    x, y, str, NONE, 0));
  848. ! }
  849.   
  850.   
  851. ! /* ---------------------------------------------------------------------- */
  852.   
  853.   
  854. ! /**************************************************************************/
  855. ! /*  A front end to XRotPaintAlignedString:                                */
  856. ! /*      -no alignment, paints background                                  */
  857. ! /**************************************************************************/
  858.   
  859. ! int XRotDrawImageString(dpy, font, angle, drawable, gc, x, y, str)
  860. !     Display *dpy;
  861. !     XFontStruct *font;
  862. !     float angle;
  863. !     Drawable drawable;
  864. !     GC gc;
  865. !     int x, y;
  866. !     char *str;
  867. ! {
  868. !     return(XRotPaintAlignedString(dpy, font, angle, drawable, gc,
  869. !                   x, y, str, NONE, 1));
  870. ! }
  871.   
  872.   
  873. ! /* ---------------------------------------------------------------------- */
  874.   
  875.   
  876. ! /**************************************************************************/
  877. ! /*  A front end to XRotPaintAlignedString:                                */
  878. ! /*      -does alignment, no background                                    */
  879. ! /**************************************************************************/
  880.   
  881. ! int XRotDrawAlignedString(dpy, font, angle, drawable, gc, x, y, text, align)
  882. !     Display *dpy;
  883. !     XFontStruct *font;
  884. !     float angle;
  885. !     Drawable drawable;
  886. !     GC gc;
  887. !     int x, y;
  888. !     char *text;
  889. !     int align;
  890. ! {
  891. !     return(XRotPaintAlignedString(dpy, font, angle, drawable, gc,
  892. !                   x, y, text, align, 0));
  893. ! }
  894.   
  895.   
  896. ! /* ---------------------------------------------------------------------- */
  897.   
  898.   
  899. ! /**************************************************************************/
  900. ! /*  A front end to XRotPaintAlignedString:                                */
  901. ! /*      -does alignment, paints background                                */
  902. ! /**************************************************************************/
  903.   
  904. ! int XRotDrawAlignedImageString(dpy, font, angle, drawable, gc, x, y, text,
  905. !                    align)
  906. !     Display *dpy;
  907. !     XFontStruct *font;
  908. !     float angle;
  909. !     Drawable drawable;
  910. !     GC gc;
  911. !     int x, y;
  912. !     char *text;
  913. !     int align;
  914. ! {
  915. !     return(XRotPaintAlignedString(dpy, font, angle, drawable, gc,
  916. !                   x, y, text, align, 1));
  917.   }
  918.   
  919.   
  920. ***************
  921. *** 332,608 ****
  922.   /* ---------------------------------------------------------------------- */
  923.   
  924.   
  925. ! /* *** Free the resources associated with a rotated font *** */
  926.   
  927. ! void XRotUnloadFont(dpy, rotfont)
  928. !  Display *dpy;
  929. !  XRotFontStruct *rotfont;
  930.   {
  931. !  int ichar;
  932.   
  933. !  if(rotfont->dir==0) XFreeFont(dpy, rotfont->xfontstruct);
  934.   
  935. !  else
  936. !   /* loop through each character, freeing its pixmap ... */
  937. !   for(ichar=rotfont->min_char-32; ichar<=rotfont->max_char-32; ichar++)
  938. !     XFreePixmap(dpy, rotfont->per_char[ichar].glyph.bm);
  939.   
  940. !  /* rotfont should never be referenced again ... */
  941. !  free((char *)rotfont);
  942.   }
  943.   
  944.   
  945.   /* ---------------------------------------------------------------------- */
  946. -    
  947.   
  948. - /* *** Return the width of a string *** */
  949.   
  950. ! int XRotTextWidth(rotfont, str, len)
  951. !  XRotFontStruct *rotfont;
  952. !  char *str;
  953. !  int len;
  954.   {
  955. !  int i, width=0, ichar;
  956.   
  957. !  if(str==NULL) 
  958.       return 0;
  959.   
  960. !  if(rotfont->dir==0)
  961. !     width=XTextWidth(rotfont->xfontstruct, str, len);
  962.   
  963.