Module: Prawn::Graphics::Transparency
- Included in:
 - Prawn::Graphics
 
- Defined in:
 - lib/prawn/graphics/transparency.rb
 
Overview
The Prawn::Transparency module is used to place transparent content on the page. It has the capacity for separate transparency values for stroked content and all other content.
Example:
# both the fill and stroke will be at 50% opacity
pdf.transparent(0.5) do
  pdf.text("hello world")
  pdf.fill_and_stroke_circle([x, y], 25)
end
# the fill will be at 50% opacity, but the stroke will
# be at 75% opacity
pdf.transparent(0.5, 0.75) do
  pdf.text("hello world")
  pdf.fill_and_stroke_circle([x, y], 25)
end
  Stable API collapse
- 
  
    
      #transparent(opacity, stroke_opacity = opacity)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Sets the
opacityandstroke_opacityfor all the content within theblockIfstroke_opacityis not provided, then it takes on the same value asopacity. 
Instance Method Details
#transparent(opacity, stroke_opacity = opacity) ⇒ Object
Sets the opacity and stroke_opacity for all the content within the block If stroke_opacity is not provided, then it takes on the same value as opacity
Valid ranges for both paramters are 0.0 to 1.0
Example:
# both the fill and stroke will be at 50% opacity
pdf.transparent(0.5) do
  pdf.text("hello world")
  pdf.fill_and_stroke_circle([x, y], 25)
end
# the fill will be at 50% opacity, but the stroke will
# be at 75% opacity
pdf.transparent(0.5, 0.75) do
  pdf.text("hello world")
  pdf.fill_and_stroke_circle([x, y], 25)
end
  
      54 55 56 57 58 59 60 61 62 63 64 65 66  | 
    
      # File 'lib/prawn/graphics/transparency.rb', line 54 def transparent(opacity, stroke_opacity = opacity) renderer.min_version(1.4) opacity = [[opacity, 0.0].max, 1.0].min stroke_opacity = [[stroke_opacity, 0.0].max, 1.0].min save_graphics_state renderer.add_content( "/#{opacity_dictionary_name(opacity, stroke_opacity)} gs" ) yield restore_graphics_state end  |