home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / x / volume21 / xfig / patch02n < prev    next >
Encoding:
Text File  |  1993-10-21  |  30.9 KB  |  1,062 lines

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