Method: HexaPDF::Type::Annotation#appearance

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

#appearance(type: :normal, state_name: ) ⇒ Object Also known as: appearance?

Returns the annotation’s appearance stream of the given type (:normal, :rollover, or :down) or nil if it doesn’t exist.

The appearance state in /AS or the one provided via state_name is taken into account if necessary.



245
246
247
248
249
250
251
252
253
254
255
256
257
258
# File 'lib/hexapdf/type/annotation.rb', line 245

def appearance(type: :normal, state_name: self[:AS])
  entry = appearance_dict&.send("#{type}_appearance") rescue nil
  if entry.kind_of?(HexaPDF::Dictionary) && !entry.kind_of?(HexaPDF::Stream)
    entry = entry[state_name]
  end
  return unless entry.kind_of?(HexaPDF::Stream)

  if entry.type == :XObject && entry[:Subtype] == :Form && !entry.instance_of?(HexaPDF::Stream)
    entry
  elsif (entry[:Type].nil? || entry[:Type] == :XObject) &&
      (entry[:Subtype].nil? || entry[:Subtype] == :Form) && entry[:BBox]
    document.wrap(entry, type: :XObject, subtype: :Form)
  end
end