Class: Pdfrb::Document::Outline
- Inherits:
-
Object
- Object
- Pdfrb::Document::Outline
- Defined in:
- lib/pdfrb/document/outline.rb
Overview
Bookmark/outline facade. Builds the /Outlines tree on the Catalog so PDF viewers show a navigation panel.
Instance Attribute Summary collapse
-
#document ⇒ Object
readonly
Returns the value of attribute document.
-
#entries ⇒ Object
readonly
Returns the value of attribute entries.
Instance Method Summary collapse
- #add(title, dest: nil, parent: nil) ⇒ Object
- #build! ⇒ Object
-
#initialize(document) ⇒ Outline
constructor
A new instance of Outline.
Constructor Details
#initialize(document) ⇒ Outline
Returns a new instance of Outline.
10 11 12 13 |
# File 'lib/pdfrb/document/outline.rb', line 10 def initialize(document) @document = document @entries = [] end |
Instance Attribute Details
#document ⇒ Object (readonly)
Returns the value of attribute document.
8 9 10 |
# File 'lib/pdfrb/document/outline.rb', line 8 def document @document end |
#entries ⇒ Object (readonly)
Returns the value of attribute entries.
8 9 10 |
# File 'lib/pdfrb/document/outline.rb', line 8 def entries @entries end |
Instance Method Details
#add(title, dest: nil, parent: nil) ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/pdfrb/document/outline.rb', line 15 def add(title, dest: nil, parent: nil) entry = OutlineEntry.new(title: title.to_s, dest: dest) if parent parent.add_child(entry) else @entries << entry end entry end |
#build! ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/pdfrb/document/outline.rb', line 25 def build! return if @entries.empty? root = @document.add( { Type: :Outlines }, type: Pdfrb::Model::Cos::Dictionary ) root_ref = Pdfrb::Model::Reference.new(root.oid, root.gen) prev_dict = nil first_ref = nil @entries.each do |entry| dict = entry.build!(@document) ref = Pdfrb::Model::Reference.new(dict.oid, dict.gen) dict.value[:Parent] = root_ref dict.value[:Prev] = Pdfrb::Model::Reference.new(prev_dict.oid, dict.gen) if prev_dict dict.value[:Next] = nil prev_dict&.value&.[]=(:Next, ref) first_ref ||= ref prev_dict = dict end root.value[:First] = first_ref root.value[:Last] = Pdfrb::Model::Reference.new(prev_dict.oid, prev_dict.gen) if prev_dict root.value[:Count] = @entries.length @document.catalog.value[:Outlines] = root_ref root end |