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
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
# File lib/prawn/graphics/transparency.rb, line 54
54: def transparent(opacity, stroke_opacity=opacity, &block)
55: min_version(1.4)
56:
57: opacity = [[opacity, 0.0].max, 1.0].min
58: stroke_opacity = [[stroke_opacity, 0.0].max, 1.0].min
59:
60: save_graphics_state
61: add_content "/#{opacity_dictionary_name(opacity, stroke_opacity)} gs"
62: yield
63: restore_graphics_state
64: end
# File lib/prawn/graphics/transparency.rb, line 72
72: def next_opacity_dictionary_id
73: opacity_dictionary_registry.length + 1
74: end
# File lib/prawn/graphics/transparency.rb, line 76
76: def opacity_dictionary_name(opacity, stroke_opacity)
77: key = "#{opacity}_#{stroke_opacity}"
78:
79: if opacity_dictionary_registry[key]
80: dictionary = opacity_dictionary_registry[key][:obj]
81: dictionary_name = opacity_dictionary_registry[key][:name]
82: else
83: dictionary = ref!(:Type => :ExtGState,
84: :CA => stroke_opacity,
85: :ca => opacity
86: )
87:
88: dictionary_name = "Tr#{next_opacity_dictionary_id}"
89: opacity_dictionary_registry[key] = { :name => dictionary_name,
90: :obj => dictionary }
91: end
92:
93: page.ext_gstates.merge!(dictionary_name => dictionary)
94: dictionary_name
95: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.