Class: Rpdfium::Outline
- Inherits:
-
Object
- Object
- Rpdfium::Outline
- Defined in:
- lib/rpdfium/structure/outline.rb
Overview
Albero di bookmark (outline) del documento. Costruito ricorsivamente.
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#page_index ⇒ Object
readonly
Returns the value of attribute page_index.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Class Method Summary collapse
- .build_siblings(doc, bookmark_handle) ⇒ Object
-
.flatten(outline_tree, depth = 0, &block) ⇒ Object
Iteratore flat preorder: utile per generare un sommario lineare.
- .from_document(document) ⇒ Object
Instance Method Summary collapse
-
#initialize(title, page_index, children) ⇒ Outline
constructor
A new instance of Outline.
- #to_h ⇒ Object
Constructor Details
#initialize(title, page_index, children) ⇒ Outline
Returns a new instance of Outline.
8 9 10 11 12 |
# File 'lib/rpdfium/structure/outline.rb', line 8 def initialize(title, page_index, children) @title = title @page_index = page_index @children = children end |
Instance Attribute Details
#children ⇒ Object (readonly)
Returns the value of attribute children.
6 7 8 |
# File 'lib/rpdfium/structure/outline.rb', line 6 def children @children end |
#page_index ⇒ Object (readonly)
Returns the value of attribute page_index.
6 7 8 |
# File 'lib/rpdfium/structure/outline.rb', line 6 def page_index @page_index end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
6 7 8 |
# File 'lib/rpdfium/structure/outline.rb', line 6 def title @title end |
Class Method Details
.build_siblings(doc, bookmark_handle) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/rpdfium/structure/outline.rb', line 19 def self.build_siblings(doc, bookmark_handle) result = [] ptr = bookmark_handle until ptr.null? title = Raw.read_utf16_string(:FPDFBookmark_GetTitle, ptr) dest = Raw.FPDFBookmark_GetDest(doc.handle, ptr) idx = dest.null? ? nil : Raw.FPDFDest_GetDestPageIndex(doc.handle, dest) idx = nil if idx == -1 children_handle = Raw.FPDFBookmark_GetFirstChild(doc.handle, ptr) children = build_siblings(doc, children_handle) result << new(title, idx, children) ptr = Raw.FPDFBookmark_GetNextSibling(doc.handle, ptr) end result end |
.flatten(outline_tree, depth = 0, &block) ⇒ Object
Iteratore flat preorder: utile per generare un sommario lineare.
36 37 38 39 40 41 |
# File 'lib/rpdfium/structure/outline.rb', line 36 def self.flatten(outline_tree, depth = 0, &block) outline_tree.each do |item| block.call(item, depth) flatten(item.children, depth + 1, &block) end end |
.from_document(document) ⇒ Object
14 15 16 17 |
# File 'lib/rpdfium/structure/outline.rb', line 14 def self.from_document(document) first = Raw.FPDFBookmark_GetFirstChild(document.handle, FFI::Pointer::NULL) build_siblings(document, first) end |
Instance Method Details
#to_h ⇒ Object
43 44 45 46 |
# File 'lib/rpdfium/structure/outline.rb', line 43 def to_h { title: @title, page: @page_index, children: @children.map(&:to_h) } end |