home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1996 February / PCWK0296.iso / sharewar / dos / program / gs300sr1 / gs300sr1.exe / ZPATH.C < prev    next >
C/C++ Source or Header  |  1994-07-27  |  5KB  |  197 lines

  1. /* Copyright (C) 1989, 1990, 1991, 1993 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of Aladdin Ghostscript.
  4.   
  5.   Aladdin Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author
  6.   or distributor accepts any responsibility for the consequences of using it,
  7.   or for whether it serves any particular purpose or works at all, unless he
  8.   or she says so in writing.  Refer to the Aladdin Ghostscript Free Public
  9.   License (the "License") for full details.
  10.   
  11.   Every copy of Aladdin Ghostscript must include a copy of the License,
  12.   normally in a plain ASCII text file named PUBLIC.  The License grants you
  13.   the right to copy, modify and redistribute Aladdin Ghostscript, but only
  14.   under certain conditions described in the License.  Among other things, the
  15.   License requires that the copyright notice and this notice be preserved on
  16.   all copies.
  17. */
  18.  
  19. /* zpath.c */
  20. /* Path operators */
  21. #include "math_.h"
  22. #include "ghost.h"
  23. #include "errors.h"
  24. #include "oper.h"
  25. #include "igstate.h"
  26. #include "gsmatrix.h"
  27. #include "gspath.h"
  28. #include "store.h"
  29.  
  30. /* Forward references */
  31. private int near common_to(P2(os_ptr,
  32.   int (*)(P3(gs_state *, floatp, floatp))));
  33. private int near common_arc(P2(os_ptr,
  34.   int (*)(P6(gs_state *, floatp, floatp, floatp, floatp, floatp))));
  35. private int near common_arct(P2(os_ptr, float *));
  36. private int near common_curve(P2(os_ptr,
  37.   int (*)(P7(gs_state *, floatp, floatp, floatp, floatp, floatp, floatp))));
  38.  
  39. /* - newpath - */
  40. int
  41. znewpath(register os_ptr op)
  42. {    return gs_newpath(igs);
  43. }
  44.  
  45. /* - currentpoint <x> <y> */
  46. int
  47. zcurrentpoint(register os_ptr op)
  48. {    gs_point pt;
  49.     int code = gs_currentpoint(igs, &pt);
  50.     if ( code < 0 ) return code;
  51.     push(2);
  52.     make_real(op - 1, pt.x);
  53.     make_real(op, pt.y);
  54.     return 0;
  55. }
  56.  
  57. /* <x> <y> moveto - */
  58. int
  59. zmoveto(os_ptr op)
  60. {    return common_to(op, gs_moveto);
  61. }
  62.  
  63. /* <dx> <dy> rmoveto - */
  64. int
  65. zrmoveto(os_ptr op)
  66. {    return common_to(op, gs_rmoveto);
  67. }
  68.  
  69. /* <x> <y> lineto - */
  70. int
  71. zlineto(os_ptr op)
  72. {    return common_to(op, gs_lineto);
  73. }
  74.  
  75. /* <dx> <dy> rlineto - */
  76. int
  77. zrlineto(os_ptr op)
  78. {    return common_to(op, gs_rlineto);
  79. }
  80.  
  81. /* Common code for [r](move/line)to */
  82. private int near
  83. common_to(os_ptr op, int (*add_proc)(P3(gs_state *, floatp, floatp)))
  84. {    float opxy[2];
  85.     int code;
  86.     if (    (code = num_params(op, 2, opxy)) < 0 ||
  87.         (code = (*add_proc)(igs, opxy[0], opxy[1])) < 0
  88.        ) return code;
  89.     pop(2);
  90.     return 0;
  91. }
  92.  
  93. /* <x> <y> <r> <ang1> <ang2> arc - */
  94. int
  95. zarc(os_ptr op)
  96. {    return common_arc(op, gs_arc);
  97. }
  98.  
  99. /* <x> <y> <r> <ang1> <ang2> arcn - */
  100. int
  101. zarcn(os_ptr op)
  102. {    return common_arc(op, gs_arcn);
  103. }
  104.  
  105. /* Common code for arc[n] */
  106. private int near
  107. common_arc(os_ptr op,
  108.   int (*aproc)(P6(gs_state *, floatp, floatp, floatp, floatp, floatp)))
  109. {    float xyra[5];            /* x, y, r, ang1, ang2 */
  110.     int code;
  111.     if ( (code = num_params(op, 5, xyra)) < 0 ) return code;
  112.     code = (*aproc)(igs, xyra[0], xyra[1], xyra[2], xyra[3], xyra[4]);
  113.     if ( code >= 0 ) pop(5);
  114.     return code;
  115. }
  116.  
  117. /* <x1> <y1> <x2> <y2> <r> arct - */
  118. int
  119. zarct(register os_ptr op)
  120. {    int code = common_arct(op, (float *)0);
  121.     if ( code < 0 ) return code;
  122.     pop(5);
  123.     return 0;
  124. }
  125.  
  126. /* <x1> <y1> <x2> <y2> <r> arcto <xt1> <yt1> <xt2> <yt2> */
  127. int
  128. zarcto(register os_ptr op)
  129. {    float tanxy[4];            /* xt1, yt1, xt2, yt2 */
  130.     int code = common_arct(op, tanxy);
  131.     if ( code < 0 ) return code;
  132.     make_real(op - 4, tanxy[0]);
  133.     make_real(op - 3, tanxy[1]);
  134.     make_real(op - 2, tanxy[2]);
  135.     make_real(op - 1, tanxy[3]);
  136.     pop(1);
  137.     return 0;
  138. }
  139.  
  140. /* Common code for arct[o] */
  141. private int near
  142. common_arct(os_ptr op, float *tanxy)
  143. {    float args[5];            /* x1, y1, x2, y2, r */
  144.     int code;
  145.     if ( (code = num_params(op, 5, args)) < 0 ) return code;
  146.     return gs_arcto(igs, args[0], args[1], args[2], args[3], args[4], tanxy);
  147. }
  148.  
  149. /* <x1> <y1> <x2> <y2> <x3> <y3> curveto - */
  150. int
  151. zcurveto(register os_ptr op)
  152. {    return common_curve(op, gs_curveto);
  153. }
  154.  
  155. /* <dx1> <dy1> <dx2> <dy2> <dx3> <dy3> rcurveto - */
  156. int
  157. zrcurveto(register os_ptr op)
  158. {    return common_curve(op, gs_rcurveto);
  159. }
  160.  
  161. /* Common code for [r]curveto */
  162. private int near
  163. common_curve(os_ptr op,
  164.   int (*add_proc)(P7(gs_state *, floatp, floatp, floatp, floatp, floatp, floatp)))
  165. {    float opxy[6];
  166.     int code;
  167.     if ( (code = num_params(op, 6, opxy)) < 0 ) return code;
  168.     code = (*add_proc)(igs, opxy[0], opxy[1], opxy[2], opxy[3], opxy[4], opxy[5]);
  169.     if ( code >= 0 ) pop(6);
  170.     return code;
  171. }
  172.  
  173. /* - closepath - */
  174. int
  175. zclosepath(register os_ptr op)
  176. {    return gs_closepath(igs);
  177. }
  178.  
  179. /* ------ Initialization procedure ------ */
  180.  
  181. op_def zpath_op_defs[] = {
  182.     {"5arc", zarc},
  183.     {"5arcn", zarcn},
  184.     {"5arct", zarct},
  185.     {"5arcto", zarcto},
  186.     {"0closepath", zclosepath},
  187.     {"0currentpoint", zcurrentpoint},
  188.     {"6curveto", zcurveto},
  189.     {"2lineto", zlineto},
  190.     {"2moveto", zmoveto},
  191.     {"0newpath", znewpath},
  192.     {"6rcurveto", zrcurveto},
  193.     {"2rlineto", zrlineto},
  194.     {"2rmoveto", zrmoveto},
  195.     op_def_end(0)
  196. };
  197.