The outage for Sunday 24th November has been cancelled.
Bioplib
Protein Structure C Library
 All Data Structures Files Functions Variables Typedefs Macros Pages
plotting.c
Go to the documentation of this file.
1 /************************************************************************/
2 /**
3 
4  \file plotting.c
5 
6  \version V1.3
7  \date 07.07.14
8  \brief Top level HPGL/PS plotting routines
9 
10  \copyright (c) UCL / Dr. Andrew C. R. Martin 1992-2014
11  \author Dr. Andrew C. R. Martin
12  \par
13  Institute of Structural & Molecular Biology,
14  University College London,
15  Gower Street,
16  London.
17  WC1E 6BT.
18  \par
19  andrew@bioinf.org.uk
20  andrew.martin@ucl.ac.uk
21 
22 **************************************************************************
23 
24  This code is NOT IN THE PUBLIC DOMAIN, but it may be copied
25  according to the conditions laid out in the accompanying file
26  COPYING.DOC.
27 
28  The code may be modified as required, but any modifications must be
29  documented so that the person responsible can be identified.
30 
31  The code may not be sold commercially or included as part of a
32  commercial product except as described in the file COPYING.DOC.
33 
34 **************************************************************************
35 
36  Description:
37  ============
38 
39  These functions provide a common interface to either PostScript or
40  HPGL output.
41 
42  They simplified from a set written for the Amiga which also supports
43  IFF-DR2D and Amiga screen output
44 
45 **************************************************************************
46 
47  Usage:
48  ======
49 
50 **************************************************************************
51 
52  Revision History:
53  =================
54 - V1.0 06.04.92 Original By: ACRM
55 - V1.1 01.03.94 First release
56 - V1.2 27.02.98 Removed unreachable breaks from switch() statement
57 - V1.3 07.07.14 Use bl prefix for functions By: CTP
58 
59 *************************************************************************/
60 /* Doxygen
61  -------
62  #GROUP Graphics
63  #SUBGROUP Plotting
64  #FUNCTION blAMInitPlot()
65  Initialise a device ready for plotting.
66 
67  #FUNCTION blAMSetPen()
68  Change pen
69 
70  #FUNCTION blAMMove()
71  Move to a position specified in data coordinates.
72 
73  #FUNCTION blAMDraw()
74  Draw to a position specified in data coordinates.
75 
76  #FUNCTION blAMSetLineStyle()
77  Set the line style
78 
79  #FUNCTION blAMEndLine()
80  End a line; required by PostScript actually to draw on the paper.
81 
82  #FUNCTION blAMSetFont()
83  Sets the current font using PostScript font names. If producing HPGL
84  output, a lookup table is used to translate this to an HPGL font
85  number
86 
87  #FUNCTION blAMText()
88  Left/bottom justify text at position in data coordinates
89 
90  #FUNCTION blAMCBText()
91  Centre-bottom justify text
92 
93  #FUNCTION blAMRText()
94  Right/centre justify text at position in data coordinates; offset is
95  an x-offset specified in device coordinates (pt)
96 
97  #FUNCTION blAMLCText()
98  Left/centre height justify text at position in data coordinates
99 
100  #FUNCTION blAMCTText()
101  Centre/top justify text at position in data coordinates.
102 
103  #FUNCTION blAMEndPlot()
104  Close up a device after plotting.
105 
106  #FUNCTION blPS2HPGLFont()
107  Takes the PostScript font name and works out the best HPGL equivalent
108  from a translation table. On the first call, the table is read from
109  disk and space is allocated for it. If the routine is called with a
110  NULL parameter, the space allocated for the table is freed. It is
111  quite safe to call the routine again after this has occurred; the
112  table will simply be re-read from disk.
113 
114  #FUNCTION blSimplifyText()
115  Removes control codes from a string for screen display. Also used for
116  calculating string length. The returned string is stored as static
117  within the routine
118 */
119 /************************************************************************/
120 /* Includes
121 */
122 #include <math.h>
123 #include <string.h>
124 #include <stdlib.h>
125 
126 #include "MathType.h"
127 #include "SysDefs.h"
128 #include "general.h"
129 #include "macros.h"
130 #include "plotting.h"
131 
132 /************************************************************************/
133 /* Defines and macros
134 */
135 #define MAXTRANS 10
136 #define TRANS_TABLE "HPGL.ftr"
137 
138 #define MAXPEN 6
139 #define MAXBUFF 160
140 
141 /************************************************************************/
142 /* Globals
143 */
144 static struct
145 {
147  ymin,
148  XPScale,
149  YPScale;
150 } sGraph;
151 
152 /************************************************************************/
153 /* Prototypes
154 */
155 
156 /************************************************************************/
157 /*>BOOL blAMInitPlot(char *filename, char *title, int dest,
158  REAL OutXSize, REAL OutYSize,
159  REAL OutXOff, REAL OutYOff,
160  char *AltFont, REAL xmargin, REAL ymargin,
161  REAL DataXMin, REAL DataYMin,
162  REAL DataXMax, REAL DataYMax)
163  -------------------------------------------------------------
164 *//**
165  \param[in] *filename File to open
166  \param[in] *title Title for plot
167  \param[in] dest Destination (DEST_PS or DEST_HPGL)
168  \param[in] OutXSize Output plot X size (inches)
169  \param[in] OutYSize Output plot Y size (inches)
170  \param[in] OutXOff Output plot X offset (inches)
171  \param[in] OutYOff Output plot Y offset (inches)
172  \param[in] *AltFont Alternate font name
173  \param[in] xmargin Unprintable x margin (inches, HPGL)
174  Sensible default: 0.58
175  \param[in] ymargin Unprintable y margin (inches, HPGL)
176  Sensible default: 0.1465
177  \param[in] DataXMin Min data X value
178  \param[in] DataYMin Min data Y value
179  \param[in] DataXMax Max data X value
180  \param[in] DataYMax Max data Y value
181  \return TRUE: OK, FALSE: Failed
182 
183  Initialise a device ready for plotting.
184 
185 - 07.05.92 Original
186 - 25.06.92 Added HPGL support. Moved setting of PS globals to here.
187 - 02.07.92 Put ClearWindow() in for screen plotting. Added seek to
188  start of file for PS and HPGL file plotting.
189 - 16.07.92 Added DR2D support
190 - 17.07.92 Corrected call to InstallDR2DFonts() *before* InitDR2D().
191  Changed buffer to [40]. Added bounds calc'n for DR2D.
192 - 20.07.92 Added alternate font parameter to DR2DInit(). Added check on
193  DR2DInit() return.
194 - 22.07.92 Consider x-axis labelling in finding max x. Corrected to
195  consider precision for log axes
196 - 24.07.92 Added extras parameter to ftostr
197 - 27.07.92 Removed the specification of EPSF offsets since the
198  PSFixBoundingBox() routine takes care of all this. Increased
199  size of xmax border for DR2D plots.
200 - 06.07.93 Changed parameters
201 - 27.02.98 Removed unreachable breaks from switch() statement
202 - 07.07.14 Use bl prefix for functions By: CTP
203 */
204 BOOL blAMInitPlot(char *filename,
205  char *title,
206  int dest,
207  REAL OutXSize,
208  REAL OutYSize,
209  REAL OutXOff,
210  REAL OutYOff,
211  char *AltFont,
212  REAL xmargin,
213  REAL ymargin,
214  REAL DataXMin,
215  REAL DataYMin,
216  REAL DataXMax,
217  REAL DataYMax)
218 {
219  PSxpicsize = OutXSize;
220  PSypicsize = OutYSize;
221  PSxoffset = OutXOff;
222  PSyoffset = OutYOff;
223 
224  sGraph.xmin = DataXMin;
225  sGraph.ymin = DataYMin;
226 
227  sGraph.XPScale = 1.0 / (DataXMax - DataXMin);
228  sGraph.YPScale = 1.0 / (DataYMax - DataYMin);
229 
230  switch(dest)
231  {
232  case DEST_SCREEN:
233  /* Screen Version */
234  break;
235  case DEST_PS:
236  return(blPSInit(filename, title, AltFont));
237  case DEST_HPGL:
238  return(blHPGLInit(filename, AltFont, xmargin, ymargin));
239  default:
240  break;
241  }
242 
243  return(FALSE);
244 }
245 
246 /************************************************************************/
247 /*>void blAMSetPen(int dest, int pen)
248  ----------------------------------
249 *//**
250 
251  \param[in] dest Destination
252  \param[in] pen Pen number
253 
254  Change pen
255 - 06.04.92 Handles screen
256 - 07.05.92 Added PS support
257 - 25.06.92 Added HPGL support
258 - 16.07.92 Added DR2D support
259 - 07.07.14 Use bl prefix for functions By: CTP
260 */
261 void blAMSetPen(int dest,
262  int pen)
263 {
264  static REAL pens[MAXPEN] = {0.5, 0.75, 1.0, 1.25, 1.5, 1.75};
265 
266  pen--;
267  pen = pen % MAXPEN;
268 
269  switch(dest)
270  {
271  case DEST_SCREEN:
272  /* Screen Version */
273  break;
274  case DEST_PS:
275  blPSThick(pens[pen]);
276  break;
277  case DEST_HPGL:
278  blHPGLPen(pen+1);
279  break;
280  default:
281  break;
282  }
283 }
284 
285 /************************************************************************/
286 /*>void blAMMove(int dest, REAL x, REAL y)
287  ---------------------------------------
288 *//**
289 
290  \param[in] dest Destination
291  \param[in] x X coordinate
292  \param[in] y Y coordinate
293 
294  Move to a position specified in data coordinates.
295 - 06.04.92 Handles screen
296 - 10.04.92 Added log support
297 - 29.04.92 Added check on log bounds
298 - 07.05.92 Added PS support
299 - 25.06.92 Added HPGL support
300 - 16.07.92 Added DR2D support
301 - 07.07.14 Use bl prefix for functions By: CTP
302 */
303 void blAMMove(int dest,
304  REAL x,
305  REAL y)
306 {
307  switch(dest)
308  {
309  case DEST_SCREEN:
310  /* Screen Version */
311  break;
312  case DEST_PS:
313  x = (x-sGraph.xmin) * sGraph.XPScale;
314  y = (y-sGraph.ymin) * sGraph.YPScale;
315 
316  blPSMove(x,y);
317  break;
318  case DEST_HPGL:
319  x = (x-sGraph.xmin) * sGraph.XPScale;
320  y = (y-sGraph.ymin) * sGraph.YPScale;
321  blHPGLMove(x,y);
322  break;
323  default:
324  break;
325  }
326 }
327 
328 /************************************************************************/
329 /*>void blAMDraw(int dest, REAL x, REAL y)
330  ---------------------------------------
331 *//**
332 
333  \param[in] dest Destination
334  \param[in] x X coordinate
335  \param[in] y Y coordinate
336 
337  Draw to a position specified in data coordinates.
338 
339 - 06.04.92 Handles screen
340 - 10.04.92 Added log support
341 - 29.04.92 Added check on log bounds
342 - 07.05.92 Added PS support
343 - 25.06.92 Added HPGL support
344 - 16.07.92 Added DR2D support
345 - 07.07.14 Use bl prefix for functions By: CTP
346 */
347 void blAMDraw(int dest,
348  REAL x,
349  REAL y)
350 {
351  switch(dest)
352  {
353  case DEST_SCREEN:
354  /* Screen Version */
355  break;
356  case DEST_PS:
357  x = (x-sGraph.xmin) * sGraph.XPScale;
358 
359  y = (y-sGraph.ymin) * sGraph.YPScale;
360 
361  blPSDraw(x,y);
362  break;
363  case DEST_HPGL:
364  x = (x-sGraph.xmin) * sGraph.XPScale;
365 
366  y = (y-sGraph.ymin) * sGraph.YPScale;
367 
368  blHPGLDraw(x,y);
369  break;
370  default:
371  break;
372  }
373 }
374 
375 /************************************************************************/
376 /*>void blAMSetLineStyle(int dest, int style)
377  ------------------------------------------
378 *//**
379 
380  \param[in] dest Destination
381  \param[in] style Style number (0--5)
382 
383  Set the line style
384 
385 - 08.04.92 Framework
386 - 07.05.92 Original (screen & PS)
387 - 25.06.92 Added HPGL support. Removed static store of style.
388 - 05.07.92 Corrected line patterns. They don't have commas!
389 - 16.07.92 Added DR2D support
390 - 07.07.14 Use bl prefix for functions By: CTP
391 */
392 void blAMSetLineStyle(int dest,
393  int style)
394 {
395  static char PSPattern[6][16] = {"", /* PostScript line patterns */
396  "2",
397  "4 1 2 1",
398  "4",
399  "4 3 2 2 2 3",
400  "4 2 4 2 2 2"};
401  switch(dest)
402  {
403  case DEST_SCREEN:
404  /* Screen Version */
405  break;
406  case DEST_PS:
407  if(style == 0) blPSClearDash();
408  else blPSSetDash(PSPattern[style]);
409  break;
410  case DEST_HPGL:
411  blHPGLSetDash(style);
412  break;
413  default:
414  break;
415  }
416 }
417 
418 /************************************************************************/
419 /*>void blAMEndLine(int dest)
420  --------------------------
421 *//**
422 
423  \param[in] dest Destination
424 
425  End a line; required by PostScript actually to draw on the paper.
426 
427 - 07.05.92 Original
428 - 25.06.92 Added HPGL support
429 - 16.07.92 Added DR2D support
430 - 07.07.14 Use bl prefix for functions By: CTP
431 */
432 void blAMEndLine(int dest)
433 {
434  switch(dest)
435  {
436  case DEST_SCREEN:
437  /* Screen Version */
438  break;
439  case DEST_PS:
440  blPSStroke();
441  break;
442  case DEST_HPGL:
443  break;
444  default:
445  break;
446  }
447 }
448 
449 
450 /************************************************************************/
451 /*>void blAMSetFont(int dest, char *PSFontName, REAL FontSize)
452  -----------------------------------------------------------
453 *//**
454 
455  \param[in] dest Destination
456  \param[in] *PSFontName PostScript font name
457  \param[in] FontSize Size (in points) of font
458 
459  Sets the current font using PostScript font names. If producing HPGL
460  output, a lookup table is used to translate this to an HPGL font
461  number
462 
463 - 07.04.92 Framework
464 - 05.05.92 Original for Screen
465 - 07.05.92 Added PS support
466 - 25.06.92 Added HPGL support.
467 - 29.06.92 Modified to use new PS2AmigaFont() for HPGL
468 - 13.07.92 Added DEF_FONT parameter to SetAmigaFont()
469 - 16.07.92 Added DR2D support
470 - 07.07.14 Use bl prefix for functions By: CTP
471 */
472 void blAMSetFont(int dest,
473  char *PSFontName,
474  REAL FontSize)
475 {
476  int FontNum;
477 
478  switch(dest)
479  {
480  case DEST_SCREEN:
481  /* Screen Version */
482  break;
483  case DEST_PS:
484  blPSFont(PSFontName, FontSize);
485  break;
486  case DEST_HPGL:
487  FontNum = blPS2HPGLFont(PSFontName);
488  blHPGLFont(FontNum, FontSize);
489  break;
490  default:
491  break;
492  }
493 }
494 
495 /************************************************************************/
496 /*>void blAMText(int dest, REAL x, REAL y, char *text)
497  ---------------------------------------------------
498 *//**
499 
500  \param[in] dest Destination
501  \param[in] x X coordinate
502  \param[in] y Y coordinate
503  \param[in] *text Text to write
504 
505  Left/bottom justify text at position in data coordinates
506 
507 - 08.04.92 Handles screen
508 - 10.04.92 Added log support
509 - 29.04.92 Added check on log bounds
510 - 07.05.92 Added PS support
511 - 25.06.92 Added HPGL support
512 - 16.07.92 Added DR2D support
513 - 07.07.14 Use bl prefix for functions By: CTP
514 */
515 void blAMText(int dest,
516  REAL x,
517  REAL y,
518  char *text)
519 {
520  switch(dest)
521  {
522  case DEST_SCREEN:
523  /* Screen Version */
524  break;
525 
526  case DEST_PS:
527  x = (x-sGraph.xmin) * sGraph.XPScale;
528  y = (y-sGraph.ymin) * sGraph.YPScale;
529 
530  blPSLText(x,y,text);
531  break;
532  case DEST_HPGL:
533  x = (x-sGraph.xmin) * sGraph.XPScale;
534  y = (y-sGraph.ymin) * sGraph.YPScale;
535 
536  blHPGLLText(x,y,text);
537  break;
538  default:
539  break;
540  }
541 }
542 
543 /************************************************************************/
544 /*>void blAMCBText(int dest, REAL x, REAL y, char *text)
545  -----------------------------------------------------
546 *//**
547 
548  \param[in] dest Destination
549  \param[in] x X coordinate
550  \param[in] y Y coordinate
551  \param[in] *text Text to print
552 
553  Centre-bottom justify text
554 
555 - 07.04.92 Handles screen
556 - 10.04.92 Added log support
557 - 29.04.92 Added check on log bounds
558 - 07.05.92 Added PS support
559 - 25.06.92 Added HPGL support
560 - 16.07.92 Added DR2D support
561 - 07.07.14 Use bl prefix for functions By: CTP
562 */
563 void blAMCBText(int dest,
564  REAL x,
565  REAL y,
566  char *text)
567 {
568  switch(dest)
569  {
570  case DEST_SCREEN:
571  /* Screen Version */
572  break;
573 
574  case DEST_PS:
575  x = (x-sGraph.xmin) * sGraph.XPScale;
576  y = (y-sGraph.ymin) * sGraph.YPScale;
577 
578  blPSCBText(x, y, 0.0, text);
579  break;
580  case DEST_HPGL:
581  x = (x-sGraph.xmin) * sGraph.XPScale;
582  y = (y-sGraph.ymin) * sGraph.YPScale;
583 
584  blHPGLCBText(x, y, 0.0, text);
585  break;
586  default:
587  break;
588  }
589 }
590 
591 /************************************************************************/
592 /*>void blAMRText(int dest, REAL x, REAL y, REAL offset, char *text)
593  -----------------------------------------------------------------
594 *//**
595 
596  \param[in] dest Destination
597  \param[in] x X coordinate
598  \param[in] y Y coordinate
599  \param[in] offset Move left by this amount (in points)
600  \param[in] *text Text to print
601 
602  Right/centre justify text at position in data coordinates; offset is
603  an x-offset specified in device coordinates (pt)
604 
605 - 06.04.92 Handles screen
606 - 07.04.92 Fix to positioning
607 - 10.04.92 Added log support
608 - 29.04.92 Added check on log bounds
609 - 07.05.92 Added PS support and offset
610 - 25.06.92 Added HPGL support
611 - 16.07.92 Added DR2D support
612 - 07.07.14 Use bl prefix for functions By: CTP
613 */
614 void blAMRText(int dest,
615  REAL x,
616  REAL y,
617  REAL offset,
618  char *text)
619 {
620  switch(dest)
621  {
622  case DEST_SCREEN:
623  /* Screen Version */
624  break;
625 
626  case DEST_PS:
627  x = (x-sGraph.xmin) * sGraph.XPScale;
628  y = (y-sGraph.ymin) * sGraph.YPScale;
629 
630  blPSROffText(x, y, offset, text);
631  break;
632  case DEST_HPGL:
633  x = (x-sGraph.xmin) * sGraph.XPScale;
634  y = (y-sGraph.ymin) * sGraph.YPScale;
635 
636  blHPGLROffText(x, y, offset, text);
637  break;
638  default:
639  break;
640  }
641 }
642 
643 /************************************************************************/
644 /*>void blAMLCText(int dest, REAL x, REAL y, char *text)
645  -----------------------------------------------------
646 *//**
647 
648  \param[in] dest Destination
649  \param[in] x X coordinate
650  \param[in] y Y coordinate
651  \param[in] *text Text to print
652 
653  Left/centre height justify text at position in data coordinates
654 
655 - 08.04.92 Handles screen
656 - 10.04.92 Added log support
657 - 29.04.92 Added check on log bounds
658 - 06.05.92 Fix to height centering
659 - 07.05.92 Added PS support
660 - 08.05.92 Corrected Y-pos for PS
661 - 25.06.92 Added HPGL support
662 - 16.07.92 Added DR2D support
663 - 07.07.14 Use bl prefix for functions By: CTP
664 */
665 void blAMLCText(int dest,
666  REAL x,
667  REAL y,
668  char *text)
669 {
670  switch(dest)
671  {
672  case DEST_SCREEN:
673  /* Screen Version */
674  break;
675 
676  case DEST_PS:
677  x = (x-sGraph.xmin) * sGraph.XPScale;
678  y = (y-sGraph.ymin) * sGraph.YPScale;
679 
680  blPSLCText(x,y,text);
681  break;
682  case DEST_HPGL:
683  x = (x-sGraph.xmin) * sGraph.XPScale;
684  y = (y-sGraph.ymin) * sGraph.YPScale;
685 
686  blHPGLLCText(x,y,text);
687  break;
688  default:
689  break;
690  }
691 }
692 
693 /************************************************************************/
694 /*>void blAMCTText(int dest, REAL x, REAL y, REAL CTOffset, char *text)
695  --------------------------------------------------------------------
696 *//**
697 
698  \param[in] dest Destination
699  \param[in] x X coordinate
700  \param[in] y Y coordinate
701  \param[in] CTOffset Move down by this amount (points)
702  \param[in] *text Text to print
703 
704  Centre/top justify text at position in data coordinates.
705 
706 - 06.04.92 Handles screen
707 - 07.04.92 Fix to positioning
708 - 10.04.92 Added log support
709 - 29.04.92 Added check on log bounds
710 - 07.05.92 Added PS support
711 - 25.06.92 Added HPGL support
712 - 01.07.92 Changed for new versions of PSCTText() and HPGLCTText() which
713  take offset in points.
714 - 16.07.92 Added DR2D support
715 - 07.06.93 Added CTOffset param
716 - 07.07.14 Use bl prefix for functions By: CTP
717 */
718 void blAMCTText(int dest,
719  REAL x,
720  REAL y,
721  REAL CTOffset,
722  char *text)
723 {
724  switch(dest)
725  {
726  case DEST_SCREEN:
727  /* Screen Version */
728  break;
729 
730  case DEST_PS:
731  x = (x-sGraph.xmin) * sGraph.XPScale;
732 
733  y = (y-sGraph.ymin) * sGraph.YPScale;
734 
735  blPSCTText(x, y, CTOffset, text);
736  break;
737  case DEST_HPGL:
738  x = (x-sGraph.xmin) * sGraph.XPScale;
739 
740  y = (y-sGraph.ymin) * sGraph.YPScale;
741 
742  blHPGLCTText(x, y, CTOffset, text);
743  break;
744  default:
745  break;
746  }
747 }
748 
749 /************************************************************************/
750 /*>void blAMEndPlot(int dest)
751  --------------------------
752 *//**
753 
754  \param[in] dest Destination
755 
756  Close up a device after plotting.
757 
758 - 07.05.92 Original
759 - 25.06.92 Added HPGL support
760 - 01.07.92 Added blank WriteMessage() when plotting to screen
761 - 16.07.92 Added DR2D support
762 - 07.07.14 Use bl prefix for functions By: CTP
763 */
764 void blAMEndPlot(int dest)
765 {
766  switch(dest)
767  {
768  case DEST_SCREEN:
769  /* Screen Version */
770  break;
771  case DEST_PS:
772  blPSEnd();
773  break;
774  case DEST_HPGL:
775  blHPGLEnd();
776  break;
777  default:
778  break;
779  }
780 }
781 
782 /************************************************************************/
783 /*>int blPS2HPGLFont(char *font)
784  -----------------------------
785 *//**
786 
787  \param[in] *font PostScript font name
788  \return HPGL font number
789 
790  Takes the PostScript font name and works out the best HPGL equivalent
791  from a translation table. On the first call, the table is read from
792  disk and space is allocated for it. If the routine is called with a
793  NULL parameter, the space allocated for the table is freed. It is
794  quite safe to call the routine again after this has occurred; the
795  table will simply be re-read from disk.
796 
797  If the requested translation is unsuccessful, 0 will be returned as
798  the font number.
799 
800 - 06.07.93 Original By: ACRM
801 - 07.07.14 Use bl prefix for functions By: CTP
802 */
803 int blPS2HPGLFont(char *font)
804 {
805  int i;
806  char buffer[MAXBUFF];
807  static BOOL FirstCall = TRUE;
808  static int NTrans = 0;
809  static struct /* Font translation table */
810  {
811  char *PSFont;
812  int HPGLFont;
813  } FontTable[MAXTRANS];
814 
815 
816  /* If called with a NULL font name, we free the font table and
817  return.
818  */
819  if(font==NULL)
820  {
821  for(i=0; i<NTrans; i++)
822  {
823  if(FontTable[i].PSFont)
824  {
825  free(FontTable[i].PSFont);
826  FontTable[i].PSFont = NULL;
827  }
828  }
829  FirstCall = TRUE;
830  NTrans = 0;
831  return(0);
832  }
833 
834 
835  /* If it's the first call we read the font translation table allocating
836  space for the font names. Should we fail, we just drop out.
837  */
838  if(FirstCall)
839  {
840  FILE *fp = NULL; /* Font translation file */
841 
842  FirstCall = FALSE;
843 
844  if((fp=fopen(TRANS_TABLE,"r")) != NULL) /* If found table */
845  {
846  char buffer[MAXBUFF]; /* Buffer for file */
847  char FontName[40]; /* Font name read */
848  int FontNum; /* HPGL number read */
849 
850  while(fgets(buffer,MAXBUFF-1,fp)) /* Read file */
851  {
852  TERMINATE(buffer);
853  sscanf(buffer,"%s %d",FontName,&FontNum);
854 
855  if(strlen(FontName) && FontName[0] != '!')
856  {
857  /* We've got a font name and number. Allocate space */
858  FontTable[NTrans].PSFont =
859  (char *)malloc((strlen(FontName)+1) * sizeof(char));
860 
861  /* No room! */
862  if(FontTable[NTrans].PSFont == NULL) break;
863 
864  /* Copy in the info, down casing the font name & removing
865  leading spaces and tabs
866  */
867  blStringToLower(FontName, buffer);
868  strcpy(FontTable[NTrans].PSFont, blKillLeadSpaces(buffer));
869  FontTable[NTrans].HPGLFont = FontNum;
870 
871  /* Increment the translation count */
872  if(++NTrans > MAXTRANS) break;
873  }
874  }
875  fclose(fp);
876  }
877  }
878 
879  /* If we've got some translations, search for the specified font */
880  if(NTrans)
881  {
882  char *ptr = NULL;
883 
884  blStringToLower(font, buffer);
885  ptr = blKillLeadSpaces(buffer);
886 
887  for(i=0; i<NTrans; i++)
888  {
889  if(!strcmp(ptr, FontTable[i].PSFont))
890  {
891  return(FontTable[i].HPGLFont);
892  }
893  }
894  }
895 
896  /* If no translations, or font not found, just return 0 */
897  return(0);
898 }
899 
900 /************************************************************************/
901 /*>char *blSimplifyText(char *string)
902  ----------------------------------
903 *//**
904 
905  \param[in] *string String containing control codes
906  \return String with control codes removed
907 
908  Removes control codes from a string for screen display. Also used for
909  calculating string length. The returned string is stored as static
910  within the routine
911 
912 - 06.05.92 Original
913 - 07.07.14 Use bl prefix for functions By: CTP
914 */
915 char *blSimplifyText(char *string)
916 {
917  static char retstring[MAXBUFF];
918  int i, j;
919 
920  /* Just return the string unaltered if its too long */
921  if(strlen(string) > MAXBUFF-1) return(string);
922 
923  /* Walk along the string */
924  for(i=0, j=0; i<strlen(string) && j<MAXBUFF-1; i++)
925  {
926  switch(string[i])
927  {
928  case '\\': /* Should interpret next character as Greek */
929  retstring[j++] = string[++i];
930  break;
931  case '^': /* Should raise next character */
932  if(string[++i] == '{')
933  while(string[++i] != '}' && string[i] != '\0' && j<MAXBUFF-1)
934  retstring[j++] = string[i];
935  else
936  retstring[j++] = string[i];
937  break;
938  case '_': /* Should lower next character */
939  if(string[++i] == '{')
940  while(string[++i] != '}' && string[i] != '\0' && j<MAXBUFF-1)
941  retstring[j++] = string[i];
942  else
943  retstring[j++] = string[i];
944  break;
945  default: /* An ordinary character */
946  retstring[j++] = string[i];
947  break;
948  }
949  }
950 
951  retstring[j] = '\0';
952 
953  return(retstring);
954 }
955 
#define DEST_PS
Definition: plotting.h:74
void blPSClearDash(void)
Definition: ps.c:382
void blAMLCText(int dest, REAL x, REAL y, char *text)
Definition: plotting.c:665
void blPSLCText(REAL X, REAL Y, char *label)
Definition: ps.c:583
void blPSEnd(void)
Definition: ps.c:840
void blHPGLCTText(REAL x, REAL y, REAL offset, char *text)
Definition: hpgl.c:521
REAL PSyoffset
short BOOL
Definition: SysDefs.h:64
void blPSSetDash(char *linepatt)
Definition: ps.c:366
#define NULL
Definition: array2.c:99
void blHPGLPen(int num)
Definition: hpgl.c:214
#define DEST_SCREEN
Definition: plotting.h:73
void blHPGLEnd(void)
Definition: hpgl.c:651
char * blKillLeadSpaces(char *string)
void blPSThick(REAL thickness)
Definition: ps.c:309
void blPSFont(char *fontname, REAL size)
Definition: ps.c:418
char * blSimplifyText(char *string)
Definition: plotting.c:915
#define FALSE
Definition: macros.h:223
void blHPGLCBText(REAL x, REAL y, REAL offset, char *text)
Definition: hpgl.c:400
void blPSLText(REAL X, REAL Y, char *label)
Definition: ps.c:457
void blAMRText(int dest, REAL x, REAL y, REAL offset, char *text)
Definition: plotting.c:614
void blHPGLSetDash(int style)
Definition: hpgl.c:286
Useful macros.
#define DEST_HPGL
Definition: plotting.h:75
void blAMSetPen(int dest, int pen)
Definition: plotting.c:261
Include file for using plotting routines.
#define TERMINATE(x)
Definition: macros.h:366
void blPSCBText(REAL X, REAL Y, REAL Offset, char *label)
Definition: ps.c:490
REAL ymin
Definition: plotting.c:146
double REAL
Definition: MathType.h:67
REAL PSypicsize
BOOL blAMInitPlot(char *filename, char *title, int dest, REAL OutXSize, REAL OutYSize, REAL OutXOff, REAL OutYOff, char *AltFont, REAL xmargin, REAL ymargin, REAL DataXMin, REAL DataYMin, REAL DataXMax, REAL DataYMax)
Definition: plotting.c:204
void blAMEndPlot(int dest)
Definition: plotting.c:764
REAL PSxoffset
void blAMEndLine(int dest)
Definition: plotting.c:432
REAL xmin
Definition: plotting.c:146
#define TRANS_TABLE
Definition: plotting.c:136
#define TRUE
Definition: macros.h:219
void blHPGLROffText(REAL x, REAL y, REAL offset, char *text)
Definition: hpgl.c:440
REAL XPScale
Definition: plotting.c:146
void blPSROffText(REAL X, REAL Y, REAL offset, char *label)
Definition: ps.c:548
void blHPGLMove(REAL x, REAL y)
Definition: hpgl.c:235
int blPS2HPGLFont(char *font)
Definition: plotting.c:803
void blPSDraw(REAL X, REAL Y)
Definition: ps.c:348
void blHPGLLText(REAL x, REAL y, char *string)
Definition: hpgl.c:368
REAL YPScale
Definition: plotting.c:146
Header file for general purpose routines.
void blAMDraw(int dest, REAL x, REAL y)
Definition: plotting.c:347
void blAMCBText(int dest, REAL x, REAL y, char *text)
Definition: plotting.c:563
#define MAXPEN
Definition: plotting.c:138
void blPSStroke(void)
Definition: ps.c:397
void blAMMove(int dest, REAL x, REAL y)
Definition: plotting.c:303
System-type variable type definitions.
void blPSMove(REAL X, REAL Y)
Definition: ps.c:328
void blAMSetFont(int dest, char *PSFontName, REAL FontSize)
Definition: plotting.c:472
REAL PSxpicsize
BOOL blPSInit(char *FName, char *creator, char *AltFont)
Definition: ps.c:189
void blHPGLLCText(REAL x, REAL y, char *text)
Definition: hpgl.c:482
void blPSCTText(REAL X, REAL Y, REAL Offset, char *label)
Definition: ps.c:620
Type definitions for maths.
void blStringToLower(char *string1, char *string2)
#define MAXBUFF
Definition: plotting.c:139
BOOL blHPGLInit(char *filename, char *AltFont, REAL xmargin, REAL ymargin)
Definition: hpgl.c:170
void blHPGLDraw(REAL x, REAL y)
Definition: hpgl.c:257
#define MAXTRANS
Definition: plotting.c:135
void blHPGLFont(int font, REAL size)
Definition: hpgl.c:327
void blAMText(int dest, REAL x, REAL y, char *text)
Definition: plotting.c:515
void blAMSetLineStyle(int dest, int style)
Definition: plotting.c:392
void blAMCTText(int dest, REAL x, REAL y, REAL CTOffset, char *text)
Definition: plotting.c:718