Class: Pdfrb::Document::OutlineEntry
- Inherits:
-
Object
- Object
- Pdfrb::Document::OutlineEntry
- Defined in:
- lib/pdfrb/document/outline.rb
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#dest ⇒ Object
readonly
Returns the value of attribute dest.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Instance Method Summary collapse
- #add_child(entry) ⇒ Object
- #build!(document) ⇒ Object
-
#initialize(title:, dest:) ⇒ OutlineEntry
constructor
A new instance of OutlineEntry.
Constructor Details
#initialize(title:, dest:) ⇒ OutlineEntry
Returns a new instance of OutlineEntry.
61 62 63 64 65 |
# File 'lib/pdfrb/document/outline.rb', line 61 def initialize(title:, dest:) @title = title @dest = dest @children = [] end |
Instance Attribute Details
#children ⇒ Object (readonly)
Returns the value of attribute children.
59 60 61 |
# File 'lib/pdfrb/document/outline.rb', line 59 def children @children end |
#dest ⇒ Object (readonly)
Returns the value of attribute dest.
59 60 61 |
# File 'lib/pdfrb/document/outline.rb', line 59 def dest @dest end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
59 60 61 |
# File 'lib/pdfrb/document/outline.rb', line 59 def title @title end |
Instance Method Details
#add_child(entry) ⇒ Object
67 68 69 70 |
# File 'lib/pdfrb/document/outline.rb', line 67 def add_child(entry) @children << entry entry end |
#build!(document) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/pdfrb/document/outline.rb', line 72 def build!(document) dict = document.add({ Title: @title }, type: Pdfrb::Model::Cos::Dictionary) dict.value[:Dest] = @dest if @dest if @children.any? prev_child_dict = nil first_ref = nil @children.each do |child| child_dict = child.build!(document) child_ref = Pdfrb::Model::Reference.new(child_dict.oid, child_dict.gen) parent_ref = Pdfrb::Model::Reference.new(dict.oid, dict.gen) child_dict.value[:Parent] = parent_ref child_dict.value[:Prev] = Pdfrb::Model::Reference.new(prev_child_dict.oid, prev_child_dict.gen) if prev_child_dict child_dict.value[:Next] = nil prev_child_dict&.value&.[]=(:Next, child_ref) first_ref ||= child_ref prev_child_dict = child_dict end dict.value[:First] = first_ref dict.value[:Last] = Pdfrb::Model::Reference.new(prev_child_dict.oid, prev_child_dict.gen) if prev_child_dict dict.value[:Count] = @children.length end dict end |