home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Utilities / Ghostscript / src / zpath.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-01  |  3.8 KB  |  180 lines

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