Class: HexaPDF::Layout::TextBox

Inherits:
Box
  • Object
show all
Defined in:
lib/hexapdf/layout/text_box.rb

Overview

A TextBox is used for drawing text, either inside a rectangular box or by flowing it around objects of a Frame.

This class uses TextLayouter behind the scenes to do the hard work.

Used Box Properties

The spacing after the last line can be controlled via the style property last_line_gap. Also see TextLayouter#style for other style properties taken into account.

Constant Summary

Constants included from Utils

Utils::EPSILON

Instance Attribute Summary

Attributes inherited from Box

#fit_result, #height, #properties, #style, #width

Instance Method Summary collapse

Methods inherited from Box

#content_height, #content_width, create, #fit, #split, #split_box?

Constructor Details

#initialize(items:, **kwargs) ⇒ TextBox

Creates a new TextBox object with the given inline items (e.g. TextFragment and InlineBox objects).



55
56
57
58
59
60
61
# File 'lib/hexapdf/layout/text_box.rb', line 55

def initialize(items:, **kwargs)
  super(**kwargs)
  @tl = TextLayouter.new(style)
  @items = items
  @result = nil
  @x_offset = 0
end

Instance Method Details

#draw(canvas, x, y) ⇒ Object

:nodoc:



76
77
78
# File 'lib/hexapdf/layout/text_box.rb', line 76

def draw(canvas, x, y)
  super(canvas, x + @x_offset, y)
end

#empty?Boolean

:nodoc:

Returns:

  • (Boolean)


81
82
83
# File 'lib/hexapdf/layout/text_box.rb', line 81

def empty?
  super && (!@result || @result.lines.empty?)
end

#supports_position_flow?Boolean

Returns true as the ‘position’ style property value :flow is supported.

Returns:

  • (Boolean)


71
72
73
# File 'lib/hexapdf/layout/text_box.rb', line 71

def supports_position_flow?
  true
end

#textObject

Returns the text that will be drawn.

This will ignore any inline boxes or kerning values.



66
67
68
# File 'lib/hexapdf/layout/text_box.rb', line 66

def text
  @items.map {|item| item.kind_of?(TextFragment) ? item.text : '' }.join
end