Module: Prawn::Graphics::Transparency

Included in:
Prawn::Graphics
Defined in:
lib/prawn/graphics/transparency.rb

Instance Method Summary collapse

Instance Method Details

#transparent(opacity, stroke_opacity = opacity, &block) ⇒ Object


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/prawn/graphics/transparency.rb', line 14

def transparent(opacity, stroke_opacity=opacity, &block)
  min_version(1.4)

  key = "#{opacity}_#{stroke_opacity}"

  if opacity_dictionary_registry[key]
    opacity_dictionary =  opacity_dictionary_registry[key][:obj]
    opacity_dictionary_name =  opacity_dictionary_registry[key][:name]
  else
    opacity_dictionary = ref!(:Type => :ExtGState,
                              :CA   => stroke_opacity,
                              :ca   => opacity
                              )

    opacity_dictionary_name = "Tr#{next_opacity_dictionary_id}"
    opacity_dictionary_registry[key] = { :name => opacity_dictionary_name, 
                                         :obj  => opacity_dictionary }
  end

  page_ext_gstates.merge!(opacity_dictionary_name => opacity_dictionary)

  # push a new graphics context onto the graphics context stack
  add_content "q"
  add_content "/#{opacity_dictionary_name} gs"

  yield if block_given?

  add_content "Q"
end