Class: HexaPDF::Type::Annotation::AppearanceDictionary
- Inherits:
-
Dictionary
- Object
- Object
- Dictionary
- HexaPDF::Type::Annotation::AppearanceDictionary
- Defined in:
- lib/hexapdf/type/annotation.rb
Overview
The appearance dictionary references appearance streams for various use cases.
Each appearance can either be an XObject or a dictionary mapping names to XObjects. The latter is used when the appearance depends on the state of the annotation, e.g. a check box widget that can be checked or unchecked.
See: PDF2.0 s12.5.5
Constant Summary collapse
- APPEARANCE_TYPE_TO_KEY =
:nodoc:
{normal: :N, rollover: :R, down: :D}.freeze
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
-
#down_appearance ⇒ Object
The down appearance which should be used when the mouse button is pressed or held down inside the active area of the annotation.
-
#normal_appearance ⇒ Object
The annotation’s normal appearance.
-
#rollover_appearance ⇒ Object
The rollover appearance which should be used when the cursor is moved into the active area of the annotation without pressing a button.
-
#set_appearance(appearance, type: :normal, state_name: nil) ⇒ Object
Sets the appearance of the given appearance
type
, which can either be :normal, :rollover or :down, toappearance
.
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, #must_be_indirect?, #null?, #oid, #oid=, #type, #validate, #value, #value=
Constructor Details
This class inherits a constructor from HexaPDF::Object
Instance Method Details
#down_appearance ⇒ Object
The down appearance which should be used when the mouse button is pressed or held down inside the active area of the annotation.
77 78 79 |
# File 'lib/hexapdf/type/annotation.rb', line 77 def down_appearance self[:D] || self[:N] end |
#normal_appearance ⇒ Object
The annotation’s normal appearance.
65 66 67 |
# File 'lib/hexapdf/type/annotation.rb', line 65 def normal_appearance self[:N] end |
#rollover_appearance ⇒ Object
The rollover appearance which should be used when the cursor is moved into the active area of the annotation without pressing a button.
71 72 73 |
# File 'lib/hexapdf/type/annotation.rb', line 71 def rollover_appearance self[:R] || self[:N] end |
#set_appearance(appearance, type: :normal, state_name: nil) ⇒ Object
Sets the appearance of the given appearance type
, which can either be :normal, :rollover or :down, to appearance
.
If the state_name
argument is provided, the appearance
is stored under the state_name
key in a sub-dictionary of the appearance.
88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/hexapdf/type/annotation.rb', line 88 def set_appearance(appearance, type: :normal, state_name: nil) key = APPEARANCE_TYPE_TO_KEY.fetch(type) do raise ArgumentError, "Invalid value for type specified: #{type.inspect}" end if state_name self[key] = {} unless value[key].kind_of?(Hash) self[key][state_name] = appearance else self[key] = appearance end end |