Class: HexaPDF::Content::Processor::CompositeBox

Inherits:
Object
  • Object
show all
Defined in:
lib/hexapdf/content/processor.rb

Overview

Represents a box composed of GlyphBox objects.

The bounding box methods #lower_left, #lower_right, #upper_left, #upper_right are computed by just using the first and last boxes, assuming the boxes are arranged from left to right in a straight line.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCompositeBox

Creates an empty object.



160
161
162
# File 'lib/hexapdf/content/processor.rb', line 160

def initialize
  @boxes = []
end

Instance Attribute Details

#boxesObject (readonly)

The text boxes contained in this positioned text object.



157
158
159
# File 'lib/hexapdf/content/processor.rb', line 157

def boxes
  @boxes
end

Instance Method Details

#<<(glyph_box) ⇒ Object

Appends the given text glyph box.



165
166
167
168
# File 'lib/hexapdf/content/processor.rb', line 165

def <<(glyph_box)
  @boxes << glyph_box
  self
end

#[](index) ⇒ Object

Returns the glyph box at the given index, or nil if the index is out of range.



171
172
173
# File 'lib/hexapdf/content/processor.rb', line 171

def [](index)
  @boxes[index]
end

#each(&block) ⇒ Object

:call-seq:

composite.each {|glyph_box| block}       -> composite
composite.each                           -> Enumerator

Iterates over all contained glyph boxes.



180
181
182
183
184
# File 'lib/hexapdf/content/processor.rb', line 180

def each(&block)
  return to_enum(__method__) unless block_given?
  @boxes.each(&block)
  self
end

#lower_leftObject

:call-seq:

text.lower_left    -> [llx, lly]

Returns the lower left coordinate



195
196
197
# File 'lib/hexapdf/content/processor.rb', line 195

def lower_left
  @boxes[0].lower_left
end

#lower_rightObject

:call-seq:

text.lower_right   -> [lrx, lry]

Returns the lower right coordinate



203
204
205
# File 'lib/hexapdf/content/processor.rb', line 203

def lower_right
  @boxes[-1].lower_right
end

#stringObject

Returns the concatenated text of the boxes.



187
188
189
# File 'lib/hexapdf/content/processor.rb', line 187

def string
  @boxes.map(&:string).join('')
end

#upper_leftObject

:call-seq:

text.upper_left    -> [ulx, uly]

Returns the upper left coordinate



211
212
213
# File 'lib/hexapdf/content/processor.rb', line 211

def upper_left
  @boxes[0].upper_left
end

#upper_rightObject

:call-seq:

text.upper_right    -> [urx, ury]

Returns the upper right coordinate.



219
220
221
# File 'lib/hexapdf/content/processor.rb', line 219

def upper_right
  @boxes[-1].upper_right
end