home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume6 / yahp2ps / part03 / basic.c next >
C/C++ Source or Header  |  1989-02-03  |  4KB  |  224 lines

  1. /*
  2.         HPGL to PostScript converter
  3.    Copyright (C) 1988 (and following) Federico Heinz
  4.  
  5. yahp2ps is distributed in the hope that it will be useful, but WITHOUT ANY
  6. WARRANTY.  No author or distributor accepts responsibility to anyone
  7. for the consequences of using it or for whether it serves any
  8. particular purpose or works at all, unless he says so in writing.
  9. Refer to the Free Software Foundation's General Public License for full details.
  10.  
  11. Everyone is granted permission to copy, modify and redistribute yahp2ps,
  12. but only under the conditions described in the GNU General Public
  13. License.  A copy of this license is supposed to have been given to you
  14. along with yahp2ps so you can know your rights and responsibilities.  It
  15. should be in a file named COPYING.  Among other things, the copyright
  16. notice and this notice must be preserved on all copies.
  17.  
  18. In other words, go ahead and share yahp2ps, but don't try to stop
  19. anyone else from sharing it farther.  Help stamp out software hoarding!
  20.  
  21. yahp2ps is TOTALLY unrelated to GNU or the Free Software Foundation,
  22. it is only released under the same conditions.
  23.  
  24.     For bug reports, wishes, etc. send e-mail to
  25.  
  26.     ...!mcvax!unido!tub!actisb!federico  (from Europe)
  27.     ...!uunet!pyramid!actisb!federico    (from anywhere else)
  28.  
  29.     For Physical mail:
  30.  
  31.     Federico Heinz
  32.     Beusselstr. 21
  33.     1000 Berlin 21
  34.  
  35.     Tel. (+49 30) 396 77 92
  36.  
  37. */
  38. /***********************************************************************
  39.  
  40.   Basical pen movement.
  41.  
  42. ***********************************************************************/
  43.  
  44. #include <ctype.h>
  45. #include "defs.h"
  46. #include "penctrl.h"
  47. #include "io.h"
  48. #include "dispatch.h"
  49. #include "basic.h"
  50.  
  51.  
  52. static Boolean     RelativePlot;         /* Are we plotting relative points? */
  53. static char        SymbolChar;           /* Plot chars at end of vectors?    */
  54.  
  55.  
  56. /*
  57.  
  58.   Reset this module's private status.
  59.  
  60. */
  61.  
  62. void basicInit()
  63.  
  64. { RelativePlot = False;
  65.   setDash(FullLine, P1P2Diagonal / 25);
  66.   SymbolChar = '\0';
  67. }
  68.  
  69.  
  70.  
  71. /*
  72.  
  73.   Follow a Polyline given as CoordinatePairs.
  74.  
  75. */
  76.  
  77. static void followPolyLine()
  78.  
  79. { CoordinatePair target;
  80.  
  81.   while (isNumeric(LookAhead))
  82.   { if (!getCoordinatePair(target))
  83.     { endCommand();
  84.       return;
  85.     }
  86.     if (RelativePlot)
  87.     { target[X] = PenPosition[X] + target[X];
  88.       target[Y] = PenPosition[Y] + target[Y];
  89.     }
  90.     doLine(target[X], target[Y]);
  91.     if (SymbolChar)
  92.       /* symbol mode stuff here */ ;
  93.   }
  94.   if (isTerminator(LookAhead))
  95.     endCommand();
  96. }
  97.  
  98.  
  99. /***********************************************************************
  100.  
  101.   User-controlled pen lifting, lowering and selecting.
  102.   
  103. ***********************************************************************/
  104.  
  105.  
  106. /*
  107.  
  108.   Select a new pen.
  109.  
  110. */
  111.  
  112. CommandImplementation selectPen()
  113.  
  114. { Number pen;
  115.  
  116.   if (isNumeric(LookAhead) && getNumber(&pen))
  117.     changePen(pen);
  118.   else
  119.     changePen(Zero);
  120.   endCommand();
  121. }
  122.  
  123.  
  124.  
  125. /*
  126.  
  127.   Lift the pen and follow the CoordinatePair list.
  128.  
  129. */
  130.  
  131. CommandImplementation penUp()
  132.  
  133. { liftPen();
  134.   followPolyLine();
  135. }
  136.  
  137.  
  138.  
  139. /*
  140.  
  141.   Lower the pen and follow the CoordinatePair list.
  142.  
  143. */
  144.  
  145. CommandImplementation penDown()
  146.  
  147. { lowerPen();
  148.   followPolyLine();
  149. }
  150.  
  151.  
  152.  
  153. /************************************************************************
  154.  
  155.      Mode switching (absolute/relative, symbol/no symbol)
  156.   
  157. ************************************************************************/
  158.  
  159.  
  160.  
  161. /*
  162.  
  163.   Handle symbol mode switching.
  164.  
  165. */
  166.  
  167. CommandImplementation setSymbolMode()
  168.  
  169. { SymbolChar = isTerminator(LookAhead) ? '\0' : getChar();
  170.   endCommand();
  171. }
  172.   
  173.  
  174.  
  175. /*
  176.  
  177.   Start plotting with absolute coordinates.
  178.  
  179. */
  180.  
  181. CommandImplementation setAbsolutePlot()
  182.  
  183. { RelativePlot = False;
  184.   followPolyLine();
  185. }
  186.  
  187.  
  188.  
  189. /*
  190.  
  191.   Start plotting with relative coordinate 
  192.  
  193. */
  194.  
  195. CommandImplementation setRelativePlot()
  196.  
  197. { RelativePlot = True;
  198.   followPolyLine();
  199. }
  200.  
  201.  
  202.  
  203.  
  204. /*
  205.  
  206.   Change the line type.
  207.  
  208. */
  209.  
  210. CommandImplementation setLineType()
  211.  
  212. { Number pattern, patternLength;
  213.  
  214.   if (isTerminator(LookAhead))
  215.     setDash(FullLine, DefaultPatternLength);
  216.   else if (getInteger(&pattern))
  217.     if (isTerminator(LookAhead))
  218.       setDash(pattern, DefaultPatternLength);
  219.     else if (getInteger(&patternLength))
  220.       setDash(pattern, patternLength);
  221.   endCommand();
  222. }
  223.  
  224.