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

  1. /* Copyright (C) 1989, 1992, 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. /* gspaint.c */
  20. /* Painting procedures for Ghostscript library */
  21. #include "gx.h"
  22. #include "gpcheck.h"
  23. #include "gserrors.h"
  24. #include "gxfixed.h"
  25. #include "gxmatrix.h"            /* for gs_state */
  26. #include "gspaint.h"
  27. #include "gzpath.h"
  28. #include "gxpaint.h"
  29. #include "gzstate.h"
  30. #include "gxcpath.h"
  31. #include "gxdevmem.h"
  32. #include "gximage.h"
  33.  
  34. /* Erase the page */
  35. int
  36. gs_erasepage(gs_state *pgs)
  37. {    /* We can't just fill with device white; we must take the */
  38.     /* transfer function into account. */
  39.     int code;
  40.     if ( (code = gs_gsave(pgs)) < 0 )
  41.         return code;
  42.     if ( (code = gs_setgray(pgs, 1.0)) >= 0 )
  43.     {    /* Fill the page directly, ignoring clipping. */
  44.         code = gs_fillpage(pgs);
  45.     }
  46.     gs_grestore(pgs);
  47.     return code;
  48. }
  49.  
  50. /* Fill the page with the current color. */
  51. int
  52. gs_fillpage(gs_state *pgs)
  53. {    gx_device *dev;
  54.     int code;
  55.     gx_set_dev_color(pgs);
  56.     dev = gs_currentdevice(pgs);
  57.     /* Fill the page directly, ignoring clipping. */
  58.     code = gx_fill_rectangle(0, 0, dev->width, dev->height,
  59.                  pgs->dev_color, pgs);
  60.     if ( code < 0 )
  61.         return code;
  62.     return (*dev_proc(dev, sync_output))(dev);
  63. }
  64.  
  65. /* Fill using the winding number rule */
  66. int
  67. gs_fill(gs_state *pgs)
  68. {    int code;
  69.     /* If we're inside a charpath, just merge the current path */
  70.     /* into the parent's path. */
  71.     if ( pgs->in_charpath )
  72.         code = gx_path_add_path(pgs->show_gstate->path, pgs->path);
  73.     else
  74.     {    gx_set_dev_color(pgs);
  75.         code = gx_color_load(pgs->dev_color, pgs);
  76.         if ( code < 0 )
  77.             return code;
  78.         code = gx_fill_path(pgs->path, pgs->dev_color, pgs,
  79.                     gx_rule_winding_number, fixed_0);
  80.         if ( !code ) gs_newpath(pgs);
  81.     }
  82.     return code;
  83. }
  84.  
  85. /* Fill using the even/odd rule */
  86. int
  87. gs_eofill(gs_state *pgs)
  88. {    int code;
  89.     /* If we're inside a charpath, just merge the current path */
  90.     /* into the parent's path. */
  91.     if ( pgs->in_charpath )
  92.         code = gx_path_add_path(pgs->show_gstate->path, pgs->path);
  93.     else
  94.     {    gx_set_dev_color(pgs);
  95.         code = gx_color_load(pgs->dev_color, pgs);
  96.         if ( code < 0 )
  97.             return code;
  98.         code = gx_fill_path(pgs->path, pgs->dev_color, pgs,
  99.                     gx_rule_even_odd, fixed_0);
  100.         if ( !code ) gs_newpath(pgs);
  101.     }
  102.     return code;
  103. }
  104.  
  105. /* Stroke the current path */
  106. int
  107. gs_stroke(gs_state *pgs)
  108. {    int code;
  109.     /* If we're inside a charpath, just merge the current path */
  110.     /* into the parent's path. */
  111.     if ( pgs->in_charpath )
  112.         code = gx_path_add_path(pgs->show_gstate->path, pgs->path);
  113.     else
  114.     {    gx_set_dev_color(pgs);
  115.         code = gx_color_load(pgs->dev_color, pgs);
  116.         if ( code < 0 )
  117.             return code;
  118.         code = gx_stroke_fill(pgs->path, pgs);
  119.         if ( !code ) gs_newpath(pgs);
  120.     }
  121.     return code;
  122. }
  123.  
  124. /* Compute the stroked outline of the current path */
  125. int
  126. gs_strokepath(gs_state *pgs)
  127. {    gx_path spath;
  128.     int code;
  129.     gx_path_init(&spath, pgs->memory);
  130.     code = gx_stroke_add(pgs->path, &spath, pgs);
  131.     if ( code < 0 ) return code;
  132.     gx_path_release(pgs->path);
  133.     *pgs->path = spath;
  134.     return 0;
  135. }
  136.