Method: HexaPDF::Type::Annotation#opacity

Defined in:
lib/hexapdf/type/annotation.rb

#opacity(fill_alpha: nil, stroke_alpha: nil) ⇒ Object

:call-seq:

annotation.opacity                                           => current_values
annotation.opacity(fill_alpha:)                              => annotation
annotation.opacity(stroke_alpha:)                            => annotation
annotation.opacity(fill_alpha:, stroke_alpha:)               => annotation

Returns an Opacity instance representing the fill and stroke alpha values when no arguments are given. Otherwise sets the provided alpha values and returns self.

The fill and stroke alpha values are used when regenerating the annotation’s appearance stream and determine how opaque drawn elements will be. Note that the fill alpha value applies not just to fill values but to all non-stroking operations (e.g. images, …).



322
323
324
325
326
327
328
329
330
# File 'lib/hexapdf/type/annotation.rb', line 322

def opacity(fill_alpha: nil, stroke_alpha: nil)
  if !fill_alpha.nil? || !stroke_alpha.nil?
    self[:CA] = stroke_alpha unless stroke_alpha.nil?
    self[:ca] = fill_alpha unless fill_alpha.nil?
    self
  else
    Opacity.new(key?(:ca) ? self[:ca] : self[:CA], self[:CA])
  end
end