Class: Pdfrb::Linearization::HintStream
- Inherits:
-
Object
- Object
- Pdfrb::Linearization::HintStream
- Defined in:
- lib/pdfrb/linearization/hint_stream.rb
Overview
Builds the page-offset hint stream (ISO 32000-2 Annex F). The hint stream tells the viewer where each page's objects are located without needing to parse the full xref.
This implementation produces a minimal valid hint table:
/S 16 (16 bits per entry field)
One page-offset entry per page.
Constant Summary collapse
- DEFAULT_ITEM_BITS =
16
Instance Attribute Summary collapse
-
#item_bits ⇒ Object
readonly
Returns the value of attribute item_bits.
-
#page_entries ⇒ Object
readonly
Returns the value of attribute page_entries.
Instance Method Summary collapse
-
#add_page(offset_delta:, page_length:, num_objects:, page_obj_num:) ⇒ Object
Add a page entry.
-
#dictionary_fields(length) ⇒ Object
Dictionary fields for the hint stream object.
-
#encode ⇒ String
Encode the hint stream as PDF bytes (binary, ready for /Length).
-
#initialize(item_bits: DEFAULT_ITEM_BITS) ⇒ HintStream
constructor
A new instance of HintStream.
Constructor Details
#initialize(item_bits: DEFAULT_ITEM_BITS) ⇒ HintStream
Returns a new instance of HintStream.
20 21 22 23 |
# File 'lib/pdfrb/linearization/hint_stream.rb', line 20 def initialize(item_bits: DEFAULT_ITEM_BITS) @item_bits = item_bits @page_entries = [] end |
Instance Attribute Details
#item_bits ⇒ Object (readonly)
Returns the value of attribute item_bits.
18 19 20 |
# File 'lib/pdfrb/linearization/hint_stream.rb', line 18 def item_bits @item_bits end |
#page_entries ⇒ Object (readonly)
Returns the value of attribute page_entries.
18 19 20 |
# File 'lib/pdfrb/linearization/hint_stream.rb', line 18 def page_entries @page_entries end |
Instance Method Details
#add_page(offset_delta:, page_length:, num_objects:, page_obj_num:) ⇒ Object
Add a page entry.
30 31 32 33 34 35 36 37 |
# File 'lib/pdfrb/linearization/hint_stream.rb', line 30 def add_page(offset_delta:, page_length:, num_objects:, page_obj_num:) @page_entries << { offset_delta: offset_delta, page_length: page_length, num_objects: num_objects, page_obj_num: page_obj_num, } end |
#dictionary_fields(length) ⇒ Object
Dictionary fields for the hint stream object.
56 57 58 59 60 61 62 |
# File 'lib/pdfrb/linearization/hint_stream.rb', line 56 def dictionary_fields(length) { S: @item_bits, }.tap do |h| h[:Length] = length end end |
#encode ⇒ String
Encode the hint stream as PDF bytes (binary, ready for /Length).
41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/pdfrb/linearization/hint_stream.rb', line 41 def encode bits = [] @page_entries.each do |entry| bits << [entry[:offset_delta], @item_bits] bits << [entry[:page_length], @item_bits] bits << [entry[:num_objects], @item_bits] bits << [entry[:page_obj_num], @item_bits] end packed = pack_bits(bits) packed.force_encoding(Encoding::BINARY) end |