Class: HexaPDF::Type::Actions::SetOCGState
- Inherits:
-
HexaPDF::Type::Action
- Object
- Object
- Dictionary
- HexaPDF::Type::Action
- HexaPDF::Type::Actions::SetOCGState
- Defined in:
- lib/hexapdf/type/actions/set_ocg_state.rb
Overview
A Set-OCG-state action changes the state of one or more optional content groups.
See: PDF2.0 s12.6.4.13, HexaPDF::Type::OptionalContentGroup
Constant Summary collapse
- STATE_TYPE_MAPPING =
:nodoc:
{on: :ON, ON: :ON, off: :OFF, OFF: :OFF, # :nodoc: toggle: :Toggle, Toggle: :Toggle}
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
-
#add_state_change(type, ocgs) ⇒ Object
Adds a state changing sequence to the /State array.
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
#add_state_change(type, ocgs) ⇒ Object
Adds a state changing sequence to the /State array.
The type
argument specifies how the state of the given optional content groups should be changed.
type
-
The type of sequence to add, either :on/:ON (for turning the OCGs on) , :off/:OFF (for turning the OCGs off), or :toggle/:Toggle (for toggling the state of the OCGs).
ocgs
-
A single optional content group or an array of optional content groups to which the state change defined with
type
should be applied. The OCGs can be specified via their dictionary or by name which uses the first found OCG with that name.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/hexapdf/type/actions/set_ocg_state.rb', line 67 def add_state_change(type, ocgs) type = STATE_TYPE_MAPPING.fetch(type) do raise ArgumentError, "Invalid type #{type} specified, should be one of :on, :off or :toggle" end state = self[:State] state << type Array(ocgs).each do |ocg| if (ocg_name = ocg).kind_of?(String) ocg = document.optional_content.ocg(ocg_name, create: false) raise HexaPDF::Error, "Invalid OCG named '#{ocg_name}' specified" unless ocg end state << ocg end end |