Class: HexaPDF::Type::Annotation
- Inherits:
-
Dictionary
- Object
- Object
- Dictionary
- HexaPDF::Type::Annotation
- Extended by:
- Utils::BitField
- Defined in:
- lib/hexapdf/type/annotation.rb
Overview
Annotations are used to associate objects like notes, sounds or movies with a location on a PDF page or allow the user to interact with a PDF document using a keyboard or mouse.
See: PDF2.0 s12.5
Direct Known Subclasses
HexaPDF::Type::Annotations::Link, HexaPDF::Type::Annotations::MarkupAnnotation, HexaPDF::Type::Annotations::Widget
Defined Under Namespace
Classes: AppearanceDictionary, Border
Constant Summary
Constants included from DictionaryFields
DictionaryFields::Boolean, DictionaryFields::PDFByteString, DictionaryFields::PDFDate
Instance Attribute Summary
Attributes inherited from Object
#data, #document, #must_be_indirect
Instance Method Summary collapse
-
#appearance(type: :normal, state_name: ) ⇒ Object
(also: #appearance?)
Returns the annotation’s appearance stream of the given type (:normal, :rollover, or :down) or
nil
if it doesn’t exist. -
#appearance_dict ⇒ Object
Returns the AppearanceDictionary instance associated with the annotation or
nil
if none is set. -
#create_appearance(type: :normal, state_name: ) ⇒ Object
Creates an empty appearance stream (a Form XObject) of the given type (:normal, :rollover, or :down) and returns it.
-
#flags ⇒ Object
:method: unflag :call-seq: flag(*flags).
-
#must_be_indirect? ⇒ Boolean
Returns
true
because annotation objects must always be indirect objects.
Methods included from Utils::BitField
Methods inherited from Dictionary
#[], #[]=, define_field, define_type, #delete, #each, each_field, #empty?, field, #key?, #to_hash, type, #type
Methods inherited from Object
#<=>, #==, #cache, #cached?, #clear_cache, deep_copy, #deep_copy, #document?, #eql?, field, #gen, #gen=, #hash, #indirect?, #initialize, #inspect, make_direct, #null?, #oid, #oid=, #type, #validate, #value, #value=
Constructor Details
This class inherits a constructor from HexaPDF::Object
Instance Method Details
#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.
233 234 235 236 237 238 239 240 241 242 243 244 245 246 |
# File 'lib/hexapdf/type/annotation.rb', line 233 def appearance(type: :normal, state_name: self[:AS]) entry = appearance_dict&.send("#{type}_appearance") 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 |
#appearance_dict ⇒ Object
Returns the AppearanceDictionary instance associated with the annotation or nil
if none is set.
224 225 226 |
# File 'lib/hexapdf/type/annotation.rb', line 224 def appearance_dict self[:AP] end |
#create_appearance(type: :normal, state_name: ) ⇒ Object
Creates an empty appearance stream (a Form XObject) of the given type (:normal, :rollover, or :down) and returns it. If an appearance stream already exist, it is overwritten.
If there can be multiple appearance streams for the annotation, use the state_name
argument to provide the appearance state name.
254 255 256 257 258 259 260 |
# File 'lib/hexapdf/type/annotation.rb', line 254 def create_appearance(type: :normal, state_name: self[:AS]) xobject = document.add({Type: :XObject, Subtype: :Form, BBox: [0, 0, self[:Rect].width, self[:Rect].height]}) self[:AP] ||= {} appearance_dict.set_appearance(xobject, type: type, state_name: state_name) xobject end |
#flags ⇒ Object
:method: unflag :call-seq:
flag(*flags)
Clears the given flags from /F, given as flag names or bit indices.
See #flags for the list of available flags.
211 212 213 214 215 |
# File 'lib/hexapdf/type/annotation.rb', line 211 bit_field(:flags, {invisible: 0, hidden: 1, print: 2, no_zoom: 3, no_rotate: 4, no_view: 5, read_only: 6, locked: 7, toggle_no_view: 8, locked_contents: 9}, lister: "flags", getter: "flagged?", setter: "flag", unsetter: "unflag", value_getter: "self[:F]", value_setter: "self[:F]") |
#must_be_indirect? ⇒ Boolean
Returns true
because annotation objects must always be indirect objects.
218 219 220 |
# File 'lib/hexapdf/type/annotation.rb', line 218 def must_be_indirect? true end |