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
114 115 116 117 118 |
# File 'lib/pdfrb/document/outline.rb', line 114 def initialize(title:, dest:) @title = title @dest = dest @children = [] end |
Instance Attribute Details
#children ⇒ Object (readonly)
Returns the value of attribute children.
112 113 114 |
# File 'lib/pdfrb/document/outline.rb', line 112 def children @children end |
#dest ⇒ Object (readonly)
Returns the value of attribute dest.
112 113 114 |
# File 'lib/pdfrb/document/outline.rb', line 112 def dest @dest end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
112 113 114 |
# File 'lib/pdfrb/document/outline.rb', line 112 def title @title end |
Instance Method Details
#add_child(entry) ⇒ Object
120 121 122 123 |
# File 'lib/pdfrb/document/outline.rb', line 120 def add_child(entry) @children << entry entry end |
#build!(document) ⇒ Object
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/pdfrb/document/outline.rb', line 125 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 = child_dict.ref parent_ref = dict.ref child_dict.value[:Parent] = parent_ref child_dict.value[:Prev] = prev_child_dict.ref 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] = prev_child_dict.ref if prev_child_dict dict.value[:Count] = @children.length end dict end |