• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How do I keep a gsave/grestore protected fill object from flooding the clipping path meant to clip the object

Community Beginner ,
Sep 04, 2015 Sep 04, 2015

Copy link to clipboard

Copied

I have defined a clipping path  and then defined an object (closed path) to be filled protected within a gsave/grestore block.  The clipping path should clip the object and leave the remaining object filled within a the unfilled background  of the clipping path.  But the result is the entire clipping path is filled.  How do I stop this?

An example is:

/inch {72 mul } def

/triangle {gsave  .9 setgray

0 inch 0 inch moveto

5 inch 0 inch lineto

2.5 inch 5 inch lineto

0 inch 0 inch lineto fill    0 setgray

0 inch 0 inch moveto

5 inch 0 inch lineto

2.5 inch 5 inch lineto

0 inch 0 inch lineto stroke 

grestore} def

/SquarePath {newpath

1 inch 0 inch moveto

3 inch 0 inch lineto

3 inch 8 inch lineto

1 inch 8 inch lineto

1 inch 0 inch lineto closepath} def

% draw it

1 inch 1 inch translate

SquarePath clip

triangle

showpage

Any ideas?   Thanks in advance

TOPICS
Programming

Views

1.3K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 05, 2015 Sep 05, 2015

Copy link to clipboard

Copied

Hi.

One of clip's surprises is that it doesn't erase the current path, as do fill and stroke. Add a call to newpath immediately after the clip and the code should behave as you intended.

By the way, in case you haven't stumbled on this before, you can simplify your triangle code significantly by using another, nested, gsave-grestore pair:

/triangle {gsave  .9 setgray

gsave

0 inch 0 inch moveto

5 inch 0 inch lineto

2.5 inch 5 inch lineto

0 inch 0 inch lineto fill

grestore

stroke 

grestore} def

Hope this helps.

- John

-------

John Deubert

Acumen Training

PostScript & PDF consulting and training

john@acumentraining.com

www.acumentraining.com

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 08, 2015 Sep 08, 2015

Copy link to clipboard

Copied

LATEST

Thank you, John.  Great tip.  It worked like a charm.  I really appreciate the comment about clip not clearing the path. 

Again, thanks for the tips, and for the fast response.

John Hobbie

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines