Subversion Repositories planix.SVN

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 - 1
/* Copyright (C) 1997, 1998 Aladdin Enterprises.  All rights reserved.
2
 
3
  This software is provided AS-IS with no warranty, either express or
4
  implied.
5
 
6
  This software is distributed under license and may not be copied,
7
  modified or distributed except as expressly authorized under the terms
8
  of the license contained in the file LICENSE in this distribution.
9
 
10
  For more information about licensing, please refer to
11
  http://www.ghostscript.com/licensing/. For information on
12
  commercial licensing, go to http://www.artifex.com/licensing/ or
13
  contact Artifex Software, Inc., 101 Lucas Valley Road #110,
14
  San Rafael, CA  94903, U.S.A., +1(415)492-9861.
15
*/
16
 
17
/* $Id: gsdps.c,v 1.5 2002/06/16 05:48:55 lpd Exp $ */
18
/* Display PostScript extensions */
19
#include "gx.h"
20
#include "gserrors.h"
21
#include "gsdps.h"
22
#include "gspath.h"		/* for newpath */
23
#include "gxdevice.h"		/* for gxcpath.h */
24
#include "gzpath.h"		/* for gzcpath.h */
25
#include "gzstate.h"
26
#include "gzcpath.h"
27
 
28
/* ---------------- View clipping ---------------- */
29
 
30
/* Forward references */
31
private int common_viewclip(gs_state *, int);
32
 
33
int
34
gs_initviewclip(gs_state * pgs)
35
{
36
    gx_clip_path *pcpath = pgs->view_clip;
37
 
38
    if (pcpath != 0 && pcpath->rule != 0) {
39
	gx_cpath_reset(pcpath);
40
	pcpath->rule = 0;
41
    }
42
    return 0;
43
}
44
 
45
int
46
gs_viewclip(gs_state * pgs)
47
{
48
    return common_viewclip(pgs, gx_rule_winding_number);
49
}
50
 
51
int
52
gs_eoviewclip(gs_state * pgs)
53
{
54
    return common_viewclip(pgs, gx_rule_even_odd);
55
}
56
 
57
/* This code is (almost) copied from common_clip in gspath.c. */
58
/* Someday we'll find a way to merge them. */
59
private int
60
common_viewclip(gs_state * pgs, int rule)
61
{
62
    gs_fixed_rect bbox;
63
    gx_clip_path rpath;
64
    int code;
65
    gx_clip_path *pcpath = pgs->view_clip;
66
 
67
    if (pcpath == 0) {
68
	pcpath = gx_cpath_alloc(pgs->memory, "gs_[eo]viewclip");
69
	if (pcpath == 0)
70
	    return_error(gs_error_VMerror);
71
	pgs->view_clip = pcpath;
72
    }
73
    if ((code = gx_path_bbox(pgs->path, &bbox)) < 0)
74
	return code;
75
    gx_cpath_init_local(&rpath, pgs->memory);
76
    code = gx_cpath_from_rectangle(&rpath, &bbox);
77
    if (code >= 0)
78
	code = gx_cpath_clip(pgs, &rpath, pgs->path, rule);
79
    if (code < 0) {
80
	gx_cpath_free(&rpath, "gs_[eo]viewclip");
81
	return code;
82
    }
83
    rpath.rule = rule;
84
    gx_cpath_assign_free(pcpath, &rpath);
85
    gs_newpath(pgs);
86
    return 0;
87
}
88
 
89
int
90
gs_viewclippath(gs_state * pgs)
91
{
92
    gx_path cpath;
93
    gx_clip_path *pcpath = pgs->view_clip;
94
    int code;
95
 
96
    gx_path_init_local(&cpath, pgs->memory);
97
    if (pcpath == 0 || pcpath->rule == 0) {
98
	/* No view clip path is active: fabricate one. */
99
	gs_fixed_rect box;
100
 
101
	code = gx_default_clip_box(pgs, &box);
102
	if (code < 0)
103
	    return code;
104
	code = gx_path_add_rectangle(&cpath, box.p.x, box.p.y,
105
				     box.q.x, box.q.y);
106
    } else {
107
	code = gx_cpath_to_path(pcpath, &cpath);
108
    }
109
    if (code < 0)
110
	return code;
111
    return gx_path_assign_free(pgs->path, &cpath);
112
}