Class: Origami::XRef
- Inherits:
-
Object
- Object
- Origami::XRef
- Defined in:
- lib/origami/xreftable.rb
Overview
Class representing a Cross-reference information.
Defined Under Namespace
Classes: InvalidXRefSectionError, InvalidXRefSubsectionError, Section, Subsection
Constant Summary collapse
- FREE =
"f"
- USED =
"n"
- FIRSTFREE =
65535
- @@regexp =
/(?<offset>\d{10}) (?<gen>\d{5}) (?<state>n|f)(\r\n| \r| \n)/
Instance Attribute Summary collapse
-
#generation ⇒ Object
Returns the value of attribute generation.
-
#offset ⇒ Object
Returns the value of attribute offset.
-
#state ⇒ Object
Returns the value of attribute state.
Class Method Summary collapse
-
.parse(stream) ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#free! ⇒ Object
Marks an XRef as freed.
-
#free? ⇒ Boolean
Returns true if the associated object is freed.
-
#initialize(offset, generation, state) ⇒ XRef
constructor
Creates a new XRef.
-
#to_s(eol: $/) ⇒ Object
Outputs self into PDF code.
- #to_xrefstm_data(type_w, field1_w, field2_w) ⇒ Object
-
#used? ⇒ Boolean
Returns true if the associated object is used.
Constructor Details
#initialize(offset, generation, state) ⇒ XRef
Creates a new XRef.
- offset
-
The file offset of the referenced Object.
- generation
-
The generation number of the referenced Object.
- state
-
The state of the referenced Object (FREE or USED).
66 67 68 |
# File 'lib/origami/xreftable.rb', line 66 def initialize(offset, generation, state) @offset, @generation, @state = offset, generation, state end |
Instance Attribute Details
#generation ⇒ Object
Returns the value of attribute generation.
58 59 60 |
# File 'lib/origami/xreftable.rb', line 58 def generation @generation end |
#offset ⇒ Object
Returns the value of attribute offset.
58 59 60 |
# File 'lib/origami/xreftable.rb', line 58 def offset @offset end |
#state ⇒ Object
Returns the value of attribute state.
58 59 60 |
# File 'lib/origami/xreftable.rb', line 58 def state @state end |
Class Method Details
.parse(stream) ⇒ Object
:nodoc:
70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/origami/xreftable.rb', line 70 def self.parse(stream) #:nodoc: scanner = Parser.init_scanner(stream) if scanner.scan(@@regexp).nil? raise InvalidXRefError, "Invalid XRef format" end offset = scanner['offset'].to_i generation = scanner['gen'].to_i state = scanner['state'] XRef.new(offset, generation, state) end |
Instance Method Details
#free! ⇒ Object
Marks an XRef as freed.
101 102 103 |
# File 'lib/origami/xreftable.rb', line 101 def free! @state = FREE end |
#free? ⇒ Boolean
Returns true if the associated object is freed.
94 95 96 |
# File 'lib/origami/xreftable.rb', line 94 def free? @state == FREE end |
#to_s(eol: $/) ⇒ Object
Outputs self into PDF code.
108 109 110 111 112 113 |
# File 'lib/origami/xreftable.rb', line 108 def to_s(eol: $/) off = @offset.to_s.rjust(10, '0') gen = @generation.to_s.rjust(5, '0') "#{off} #{gen} #{@state}" + eol.rjust(2, ' ') end |
#to_xrefstm_data(type_w, field1_w, field2_w) ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/origami/xreftable.rb', line 115 def to_xrefstm_data(type_w, field1_w, field2_w) type_w <<= 3 field1_w <<= 3 field2_w <<= 3 type = ((@state == FREE) ? "\000" : "\001").unpack("B#{type_w}")[0] offset = @offset.to_s(2).rjust(field1_w, '0') generation = @generation.to_s(2).rjust(field2_w, '0') [ type , offset, generation ].pack("B#{type_w}B#{field1_w}B#{field2_w}") end |