home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2002 November / SGI Freeware 2002 November - Disc 3.iso / dist / fw_plotutils.idb / usr / freeware / share / libplot / h-demo.c.z / h-demo.c
Encoding:
C/C++ Source or Header  |  2002-01-08  |  6.7 KB  |  191 lines

  1. /* This C program, h-demo.c, when compiled and linked with GNU libplot,
  2.    will emit to standard output a sample page illustrating many of the
  3.    Hershey fonts.  The file will be in portable metafile format.  It may be
  4.    translated to other formats, or viewed in an X window, with the `plot'
  5.    utility.  The sample page is taken from Allen Hershey's 1972 article in
  6.    Computer Graphics and Image Processing (vol. 1, no. 4, pp. 373-385).
  7.  
  8.    Compile and link with: 
  9.  
  10.        gcc h-demo.c -lplot -lXaw -lXmu -lXt -lXext -lX11 -lm
  11.  
  12.    or, in recent versions of the X Window System,
  13.  
  14.        gcc h-demo.c -lplot -lXaw -lXmu -lXt -lSM -lICE -lXext -lX11 -lm
  15.  
  16.    To translate the sample page to Postscript, you would do 
  17.    `a.out | plot -T ps > page.ps'.  To display the page in an 
  18.    X Window, you would do `a.out | plot -T X', etc.  
  19.  
  20.    The above compilation instructions assume that your linker will be able
  21.    to find libplot and the X Window System libraries.  You may need to
  22.    include such options as -L/usr/local/lib and -L/usr/X11/lib to ensure
  23.    this.  Also, the linking options may differ if you are using Motif.
  24.    If you are using a C compiler other than gcc, consult your system
  25.    administrator.
  26.    
  27.    (The -DNO_CONST_SUPPORT option may need to be used if the C compiler,
  28.    like the version of `cc' supplied with SunOS 4.1.x, is so old that it
  29.    does not understand the `const' type qualifier.  If compiling under
  30.    SunOS 4.1.x, you may also need to specify the `-static' option, to work
  31.    around problems with undefined symbols in the SunOS X libraries.)
  32.  
  33.    If you have any trouble running the demo after compiling it, be sure
  34.    your LD_LIBRARY_PATH environment variable includes the directory in
  35.    which libplot is stored.  This only applies on systems in which libplot
  36.    is implemented as a shared library that is linked at run time. */
  37.  
  38. #include <stdio.h> 
  39. #include <plot.h>
  40.  
  41. #ifdef M_SQRT1_2
  42. #undef M_SQRT1_2
  43. #endif
  44. #define M_SQRT1_2   (0.70710678118654752440) /* 1/sqrt(2) */
  45.  
  46. #define NUM_DEMO_WORDS 34
  47. struct hershey_word 
  48. {
  49.   char *word;
  50.   char *fontname;
  51.   double m[6];
  52.   char just;
  53. };
  54.  
  55. #define CART (9.0/21.0)        /* `cartographic' size */
  56. #define INDEXICAL (13.0/21.0)    /* `indexical' size */
  57.  
  58. #define LLX -3800.0
  59. #define LLY -3450.0
  60. #define URX 3800.0
  61. #define URY 4150.0
  62.  
  63. #define BASE_FONTSIZE 220.0
  64.  
  65. struct hershey_word demo_word[NUM_DEMO_WORDS] = 
  66. {
  67.   {"Invitation", "HersheyScript-Bold", 
  68.      { 1., 0., 0., 1., -3125., 3980. }, 'l' },
  69.   {"ECONOMY", "HersheySans",           
  70.      { 1., 0., 0., 1., -3125., 3340. }, 'l'},
  71.   {"CARTOGRAPHY", "HersheySans",       
  72.      { CART, 0., 0., CART, -3125., 2700. }, 'l'},
  73.   {"Gramma", "HersheySerifSymbol",    
  74.      { 1., 0., 0., 1., -3125., 2060. }, 'l'},
  75.   {"\347\322\301\306\311\313\301", "HersheyCyrillic",       
  76.      { 1., 0., 0., 1., -3125., 1420. }, 'l'},
  77.  
  78.   {"COMMUNICATION", "HersheySans-Bold", 
  79.      { 1., 0., 0., 1., 0., 3980. }, 'c'},
  80.   {"VERSATILITY", "HersheySerif-Italic",
  81.      { 1., 0., 0., 1., 0., 3340. }, 'c'},
  82.   {"Standardization", "HersheySerif",   
  83.      { 1., 0., 0., 1., 0., 2700. }, 'c'},
  84.   {"Sumbolon", "HersheySerifSymbol",  
  85.      { INDEXICAL, 0., 0., INDEXICAL, 0., 2060. }, 'c'},
  86.   {"\363\354\357\366\356\357\363\364\370", "HersheyCyrillic",      
  87.      { 1., 0., 0., 1., 0., 1420. }, 'c'},
  88.  
  89.   {"Publication", "HersheyScript-Bold", 
  90.      { 1., 0., 0., 1., 3125., 3980. }, 'r'},
  91.   {"Quality", "HersheyGothicEnglish",  
  92.      { 1., 0., 0., 1., 3125., 3340. }, 'r'},
  93.   {"TYPOGRAPHY", "HersheySans",         
  94.      { CART, 0., 0., CART, 3125., 2700. }, 'r'},
  95.   {"AriJmo\\s-", "HersheySerifSymbol",    
  96.      { 1., 0., 0., 1., 3125., 2060. }, 'r'},
  97.   {"\346\317\316\305\324\311\313\301", "HersheyCyrillic",       
  98.      { 1., 0., 0., 1., 3125., 1420. }, 'r'},
  99.  
  100.   {"EXTENSION", "HersheySans", 
  101.      { 17./7., 0., 0., 2./7., 0., 780. }, 'c'},
  102.   {"CONDENSATION", "HersheySans", 
  103.      { 5./7., 0., 0., 17./7., 0., -20. }, 'c'},
  104.   {"Rotation", "HersheySans", 
  105.      { M_SQRT1_2, M_SQRT1_2, -M_SQRT1_2, M_SQRT1_2, -2880., -20. }, 'l'},
  106.   {"ROTATION", "HersheySans", 
  107.      { M_SQRT1_2, -M_SQRT1_2, M_SQRT1_2, M_SQRT1_2, 2880., -20. }, 'r'},
  108.  
  109.   {"Syllabary", "HersheySerif",           
  110.      { 1., 0., 0., 1., -3125., -780. }, 'l'},
  111.   {"Art", "HersheyGothicEnglish",        
  112.      { 1., 0., 0., 1., -3125., -1420. }, 'l'},
  113.   {"Meteorology", "HersheySerif-Italic",  
  114.      { INDEXICAL, 0., 0., INDEXICAL, -3125., -2060.}, 'l'},
  115.   {"CHEMISTRY", "HersheySerif",           
  116.      { 1., 0., 0., 1., -3125., -2700.}, 'l'},
  117.   {"Analysis", "HersheySerif-BoldItalic", 
  118.      { 1., 0., 0., 1., -3125., -3340.}, 'l'},
  119.  
  120.   {"LEXIKON", "HersheySerifSymbol-Bold",      
  121.      { 1., 0., 0., 1., 0., -780.}, 'c'},
  122.   {"\\#J3d71\\#J463b", "HersheySerif",      
  123.      { 1./.7, 0., 0., 1./.7, 0., -1420.}, 'c'},
  124.   {"Wissenschaft", "HersheyGothicGerman",
  125.      { 1., 0., 0., 1., 0., -2060.}, 'c'},
  126.   {"Electronics", "HersheySerif-Italic",  
  127.      { 1., 0., 0., 1., 0., -2700.}, 'c'},
  128.   {"COMPUTATION", "HersheySerif-Bold",    
  129.      { 1., 0., 0., 1., 0., -3340.}, 'c'},
  130.  
  131.   {"Alphabet", "HersheySerif",            
  132.      { 1., 0., 0., 1., 3125., -780.}, 'r'},
  133.   {"Music", "HersheyGothicItalian",      
  134.      { 1., 0., 0., 1., 3125., -1420.}, 'r'},
  135.   {"Astronomy", "HersheySerif",           
  136.      { INDEXICAL, 0., 0., INDEXICAL, 3125., -2060.}, 'r'},
  137.   {"MATHEMATICS", "HersheySerif",         
  138.      { 1., 0., 0., 1., 3125., -2700.}, 'r'},
  139.   {"Program", "HersheySerif-BoldItalic",  
  140.      { 1., 0., 0., 1., 3125., -3340.}, 'r'},
  141. };
  142.  
  143. int
  144. main()
  145. {
  146.   plPlotter *plotter;
  147.   plPlotterParams *plotter_params;
  148.   int i;
  149.  
  150.   /* set Plotter parameters */
  151.   plotter_params = pl_newplparams ();
  152.   pl_setplparam (plotter_params, "META_PORTABLE", "yes");
  153.  
  154.   /* create a Metafile Plotter with the specified parameters */
  155.   if ((plotter = pl_newpl_r ("meta", stdin, stdout, stderr,
  156.                  plotter_params)) == NULL)
  157.     {
  158.       fprintf (stderr, "Couldn't create Plotter\n");
  159.       return 1;
  160.     }
  161.   
  162.   /* open it, set up user coordinate system */
  163.   pl_openpl_r (plotter);
  164.   pl_erase_r (plotter);
  165.   pl_fspace_r (plotter, LLX, LLY, URX, URY);
  166.  
  167.   /* loop through words, each time saving and restoring graphics state */
  168.   for (i = 0; i < NUM_DEMO_WORDS; i++)
  169.     {
  170.       pl_savestate_r (plotter);
  171.       pl_fontname_r (plotter, demo_word[i].fontname);
  172.       pl_fconcat_r (plotter,
  173.             demo_word[i].m[0], demo_word[i].m[1], 
  174.             demo_word[i].m[2], demo_word[i].m[3],
  175.             demo_word[i].m[4], demo_word[i].m[5]);
  176.       pl_ffontsize_r (plotter, BASE_FONTSIZE);
  177.       pl_fmove_r (plotter, 0.0, 0.0);
  178.       pl_alabel_r (plotter, demo_word[i].just, 'c', demo_word[i].word);
  179.       pl_restorestate_r (plotter);
  180.     }
  181.  
  182.   /* close and delete Plotter */
  183.   pl_closepl_r (plotter);
  184.   if (pl_deletepl_r (plotter) < 0)
  185.     {
  186.       fprintf (stderr, "Couldn't delete Plotter\n");
  187.       return 1;
  188.     }
  189.   return 0;
  190. }
  191.