Thanks for the help! I had never used the add_content method - it looks like that could be a lifesaver if I want to do any other weird things not defined in Prawn. That and a PDF reference manual :) Below is what I ended up with to make a semi-filled rounded rectangle. I'm guessing since I clip then reset, I do need to redo the round rectangle path to stroke it. Otherwise, the stroke is clipped out also. If there's a more efficient way to re-do the round rectangle path, I'm all ears though - otherwise I'm cleaning this up a tad and making it into a nice little method.
I attached an example of what I am making - if anyone is interested I can share the final code on github - it will basically be the below with the values grabbed from the parameters passed to the method.
begin # two-part shaded round rectangle
pdf.save_graphics_state
# set clipping shape
pdf.rectangle [300,300], 200,20
pdf.set_clip_path
pdf.rounded_rectangle [300,300], 200, 60, 10
pdf.horizontal_line 300, 500, at: 280
pdf.transparent 0.5,1.0 do
pdf.fill_color "#ff0000"
pdf.fill
end
pdf.restore_graphics_state
pdf.rounded_rectangle [300,300], 200, 60, 10
pdf.horizontal_line 300, 500, at: 280
pdf.stroke
end
On Tuesday, September 4, 2012 5:27:39 PM UTC-5, Rob wrote:
Prawn does not (that I know of) have support for a clipping path. But it is easy to add by extending the Graphics class.
module Prawn
module Graphics
def set_clip_path
add_content "W* n"
end
end
end
Now you can create filled shape like a rectangle or image and use a path to clip the shape, in your case the clipping shape would be a circle.
In your code:
save_graphics_state
# create the clipping shape here like a circle
set_clip_path ## from the above method
# next create any shapes to be clipped like a rectangle with a filled color or even an image
restore_graphics_state
The order is important, the clipping shape goes on the bottom. After set_clip_path is called every subsequent item is clipped until restore_graphics_state is called.